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.
- package/.mocharc.json +3 -3
- package/CHANGELOG.md +105 -40
- package/README.md +193 -193
- package/dist/analyzer/GraphBuilder.d.ts +1 -0
- package/dist/analyzer/GraphBuilder.js +2 -1
- package/dist/analyzer/index.d.ts +0 -7
- package/dist/analyzer/index.js +3 -3
- package/dist/analyzer/inspections/functional/functional.d.ts +1 -1
- package/dist/analyzer/inspections/functional/functional.js +1 -1
- package/dist/analyzer/inspections/functional/smells.d.ts +3 -3
- package/dist/analyzer/inspections/functional/smells.js +27 -35
- package/dist/analyzer/inspections/generic/generic.d.ts +22 -14
- package/dist/analyzer/inspections/generic/generic.js +82 -60
- package/dist/analyzer/inspections/generic/smells.d.ts +2 -0
- package/dist/analyzer/inspections/generic/smells.js +55 -64
- package/dist/analyzer/inspections/imperative/imperative.d.ts +3 -3
- package/dist/analyzer/inspections/imperative/imperative.js +3 -3
- package/dist/analyzer/inspections/imperative/smells.d.ts +1 -0
- package/dist/analyzer/inspections/imperative/smells.js +8 -5
- package/dist/analyzer/inspections/logic/logic.d.ts +8 -8
- package/dist/analyzer/inspections/logic/logic.js +5 -5
- package/dist/analyzer/inspections/logic/smells.js +2 -2
- package/dist/analyzer/inspections/object/object.d.ts +5 -5
- package/dist/analyzer/inspections/object/object.js +22 -21
- package/dist/analyzer/inspections/object/smells.js +11 -23
- package/dist/analyzer/utils.d.ts +6 -2
- package/dist/analyzer/utils.js +6 -2
- package/dist/interpreter/components/EnvBuilder.d.ts +20 -1
- package/dist/interpreter/components/EnvBuilder.js +211 -66
- package/dist/interpreter/components/EqualityComparer.d.ts +15 -0
- package/dist/interpreter/components/EqualityComparer.js +69 -0
- package/dist/interpreter/components/Operations.d.ts +17 -14
- package/dist/interpreter/components/Operations.js +61 -62
- package/dist/interpreter/components/PatternMatcher.d.ts +19 -58
- package/dist/interpreter/components/PatternMatcher.js +185 -286
- package/dist/interpreter/components/RuntimeContext.d.ts +24 -15
- package/dist/interpreter/components/RuntimeContext.js +43 -4
- package/dist/interpreter/components/TestRunner.d.ts +15 -13
- package/dist/interpreter/components/TestRunner.js +86 -53
- package/dist/interpreter/components/evaluators/BaseEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/BaseEvaluator.js +20 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.d.ts +34 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.js +298 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.d.ts +25 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.js +226 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.js +50 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.d.ts +28 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.js +240 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.d.ts +15 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.js +14 -0
- package/dist/interpreter/components/evaluators/index.d.ts +110 -0
- package/dist/interpreter/components/evaluators/index.js +21 -0
- package/dist/interpreter/components/evaluators/utils.d.ts +7 -0
- package/dist/interpreter/components/evaluators/utils.js +50 -0
- package/dist/interpreter/components/hooks/YukigoHook.d.ts +27 -0
- package/dist/interpreter/components/hooks/YukigoHook.js +1 -0
- package/dist/interpreter/components/kernel/commands.d.ts +122 -0
- package/dist/interpreter/components/kernel/commands.js +203 -0
- package/dist/interpreter/components/kernel/index.d.ts +51 -0
- package/dist/interpreter/components/kernel/index.js +176 -0
- package/dist/interpreter/components/logic/LogicEngine.d.ts +26 -23
- package/dist/interpreter/components/logic/LogicEngine.js +234 -221
- package/dist/interpreter/components/logic/LogicResolver.d.ts +22 -51
- package/dist/interpreter/components/logic/LogicResolver.js +73 -440
- package/dist/interpreter/components/logic/LogicTerm.d.ts +104 -0
- package/dist/interpreter/components/logic/LogicTerm.js +423 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +25 -9
- package/dist/interpreter/components/logic/LogicTranslator.js +211 -74
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +6 -4
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +82 -84
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +13 -14
- package/dist/interpreter/components/runtimes/LazyRuntime.js +112 -239
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +17 -14
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +105 -74
- package/dist/interpreter/errors.d.ts +10 -0
- package/dist/interpreter/errors.js +17 -0
- package/dist/interpreter/index.d.ts +9 -5
- package/dist/interpreter/index.js +11 -13
- package/dist/interpreter/primitives/YuValue.d.ts +21 -0
- package/dist/interpreter/primitives/YuValue.js +40 -0
- package/dist/interpreter/primitives/capabilities.d.ts +90 -0
- package/dist/interpreter/primitives/capabilities.js +1 -0
- package/dist/interpreter/primitives/entities/LazyList.d.ts +48 -0
- package/dist/interpreter/primitives/entities/LazyList.js +164 -0
- package/dist/interpreter/primitives/entities/LogicResult.d.ts +51 -0
- package/dist/interpreter/primitives/entities/LogicResult.js +101 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.d.ts +24 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.js +57 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.d.ts +40 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.js +73 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.d.ts +27 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.js +82 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.d.ts +19 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.js +59 -0
- package/dist/interpreter/primitives/index.d.ts +14 -0
- package/dist/interpreter/primitives/index.js +14 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.d.ts +24 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.js +69 -0
- package/dist/interpreter/primitives/scalars/YuChar.d.ts +28 -0
- package/dist/interpreter/primitives/scalars/YuChar.js +78 -0
- package/dist/interpreter/primitives/scalars/YuNil.d.ts +25 -0
- package/dist/interpreter/primitives/scalars/YuNil.js +73 -0
- package/dist/interpreter/primitives/scalars/YuNumber.d.ts +49 -0
- package/dist/interpreter/primitives/scalars/YuNumber.js +165 -0
- package/dist/interpreter/primitives/sequences/YuArray.d.ts +33 -0
- package/dist/interpreter/primitives/sequences/YuArray.js +150 -0
- package/dist/interpreter/primitives/sequences/YuString.d.ts +40 -0
- package/dist/interpreter/primitives/sequences/YuString.js +130 -0
- package/dist/interpreter/utils.d.ts +23 -10
- package/dist/interpreter/utils.js +25 -30
- package/dist/tester/index.d.ts +3 -3
- package/dist/tester/index.js +39 -28
- package/dist/utils/helpers.d.ts +13 -5
- package/dist/utils/helpers.js +38 -85
- package/package.json +3 -16
- package/src/analyzer/GraphBuilder.ts +143 -142
- package/src/analyzer/index.ts +185 -194
- package/src/analyzer/inspections/functional/functional.ts +121 -121
- package/src/analyzer/inspections/functional/smells.ts +88 -102
- package/src/analyzer/inspections/generic/generic.ts +610 -577
- package/src/analyzer/inspections/generic/smells.ts +355 -365
- package/src/analyzer/inspections/imperative/imperative.ts +104 -101
- package/src/analyzer/inspections/imperative/smells.ts +58 -54
- package/src/analyzer/inspections/logic/logic.ts +84 -90
- package/src/analyzer/inspections/logic/smells.ts +54 -54
- package/src/analyzer/inspections/object/object.ts +295 -264
- package/src/analyzer/inspections/object/smells.ts +130 -144
- package/src/analyzer/utils.ts +115 -109
- package/src/index.ts +3 -3
- package/src/interpreter/components/EnvBuilder.ts +405 -202
- package/src/interpreter/components/EqualityComparer.ts +107 -0
- package/src/interpreter/components/Operations.ts +126 -99
- package/src/interpreter/components/PatternMatcher.ts +375 -475
- package/src/interpreter/components/RuntimeContext.ts +181 -119
- package/src/interpreter/components/TestRunner.ts +223 -151
- package/src/interpreter/components/evaluators/BaseEvaluator.ts +36 -0
- package/src/interpreter/components/evaluators/ExpressionEvaluator.ts +475 -0
- package/src/interpreter/components/evaluators/OperationEvaluator.ts +477 -0
- package/src/interpreter/components/evaluators/PrimitiveEvaluator.ts +80 -0
- package/src/interpreter/components/evaluators/StatementEvaluator.ts +372 -0
- package/src/interpreter/components/evaluators/TestingEvaluator.ts +26 -0
- package/src/interpreter/components/evaluators/index.ts +34 -0
- package/src/interpreter/components/evaluators/utils.ts +64 -0
- package/src/interpreter/components/hooks/YukigoHook.ts +45 -0
- package/src/interpreter/components/kernel/commands.ts +255 -0
- package/src/interpreter/components/kernel/index.ts +222 -0
- package/src/interpreter/components/logic/LogicEngine.ts +509 -519
- package/src/interpreter/components/logic/LogicResolver.ts +209 -858
- package/src/interpreter/components/logic/LogicTerm.ts +477 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +362 -149
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +249 -227
- package/src/interpreter/components/runtimes/LazyRuntime.ts +226 -334
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +262 -224
- package/src/interpreter/errors.ts +68 -47
- package/src/interpreter/index.ts +50 -52
- package/src/interpreter/primitives/YuValue.ts +64 -0
- package/src/interpreter/primitives/capabilities.ts +111 -0
- package/src/interpreter/primitives/entities/LazyList.ts +225 -0
- package/src/interpreter/primitives/entities/LogicResult.ts +133 -0
- package/src/interpreter/primitives/entities/RuntimeClass.ts +70 -0
- package/src/interpreter/primitives/entities/RuntimeFunction.ts +108 -0
- package/src/interpreter/primitives/entities/RuntimeObject.ts +110 -0
- package/src/interpreter/primitives/entities/RuntimePredicate.ts +77 -0
- package/src/interpreter/primitives/index.ts +17 -0
- package/src/interpreter/primitives/scalars/YuBoolean.ts +79 -0
- package/src/interpreter/primitives/scalars/YuChar.ts +94 -0
- package/src/interpreter/primitives/scalars/YuNil.ts +84 -0
- package/src/interpreter/primitives/scalars/YuNumber.ts +187 -0
- package/src/interpreter/primitives/sequences/YuArray.ts +178 -0
- package/src/interpreter/primitives/sequences/YuString.ts +165 -0
- package/src/interpreter/utils.ts +105 -84
- package/src/tester/index.ts +157 -128
- package/src/utils/helpers.ts +113 -169
- package/tests/analyzer/functional.spec.ts +221 -207
- package/tests/analyzer/generic.spec.ts +178 -178
- package/tests/analyzer/helpers.spec.ts +83 -89
- package/tests/analyzer/logic.spec.ts +237 -237
- package/tests/analyzer/oop.spec.ts +320 -323
- package/tests/analyzer/transitive.spec.ts +166 -166
- package/tests/interpreter/EnvBuilder.spec.ts +181 -183
- package/tests/interpreter/FunctionRuntime.spec.ts +224 -223
- package/tests/interpreter/LazyRuntime.spec.ts +227 -225
- package/tests/interpreter/LogicEngine.spec.ts +371 -327
- package/tests/interpreter/LogicSubstitution.spec.ts +90 -80
- package/tests/interpreter/ObjectRuntime.spec.ts +431 -606
- package/tests/interpreter/Operations.spec.ts +312 -220
- package/tests/interpreter/PatternSystem.spec.ts +254 -213
- package/tests/interpreter/Tests.spec.ts +122 -122
- package/tests/interpreter/interpreter.spec.ts +1143 -991
- package/tests/kernel/YukigoKernel.spec.ts +112 -0
- package/tests/tester/Tester.spec.ts +156 -152
- package/tsconfig.build.json +16 -15
- package/tsconfig.json +27 -25
- package/dist/interpreter/components/Visitor.d.ts +0 -70
- package/dist/interpreter/components/Visitor.js +0 -634
- package/dist/interpreter/entities.d.ts +0 -105
- package/dist/interpreter/entities.js +0 -96
- package/dist/interpreter/trampoline.d.ts +0 -17
- package/dist/interpreter/trampoline.js +0 -38
- package/dist/src/analyzer/GraphBuilder.d.ts +0 -30
- package/dist/src/analyzer/GraphBuilder.js +0 -100
- package/dist/src/analyzer/index.d.ts +0 -59
- package/dist/src/analyzer/index.js +0 -152
- package/dist/src/analyzer/inspections/functional/functional.d.ts +0 -44
- package/dist/src/analyzer/inspections/functional/functional.js +0 -149
- package/dist/src/analyzer/inspections/functional/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/functional/smells.js +0 -98
- package/dist/src/analyzer/inspections/generic/generic.d.ts +0 -178
- package/dist/src/analyzer/inspections/generic/generic.js +0 -604
- package/dist/src/analyzer/inspections/generic/smells.d.ts +0 -61
- package/dist/src/analyzer/inspections/generic/smells.js +0 -349
- package/dist/src/analyzer/inspections/imperative/imperative.d.ts +0 -35
- package/dist/src/analyzer/inspections/imperative/imperative.js +0 -109
- package/dist/src/analyzer/inspections/imperative/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/imperative/smells.js +0 -58
- package/dist/src/analyzer/inspections/logic/logic.d.ts +0 -32
- package/dist/src/analyzer/inspections/logic/logic.js +0 -96
- package/dist/src/analyzer/inspections/logic/smells.d.ts +0 -15
- package/dist/src/analyzer/inspections/logic/smells.js +0 -60
- package/dist/src/analyzer/inspections/object/object.d.ts +0 -90
- package/dist/src/analyzer/inspections/object/object.js +0 -321
- package/dist/src/analyzer/inspections/object/smells.d.ts +0 -30
- package/dist/src/analyzer/inspections/object/smells.js +0 -135
- package/dist/src/analyzer/utils.d.ts +0 -30
- package/dist/src/analyzer/utils.js +0 -78
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -4
- package/dist/src/interpreter/components/EnvBuilder.d.ts +0 -21
- package/dist/src/interpreter/components/EnvBuilder.js +0 -155
- package/dist/src/interpreter/components/Operations.d.ts +0 -14
- package/dist/src/interpreter/components/Operations.js +0 -84
- package/dist/src/interpreter/components/PatternMatcher.d.ts +0 -73
- package/dist/src/interpreter/components/PatternMatcher.js +0 -358
- package/dist/src/interpreter/components/RuntimeContext.d.ts +0 -35
- package/dist/src/interpreter/components/RuntimeContext.js +0 -93
- package/dist/src/interpreter/components/TestRunner.d.ts +0 -19
- package/dist/src/interpreter/components/TestRunner.js +0 -110
- package/dist/src/interpreter/components/Visitor.d.ts +0 -71
- package/dist/src/interpreter/components/Visitor.js +0 -638
- package/dist/src/interpreter/components/logic/LogicEngine.d.ts +0 -29
- package/dist/src/interpreter/components/logic/LogicEngine.js +0 -259
- package/dist/src/interpreter/components/logic/LogicResolver.d.ts +0 -53
- package/dist/src/interpreter/components/logic/LogicResolver.js +0 -484
- package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +0 -14
- package/dist/src/interpreter/components/logic/LogicTranslator.js +0 -99
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +0 -12
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +0 -149
- package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +0 -19
- package/dist/src/interpreter/components/runtimes/LazyRuntime.js +0 -269
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +0 -35
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +0 -126
- package/dist/src/interpreter/errors.d.ts +0 -19
- package/dist/src/interpreter/errors.js +0 -36
- package/dist/src/interpreter/index.d.ts +0 -24
- package/dist/src/interpreter/index.js +0 -41
- package/dist/src/interpreter/trampoline.d.ts +0 -17
- package/dist/src/interpreter/trampoline.js +0 -38
- package/dist/src/interpreter/utils.d.ts +0 -11
- package/dist/src/interpreter/utils.js +0 -65
- package/dist/src/tester/index.d.ts +0 -25
- package/dist/src/tester/index.js +0 -113
- package/dist/src/utils/helpers.d.ts +0 -13
- package/dist/src/utils/helpers.js +0 -52
- package/src/interpreter/components/Visitor.ts +0 -1065
- package/src/interpreter/trampoline.ts +0 -71
|
@@ -1,471 +1,104 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InterpreterError } from "../../errors.js";
|
|
2
|
+
import { StepCommand, BindCommand, FailCommand, ChoiceCommand, BacktrackCommand, } from "../kernel/commands.js";
|
|
3
|
+
import { isLogicResult, LogicResult, LogicAnswer, isRuntimePredicate, YuBoolean, YuNil, } from "../../primitives/index.js";
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
5
|
+
* Unified parameter list unification.
|
|
4
6
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Unifies two patterns given an existing set of substitutions.
|
|
10
|
-
* Returns the updated substitution map or null if unification fails.
|
|
11
|
-
*/
|
|
12
|
-
export function unify(t1, t2, argEnv) {
|
|
13
|
-
const env = argEnv ? new Map(argEnv) : new Map();
|
|
14
|
-
return unifyInPlace(t1, t2, env) ? env : null;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Internal unification that modifies the environment in place for efficiency during recursion.
|
|
18
|
-
*/
|
|
19
|
-
function unifyInPlace(t1, t2, env) {
|
|
20
|
-
const r1 = resolve(t1, env);
|
|
21
|
-
const r2 = resolve(t2, env);
|
|
22
|
-
if (r1 === r2)
|
|
23
|
-
return true;
|
|
24
|
-
if (r1 instanceof WildcardPattern || r2 instanceof WildcardPattern) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
if (r1 instanceof VariablePattern) {
|
|
28
|
-
env.set(r1.name.value, r2);
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
if (r2 instanceof VariablePattern) {
|
|
32
|
-
env.set(r2.name.value, r1);
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
if (r1 instanceof LiteralPattern && r2 instanceof LiteralPattern) {
|
|
36
|
-
return r1.name.equals(r2.name);
|
|
37
|
-
}
|
|
38
|
-
if (r1 instanceof FunctorPattern && r2 instanceof FunctorPattern) {
|
|
39
|
-
if (r1.identifier.value !== r2.identifier.value)
|
|
40
|
-
return false;
|
|
41
|
-
if (r1.args.length !== r2.args.length)
|
|
42
|
-
return false;
|
|
43
|
-
for (let i = 0; i < r1.args.length; i++) {
|
|
44
|
-
if (!unifyInPlace(r1.args[i], r2.args[i], env))
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
if (r1 instanceof ListPattern && r2 instanceof ListPattern) {
|
|
50
|
-
if (r1.elements.length !== r2.elements.length)
|
|
51
|
-
return false;
|
|
52
|
-
for (let i = 0; i < r1.elements.length; i++) {
|
|
53
|
-
if (!unifyInPlace(r1.elements[i], r2.elements[i], env))
|
|
54
|
-
return false;
|
|
7
|
+
function unifyParameters(patterns, args, baseSubst, translator, scope, onSuccess, onFailure) {
|
|
8
|
+
const next = (index, currentSubst) => {
|
|
9
|
+
if (index >= patterns.length) {
|
|
10
|
+
return onSuccess(currentSubst);
|
|
55
11
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let curr2 = r2;
|
|
61
|
-
while (curr1 instanceof ConsPattern && curr2 instanceof ConsPattern) {
|
|
62
|
-
if (!unifyInPlace(curr1.left, curr2.left, env))
|
|
63
|
-
return false;
|
|
64
|
-
curr1 = resolve(curr1.right, env);
|
|
65
|
-
curr2 = resolve(curr2.right, env);
|
|
66
|
-
}
|
|
67
|
-
return unifyInPlace(curr1, curr2, env);
|
|
68
|
-
}
|
|
69
|
-
if (r1 instanceof ConsPattern && r2 instanceof ListPattern) {
|
|
70
|
-
if (r2.elements.length === 0)
|
|
71
|
-
return false;
|
|
72
|
-
const [head, ...tail] = r2.elements;
|
|
73
|
-
return (unifyInPlace(r1.left, head, env) &&
|
|
74
|
-
unifyInPlace(r1.right, new ListPattern(tail), env));
|
|
75
|
-
}
|
|
76
|
-
if (r1 instanceof ListPattern && r2 instanceof ConsPattern) {
|
|
77
|
-
if (r1.elements.length === 0)
|
|
78
|
-
return false;
|
|
79
|
-
const [head, ...tail] = r1.elements;
|
|
80
|
-
return (unifyInPlace(head, r2.left, env) &&
|
|
81
|
-
unifyInPlace(new ListPattern(tail), r2.right, env));
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Follows variable bindings in the substitution map until a non-variable or unbound variable is found.
|
|
87
|
-
*/
|
|
88
|
-
export function resolve(node, env) {
|
|
89
|
-
let current = node;
|
|
90
|
-
const seen = new Set();
|
|
91
|
-
while (current instanceof VariablePattern) {
|
|
92
|
-
const name = current.name.value;
|
|
93
|
-
if (seen.has(name))
|
|
94
|
-
break;
|
|
95
|
-
seen.add(name);
|
|
96
|
-
const bound = env.get(name);
|
|
97
|
-
if (!bound)
|
|
98
|
-
break;
|
|
99
|
-
current = bound;
|
|
100
|
-
}
|
|
101
|
-
return current;
|
|
102
|
-
}
|
|
103
|
-
class Instantiator {
|
|
104
|
-
substs;
|
|
105
|
-
seen;
|
|
106
|
-
constructor(substs, seen = new Set()) {
|
|
107
|
-
this.substs = substs;
|
|
108
|
-
this.seen = seen;
|
|
109
|
-
}
|
|
110
|
-
visitVariablePattern(node) {
|
|
111
|
-
const name = node.name.value;
|
|
112
|
-
if (this.seen.has(name))
|
|
113
|
-
return node;
|
|
114
|
-
const val = this.substs.get(name);
|
|
115
|
-
if (val) {
|
|
116
|
-
const nextSeen = new Set(this.seen);
|
|
117
|
-
nextSeen.add(name);
|
|
118
|
-
return new Instantiator(this.substs, nextSeen).instantiate(val);
|
|
119
|
-
}
|
|
120
|
-
return node;
|
|
121
|
-
}
|
|
122
|
-
visitLiteralPattern(node) {
|
|
123
|
-
return node;
|
|
124
|
-
}
|
|
125
|
-
visitApplicationPattern(node) {
|
|
126
|
-
return new ApplicationPattern(node.identifier, node.args.map((arg) => this.instantiate(arg)), node.loc);
|
|
127
|
-
}
|
|
128
|
-
visitTuplePattern(node) {
|
|
129
|
-
return new TuplePattern(node.elements.map((el) => this.instantiate(el)), node.loc);
|
|
130
|
-
}
|
|
131
|
-
visitListPattern(node) {
|
|
132
|
-
return new ListPattern(node.elements.map((el) => this.instantiate(el)), node.loc);
|
|
133
|
-
}
|
|
134
|
-
visitFunctorPattern(node) {
|
|
135
|
-
return new FunctorPattern(node.identifier, node.args.map((arg) => this.instantiate(arg)), node.loc);
|
|
136
|
-
}
|
|
137
|
-
visitAsPattern(node) {
|
|
138
|
-
return new AsPattern(this.instantiate(node.left), this.instantiate(node.right), node.loc);
|
|
139
|
-
}
|
|
140
|
-
visitWildcardPattern(node) {
|
|
141
|
-
return node;
|
|
142
|
-
}
|
|
143
|
-
visitUnionPattern(node) {
|
|
144
|
-
return new UnionPattern(node.elements.map((el) => this.instantiate(el)), node.loc);
|
|
145
|
-
}
|
|
146
|
-
visitConstructorPattern(node) {
|
|
147
|
-
return new ConstructorPattern(node.identifier, node.args.map((arg) => this.instantiate(arg)), node.loc);
|
|
148
|
-
}
|
|
149
|
-
visitConsPattern(node) {
|
|
150
|
-
return new ConsPattern(this.instantiate(node.left), this.instantiate(node.right), node.loc);
|
|
151
|
-
}
|
|
152
|
-
visitTypePattern(node) {
|
|
153
|
-
return new TypePattern(node.targetType, node.innerPattern ? this.instantiate(node.innerPattern) : undefined, node.loc);
|
|
154
|
-
}
|
|
155
|
-
instantiate(pattern) {
|
|
156
|
-
return pattern.accept(this);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Fully instantiates a pattern by replacing all bound variables with their values.
|
|
161
|
-
*/
|
|
162
|
-
export function instantiate(pattern, substs, seen = new Set()) {
|
|
163
|
-
return new Instantiator(substs, seen).instantiate(pattern);
|
|
164
|
-
}
|
|
165
|
-
let variableCounter = 0;
|
|
166
|
-
class LogicVariableRenamer {
|
|
167
|
-
renames;
|
|
168
|
-
freshId;
|
|
169
|
-
constructor(renames, freshId) {
|
|
170
|
-
this.renames = renames;
|
|
171
|
-
this.freshId = freshId;
|
|
172
|
-
}
|
|
173
|
-
rename(node) {
|
|
174
|
-
if (!node || typeof node !== "object")
|
|
175
|
-
return node;
|
|
176
|
-
if (typeof node.accept === "function") {
|
|
177
|
-
return node.accept(this);
|
|
178
|
-
}
|
|
179
|
-
return node;
|
|
180
|
-
}
|
|
181
|
-
visitFact(node) {
|
|
182
|
-
return new Fact(node.identifier, node.patterns.map((p) => this.rename(p)), node.loc);
|
|
183
|
-
}
|
|
184
|
-
visitRule(node) {
|
|
185
|
-
const renamedEquations = node.equations.map((eq) => {
|
|
186
|
-
const body = eq.body;
|
|
187
|
-
if (!isUnguardedBody(body))
|
|
188
|
-
throw new Error("GuardedBody renaming not implemented");
|
|
189
|
-
return new Equation(eq.patterns.map((p) => this.rename(p)), body.accept(this), eq.returnExpr, eq.loc);
|
|
190
|
-
});
|
|
191
|
-
return new Rule(node.identifier, renamedEquations, node.loc);
|
|
192
|
-
}
|
|
193
|
-
visitUnguardedBody(node) {
|
|
194
|
-
return new UnguardedBody(new Sequence(node.sequence.statements.map((stmt) => this.rename(stmt)), node.sequence.loc), node.loc);
|
|
195
|
-
}
|
|
196
|
-
// PatternVisitor
|
|
197
|
-
visitVariablePattern(node) {
|
|
198
|
-
const name = node.name.value;
|
|
199
|
-
let newName = this.renames.get(name);
|
|
200
|
-
if (!newName) {
|
|
201
|
-
newName = `${name}_${this.freshId}`;
|
|
202
|
-
this.renames.set(name, newName);
|
|
203
|
-
}
|
|
204
|
-
return new VariablePattern(new SymbolPrimitive(newName), node.loc);
|
|
205
|
-
}
|
|
206
|
-
visitLiteralPattern(node) {
|
|
207
|
-
return node;
|
|
208
|
-
}
|
|
209
|
-
visitApplicationPattern(node) {
|
|
210
|
-
return new ApplicationPattern(node.identifier, node.args.map((arg) => this.rename(arg)), node.loc);
|
|
211
|
-
}
|
|
212
|
-
visitTuplePattern(node) {
|
|
213
|
-
return new TuplePattern(node.elements.map((el) => this.rename(el)), node.loc);
|
|
214
|
-
}
|
|
215
|
-
visitListPattern(node) {
|
|
216
|
-
return new ListPattern(node.elements.map((el) => this.rename(el)), node.loc);
|
|
217
|
-
}
|
|
218
|
-
visitFunctorPattern(node) {
|
|
219
|
-
return new FunctorPattern(node.identifier, node.args.map((arg) => this.rename(arg)), node.loc);
|
|
220
|
-
}
|
|
221
|
-
visitAsPattern(node) {
|
|
222
|
-
return new AsPattern(this.rename(node.left), this.rename(node.right), node.loc);
|
|
223
|
-
}
|
|
224
|
-
visitWildcardPattern(node) {
|
|
225
|
-
return node;
|
|
226
|
-
}
|
|
227
|
-
visitUnionPattern(node) {
|
|
228
|
-
return new UnionPattern(node.elements.map((el) => this.rename(el)), node.loc);
|
|
229
|
-
}
|
|
230
|
-
visitConstructorPattern(node) {
|
|
231
|
-
return new ConstructorPattern(node.identifier, node.args.map((arg) => this.rename(arg)), node.loc);
|
|
232
|
-
}
|
|
233
|
-
visitConsPattern(node) {
|
|
234
|
-
return new ConsPattern(this.rename(node.left), this.rename(node.right), node.loc);
|
|
235
|
-
}
|
|
236
|
-
visitTypePattern(node) {
|
|
237
|
-
return new TypePattern(node.targetType, node.innerPattern ? this.rename(node.innerPattern) : undefined, node.loc);
|
|
238
|
-
}
|
|
239
|
-
// Expression/Statement Visitor
|
|
240
|
-
visitSymbolPrimitive(node) {
|
|
241
|
-
const name = node.value;
|
|
242
|
-
if (/^[A-Z_]/.test(name) && name !== "_") {
|
|
243
|
-
let newName = this.renames.get(name);
|
|
244
|
-
if (!newName) {
|
|
245
|
-
newName = `${name}_${this.freshId}`;
|
|
246
|
-
this.renames.set(name, newName);
|
|
12
|
+
const term = translator.patternToTerm(patterns[index], scope);
|
|
13
|
+
return new BindCommand(term.unify(args[index], currentSubst), (res) => {
|
|
14
|
+
if (res instanceof YuBoolean && res.value) {
|
|
15
|
+
return next(index + 1, currentSubst);
|
|
247
16
|
}
|
|
248
|
-
return
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
visitNumberPrimitive(node) {
|
|
253
|
-
return node;
|
|
254
|
-
}
|
|
255
|
-
visitStringPrimitive(node) {
|
|
256
|
-
return node;
|
|
257
|
-
}
|
|
258
|
-
visitBooleanPrimitive(node) {
|
|
259
|
-
return node;
|
|
260
|
-
}
|
|
261
|
-
visitNilPrimitive(node) {
|
|
262
|
-
return node;
|
|
263
|
-
}
|
|
264
|
-
visitCharPrimitive(node) {
|
|
265
|
-
return node;
|
|
266
|
-
}
|
|
267
|
-
visitGoal(node) {
|
|
268
|
-
return new Goal(node.identifier, node.args.map((arg) => this.rename(arg)), node.loc);
|
|
269
|
-
}
|
|
270
|
-
visitExist(node) {
|
|
271
|
-
return new Exist(node.identifier, node.patterns.map((pat) => this.rename(pat)), node.loc);
|
|
272
|
-
}
|
|
273
|
-
visitFindall(node) {
|
|
274
|
-
return new Findall(this.rename(node.template), this.rename(node.goal), this.rename(node.bag), node.loc);
|
|
275
|
-
}
|
|
276
|
-
visitForall(node) {
|
|
277
|
-
return new Forall(this.rename(node.condition), this.rename(node.action), node.loc);
|
|
278
|
-
}
|
|
279
|
-
visitCall(node) {
|
|
280
|
-
return new Call(this.rename(node.callee), node.args.map((arg) => this.rename(arg)), node.loc);
|
|
281
|
-
}
|
|
282
|
-
visitNot(node) {
|
|
283
|
-
return new Not(this.rename(node.expression), node.loc);
|
|
284
|
-
}
|
|
285
|
-
visitLogicConstraint(node) {
|
|
286
|
-
return new LogicConstraint(this.rename(node.expression), node.loc);
|
|
287
|
-
}
|
|
288
|
-
visitSequence(node) {
|
|
289
|
-
return new Sequence(node.statements.map((stmt) => this.rename(stmt)), node.loc);
|
|
290
|
-
}
|
|
291
|
-
visitIf(node) {
|
|
292
|
-
return new If(this.rename(node.condition), this.rename(node.then), this.rename(node.elseExpr), node.loc);
|
|
293
|
-
}
|
|
294
|
-
visitComparisonOperation(node) {
|
|
295
|
-
return new ComparisonOperation(node.operator, this.rename(node.left), this.rename(node.right), node.loc);
|
|
296
|
-
}
|
|
297
|
-
visitUnifyOperation(node) {
|
|
298
|
-
return new UnifyOperation(node.operator, this.rename(node.left), this.rename(node.right), node.loc);
|
|
299
|
-
}
|
|
300
|
-
visitAssignOperation(node) {
|
|
301
|
-
return new AssignOperation(node.operator, this.rename(node.left), this.rename(node.right), node.loc);
|
|
302
|
-
}
|
|
303
|
-
visitArithmeticBinaryOperation(node) {
|
|
304
|
-
return new ArithmeticBinaryOperation(node.operator, this.rename(node.left), this.rename(node.right), node.loc);
|
|
305
|
-
}
|
|
306
|
-
visitArithmeticUnaryOperation(node) {
|
|
307
|
-
return new ArithmeticUnaryOperation(node.operator, this.rename(node.operand), node.loc);
|
|
308
|
-
}
|
|
309
|
-
visitListBinaryOperation(node) {
|
|
310
|
-
return new ListBinaryOperation(node.operator, this.rename(node.left), this.rename(node.right), node.loc);
|
|
311
|
-
}
|
|
312
|
-
visitListUnaryOperation(node) {
|
|
313
|
-
return new ListUnaryOperation(node.operator, this.rename(node.operand), node.loc);
|
|
314
|
-
}
|
|
315
|
-
visitLogicalBinaryOperation(node) {
|
|
316
|
-
return new LogicalBinaryOperation(node.operator, this.rename(node.left), this.rename(node.right), node.loc);
|
|
317
|
-
}
|
|
318
|
-
visitLogicalUnaryOperation(node) {
|
|
319
|
-
return new LogicalUnaryOperation(node.operator, this.rename(node.operand), node.loc);
|
|
320
|
-
}
|
|
321
|
-
visitBitwiseBinaryOperation(node) {
|
|
322
|
-
return new BitwiseBinaryOperation(node.operator, this.rename(node.left), this.rename(node.right), node.loc);
|
|
323
|
-
}
|
|
324
|
-
visitBitwiseUnaryOperation(node) {
|
|
325
|
-
return new BitwiseUnaryOperation(node.operator, this.rename(node.operand), node.loc);
|
|
326
|
-
}
|
|
327
|
-
visitStringOperation(node) {
|
|
328
|
-
return new StringOperation(node.operator, this.rename(node.left), this.rename(node.right), node.loc);
|
|
329
|
-
}
|
|
330
|
-
visitConsExpression(node) {
|
|
331
|
-
return new ConsExpression(this.rename(node.head), this.rename(node.tail), node.loc);
|
|
332
|
-
}
|
|
333
|
-
visitListPrimitive(node) {
|
|
334
|
-
return new ListPrimitive(node.value.map((el) => this.rename(el)), node.loc);
|
|
335
|
-
}
|
|
336
|
-
visitTupleExpr(node) {
|
|
337
|
-
return new TupleExpression(node.elements.map((el) => this.rename(el)), node.loc);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Renames all variables in a Rule or Fact to fresh names to avoid name clashes during unification.
|
|
342
|
-
*/
|
|
343
|
-
export function renameVariables(clause) {
|
|
344
|
-
const renames = new Map();
|
|
345
|
-
const freshId = ++variableCounter;
|
|
346
|
-
const renamer = new LogicVariableRenamer(renames, freshId);
|
|
347
|
-
const renamedClause = clause.accept(renamer);
|
|
348
|
-
return renamedClause;
|
|
17
|
+
return onFailure();
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
return next(0, new Map(baseSubst));
|
|
349
21
|
}
|
|
350
|
-
class
|
|
22
|
+
class KernelBodyVisitor {
|
|
351
23
|
solveBody;
|
|
352
24
|
substs;
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
constructor(solveBody, substs, onSuccess, onNextEq) {
|
|
25
|
+
scope;
|
|
26
|
+
constructor(solveBody, substs, scope) {
|
|
356
27
|
this.solveBody = solveBody;
|
|
357
28
|
this.substs = substs;
|
|
358
|
-
this.
|
|
359
|
-
|
|
29
|
+
this.scope = scope;
|
|
30
|
+
}
|
|
31
|
+
visitNativeBody(body) {
|
|
32
|
+
return new StepCommand(YuNil.getInstance());
|
|
360
33
|
}
|
|
361
34
|
visitUnguardedBody(body) {
|
|
362
|
-
return this.solveBody(body.sequence.statements, this.substs, this.
|
|
35
|
+
return this.solveBody(body.sequence.statements, this.substs, this.scope);
|
|
36
|
+
}
|
|
37
|
+
visitGuard(guard) {
|
|
38
|
+
return new BindCommand(this.solveBody([guard.condition], this.substs, this.scope), (res) => {
|
|
39
|
+
if (!isLogicResult(res) || !res.allSuccessful())
|
|
40
|
+
return new BacktrackCommand();
|
|
41
|
+
const solutions = res.getSuccessfulSolutions();
|
|
42
|
+
if (solutions.length === 1)
|
|
43
|
+
return this.solveBody([guard.body], solutions[0], this.scope);
|
|
44
|
+
return new ChoiceCommand(solutions.map((s) => this.solveBody([guard.body], s, this.scope)));
|
|
45
|
+
});
|
|
363
46
|
}
|
|
364
|
-
|
|
365
|
-
return
|
|
366
|
-
return this.solveBody([body.body], guardSubsts, this.onSuccess, this.onNextEq);
|
|
367
|
-
}, this.onNextEq);
|
|
47
|
+
fallback(node) {
|
|
48
|
+
return new FailCommand(new InterpreterError("Logic", `Unexpected node ${node.constructor.name} in equation body`));
|
|
368
49
|
}
|
|
369
50
|
}
|
|
370
|
-
class
|
|
51
|
+
export class GoalKernelVisitor {
|
|
371
52
|
args;
|
|
372
53
|
baseSubst;
|
|
373
54
|
solveBody;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
constructor(args, baseSubst, solveBody, onSuccess, onNextClause) {
|
|
55
|
+
translator;
|
|
56
|
+
constructor(args, baseSubst, solveBody, translator) {
|
|
377
57
|
this.args = args;
|
|
378
58
|
this.baseSubst = baseSubst;
|
|
379
59
|
this.solveBody = solveBody;
|
|
380
|
-
this.
|
|
381
|
-
this.onNextClause = onNextClause;
|
|
60
|
+
this.translator = translator;
|
|
382
61
|
}
|
|
383
62
|
visitFact(fact) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const substs = unifyParameters(renamedFact.patterns, this.args, this.baseSubst);
|
|
388
|
-
if (substs)
|
|
389
|
-
return this.onSuccess(substs, this.onNextClause);
|
|
390
|
-
return this.onNextClause;
|
|
63
|
+
const scope = new Map();
|
|
64
|
+
const onSuccess = (substs) => new StepCommand(new LogicResult([new LogicAnswer(true, substs)]));
|
|
65
|
+
return unifyParameters(fact.patterns, this.args, this.baseSubst, this.translator, scope, onSuccess, () => new BacktrackCommand());
|
|
391
66
|
}
|
|
392
67
|
visitRule(rule) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
return onNextEq;
|
|
407
|
-
const bodyVisitor = new CPSBodyVisitor(this.solveBody, substs, this.onSuccess, onNextEq);
|
|
408
|
-
if (isUnguardedBody(eq.body))
|
|
409
|
-
return eq.body.accept(bodyVisitor);
|
|
410
|
-
return eq.body.forEach((branch) => branch.accept(bodyVisitor));
|
|
68
|
+
const tryEquation = (eqIndex) => {
|
|
69
|
+
if (eqIndex >= rule.equations.length) {
|
|
70
|
+
return new BacktrackCommand();
|
|
71
|
+
}
|
|
72
|
+
const eq = rule.equations[eqIndex];
|
|
73
|
+
const scope = new Map();
|
|
74
|
+
const onFailure = () => tryEquation(eqIndex + 1);
|
|
75
|
+
const onSuccess = (substs) => {
|
|
76
|
+
const bodyVisitor = new KernelBodyVisitor(this.solveBody, substs, scope);
|
|
77
|
+
const currentCmd = eq.body.accept(bodyVisitor);
|
|
78
|
+
return new ChoiceCommand([currentCmd, tryEquation(eqIndex + 1)]);
|
|
79
|
+
};
|
|
80
|
+
return unifyParameters(eq.patterns, this.args, this.baseSubst, this.translator, scope, onSuccess, onFailure);
|
|
411
81
|
};
|
|
412
|
-
return (
|
|
82
|
+
return tryEquation(0);
|
|
413
83
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
* Solves a single logic goal (predicate call) using CPS.
|
|
417
|
-
*/
|
|
418
|
-
export function solveGoalCPS(ctx, predicateName, args, solveBody, baseSubst, onSuccess, onFailure) {
|
|
419
|
-
const tryClause = (index) => {
|
|
420
|
-
let equations;
|
|
421
|
-
try {
|
|
422
|
-
const pred = ctx.lookup(predicateName);
|
|
423
|
-
if (!pred || !isRuntimePredicate(pred))
|
|
424
|
-
return () => onFailure();
|
|
425
|
-
equations = pred.equations;
|
|
426
|
-
}
|
|
427
|
-
catch (error) {
|
|
428
|
-
return () => onFailure();
|
|
429
|
-
}
|
|
430
|
-
if (index >= equations.length)
|
|
431
|
-
return () => onFailure();
|
|
432
|
-
const clause = equations[index];
|
|
433
|
-
const onNextClause = () => tryClause(index + 1);
|
|
434
|
-
const clauseVisitor = new GoalSolverVisitor(args, baseSubst, solveBody, onSuccess, onNextClause);
|
|
435
|
-
return clause.accept(clauseVisitor);
|
|
436
|
-
};
|
|
437
|
-
return () => tryClause(0);
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Unifies two lists of parameters. Returns the resulting Substitution or null.
|
|
441
|
-
*/
|
|
442
|
-
function unifyParameters(patterns, args, baseSubst) {
|
|
443
|
-
let subst = new Map(baseSubst);
|
|
444
|
-
for (let i = 0; i < patterns.length; i++) {
|
|
445
|
-
const nextSubst = unify(patterns[i], args[i], subst);
|
|
446
|
-
if (!nextSubst)
|
|
447
|
-
return null;
|
|
448
|
-
subst = nextSubst;
|
|
84
|
+
fallback(node) {
|
|
85
|
+
return new FailCommand(new InterpreterError("Logic", `Unexpected node ${node.constructor.name} in predicate definition`));
|
|
449
86
|
}
|
|
450
|
-
return subst;
|
|
451
87
|
}
|
|
452
88
|
/**
|
|
453
|
-
* Solves a
|
|
89
|
+
* Solves a single logic goal (predicate call) using the Kernel.
|
|
90
|
+
* Returns a non-deterministic command. Aggregation should happen at top-level.
|
|
454
91
|
*/
|
|
455
|
-
export function
|
|
456
|
-
const
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return () => onFailure();
|
|
468
|
-
});
|
|
469
|
-
};
|
|
470
|
-
return collectResults();
|
|
92
|
+
export function solveGoalKernel(ctx, predicateName, args, solveBody, baseSubst, translator) {
|
|
93
|
+
const pred = ctx.isDefined(predicateName) ? ctx.lookup(predicateName) : null;
|
|
94
|
+
const validPredicate = isRuntimePredicate(pred) && pred.validateArity(args.length);
|
|
95
|
+
if (!validPredicate)
|
|
96
|
+
return new BacktrackCommand();
|
|
97
|
+
const visitor = new GoalKernelVisitor(args, baseSubst, solveBody, translator);
|
|
98
|
+
const choices = pred
|
|
99
|
+
.apply(visitor)
|
|
100
|
+
.filter((c) => !(c instanceof FailCommand));
|
|
101
|
+
if (choices.length === 0)
|
|
102
|
+
return new BacktrackCommand();
|
|
103
|
+
return choices.length === 1 ? choices[0] : new ChoiceCommand(choices);
|
|
471
104
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { YuValue } from "../../primitives/index.js";
|
|
2
|
+
import { ExecutionCommand } from "../kernel/commands.js";
|
|
3
|
+
import { LogicTerm, Substitution } from "../../primitives/entities/LogicResult.js";
|
|
4
|
+
/**
|
|
5
|
+
* Represents a logic variable with a unique numeric ID.
|
|
6
|
+
*/
|
|
7
|
+
export declare class VariableTerm extends LogicTerm {
|
|
8
|
+
readonly id: number;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly logicTermType = "Variable";
|
|
11
|
+
constructor(id: number, name: string);
|
|
12
|
+
getType(): string;
|
|
13
|
+
toJSON(): unknown;
|
|
14
|
+
resolve(env: Substitution): LogicTerm;
|
|
15
|
+
unify(other: LogicTerm, env: Substitution): ExecutionCommand;
|
|
16
|
+
occurs(v: VariableTerm, env: Substitution): boolean;
|
|
17
|
+
instantiate(env: Substitution, seen?: Set<number>): LogicTerm;
|
|
18
|
+
toPrimitive(env: Substitution): YuValue;
|
|
19
|
+
toString(): string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Represents a constant value (Numbers, Strings, Booleans).
|
|
23
|
+
*/
|
|
24
|
+
export declare class ConstantTerm extends LogicTerm {
|
|
25
|
+
readonly value: YuValue;
|
|
26
|
+
readonly logicTermType = "Constant";
|
|
27
|
+
constructor(value: YuValue);
|
|
28
|
+
equals(other: YuValue): ExecutionCommand;
|
|
29
|
+
compare(other: YuValue): ExecutionCommand;
|
|
30
|
+
getType(): string;
|
|
31
|
+
toJSON(): unknown;
|
|
32
|
+
resolve(): LogicTerm;
|
|
33
|
+
occurs(): boolean;
|
|
34
|
+
unify(other: LogicTerm, env: Substitution): ExecutionCommand;
|
|
35
|
+
instantiate(): LogicTerm;
|
|
36
|
+
toPrimitive(): YuValue;
|
|
37
|
+
toString(): string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Represents a compound structure (Functors, Constructors, Application).
|
|
41
|
+
*/
|
|
42
|
+
export declare class CompoundTerm extends LogicTerm {
|
|
43
|
+
readonly functor: string;
|
|
44
|
+
readonly args: LogicTerm[];
|
|
45
|
+
readonly logicTermType = "Compound";
|
|
46
|
+
constructor(functor: string, args: LogicTerm[]);
|
|
47
|
+
getType(): string;
|
|
48
|
+
toJSON(): unknown;
|
|
49
|
+
resolve(): LogicTerm;
|
|
50
|
+
occurs(v: VariableTerm, env: Substitution): boolean;
|
|
51
|
+
unify(other: LogicTerm, env: Substitution): ExecutionCommand;
|
|
52
|
+
instantiate(env: Substitution, seen?: Set<number>): LogicTerm;
|
|
53
|
+
toPrimitive(env: Substitution): YuValue;
|
|
54
|
+
toString(): string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Represents the wildcard pattern (_).
|
|
58
|
+
*/
|
|
59
|
+
export declare class WildcardTerm extends LogicTerm {
|
|
60
|
+
readonly logicTermType = "Wildcard";
|
|
61
|
+
equals(other: YuValue): ExecutionCommand;
|
|
62
|
+
compare(other: YuValue): ExecutionCommand;
|
|
63
|
+
getType(): string;
|
|
64
|
+
toJSON(): unknown;
|
|
65
|
+
resolve(): LogicTerm;
|
|
66
|
+
occurs(): boolean;
|
|
67
|
+
unify(other: LogicTerm, env: Substitution): ExecutionCommand;
|
|
68
|
+
instantiate(): LogicTerm;
|
|
69
|
+
toPrimitive(): YuValue;
|
|
70
|
+
toString(): string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Represents a List [x, y, z].
|
|
74
|
+
*/
|
|
75
|
+
export declare class ListTerm extends LogicTerm {
|
|
76
|
+
readonly elements: LogicTerm[];
|
|
77
|
+
readonly logicTermType = "List";
|
|
78
|
+
constructor(elements: LogicTerm[]);
|
|
79
|
+
getType(): string;
|
|
80
|
+
toJSON(): unknown;
|
|
81
|
+
resolve(): LogicTerm;
|
|
82
|
+
occurs(v: VariableTerm, env: Substitution): boolean;
|
|
83
|
+
unify(other: LogicTerm, env: Substitution): ExecutionCommand;
|
|
84
|
+
instantiate(env: Substitution, seen?: Set<number>): LogicTerm;
|
|
85
|
+
toPrimitive(env: Substitution): YuValue;
|
|
86
|
+
toString(): string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Represents a Cons cell (head:tail).
|
|
90
|
+
*/
|
|
91
|
+
export declare class ConsTerm extends LogicTerm {
|
|
92
|
+
readonly head: LogicTerm;
|
|
93
|
+
readonly tail: LogicTerm;
|
|
94
|
+
readonly logicTermType = "Cons";
|
|
95
|
+
constructor(head: LogicTerm, tail: LogicTerm);
|
|
96
|
+
getType(): string;
|
|
97
|
+
toJSON(): unknown;
|
|
98
|
+
resolve(): LogicTerm;
|
|
99
|
+
occurs(v: VariableTerm, env: Substitution): boolean;
|
|
100
|
+
unify(other: LogicTerm, env: Substitution): ExecutionCommand;
|
|
101
|
+
instantiate(env: Substitution, seen?: Set<number>): LogicTerm;
|
|
102
|
+
toPrimitive(env: Substitution): YuValue;
|
|
103
|
+
toString(): string;
|
|
104
|
+
}
|