~technomancy/fennel

8929644595e2c0dfaf62a03edf60a8f1d5639779 — equa 3 days ago 1a46947 main
Fix correlation being broken with macros

Before, a program like (when true 4) would input sixty-odd lines of
space when compiled with --correlate. This is because the invocation
of the when macro caused the AST to include a node with a line number
of the code *in macro.fnl*. The compiler already checked for the file
name of the syntax tree and the currently-compiled file being equal,
but both checks were broken and always returned nil (without an error),
so the correlation always happened.

This patch might break something, since it messes with some code that
has been silently failing for a bit.
1 files changed, 5 insertions(+), 5 deletions(-)

M src/fennel/compiler.fnl
M src/fennel/compiler.fnl => src/fennel/compiler.fnl +5 -5
@@ 70,7 70,7 @@ The ast arg should be unmodified so that its first element is the form called."
(fn serialize-string [str]
  (-> (string.format "%q" str)
      (string.gsub "." serialize-subst)
      (string.gsub "[�-�]" #(.. "\\" ($:byte)))))
      (string.gsub "[\x80-\xff]" #(.. "\\" ($:byte)))))

(fn global-mangling [str]
  "Mangler for global symbols. Does not protect against collisions,


@@ 244,7 244,7 @@ store it on the metatable instead."
  (let [m (getmetatable ast)]
    (or (and m m.line m) (and (= :table (type ast)) ast) {})))

(fn flatten-chunk-correlated [main-chunk]
(fn flatten-chunk-correlated [main-chunk options]
  "Correlate line numbers in input with line numbers in output."
  (fn flatten [chunk out last-line file]
    (var last-line last-line)


@@ 254,13 254,13 @@ store it on the metatable instead."
          (when (or subchunk.leaf (> (length subchunk) 0)) ; ignore empty chunks
            ;; don't increase line unless it's from the same file
            (let [source (ast-source subchunk.ast)]
              (when (= file source.file)
              (when (= file source.filename)
                (set last-line (math.max last-line (or source.line 0))))
              (set last-line (flatten subchunk out last-line file))))))
    last-line)

  (let [out []
        last (flatten main-chunk out 1 main-chunk.file)]
        last (flatten main-chunk out 1 options.filename)]
    (for [i 1 last]
      (when (= (. out i) nil)
        (tset out i "")))


@@ 306,7 306,7 @@ Tab is what is used to indent a block."
  "Return Lua source and source map table."
  (let [chunk (peephole chunk)]
    (if options.correlate
        (values (flatten-chunk-correlated chunk) [])
        (values (flatten-chunk-correlated chunk options) [])
        (let [sm []
              ret (flatten-chunk sm chunk options.indent 0)]
          (when sm