gofront 0.0.7 → 0.0.9
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 +104 -18
- package/package.json +9 -4
- package/src/codegen/expressions.js +351 -6
- package/src/codegen/source-map.js +8 -5
- package/src/codegen.js +329 -4
- package/src/compiler.js +39 -4
- package/src/dev-server.js +1 -0
- package/src/index.js +10 -6
- package/src/lexer.js +14 -14
- package/src/parser/expressions.js +3 -2
- package/src/parser/statements.js +5 -1
- package/src/parser.js +8 -1
- package/src/resolver.js +29 -0
- package/src/templ-lexer.js +737 -0
- package/src/templ-parser.js +235 -0
- package/src/typechecker/stdlib.js +305 -2
- package/src/typechecker/types.js +6 -18
- package/src/typechecker.js +30 -2
package/src/typechecker.js
CHANGED
|
@@ -157,6 +157,8 @@ export class TypeChecker {
|
|
|
157
157
|
for (const decl of program.decls) {
|
|
158
158
|
if (decl.kind === "FuncDecl" || decl.kind === "MethodDecl") {
|
|
159
159
|
this.collectFunc(decl);
|
|
160
|
+
} else if (decl.kind === "TemplDecl") {
|
|
161
|
+
this._collectTemplDecl(decl);
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
// Pass 2.1: Promote embedded methods
|
|
@@ -203,9 +205,11 @@ export class TypeChecker {
|
|
|
203
205
|
for (const p of programs) {
|
|
204
206
|
this._currentFile = p._filename ?? null;
|
|
205
207
|
this._currentSource = p._source ?? null;
|
|
206
|
-
for (const d of p.decls)
|
|
208
|
+
for (const d of p.decls) {
|
|
207
209
|
if (d.kind === "FuncDecl" || d.kind === "MethodDecl")
|
|
208
210
|
this.collectFunc(d);
|
|
211
|
+
else if (d.kind === "TemplDecl") this._collectTemplDecl(d);
|
|
212
|
+
}
|
|
209
213
|
}
|
|
210
214
|
|
|
211
215
|
// Pass 2.1: Promote embedded methods
|
|
@@ -407,8 +411,32 @@ export class TypeChecker {
|
|
|
407
411
|
this.checkConstDecl(decl, scope);
|
|
408
412
|
break;
|
|
409
413
|
case "TypeDecl":
|
|
410
|
-
|
|
414
|
+
case "TemplDecl":
|
|
415
|
+
break; // already collected / no body to check
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
_collectTemplDecl(decl) {
|
|
420
|
+
const paramTypes = decl.params.map((p) =>
|
|
421
|
+
this.resolveTypeNode(p.type, this.globals),
|
|
422
|
+
);
|
|
423
|
+
const gomNodeType = this.types.get("gom.Node") ?? {
|
|
424
|
+
kind: "basic",
|
|
425
|
+
name: "any",
|
|
426
|
+
};
|
|
427
|
+
const isVariadic =
|
|
428
|
+
decl.params.length > 0 && decl.params[decl.params.length - 1].variadic;
|
|
429
|
+
const funcType = {
|
|
430
|
+
kind: "func",
|
|
431
|
+
params: paramTypes,
|
|
432
|
+
returns: [gomNodeType],
|
|
433
|
+
variadic: isVariadic,
|
|
434
|
+
async: false,
|
|
435
|
+
};
|
|
436
|
+
if (this.globals.symbols.has(decl.name) && decl.name !== "init") {
|
|
437
|
+
this.err(`${decl.name} redeclared in this block`, decl);
|
|
411
438
|
}
|
|
439
|
+
this.globals.define(decl.name, funcType);
|
|
412
440
|
}
|
|
413
441
|
|
|
414
442
|
checkFuncDecl(decl, outer) {
|