@rcrsr/rill 0.1.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/LICENSE +21 -0
- package/README.md +187 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +69 -0
- package/dist/cli.js.map +1 -0
- package/dist/demo.d.ts +6 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/demo.js +121 -0
- package/dist/demo.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/lexer/errors.d.ts +9 -0
- package/dist/lexer/errors.d.ts.map +1 -0
- package/dist/lexer/errors.js +12 -0
- package/dist/lexer/errors.js.map +1 -0
- package/dist/lexer/helpers.d.ts +14 -0
- package/dist/lexer/helpers.d.ts.map +1 -0
- package/dist/lexer/helpers.js +30 -0
- package/dist/lexer/helpers.js.map +1 -0
- package/dist/lexer/index.d.ts +8 -0
- package/dist/lexer/index.d.ts.map +1 -0
- package/dist/lexer/index.js +8 -0
- package/dist/lexer/index.js.map +1 -0
- package/dist/lexer/operators.d.ts +11 -0
- package/dist/lexer/operators.d.ts.map +1 -0
- package/dist/lexer/operators.js +58 -0
- package/dist/lexer/operators.js.map +1 -0
- package/dist/lexer/readers.d.ts +12 -0
- package/dist/lexer/readers.d.ts.map +1 -0
- package/dist/lexer/readers.js +144 -0
- package/dist/lexer/readers.js.map +1 -0
- package/dist/lexer/state.d.ts +18 -0
- package/dist/lexer/state.d.ts.map +1 -0
- package/dist/lexer/state.js +37 -0
- package/dist/lexer/state.js.map +1 -0
- package/dist/lexer/tokenizer.d.ts +9 -0
- package/dist/lexer/tokenizer.d.ts.map +1 -0
- package/dist/lexer/tokenizer.js +100 -0
- package/dist/lexer/tokenizer.js.map +1 -0
- package/dist/lexer.d.ts +19 -0
- package/dist/lexer.d.ts.map +1 -0
- package/dist/lexer.js +344 -0
- package/dist/lexer.js.map +1 -0
- package/dist/parser/arithmetic.d.ts +16 -0
- package/dist/parser/arithmetic.d.ts.map +1 -0
- package/dist/parser/arithmetic.js +128 -0
- package/dist/parser/arithmetic.js.map +1 -0
- package/dist/parser/boolean.d.ts +15 -0
- package/dist/parser/boolean.d.ts.map +1 -0
- package/dist/parser/boolean.js +20 -0
- package/dist/parser/boolean.js.map +1 -0
- package/dist/parser/control-flow.d.ts +56 -0
- package/dist/parser/control-flow.d.ts.map +1 -0
- package/dist/parser/control-flow.js +167 -0
- package/dist/parser/control-flow.js.map +1 -0
- package/dist/parser/expressions.d.ts +23 -0
- package/dist/parser/expressions.d.ts.map +1 -0
- package/dist/parser/expressions.js +950 -0
- package/dist/parser/expressions.js.map +1 -0
- package/dist/parser/extraction.d.ts +48 -0
- package/dist/parser/extraction.d.ts.map +1 -0
- package/dist/parser/extraction.js +279 -0
- package/dist/parser/extraction.js.map +1 -0
- package/dist/parser/functions.d.ts +20 -0
- package/dist/parser/functions.d.ts.map +1 -0
- package/dist/parser/functions.js +96 -0
- package/dist/parser/functions.js.map +1 -0
- package/dist/parser/helpers.d.ts +94 -0
- package/dist/parser/helpers.d.ts.map +1 -0
- package/dist/parser/helpers.js +225 -0
- package/dist/parser/helpers.js.map +1 -0
- package/dist/parser/index.d.ts +49 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +73 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/literals.d.ts +37 -0
- package/dist/parser/literals.d.ts.map +1 -0
- package/dist/parser/literals.js +373 -0
- package/dist/parser/literals.js.map +1 -0
- package/dist/parser/parser-collect.d.ts +16 -0
- package/dist/parser/parser-collect.d.ts.map +1 -0
- package/dist/parser/parser-collect.js +125 -0
- package/dist/parser/parser-collect.js.map +1 -0
- package/dist/parser/parser-control.d.ts +20 -0
- package/dist/parser/parser-control.d.ts.map +1 -0
- package/dist/parser/parser-control.js +120 -0
- package/dist/parser/parser-control.js.map +1 -0
- package/dist/parser/parser-expr.d.ts +37 -0
- package/dist/parser/parser-expr.d.ts.map +1 -0
- package/dist/parser/parser-expr.js +639 -0
- package/dist/parser/parser-expr.js.map +1 -0
- package/dist/parser/parser-extract.d.ts +17 -0
- package/dist/parser/parser-extract.d.ts.map +1 -0
- package/dist/parser/parser-extract.js +222 -0
- package/dist/parser/parser-extract.js.map +1 -0
- package/dist/parser/parser-functions.d.ts +21 -0
- package/dist/parser/parser-functions.d.ts.map +1 -0
- package/dist/parser/parser-functions.js +155 -0
- package/dist/parser/parser-functions.js.map +1 -0
- package/dist/parser/parser-literals.d.ts +22 -0
- package/dist/parser/parser-literals.d.ts.map +1 -0
- package/dist/parser/parser-literals.js +288 -0
- package/dist/parser/parser-literals.js.map +1 -0
- package/dist/parser/parser-script.d.ts +21 -0
- package/dist/parser/parser-script.d.ts.map +1 -0
- package/dist/parser/parser-script.js +174 -0
- package/dist/parser/parser-script.js.map +1 -0
- package/dist/parser/parser-variables.d.ts +20 -0
- package/dist/parser/parser-variables.d.ts.map +1 -0
- package/dist/parser/parser-variables.js +146 -0
- package/dist/parser/parser-variables.js.map +1 -0
- package/dist/parser/parser.d.ts +49 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +54 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/script.d.ts +14 -0
- package/dist/parser/script.d.ts.map +1 -0
- package/dist/parser/script.js +196 -0
- package/dist/parser/script.js.map +1 -0
- package/dist/parser/state.d.ts +40 -0
- package/dist/parser/state.d.ts.map +1 -0
- package/dist/parser/state.js +129 -0
- package/dist/parser/state.js.map +1 -0
- package/dist/parser/variables.d.ts +10 -0
- package/dist/parser/variables.d.ts.map +1 -0
- package/dist/parser/variables.js +215 -0
- package/dist/parser/variables.js.map +1 -0
- package/dist/runtime/ast-equals.d.ts +13 -0
- package/dist/runtime/ast-equals.d.ts.map +1 -0
- package/dist/runtime/ast-equals.js +447 -0
- package/dist/runtime/ast-equals.js.map +1 -0
- package/dist/runtime/builtins.d.ts +13 -0
- package/dist/runtime/builtins.d.ts.map +1 -0
- package/dist/runtime/builtins.js +180 -0
- package/dist/runtime/builtins.js.map +1 -0
- package/dist/runtime/callable.d.ts +88 -0
- package/dist/runtime/callable.d.ts.map +1 -0
- package/dist/runtime/callable.js +98 -0
- package/dist/runtime/callable.js.map +1 -0
- package/dist/runtime/context.d.ts +13 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/context.js +73 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/core/callable.d.ts +171 -0
- package/dist/runtime/core/callable.d.ts.map +1 -0
- package/dist/runtime/core/callable.js +246 -0
- package/dist/runtime/core/callable.js.map +1 -0
- package/dist/runtime/core/context.d.ts +29 -0
- package/dist/runtime/core/context.d.ts.map +1 -0
- package/dist/runtime/core/context.js +154 -0
- package/dist/runtime/core/context.js.map +1 -0
- package/dist/runtime/core/equals.d.ts +9 -0
- package/dist/runtime/core/equals.d.ts.map +1 -0
- package/dist/runtime/core/equals.js +381 -0
- package/dist/runtime/core/equals.js.map +1 -0
- package/dist/runtime/core/eval/base.d.ts +65 -0
- package/dist/runtime/core/eval/base.d.ts.map +1 -0
- package/dist/runtime/core/eval/base.js +112 -0
- package/dist/runtime/core/eval/base.js.map +1 -0
- package/dist/runtime/core/eval/evaluator.d.ts +47 -0
- package/dist/runtime/core/eval/evaluator.d.ts.map +1 -0
- package/dist/runtime/core/eval/evaluator.js +73 -0
- package/dist/runtime/core/eval/evaluator.js.map +1 -0
- package/dist/runtime/core/eval/index.d.ts +57 -0
- package/dist/runtime/core/eval/index.d.ts.map +1 -0
- package/dist/runtime/core/eval/index.js +95 -0
- package/dist/runtime/core/eval/index.js.map +1 -0
- package/dist/runtime/core/eval/mixins/annotations.d.ts +19 -0
- package/dist/runtime/core/eval/mixins/annotations.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/annotations.js +146 -0
- package/dist/runtime/core/eval/mixins/annotations.js.map +1 -0
- package/dist/runtime/core/eval/mixins/closures.d.ts +49 -0
- package/dist/runtime/core/eval/mixins/closures.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/closures.js +479 -0
- package/dist/runtime/core/eval/mixins/closures.js.map +1 -0
- package/dist/runtime/core/eval/mixins/collections.d.ts +24 -0
- package/dist/runtime/core/eval/mixins/collections.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/collections.js +466 -0
- package/dist/runtime/core/eval/mixins/collections.js.map +1 -0
- package/dist/runtime/core/eval/mixins/control-flow.d.ts +27 -0
- package/dist/runtime/core/eval/mixins/control-flow.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/control-flow.js +369 -0
- package/dist/runtime/core/eval/mixins/control-flow.js.map +1 -0
- package/dist/runtime/core/eval/mixins/core.d.ts +24 -0
- package/dist/runtime/core/eval/mixins/core.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/core.js +335 -0
- package/dist/runtime/core/eval/mixins/core.js.map +1 -0
- package/dist/runtime/core/eval/mixins/expressions.d.ts +19 -0
- package/dist/runtime/core/eval/mixins/expressions.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/expressions.js +202 -0
- package/dist/runtime/core/eval/mixins/expressions.js.map +1 -0
- package/dist/runtime/core/eval/mixins/extraction.d.ts +10 -0
- package/dist/runtime/core/eval/mixins/extraction.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/extraction.js +250 -0
- package/dist/runtime/core/eval/mixins/extraction.js.map +1 -0
- package/dist/runtime/core/eval/mixins/literals.d.ts +23 -0
- package/dist/runtime/core/eval/mixins/literals.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/literals.js +180 -0
- package/dist/runtime/core/eval/mixins/literals.js.map +1 -0
- package/dist/runtime/core/eval/mixins/types.d.ts +20 -0
- package/dist/runtime/core/eval/mixins/types.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/types.js +109 -0
- package/dist/runtime/core/eval/mixins/types.js.map +1 -0
- package/dist/runtime/core/eval/mixins/variables.d.ts +34 -0
- package/dist/runtime/core/eval/mixins/variables.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/variables.js +247 -0
- package/dist/runtime/core/eval/mixins/variables.js.map +1 -0
- package/dist/runtime/core/eval/types.d.ts +41 -0
- package/dist/runtime/core/eval/types.d.ts.map +1 -0
- package/dist/runtime/core/eval/types.js +10 -0
- package/dist/runtime/core/eval/types.js.map +1 -0
- package/dist/runtime/core/evaluate.d.ts +42 -0
- package/dist/runtime/core/evaluate.d.ts.map +1 -0
- package/dist/runtime/core/evaluate.debug.js +1251 -0
- package/dist/runtime/core/evaluate.js +1913 -0
- package/dist/runtime/core/evaluate.js.map +1 -0
- package/dist/runtime/core/execute.d.ts +26 -0
- package/dist/runtime/core/execute.d.ts.map +1 -0
- package/dist/runtime/core/execute.js +177 -0
- package/dist/runtime/core/execute.js.map +1 -0
- package/dist/runtime/core/signals.d.ts +19 -0
- package/dist/runtime/core/signals.d.ts.map +1 -0
- package/dist/runtime/core/signals.js +26 -0
- package/dist/runtime/core/signals.js.map +1 -0
- package/dist/runtime/core/types.d.ts +177 -0
- package/dist/runtime/core/types.d.ts.map +1 -0
- package/dist/runtime/core/types.js +50 -0
- package/dist/runtime/core/types.js.map +1 -0
- package/dist/runtime/core/values.d.ts +66 -0
- package/dist/runtime/core/values.d.ts.map +1 -0
- package/dist/runtime/core/values.js +240 -0
- package/dist/runtime/core/values.js.map +1 -0
- package/dist/runtime/evaluate.d.ts +32 -0
- package/dist/runtime/evaluate.d.ts.map +1 -0
- package/dist/runtime/evaluate.js +1111 -0
- package/dist/runtime/evaluate.js.map +1 -0
- package/dist/runtime/execute.d.ts +26 -0
- package/dist/runtime/execute.d.ts.map +1 -0
- package/dist/runtime/execute.js +121 -0
- package/dist/runtime/execute.js.map +1 -0
- package/dist/runtime/ext/builtins.d.ts +16 -0
- package/dist/runtime/ext/builtins.d.ts.map +1 -0
- package/dist/runtime/ext/builtins.js +528 -0
- package/dist/runtime/ext/builtins.js.map +1 -0
- package/dist/runtime/ext/content-parser.d.ts +83 -0
- package/dist/runtime/ext/content-parser.d.ts.map +1 -0
- package/dist/runtime/ext/content-parser.js +536 -0
- package/dist/runtime/ext/content-parser.js.map +1 -0
- package/dist/runtime/index.d.ts +28 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +34 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/signals.d.ts +19 -0
- package/dist/runtime/signals.d.ts.map +1 -0
- package/dist/runtime/signals.js +26 -0
- package/dist/runtime/signals.js.map +1 -0
- package/dist/runtime/types.d.ts +169 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +50 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/values.d.ts +50 -0
- package/dist/runtime/values.d.ts.map +1 -0
- package/dist/runtime/values.js +209 -0
- package/dist/runtime/values.js.map +1 -0
- package/dist/runtime.d.ts +254 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +2014 -0
- package/dist/runtime.js.map +1 -0
- package/dist/types.d.ts +752 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +189 -0
- package/dist/types.js.map +1 -0
- package/docs/00_INDEX.md +65 -0
- package/docs/01_guide.md +390 -0
- package/docs/02_types.md +399 -0
- package/docs/03_variables.md +314 -0
- package/docs/04_operators.md +551 -0
- package/docs/05_control-flow.md +350 -0
- package/docs/06_closures.md +353 -0
- package/docs/07_collections.md +686 -0
- package/docs/08_iterators.md +330 -0
- package/docs/09_strings.md +205 -0
- package/docs/10_parsing.md +366 -0
- package/docs/11_reference.md +350 -0
- package/docs/12_examples.md +771 -0
- package/docs/13_modules.md +519 -0
- package/docs/14_host-integration.md +826 -0
- package/docs/15_grammar.ebnf +693 -0
- package/docs/16_conventions.md +696 -0
- package/docs/99_llm-reference.txt +300 -0
- package/docs/assets/logo.png +0 -0
- package/package.json +70 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composed Evaluator
|
|
3
|
+
*
|
|
4
|
+
* The complete evaluator class composed from all mixins.
|
|
5
|
+
* Uses WeakMap caching to reuse evaluator instances per RuntimeContext.
|
|
6
|
+
*
|
|
7
|
+
* Mixin composition order (bottom to top):
|
|
8
|
+
* 1. EvaluatorBase - Foundation utilities
|
|
9
|
+
* 2. CoreMixin - Expression dispatch
|
|
10
|
+
* 3. LiteralsMixin - String, dict, tuple, closure literals
|
|
11
|
+
* 4. VariablesMixin - Variable resolution and access chains
|
|
12
|
+
* 5. CollectionsMixin - each, map, fold, filter operators
|
|
13
|
+
* 6. ExtractionMixin - Destructure, slice, spread operators
|
|
14
|
+
* 7. ControlFlowMixin - Conditionals, loops, blocks
|
|
15
|
+
* 8. ClosuresMixin - Function calls and invocation
|
|
16
|
+
* 9. ExpressionsMixin - Binary, unary, grouped expressions
|
|
17
|
+
* 10. TypesMixin - Type assertions and checks
|
|
18
|
+
* 11. AnnotationsMixin - Annotated statement execution (outermost)
|
|
19
|
+
*
|
|
20
|
+
* The order ensures that each mixin can depend on the methods provided
|
|
21
|
+
* by mixins below it in the stack.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
import { EvaluatorBase } from './base.js';
|
|
26
|
+
import { CoreMixin } from './mixins/core.js';
|
|
27
|
+
import { LiteralsMixin } from './mixins/literals.js';
|
|
28
|
+
import { VariablesMixin } from './mixins/variables.js';
|
|
29
|
+
import { CollectionsMixin } from './mixins/collections.js';
|
|
30
|
+
import { ExtractionMixin } from './mixins/extraction.js';
|
|
31
|
+
import { ControlFlowMixin } from './mixins/control-flow.js';
|
|
32
|
+
import { ClosuresMixin } from './mixins/closures.js';
|
|
33
|
+
import { ExpressionsMixin } from './mixins/expressions.js';
|
|
34
|
+
import { TypesMixin } from './mixins/types.js';
|
|
35
|
+
import { AnnotationsMixin } from './mixins/annotations.js';
|
|
36
|
+
/**
|
|
37
|
+
* Complete Evaluator class composed from all mixins.
|
|
38
|
+
*
|
|
39
|
+
* This is the final, fully-composed evaluator that has all evaluation
|
|
40
|
+
* capabilities. The composition order is carefully chosen to ensure
|
|
41
|
+
* dependencies are satisfied.
|
|
42
|
+
*/
|
|
43
|
+
export const Evaluator = AnnotationsMixin(TypesMixin(ExpressionsMixin(ClosuresMixin(ControlFlowMixin(ExtractionMixin(CollectionsMixin(VariablesMixin(LiteralsMixin(CoreMixin(EvaluatorBase))))))))));
|
|
44
|
+
/**
|
|
45
|
+
* WeakMap cache for evaluator instances.
|
|
46
|
+
*
|
|
47
|
+
* Key: RuntimeContext object reference
|
|
48
|
+
* Value: Evaluator instance for that context
|
|
49
|
+
*
|
|
50
|
+
* Cache eviction happens automatically when the RuntimeContext is
|
|
51
|
+
* garbage collected, since WeakMap keys don't prevent GC.
|
|
52
|
+
*/
|
|
53
|
+
const evaluatorCache = new WeakMap();
|
|
54
|
+
/**
|
|
55
|
+
* Get or create an evaluator instance for a given RuntimeContext.
|
|
56
|
+
*
|
|
57
|
+
* Evaluator instances are cached per context to avoid recreating
|
|
58
|
+
* the same evaluator multiple times during script execution.
|
|
59
|
+
*
|
|
60
|
+
* @param ctx - The runtime context
|
|
61
|
+
* @returns Evaluator instance (cached or newly created)
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export function getEvaluator(ctx) {
|
|
66
|
+
let evaluator = evaluatorCache.get(ctx);
|
|
67
|
+
if (!evaluator) {
|
|
68
|
+
evaluator = new Evaluator(ctx);
|
|
69
|
+
evaluatorCache.set(ctx, evaluator);
|
|
70
|
+
}
|
|
71
|
+
return evaluator;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../../../../src/runtime/core/eval/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM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aluation Public API
|
|
3
|
+
*
|
|
4
|
+
* Public API for AST evaluation using the class-based Evaluator architecture.
|
|
5
|
+
* Provides functional wrappers around Evaluator methods for backward compatibility.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
import type { AnnotatedStatementNode, ASTNode, CaptureNode, ExpressionNode, RillTypeName, SourceLocation, StatementNode } from '../../../types.js';
|
|
10
|
+
import type { RuntimeContext } from '../types.js';
|
|
11
|
+
import type { RillValue } from '../values.js';
|
|
12
|
+
/**
|
|
13
|
+
* Capture information returned by handleCapture.
|
|
14
|
+
*/
|
|
15
|
+
export type CaptureInfo = {
|
|
16
|
+
name: string;
|
|
17
|
+
value: RillValue;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Check if execution has been aborted via AbortSignal.
|
|
21
|
+
* Throws AbortError if signal is aborted.
|
|
22
|
+
*/
|
|
23
|
+
export declare function checkAborted(ctx: RuntimeContext, node?: ASTNode): void;
|
|
24
|
+
/**
|
|
25
|
+
* Check if the current pipe value matches any autoException pattern.
|
|
26
|
+
* Only checks string values. Throws AutoExceptionError on match.
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkAutoExceptions(value: RillValue, ctx: RuntimeContext, node?: ASTNode): void;
|
|
29
|
+
/**
|
|
30
|
+
* Handle statement capture: set variable and fire observability event.
|
|
31
|
+
* Returns capture info if a capture occurred.
|
|
32
|
+
*
|
|
33
|
+
* Note: Accepts CaptureNode | null because internal calls from CoreMixin
|
|
34
|
+
* pass chain.terminator which may be null.
|
|
35
|
+
*/
|
|
36
|
+
export declare function handleCapture(capture: CaptureNode | null, value: RillValue, ctx: RuntimeContext): CaptureInfo | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Assert that a value is of the expected type.
|
|
39
|
+
* Returns the value unchanged if assertion passes, throws on mismatch.
|
|
40
|
+
*/
|
|
41
|
+
export declare function assertType(value: RillValue, expected: RillTypeName, location?: SourceLocation): RillValue;
|
|
42
|
+
/**
|
|
43
|
+
* Evaluate an expression and return its value.
|
|
44
|
+
* Main entry point for expression evaluation.
|
|
45
|
+
*/
|
|
46
|
+
export declare function evaluateExpression(expr: ExpressionNode, ctx: RuntimeContext): Promise<RillValue>;
|
|
47
|
+
/**
|
|
48
|
+
* Execute a statement and return the result.
|
|
49
|
+
* Handles annotations and observability events.
|
|
50
|
+
*/
|
|
51
|
+
export declare function executeStatement(stmt: StatementNode | AnnotatedStatementNode, ctx: RuntimeContext): Promise<RillValue>;
|
|
52
|
+
/**
|
|
53
|
+
* Get annotation value by key from the context's annotation stack.
|
|
54
|
+
* Returns undefined if annotation is not set.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getAnnotation(ctx: RuntimeContext, key: string): RillValue | undefined;
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/core/eval/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,OAAO,EACP,WAAW,EACX,cAAc,EACd,YAAY,EACZ,cAAc,EACd,aAAa,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAE7D;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAKtE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,cAAc,EACnB,IAAI,CAAC,EAAE,OAAO,GACb,IAAI,CAKN;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,WAAW,GAAG,IAAI,EAC3B,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,cAAc,GAClB,WAAW,GAAG,SAAS,CAUzB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,cAAc,GACxB,SAAS,CAoBX;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,SAAS,CAAC,CAGpB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,aAAa,GAAG,sBAAsB,EAC5C,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC,SAAS,CAAC,CAGpB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,MAAM,GACV,SAAS,GAAG,SAAS,CAGvB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluation Public API
|
|
3
|
+
*
|
|
4
|
+
* Public API for AST evaluation using the class-based Evaluator architecture.
|
|
5
|
+
* Provides functional wrappers around Evaluator methods for backward compatibility.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
import { getEvaluator } from './evaluator.js';
|
|
10
|
+
/**
|
|
11
|
+
* Check if execution has been aborted via AbortSignal.
|
|
12
|
+
* Throws AbortError if signal is aborted.
|
|
13
|
+
*/
|
|
14
|
+
export function checkAborted(ctx, node) {
|
|
15
|
+
const evaluator = getEvaluator(ctx);
|
|
16
|
+
// Access protected method via type assertion
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
evaluator.checkAborted(node);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if the current pipe value matches any autoException pattern.
|
|
22
|
+
* Only checks string values. Throws AutoExceptionError on match.
|
|
23
|
+
*/
|
|
24
|
+
export function checkAutoExceptions(value, ctx, node) {
|
|
25
|
+
const evaluator = getEvaluator(ctx);
|
|
26
|
+
// Access protected method via type assertion
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
evaluator.checkAutoExceptions(value, node);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Handle statement capture: set variable and fire observability event.
|
|
32
|
+
* Returns capture info if a capture occurred.
|
|
33
|
+
*
|
|
34
|
+
* Note: Accepts CaptureNode | null because internal calls from CoreMixin
|
|
35
|
+
* pass chain.terminator which may be null.
|
|
36
|
+
*/
|
|
37
|
+
export function handleCapture(capture, value, ctx) {
|
|
38
|
+
if (!capture)
|
|
39
|
+
return undefined;
|
|
40
|
+
const evaluator = getEvaluator(ctx);
|
|
41
|
+
// Access protected evaluateCapture method via type assertion
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
evaluator.evaluateCapture(capture, value);
|
|
44
|
+
// Return capture info for observability
|
|
45
|
+
return { name: capture.name, value };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Assert that a value is of the expected type.
|
|
49
|
+
* Returns the value unchanged if assertion passes, throws on mismatch.
|
|
50
|
+
*/
|
|
51
|
+
export function assertType(value, expected, location) {
|
|
52
|
+
// Create a minimal context for standalone type assertions
|
|
53
|
+
// This is needed for assertType calls that occur outside expression evaluation
|
|
54
|
+
const minimalContext = {
|
|
55
|
+
variables: new Map(),
|
|
56
|
+
variableTypes: new Map(),
|
|
57
|
+
functions: new Map(),
|
|
58
|
+
methods: new Map(),
|
|
59
|
+
callbacks: { onLog: () => { } },
|
|
60
|
+
pipeValue: null,
|
|
61
|
+
parent: undefined,
|
|
62
|
+
signal: undefined,
|
|
63
|
+
observability: {},
|
|
64
|
+
timeout: undefined,
|
|
65
|
+
autoExceptions: [],
|
|
66
|
+
annotationStack: [],
|
|
67
|
+
};
|
|
68
|
+
const evaluator = getEvaluator(minimalContext);
|
|
69
|
+
return evaluator.assertType(value, expected, location);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Evaluate an expression and return its value.
|
|
73
|
+
* Main entry point for expression evaluation.
|
|
74
|
+
*/
|
|
75
|
+
export async function evaluateExpression(expr, ctx) {
|
|
76
|
+
const evaluator = getEvaluator(ctx);
|
|
77
|
+
return evaluator.evaluateExpression(expr);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Execute a statement and return the result.
|
|
81
|
+
* Handles annotations and observability events.
|
|
82
|
+
*/
|
|
83
|
+
export async function executeStatement(stmt, ctx) {
|
|
84
|
+
const evaluator = getEvaluator(ctx);
|
|
85
|
+
return evaluator.executeStatement(stmt);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get annotation value by key from the context's annotation stack.
|
|
89
|
+
* Returns undefined if annotation is not set.
|
|
90
|
+
*/
|
|
91
|
+
export function getAnnotation(ctx, key) {
|
|
92
|
+
const evaluator = getEvaluator(ctx);
|
|
93
|
+
return evaluator.getAnnotation(key);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/runtime/core/eval/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAO9C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAmB,EAAE,IAAc;IAC9D,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACpC,6CAA6C;IAC7C,8DAA8D;IAC7D,SAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAgB,EAChB,GAAmB,EACnB,IAAc;IAEd,MA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C,KAAK,UAAU,kBAAkB,CACtC,IAAoB,EACpB,GAAmB;IAEnB,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAA4C,EAC5C,GAAmB;IAEnB,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,GAAmB,EACnB,GAAW;IAEX,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnnotationsMixin: Annotated Statement Execution
|
|
3
|
+
*
|
|
4
|
+
* Provides statement execution wrapper with annotation handling.
|
|
5
|
+
* Annotations modify execution behavior (e.g., iteration limits).
|
|
6
|
+
*
|
|
7
|
+
* Interface requirements (from spec IR-53 through IR-55):
|
|
8
|
+
* - executeStatement(stmt) -> Promise<RillValue> [IR-53]
|
|
9
|
+
* - getAnnotation(key) -> RillValue | undefined [IR-54]
|
|
10
|
+
* - getIterationLimit() -> number [IR-55]
|
|
11
|
+
*
|
|
12
|
+
* Error Handling:
|
|
13
|
+
* - Annotated statement execution errors propagate [EC-25]
|
|
14
|
+
* - Annotation evaluation errors propagate [EC-26]
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare const AnnotationsMixin: any;
|
|
19
|
+
//# sourceMappingURL=annotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/annotations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA2KH,eAAO,MAAM,gBAAgB,EAA6B,GAAG,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnnotationsMixin: Annotated Statement Execution
|
|
3
|
+
*
|
|
4
|
+
* Provides statement execution wrapper with annotation handling.
|
|
5
|
+
* Annotations modify execution behavior (e.g., iteration limits).
|
|
6
|
+
*
|
|
7
|
+
* Interface requirements (from spec IR-53 through IR-55):
|
|
8
|
+
* - executeStatement(stmt) -> Promise<RillValue> [IR-53]
|
|
9
|
+
* - getAnnotation(key) -> RillValue | undefined [IR-54]
|
|
10
|
+
* - getIterationLimit() -> number [IR-55]
|
|
11
|
+
*
|
|
12
|
+
* Error Handling:
|
|
13
|
+
* - Annotated statement execution errors propagate [EC-25]
|
|
14
|
+
* - Annotation evaluation errors propagate [EC-26]
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
import { RuntimeError, RILL_ERROR_CODES } from '../../../../types.js';
|
|
19
|
+
import { isCallable } from '../../callable.js';
|
|
20
|
+
/** Default maximum loop iterations */
|
|
21
|
+
const DEFAULT_MAX_ITERATIONS = 10000;
|
|
22
|
+
/**
|
|
23
|
+
* AnnotationsMixin implementation.
|
|
24
|
+
*
|
|
25
|
+
* Provides methods for handling annotated statements and retrieving
|
|
26
|
+
* annotation values from the context stack.
|
|
27
|
+
*
|
|
28
|
+
* Depends on:
|
|
29
|
+
* - EvaluatorBase: ctx, checkAborted(), getNodeLocation(), checkAutoExceptions()
|
|
30
|
+
* - CoreMixin: evaluateExpression()
|
|
31
|
+
*
|
|
32
|
+
* Methods added:
|
|
33
|
+
* - executeStatement(stmt) -> Promise<RillValue>
|
|
34
|
+
* - getAnnotation(key) -> RillValue | undefined
|
|
35
|
+
* - getIterationLimit() -> number
|
|
36
|
+
*/
|
|
37
|
+
function createAnnotationsMixin(Base) {
|
|
38
|
+
return class AnnotationsEvaluator extends Base {
|
|
39
|
+
/**
|
|
40
|
+
* Execute statement with annotation handling [IR-53].
|
|
41
|
+
*
|
|
42
|
+
* Handles both regular and annotated statements.
|
|
43
|
+
* For annotated statements, evaluates annotations, pushes to stack,
|
|
44
|
+
* executes inner statement, and pops annotations.
|
|
45
|
+
*/
|
|
46
|
+
async executeStatement(stmt) {
|
|
47
|
+
// Handle annotated statements
|
|
48
|
+
if (stmt.type === 'AnnotatedStatement') {
|
|
49
|
+
return this.executeAnnotatedStatement(stmt);
|
|
50
|
+
}
|
|
51
|
+
// Regular statement: evaluate expression
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
const value = await this.evaluateExpression(stmt.expression);
|
|
54
|
+
// Note: Do NOT set ctx.pipeValue = value here.
|
|
55
|
+
// Statements don't propagate $ to siblings. $ flows only via explicit ->.
|
|
56
|
+
this.checkAutoExceptions(value, stmt);
|
|
57
|
+
// Terminator handling is now inside PipeChainNode evaluation
|
|
58
|
+
// (evaluatePipeChain handles capture/break/return terminators)
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Execute an annotated statement.
|
|
63
|
+
* Evaluates annotations, pushes them to the stack, executes the inner statement,
|
|
64
|
+
* and pops the annotations.
|
|
65
|
+
*
|
|
66
|
+
* Errors during annotation evaluation or statement execution propagate.
|
|
67
|
+
*/
|
|
68
|
+
async executeAnnotatedStatement(stmt) {
|
|
69
|
+
// Evaluate annotation arguments to build annotation dict [EC-26]
|
|
70
|
+
const newAnnotations = await this.evaluateAnnotations(stmt.annotations);
|
|
71
|
+
// Merge with inherited annotations (inner overrides outer)
|
|
72
|
+
const inherited = this.ctx.annotationStack.at(-1) ?? {};
|
|
73
|
+
const merged = { ...inherited, ...newAnnotations };
|
|
74
|
+
// Push merged annotations, execute inner statement, pop
|
|
75
|
+
this.ctx.annotationStack.push(merged);
|
|
76
|
+
try {
|
|
77
|
+
return await this.executeStatement(stmt.statement);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
this.ctx.annotationStack.pop();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Evaluate annotation arguments to a dict of key-value pairs.
|
|
85
|
+
* Handles both named arguments and spread arguments.
|
|
86
|
+
*
|
|
87
|
+
* Errors during evaluation propagate [EC-26].
|
|
88
|
+
*/
|
|
89
|
+
async evaluateAnnotations(annotations) {
|
|
90
|
+
const result = {};
|
|
91
|
+
for (const arg of annotations) {
|
|
92
|
+
if (arg.type === 'NamedArg') {
|
|
93
|
+
const namedArg = arg;
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
+
result[namedArg.name] = await this.evaluateExpression(namedArg.value);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// SpreadArg: spread tuple/dict keys as annotations
|
|
99
|
+
const spreadArg = arg;
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
|
+
const spreadValue = await this.evaluateExpression(spreadArg.expression);
|
|
102
|
+
if (typeof spreadValue === 'object' &&
|
|
103
|
+
spreadValue !== null &&
|
|
104
|
+
!Array.isArray(spreadValue) &&
|
|
105
|
+
!isCallable(spreadValue)) {
|
|
106
|
+
// Dict: spread all key-value pairs
|
|
107
|
+
Object.assign(result, spreadValue);
|
|
108
|
+
}
|
|
109
|
+
else if (Array.isArray(spreadValue)) {
|
|
110
|
+
// Tuple/list: not valid for annotations (need named keys)
|
|
111
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, 'Annotation spread requires dict with named keys, got list', spreadArg.span.start);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Annotation spread requires dict, got ${typeof spreadValue}`, spreadArg.span.start);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the current value of an annotation from the annotation stack [IR-54].
|
|
122
|
+
*
|
|
123
|
+
* Returns the value from the top of the annotation stack (innermost scope).
|
|
124
|
+
*/
|
|
125
|
+
getAnnotation(key) {
|
|
126
|
+
return this.ctx.annotationStack.at(-1)?.[key];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get the iteration limit for loops from the `limit` annotation [IR-55].
|
|
130
|
+
*
|
|
131
|
+
* Returns the default if not set or if the value is not a positive number.
|
|
132
|
+
*/
|
|
133
|
+
getIterationLimit() {
|
|
134
|
+
const limit = this.getAnnotation('limit');
|
|
135
|
+
if (typeof limit === 'number' && limit > 0) {
|
|
136
|
+
return Math.floor(limit);
|
|
137
|
+
}
|
|
138
|
+
return DEFAULT_MAX_ITERATIONS;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// Export with type assertion to work around TS4094 limitation
|
|
143
|
+
// TypeScript can't generate declarations for functions returning classes with protected members
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
|
+
export const AnnotationsMixin = createAnnotationsMixin;
|
|
146
|
+
//# sourceMappingURL=annotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.js","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/annotations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AASH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,sCAAsC;AACtC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAErC;;;;;;;;;;;;;;GAcG;AACH,SAAS,sBAAsB,CAAC,IAAyC;IACvE,OAAO,MAAM,oBAAqB,SAAQ,IAAI;QAC5C;;;;;;WAMG;QACH,KAAK,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AAC,CAAC;QAChD,CAAC;QAED;;;;WAIG;QACH,iBAAiB;YACf,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YACD,OAAO,sBAAsB,CAAC;QAChC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,gGAAgG;AAChG,8DAA8D;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAA6B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClosuresMixin: Closure and Method Invocation
|
|
3
|
+
*
|
|
4
|
+
* Handles all callable operations:
|
|
5
|
+
* - Host function calls
|
|
6
|
+
* - Closure calls (script callables)
|
|
7
|
+
* - Method calls on values
|
|
8
|
+
* - Invoke operations
|
|
9
|
+
* - Pipe invocations
|
|
10
|
+
* - Property access on piped values
|
|
11
|
+
* - Closure chains
|
|
12
|
+
*
|
|
13
|
+
* Interface requirements (from spec):
|
|
14
|
+
* - invokeCallable(callable, args, location) -> Promise<RillValue>
|
|
15
|
+
* - evaluateHostCall(node) -> Promise<RillValue>
|
|
16
|
+
* - evaluateClosureCall(node) -> Promise<RillValue>
|
|
17
|
+
* - evaluateClosureCallWithPipe(node, pipeInput) -> Promise<RillValue>
|
|
18
|
+
* - evaluatePipePropertyAccess(node, pipeInput) -> Promise<RillValue>
|
|
19
|
+
* - evaluateVariableInvoke(node, pipeInput) -> Promise<RillValue>
|
|
20
|
+
* - evaluatePipeInvoke(node, input) -> Promise<RillValue>
|
|
21
|
+
* - evaluateMethod(node, receiver) -> Promise<RillValue>
|
|
22
|
+
* - evaluateInvoke(node, receiver) -> Promise<RillValue>
|
|
23
|
+
* - evaluateClosureChain(node, input) -> Promise<RillValue>
|
|
24
|
+
*
|
|
25
|
+
* Error Handling:
|
|
26
|
+
* - Undefined functions throw RuntimeError(RUNTIME_UNDEFINED_FUNCTION) [EC-18]
|
|
27
|
+
* - Undefined methods throw RuntimeError(RUNTIME_UNDEFINED_METHOD) [EC-19]
|
|
28
|
+
* - Parameter type mismatches throw RuntimeError(RUNTIME_TYPE_ERROR) [EC-20]
|
|
29
|
+
* - Async operations timeout per TimeoutError [EC-21]
|
|
30
|
+
*
|
|
31
|
+
* ## Implementation Notes
|
|
32
|
+
*
|
|
33
|
+
* [DEVIATION] Function naming: Spec references validateHostFunctionArgs but implementation
|
|
34
|
+
* uses validateCallableArgs because ApplicationCallable stores CallableParam[] (not
|
|
35
|
+
* HostFunctionParam[]). The two interfaces have different type field names ('type' vs
|
|
36
|
+
* 'typeName'). Separate validation functions maintain proper abstraction boundaries.
|
|
37
|
+
*
|
|
38
|
+
* [ASSUMPTION] Excess argument validation occurs before default application to fail fast
|
|
39
|
+
* on arity mismatches, improving error messages. This matches the algorithm order in the
|
|
40
|
+
* spec where excess check happens first.
|
|
41
|
+
*
|
|
42
|
+
* [ASSUMPTION] boundDict substitution happens before validation for property-style
|
|
43
|
+
* callables to ensure type checks apply to the effective arguments (including bound dict).
|
|
44
|
+
* This prevents validation bypass when property-style callables are accessed.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare const ClosuresMixin: any;
|
|
49
|
+
//# sourceMappingURL=closures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"closures.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/closures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AA2rBH,eAAO,MAAM,aAAa,EAA0B,GAAG,CAAC"}
|