diff options
Diffstat (limited to '')
-rw-r--r-- | new-luxc/source/luxc/scope.lux | 57 |
1 files changed, 36 insertions, 21 deletions
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>] text/format [maybe "maybe/" Monad<Maybe>] [product] ["e" error] - (coll [list "list/" Fold<List> Monoid<List>])) + (coll [list "list/" Functor<List> Fold<List> Monoid<List>])) [meta]) - (luxc ["&" base])) + (luxc ["&" base] + (lang [";L" variable #+ Variable]))) (type: Locals (Bindings Text [Type Nat])) (type: Captured (Bindings Text [Type Ref])) -(do-template [<slot> <is> <get> <then>] - [(def: (<is> name scope) - (-> Text Scope Bool) - (|> scope - (get@ [<slot> #;mappings]) - (&;pl-contains? name))) - - (def: (<get> name scope) - (-> Text Scope (Maybe [Type Ref])) - (|> scope - (get@ [<slot> #;mappings]) - (&;pl-get name) - (maybe/map (function [[type value]] - [type (<then> 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) |