blob: 8de6c4fa5362a1f135dc74cac1ba724ebfbcfa31 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
(.module:
lux
(lux [io]
(control [monad #+ do]
pipe)
(data ["e" error]
[text])
["r" math/random]
[macro]
(macro [code])
test)
(luxc [lang]
(lang ["_." module]
(host ["$" jvm]
(jvm ["$i" inst]))
["ls" synthesis]
(translation (jvm [".T" statement]
[".T" eval]
[".T" expression]
[".T" case]
[".T" runtime]))))
(test/luxc common))
(def: ident-part
(r.Random Text)
(|> (r.text +5)
(r.filter (function [sample]
(not (or (text.contains? "/" sample)
(text.contains? "[" sample)
(text.contains? "]" sample)))))))
(context: "Definitions."
(<| (times +100)
(do @
[module-name ident-part
def-name ident-part
def-value r.int
#let [valueI (|>> ($i.long def-value) ($i.wrap #$.Long))]]
($_ seq
(test "Can refer to definitions."
(|> (do macro.Monad<Meta>
[_ (_module.with-module +0 module-name
(statementT.translate-def def-name Int valueI (' {})))
sampleI (expressionT.translate (code.symbol [module-name def-name]))]
(evalT.eval sampleI))
(lang.with-current-module "")
(macro.run (init-compiler []))
(case> (#e.Success valueT)
(i/= def-value (:! Int valueT))
(#e.Error error)
false)))
))))
(context: "Variables."
(<| (times +100)
(do @
[module-name (|> (r.text +5) (r.filter (|>> (text.contains? "/") not)))
register (|> r.nat (:: @ map (n/% +100)))
value r.int]
($_ seq
(test "Can refer to local variables/registers."
(|> (do macro.Monad<Meta>
[sampleI (caseT.translate-let expressionT.translate
register
(code.int value)
(` ((~ (code.int (nat-to-int register))))))]
(evalT.eval sampleI))
(lang.with-current-module "")
(macro.run (init-compiler []))
(case> (#e.Success outputT)
(i/= value (:! Int outputT))
(#e.Error error)
false)))
))))
|