aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--luxc/src/lux/analyser/env.clj16
-rw-r--r--luxc/src/lux/analyser/function.clj2
-rw-r--r--luxc/src/lux/analyser/lux.clj6
-rw-r--r--stdlib/source/lux.lux43
-rw-r--r--stdlib/source/lux/macro.lux23
5 files changed, 56 insertions, 34 deletions
diff --git a/luxc/src/lux/analyser/env.clj b/luxc/src/lux/analyser/env.clj
index 6f6e9f986..a6be49f98 100644
--- a/luxc/src/lux/analyser/env.clj
+++ b/luxc/src/lux/analyser/env.clj
@@ -1,7 +1,7 @@
(ns lux.analyser.env
(:require clojure.core.match
clojure.core.match.array
- (lux [base :as & :refer [|do return return* |case]])
+ (lux [base :as & :refer [|do return return* |case |let]])
[lux.analyser.base :as &&]))
;; [Exports]
@@ -17,7 +17,7 @@
(let [var-analysis (&&/|meta type &/empty-cursor (&&/$var (&/$Local (->> (&/|head stack) (&/get$ &/$locals) (&/get$ &/$counter)))))]
(&/$Cons (&/update$ &/$locals #(->> %
(&/update$ &/$counter inc)
- (&/update$ &/$mappings (fn [m] (&/|put name var-analysis m))))
+ (&/update$ &/$mappings (fn [m] (&/|put name (&/T [type var-analysis]) m))))
(&/|head stack))
(&/|tail stack))))
state))]
@@ -41,7 +41,10 @@
=return (body (&/update$ &/$scopes
(fn [stack]
(&/$Cons (&/update$ &/$locals #(->> %
- (&/update$ &/$mappings (fn [m] (&/|put name var-analysis m))))
+ (&/update$ &/$mappings (fn [m] (&/|put name
+ (&/T [(&&/expr-type* var-analysis)
+ var-analysis])
+ m))))
(&/|head stack))
(&/|tail stack)))
state))]
@@ -66,5 +69,10 @@
state)
(&/$Cons env _)
- (return* state (->> env (&/get$ &/$captured) (&/get$ &/$mappings))))
+ (return* state (->> env
+ (&/get$ &/$captured)
+ (&/get$ &/$mappings)
+ (&/|map (fn [mapping]
+ (|let [[k v] mapping]
+ (&/T [k (&/|second v)])))))))
))
diff --git a/luxc/src/lux/analyser/function.clj b/luxc/src/lux/analyser/function.clj
index 7d199ba30..68f5e89fe 100644
--- a/luxc/src/lux/analyser/function.clj
+++ b/luxc/src/lux/analyser/function.clj
@@ -24,5 +24,5 @@
register])))]
(&/T [register* (&/update$ &/$captured #(->> %
(&/update$ &/$counter inc)
- (&/update$ &/$mappings (fn [mps] (&/|put name register* mps))))
+ (&/update$ &/$mappings (fn [mps] (&/|put name (&/T [register-type register*]) mps))))
frame)])))
diff --git a/luxc/src/lux/analyser/lux.clj b/luxc/src/lux/analyser/lux.clj
index 6649628c7..95dc9af59 100644
--- a/luxc/src/lux/analyser/lux.clj
+++ b/luxc/src/lux/analyser/lux.clj
@@ -291,8 +291,8 @@
(|let [[register new-inner] register+new-inner
[register* frame*] (&&function/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$ &/$captured) (&/get$ &/$mappings) (&/|get name)))
+ (&/T [(&/|second (or (->> bottom-outer (&/get$ &/$locals) (&/get$ &/$mappings) (&/|get name))
+ (->> bottom-outer (&/get$ &/$captured) (&/get$ &/$mappings) (&/|get name))))
&/$Nil])
(&/|reverse inner) scopes)]
((|do [_ (&type/check exo-type (&&/expr-type* =local))]
@@ -538,7 +538,7 @@
module-name &/get-module-name
? (&&module/defined? module-name ?name)
_ (&/assert! (not ?)
- (&/fail-with-loc (str "[Analyser Error] Cannot re-define " (str module-name ";" ?name))))
+ (str "[Analyser Error] Cannot re-define " (str module-name ";" ?name)))
=value (&/without-repl-closure
(&/with-scope ?name
(&&/analyse-1+ analyse ?value)))
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux
index 1632e6eab..fe9958d56 100644
--- a/stdlib/source/lux.lux
+++ b/stdlib/source/lux.lux
@@ -351,11 +351,25 @@
(#Cons [["lux" "type-args"] (#ListA (#Cons (#TextA "m") (#Cons (#TextA "v") #;Nil)))]
default-def-meta-exported))))
+## (type: #export Ref
+## (#Local Nat)
+## (#Captured Nat))
+(_lux_def Ref
+ (#NamedT ["lux" "Ref"]
+ (#SumT ## Local
+ Nat
+ ## Captured
+ Nat))
+ (#Cons [["lux" "tags"] (#ListA (#Cons (#TextA "Local")
+ (#Cons (#TextA "Captured")
+ #Nil)))]
+ default-def-meta-exported))
+
## (type: Scope
## {#name (List Text)
## #inner Nat
-## #locals (Bindings Text Void)
-## #captured (Bindings Text Void)})
+## #locals (Bindings Text [Type Nat])
+## #captured (Bindings Text [Type Ref])})
(_lux_def Scope
(#NamedT ["lux" "Scope"]
(#ProdT ## name
@@ -363,9 +377,9 @@
(#ProdT ## inner
Nat
(#ProdT ## locals
- (#AppT (#AppT Bindings Text) Void)
+ (#AppT (#AppT Bindings Text) (#ProdT Type Nat))
## captured
- (#AppT (#AppT Bindings Text) Void)))))
+ (#AppT (#AppT Bindings Text) (#ProdT Type Ref))))))
(#Cons [["lux" "tags"] (#ListA (#Cons (#TextA "name")
(#Cons (#TextA "inner")
(#Cons (#TextA "locals")
@@ -4130,16 +4144,17 @@
(find (: (-> Scope (Maybe Type))
(function [env]
(case env
- {#name _ #inner _ #locals {#counter _ #mappings locals} #captured {#counter _ #mappings closure}}
- (try-both (find (: (-> [Text Void] (Maybe Type))
- (function [[bname analysis]]
- (let [[[type _] _] (:! (Meta [Type Cursor] Void)
- analysis)]
- (if (Text/= name bname)
- (#Some type)
- #None)))))
- locals
- closure))))
+ {#name _
+ #inner _
+ #locals {#counter _ #mappings locals}
+ #captured {#counter _ #mappings closure}}
+ (try-both (find (: (-> [Text [Type Top]] (Maybe Type))
+ (function [[bname [type _]]]
+ (if (Text/= name bname)
+ (#Some type)
+ #None))))
+ (: (List [Text [Type Top]]) locals)
+ (: (List [Text [Type Top]]) closure)))))
scopes)))
(def: (find-def-type name state)
diff --git a/stdlib/source/lux/macro.lux b/stdlib/source/lux/macro.lux
index 77902ba1a..9965a0677 100644
--- a/stdlib/source/lux/macro.lux
+++ b/stdlib/source/lux/macro.lux
@@ -424,20 +424,20 @@
{#;doc "Looks-up the type of a local variable somewhere in the environment."}
(-> Text (Lux Type))
(function [state]
- (let [test (: (-> [Text (Meta [Type Cursor] Void)] Bool)
+ (let [test (: (-> [Text [Type Top]] Bool)
(|>. product;left (Text/= name)))]
(case (do Monad<Maybe>
[scope (find (function [env]
- (or (any? test (:! (List [Text (Meta [Type Cursor] Void)])
- (get@ [#;locals #;mappings] env)))
- (any? test (:! (List [Text (Meta [Type Cursor] Void)])
- (get@ [#;captured #;mappings] env)))))
+ (or (any? test (: (List [Text [Type Top]])
+ (get@ [#;locals #;mappings] env)))
+ (any? test (: (List [Text [Type Top]])
+ (get@ [#;captured #;mappings] env)))))
(get@ #;scopes state))
- [_ [[type _] _]] (try-both (find test)
- (:! (List [Text (Meta [Type Cursor] Void)])
- (get@ [#;locals #;mappings] scope))
- (:! (List [Text (Meta [Type Cursor] Void)])
- (get@ [#;captured #;mappings] scope)))]
+ [_ [type _]] (try-both (find test)
+ (: (List [Text [Type Top]])
+ (get@ [#;locals #;mappings] scope))
+ (: (List [Text [Type Top]])
+ (get@ [#;captured #;mappings] scope)))]
(wrap type))
(#;Some var-type)
(#;Right [state var-type])
@@ -590,8 +590,7 @@
(#;Some scopes)
(#;Right [state
(List/map (|>. (get@ [#;locals #;mappings])
- (:! (List [Text (Meta [Type Cursor] Void)]))
- (List/map (function [[name [[type cursor] analysis]]]
+ (List/map (function [[name [type _]]]
[name type])))
scopes)]))))