gofront 0.0.9 → 1.0.1

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.
Files changed (53) hide show
  1. package/README.md +5 -5
  2. package/package.json +7 -4
  3. package/src/cli-core.js +65 -0
  4. package/src/codegen/expressions.js +523 -1717
  5. package/src/codegen/index.js +576 -0
  6. package/src/codegen/runtime.js +151 -0
  7. package/src/codegen/statements.js +308 -296
  8. package/src/codegen/stdlib/builder.js +39 -0
  9. package/src/codegen/stdlib/bytes.js +65 -0
  10. package/src/codegen/stdlib/errors.js +20 -0
  11. package/src/codegen/stdlib/fmt.js +104 -0
  12. package/src/codegen/stdlib/gom.js +155 -0
  13. package/src/codegen/stdlib/html.js +20 -0
  14. package/src/codegen/stdlib/index.js +98 -0
  15. package/src/codegen/stdlib/io.js +36 -0
  16. package/src/codegen/stdlib/maps.js +45 -0
  17. package/src/codegen/stdlib/math.js +56 -0
  18. package/src/codegen/stdlib/os.js +13 -0
  19. package/src/codegen/stdlib/path.js +34 -0
  20. package/src/codegen/stdlib/rand.js +27 -0
  21. package/src/codegen/stdlib/regexp.js +54 -0
  22. package/src/codegen/stdlib/slices.js +51 -0
  23. package/src/codegen/stdlib/sort.js +31 -0
  24. package/src/codegen/stdlib/strconv.js +33 -0
  25. package/src/codegen/stdlib/strings.js +86 -0
  26. package/src/codegen/stdlib/time.js +57 -0
  27. package/src/codegen/stdlib/unicode.js +25 -0
  28. package/src/codegen/stdlib/utf8.js +26 -0
  29. package/src/codegen/templ.js +284 -0
  30. package/src/compiler.js +142 -77
  31. package/src/dts-parser.js +355 -371
  32. package/src/index.js +32 -162
  33. package/src/lexer.js +186 -272
  34. package/src/minifier.js +305 -318
  35. package/src/{parser.js → parser/declarations.js} +18 -175
  36. package/src/parser/expressions.js +51 -34
  37. package/src/parser/index.js +161 -0
  38. package/src/parser/statements.js +24 -34
  39. package/src/parser/types.js +31 -29
  40. package/src/templ-parser.js +2 -2
  41. package/src/tokens.js +109 -0
  42. package/src/typechecker/assignability.js +261 -0
  43. package/src/typechecker/expressions.js +568 -549
  44. package/src/typechecker/index.js +556 -0
  45. package/src/typechecker/resolve.js +428 -0
  46. package/src/typechecker/statements.js +270 -280
  47. package/src/typechecker/stdlib/core.js +592 -0
  48. package/src/typechecker/stdlib/extended.js +332 -0
  49. package/src/typechecker/stdlib.js +9 -1060
  50. package/src/typechecker/termination.js +86 -0
  51. package/src/typechecker/types.js +1 -0
  52. package/src/codegen.js +0 -882
  53. package/src/typechecker.js +0 -1299
@@ -0,0 +1,86 @@
1
+ // Termination analysis — determines whether a statement/block always returns.
2
+ // Installed as a mixin on TypeChecker.prototype.
3
+
4
+ /** @typedef {import('./index.js').TypeChecker} TypeChecker */
5
+
6
+ /** @type {ThisType<TypeChecker>} */
7
+ export const terminationMethods = {
8
+ _isPanicCall(expr) {
9
+ return (
10
+ expr?.kind === "CallExpr" &&
11
+ expr?.func?.kind === "Ident" &&
12
+ expr?.func?.name === "panic"
13
+ );
14
+ },
15
+
16
+ _isTerminating(stmt) {
17
+ if (!stmt) return false;
18
+ switch (stmt.kind) {
19
+ case "ReturnStmt":
20
+ return true;
21
+ case "BranchStmt":
22
+ return false;
23
+ case "ExprStmt":
24
+ return this._isPanicCall(stmt.expr);
25
+ case "LabeledStmt":
26
+ return this._isTerminating(stmt.body);
27
+ case "Block":
28
+ return this._isTerminatingBlock(stmt);
29
+ case "SwitchStmt":
30
+ return this._isTerminatingSwitch(stmt);
31
+ case "TypeSwitchStmt":
32
+ return this._isTerminatingTypeSwitch(stmt);
33
+ case "ForStmt":
34
+ return !stmt.cond && !this._blockHasBreak(stmt.body);
35
+ case "IfStmt":
36
+ return this._isTerminatingIfStmt(stmt);
37
+ default:
38
+ return false;
39
+ }
40
+ },
41
+
42
+ _isTerminatingIfStmt(stmt) {
43
+ if (!stmt.elseBody) return false;
44
+ return (
45
+ this._isTerminatingBlock(stmt.body) &&
46
+ (stmt.elseBody.kind === "Block"
47
+ ? this._isTerminatingBlock(stmt.elseBody)
48
+ : this._isTerminating(stmt.elseBody))
49
+ );
50
+ },
51
+
52
+ _isTerminatingBlock(block) {
53
+ if (!block?.stmts?.length) return false;
54
+ return this._isTerminating(block.stmts[block.stmts.length - 1]);
55
+ },
56
+
57
+ _blockHasBreak(block) {
58
+ if (!block?.stmts) return false;
59
+ for (const s of block.stmts) {
60
+ if (s.kind === "BranchStmt" && s.keyword === "break") return true;
61
+ }
62
+ return false;
63
+ },
64
+
65
+ _isTerminatingSwitch(stmt) {
66
+ let hasDefault = false;
67
+ for (const c of stmt.cases ?? []) {
68
+ if (!c.list) hasDefault = true;
69
+ if (!c.stmts?.length) return false;
70
+ const last = c.stmts[c.stmts.length - 1];
71
+ if (!this._isTerminating(last)) return false;
72
+ }
73
+ return hasDefault;
74
+ },
75
+
76
+ _isTerminatingTypeSwitch(stmt) {
77
+ let hasDefault = false;
78
+ for (const c of stmt.cases ?? []) {
79
+ if (!c.types) hasDefault = true;
80
+ if (!c.stmts?.length) return false;
81
+ const last = c.stmts[c.stmts.length - 1];
82
+ if (!this._isTerminating(last)) return false;
83
+ }
84
+ return hasDefault;
85
+ },
86
+ };
@@ -48,6 +48,7 @@ export const FLOAT64 = { kind: "basic", name: "float64" };
48
48
  export const STRING = { kind: "basic", name: "string" };
49
49
  export const BOOL = { kind: "basic", name: "bool" };
50
50
  export const ANY = { kind: "basic", name: "any" };
51
+ export const TAINTED_ANY = { kind: "basic", name: "any", _tainted: true };
51
52
  export const VOID = { kind: "basic", name: "void" };
52
53
  export const NIL = { kind: "basic", name: "nil" };
53
54
  export const ERROR = {