1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

Support looking up missing symbols during compilation

This commit is contained in:
Michael Camilleri 2022-01-21 13:07:11 +09:00
parent 2f3b4c8bfb
commit 1eb34989d4
No known key found for this signature in database
GPG Key ID: 7EB218A48DF8B572
3 changed files with 23 additions and 2 deletions

View File

@ -2746,6 +2746,8 @@
(and as (string as "/"))
prefix
(string (last (string/split "/" path)) "/")))
(unless (zero? (length prefix))
(put-in env [:modules prefix] newenv))
(merge-module env newenv prefix ep))
(defmacro import

View File

@ -607,8 +607,14 @@ JanetBinding janet_resolve_ext(JanetTable *env, const uint8_t *sym) {
};
/* Check environment for entry */
if (!janet_checktype(entry, JANET_TABLE))
return binding;
if (!janet_checktype(entry, JANET_TABLE)) {
Janet fn_entry = janet_table_get(env, janet_ckeywordv("missing-symbol"));
if (janet_checktype(fn_entry, JANET_FUNCTION)) {
Janet args[2] = { janet_wrap_symbol(sym), janet_wrap_table(env) };
entry = janet_call(janet_unwrap_function(fn_entry), 2, args);
}
if (!janet_checktype(entry, JANET_TABLE)) return binding;
}
entry_table = janet_unwrap_table(entry);
/* deprecation check */

View File

@ -26,5 +26,18 @@
(assert (< 11899423.08 (math/gamma 11.5) 11899423.085) "math/gamma")
(assert (< 2605.1158 (math/log-gamma 500) 2605.1159) "math/log-gamma")
# missing symbols
(def replacement 10)
(defn lookup-symbol [sym env] (dyn 'replacement))
(setdyn :missing-symbol lookup-symbol)
(assert (= (eval-string "(+ a 5)") 15) "lookup missing symbol")
(setdyn :missing-symbol nil)
(assert-error "compile error" (eval-string "(+ a 5)"))
(end-suite)