blob: 8df7f23b22e8ceb40f9cd07c141b5747498d3508 (
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
;; Copyright (c) Eduardo Julian. All rights reserved.
;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
;; If a copy of the MPL was not distributed with this file,
;; You can obtain one at http://mozilla.org/MPL/2.0/.
(ns lux.analyser.base
(:require clojure.core.match
clojure.core.match.array
(lux [base :as & :refer [deftags |let |do return fail |case]]
[type :as &type])))
;; [Tags]
(deftags
["bool"
"int"
"real"
"char"
"text"
"variant"
"tuple"
"apply"
"case"
"lambda"
"ann"
"def"
"declare-macro"
"var"
"captured"
"jvm-getstatic"
"jvm-getfield"
"jvm-putstatic"
"jvm-putfield"
"jvm-invokestatic"
"jvm-instanceof"
"jvm-invokevirtual"
"jvm-invokeinterface"
"jvm-invokespecial"
"jvm-null?"
"jvm-null"
"jvm-new"
"jvm-class"
"jvm-interface"
"jvm-try"
"jvm-throw"
"jvm-monitorenter"
"jvm-monitorexit"
"jvm-program"
"jvm-znewarray"
"jvm-zastore"
"jvm-zaload"
"jvm-bnewarray"
"jvm-bastore"
"jvm-baload"
"jvm-snewarray"
"jvm-sastore"
"jvm-saload"
"jvm-inewarray"
"jvm-iastore"
"jvm-iaload"
"jvm-lnewarray"
"jvm-lastore"
"jvm-laload"
"jvm-fnewarray"
"jvm-fastore"
"jvm-faload"
"jvm-dnewarray"
"jvm-dastore"
"jvm-daload"
"jvm-cnewarray"
"jvm-castore"
"jvm-caload"
"jvm-anewarray"
"jvm-aastore"
"jvm-aaload"
"jvm-arraylength"
"jvm-iadd"
"jvm-isub"
"jvm-imul"
"jvm-idiv"
"jvm-irem"
"jvm-ieq"
"jvm-ilt"
"jvm-igt"
"jvm-ceq"
"jvm-clt"
"jvm-cgt"
"jvm-ladd"
"jvm-lsub"
"jvm-lmul"
"jvm-ldiv"
"jvm-lrem"
"jvm-leq"
"jvm-llt"
"jvm-lgt"
"jvm-fadd"
"jvm-fsub"
"jvm-fmul"
"jvm-fdiv"
"jvm-frem"
"jvm-feq"
"jvm-flt"
"jvm-fgt"
"jvm-dadd"
"jvm-dsub"
"jvm-dmul"
"jvm-ddiv"
"jvm-drem"
"jvm-deq"
"jvm-dlt"
"jvm-dgt"
"jvm-d2f"
"jvm-d2i"
"jvm-d2l"
"jvm-f2d"
"jvm-f2i"
"jvm-f2l"
"jvm-i2b"
"jvm-i2c"
"jvm-i2d"
"jvm-i2f"
"jvm-i2l"
"jvm-i2s"
"jvm-l2d"
"jvm-l2f"
"jvm-l2i"
"jvm-iand"
"jvm-ior"
"jvm-ixor"
"jvm-ishl"
"jvm-ishr"
"jvm-iushr"
"jvm-land"
"jvm-lor"
"jvm-lxor"
"jvm-lshl"
"jvm-lshr"
"jvm-lushr"])
;; [Exports]
(defn expr-type* [syntax+]
(|let [[_ type] syntax+]
type))
(defn cap-1 [action]
(|do [result action]
(|case result
(&/$Cons x (&/$Nil))
(return x)
_
(fail "[Analyser Error] Can't expand to other than 1 element."))))
(defn analyse-1 [analyse exo-type elem]
(cap-1 (analyse exo-type elem)))
(defn analyse-1+ [analyse ?token]
(&type/with-var
(fn [$var]
(|do [=expr (analyse-1 analyse $var ?token)
:let [[?item ?type] =expr]
=type (&type/clean $var ?type)]
(return (&/T ?item =type))))))
(defn resolved-ident [ident]
(|let [[?module ?name] ident]
(|do [module* (if (.equals "" ?module)
&/get-module-name
(return ?module))]
(return (&/T module* ?name)))))
(let [tag-names #{"DataT" "VariantT" "TupleT" "LambdaT" "BoundT" "VarT" "ExT" "UnivQ" "ExQ" "AppT" "NamedT"}]
(defn type-tag? [module name]
(and (= "lux" module)
(contains? tag-names name))))
|