fix tests }:)
This commit is contained in:
1 parent
0b74b088fd
commit
2f6160f178
2 files changed
+40
-13
No files matched your search
+34
-10
@@ -233,7 +233,6 @@
|
||||
scopes)))
|
||||
|
||||
(defn lookup [variable env symtable]
|
||||
(tap> [variable env symtable])
|
||||
(let [[sym scopes] (or (destructure-variable variable)
|
||||
(throw (ex-info "not a var" {:var variable})))
|
||||
ss (symtable-scopes symtable sym)]
|
||||
@@ -256,8 +255,8 @@
|
||||
prim-name))
|
||||
|
||||
(defn new-scope
|
||||
([] (gensym))
|
||||
([prefix] (gensym prefix)))
|
||||
([] (gensym "scope__"))
|
||||
([prefix] (gensym (str "scope__" prefix))))
|
||||
|
||||
(defn bind-lexical [[sym scopes] denot symtable-ref]
|
||||
(let [bind [:lexical sym (gensym)]]
|
||||
@@ -447,7 +446,6 @@
|
||||
(expand
|
||||
datum scheme-base-env (atom (symtable-for-env scheme-base-env)) #{}))
|
||||
([datum env symtable-ref scopes]
|
||||
(tap> datum)
|
||||
(match datum
|
||||
;; literals
|
||||
(x :guard literal?) x
|
||||
@@ -459,11 +457,37 @@
|
||||
|
||||
;; lists
|
||||
([f & xs] :seq)
|
||||
(if (variable? f)
|
||||
(do (tap> f)
|
||||
(match (lookup (offer-scopes f scopes) env @symtable-ref)
|
||||
(or (when-some [v (and (variable? f)
|
||||
(offer-scopes f scopes))]
|
||||
(match (lookup v env @symtable-ref)
|
||||
[:primitive prim] (expand-primitive
|
||||
datum prim env symtable-ref scopes)
|
||||
[:macro trans] (expand-macro trans datum env symtable-ref scopes)))
|
||||
(cons (expand f env symtable-ref scopes)
|
||||
(map #(expand % env symtable-ref scopes) xs))))))
|
||||
[:macro trans] (expand-macro trans datum env symtable-ref scopes)
|
||||
[:var] nil))
|
||||
(cons (expand f env symtable-ref scopes)
|
||||
(map #(expand % env symtable-ref scopes) xs))))))
|
||||
|
||||
|
||||
|
||||
(defn beautify
|
||||
"Renumber the gensyms created by `new-scope` found in datum,
|
||||
starting from zero."
|
||||
[datum]
|
||||
(let [c (atom 0)]
|
||||
(walk/postwalk (fn [x]
|
||||
(if (and (symbol? x)
|
||||
(clojure.string/starts-with?
|
||||
(name x)
|
||||
"scope__"))
|
||||
(symbol (str "s" (first (swap-vals! c inc))))
|
||||
x))
|
||||
datum)))
|
||||
|
||||
(defn unscope
|
||||
"Remove all scopes from the variables found in datum."
|
||||
[datum]
|
||||
(walk/postwalk (fn [x]
|
||||
(if (instance? Variable x)
|
||||
(variable-symbol x)
|
||||
x))
|
||||
datum))
|
||||
Reference in new issue
Block a user