From: equa <equaa@protonmail.com>
This allows for proper line numbering when expanding macros, for
example, whereas previously tracebacks would produce the line number
of the macro source but the file name of the invocation.
Thanks! This is a really old chunk of code from the compiler that I
have never taken the opportunity to examine thoroughly. It sounds like
the problem was that previously the sourcemap assumed every AST in a
given chunk came from the same file, which was only true back before we
had a macro system.
Looks like this does the job! Thanks for taking the time to dig in.
-Phil
---
src/fennel/compiler.fnl | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/fennel/compiler.fnl b/src/fennel/compiler.fnl
index 09be556..4f66edb 100644
--- a/src/fennel/compiler.fnl+++ b/src/fennel/compiler.fnl
@@ -260,7 +260,10 @@ Tab is what is used to indent a block."
(let [code chunk.leaf
info chunk.ast]
(when sm
- (table.insert sm (or (and info info.line) (- 1))))+ (table.insert+ sm+ [(and info info.filename)+ (and info info.line)])) code)
(let [tab (match tab
true " " false "" tab tab nil "")]
@@ -293,8 +296,8 @@ Tab is what is used to indent a block."
(let [sm []
ret (flatten-chunk sm chunk options.indent 0)]
(when sm
- (set sm.short_src (make-short-src (or options.filename- options.source ret)))+ (set sm.short_src (or options.filename+ (make-short-src (or options.source ret)))) (set sm.key (if options.filename (.. "@" options.filename) ret))
(tset fennel-sourcemap sm.key sm))
(values ret sm)))))
@@ -777,16 +780,18 @@ which we have to do if we don't know."
(let [remap (. fennel-sourcemap info.source)]
(when (and remap (. remap info.currentline))
;; And some global info
- (set info.short-src remap.short-src)+ (set info.short_src+ (if (. remap info.currentline 1)+ (. fennel-sourcemap (.. "@" (. remap info.currentline 1))+ :short_src)+ remap.short_src)) ;; Overwrite info with values from the mapping
- ;; (mapping is now just integer, but may- ;; eventually be a table)- (set info.currentline (. remap info.currentline)))+ (set info.currentline (or (. remap info.currentline 2) -1))) (if (= info.what "Lua")
(string.format " %s:%d: in function %s"
info.short_src info.currentline
(if info.name (.. "'" info.name "'") "?"))
- (= info.short-src "(tail call)")+ (= info.short_src "(tail call)") " (tail call)"
(string.format " %s:%d: in main chunk"
info.short_src info.currentline)))))
--
2.26.2