yukigo 0.2.3 → 0.3.2

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 (266) hide show
  1. package/.mocharc.json +3 -3
  2. package/CHANGELOG.md +105 -40
  3. package/README.md +193 -193
  4. package/dist/analyzer/GraphBuilder.d.ts +1 -0
  5. package/dist/analyzer/GraphBuilder.js +2 -1
  6. package/dist/analyzer/index.d.ts +0 -7
  7. package/dist/analyzer/index.js +3 -3
  8. package/dist/analyzer/inspections/functional/functional.d.ts +1 -1
  9. package/dist/analyzer/inspections/functional/functional.js +1 -1
  10. package/dist/analyzer/inspections/functional/smells.d.ts +3 -3
  11. package/dist/analyzer/inspections/functional/smells.js +27 -35
  12. package/dist/analyzer/inspections/generic/generic.d.ts +22 -14
  13. package/dist/analyzer/inspections/generic/generic.js +82 -60
  14. package/dist/analyzer/inspections/generic/smells.d.ts +2 -0
  15. package/dist/analyzer/inspections/generic/smells.js +55 -64
  16. package/dist/analyzer/inspections/imperative/imperative.d.ts +3 -3
  17. package/dist/analyzer/inspections/imperative/imperative.js +3 -3
  18. package/dist/analyzer/inspections/imperative/smells.d.ts +1 -0
  19. package/dist/analyzer/inspections/imperative/smells.js +8 -5
  20. package/dist/analyzer/inspections/logic/logic.d.ts +8 -8
  21. package/dist/analyzer/inspections/logic/logic.js +5 -5
  22. package/dist/analyzer/inspections/logic/smells.js +2 -2
  23. package/dist/analyzer/inspections/object/object.d.ts +5 -5
  24. package/dist/analyzer/inspections/object/object.js +22 -21
  25. package/dist/analyzer/inspections/object/smells.js +11 -23
  26. package/dist/analyzer/utils.d.ts +6 -2
  27. package/dist/analyzer/utils.js +6 -2
  28. package/dist/interpreter/components/EnvBuilder.d.ts +20 -1
  29. package/dist/interpreter/components/EnvBuilder.js +211 -66
  30. package/dist/interpreter/components/EqualityComparer.d.ts +15 -0
  31. package/dist/interpreter/components/EqualityComparer.js +69 -0
  32. package/dist/interpreter/components/Operations.d.ts +17 -14
  33. package/dist/interpreter/components/Operations.js +61 -62
  34. package/dist/interpreter/components/PatternMatcher.d.ts +19 -58
  35. package/dist/interpreter/components/PatternMatcher.js +185 -286
  36. package/dist/interpreter/components/RuntimeContext.d.ts +24 -15
  37. package/dist/interpreter/components/RuntimeContext.js +43 -4
  38. package/dist/interpreter/components/TestRunner.d.ts +15 -13
  39. package/dist/interpreter/components/TestRunner.js +86 -53
  40. package/dist/interpreter/components/evaluators/BaseEvaluator.d.ts +19 -0
  41. package/dist/interpreter/components/evaluators/BaseEvaluator.js +20 -0
  42. package/dist/interpreter/components/evaluators/ExpressionEvaluator.d.ts +34 -0
  43. package/dist/interpreter/components/evaluators/ExpressionEvaluator.js +298 -0
  44. package/dist/interpreter/components/evaluators/OperationEvaluator.d.ts +25 -0
  45. package/dist/interpreter/components/evaluators/OperationEvaluator.js +226 -0
  46. package/dist/interpreter/components/evaluators/PrimitiveEvaluator.d.ts +19 -0
  47. package/dist/interpreter/components/evaluators/PrimitiveEvaluator.js +50 -0
  48. package/dist/interpreter/components/evaluators/StatementEvaluator.d.ts +28 -0
  49. package/dist/interpreter/components/evaluators/StatementEvaluator.js +240 -0
  50. package/dist/interpreter/components/evaluators/TestingEvaluator.d.ts +15 -0
  51. package/dist/interpreter/components/evaluators/TestingEvaluator.js +14 -0
  52. package/dist/interpreter/components/evaluators/index.d.ts +110 -0
  53. package/dist/interpreter/components/evaluators/index.js +21 -0
  54. package/dist/interpreter/components/evaluators/utils.d.ts +7 -0
  55. package/dist/interpreter/components/evaluators/utils.js +50 -0
  56. package/dist/interpreter/components/hooks/YukigoHook.d.ts +27 -0
  57. package/dist/interpreter/components/hooks/YukigoHook.js +1 -0
  58. package/dist/interpreter/components/kernel/commands.d.ts +122 -0
  59. package/dist/interpreter/components/kernel/commands.js +203 -0
  60. package/dist/interpreter/components/kernel/index.d.ts +51 -0
  61. package/dist/interpreter/components/kernel/index.js +176 -0
  62. package/dist/interpreter/components/logic/LogicEngine.d.ts +26 -23
  63. package/dist/interpreter/components/logic/LogicEngine.js +234 -221
  64. package/dist/interpreter/components/logic/LogicResolver.d.ts +22 -51
  65. package/dist/interpreter/components/logic/LogicResolver.js +73 -440
  66. package/dist/interpreter/components/logic/LogicTerm.d.ts +104 -0
  67. package/dist/interpreter/components/logic/LogicTerm.js +423 -0
  68. package/dist/interpreter/components/logic/LogicTranslator.d.ts +25 -9
  69. package/dist/interpreter/components/logic/LogicTranslator.js +211 -74
  70. package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +6 -4
  71. package/dist/interpreter/components/runtimes/FunctionRuntime.js +82 -84
  72. package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +13 -14
  73. package/dist/interpreter/components/runtimes/LazyRuntime.js +112 -239
  74. package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +17 -14
  75. package/dist/interpreter/components/runtimes/ObjectRuntime.js +105 -74
  76. package/dist/interpreter/errors.d.ts +10 -0
  77. package/dist/interpreter/errors.js +17 -0
  78. package/dist/interpreter/index.d.ts +9 -5
  79. package/dist/interpreter/index.js +11 -13
  80. package/dist/interpreter/primitives/YuValue.d.ts +21 -0
  81. package/dist/interpreter/primitives/YuValue.js +40 -0
  82. package/dist/interpreter/primitives/capabilities.d.ts +90 -0
  83. package/dist/interpreter/primitives/capabilities.js +1 -0
  84. package/dist/interpreter/primitives/entities/LazyList.d.ts +48 -0
  85. package/dist/interpreter/primitives/entities/LazyList.js +164 -0
  86. package/dist/interpreter/primitives/entities/LogicResult.d.ts +51 -0
  87. package/dist/interpreter/primitives/entities/LogicResult.js +101 -0
  88. package/dist/interpreter/primitives/entities/RuntimeClass.d.ts +24 -0
  89. package/dist/interpreter/primitives/entities/RuntimeClass.js +57 -0
  90. package/dist/interpreter/primitives/entities/RuntimeFunction.d.ts +40 -0
  91. package/dist/interpreter/primitives/entities/RuntimeFunction.js +73 -0
  92. package/dist/interpreter/primitives/entities/RuntimeObject.d.ts +27 -0
  93. package/dist/interpreter/primitives/entities/RuntimeObject.js +82 -0
  94. package/dist/interpreter/primitives/entities/RuntimePredicate.d.ts +19 -0
  95. package/dist/interpreter/primitives/entities/RuntimePredicate.js +59 -0
  96. package/dist/interpreter/primitives/index.d.ts +14 -0
  97. package/dist/interpreter/primitives/index.js +14 -0
  98. package/dist/interpreter/primitives/scalars/YuBoolean.d.ts +24 -0
  99. package/dist/interpreter/primitives/scalars/YuBoolean.js +69 -0
  100. package/dist/interpreter/primitives/scalars/YuChar.d.ts +28 -0
  101. package/dist/interpreter/primitives/scalars/YuChar.js +78 -0
  102. package/dist/interpreter/primitives/scalars/YuNil.d.ts +25 -0
  103. package/dist/interpreter/primitives/scalars/YuNil.js +73 -0
  104. package/dist/interpreter/primitives/scalars/YuNumber.d.ts +49 -0
  105. package/dist/interpreter/primitives/scalars/YuNumber.js +165 -0
  106. package/dist/interpreter/primitives/sequences/YuArray.d.ts +33 -0
  107. package/dist/interpreter/primitives/sequences/YuArray.js +150 -0
  108. package/dist/interpreter/primitives/sequences/YuString.d.ts +40 -0
  109. package/dist/interpreter/primitives/sequences/YuString.js +130 -0
  110. package/dist/interpreter/utils.d.ts +23 -10
  111. package/dist/interpreter/utils.js +25 -30
  112. package/dist/tester/index.d.ts +3 -3
  113. package/dist/tester/index.js +39 -28
  114. package/dist/utils/helpers.d.ts +13 -5
  115. package/dist/utils/helpers.js +38 -85
  116. package/package.json +3 -16
  117. package/src/analyzer/GraphBuilder.ts +143 -142
  118. package/src/analyzer/index.ts +185 -194
  119. package/src/analyzer/inspections/functional/functional.ts +121 -121
  120. package/src/analyzer/inspections/functional/smells.ts +88 -102
  121. package/src/analyzer/inspections/generic/generic.ts +610 -577
  122. package/src/analyzer/inspections/generic/smells.ts +355 -365
  123. package/src/analyzer/inspections/imperative/imperative.ts +104 -101
  124. package/src/analyzer/inspections/imperative/smells.ts +58 -54
  125. package/src/analyzer/inspections/logic/logic.ts +84 -90
  126. package/src/analyzer/inspections/logic/smells.ts +54 -54
  127. package/src/analyzer/inspections/object/object.ts +295 -264
  128. package/src/analyzer/inspections/object/smells.ts +130 -144
  129. package/src/analyzer/utils.ts +115 -109
  130. package/src/index.ts +3 -3
  131. package/src/interpreter/components/EnvBuilder.ts +405 -202
  132. package/src/interpreter/components/EqualityComparer.ts +107 -0
  133. package/src/interpreter/components/Operations.ts +126 -99
  134. package/src/interpreter/components/PatternMatcher.ts +375 -475
  135. package/src/interpreter/components/RuntimeContext.ts +181 -119
  136. package/src/interpreter/components/TestRunner.ts +223 -151
  137. package/src/interpreter/components/evaluators/BaseEvaluator.ts +36 -0
  138. package/src/interpreter/components/evaluators/ExpressionEvaluator.ts +475 -0
  139. package/src/interpreter/components/evaluators/OperationEvaluator.ts +477 -0
  140. package/src/interpreter/components/evaluators/PrimitiveEvaluator.ts +80 -0
  141. package/src/interpreter/components/evaluators/StatementEvaluator.ts +372 -0
  142. package/src/interpreter/components/evaluators/TestingEvaluator.ts +26 -0
  143. package/src/interpreter/components/evaluators/index.ts +34 -0
  144. package/src/interpreter/components/evaluators/utils.ts +64 -0
  145. package/src/interpreter/components/hooks/YukigoHook.ts +45 -0
  146. package/src/interpreter/components/kernel/commands.ts +255 -0
  147. package/src/interpreter/components/kernel/index.ts +222 -0
  148. package/src/interpreter/components/logic/LogicEngine.ts +509 -519
  149. package/src/interpreter/components/logic/LogicResolver.ts +209 -858
  150. package/src/interpreter/components/logic/LogicTerm.ts +477 -0
  151. package/src/interpreter/components/logic/LogicTranslator.ts +362 -149
  152. package/src/interpreter/components/runtimes/FunctionRuntime.ts +249 -227
  153. package/src/interpreter/components/runtimes/LazyRuntime.ts +226 -334
  154. package/src/interpreter/components/runtimes/ObjectRuntime.ts +262 -224
  155. package/src/interpreter/errors.ts +68 -47
  156. package/src/interpreter/index.ts +50 -52
  157. package/src/interpreter/primitives/YuValue.ts +64 -0
  158. package/src/interpreter/primitives/capabilities.ts +111 -0
  159. package/src/interpreter/primitives/entities/LazyList.ts +225 -0
  160. package/src/interpreter/primitives/entities/LogicResult.ts +133 -0
  161. package/src/interpreter/primitives/entities/RuntimeClass.ts +70 -0
  162. package/src/interpreter/primitives/entities/RuntimeFunction.ts +108 -0
  163. package/src/interpreter/primitives/entities/RuntimeObject.ts +110 -0
  164. package/src/interpreter/primitives/entities/RuntimePredicate.ts +77 -0
  165. package/src/interpreter/primitives/index.ts +17 -0
  166. package/src/interpreter/primitives/scalars/YuBoolean.ts +79 -0
  167. package/src/interpreter/primitives/scalars/YuChar.ts +94 -0
  168. package/src/interpreter/primitives/scalars/YuNil.ts +84 -0
  169. package/src/interpreter/primitives/scalars/YuNumber.ts +187 -0
  170. package/src/interpreter/primitives/sequences/YuArray.ts +178 -0
  171. package/src/interpreter/primitives/sequences/YuString.ts +165 -0
  172. package/src/interpreter/utils.ts +105 -84
  173. package/src/tester/index.ts +157 -128
  174. package/src/utils/helpers.ts +113 -169
  175. package/tests/analyzer/functional.spec.ts +221 -207
  176. package/tests/analyzer/generic.spec.ts +178 -178
  177. package/tests/analyzer/helpers.spec.ts +83 -89
  178. package/tests/analyzer/logic.spec.ts +237 -237
  179. package/tests/analyzer/oop.spec.ts +320 -323
  180. package/tests/analyzer/transitive.spec.ts +166 -166
  181. package/tests/interpreter/EnvBuilder.spec.ts +181 -183
  182. package/tests/interpreter/FunctionRuntime.spec.ts +224 -223
  183. package/tests/interpreter/LazyRuntime.spec.ts +227 -225
  184. package/tests/interpreter/LogicEngine.spec.ts +371 -327
  185. package/tests/interpreter/LogicSubstitution.spec.ts +90 -80
  186. package/tests/interpreter/ObjectRuntime.spec.ts +431 -606
  187. package/tests/interpreter/Operations.spec.ts +312 -220
  188. package/tests/interpreter/PatternSystem.spec.ts +254 -213
  189. package/tests/interpreter/Tests.spec.ts +122 -122
  190. package/tests/interpreter/interpreter.spec.ts +1143 -991
  191. package/tests/kernel/YukigoKernel.spec.ts +112 -0
  192. package/tests/tester/Tester.spec.ts +156 -152
  193. package/tsconfig.build.json +16 -15
  194. package/tsconfig.json +27 -25
  195. package/dist/interpreter/components/Visitor.d.ts +0 -70
  196. package/dist/interpreter/components/Visitor.js +0 -634
  197. package/dist/interpreter/entities.d.ts +0 -105
  198. package/dist/interpreter/entities.js +0 -96
  199. package/dist/interpreter/trampoline.d.ts +0 -17
  200. package/dist/interpreter/trampoline.js +0 -38
  201. package/dist/src/analyzer/GraphBuilder.d.ts +0 -30
  202. package/dist/src/analyzer/GraphBuilder.js +0 -100
  203. package/dist/src/analyzer/index.d.ts +0 -59
  204. package/dist/src/analyzer/index.js +0 -152
  205. package/dist/src/analyzer/inspections/functional/functional.d.ts +0 -44
  206. package/dist/src/analyzer/inspections/functional/functional.js +0 -149
  207. package/dist/src/analyzer/inspections/functional/smells.d.ts +0 -16
  208. package/dist/src/analyzer/inspections/functional/smells.js +0 -98
  209. package/dist/src/analyzer/inspections/generic/generic.d.ts +0 -178
  210. package/dist/src/analyzer/inspections/generic/generic.js +0 -604
  211. package/dist/src/analyzer/inspections/generic/smells.d.ts +0 -61
  212. package/dist/src/analyzer/inspections/generic/smells.js +0 -349
  213. package/dist/src/analyzer/inspections/imperative/imperative.d.ts +0 -35
  214. package/dist/src/analyzer/inspections/imperative/imperative.js +0 -109
  215. package/dist/src/analyzer/inspections/imperative/smells.d.ts +0 -16
  216. package/dist/src/analyzer/inspections/imperative/smells.js +0 -58
  217. package/dist/src/analyzer/inspections/logic/logic.d.ts +0 -32
  218. package/dist/src/analyzer/inspections/logic/logic.js +0 -96
  219. package/dist/src/analyzer/inspections/logic/smells.d.ts +0 -15
  220. package/dist/src/analyzer/inspections/logic/smells.js +0 -60
  221. package/dist/src/analyzer/inspections/object/object.d.ts +0 -90
  222. package/dist/src/analyzer/inspections/object/object.js +0 -321
  223. package/dist/src/analyzer/inspections/object/smells.d.ts +0 -30
  224. package/dist/src/analyzer/inspections/object/smells.js +0 -135
  225. package/dist/src/analyzer/utils.d.ts +0 -30
  226. package/dist/src/analyzer/utils.js +0 -78
  227. package/dist/src/index.d.ts +0 -4
  228. package/dist/src/index.js +0 -4
  229. package/dist/src/interpreter/components/EnvBuilder.d.ts +0 -21
  230. package/dist/src/interpreter/components/EnvBuilder.js +0 -155
  231. package/dist/src/interpreter/components/Operations.d.ts +0 -14
  232. package/dist/src/interpreter/components/Operations.js +0 -84
  233. package/dist/src/interpreter/components/PatternMatcher.d.ts +0 -73
  234. package/dist/src/interpreter/components/PatternMatcher.js +0 -358
  235. package/dist/src/interpreter/components/RuntimeContext.d.ts +0 -35
  236. package/dist/src/interpreter/components/RuntimeContext.js +0 -93
  237. package/dist/src/interpreter/components/TestRunner.d.ts +0 -19
  238. package/dist/src/interpreter/components/TestRunner.js +0 -110
  239. package/dist/src/interpreter/components/Visitor.d.ts +0 -71
  240. package/dist/src/interpreter/components/Visitor.js +0 -638
  241. package/dist/src/interpreter/components/logic/LogicEngine.d.ts +0 -29
  242. package/dist/src/interpreter/components/logic/LogicEngine.js +0 -259
  243. package/dist/src/interpreter/components/logic/LogicResolver.d.ts +0 -53
  244. package/dist/src/interpreter/components/logic/LogicResolver.js +0 -484
  245. package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +0 -14
  246. package/dist/src/interpreter/components/logic/LogicTranslator.js +0 -99
  247. package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +0 -12
  248. package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +0 -149
  249. package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +0 -19
  250. package/dist/src/interpreter/components/runtimes/LazyRuntime.js +0 -269
  251. package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +0 -35
  252. package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +0 -126
  253. package/dist/src/interpreter/errors.d.ts +0 -19
  254. package/dist/src/interpreter/errors.js +0 -36
  255. package/dist/src/interpreter/index.d.ts +0 -24
  256. package/dist/src/interpreter/index.js +0 -41
  257. package/dist/src/interpreter/trampoline.d.ts +0 -17
  258. package/dist/src/interpreter/trampoline.js +0 -38
  259. package/dist/src/interpreter/utils.d.ts +0 -11
  260. package/dist/src/interpreter/utils.js +0 -65
  261. package/dist/src/tester/index.d.ts +0 -25
  262. package/dist/src/tester/index.js +0 -113
  263. package/dist/src/utils/helpers.d.ts +0 -13
  264. package/dist/src/utils/helpers.js +0 -52
  265. package/src/interpreter/components/Visitor.ts +0 -1065
  266. package/src/interpreter/trampoline.ts +0 -71
@@ -0,0 +1,298 @@
1
+ import { Application, NamedArgument, Generator as YuGenerator, SymbolPrimitive, Return, Sequence, Super, UnguardedBody, VariablePattern, } from "yukigo-ast";
2
+ import { BindCommand, FailCommand, RaiseCommand, StepCommand, } from "../kernel/commands.js";
3
+ import { InterpreterError } from "../../errors.js";
4
+ import { YuArray, RuntimeClass, RuntimeFunction, } from "../../primitives/index.js";
5
+ import { boolean, error, isTrue, raise } from "../../utils.js";
6
+ import { EnvBuilderVisitor } from "../EnvBuilder.js";
7
+ import { getClassFields, getClassInitializers, getLogicEngine, } from "./utils.js";
8
+ export function ExpressionEvaluator(Base) {
9
+ return class extends Base {
10
+ visitTupleExpr(node) {
11
+ const results = [];
12
+ const evaluateNext = (index) => {
13
+ if (index >= node.elements.length)
14
+ return new StepCommand(new YuArray(results));
15
+ return new BindCommand(this.evaluate(node.elements[index]), (val) => {
16
+ results.push(val);
17
+ return evaluateNext(index + 1);
18
+ });
19
+ };
20
+ return evaluateNext(0);
21
+ }
22
+ visitFieldExpression(node) {
23
+ return new BindCommand(this.evaluate(node.name), (obj) => {
24
+ return new StepCommand(this.context.objRuntime.getField(obj, node.name.value));
25
+ });
26
+ }
27
+ visitDataExpr(node) {
28
+ const fieldValues = new Map();
29
+ const evaluateFields = (index) => {
30
+ if (index >= node.contents.length) {
31
+ const identifier = node.name.value;
32
+ const classDef = new RuntimeClass(identifier, fieldValues, new Map(), []);
33
+ return new StepCommand(classDef.instantiate(identifier));
34
+ }
35
+ const field = node.contents[index];
36
+ return new BindCommand(this.evaluate(field.expression), (value) => {
37
+ fieldValues.set(field.name.value, value);
38
+ return evaluateFields(index + 1);
39
+ });
40
+ };
41
+ return evaluateFields(0);
42
+ }
43
+ visitConsExpr(node) {
44
+ return this.context.lazyRuntime.evaluateCons(node, this);
45
+ }
46
+ visitLetInExpr(node) {
47
+ const oldEnv = this.context.env;
48
+ this.context.pushEnv();
49
+ const envBuilder = new EnvBuilderVisitor(this.context);
50
+ node.declarations.accept(envBuilder);
51
+ return new BindCommand(this.evaluate(node.expression), (result) => {
52
+ this.context.env = oldEnv;
53
+ return new StepCommand(result);
54
+ });
55
+ }
56
+ visitCall(node) {
57
+ return new BindCommand(this.evaluate(node.callee), (callee) => {
58
+ const args = [];
59
+ const evaluateArgs = (index) => {
60
+ if (index < node.args.length)
61
+ return new BindCommand(this.evaluate(node.args[index]), (val) => {
62
+ args.push(val);
63
+ return evaluateArgs(index + 1);
64
+ });
65
+ if (!(callee instanceof RuntimeFunction))
66
+ return new FailCommand(new InterpreterError("Call", "Target is not a function"));
67
+ return this.context.funcRuntime.apply(callee, args);
68
+ };
69
+ return evaluateArgs(0);
70
+ });
71
+ }
72
+ visitOtherwise(node) {
73
+ return boolean(true);
74
+ }
75
+ visitCompositionExpression(node) {
76
+ return new BindCommand(this.evaluate(node.left), (f) => {
77
+ return new BindCommand(this.evaluate(node.right), (g) => {
78
+ if (!(f instanceof RuntimeFunction) ||
79
+ !(g instanceof RuntimeFunction)) {
80
+ return new FailCommand(new InterpreterError("Composition", "Both operands of (.) must be functions"));
81
+ }
82
+ const F_REF = "__internal_f";
83
+ const G_REF = "__internal_g";
84
+ const PARAM_NAME = "__x";
85
+ const compositionBody = new Application(new SymbolPrimitive(F_REF), new Application(new SymbolPrimitive(G_REF), new SymbolPrimitive(PARAM_NAME)));
86
+ const patterns = [
87
+ new VariablePattern(new SymbolPrimitive(PARAM_NAME)),
88
+ ];
89
+ const equation = {
90
+ patterns,
91
+ body: new UnguardedBody(new Sequence([new Return(compositionBody)])),
92
+ };
93
+ const privateScope = new Map();
94
+ privateScope.set(F_REF, f);
95
+ privateScope.set(G_REF, g);
96
+ const capturedEnv = {
97
+ head: privateScope,
98
+ tail: this.context.env,
99
+ };
100
+ const func = new RuntimeFunction(1, [equation], `<(${f.identifier} . ${g.identifier})>`, [], capturedEnv);
101
+ return new StepCommand(func);
102
+ });
103
+ });
104
+ }
105
+ visitLambda(node) {
106
+ const patterns = node.parameters;
107
+ const equation = {
108
+ patterns,
109
+ body: new UnguardedBody(new Sequence([new Return(node.body)])),
110
+ };
111
+ const func = new RuntimeFunction(patterns.length, [equation], "<lambda>", [], this.context.env);
112
+ return new StepCommand(func);
113
+ }
114
+ visitGuardedExpression(expr) {
115
+ const tryNextGuard = (guardIndex) => {
116
+ if (guardIndex >= expr.guards.length) {
117
+ return new RaiseCommand(new InterpreterError("PatternMatch", "Non-exhaustive guards in equation: the pattern matched but no guard succeeded."));
118
+ }
119
+ const guard = expr.guards[guardIndex];
120
+ return new BindCommand(this.evaluate(guard.condition), (cond) => {
121
+ if (!isTrue(cond))
122
+ return tryNextGuard(guardIndex + 1);
123
+ return this.evaluate(guard.body);
124
+ });
125
+ };
126
+ return tryNextGuard(0);
127
+ }
128
+ visitApplication(node) {
129
+ const { funcRuntime } = this.context;
130
+ return new BindCommand(this.evaluate(node.functionExpr), (func) => {
131
+ if (!(func instanceof RuntimeFunction)) {
132
+ return new FailCommand(new InterpreterError("Application", "Cannot apply non-function"));
133
+ }
134
+ const applyFuncToNode = (func) => new BindCommand(this.evaluate(node.parameter), (arg) => {
135
+ return funcRuntime.applyArguments(func, [() => arg]);
136
+ });
137
+ if (func.arity === 0) {
138
+ return new BindCommand(funcRuntime.applyArguments(func), (resultOfFunc) => {
139
+ if (!(resultOfFunc instanceof RuntimeFunction))
140
+ return new FailCommand(new InterpreterError("Application", "Cannot apply non-function result of arity-0 function"));
141
+ return applyFuncToNode(resultOfFunc);
142
+ });
143
+ }
144
+ return applyFuncToNode(func);
145
+ });
146
+ }
147
+ visitExist(node) {
148
+ return getLogicEngine(this, this.context).solveGoalLike(node);
149
+ }
150
+ visitNot(node) {
151
+ return getLogicEngine(this, this.context).solveNot(node);
152
+ }
153
+ visitFindall(node) {
154
+ return getLogicEngine(this, this.context).solveFindall(node);
155
+ }
156
+ visitForall(node) {
157
+ return getLogicEngine(this, this.context).solveForall(node);
158
+ }
159
+ visitGoal(node) {
160
+ return getLogicEngine(this, this.context).solveGoalLike(node);
161
+ }
162
+ visitSend(node) {
163
+ if (node.receiver instanceof Super) {
164
+ const methodName = node.selector.value;
165
+ const args = [];
166
+ const evaluateNextArg = (index) => {
167
+ if (index >= node.args.length) {
168
+ try {
169
+ return this.context.objRuntime.dispatchSuper(methodName, args);
170
+ }
171
+ catch (error) {
172
+ if (error instanceof InterpreterError) {
173
+ const mappedErrors = this.context.dispatchHook("onInterpreterError", error, this.context);
174
+ const userException = mappedErrors.find((res) => res !== undefined && res !== null);
175
+ return new RaiseCommand(userException || error);
176
+ }
177
+ return new RaiseCommand(new InterpreterError("RuntimeError", String(error)));
178
+ }
179
+ }
180
+ return new BindCommand(this.evaluate(node.args[index]), (val) => {
181
+ args.push(val);
182
+ return evaluateNextArg(index + 1);
183
+ });
184
+ };
185
+ return evaluateNextArg(0);
186
+ }
187
+ return new BindCommand(this.evaluate(node.receiver), (receiver) => {
188
+ const methodName = node.selector.value;
189
+ const args = [];
190
+ const evaluateNextArg = (index) => {
191
+ if (index >= node.args.length) {
192
+ try {
193
+ return this.context.objRuntime.dispatch(receiver, methodName, args);
194
+ }
195
+ catch (error) {
196
+ if (error instanceof InterpreterError) {
197
+ const mappedErrors = this.context.dispatchHook("onInterpreterError", error, this.context);
198
+ const userException = mappedErrors.find((res) => res !== undefined && res !== null);
199
+ return new RaiseCommand(userException || error);
200
+ }
201
+ return new RaiseCommand(new InterpreterError("RuntimeError", String(error)));
202
+ }
203
+ }
204
+ return new BindCommand(this.evaluate(node.args[index]), (val) => {
205
+ args.push(val);
206
+ return evaluateNextArg(index + 1);
207
+ });
208
+ };
209
+ return evaluateNextArg(0);
210
+ });
211
+ }
212
+ visitNew(node) {
213
+ const className = node.identifier.value;
214
+ const classDef = this.context.lookup(className);
215
+ if (!(classDef instanceof RuntimeClass))
216
+ return new FailCommand(new InterpreterError("New", `${className} is not a class.`));
217
+ const instance = classDef.instantiate(node.identifier.value);
218
+ instance.fields = getClassFields(classDef, this.context);
219
+ const evaluateArgs = (index) => {
220
+ if (index >= node.args.length) {
221
+ return new StepCommand(instance);
222
+ }
223
+ const arg = node.args[index];
224
+ if (arg instanceof NamedArgument ||
225
+ arg.constructor.name === "NamedArgument") {
226
+ const fieldName = arg.identifier.value;
227
+ return new BindCommand(this.evaluate(arg.expression), (val) => {
228
+ instance.setField(fieldName, val);
229
+ return evaluateArgs(index + 1);
230
+ });
231
+ }
232
+ return evaluateArgs(index + 1);
233
+ };
234
+ const initializers = getClassInitializers(classDef, this.context);
235
+ const initializerKeys = Array.from(initializers.keys());
236
+ const evaluateInitializers = (keyIndex) => {
237
+ if (keyIndex >= initializerKeys.length) {
238
+ return evaluateArgs(0);
239
+ }
240
+ const key = initializerKeys[keyIndex];
241
+ const expr = initializers.get(key);
242
+ return new BindCommand(this.evaluate(expr), (val) => {
243
+ instance.setField(key, val);
244
+ return evaluateInitializers(keyIndex + 1);
245
+ });
246
+ };
247
+ return evaluateInitializers(0);
248
+ }
249
+ visitListComprehension(node) {
250
+ const results = [];
251
+ const process = (index) => {
252
+ if (index >= node.generators.length) {
253
+ return new BindCommand(this.evaluate(node.projection), (proj) => {
254
+ results.push(proj);
255
+ return new StepCommand(new YuArray(results));
256
+ });
257
+ }
258
+ const current = node.generators[index];
259
+ if (current instanceof YuGenerator) {
260
+ return new BindCommand(this.evaluate(current.expression), (exprResult) => {
261
+ return new BindCommand(this.context.lazyRuntime.realizeList(exprResult), (sourceListVal) => {
262
+ const sourceList = sourceListVal.asSequence;
263
+ if (!(sourceList instanceof YuArray))
264
+ return raise(error("visitListComprehension", `Error expected YuArray and got ${sourceListVal.getType()}`));
265
+ const iterateSource = (sourceIndex) => {
266
+ if (sourceIndex >= sourceList.items.length)
267
+ return new StepCommand(new YuArray(results));
268
+ const item = sourceList.at(sourceIndex);
269
+ const varName = current.variable.value;
270
+ this.context.define(varName, item);
271
+ return process(index + 1);
272
+ };
273
+ return iterateSource(0);
274
+ });
275
+ });
276
+ }
277
+ else {
278
+ return new BindCommand(this.evaluate(current), (condition) => {
279
+ return isTrue(condition)
280
+ ? process(index + 1)
281
+ : new StepCommand(new YuArray(results));
282
+ });
283
+ }
284
+ };
285
+ this.context.pushEnv();
286
+ return process(0);
287
+ }
288
+ visitGenerator(node) {
289
+ return this.evaluate(node.expression);
290
+ }
291
+ visitRangeExpression(node) {
292
+ return this.context.lazyRuntime.evaluateRange(node, this);
293
+ }
294
+ visitTypeCast(node) {
295
+ return node.expression.accept(this);
296
+ }
297
+ };
298
+ }
@@ -0,0 +1,25 @@
1
+ import { ArithmeticBinaryOperation, ArithmeticUnaryOperation, AssignOperation, BitwiseBinaryOperation, BitwiseUnaryOperation, ComparisonOperation, ListBinaryOperation, ListUnaryOperation, LogicalBinaryOperation, LogicalUnaryOperation, StringOperation, UnifyOperation } from "yukigo-ast";
2
+ import { ExecutionCommand } from "../kernel/commands.js";
3
+ import { Constructor, EvaluatorBase } from "./BaseEvaluator.js";
4
+ import { RuntimeContext } from "../RuntimeContext.js";
5
+ export declare function OperationEvaluator<TBase extends Constructor<EvaluatorBase>>(Base: TBase): {
6
+ new (...args: any[]): {
7
+ visitArithmeticUnaryOperation(node: ArithmeticUnaryOperation): ExecutionCommand;
8
+ visitListUnaryOperation(node: ListUnaryOperation): ExecutionCommand;
9
+ visitListBinaryOperation(node: ListBinaryOperation): ExecutionCommand;
10
+ visitComparisonOperation(node: ComparisonOperation): ExecutionCommand;
11
+ visitLogicalBinaryOperation(node: LogicalBinaryOperation): ExecutionCommand;
12
+ visitLogicalUnaryOperation(node: LogicalUnaryOperation): ExecutionCommand;
13
+ visitBitwiseBinaryOperation(node: BitwiseBinaryOperation): ExecutionCommand;
14
+ visitBitwiseUnaryOperation(node: BitwiseUnaryOperation): ExecutionCommand;
15
+ visitStringOperation(node: StringOperation): ExecutionCommand;
16
+ visitUnifyOperation(node: UnifyOperation): ExecutionCommand;
17
+ visitAssignOperation(node: AssignOperation): ExecutionCommand;
18
+ visitArithmeticBinaryOperation(node: ArithmeticBinaryOperation): ExecutionCommand;
19
+ context: RuntimeContext;
20
+ getContext(): RuntimeContext;
21
+ evaluate(node: import("yukigo-ast").ASTNode): ExecutionCommand;
22
+ realizeList(val: any): ExecutionCommand;
23
+ fallback(node: import("yukigo-ast").ASTNode): ExecutionCommand;
24
+ };
25
+ } & TBase;
@@ -0,0 +1,226 @@
1
+ import { SymbolPrimitive, } from "yukigo-ast";
2
+ import { BindCommand, EvalCommand, FailCommand, RaiseCommand, StepCommand, } from "../kernel/commands.js";
3
+ import { ArithmeticBinaryTable, ArithmeticUnaryTable, BitwiseBinaryTable, BitwiseUnaryTable, ComparisonOperationTable, ListBinaryTable, ListUnaryTable, LogicalBinaryTable, LogicalUnaryTable, StringOperationTable, } from "../Operations.js";
4
+ import { InterpreterError } from "../../errors.js";
5
+ import { LazyList, RuntimeObject, YuBoolean, YuNumber, } from "../../primitives/index.js";
6
+ import { YukigoKernel } from "../kernel/index.js";
7
+ import { EqualityComparer } from "../EqualityComparer.js";
8
+ import { boolean, error, isTrue, raise } from "../../utils.js";
9
+ import { getLogicEngine } from "./utils.js";
10
+ const processBinary = (evaluator, node, table, typeGuard, contextName) => {
11
+ return new BindCommand(evaluator.evaluate(node.left), (rawLeft) => {
12
+ return new BindCommand(evaluator.context.forceValue(rawLeft), (left) => {
13
+ return new BindCommand(evaluator.evaluate(node.right), (rawRight) => {
14
+ return new BindCommand(evaluator.context.forceValue(rawRight), (right) => {
15
+ if (!typeGuard(left, right)) {
16
+ return new FailCommand(new InterpreterError(contextName, `Type mismatch: ${left.getType()}, ${right.getType()}`));
17
+ }
18
+ const fn = table[node.operator];
19
+ if (!fn) {
20
+ return new FailCommand(new InterpreterError(contextName, `Unknown op: ${node.operator}`));
21
+ }
22
+ try {
23
+ return fn(left, right);
24
+ }
25
+ catch (e) {
26
+ return new FailCommand(e);
27
+ }
28
+ });
29
+ });
30
+ });
31
+ });
32
+ };
33
+ const processUnary = (evaluator, node, table, typeGuard, contextName) => {
34
+ return new BindCommand(evaluator.evaluate(node.operand), (rawOperand) => {
35
+ return new BindCommand(evaluator.context.forceValue(rawOperand), (operand) => {
36
+ if (!typeGuard(operand))
37
+ return new FailCommand(new InterpreterError(contextName, `Type mismatch: ${operand.getType()}`));
38
+ const fn = table[node.operator];
39
+ if (!fn)
40
+ return new FailCommand(new InterpreterError(contextName, `Unknown op: ${node.operator}`));
41
+ try {
42
+ return fn(operand);
43
+ }
44
+ catch (e) {
45
+ return new FailCommand(e);
46
+ }
47
+ });
48
+ });
49
+ };
50
+ export function OperationEvaluator(Base) {
51
+ return class extends Base {
52
+ visitArithmeticUnaryOperation(node) {
53
+ return processUnary(this, node, ArithmeticUnaryTable, (a) => !!a.asNumeric, "ArithmeticUnaryOperation");
54
+ }
55
+ visitListUnaryOperation(node) {
56
+ return new BindCommand(this.evaluate(node.operand), (rawOperand) => {
57
+ return new BindCommand(this.context.forceValue(rawOperand), (operand) => {
58
+ if (!operand.asSequence)
59
+ return new FailCommand(new InterpreterError("ListUnaryOperation", `Expected Sequence but got ${operand.getType()}`));
60
+ return new BindCommand(this.context.lazyRuntime.realizeList(operand), (arr) => {
61
+ const seq = arr.asSequence;
62
+ if (!seq)
63
+ return new RaiseCommand(new InterpreterError(`[${node.operator}]`, `Expected ${arr} to be a YuSequence.`));
64
+ const fn = ListUnaryTable[node.operator];
65
+ if (!fn)
66
+ return new FailCommand(new InterpreterError("ListUnaryOperation", `Unknown operator: ${node.operator}`));
67
+ return fn(seq);
68
+ });
69
+ });
70
+ });
71
+ }
72
+ visitListBinaryOperation(node) {
73
+ if (node.operator === "Concat") {
74
+ const capturedCtx = this.context.clone();
75
+ return new BindCommand(this.evaluate(node.left), (rawLeft) => {
76
+ return new BindCommand(this.context.forceValue(rawLeft), (left) => {
77
+ const seqL = left.asSequence;
78
+ if (!seqL)
79
+ return new RaiseCommand(new InterpreterError("ListBinaryOperation", "Invalid left operand for lazy Concat"));
80
+ if (this.context.config.lazyLoading) {
81
+ const lazyRight = new LazyList(() => {
82
+ if (!capturedCtx.evaluatorFactory)
83
+ return new RaiseCommand(new InterpreterError("ListBinaryOperation", "EvaluatorFactory not initialized in RuntimeContext"));
84
+ const subEvaluator = capturedCtx.evaluatorFactory(capturedCtx);
85
+ const subKernel = new YukigoKernel(subEvaluator);
86
+ const rawRight = subKernel.run(new EvalCommand(node.right));
87
+ const right = subKernel.run(capturedCtx.forceValue(rawRight));
88
+ const seqR = right.asSequence;
89
+ if (!seqR)
90
+ return new RaiseCommand(new InterpreterError("ListBinaryOperation", "Invalid right operand for lazy Concat"));
91
+ return seqR.step();
92
+ }, "LazyRight", capturedCtx);
93
+ return this.context.lazyRuntime.evaluateConcat(seqL, lazyRight);
94
+ }
95
+ return new BindCommand(this.evaluate(node.right), (rawRight) => {
96
+ return new BindCommand(this.context.forceValue(rawRight), (right) => {
97
+ const seqR = right.asSequence;
98
+ if (!seqR)
99
+ return new RaiseCommand(new InterpreterError("ListBinaryOperation", "Invalid right operand for lazy Concat"));
100
+ return seqL.concat(seqR);
101
+ });
102
+ });
103
+ });
104
+ });
105
+ }
106
+ return processBinary(this, node, ListBinaryTable, (a, b) => !!a.asSequence && !!b.asSequence, "ListBinaryOperation");
107
+ }
108
+ visitComparisonOperation(node) {
109
+ return new BindCommand(this.evaluate(node.left), (rawLeft) => {
110
+ return new BindCommand(this.context.forceValue(rawLeft), (left) => {
111
+ return new BindCommand(this.evaluate(node.right), (rawRight) => {
112
+ return new BindCommand(this.context.forceValue(rawRight), (right) => {
113
+ if (node.operator === "Equal" || node.operator === "NotEqual") {
114
+ return new BindCommand(EqualityComparer.compare(left, right, this.context), (eq) => {
115
+ const isEq = isTrue(eq);
116
+ return new StepCommand(new YuBoolean(node.operator === "Equal" ? isEq : !isEq));
117
+ });
118
+ }
119
+ if (left instanceof RuntimeObject) {
120
+ const objRuntime = this.context.objRuntime;
121
+ const chain = objRuntime.getResolutionChain(left);
122
+ const hasCompare = !!objRuntime.findMethodInChain(chain, "compare/1") ||
123
+ !!objRuntime.findMethodInChain(chain, "compare");
124
+ if (hasCompare) {
125
+ return new BindCommand(this.context.objRuntime.dispatch(left, "compare", [
126
+ right,
127
+ ]), (compRes) => {
128
+ if (compRes instanceof YuNumber) {
129
+ const val = compRes.value;
130
+ let isTrue = false;
131
+ if (node.operator === "GreaterOrEqualThan")
132
+ isTrue = val >= 0;
133
+ else if (node.operator === "GreaterThan")
134
+ isTrue = val > 0;
135
+ else if (node.operator === "LessOrEqualThan")
136
+ isTrue = val <= 0;
137
+ else if (node.operator === "LessThan")
138
+ isTrue = val < 0;
139
+ return new StepCommand(new YuBoolean(isTrue));
140
+ }
141
+ return new RaiseCommand(new InterpreterError("ComparisonOperation", "compare method did not return a number"));
142
+ });
143
+ }
144
+ }
145
+ if (!ComparisonOperationTable[node.operator]) {
146
+ return new FailCommand(new InterpreterError("ComparisonOperation", `Unknown op: ${node.operator}`));
147
+ }
148
+ try {
149
+ return ComparisonOperationTable[node.operator](left, right);
150
+ }
151
+ catch (error) {
152
+ return new FailCommand(new InterpreterError("ComparisonOperation", error.message));
153
+ }
154
+ });
155
+ });
156
+ });
157
+ });
158
+ }
159
+ visitLogicalBinaryOperation(node) {
160
+ return new BindCommand(this.evaluate(node.left), (left) => {
161
+ const logicValue = left.asLogic;
162
+ if (!logicValue)
163
+ return new FailCommand(new InterpreterError("LogicalBinaryOperation", `Expected left side to be boolean and got: ${left}`));
164
+ if (this.context.config.lazyLoading) {
165
+ if (node.operator === "And") {
166
+ const val = logicValue.toJSON();
167
+ if (val === false)
168
+ return boolean(false);
169
+ }
170
+ if (node.operator === "Or") {
171
+ const val = logicValue.toJSON();
172
+ if (val === true)
173
+ return boolean(true);
174
+ }
175
+ }
176
+ const fn = LogicalBinaryTable[node.operator];
177
+ if (!fn)
178
+ return new FailCommand(new InterpreterError("LogicalBinaryOperation", `Unknown operator '${node.operator}'`));
179
+ return fn(logicValue, () => this.evaluate(node.right));
180
+ });
181
+ }
182
+ visitLogicalUnaryOperation(node) {
183
+ return processUnary(this, node, LogicalUnaryTable, (a) => !!a.asLogic, "LogicalUnaryOperation");
184
+ }
185
+ visitBitwiseBinaryOperation(node) {
186
+ return processBinary(this, node, BitwiseBinaryTable, (a, b) => !!a.asNumeric && !!b.asNumeric, "BitwiseBinaryOperation");
187
+ }
188
+ visitBitwiseUnaryOperation(node) {
189
+ return processUnary(this, node, BitwiseUnaryTable, (a) => !!a.asNumeric, "BitwiseUnaryOperation");
190
+ }
191
+ visitStringOperation(node) {
192
+ return processBinary(this, node, StringOperationTable, (a, b) => !!a.asSummable && !!b.asSummable, "StringOperation");
193
+ }
194
+ visitUnifyOperation(node) {
195
+ return getLogicEngine(this, this.context).unifyExpr(node.left, node.right);
196
+ }
197
+ visitAssignOperation(node) {
198
+ if (!this.context.config.mutability) {
199
+ return raise(error("AssignOperation", `Cannot perform assignment operation: mutability is disabled`));
200
+ }
201
+ if (!(node.left instanceof SymbolPrimitive))
202
+ return new FailCommand(new InterpreterError("AssignOperation", "Left side must be a SymbolPrimitive"));
203
+ const name = node.left.value;
204
+ return new BindCommand(this.evaluate(node.right), (value) => {
205
+ const onReplace = (scope) => {
206
+ if (scope.has("self")) {
207
+ const self = scope.get("self");
208
+ if (self instanceof RuntimeObject && self.fields.has(name)) {
209
+ self.fields.set(name, value);
210
+ }
211
+ }
212
+ };
213
+ if (!this.context.replace(name, value, onReplace)) {
214
+ this.context.define(name, value);
215
+ }
216
+ return boolean(true);
217
+ });
218
+ }
219
+ visitArithmeticBinaryOperation(node) {
220
+ const isPlus = node.operator === "Plus";
221
+ const summablePair = (a, b) => !!a.asSummable && !!b.asSummable;
222
+ const numericPair = (a, b) => !!a.asNumeric && !!b.asNumeric;
223
+ return processBinary(this, node, ArithmeticBinaryTable, isPlus ? summablePair : numericPair, "ArithmeticBinaryOperation");
224
+ }
225
+ };
226
+ }
@@ -0,0 +1,19 @@
1
+ import { BooleanPrimitive, CharPrimitive, ListPrimitive, NilPrimitive, NumberPrimitive, StringPrimitive, SymbolPrimitive } from "yukigo-ast";
2
+ import { ExecutionCommand } from "../kernel/commands.js";
3
+ import { Constructor, EvaluatorBase } from "./BaseEvaluator.js";
4
+ export declare function PrimitiveEvaluator<TBase extends Constructor<EvaluatorBase>>(Base: TBase): {
5
+ new (...args: any[]): {
6
+ visitStringPrimitive(node: StringPrimitive): ExecutionCommand;
7
+ visitListPrimitive(node: ListPrimitive): ExecutionCommand;
8
+ visitNilPrimitive(node: NilPrimitive): ExecutionCommand;
9
+ visitSymbolPrimitive(node: SymbolPrimitive): ExecutionCommand;
10
+ visitCharPrimitive(node: CharPrimitive): ExecutionCommand;
11
+ visitNumberPrimitive(node: NumberPrimitive): ExecutionCommand;
12
+ visitBooleanPrimitive(node: BooleanPrimitive): ExecutionCommand;
13
+ context: import("../RuntimeContext.js").RuntimeContext;
14
+ getContext(): import("../RuntimeContext.js").RuntimeContext;
15
+ evaluate(node: import("yukigo-ast").ASTNode): ExecutionCommand;
16
+ realizeList(val: any): ExecutionCommand;
17
+ fallback(node: import("yukigo-ast").ASTNode): ExecutionCommand;
18
+ };
19
+ } & TBase;
@@ -0,0 +1,50 @@
1
+ import { BindCommand, FailCommand, StepCommand, } from "../kernel/commands.js";
2
+ import { YuArray, YuBoolean, YuNil, YuNumber, YuString, } from "../../primitives/index.js";
3
+ import { InterpreterError } from "../../errors.js";
4
+ export function PrimitiveEvaluator(Base) {
5
+ return class extends Base {
6
+ visitStringPrimitive(node) {
7
+ return new StepCommand(new YuString(node.value));
8
+ }
9
+ visitListPrimitive(node) {
10
+ if (node.value.length === 0)
11
+ return new StepCommand(new YuArray([]));
12
+ const results = [];
13
+ const evaluateNext = (index) => {
14
+ if (index >= node.value.length)
15
+ return new StepCommand(new YuArray(results));
16
+ return new BindCommand(this.evaluate(node.value[index]), (val) => {
17
+ results.push(val);
18
+ return evaluateNext(index + 1);
19
+ });
20
+ };
21
+ return evaluateNext(0);
22
+ }
23
+ visitNilPrimitive(node) {
24
+ return new StepCommand(YuNil.getInstance());
25
+ }
26
+ visitSymbolPrimitive(node) {
27
+ try {
28
+ const isLogic = !!this.context.logicState;
29
+ const isVar = /^[A-Z_]/.test(node.value);
30
+ if (isLogic && !isVar && !this.context.isDefined(node.value)) {
31
+ return new StepCommand(new YuString(node.value));
32
+ }
33
+ const val = this.context.lookup(node.value);
34
+ return new StepCommand(val);
35
+ }
36
+ catch (error) {
37
+ return new FailCommand(new InterpreterError("Symbol Lookup", error.message));
38
+ }
39
+ }
40
+ visitCharPrimitive(node) {
41
+ return new StepCommand(new YuString(node.value));
42
+ }
43
+ visitNumberPrimitive(node) {
44
+ return new StepCommand(new YuNumber(node.value));
45
+ }
46
+ visitBooleanPrimitive(node) {
47
+ return new StepCommand(new YuBoolean(node.value));
48
+ }
49
+ };
50
+ }
@@ -0,0 +1,28 @@
1
+ import { Assignment, Attribute, Function, If, LogicConstraint, Object, Print, Query, Raise, Return, Self, Sequence, Super, Try, Variable } from "yukigo-ast";
2
+ import { Constructor as EvaluatorConstructor, EvaluatorBase } from "./BaseEvaluator.js";
3
+ import { ExecutionCommand } from "../kernel/commands.js";
4
+ import { RuntimeContext } from "../RuntimeContext.js";
5
+ export declare function StatementEvaluator<TBase extends EvaluatorConstructor<EvaluatorBase>>(Base: TBase): {
6
+ new (...args: any[]): {
7
+ visitSequence(node: Sequence): ExecutionCommand;
8
+ visitSelf(node: Self): ExecutionCommand;
9
+ visitSuper(node: Super): ExecutionCommand;
10
+ visitIf(node: If): ExecutionCommand;
11
+ visitReturn(node: Return): ExecutionCommand;
12
+ visitFunction(node: Function): ExecutionCommand;
13
+ visitTry(node: Try): ExecutionCommand;
14
+ visitRaise(node: Raise): ExecutionCommand;
15
+ visitPrint(node: Print): ExecutionCommand;
16
+ visitVariable(node: Variable): ExecutionCommand;
17
+ visitAssignment(node: Assignment): ExecutionCommand;
18
+ visitQuery(node: Query): ExecutionCommand;
19
+ visitAttribute(node: Attribute): ExecutionCommand;
20
+ visitObject(node: Object): ExecutionCommand;
21
+ visitLogicConstraint(node: LogicConstraint): ExecutionCommand;
22
+ context: RuntimeContext;
23
+ getContext(): RuntimeContext;
24
+ evaluate(node: import("yukigo-ast").ASTNode): ExecutionCommand;
25
+ realizeList(val: any): ExecutionCommand;
26
+ fallback(node: import("yukigo-ast").ASTNode): ExecutionCommand;
27
+ };
28
+ } & TBase;