mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Support looking up missing symbols during compilation
This commit is contained in:
parent
2f3b4c8bfb
commit
1eb34989d4
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user