diff options
Diffstat (limited to '')
-rw-r--r-- | new-luxc/source/luxc/lang/variable.lux | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/variable.lux b/new-luxc/source/luxc/lang/variable.lux new file mode 100644 index 000000000..c04269e63 --- /dev/null +++ b/new-luxc/source/luxc/lang/variable.lux @@ -0,0 +1,47 @@ +(;module: + lux + (lux (data (coll [list "list/" Functor<List>])))) + +(def: #export Variable Int) +(def: #export Register Nat) + +(def: #export (captured register) + (-> Nat Variable) + (|> register n.inc nat-to-int (i.* -1))) + +(def: #export (local register) + (-> Nat Variable) + (nat-to-int register)) + +(def: #export (local-register variable) + (-> Variable Register) + (int-to-nat variable)) + +(def: #export (captured-register variable) + (-> Variable Register) + (|> variable (i.* -1) int-to-nat n.dec)) + +(do-template [<name> <comp>] + [(def: #export (<name> var) + (-> Variable Bool) + (<comp> 0 var))] + + [self? i.=] + [local? i.>] + [captured? i.<] + ) + +(def: #export (from-ref ref) + (-> Ref Variable) + (case ref + (#;Local register) + (local register) + + (#;Captured register) + (captured register))) + +(def: #export (environment scope) + (-> Scope (List Variable)) + (|> scope + (get@ [#;captured #;mappings]) + (list/map (function [[_ [_ ref]]] (from-ref ref))))) |