blob: 4fb90a51e33416adc98348b07e2cd4bc30057cb4 (
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
|
(.module:
[lux (#- Scope)]
(lux (control [monad (#+ do)])
(data [product]
[text]
text/format
(collection [list ("list/" Functor<List>)]))
[macro])
(///// (host ["_" scheme (#+ Computation Var)])
[compiler]
(compiler [synthesis (#+ Scope Synthesis)]))
[///]
[//runtime (#+ Operation Translator)]
[//reference])
(def: @scope (_.var "scope"))
(def: #export (scope translate [start initsS+ bodyS])
(-> Translator (Scope Synthesis) (Operation Computation))
(do compiler.Monad<Operation>
[initsO+ (monad.map @ translate initsS+)
bodyO (///.with-anchor @scope
(translate bodyS))]
(wrap (_.letrec (list [@scope (_.lambda [(|> initsS+
list.enumerate
(list/map (|>> product.left (n/+ start) //reference.local')))
#.None]
bodyO)])
(_.apply/* @scope initsO+)))))
(def: #export (recur translate argsS+)
(-> Translator (List Synthesis) (Operation Computation))
(do compiler.Monad<Operation>
[@scope ///.anchor
argsO+ (monad.map @ translate argsS+)]
(wrap (_.apply/* @scope argsO+))))
|