blob: 4ffa673fcba30e28e36b2d3c54aaf2c9f580f390 (
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
77
78
79
80
81
82
|
(.module:
[lux #*
[abstract
monad]
[control
["." exception (#+ exception:)]]
["." macro]
[data
["." text ("#@." equivalence)
format]]]
["." // #_
["#." scope]
["#." type]
["#/" //
["#." extension]
["#/" // #_
["#." reference]
["/" analysis (#+ Analysis Operation)]]]])
(exception: #export (foreign-module-has-not-been-imported {current Text} {foreign Text})
(exception.report
["Current" current]
["Foreign" foreign]))
(exception: #export (definition-has-not-been-exported {definition Name})
(exception.report
["Definition" (%name definition)]))
(def: (definition def-name)
(-> Name (Operation Analysis))
(with-expansions [<return> (wrap (|> def-name ////reference.constant #/.Reference))]
(do ///.monad
[[actualT def-anns _] (///extension.lift (macro.find-def def-name))]
(case (macro.get-identifier-ann (name-of #.alias) def-anns)
(#.Some real-def-name)
(definition real-def-name)
_
(do @
[_ (//type.infer actualT)
(^@ def-name [::module ::name]) (///extension.lift (macro.normalize def-name))
current (///extension.lift macro.current-module-name)]
(if (text@= current ::module)
<return>
(if (macro.export? def-anns)
(do @
[imported! (///extension.lift (macro.imported-by? ::module current))]
(if imported!
<return>
(/.throw foreign-module-has-not-been-imported [current ::module])))
(/.throw definition-has-not-been-exported def-name))))))))
(def: (variable var-name)
(-> Text (Operation (Maybe Analysis)))
(do ///.monad
[?var (//scope.find var-name)]
(case ?var
(#.Some [actualT ref])
(do @
[_ (//type.infer actualT)]
(wrap (#.Some (|> ref ////reference.variable #/.Reference))))
#.None
(wrap #.None))))
(def: #export (reference reference)
(-> Name (Operation Analysis))
(case reference
["" simple-name]
(do ///.monad
[?var (variable simple-name)]
(case ?var
(#.Some varA)
(wrap varA)
#.None
(do @
[this-module (///extension.lift macro.current-module-name)]
(definition [this-module simple-name]))))
_
(definition reference)))
|