1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 19:19:53 +00:00

Change metadata keyword back to :redef

This commit is contained in:
Michael Camilleri 2022-01-02 12:35:22 +09:00
parent ec65f038a8
commit ea9d5ec793
No known key found for this signature in database
GPG Key ID: 7EB218A48DF8B572
4 changed files with 37 additions and 24 deletions

View File

@ -1952,7 +1952,7 @@
(def h (in t 0))
(def s (in specs h))
(def entry (or (dyn h) {}))
(def m (entry :value))
(def m (if (entry :redef) (in (entry :value) 0) (entry :value)))
(def m? (entry :macro))
(cond
s (s t)
@ -3080,12 +3080,13 @@
(x :ref) (string :var " (" (type (in (x :ref) 0)) ")")
(x :macro) :macro
(x :module) (string :module " (" (x :kind) ")")
(x :redef) (type (in (x :value) 0))
(type (x :value)))
"\n"))
(def sm (x :source-map))
(def d (x :doc))
(print "\n\n"
(when d bind-type)
bind-type
(when-let [[path line col] sm]
(string " " path (when (and line col) (string " on line " line ", column " col))))
(when sm "\n")
@ -3143,7 +3144,7 @@
(loop [module-set :in [[root-env] module/cache]
module :in module-set
value :in module]
(let [check (or (get value :ref) (get value :value))]
(let [check (or (value :ref) (if (value :redef) (in (value :value) 0) (value :value)))]
(when (= check x)
(print-module-entry value)
(set found true)
@ -3536,7 +3537,8 @@
(defn- run-main
[env subargs arg]
(if-let [main (get (in env 'main) :value)]
(if-let [entry (in env 'main)
main (if (entry :redef) (in (entry :value) 0) (entry :value))]
(let [thunk (compile [main ;subargs] env arg)]
(if (function? thunk) (thunk) (error (thunk :error))))))
@ -3581,7 +3583,7 @@
-e code : Execute a string of janet
-E code arguments... : Evaluate an expression as a short-fn with arguments
-d : Set the debug flag in the REPL
-D : Use dynamic def bindings
-D : Use redefinable def bindings
-r : Enter the REPL after running all scripts
-R : Disables loading profile.janet when JANET_PROFILE is present
-p : Keep on executing if there is a top-level error (persistent)
@ -3632,7 +3634,7 @@
(error (get thunk :error)))
math/inf)
"d" (fn [&] (set debug-flag true) 1)
"D" (fn [&] (setdyn :dynamic-defs true) 1)
"D" (fn [&] (setdyn :redefs true) 1)
"w" (fn [i &] (set warn-level (get-lint-level i)) 2)
"x" (fn [i &] (set error-level (get-lint-level i)) 2)
"R" (fn [&] (setdyn :profilepath nil) 1)})

View File

@ -331,11 +331,17 @@ static int defleaf(
JanetTable *entry = janet_table_clone(tab);
janet_table_put(entry, janet_ckeywordv("source-map"),
janet_wrap_tuple(janetc_make_sourcemap(c)));
if (janet_truthy(janet_dyn("dynamic-defs"))) {
janet_table_put(entry, janet_ckeywordv("dynamic"), janet_wrap_true());
int is_redef = 0;
Janet meta_redef = janet_table_get(entry, janet_ckeywordv("redef"));
if (janet_truthy(meta_redef)) {
is_redef = 1;
} else if (janet_checktype(meta_redef, JANET_NIL) && janet_truthy(janet_dyn("redefs"))) {
janet_table_put(entry, janet_ckeywordv("redef"), janet_wrap_true());
is_redef = 1;
}
if (!janet_checktype(janet_table_get(entry, janet_ckeywordv("dynamic")), JANET_NIL)) {
if (is_redef) {
JanetBinding binding = janet_resolve_ext(c->env, sym);
JanetArray *ref;
if (janet_checktype(binding.value, JANET_ARRAY)) {

View File

@ -628,7 +628,7 @@ JanetBinding janet_resolve_ext(JanetTable *env, const uint8_t *sym) {
binding.deprecation = JANET_BINDING_DEP_NORMAL;
}
binding.dynamic = !janet_checktype(janet_table_get(entry_table, janet_ckeywordv("dynamic")), JANET_NIL);
binding.dynamic = janet_truthy(janet_table_get(entry_table, janet_ckeywordv("redef")));
if (!janet_checktype(
janet_table_get(entry_table, janet_ckeywordv("macro")),

View File

@ -297,23 +297,28 @@
# Dynamic defs
(def staticdef 0)
(defn staticdef-inc [] (+ 1 staticdef))
(assert (= 1 (staticdef-inc)) "result before redefinition without :dynamic")
(def staticdef 1)
(assert (= 1 (staticdef-inc)) "result after redefinition without :dynamic")
(def dynamicdef :dynamic 0)
(defn dynamicdef-inc [] (+ 1 dynamicdef))
(assert (= 1 (dynamicdef-inc)) "result before redefinition with :dynamic")
(def dynamicdef :dynamic 1)
(assert (= 2 (dynamicdef-inc)) "result after redefinition with :dynamic")
(setdyn :dynamic-defs true)
(def staticdef1 0)
(defn staticdef1-inc [] (+ 1 staticdef1))
(assert (= 1 (staticdef1-inc)) "before redefinition without :redef")
(def staticdef1 1)
(assert (= 1 (staticdef1-inc)) "after redefinition without :redef")
(def dynamicdef1 :redef 0)
(defn dynamicdef1-inc [] (+ 1 dynamicdef1))
(assert (= 1 (dynamicdef1-inc)) "before redefinition with :redef")
(def dynamicdef1 :redef 1)
(assert (= 2 (dynamicdef1-inc)) "after redefinition with :redef")
(setdyn :redefs true)
(def staticdef2 {:redef false} 0)
(defn staticdef2-inc [] (+ 1 staticdef2))
(assert (= 1 (staticdef2-inc)) "before redefinition with :redef false")
(def staticdef2 {:redef false} 1)
(assert (= 1 (staticdef2-inc)) "after redefinition with :redef false")
(def dynamicdef2 0)
(defn dynamicdef2-inc [] (+ 1 dynamicdef2))
(assert (= 1 (dynamicdef2-inc)) "result before redefinition with :dynamic-defs")
(assert (= 1 (dynamicdef2-inc)) "before redefinition with dyn :redefs")
(def dynamicdef2 1)
(assert (= 2 (dynamicdef2-inc)) "result after redefinition with :dynamic-defs")
(setdyn :dynamic-defs nil)
(assert (= 2 (dynamicdef2-inc)) "after redefinition with dyn :redefs")
(setdyn :redefs nil)
# Denormal tables and structs