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. --- stdlib/source/lux.lux | 43 +++++++++++++++++++++++++++++-------------- stdlib/source/lux/macro.lux | 23 +++++++++++------------ 2 files changed, 40 insertions(+), 26 deletions(-) (limited to 'stdlib') 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 [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)])))) -- cgit v1.2.3