From dd7e449fa54e2aeed1c913afc46522a1f18d7fac Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Sun, 11 Aug 2024 20:02:35 +1000 Subject: [PATCH] fix: add `./fnl/...;` dirs to fennel.path and fennel.macro-path for AOT 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. --- fnl/hotpot/lang/fennel/compiler.fnl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fnl/hotpot/lang/fennel/compiler.fnl b/fnl/hotpot/lang/fennel/compiler.fnl index 57e80d80..4cd65788 100644 --- a/fnl/hotpot/lang/fennel/compiler.fnl +++ b/fnl/hotpot/lang/fennel/compiler.fnl @@ -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) @@ -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, @@ -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) {})]