From cab9451961fa25fd6683c1c7bd836941bd84e48b Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 6 Nov 2017 18:34:51 -0400 Subject: - Fixed some bugs. --- new-luxc/source/luxc/scope.lux | 57 ++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'new-luxc/source/luxc/scope.lux') diff --git a/new-luxc/source/luxc/scope.lux b/new-luxc/source/luxc/scope.lux index 4ce8a51cb..165399c8f 100644 --- a/new-luxc/source/luxc/scope.lux +++ b/new-luxc/source/luxc/scope.lux @@ -1,36 +1,51 @@ (;module: lux (lux (control monad) - (data [text] + (data [text "text/" Eq] text/format [maybe "maybe/" Monad] [product] ["e" error] - (coll [list "list/" Fold Monoid])) + (coll [list "list/" Functor Fold Monoid])) [meta]) - (luxc ["&" base])) + (luxc ["&" base] + (lang [";L" variable #+ Variable]))) (type: Locals (Bindings Text [Type Nat])) (type: Captured (Bindings Text [Type Ref])) -(do-template [ ] - [(def: ( name scope) - (-> Text Scope Bool) - (|> scope - (get@ [ #;mappings]) - (&;pl-contains? name))) - - (def: ( name scope) - (-> Text Scope (Maybe [Type Ref])) - (|> scope - (get@ [ #;mappings]) - (&;pl-get name) - (maybe/map (function [[type value]] - [type ( value)]))))] - - [#;locals is-local? get-local #;Local] - [#;captured is-captured? get-captured id] - ) +(def: (is-local? name scope) + (-> Text Scope Bool) + (|> scope + (get@ [#;locals #;mappings]) + (&;pl-contains? name))) + +(def: (get-local name scope) + (-> Text Scope (Maybe [Type Ref])) + (|> scope + (get@ [#;locals #;mappings]) + (&;pl-get name) + (maybe/map (function [[type value]] + [type (#;Local value)])))) + +(def: (is-captured? name scope) + (-> Text Scope Bool) + (|> scope + (get@ [#;captured #;mappings]) + (&;pl-contains? name))) + +(def: (get-captured name scope) + (-> Text Scope (Maybe [Type Ref])) + (loop [idx +0 + mappings (get@ [#;captured #;mappings] scope)] + (case mappings + #;Nil + #;None + + (#;Cons [_name [_source-type _source-ref]] mappings') + (if (text/= name _name) + (#;Some [_source-type (#;Captured idx)]) + (recur (n.inc idx) mappings'))))) (def: (is-ref? name scope) (-> Text Scope Bool) -- cgit v1.2.3