Show LINE NUMBERS in compiler errors!!

This commit is contained in:
Jeremy Penner 2021-08-18 22:19:57 -04:00
parent bee38a4168
commit 64281801b2
3 changed files with 35 additions and 20 deletions

View file

@ -440,7 +440,7 @@
(def-toolbox 0x9a04 SetTextFace (textFace) void)
(def-toolbox 0x9c04 SetTextMode (textMode) void)
(def-toolbox 0xd204 SetTextSize (textSize) void)
(def-toolbox 0x4604 SetUserFIeld ((long userFieldValue)) void)
(def-toolbox 0x4604 SetUserField ((long userFieldValue)) void)
(def-toolbox 0xc804 SetVisHandle ((long rgnHandle)) void)
(def-toolbox 0xb404 SetVisRgn ((long rgnHandle)) void)
(def-toolbox 0x9104 ShowCursor () void)

View file

@ -441,22 +441,30 @@
post (icollect [_ (countiter (length args))] (self:drop))]
(values (lume.concat [:block] pre [[:jsr f.name]] post) f.type)))
(fn Ssc.enter-expr [self expr]
(let [m (getmetatable expr)]
(when (and m m.filename) (set self.expr-metadata m))))
(fn Ssc.expr-poly [self expr]
; (pp expr)
(match expr
(where lit (?. (self:opgen lit) :hi)) (let [{: lo : hi} (self:opgen lit)]
(values [:block (lo :lda) [:sta self.LONG_LO] (hi :lda) [:sta self.LONG_HI]] :long))
(where lit (?. (self:opgen lit) :lo)) (let [{: lo} (self:opgen lit)] (values (lo :lda) :word))
(where getter (= (type getter) :string) (. self.getters getter))
(self:compile-function-call (. self.getters getter) [])
(where [func & args] (= (?. self.functions func :arity) (length args)))
(self:compile-function-call (. self.functions func) args)
(where [form & args] (. self.forms form))
(let [f (. self.forms form)
(cexpr etype) (f self (table.unpack args))]
(values cexpr (or etype :word)))
nil (values [:block] :void)
_ (error (.. "Unrecognized expression " (fv expr)))))
(self:enter-expr expr)
(let [(success c-expr etype)
(pcall #(match expr
(where lit (?. (self:opgen lit) :hi)) (let [{: lo : hi} (self:opgen lit)]
(values [:block (lo :lda) [:sta self.LONG_LO] (hi :lda) [:sta self.LONG_HI]] :long))
(where lit (?. (self:opgen lit) :lo)) (let [{: lo} (self:opgen lit)] (values (lo :lda) :word))
(where getter (= (type getter) :string) (. self.getters getter))
(self:compile-function-call (. self.getters getter) [])
(where [func & args] (= (?. self.functions func :arity) (length args)))
(self:compile-function-call (. self.functions func) args)
(where [form & args] (. self.forms form))
(let [f (. self.forms form)
(cexpr etype) (f self (table.unpack args))]
(values cexpr (or etype :word)))
nil (values [:block] :void)
_ (error (.. "Unrecognized expression"))))]
(if success (values c-expr etype)
(let [{: filename : line} (or self.expr-metadata {:filename "<unknown>" :line "??"})]
(error (.. filename "@" line ": " (fv expr) "\n" c-expr))))))
(fn Ssc.expr-word [self expr]
(let [(c etype) (self:expr-poly expr)]

View file

@ -7,11 +7,18 @@
; (form mymacro [(fn [ssc] (ssc:compile-expr [:+ 1 2]))])
; => [:form :mymacro (fn [ssc] (ssc:compile-expr [:+ 1 2]))]
(fn attach-metadata [form result]
(if (list? form)
(let [{: filename : line : bytestart : byteend} form]
`(setmetatable ,result ,{: filename : line : bytestart : byteend}))
result))
(fn form-to-fnl [form]
(if (sym? form) (tostring form)
(sequence? form) (. form 1) ; escape
(list? form) (icollect [_ inner-form (ipairs form)] (form-to-fnl inner-form))
form))
(attach-metadata form
(if (sym? form) (tostring form)
(sequence? form) (. form 1) ; escape
(list? form) (icollect [_ inner-form (ipairs form)] (form-to-fnl inner-form))
form)))
(fn sss [...]
(let [result `(values)]