aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Julian2016-07-30 18:37:45 -0400
committerEduardo Julian2016-07-30 18:37:45 -0400
commit256faabe7dd8ac26ed86c5868af4d417c441cdc1 (patch)
tree599687897fa8d36b5d08fc778ce113b3bd846650 /src
parent196fe38526fef3516be5fac9501cdabeeee19eef (diff)
- Now storing the name of each scope as a list/stack of name-fragments, to eliminate the need to keep an explicit cache for it.
Diffstat (limited to 'src')
-rw-r--r--src/lux/analyser/lux.clj6
-rw-r--r--src/lux/analyser/module.clj4
-rw-r--r--src/lux/base.clj20
-rw-r--r--src/lux/compiler/lux.clj2
4 files changed, 11 insertions, 21 deletions
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index b78908922..6877788db 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -293,12 +293,10 @@
(fail* (str "[Analyser Error] Unknown global definition: " name)))
(&/$Cons bottom-outer _)
- (|let [scopes (&/|tail (&/folds #(&/$Cons (&/get$ &/$name %2) %1)
- (&/|map #(&/get$ &/$name %) outer)
- (&/|reverse inner)))
+ (|let [scopes (&/|map #(&/get$ &/$name %) (&/|reverse inner))
[=local inner*] (&/fold2 (fn [register+new-inner frame in-scope]
(|let [[register new-inner] register+new-inner
- [register* frame*] (&&lambda/close-over (&/get-cached-scope-name in-scope) name register frame)]
+ [register* frame*] (&&lambda/close-over in-scope name register frame)]
(&/T [register* (&/$Cons frame* new-inner)])))
(&/T [(or (->> bottom-outer (&/get$ &/$locals) (&/get$ &/$mappings) (&/|get name))
(->> bottom-outer (&/get$ &/$closure) (&/get$ &/$mappings) (&/|get name)))
diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj
index dac7a3870..f35334399 100644
--- a/src/lux/analyser/module.clj
+++ b/src/lux/analyser/module.clj
@@ -205,7 +205,7 @@
(fn [state]
(return* (->> state
(&/update$ &/$modules #(&/|put name (new-module hash) %))
- (&/set$ &/$envs (&/|list (&/env name))))
+ (&/set$ &/$envs (&/|list (&/env name &/$Nil))))
nil)))
(do-template [<name> <tag> <type>]
@@ -218,7 +218,7 @@
state))
))
- tags-by-module $tags "(-> Text (Lux (List (, Text (, Int (List Text) Type)))))"
+ tags-by-module $tags "(-> Text (Lux (List (, Text (, Int (List Text) Type)))))"
types-by-module $types "(-> Text (Lux (List (, Text (, (List Text) Type)))))"
module-hash $module-hash "(-> Text (Lux Int))"
)
diff --git a/src/lux/base.clj b/src/lux/base.clj
index 0d9fcebe8..32b8c661e 100644
--- a/src/lux/base.clj
+++ b/src/lux/base.clj
@@ -710,9 +710,9 @@
;; "lux;mappings"
(|table)]))
-(defn env [name]
+(defn env [name old-name]
(T [;; "lux;name"
- name
+ ($Cons name old-name)
;; "lux;inner-closures"
0
;; "lux;locals"
@@ -878,7 +878,7 @@
((fail-with-loc "[Analyser Error] Can't get the module-name without a module.") state)
($Cons ?global _)
- (return* state (get$ $name ?global)))))
+ (return* state (|head (get$ $name ?global))))))
(defn find-module [name]
"(-> Text (Lux (Module Compiler)))"
@@ -894,7 +894,8 @@
(defn with-scope [name body]
(fn [state]
- (let [output (body (update$ $envs #($Cons (env name) %) state))]
+ (let [old-name (->> state (get$ $envs) |head (get$ $name))
+ output (body (update$ $envs #($Cons (env name old-name) %) state))]
(|case output
($Right state* datum)
(return* (update$ $envs |tail state*) datum)
@@ -914,18 +915,9 @@
(|tail %))
state))))))
-(let [cache (atom {})]
- (defn get-cached-scope-name [raw]
- (let [signature (fold (fn [tail head] (str head "\t" tail))
- ""
- raw)]
- (or (get @cache signature)
- (do (swap! cache assoc signature raw)
- raw)))))
-
(def get-scope-name
(fn [state]
- (return* state (get-cached-scope-name (->> state (get$ $envs) (|map #(get$ $name %)))))))
+ (return* state (->> state (get$ $envs) |head (get$ $name)))))
(defn with-writer [writer body]
(fn [state]
diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj
index e3cf37584..002bcc503 100644
--- a/src/lux/compiler/lux.clj
+++ b/src/lux/compiler/lux.clj
@@ -235,7 +235,7 @@
_
(|case (de-ann ?body)
[_ (&o/$function _ __scope _ _)]
- (|let [[_ (&o/$function _arity _scope _captured ?body+)] (&o/shift-function-body (&/get-cached-scope-name (&/|tail __scope)) __scope
+ (|let [[_ (&o/$function _arity _scope _captured ?body+)] (&o/shift-function-body (&/|tail __scope) __scope
false
(de-ann ?body))]
(|do [:let [=value-type (&a/expr-type* ?body)]