From 94cca1d49c0d3f6d328a81eaf6ce9660a6f149c1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 1 May 2017 00:07:09 -0400 Subject: - Changed the way Scope works, to make it independent from the notion of Analysis, and make it easier to port to the new re-written compiler. - Fixed a type-bug when asserting whether a def is being re-defined. --- luxc/src/lux/analyser/env.clj | 16 ++++++++++++---- luxc/src/lux/analyser/function.clj | 2 +- luxc/src/lux/analyser/lux.clj | 6 +++--- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'luxc/src') 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))) -- cgit v1.2.3