gofront 0.0.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/package.json +7 -4
- package/src/codegen/expressions.js +520 -1717
- package/src/codegen/index.js +576 -0
- package/src/codegen/runtime.js +151 -0
- package/src/codegen/statements.js +305 -296
- package/src/codegen/stdlib/builder.js +36 -0
- package/src/codegen/stdlib/bytes.js +62 -0
- package/src/codegen/stdlib/errors.js +17 -0
- package/src/codegen/stdlib/fmt.js +101 -0
- package/src/codegen/stdlib/gom.js +152 -0
- package/src/codegen/stdlib/html.js +17 -0
- package/src/codegen/stdlib/index.js +95 -0
- package/src/codegen/stdlib/io.js +33 -0
- package/src/codegen/stdlib/maps.js +42 -0
- package/src/codegen/stdlib/math.js +53 -0
- package/src/codegen/stdlib/os.js +10 -0
- package/src/codegen/stdlib/path.js +31 -0
- package/src/codegen/stdlib/rand.js +24 -0
- package/src/codegen/stdlib/regexp.js +51 -0
- package/src/codegen/stdlib/slices.js +48 -0
- package/src/codegen/stdlib/sort.js +28 -0
- package/src/codegen/stdlib/strconv.js +30 -0
- package/src/codegen/stdlib/strings.js +83 -0
- package/src/codegen/stdlib/time.js +54 -0
- package/src/codegen/stdlib/unicode.js +22 -0
- package/src/codegen/stdlib/utf8.js +23 -0
- package/src/codegen/templ.js +281 -0
- package/src/compiler.js +80 -74
- package/src/dts-parser.js +355 -371
- package/src/index.js +13 -49
- package/src/lexer.js +186 -272
- package/src/minifier.js +305 -318
- package/src/parser/expressions.js +51 -34
- package/src/{parser.js → parser/index.js} +4 -4
- package/src/parser/statements.js +24 -34
- package/src/parser/types.js +31 -29
- package/src/templ-parser.js +2 -2
- package/src/tokens.js +109 -0
- package/src/typechecker/assignability.js +258 -0
- package/src/typechecker/expressions.js +559 -549
- package/src/typechecker/index.js +555 -0
- package/src/typechecker/resolve.js +421 -0
- package/src/typechecker/statements.js +267 -280
- package/src/typechecker/stdlib/core.js +592 -0
- package/src/typechecker/stdlib/extended.js +332 -0
- package/src/typechecker/stdlib.js +9 -1060
- package/src/typechecker/termination.js +83 -0
- package/src/codegen.js +0 -882
- package/src/typechecker.js +0 -1299
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// Extended standard library type definitions — gom, maps, regexp, rand, utf8,
|
|
2
|
+
// path, strings.Builder / bytes.Buffer types, and built-in functions.
|
|
3
|
+
|
|
4
|
+
import { ANY, BOOL, ERROR, FLOAT64, INT, STRING, VOID } from "../types.js";
|
|
5
|
+
|
|
6
|
+
export function setupExtendedGlobals(globals, types) {
|
|
7
|
+
const GOM_NODE_T = {
|
|
8
|
+
kind: "interface",
|
|
9
|
+
methods: new Map([
|
|
10
|
+
["Mount", { kind: "func", params: [ANY], returns: [VOID] }],
|
|
11
|
+
]),
|
|
12
|
+
};
|
|
13
|
+
const GOM_NODE_FUNC_T = {
|
|
14
|
+
kind: "named",
|
|
15
|
+
name: "gom.NodeFunc",
|
|
16
|
+
underlying: { kind: "func", params: [ANY], returns: [VOID] },
|
|
17
|
+
};
|
|
18
|
+
const GOM_GROUP_T = {
|
|
19
|
+
kind: "named",
|
|
20
|
+
name: "gom.Group",
|
|
21
|
+
underlying: { kind: "slice", elem: GOM_NODE_T },
|
|
22
|
+
};
|
|
23
|
+
const gomEl = {
|
|
24
|
+
kind: "func",
|
|
25
|
+
params: [GOM_NODE_T],
|
|
26
|
+
returns: [GOM_NODE_T],
|
|
27
|
+
variadic: true,
|
|
28
|
+
};
|
|
29
|
+
const gomAttr1 = { kind: "func", params: [STRING], returns: [GOM_NODE_T] };
|
|
30
|
+
const gomBoolAttr = { kind: "func", params: [], returns: [GOM_NODE_T] };
|
|
31
|
+
const gomMembers = {
|
|
32
|
+
Node: GOM_NODE_T,
|
|
33
|
+
NodeFunc: GOM_NODE_FUNC_T,
|
|
34
|
+
Group: GOM_GROUP_T,
|
|
35
|
+
El: {
|
|
36
|
+
kind: "func",
|
|
37
|
+
params: [STRING, GOM_NODE_T],
|
|
38
|
+
returns: [GOM_NODE_T],
|
|
39
|
+
variadic: true,
|
|
40
|
+
},
|
|
41
|
+
Text: { kind: "func", params: [STRING], returns: [GOM_NODE_T] },
|
|
42
|
+
Attr: { kind: "func", params: [STRING, STRING], returns: [GOM_NODE_T] },
|
|
43
|
+
DataAttr: { kind: "func", params: [STRING, STRING], returns: [GOM_NODE_T] },
|
|
44
|
+
If: { kind: "func", params: [BOOL, GOM_NODE_T], returns: [GOM_NODE_T] },
|
|
45
|
+
Map: { kind: "func", params: [ANY, ANY], returns: [GOM_NODE_T] },
|
|
46
|
+
Mount: { kind: "func", params: [STRING, GOM_NODE_T], returns: [VOID] },
|
|
47
|
+
MountTo: { kind: "func", params: [STRING, GOM_NODE_T], returns: [VOID] },
|
|
48
|
+
};
|
|
49
|
+
for (const name of [
|
|
50
|
+
"Div",
|
|
51
|
+
"Section",
|
|
52
|
+
"Article",
|
|
53
|
+
"Aside",
|
|
54
|
+
"Header",
|
|
55
|
+
"Footer",
|
|
56
|
+
"Main",
|
|
57
|
+
"Nav",
|
|
58
|
+
"Figure",
|
|
59
|
+
"H1",
|
|
60
|
+
"H2",
|
|
61
|
+
"H3",
|
|
62
|
+
"H4",
|
|
63
|
+
"H5",
|
|
64
|
+
"H6",
|
|
65
|
+
"Span",
|
|
66
|
+
"A",
|
|
67
|
+
"Strong",
|
|
68
|
+
"Em",
|
|
69
|
+
"Code",
|
|
70
|
+
"Pre",
|
|
71
|
+
"Small",
|
|
72
|
+
"Mark",
|
|
73
|
+
"P",
|
|
74
|
+
"Br",
|
|
75
|
+
"Hr",
|
|
76
|
+
"Ul",
|
|
77
|
+
"Ol",
|
|
78
|
+
"Li",
|
|
79
|
+
"Dl",
|
|
80
|
+
"Dt",
|
|
81
|
+
"Dd",
|
|
82
|
+
"Form",
|
|
83
|
+
"Input",
|
|
84
|
+
"Button",
|
|
85
|
+
"Textarea",
|
|
86
|
+
"Select",
|
|
87
|
+
"Option",
|
|
88
|
+
"Label",
|
|
89
|
+
"Fieldset",
|
|
90
|
+
"Legend",
|
|
91
|
+
"Img",
|
|
92
|
+
"Video",
|
|
93
|
+
"Audio",
|
|
94
|
+
"Canvas",
|
|
95
|
+
"Table",
|
|
96
|
+
"Thead",
|
|
97
|
+
"Tbody",
|
|
98
|
+
"Tfoot",
|
|
99
|
+
"Tr",
|
|
100
|
+
"Th",
|
|
101
|
+
"Td",
|
|
102
|
+
])
|
|
103
|
+
gomMembers[name] = gomEl;
|
|
104
|
+
for (const name of [
|
|
105
|
+
"Class",
|
|
106
|
+
"Type",
|
|
107
|
+
"Href",
|
|
108
|
+
"Src",
|
|
109
|
+
"Placeholder",
|
|
110
|
+
"Style",
|
|
111
|
+
"For",
|
|
112
|
+
"Name",
|
|
113
|
+
"Value",
|
|
114
|
+
"Target",
|
|
115
|
+
"Rel",
|
|
116
|
+
"Alt",
|
|
117
|
+
"Title",
|
|
118
|
+
"Lang",
|
|
119
|
+
"Action",
|
|
120
|
+
"Method",
|
|
121
|
+
"AutoComplete",
|
|
122
|
+
"Draggable",
|
|
123
|
+
"Role",
|
|
124
|
+
"AriaLabel",
|
|
125
|
+
"StyleAttr",
|
|
126
|
+
])
|
|
127
|
+
gomMembers[name] = gomAttr1;
|
|
128
|
+
for (const name of ["Disabled", "Checked", "Selected", "Readonly"])
|
|
129
|
+
gomMembers[name] = gomBoolAttr;
|
|
130
|
+
globals.define("gom", {
|
|
131
|
+
kind: "namespace",
|
|
132
|
+
name: "gom",
|
|
133
|
+
members: gomMembers,
|
|
134
|
+
});
|
|
135
|
+
types.set("gom.Node", GOM_NODE_T);
|
|
136
|
+
types.set("gom.NodeFunc", GOM_NODE_FUNC_T);
|
|
137
|
+
types.set("gom.Group", GOM_GROUP_T);
|
|
138
|
+
|
|
139
|
+
globals.define("maps", {
|
|
140
|
+
kind: "namespace",
|
|
141
|
+
name: "maps",
|
|
142
|
+
members: {
|
|
143
|
+
Keys: { kind: "func", params: [ANY], returns: [ANY] },
|
|
144
|
+
Values: { kind: "func", params: [ANY], returns: [ANY] },
|
|
145
|
+
Clone: { kind: "func", params: [ANY], returns: [ANY] },
|
|
146
|
+
Copy: { kind: "func", params: [ANY, ANY], returns: [VOID] },
|
|
147
|
+
Equal: { kind: "func", params: [ANY, ANY], returns: [BOOL] },
|
|
148
|
+
EqualFunc: { kind: "func", params: [ANY, ANY, ANY], returns: [BOOL] },
|
|
149
|
+
Delete: { kind: "func", params: [ANY, ANY], returns: [VOID] },
|
|
150
|
+
DeleteFunc: { kind: "func", params: [ANY, ANY], returns: [VOID] },
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const REGEXP_T = {
|
|
155
|
+
kind: "named",
|
|
156
|
+
name: "regexp.Regexp",
|
|
157
|
+
underlying: { kind: "struct", fields: new Map(), methods: new Map() },
|
|
158
|
+
};
|
|
159
|
+
const REGEXP_PTR = { kind: "pointer", base: REGEXP_T };
|
|
160
|
+
const STR_SLICE = { kind: "slice", elem: STRING };
|
|
161
|
+
const INT_SLICE = { kind: "slice", elem: INT };
|
|
162
|
+
REGEXP_T.underlying.methods = new Map([
|
|
163
|
+
["MatchString", { kind: "func", params: [STRING], returns: [BOOL] }],
|
|
164
|
+
["FindString", { kind: "func", params: [STRING], returns: [STRING] }],
|
|
165
|
+
[
|
|
166
|
+
"FindStringIndex",
|
|
167
|
+
{ kind: "func", params: [STRING], returns: [INT_SLICE] },
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
"FindAllString",
|
|
171
|
+
{ kind: "func", params: [STRING, INT], returns: [STR_SLICE] },
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
"FindStringSubmatch",
|
|
175
|
+
{ kind: "func", params: [STRING], returns: [STR_SLICE] },
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
"FindAllStringSubmatch",
|
|
179
|
+
{
|
|
180
|
+
kind: "func",
|
|
181
|
+
params: [STRING, INT],
|
|
182
|
+
returns: [{ kind: "slice", elem: STR_SLICE }],
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
[
|
|
186
|
+
"ReplaceAllString",
|
|
187
|
+
{ kind: "func", params: [STRING, STRING], returns: [STRING] },
|
|
188
|
+
],
|
|
189
|
+
[
|
|
190
|
+
"ReplaceAllLiteralString",
|
|
191
|
+
{ kind: "func", params: [STRING, STRING], returns: [STRING] },
|
|
192
|
+
],
|
|
193
|
+
["Split", { kind: "func", params: [STRING, INT], returns: [STR_SLICE] }],
|
|
194
|
+
["String", { kind: "func", params: [], returns: [STRING] }],
|
|
195
|
+
]);
|
|
196
|
+
types.set("regexp.Regexp", REGEXP_T);
|
|
197
|
+
globals.define("regexp", {
|
|
198
|
+
kind: "namespace",
|
|
199
|
+
name: "regexp",
|
|
200
|
+
members: {
|
|
201
|
+
MustCompile: { kind: "func", params: [STRING], returns: [REGEXP_PTR] },
|
|
202
|
+
Compile: { kind: "func", params: [STRING], returns: [REGEXP_PTR, ERROR] },
|
|
203
|
+
MatchString: {
|
|
204
|
+
kind: "func",
|
|
205
|
+
params: [STRING, STRING],
|
|
206
|
+
returns: [BOOL, ERROR],
|
|
207
|
+
},
|
|
208
|
+
QuoteMeta: { kind: "func", params: [STRING], returns: [STRING] },
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const BYTE_SLICE_T = { kind: "slice", elem: INT };
|
|
213
|
+
const _builderBase = [
|
|
214
|
+
["WriteString", { kind: "func", params: [STRING], returns: [INT, ERROR] }],
|
|
215
|
+
["WriteByte", { kind: "func", params: [INT], returns: [ERROR] }],
|
|
216
|
+
["Write", { kind: "func", params: [BYTE_SLICE_T], returns: [INT, ERROR] }],
|
|
217
|
+
["String", { kind: "func", params: [], returns: [STRING] }],
|
|
218
|
+
["Len", { kind: "func", params: [], returns: [INT] }],
|
|
219
|
+
["Reset", { kind: "func", params: [], returns: [VOID] }],
|
|
220
|
+
["Grow", { kind: "func", params: [INT], returns: [VOID] }],
|
|
221
|
+
];
|
|
222
|
+
const _makeBuilderType = (name, extra = []) => ({
|
|
223
|
+
kind: "named",
|
|
224
|
+
name,
|
|
225
|
+
underlying: {
|
|
226
|
+
kind: "struct",
|
|
227
|
+
fields: new Map(),
|
|
228
|
+
methods: new Map([..._builderBase, ...extra]),
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
types.set(
|
|
232
|
+
"strings.Builder",
|
|
233
|
+
_makeBuilderType("strings.Builder", [
|
|
234
|
+
["WriteRune", { kind: "func", params: [INT], returns: [INT, ERROR] }],
|
|
235
|
+
]),
|
|
236
|
+
);
|
|
237
|
+
types.set(
|
|
238
|
+
"bytes.Buffer",
|
|
239
|
+
_makeBuilderType("bytes.Buffer", [
|
|
240
|
+
["Bytes", { kind: "func", params: [], returns: [BYTE_SLICE_T] }],
|
|
241
|
+
]),
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
globals.define("rand", {
|
|
245
|
+
kind: "namespace",
|
|
246
|
+
name: "rand",
|
|
247
|
+
members: {
|
|
248
|
+
Intn: { kind: "func", params: [INT], returns: [INT] },
|
|
249
|
+
Float64: { kind: "func", params: [], returns: [FLOAT64] },
|
|
250
|
+
Float32: { kind: "func", params: [], returns: [FLOAT64] },
|
|
251
|
+
Int: { kind: "func", params: [], returns: [INT] },
|
|
252
|
+
Int63: { kind: "func", params: [], returns: [INT] },
|
|
253
|
+
Int63n: { kind: "func", params: [INT], returns: [INT] },
|
|
254
|
+
Int31: { kind: "func", params: [], returns: [INT] },
|
|
255
|
+
Int31n: { kind: "func", params: [INT], returns: [INT] },
|
|
256
|
+
Seed: { kind: "func", params: [INT], returns: [VOID] },
|
|
257
|
+
Shuffle: { kind: "func", params: [INT, ANY], returns: [VOID] },
|
|
258
|
+
Perm: {
|
|
259
|
+
kind: "func",
|
|
260
|
+
params: [INT],
|
|
261
|
+
returns: [{ kind: "slice", elem: INT }],
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
globals.define("utf8", {
|
|
267
|
+
kind: "namespace",
|
|
268
|
+
name: "utf8",
|
|
269
|
+
members: {
|
|
270
|
+
RuneCountInString: { kind: "func", params: [STRING], returns: [INT] },
|
|
271
|
+
RuneLen: { kind: "func", params: [INT], returns: [INT] },
|
|
272
|
+
ValidString: { kind: "func", params: [STRING], returns: [BOOL] },
|
|
273
|
+
ValidRune: { kind: "func", params: [INT], returns: [BOOL] },
|
|
274
|
+
DecodeRuneInString: {
|
|
275
|
+
kind: "func",
|
|
276
|
+
params: [STRING],
|
|
277
|
+
returns: [INT, INT],
|
|
278
|
+
},
|
|
279
|
+
DecodeLastRuneInString: {
|
|
280
|
+
kind: "func",
|
|
281
|
+
params: [STRING],
|
|
282
|
+
returns: [INT, INT],
|
|
283
|
+
},
|
|
284
|
+
FullRuneInString: { kind: "func", params: [STRING], returns: [BOOL] },
|
|
285
|
+
RuneError: INT,
|
|
286
|
+
MaxRune: INT,
|
|
287
|
+
UTFMax: INT,
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
globals.define("path", {
|
|
292
|
+
kind: "namespace",
|
|
293
|
+
name: "path",
|
|
294
|
+
members: {
|
|
295
|
+
Base: { kind: "func", params: [STRING], returns: [STRING] },
|
|
296
|
+
Dir: { kind: "func", params: [STRING], returns: [STRING] },
|
|
297
|
+
Ext: { kind: "func", params: [STRING], returns: [STRING] },
|
|
298
|
+
Join: {
|
|
299
|
+
kind: "func",
|
|
300
|
+
params: [STRING],
|
|
301
|
+
returns: [STRING],
|
|
302
|
+
variadic: true,
|
|
303
|
+
},
|
|
304
|
+
Clean: { kind: "func", params: [STRING], returns: [STRING] },
|
|
305
|
+
IsAbs: { kind: "func", params: [STRING], returns: [BOOL] },
|
|
306
|
+
Split: { kind: "func", params: [STRING], returns: [STRING, STRING] },
|
|
307
|
+
Match: { kind: "func", params: [STRING, STRING], returns: [BOOL, ERROR] },
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
for (const name of [
|
|
312
|
+
"append",
|
|
313
|
+
"len",
|
|
314
|
+
"cap",
|
|
315
|
+
"make",
|
|
316
|
+
"delete",
|
|
317
|
+
"print",
|
|
318
|
+
"println",
|
|
319
|
+
"panic",
|
|
320
|
+
"recover",
|
|
321
|
+
"new",
|
|
322
|
+
"copy",
|
|
323
|
+
"error",
|
|
324
|
+
"min",
|
|
325
|
+
"max",
|
|
326
|
+
"clear",
|
|
327
|
+
"complex",
|
|
328
|
+
"real",
|
|
329
|
+
"imag",
|
|
330
|
+
])
|
|
331
|
+
globals.define(name, { kind: "builtin", name });
|
|
332
|
+
}
|