blob: f766ffdcf1a863b16602c5c0b6ee1c257e59b743 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
(;module:
lux
(lux (data (coll [list "list/" Functor<List>]))))
(def: #export Variable Int)
(def: #export Register Nat)
(def: #export (captured register)
(-> Register Variable)
(|> register n.inc nat-to-int (i.* -1)))
(def: #export (local register)
(-> Register 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)))))
|