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:
parent
ec65f038a8
commit
ea9d5ec793
@ -1952,7 +1952,7 @@
|
|||||||
(def h (in t 0))
|
(def h (in t 0))
|
||||||
(def s (in specs h))
|
(def s (in specs h))
|
||||||
(def entry (or (dyn 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))
|
(def m? (entry :macro))
|
||||||
(cond
|
(cond
|
||||||
s (s t)
|
s (s t)
|
||||||
@ -3080,12 +3080,13 @@
|
|||||||
(x :ref) (string :var " (" (type (in (x :ref) 0)) ")")
|
(x :ref) (string :var " (" (type (in (x :ref) 0)) ")")
|
||||||
(x :macro) :macro
|
(x :macro) :macro
|
||||||
(x :module) (string :module " (" (x :kind) ")")
|
(x :module) (string :module " (" (x :kind) ")")
|
||||||
|
(x :redef) (type (in (x :value) 0))
|
||||||
(type (x :value)))
|
(type (x :value)))
|
||||||
"\n"))
|
"\n"))
|
||||||
(def sm (x :source-map))
|
(def sm (x :source-map))
|
||||||
(def d (x :doc))
|
(def d (x :doc))
|
||||||
(print "\n\n"
|
(print "\n\n"
|
||||||
(when d bind-type)
|
bind-type
|
||||||
(when-let [[path line col] sm]
|
(when-let [[path line col] sm]
|
||||||
(string " " path (when (and line col) (string " on line " line ", column " col))))
|
(string " " path (when (and line col) (string " on line " line ", column " col))))
|
||||||
(when sm "\n")
|
(when sm "\n")
|
||||||
@ -3143,7 +3144,7 @@
|
|||||||
(loop [module-set :in [[root-env] module/cache]
|
(loop [module-set :in [[root-env] module/cache]
|
||||||
module :in module-set
|
module :in module-set
|
||||||
value :in module]
|
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)
|
(when (= check x)
|
||||||
(print-module-entry value)
|
(print-module-entry value)
|
||||||
(set found true)
|
(set found true)
|
||||||
@ -3536,7 +3537,8 @@
|
|||||||
|
|
||||||
(defn- run-main
|
(defn- run-main
|
||||||
[env subargs arg]
|
[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)]
|
(let [thunk (compile [main ;subargs] env arg)]
|
||||||
(if (function? thunk) (thunk) (error (thunk :error))))))
|
(if (function? thunk) (thunk) (error (thunk :error))))))
|
||||||
|
|
||||||
@ -3581,7 +3583,7 @@
|
|||||||
-e code : Execute a string of janet
|
-e code : Execute a string of janet
|
||||||
-E code arguments... : Evaluate an expression as a short-fn with arguments
|
-E code arguments... : Evaluate an expression as a short-fn with arguments
|
||||||
-d : Set the debug flag in the REPL
|
-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 : Enter the REPL after running all scripts
|
||||||
-R : Disables loading profile.janet when JANET_PROFILE is present
|
-R : Disables loading profile.janet when JANET_PROFILE is present
|
||||||
-p : Keep on executing if there is a top-level error (persistent)
|
-p : Keep on executing if there is a top-level error (persistent)
|
||||||
@ -3632,7 +3634,7 @@
|
|||||||
(error (get thunk :error)))
|
(error (get thunk :error)))
|
||||||
math/inf)
|
math/inf)
|
||||||
"d" (fn [&] (set debug-flag true) 1)
|
"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)
|
"w" (fn [i &] (set warn-level (get-lint-level i)) 2)
|
||||||
"x" (fn [i &] (set error-level (get-lint-level i)) 2)
|
"x" (fn [i &] (set error-level (get-lint-level i)) 2)
|
||||||
"R" (fn [&] (setdyn :profilepath nil) 1)})
|
"R" (fn [&] (setdyn :profilepath nil) 1)})
|
||||||
|
@ -331,11 +331,17 @@ static int defleaf(
|
|||||||
JanetTable *entry = janet_table_clone(tab);
|
JanetTable *entry = janet_table_clone(tab);
|
||||||
janet_table_put(entry, janet_ckeywordv("source-map"),
|
janet_table_put(entry, janet_ckeywordv("source-map"),
|
||||||
janet_wrap_tuple(janetc_make_sourcemap(c)));
|
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);
|
JanetBinding binding = janet_resolve_ext(c->env, sym);
|
||||||
JanetArray *ref;
|
JanetArray *ref;
|
||||||
if (janet_checktype(binding.value, JANET_ARRAY)) {
|
if (janet_checktype(binding.value, JANET_ARRAY)) {
|
||||||
|
@ -628,7 +628,7 @@ JanetBinding janet_resolve_ext(JanetTable *env, const uint8_t *sym) {
|
|||||||
binding.deprecation = JANET_BINDING_DEP_NORMAL;
|
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(
|
if (!janet_checktype(
|
||||||
janet_table_get(entry_table, janet_ckeywordv("macro")),
|
janet_table_get(entry_table, janet_ckeywordv("macro")),
|
||||||
|
@ -297,23 +297,28 @@
|
|||||||
|
|
||||||
# Dynamic defs
|
# Dynamic defs
|
||||||
|
|
||||||
(def staticdef 0)
|
(def staticdef1 0)
|
||||||
(defn staticdef-inc [] (+ 1 staticdef))
|
(defn staticdef1-inc [] (+ 1 staticdef1))
|
||||||
(assert (= 1 (staticdef-inc)) "result before redefinition without :dynamic")
|
(assert (= 1 (staticdef1-inc)) "before redefinition without :redef")
|
||||||
(def staticdef 1)
|
(def staticdef1 1)
|
||||||
(assert (= 1 (staticdef-inc)) "result after redefinition without :dynamic")
|
(assert (= 1 (staticdef1-inc)) "after redefinition without :redef")
|
||||||
(def dynamicdef :dynamic 0)
|
(def dynamicdef1 :redef 0)
|
||||||
(defn dynamicdef-inc [] (+ 1 dynamicdef))
|
(defn dynamicdef1-inc [] (+ 1 dynamicdef1))
|
||||||
(assert (= 1 (dynamicdef-inc)) "result before redefinition with :dynamic")
|
(assert (= 1 (dynamicdef1-inc)) "before redefinition with :redef")
|
||||||
(def dynamicdef :dynamic 1)
|
(def dynamicdef1 :redef 1)
|
||||||
(assert (= 2 (dynamicdef-inc)) "result after redefinition with :dynamic")
|
(assert (= 2 (dynamicdef1-inc)) "after redefinition with :redef")
|
||||||
(setdyn :dynamic-defs true)
|
(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)
|
(def dynamicdef2 0)
|
||||||
(defn dynamicdef2-inc [] (+ 1 dynamicdef2))
|
(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)
|
(def dynamicdef2 1)
|
||||||
(assert (= 2 (dynamicdef2-inc)) "result after redefinition with :dynamic-defs")
|
(assert (= 2 (dynamicdef2-inc)) "after redefinition with dyn :redefs")
|
||||||
(setdyn :dynamic-defs nil)
|
(setdyn :redefs nil)
|
||||||
|
|
||||||
# Denormal tables and structs
|
# Denormal tables and structs
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user