Skip to content

Commit

Permalink
fix: add ./fnl/...; dirs to fennel.path and fennel.macro-path for AOT
Browse files Browse the repository at this point in the history
By default fennel only includes the current dir in its search paths, but
we often have our cwd one step above. This means macros and any include
calls would fail to find the correct files when compiling.

Now we insert `./fnl/?.fnl` etc into the search paths before compiling.

This does not effect JIT compilation, but does effect AOT.
  • Loading branch information
rktjmp committed Aug 11, 2024
1 parent 5282941 commit dd7e449
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions fnl/hotpot/lang/fennel/compiler.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@

(λ compile-string [source modules-options macros-options ?preprocessor]
"Compile given string of fennel into lua, returns `true lua` or `false error`"
;; (string table) :: (true string) | (false string)
(let [fennel (require :hotpot.fennel)
;; By default fennels path does not include a "fnl" dir, but in most
;; cases we want to search this for macros and other files for (include).
saved-fennel-path fennel.path
saved-fennel-macro-path fennel.macro-path
_ (set fennel.path (.. "./fnl/?.fnl;./fnl/?/init.fnl;" fennel.path))
_ (set fennel.macro-path (.. "./fnl/?.fnl;./fnl/?/init-macros.fnl;./fnl/?/init.fnl;" fennel.macro-path))
{: traceback} (require :hotpot.runtime)
options (doto modules-options
(tset :error-pinpoint false)
Expand All @@ -93,7 +98,9 @@
:macros macros-options
:preprocessor preprocessor})
(local (ok? val) (xpcall #(pick-values 1 (fennel.compile-string source options))
traceback))
traceback))
(set fennel.path saved-fennel-path)
(set fennel.macro-path saved-fennel-macro-path)
(table.remove compiler-options-stack 1)
;; We have to manually nil these out so they dont hang around.
;; We currently dont deep_extend these option tables because they may contain _G,
Expand All @@ -105,7 +112,6 @@

(λ compile-file [fnl-path lua-path modules-options macros-options ?preprocessor]
"Compile fennel code from `fnl-path` and save to `lua-path`"
;; (string, string) :: (true, nil) | (false, errors)
(fn check-existing [path]
(let [uv vim.loop
{: type} (or (uv.fs_stat path) {})]
Expand Down

0 comments on commit dd7e449

Please sign in to comment.