diff --git a/ssc/iigs/toolbox.fnl b/ssc/iigs/toolbox.fnl index 45fdf21..dc812d3 100644 --- a/ssc/iigs/toolbox.fnl +++ b/ssc/iigs/toolbox.fnl @@ -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) diff --git a/ssc/init.fnl b/ssc/init.fnl index 478e48b..927af61 100644 --- a/ssc/init.fnl +++ b/ssc/init.fnl @@ -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 "" :line "??"})] + (error (.. filename "@" line ": " (fv expr) "\n" c-expr)))))) (fn Ssc.expr-word [self expr] (let [(c etype) (self:expr-poly expr)] diff --git a/ssc/macros.fnl b/ssc/macros.fnl index b87c41d..880bb4e 100644 --- a/ssc/macros.fnl +++ b/ssc/macros.fnl @@ -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)]