@cotal-ai/lang 0.23.0 → 0.25.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.
Files changed (101) hide show
  1. package/README.md +68 -0
  2. package/dist/effects.d.ts +19 -0
  3. package/dist/effects.d.ts.map +1 -1
  4. package/dist/effects.js +23 -0
  5. package/dist/effects.js.map +1 -1
  6. package/dist/engine/bridge.d.ts +71 -0
  7. package/dist/engine/bridge.d.ts.map +1 -0
  8. package/dist/engine/bridge.js +277 -0
  9. package/dist/engine/bridge.js.map +1 -0
  10. package/dist/engine/ctx.d.ts +140 -0
  11. package/dist/engine/ctx.d.ts.map +1 -0
  12. package/dist/engine/ctx.js +834 -0
  13. package/dist/engine/ctx.js.map +1 -0
  14. package/dist/engine/frame.d.ts +69 -0
  15. package/dist/engine/frame.d.ts.map +1 -0
  16. package/dist/engine/frame.js +105 -0
  17. package/dist/engine/frame.js.map +1 -0
  18. package/dist/engine/host.d.ts +77 -0
  19. package/dist/engine/host.d.ts.map +1 -0
  20. package/dist/engine/host.js +134 -0
  21. package/dist/engine/host.js.map +1 -0
  22. package/dist/engine/worker-entry.d.ts +26 -0
  23. package/dist/engine/worker-entry.d.ts.map +1 -0
  24. package/dist/engine/worker-entry.js +175 -0
  25. package/dist/engine/worker-entry.js.map +1 -0
  26. package/dist/engine/worker.d.ts +156 -0
  27. package/dist/engine/worker.d.ts.map +1 -0
  28. package/dist/engine/worker.js +123 -0
  29. package/dist/engine/worker.js.map +1 -0
  30. package/dist/errors.d.ts +92 -2
  31. package/dist/errors.d.ts.map +1 -1
  32. package/dist/errors.js +187 -2
  33. package/dist/errors.js.map +1 -1
  34. package/dist/grammar.d.ts.map +1 -1
  35. package/dist/grammar.js +561 -128
  36. package/dist/grammar.js.map +1 -1
  37. package/dist/index.d.ts +19 -6
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +19 -6
  40. package/dist/index.js.map +1 -1
  41. package/dist/interpret.d.ts +59 -12
  42. package/dist/interpret.d.ts.map +1 -1
  43. package/dist/interpret.js +831 -613
  44. package/dist/interpret.js.map +1 -1
  45. package/dist/journal.d.ts +218 -9
  46. package/dist/journal.d.ts.map +1 -1
  47. package/dist/journal.js +306 -12
  48. package/dist/journal.js.map +1 -1
  49. package/dist/keys.d.ts +39 -1
  50. package/dist/keys.d.ts.map +1 -1
  51. package/dist/keys.js +61 -0
  52. package/dist/keys.js.map +1 -1
  53. package/dist/library.d.ts +65 -0
  54. package/dist/library.d.ts.map +1 -0
  55. package/dist/library.js +537 -0
  56. package/dist/library.js.map +1 -0
  57. package/dist/notify-fact.d.ts +8 -0
  58. package/dist/notify-fact.d.ts.map +1 -0
  59. package/dist/notify-fact.js +69 -0
  60. package/dist/notify-fact.js.map +1 -0
  61. package/dist/perform.d.ts +138 -0
  62. package/dist/perform.d.ts.map +1 -0
  63. package/dist/perform.js +1052 -0
  64. package/dist/perform.js.map +1 -0
  65. package/dist/pins.d.ts +102 -0
  66. package/dist/pins.d.ts.map +1 -0
  67. package/dist/pins.js +107 -0
  68. package/dist/pins.js.map +1 -0
  69. package/dist/primitives.d.ts +14 -0
  70. package/dist/primitives.d.ts.map +1 -1
  71. package/dist/primitives.js +45 -5
  72. package/dist/primitives.js.map +1 -1
  73. package/dist/sim.d.ts +24 -2
  74. package/dist/sim.d.ts.map +1 -1
  75. package/dist/sim.js +9 -1
  76. package/dist/sim.js.map +1 -1
  77. package/dist/syntax.d.ts +34 -0
  78. package/dist/syntax.d.ts.map +1 -0
  79. package/dist/syntax.js +178 -0
  80. package/dist/syntax.js.map +1 -0
  81. package/dist/transform/emit.d.ts +23 -0
  82. package/dist/transform/emit.d.ts.map +1 -0
  83. package/dist/transform/emit.js +934 -0
  84. package/dist/transform/emit.js.map +1 -0
  85. package/dist/transform/index.d.ts +34 -0
  86. package/dist/transform/index.d.ts.map +1 -0
  87. package/dist/transform/index.js +31 -0
  88. package/dist/transform/index.js.map +1 -0
  89. package/dist/transform/scope.d.ts +58 -0
  90. package/dist/transform/scope.d.ts.map +1 -0
  91. package/dist/transform/scope.js +500 -0
  92. package/dist/transform/scope.js.map +1 -0
  93. package/dist/transform/seam.d.ts +78 -0
  94. package/dist/transform/seam.d.ts.map +1 -0
  95. package/dist/transform/seam.js +111 -0
  96. package/dist/transform/seam.js.map +1 -0
  97. package/dist/values.d.ts +35 -1
  98. package/dist/values.d.ts.map +1 -1
  99. package/dist/values.js +0 -0
  100. package/dist/values.js.map +1 -1
  101. package/package.json +9 -4
package/dist/syntax.js ADDED
@@ -0,0 +1,178 @@
1
+ /**
2
+ * The syntax table: every node type acorn can produce, sorted into the sets the language is made of.
3
+ *
4
+ * ONE TABLE, READ BY BOTH HALVES. The validator admits exactly {@link ADMITTED_NODES} and
5
+ * {@link STRUCTURAL_NODES}, refuses each row of {@link FORBIDDEN_NODES} with its own code, and refuses
6
+ * everything else with L1029. The interpreter executes exactly the admitted set. `surface.smoke`
7
+ * holds the two halves to this file: every admitted node type is executed by a program, every
8
+ * `case` label in the interpreter's node switches is on this table, and every node type acorn knows
9
+ * lands in exactly one set. Before this table existed the two halves were two hand-kept lists, and
10
+ * `x++`, `?.`, rest parameters and `**` were admitted by one and refused by the other.
11
+ */
12
+ /** Node types the interpreter executes. A validated program is made of these and nothing else. */
13
+ export const ADMITTED_NODES = new Set([
14
+ // statements
15
+ "Program",
16
+ "ExpressionStatement",
17
+ "VariableDeclaration",
18
+ "FunctionDeclaration",
19
+ "BlockStatement",
20
+ "IfStatement",
21
+ "WhileStatement",
22
+ "ForStatement",
23
+ "ForOfStatement",
24
+ "ReturnStatement",
25
+ "BreakStatement",
26
+ "ContinueStatement",
27
+ "ThrowStatement",
28
+ "TryStatement",
29
+ "SwitchStatement",
30
+ "EmptyStatement",
31
+ // expressions
32
+ "Literal",
33
+ "Identifier",
34
+ "TemplateLiteral",
35
+ "ArrayExpression",
36
+ "ObjectExpression",
37
+ "MemberExpression",
38
+ "ChainExpression",
39
+ "UnaryExpression",
40
+ "UpdateExpression",
41
+ "BinaryExpression",
42
+ "LogicalExpression",
43
+ "ConditionalExpression",
44
+ "AssignmentExpression",
45
+ "AwaitExpression",
46
+ "ArrowFunctionExpression",
47
+ "FunctionExpression",
48
+ "CallExpression",
49
+ ]);
50
+ /**
51
+ * Node types that only occur INSIDE an admitted node and are executed as part of it: a `Property`
52
+ * inside an object literal, a `SwitchCase` inside a `switch`, a pattern inside a declaration.
53
+ */
54
+ export const STRUCTURAL_NODES = new Set([
55
+ "VariableDeclarator",
56
+ "Property",
57
+ "SpreadElement",
58
+ "RestElement",
59
+ "AssignmentPattern",
60
+ "ObjectPattern",
61
+ "ArrayPattern",
62
+ "TemplateElement",
63
+ "SwitchCase",
64
+ "CatchClause",
65
+ ]);
66
+ /** Node types rejected outright, with the code and the repair to suggest. */
67
+ export const FORBIDDEN_NODES = Object.freeze({
68
+ ClassDeclaration: {
69
+ code: "L1001",
70
+ cause: "There are no classes in this language. State lives in records and behaviour lives in functions.",
71
+ fix: "Replace the class with a function that returns a record.",
72
+ },
73
+ ClassExpression: {
74
+ code: "L1001",
75
+ cause: "There are no classes in this language. State lives in records and behaviour lives in functions.",
76
+ fix: "Replace the class with a function that returns a record.",
77
+ },
78
+ ThisExpression: {
79
+ code: "L1002",
80
+ cause: "`this` does not exist, so nothing can capture a calling context by accident.",
81
+ fix: "Pass what the function needs as an argument.",
82
+ },
83
+ ForInStatement: {
84
+ code: "L1004",
85
+ cause: "`for...in` walks an unspecified order and reaches inherited names, so it cannot be deterministic.",
86
+ fix: "Iterate explicitly: `for (const k of keys(record)) { ... }`.",
87
+ },
88
+ YieldExpression: {
89
+ code: "L1005",
90
+ cause: "Generators suspend and resume outside the effect journal, so a resumed run could not reproduce them.",
91
+ fix: "Use a loop, and `await` the effects inside it.",
92
+ },
93
+ TaggedTemplateExpression: {
94
+ code: "L1018",
95
+ cause: "A tagged template runs user code during evaluation of a literal, which hides an effect inside what looks like data.",
96
+ fix: "Use a plain template literal, or call the function explicitly.",
97
+ },
98
+ NewExpression: {
99
+ code: "L1019",
100
+ cause: "There are no constructors, so `new` has nothing to construct.",
101
+ fix: "Build a record literal, or call a function that returns one.",
102
+ },
103
+ ImportDeclaration: {
104
+ code: "L1020",
105
+ cause: "A program is exactly one module, because a run pins to the content hash of its source.",
106
+ fix: "Define the function in this file. Shared procedures are ordinary functions.",
107
+ },
108
+ ImportExpression: {
109
+ code: "L1020",
110
+ cause: "A program is exactly one module, because a run pins to the content hash of its source; a dynamic `import()` would load code the hash does not cover.",
111
+ fix: "Define the function in this file. Shared procedures are ordinary functions.",
112
+ },
113
+ ExportNamedDeclaration: {
114
+ code: "L1020",
115
+ cause: "A program is exactly one module and has nothing to export to.",
116
+ fix: "Remove the `export`.",
117
+ },
118
+ ExportDefaultDeclaration: {
119
+ code: "L1020",
120
+ cause: "A program is exactly one module and has nothing to export to.",
121
+ fix: "Remove the `export`.",
122
+ },
123
+ ExportAllDeclaration: {
124
+ code: "L1020",
125
+ cause: "A program is exactly one module and has nothing to export to.",
126
+ fix: "Remove the `export`.",
127
+ },
128
+ DoWhileStatement: {
129
+ code: "L1022",
130
+ cause: "`do...while` is not in the language.",
131
+ fix: "Use `while` with the condition checked first, or a `for` loop.",
132
+ },
133
+ LabeledStatement: {
134
+ code: "L1017",
135
+ cause: "Labels turn the derived flowchart's back-edges into arbitrary jumps.",
136
+ fix: "Restructure with a helper function or a boolean flag.",
137
+ },
138
+ SequenceExpression: {
139
+ code: "L1026",
140
+ cause: "The comma operator evaluates several expressions and keeps only the last, which hides work inside one expression.",
141
+ fix: "Write one statement per expression.",
142
+ },
143
+ MetaProperty: {
144
+ code: "L1020",
145
+ cause: "`import.meta` and `new.target` describe a module system and constructors, and this language has neither.",
146
+ fix: "Use `run()` for this run's own metadata.",
147
+ },
148
+ DebuggerStatement: {
149
+ code: "L1029",
150
+ cause: "`debugger` addresses a host debugger, and there is no host to address.",
151
+ fix: "Use `log(...)` to trace a value.",
152
+ },
153
+ });
154
+ /** Node types that occur only inside a forbidden node and are reported through their parent's row. */
155
+ export const FORBIDDEN_CHILDREN = Object.freeze([
156
+ "ClassBody",
157
+ "MethodDefinition",
158
+ "PropertyDefinition",
159
+ "StaticBlock",
160
+ "PrivateIdentifier",
161
+ "Super",
162
+ "ImportSpecifier",
163
+ "ImportDefaultSpecifier",
164
+ "ImportNamespaceSpecifier",
165
+ "ExportSpecifier",
166
+ ]);
167
+ /**
168
+ * Every node type acorn 8 emits for `ecmaVersion: 2023, sourceType: "module"`, whether or not it
169
+ * is in the language. `surface.smoke` asserts each one lands in exactly one of the sets above, so a
170
+ * node type acorn adds or one this file forgets is a red suite rather than a runtime surprise.
171
+ */
172
+ export const KNOWN_NODES = Object.freeze([
173
+ ...ADMITTED_NODES,
174
+ ...STRUCTURAL_NODES,
175
+ ...Object.keys(FORBIDDEN_NODES),
176
+ ...FORBIDDEN_CHILDREN,
177
+ ]);
178
+ //# sourceMappingURL=syntax.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax.js","sourceRoot":"","sources":["../src/syntax.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,kGAAkG;AAClG,MAAM,CAAC,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC;IACzD,aAAa;IACb,SAAS;IACT,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,gBAAgB;IAChB,aAAa;IACb,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,mBAAmB;IACnB,gBAAgB;IAChB,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,cAAc;IACd,SAAS;IACT,YAAY;IACZ,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,mBAAmB;IACnB,uBAAuB;IACvB,sBAAsB;IACtB,iBAAiB;IACjB,yBAAyB;IACzB,oBAAoB;IACpB,gBAAgB;CAC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CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The emitter: one rule per admitted node type, and every rule that carries a law routes it through
3
+ * the seam rather than restating it.
4
+ *
5
+ * The walk order here is the walker's walk order, deliberately and line by line: a journal's step
6
+ * keys are occurrence counters allocated at the call, so two engines agree on a journal only if they
7
+ * agree on the ORDER effects are reached in. Where this file departs from the shape of
8
+ * `interpret.ts` it is because native JavaScript already has the meaning (block scoping, `switch`
9
+ * selection, `try`/`finally` completions) and re-deriving it would be a second implementation to
10
+ * keep in step.
11
+ */
12
+ import { type AnyNode } from "./scope.js";
13
+ import { type Names } from "./seam.js";
14
+ export interface Emission {
15
+ readonly module: string;
16
+ /** How many times each seam member is reached. A check reports its count, not merely that it ran. */
17
+ readonly sites: Readonly<Record<string, number>>;
18
+ /** Which SURFACED-but-unruled members this emission needed. Empty is the landing condition. */
19
+ readonly proposed: readonly string[];
20
+ readonly names: Names;
21
+ }
22
+ export declare function emit(program: AnyNode): Emission;
23
+ //# sourceMappingURL=emit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/transform/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAA0B,KAAK,OAAO,EAAgB,MAAM,YAAY,CAAC;AAEhF,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC;AASlD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qGAAqG;IACrG,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,+FAA+F;IAC/F,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAg7BD,wBAAgB,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAO/C"}