From 077e8286b1168909d702ae0c28a0d2941c956f15 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 4 Dec 2017 19:46:36 -0400 Subject: - No longer deleting type-vars in luxc, to better match it with the type-checking in new-luxc. - Fixed some minor bugs and inconsistencies. --- luxc/src/lux/analyser/lux.clj | 11 ++--------- luxc/src/lux/compiler/cache.clj | 2 +- luxc/src/lux/type.clj | 44 ++++------------------------------------- 3 files changed, 7 insertions(+), 50 deletions(-) (limited to 'luxc/src') diff --git a/luxc/src/lux/analyser/lux.clj b/luxc/src/lux/analyser/lux.clj index 07cf17d2f..18941a0e3 100644 --- a/luxc/src/lux/analyser/lux.clj +++ b/luxc/src/lux/analyser/lux.clj @@ -428,8 +428,7 @@ (&/fold% (fn [_func _inf-var] (|do [:let [$inf-var (&/$Var _inf-var)] =inf-var (&type/resolve-type $inf-var) - _func* (clean-func-inference $inf-var $output =inf-var _func) - _ (&type/delete-var _inf-var)] + _func* (clean-func-inference $inf-var $output =inf-var _func)] (return _func*))) =func (unravel-inf-appt =input)) @@ -438,8 +437,7 @@ (&/fold% (fn [_func _inf-var] (|do [:let [$inf-var (&/$Var _inf-var)] =inf-var (&type/resolve-type $inf-var) - _func* (clean-func-inference $inf-var $output =inf-var _func) - _ (&type/delete-var _inf-var)] + _func* (clean-func-inference $inf-var $output =inf-var _func)] (return _func*))) =func (&/|reverse (&type/flatten-prod =input))) @@ -545,11 +543,6 @@ _ (&&module/test-type module-name ?name ==meta (&&/expr-type* =value)) _ (&&module/test-macro module-name ?name ==meta (&&/expr-type* =value)) _ (compile-def ?name (optimize =value) ==meta) - ;; TODO: Make the call to &type/reset-mappings unnecessary. - ;; It should not be necessary to reset the mappings of the - ;; type-vars, because those mappings should not stay around - ;; after being cleaned-up. - ;; I must figure out why they're staying around. _ &type/reset-mappings] (return &/$Nil))) diff --git a/luxc/src/lux/compiler/cache.clj b/luxc/src/lux/compiler/cache.clj index 4ec18798e..a0b2b0588 100644 --- a/luxc/src/lux/compiler/cache.clj +++ b/luxc/src/lux/compiler/cache.clj @@ -229,7 +229,7 @@ (return nil))) (defn ^:private inject-module - "(-> (Module Compiler) (-> Compiler (Lux Null)))" + "(-> Module Compiler (Lux Null))" [module-name module] (fn [compiler] (return* (&/update$ &/$modules diff --git a/luxc/src/lux/type.clj b/luxc/src/lux/type.clj index 0834db3a6..897b3bc67 100644 --- a/luxc/src/lux/type.clj +++ b/luxc/src/lux/type.clj @@ -242,7 +242,7 @@ (fn [state] (if-let [tvar (->> state (&/get$ &/$type-context) (&/get$ &/$var-bindings) (&/|get id))] (return* (&/update$ &/$type-context (fn [ts] (&/update$ &/$var-bindings #(&/|put id &/$None %) - ts)) + ts)) state) nil) ((&/fail-with-loc (str "[Type Error] Unknown type-var: " id " | " (->> state (&/get$ &/$type-context) (&/get$ &/$var-bindings) &/|length))) @@ -253,7 +253,7 @@ (def reset-mappings (fn [state] (return* (&/update$ &/$type-context #(->> % - ;; (&/set$ &/$var-counter 0) + (&/set$ &/$var-counter 0) (&/set$ &/$var-bindings (&/|table))) state) nil))) @@ -279,45 +279,9 @@ (&/get$ &/$ex-counter) &/$Ex)))) -(declare clean*) -(defn delete-var [id] - (|do [? (bound? id) - _ (if ? - (return nil) - (|do [ex existential] - (set-var id ex)))] - (fn [state] - ((|do [mappings* (&/map% (fn [binding] - (|let [[?id ?type] binding] - (if (= id ?id) - (return binding) - (|case ?type - (&/$None) - (return binding) - - (&/$Some ?type*) - (|case ?type* - (&/$Var ?id*) - (if (= id ?id*) - (return (&/T [?id &/$None])) - (return binding)) - - _ - (|do [?type** (clean* id ?type*)] - (return (&/T [?id (&/$Some ?type**)])))) - )))) - (->> state (&/get$ &/$type-context) (&/get$ &/$var-bindings)))] - (fn [state] - (return* (&/update$ &/$type-context #(&/set$ &/$var-bindings (&/|remove id mappings*) %) - state) - nil))) - state)))) - (defn with-var [k] - (|do [id create-var - output (k (&/$Var id)) - _ (delete-var id)] - (return output))) + (|do [id create-var] + (k (&/$Var id)))) (defn clean* [?tid type] (|case type -- cgit v1.2.3