aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/scope.lux
diff options
context:
space:
mode:
authorEduardo Julian2017-11-06 18:34:51 -0400
committerEduardo Julian2017-11-06 18:34:51 -0400
commitcab9451961fa25fd6683c1c7bd836941bd84e48b (patch)
treea03e681579ecc34a84881a2efd8efacea2420e9f /new-luxc/source/luxc/scope.lux
parent4e932a33ac56bb3cb1d7b49771e770e8c373bf8e (diff)
- Fixed some bugs.
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/scope.lux57
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)