@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.
- package/README.md +68 -0
- package/dist/effects.d.ts +19 -0
- package/dist/effects.d.ts.map +1 -1
- package/dist/effects.js +23 -0
- package/dist/effects.js.map +1 -1
- package/dist/engine/bridge.d.ts +71 -0
- package/dist/engine/bridge.d.ts.map +1 -0
- package/dist/engine/bridge.js +277 -0
- package/dist/engine/bridge.js.map +1 -0
- package/dist/engine/ctx.d.ts +140 -0
- package/dist/engine/ctx.d.ts.map +1 -0
- package/dist/engine/ctx.js +834 -0
- package/dist/engine/ctx.js.map +1 -0
- package/dist/engine/frame.d.ts +69 -0
- package/dist/engine/frame.d.ts.map +1 -0
- package/dist/engine/frame.js +105 -0
- package/dist/engine/frame.js.map +1 -0
- package/dist/engine/host.d.ts +77 -0
- package/dist/engine/host.d.ts.map +1 -0
- package/dist/engine/host.js +134 -0
- package/dist/engine/host.js.map +1 -0
- package/dist/engine/worker-entry.d.ts +26 -0
- package/dist/engine/worker-entry.d.ts.map +1 -0
- package/dist/engine/worker-entry.js +175 -0
- package/dist/engine/worker-entry.js.map +1 -0
- package/dist/engine/worker.d.ts +156 -0
- package/dist/engine/worker.d.ts.map +1 -0
- package/dist/engine/worker.js +123 -0
- package/dist/engine/worker.js.map +1 -0
- package/dist/errors.d.ts +92 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +187 -2
- package/dist/errors.js.map +1 -1
- package/dist/grammar.d.ts.map +1 -1
- package/dist/grammar.js +561 -128
- package/dist/grammar.js.map +1 -1
- package/dist/index.d.ts +19 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/interpret.d.ts +59 -12
- package/dist/interpret.d.ts.map +1 -1
- package/dist/interpret.js +831 -613
- package/dist/interpret.js.map +1 -1
- package/dist/journal.d.ts +218 -9
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +306 -12
- package/dist/journal.js.map +1 -1
- package/dist/keys.d.ts +39 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +61 -0
- package/dist/keys.js.map +1 -1
- package/dist/library.d.ts +65 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +537 -0
- package/dist/library.js.map +1 -0
- package/dist/notify-fact.d.ts +8 -0
- package/dist/notify-fact.d.ts.map +1 -0
- package/dist/notify-fact.js +69 -0
- package/dist/notify-fact.js.map +1 -0
- package/dist/perform.d.ts +138 -0
- package/dist/perform.d.ts.map +1 -0
- package/dist/perform.js +1052 -0
- package/dist/perform.js.map +1 -0
- package/dist/pins.d.ts +102 -0
- package/dist/pins.d.ts.map +1 -0
- package/dist/pins.js +107 -0
- package/dist/pins.js.map +1 -0
- package/dist/primitives.d.ts +14 -0
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +45 -5
- package/dist/primitives.js.map +1 -1
- package/dist/sim.d.ts +24 -2
- package/dist/sim.d.ts.map +1 -1
- package/dist/sim.js +9 -1
- package/dist/sim.js.map +1 -1
- package/dist/syntax.d.ts +34 -0
- package/dist/syntax.d.ts.map +1 -0
- package/dist/syntax.js +178 -0
- package/dist/syntax.js.map +1 -0
- package/dist/transform/emit.d.ts +23 -0
- package/dist/transform/emit.d.ts.map +1 -0
- package/dist/transform/emit.js +934 -0
- package/dist/transform/emit.js.map +1 -0
- package/dist/transform/index.d.ts +34 -0
- package/dist/transform/index.d.ts.map +1 -0
- package/dist/transform/index.js +31 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/transform/scope.d.ts +58 -0
- package/dist/transform/scope.d.ts.map +1 -0
- package/dist/transform/scope.js +500 -0
- package/dist/transform/scope.js.map +1 -0
- package/dist/transform/seam.d.ts +78 -0
- package/dist/transform/seam.d.ts.map +1 -0
- package/dist/transform/seam.js +111 -0
- package/dist/transform/seam.js.map +1 -0
- package/dist/values.d.ts +35 -1
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +0 -0
- package/dist/values.js.map +1 -1
- package/package.json +9 -4
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `__ctx`: the WHOLE seam between the transformed program and the host.
|
|
3
|
+
*
|
|
4
|
+
* The transform emits a CLOSED function expression with zero free identifiers; the host
|
|
5
|
+
* evaluates it in a Compartment with ZERO endowments and passes this object as the call argument
|
|
6
|
+
* (the seam contract). So this file is the complete list of what a program can reach. Anything not
|
|
7
|
+
* here is not reachable, which is why the member list is a surface both sides hold each other to.
|
|
8
|
+
*
|
|
9
|
+
* Every law lives here, and every table it needs is IMPORTED. `library.ts` owns the curated method
|
|
10
|
+
* tables and the free builtins; `values.ts` owns freezing, birth-depth stamping and the crossing
|
|
11
|
+
* check; `keys.ts` owns key allocation; `journal.ts` owns the entries. Nothing in this file is a
|
|
12
|
+
* second copy of any of them: a copied table is a table that disagrees with the walker on its
|
|
13
|
+
* first edit, and the walker is the differential oracle.
|
|
14
|
+
*
|
|
15
|
+
* WHAT THIS FILE IS NOT: it is not the walker rewritten. The walker enforces these laws inline
|
|
16
|
+
* while it walks; here they are the host side of a native program's calls. The behaviours must be
|
|
17
|
+
* identical and the differential suite is what says so: same programs, walker and engine,
|
|
18
|
+
* identical journals (entry sequences and step keys, not merely output).
|
|
19
|
+
*/
|
|
20
|
+
import { type EffectHandler } from "../effects.js";
|
|
21
|
+
import type { Journal } from "../journal.js";
|
|
22
|
+
import type { RunPins } from "../pins.js";
|
|
23
|
+
/**
|
|
24
|
+
* A static per-call-site payload the transform computes from the input AST.
|
|
25
|
+
*
|
|
26
|
+
* It exists because the engine has NO AST at run time and one journal field is a function of one:
|
|
27
|
+
* a settled `race` records a `branchDigest` over its unwalked arms. Without this the engine could
|
|
28
|
+
* not produce a byte-identical entry for any race that settled, and the differential gate would
|
|
29
|
+
* fail on shape rather than on behaviour.
|
|
30
|
+
*/
|
|
31
|
+
export interface Site {
|
|
32
|
+
/** Branch key -> `digest(stripPositions(armBody))`, computed with the walker's own functions. */
|
|
33
|
+
readonly branchDigests?: Readonly<Record<string, unknown>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The seam. Fourteen members, and the count is the point: a member added here without a joint rule
|
|
37
|
+
* is a widening, and the transform's surface cell reddens on any call to a name not on this
|
|
38
|
+
* interface. Thirteen came with the seam contract; `callee` is the fourteenth, added under the
|
|
39
|
+
* adaptation invariant below.
|
|
40
|
+
*/
|
|
41
|
+
export interface EngineCtx {
|
|
42
|
+
/** L4013 step budget, plus the yield that keeps the macrotask queue alive and applies the cut. */
|
|
43
|
+
fuel(): void | Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Read a member: L4014 (no prototype reach, curated tables), L4020, L4018 on a computed key.
|
|
46
|
+
*
|
|
47
|
+
* `binding` is the cell read, taken as a third argument rather than a fifteenth member. A binding
|
|
48
|
+
* the transform classified as a CELL is emitted as `get(cell, "v", "x")`, and an absent OWN key
|
|
49
|
+
* means the declaration has not run yet, which is L2004 for that binding by name. PRESENCE is
|
|
50
|
+
* `hasOwn` and not truthiness, because `v: undefined` is a binding that HAS been initialised, to
|
|
51
|
+
* undefined. Without the argument, `get` is byte-unchanged.
|
|
52
|
+
*/
|
|
53
|
+
get(o: unknown, k: unknown, binding?: string): unknown;
|
|
54
|
+
/**
|
|
55
|
+
* Write a member: L2031, L2032, L4014, L4017, L4019. Answers `v`, as an assignment does.
|
|
56
|
+
*
|
|
57
|
+
* `binding` is the cell WRITE, taken as a fourth argument for the same reason `get` took a third.
|
|
58
|
+
* It is present ONLY on an ASSIGNMENT to a cell, never on the declaration's own initialising write,
|
|
59
|
+
* and an absent OWN key there means the declaration has not run: L2004 naming the binding, in the
|
|
60
|
+
* walker's assignment words, which are not the read's. The key is LEFT ABSENT by the refusal, so
|
|
61
|
+
* the declaration that has not run yet still initialises the binding when it does.
|
|
62
|
+
*/
|
|
63
|
+
set(o: unknown, k: unknown, v: unknown, binding?: string): unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Call a member. The single L4020 exception: a method is resolved AT the call and nowhere else.
|
|
66
|
+
*
|
|
67
|
+
* `optional` is `o.m?.()`, a flag rather than a fifteenth member. It guards a
|
|
68
|
+
* NULLISH MEMBER and nothing else (measured on the walker, `?.` softens neither L4014 nor L4011),
|
|
69
|
+
* and a short-circuited call evaluates NO ARGUMENT, which is why the optional form takes a thunk.
|
|
70
|
+
*
|
|
71
|
+
* `chain` is EVERYTHING WRITTEN AFTER the optional call, as a closure. A short-circuit swallows the
|
|
72
|
+
* whole rest of the chain, and only the host knows a short-circuit happened: measured, `o.z?.().x`
|
|
73
|
+
* on an absent member is `undefined` while `o.m?.().x` on a member that RETURNS undefined is L4010,
|
|
74
|
+
* and a guard on the returned value cannot tell those apart, so it would drop a refusal in silence.
|
|
75
|
+
* Handing the continuation here lets the one place that made the decision apply it.
|
|
76
|
+
*/
|
|
77
|
+
call(o: unknown, k: unknown, args: unknown[] | (() => unknown[] | Promise<unknown[]>), optional?: boolean, chain?: (value: unknown) => unknown): Promise<unknown>;
|
|
78
|
+
/** Stamp a freshly built container with this frame's depth (L2032's runtime half). */
|
|
79
|
+
born<T>(v: T): T;
|
|
80
|
+
/** A journalled primitive. */
|
|
81
|
+
effect(name: string, args: unknown[], site?: Site): Promise<unknown>;
|
|
82
|
+
/** A free builtin: called with `args`, or READ as a value when `args` is omitted. */
|
|
83
|
+
free(name: string, args?: unknown[]): unknown;
|
|
84
|
+
/** The thenable gate, before the host's await machinery can run a program closure. */
|
|
85
|
+
await(v: unknown): Promise<unknown>;
|
|
86
|
+
/** Template interpolation: L4018, no implicit conversion. */
|
|
87
|
+
template(parts: readonly string[], values: readonly unknown[]): string;
|
|
88
|
+
/** The binary operators' coercion law (L4018) and JavaScript's meaning. `===`/`!==` stay native. */
|
|
89
|
+
binary(op: string, l: unknown, r: unknown): unknown;
|
|
90
|
+
/** `-`, `+`, `~` under the same law, and `update` for the operand of `++`/`--`. `!`/`typeof` are native. */
|
|
91
|
+
unary(op: string, v: unknown): unknown;
|
|
92
|
+
/** The iterability law (L4015): arrays and strings, nothing else. */
|
|
93
|
+
iter(v: unknown): unknown[];
|
|
94
|
+
/** The L4011 refusal at a non-function callee. Emitted behind a `typeof`, so only the refusal runs. */
|
|
95
|
+
callee(v: unknown): unknown;
|
|
96
|
+
/** At the head of every emitted catch: rethrow the uncatchable, else the program-visible error. */
|
|
97
|
+
caught(e: unknown): unknown;
|
|
98
|
+
}
|
|
99
|
+
/** What a run hands the seam. */
|
|
100
|
+
export interface EngineRun {
|
|
101
|
+
readonly runId: string;
|
|
102
|
+
readonly programHash: string;
|
|
103
|
+
readonly journal: Journal;
|
|
104
|
+
readonly handler: EffectHandler;
|
|
105
|
+
readonly pins: RunPins;
|
|
106
|
+
readonly onLog?: (line: {
|
|
107
|
+
scope: string;
|
|
108
|
+
values: readonly unknown[];
|
|
109
|
+
}) => void;
|
|
110
|
+
readonly shouldStop?: () => string | undefined;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The seam, plus the one thing the HOST needs from it that the program must never see.
|
|
114
|
+
*
|
|
115
|
+
* `steps()` is the count charged against the step budget, which a `RunResult` reports so a host can
|
|
116
|
+
* see how close a program runs to the ceiling before the ceiling is what tells it. It is deliberately
|
|
117
|
+
* NOT a member of {@link EngineCtx}: everything on that interface is reachable from inside the
|
|
118
|
+
* compartment, and a program that can read its own fuel gauge can shape its behaviour around one.
|
|
119
|
+
*/
|
|
120
|
+
export declare function createEngine(run: EngineRun): {
|
|
121
|
+
readonly ctx: EngineCtx;
|
|
122
|
+
steps(): number;
|
|
123
|
+
};
|
|
124
|
+
/** The seam alone. */
|
|
125
|
+
export declare function createCtx(run: EngineRun): EngineCtx;
|
|
126
|
+
/**
|
|
127
|
+
* The engine broke its own contract, and no program may catch that.
|
|
128
|
+
*
|
|
129
|
+
* The one thing that reaches this today is a native `ReferenceError`. The emitted module is a closed
|
|
130
|
+
* expression with zero free identifiers, so nothing the program wrote can name a binding that is not
|
|
131
|
+
* there; a ReferenceError therefore means a TDZ read the transform's classifier missed or an emitter
|
|
132
|
+
* temporary read before it was bound. It is not the program's error, it is not converted to one, and
|
|
133
|
+
* it is never mapped to L2004 by reading its message - that mapping would make a compiler bug
|
|
134
|
+
* indistinguishable from the language rule it imitates.
|
|
135
|
+
*/
|
|
136
|
+
export declare class EngineFault extends Error {
|
|
137
|
+
readonly cause: unknown;
|
|
138
|
+
constructor(cause: unknown);
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=ctx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/engine/ctx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAS1C;;;;;;;GAOG;AACH,MAAM,WAAW,IAAI;IACnB,iGAAiG;IACjG,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC5D;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,kGAAkG;IAClG,IAAI,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B;;;;;;;;OAQG;IACH,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACvD;;;;;;;;OAQG;IACH,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACnE;;;;;;;;;;;;OAYG;IACH,IAAI,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