@almadar/evaluator 2.30.0 → 2.32.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/dist/{index-BjtK8dP9.d.ts → index-rPqsFqVO.d.ts} +11 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/dist/operators/index.d.ts +1 -1
- package/dist/operators/index.js +3 -2
- package/dist/operators/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -268,6 +268,17 @@ type Evaluator$2 = (expr: SExpr, ctx: EvaluationContext) => unknown;
|
|
|
268
268
|
* Supports two formats:
|
|
269
269
|
* - Array of pairs: ["let", [["x", 10], ["y", 20]], body]
|
|
270
270
|
* - Object style: ["let", {"x": 10, "y": 20}, body]
|
|
271
|
+
*
|
|
272
|
+
* Sequential (`let*`) semantics: each binding's value expression can
|
|
273
|
+
* reference any EARLIER binding in the same `let` via `@<name>` — matches
|
|
274
|
+
* `@almadar/runtime`'s `EffectExecutor` `let` case (its own, independent
|
|
275
|
+
* implementation, which already threads bindings this way) and how `.lolo`
|
|
276
|
+
* is authored in practice: multi-step chains where a later step's formula
|
|
277
|
+
* builds on an earlier one (e.g. std-evade-chase's `chase` tick computing
|
|
278
|
+
* `nc2x` from `nc1x`). Evaluating every binding against the original,
|
|
279
|
+
* unmodified `ctx` (the prior behavior here) left every cross-binding
|
|
280
|
+
* reference unresolved (`undefined`), silently corrupting any `let` with
|
|
281
|
+
* dependent bindings.
|
|
271
282
|
*/
|
|
272
283
|
declare function evalLet(args: SExpr[], evaluate: Evaluator$2, ctx: EvaluationContext): unknown;
|
|
273
284
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SExpr } from '@almadar/core';
|
|
2
2
|
export { CORE_BINDINGS, CoreBinding, Expression, ExpressionSchema, ParsedBinding, SExpr, SExprAtom, SExprSchema, collectBindings, getArgs, getOperator, isBinding, isSExpr, isSExprAtom, isSExprCall, isValidBinding, parseBinding, sexpr, walkSExpr } from '@almadar/core';
|
|
3
|
-
import { E as EvaluationContext } from './index-
|
|
4
|
-
export { U as UserContext, c as createChildContext, a as createEffectContext, b as createMinimalContext, e as evalAbs, d as evalAdd, f as evalAnd, g as evalAtomic, h as evalCallService, i as evalCeil, j as evalClamp, k as evalConcat, l as evalCount, m as evalDecrement, n as evalDeref, o as evalDespawn, p as evalDivide, q as evalDo, r as evalEmit, s as evalEmpty, t as evalEqual, u as evalFilter, v as evalFind, w as evalFirst, x as evalFloor, y as evalFn, z as evalGreaterThan, A as evalGreaterThanOrEqual, B as evalIf, C as evalIncludes, D as evalIncrement, F as evalLast, G as evalLessThan, H as evalLessThanOrEqual, I as evalLet, J as evalList, K as evalMap, L as evalMatches, M as evalMax, N as evalMin, O as evalModulo, P as evalMultiply, Q as evalNavigate, R as evalNot, S as evalNotEqual, T as evalNotify, V as evalNth, W as evalOr, X as evalPersist, Y as evalRef, Z as evalRenderUI, _ as evalRound, $ as evalSet, a0 as evalSetDynamic, a1 as evalSpawn, a2 as evalSubtract, a3 as evalSum, a4 as evalSwap, a5 as evalWatch, a6 as evalWhen, a7 as resolveBinding } from './index-
|
|
3
|
+
import { E as EvaluationContext } from './index-rPqsFqVO.js';
|
|
4
|
+
export { U as UserContext, c as createChildContext, a as createEffectContext, b as createMinimalContext, e as evalAbs, d as evalAdd, f as evalAnd, g as evalAtomic, h as evalCallService, i as evalCeil, j as evalClamp, k as evalConcat, l as evalCount, m as evalDecrement, n as evalDeref, o as evalDespawn, p as evalDivide, q as evalDo, r as evalEmit, s as evalEmpty, t as evalEqual, u as evalFilter, v as evalFind, w as evalFirst, x as evalFloor, y as evalFn, z as evalGreaterThan, A as evalGreaterThanOrEqual, B as evalIf, C as evalIncludes, D as evalIncrement, F as evalLast, G as evalLessThan, H as evalLessThanOrEqual, I as evalLet, J as evalList, K as evalMap, L as evalMatches, M as evalMax, N as evalMin, O as evalModulo, P as evalMultiply, Q as evalNavigate, R as evalNot, S as evalNotEqual, T as evalNotify, V as evalNth, W as evalOr, X as evalPersist, Y as evalRef, Z as evalRenderUI, _ as evalRound, $ as evalSet, a0 as evalSetDynamic, a1 as evalSpawn, a2 as evalSubtract, a3 as evalSum, a4 as evalSwap, a5 as evalWatch, a6 as evalWhen, a7 as resolveBinding } from './index-rPqsFqVO.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* S-Expression Evaluator
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isSExpr, isBinding, getOperator, getArgs, isFieldValue, isEventPayloadValue, isSessionHistoryEntry, isPlanSnapshot, OrbitalZodSchema, safeParseOrbitalSchema } from '@almadar/core';
|
|
2
2
|
export { CORE_BINDINGS, ExpressionSchema, SExprSchema, collectBindings, getArgs, getOperator, isBinding, isSExpr, isSExprAtom, isSExprCall, isValidBinding, parseBinding, sexpr, walkSExpr } from '@almadar/core';
|
|
3
|
+
import { createRequire } from 'module';
|
|
3
4
|
|
|
4
5
|
// types/expression.ts
|
|
5
6
|
|
|
@@ -103,6 +104,27 @@ function resolveBinding(binding, ctx) {
|
|
|
103
104
|
}
|
|
104
105
|
return value;
|
|
105
106
|
}
|
|
107
|
+
var require2 = createRequire(import.meta.url);
|
|
108
|
+
var canonicalOperators = require2("@almadar/std/canonical-operators.json");
|
|
109
|
+
var ARITY = new Map(
|
|
110
|
+
Object.entries(canonicalOperators.operators).map(
|
|
111
|
+
([name, meta]) => [
|
|
112
|
+
name,
|
|
113
|
+
{ min: meta.minArity ?? 0, max: meta.maxArity === void 0 ? null : meta.maxArity }
|
|
114
|
+
]
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
function assertOperatorArity(op, argCount) {
|
|
118
|
+
const bounds = ARITY.get(op);
|
|
119
|
+
if (!bounds) return;
|
|
120
|
+
const { min, max } = bounds;
|
|
121
|
+
if (argCount < min || max !== null && argCount > max) {
|
|
122
|
+
const range = max === null ? `at least ${min}` : min === max ? `${min}` : `${min}..${max}`;
|
|
123
|
+
throw new Error(
|
|
124
|
+
`(${op} \u2026): expected ${range} argument(s), got ${argCount} \u2014 same bounds the compiled path enforces (canonical-operators.json)`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
106
128
|
|
|
107
129
|
// operators/arithmetic.ts
|
|
108
130
|
function evalAdd(args, evaluate2, ctx) {
|
|
@@ -276,11 +298,12 @@ function evalLet(args, evaluate2, ctx) {
|
|
|
276
298
|
const body = args[1];
|
|
277
299
|
const bindingPairs = Array.isArray(rawBindings) ? rawBindings.map((b) => [b[0], b[1]]) : Object.entries(rawBindings);
|
|
278
300
|
const locals = /* @__PURE__ */ new Map();
|
|
301
|
+
let childCtx = ctx;
|
|
279
302
|
for (const [name, valueExpr] of bindingPairs) {
|
|
280
|
-
const value = evaluate2(valueExpr,
|
|
303
|
+
const value = evaluate2(valueExpr, childCtx);
|
|
281
304
|
locals.set(name, value);
|
|
305
|
+
childCtx = createChildContext(ctx, locals);
|
|
282
306
|
}
|
|
283
|
-
const childCtx = createChildContext(ctx, locals);
|
|
284
307
|
return evaluate2(body, childCtx);
|
|
285
308
|
}
|
|
286
309
|
function evalDo(args, evaluate2, ctx) {
|
|
@@ -972,6 +995,8 @@ function evalWithItem(expr, evaluate2, ctx, item, index) {
|
|
|
972
995
|
let result = evaluate2(expr, childCtx);
|
|
973
996
|
if (isSExpr(result)) {
|
|
974
997
|
result = evalWithItem(result, evaluate2, childCtx, item, index);
|
|
998
|
+
} else if (typeof result === "function") {
|
|
999
|
+
result = result(item, evaluate2, childCtx);
|
|
975
1000
|
}
|
|
976
1001
|
return result;
|
|
977
1002
|
}
|
|
@@ -3810,6 +3835,7 @@ var SExpressionEvaluator = class {
|
|
|
3810
3835
|
* Dispatch to the appropriate operator implementation.
|
|
3811
3836
|
*/
|
|
3812
3837
|
dispatchOperator(op, args, ctx) {
|
|
3838
|
+
assertOperatorArity(op, args.length);
|
|
3813
3839
|
const evaluate2 = (expr, c) => this.evaluate(expr, c);
|
|
3814
3840
|
switch (op) {
|
|
3815
3841
|
// Arithmetic
|