blob: f6021e1842c9eaf0d68c5fc79a323a3b8b496a76 (
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
|
(;module:
lux
(lux [io]
(control [monad #+ do]
pipe)
(data ["e" error])
["r" math/random]
[meta #+ Monad<Meta>]
(meta [type "type/" Eq<Type>])
test)
(luxc ["&;" scope]
["&;" module]
(lang ["~" analysis]
(analysis [";A" expression]
["@" reference]
["@;" common])))
(.. common)
(test/luxc common))
(context: "References"
(<| (times +100)
(do @
[[ref-type _] gen-primitive
module-name (r;text +5)
scope-name (r;text +5)
var-name (r;text +5)]
($_ seq
(test "Can analyse variable."
(|> (&scope;with-scope scope-name
(&scope;with-local [var-name ref-type]
(@common;with-unknown-type
(@;analyse-reference ["" var-name]))))
(meta;run (init-compiler []))
(case> (^ (#e;Success [_type (^code ((~ [_ (#;Int var)])))]))
(type/= ref-type _type)
_
false)))
(test "Can analyse definition."
(|> (do Monad<Meta>
[_ (&module;create +0 module-name)
_ (&module;define [module-name var-name]
[ref-type (' {}) (:! Void [])])]
(@common;with-unknown-type
(@;analyse-reference [module-name var-name])))
(meta;run (init-compiler []))
(case> (#e;Success [_type [_ (#;Symbol def-name)]])
(type/= ref-type _type)
_
false)))
))))
|