blob: 248bfbb716c21c50db46695a6db24499cf8a4db7 (
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
83
84
85
86
87
88
89
90
91
92
|
(.module:
lux
(lux (control [monad #+ do]
["ex" exception #+ exception:])
(data ["e" error]
[text]
(coll [dict #+ Dict]))
[macro])
[//])
(exception: #export Unknown-Analysis)
(exception: #export Unknown-Synthesis)
(exception: #export Unknown-Translation)
(exception: #export Unknown-Statement)
(exception: #export Cannot-Define-Analysis-More-Than-Once)
(exception: #export Cannot-Define-Synthesis-More-Than-Once)
(exception: #export Cannot-Define-Translation-More-Than-Once)
(exception: #export Cannot-Define-Statement-More-Than-Once)
(type: #export Analysis
(-> (-> Code (Meta Code))
(-> Type Code (Meta Top))
(List Code) (Meta Code)))
(type: #export Synthesis
(-> (List Code) (Meta Code)))
(type: #export Translation
(-> (List Code) (Meta Code)))
(type: #export Statement
(-> (List Code) (Meta Unit)))
(type: #export Extensions
{#analysis (Dict Text Analysis)
#synthesis (Dict Text Synthesis)
#translation (Dict Text Translation)
#statement (Dict Text Statement)})
(def: #export fresh
Extensions
{#analysis (dict.new text.Hash<Text>)
#synthesis (dict.new text.Hash<Text>)
#translation (dict.new text.Hash<Text>)
#statement (dict.new text.Hash<Text>)})
(def: get
(Meta Extensions)
(function [compiler]
(#e.Success [compiler
(|> compiler (get@ #.extensions) (:! Extensions))])))
(def: (set extensions)
(-> Extensions (Meta Unit))
(function [compiler]
(#e.Success [(set@ #.extensions (:! Void extensions) compiler)
[]])))
(do-template [<name> <type> <category> <exception>]
[(def: #export (<name> name)
(-> Text (Meta <type>))
(do macro.Monad<Meta>
[extensions ..get]
(case (dict.get name (get@ <category> extensions))
(#.Some extension)
(wrap extension)
#.None
(//.throw <exception> name))))]
[find-analysis Analysis #analysis Unknown-Analysis]
[find-synthesis Synthesis #synthesis Unknown-Synthesis]
[find-translation Translation #translation Unknown-Translation]
[find-statement Statement #statement Unknown-Statement]
)
(do-template [<name> <type> <category> <exception>]
[(def: #export (<name> name extension)
(-> Text <type> (Meta Unit))
(do macro.Monad<Meta>
[extensions ..get
_ (//.assert <exception> name
(not (dict.contains? name (get@ <category> extensions))))
_ (..set (update@ <category> (dict.put name extension) extensions))]
(wrap [])))]
[install-analysis Analysis #analysis Cannot-Define-Analysis-More-Than-Once]
[install-synthesis Synthesis #synthesis Cannot-Define-Synthesis-More-Than-Once]
[install-translation Translation #translation Cannot-Define-Translation-More-Than-Once]
[install-statement Statement #statement Cannot-Define-Statement-More-Than-Once]
)
|