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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Fact } from "yukigo-ast";
|
|
2
|
+
import { InterpreterError } from "../../errors.js";
|
|
3
|
+
import { YuValue } from "../YuValue.js";
|
|
4
|
+
import { boolean, error, raise } from "../../utils.js";
|
|
5
|
+
export class RuntimePredicate extends YuValue {
|
|
6
|
+
identifier;
|
|
7
|
+
equations;
|
|
8
|
+
arity;
|
|
9
|
+
constructor(identifier, equations) {
|
|
10
|
+
super();
|
|
11
|
+
this.identifier = identifier;
|
|
12
|
+
this.equations = equations;
|
|
13
|
+
if (equations.length === 0) {
|
|
14
|
+
throw new InterpreterError("RuntimePredicate", `Predicate "${identifier}" must have at least one clause.`);
|
|
15
|
+
}
|
|
16
|
+
this.arity = this.getArityFromClause(equations[0]);
|
|
17
|
+
}
|
|
18
|
+
equals(other) {
|
|
19
|
+
return boolean(other === this);
|
|
20
|
+
}
|
|
21
|
+
compare(other) {
|
|
22
|
+
return raise(error("RuntimePredicate.compare", "Predicates are not comparable"));
|
|
23
|
+
}
|
|
24
|
+
apply(visitor) {
|
|
25
|
+
return this.equations.map((clause) => clause.accept(visitor));
|
|
26
|
+
}
|
|
27
|
+
addClause(clause) {
|
|
28
|
+
const clauseArity = this.getArityFromClause(clause);
|
|
29
|
+
if (!this.validateClause(clause)) {
|
|
30
|
+
throw new InterpreterError("RuntimePredicate", `Arity mismatch for "${this.identifier}": expected ${this.arity}, got ${clauseArity}.`);
|
|
31
|
+
}
|
|
32
|
+
this.equations.push(clause);
|
|
33
|
+
}
|
|
34
|
+
validateClause(clause) {
|
|
35
|
+
const clauseArity = this.getArityFromClause(clause);
|
|
36
|
+
return this.validateArity(clauseArity);
|
|
37
|
+
}
|
|
38
|
+
validateArity(args) {
|
|
39
|
+
return this.arity === args;
|
|
40
|
+
}
|
|
41
|
+
getArityFromClause(clause) {
|
|
42
|
+
if (clause.is(Fact))
|
|
43
|
+
return clause.patterns.length;
|
|
44
|
+
const patterns = clause.equations.length > 0 ? clause.equations[0].patterns : [];
|
|
45
|
+
return patterns.length;
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
return {
|
|
49
|
+
identifier: this.identifier,
|
|
50
|
+
arity: this.arity,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
toString() {
|
|
54
|
+
return `[Predicate: ${this.identifier}/${this.arity}]`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const isRuntimePredicate = (prim) => {
|
|
58
|
+
return prim instanceof RuntimePredicate;
|
|
59
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./YuValue.js";
|
|
2
|
+
export * from "./capabilities.js";
|
|
3
|
+
export { YuBoolean } from "./scalars/YuBoolean.js";
|
|
4
|
+
export { YuNil } from "./scalars/YuNil.js";
|
|
5
|
+
export { YuNumber } from "./scalars/YuNumber.js";
|
|
6
|
+
export { YuArray } from "./sequences/YuArray.js";
|
|
7
|
+
export { YuChar } from "./scalars/YuChar.js";
|
|
8
|
+
export { YuString } from "./sequences/YuString.js";
|
|
9
|
+
export * from "./entities/LazyList.js";
|
|
10
|
+
export * from "./entities/LogicResult.js";
|
|
11
|
+
export * from "./entities/RuntimeClass.js";
|
|
12
|
+
export * from "./entities/RuntimeFunction.js";
|
|
13
|
+
export * from "./entities/RuntimeObject.js";
|
|
14
|
+
export * from "./entities/RuntimePredicate.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./YuValue.js";
|
|
2
|
+
export * from "./capabilities.js";
|
|
3
|
+
export { YuBoolean } from "./scalars/YuBoolean.js";
|
|
4
|
+
export { YuNil } from "./scalars/YuNil.js";
|
|
5
|
+
export { YuNumber } from "./scalars/YuNumber.js";
|
|
6
|
+
export { YuArray } from "./sequences/YuArray.js";
|
|
7
|
+
export { YuChar } from "./scalars/YuChar.js";
|
|
8
|
+
export { YuString } from "./sequences/YuString.js";
|
|
9
|
+
export * from "./entities/LazyList.js";
|
|
10
|
+
export * from "./entities/LogicResult.js";
|
|
11
|
+
export * from "./entities/RuntimeClass.js";
|
|
12
|
+
export * from "./entities/RuntimeFunction.js";
|
|
13
|
+
export * from "./entities/RuntimeObject.js";
|
|
14
|
+
export * from "./entities/RuntimePredicate.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ExecutionCommand } from "../../components/kernel/commands.js";
|
|
2
|
+
import { Comparable, Logic, YuComparable, YuLogic } from "../capabilities.js";
|
|
3
|
+
import { YuValue } from "../YuValue.js";
|
|
4
|
+
export declare class YuBoolean extends YuValue implements Logic, Comparable {
|
|
5
|
+
readonly value: boolean;
|
|
6
|
+
constructor(value: boolean);
|
|
7
|
+
get asLogic(): YuLogic;
|
|
8
|
+
get asComparable(): YuComparable;
|
|
9
|
+
not(): ExecutionCommand;
|
|
10
|
+
equals(other: YuValue): ExecutionCommand;
|
|
11
|
+
equalsWithNumber(): ExecutionCommand;
|
|
12
|
+
equalsWithBoolean(left: YuBoolean): ExecutionCommand;
|
|
13
|
+
equalsWithString(): ExecutionCommand;
|
|
14
|
+
equalsWithArray(): ExecutionCommand;
|
|
15
|
+
equalsWithNil(): ExecutionCommand;
|
|
16
|
+
compare(other: YuValue): ExecutionCommand;
|
|
17
|
+
compareWithNumber(): ExecutionCommand;
|
|
18
|
+
compareWithBoolean(left: YuBoolean): ExecutionCommand;
|
|
19
|
+
compareWithString(): ExecutionCommand;
|
|
20
|
+
compareWithArray(): ExecutionCommand;
|
|
21
|
+
compareWithNil(): ExecutionCommand;
|
|
22
|
+
toString(): string;
|
|
23
|
+
toJSON(): boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { StepCommand, } from "../../components/kernel/commands.js";
|
|
2
|
+
import { UnsupportedOperation } from "../../errors.js";
|
|
3
|
+
import { boolean, raise } from "../../utils.js";
|
|
4
|
+
import { YuValue } from "../YuValue.js";
|
|
5
|
+
import { YuNumber } from "./YuNumber.js";
|
|
6
|
+
export class YuBoolean extends YuValue {
|
|
7
|
+
value;
|
|
8
|
+
constructor(value) {
|
|
9
|
+
super();
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
get asLogic() {
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
get asComparable() {
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
not() {
|
|
19
|
+
return boolean(!this.value);
|
|
20
|
+
}
|
|
21
|
+
equals(other) {
|
|
22
|
+
const c = other.asComparable;
|
|
23
|
+
if (!c)
|
|
24
|
+
return boolean(false);
|
|
25
|
+
return c.equalsWithBoolean(this);
|
|
26
|
+
}
|
|
27
|
+
equalsWithNumber() {
|
|
28
|
+
return boolean(false);
|
|
29
|
+
}
|
|
30
|
+
equalsWithBoolean(left) {
|
|
31
|
+
return boolean(left.value === this.value);
|
|
32
|
+
}
|
|
33
|
+
equalsWithString() {
|
|
34
|
+
return boolean(false);
|
|
35
|
+
}
|
|
36
|
+
equalsWithArray() {
|
|
37
|
+
return boolean(false);
|
|
38
|
+
}
|
|
39
|
+
equalsWithNil() {
|
|
40
|
+
return boolean(false);
|
|
41
|
+
}
|
|
42
|
+
compare(other) {
|
|
43
|
+
const c = other.asComparable;
|
|
44
|
+
if (!c)
|
|
45
|
+
return raise(new UnsupportedOperation(other, "compare"));
|
|
46
|
+
return c.compareWithBoolean(this);
|
|
47
|
+
}
|
|
48
|
+
compareWithNumber() {
|
|
49
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
50
|
+
}
|
|
51
|
+
compareWithBoolean(left) {
|
|
52
|
+
return new StepCommand(new YuNumber((left.value ? 1 : 0) - (this.value ? 1 : 0)));
|
|
53
|
+
}
|
|
54
|
+
compareWithString() {
|
|
55
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
56
|
+
}
|
|
57
|
+
compareWithArray() {
|
|
58
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
59
|
+
}
|
|
60
|
+
compareWithNil() {
|
|
61
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
62
|
+
}
|
|
63
|
+
toString() {
|
|
64
|
+
return this.value.toString();
|
|
65
|
+
}
|
|
66
|
+
toJSON() {
|
|
67
|
+
return this.value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ExecutionCommand } from "../../components/kernel/commands.js";
|
|
2
|
+
import { Comparable, Summable, YuComparable, YuSummable } from "../capabilities.js";
|
|
3
|
+
import { YuString } from "../sequences/YuString.js";
|
|
4
|
+
import { YuValue } from "../YuValue.js";
|
|
5
|
+
import { YuNumber } from "./YuNumber.js";
|
|
6
|
+
export declare class YuChar extends YuValue implements Comparable, Summable {
|
|
7
|
+
readonly value: string;
|
|
8
|
+
constructor(value: string);
|
|
9
|
+
get asSummable(): YuSummable;
|
|
10
|
+
get asComparable(): YuComparable;
|
|
11
|
+
equals(other: YuValue): ExecutionCommand;
|
|
12
|
+
equalsWithNumber(): ExecutionCommand;
|
|
13
|
+
equalsWithBoolean(): ExecutionCommand;
|
|
14
|
+
equalsWithString(left: YuString): ExecutionCommand;
|
|
15
|
+
equalsWithArray(): ExecutionCommand;
|
|
16
|
+
equalsWithNil(): ExecutionCommand;
|
|
17
|
+
compare(other: YuValue): ExecutionCommand;
|
|
18
|
+
compareWithNumber(): ExecutionCommand;
|
|
19
|
+
compareWithBoolean(): ExecutionCommand;
|
|
20
|
+
compareWithString(left: YuString): ExecutionCommand;
|
|
21
|
+
compareWithArray(): ExecutionCommand;
|
|
22
|
+
compareWithNil(): ExecutionCommand;
|
|
23
|
+
plus(other: YuValue): ExecutionCommand;
|
|
24
|
+
plusWithNumber(left: YuNumber): ExecutionCommand;
|
|
25
|
+
plusWithString(left: YuString): ExecutionCommand;
|
|
26
|
+
toString(): string;
|
|
27
|
+
toJSON(): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { StepCommand, } from "../../components/kernel/commands.js";
|
|
2
|
+
import { UnsupportedOperation } from "../../errors.js";
|
|
3
|
+
import { boolean, raise } from "../../utils.js";
|
|
4
|
+
import { YuString } from "../sequences/YuString.js";
|
|
5
|
+
import { YuValue } from "../YuValue.js";
|
|
6
|
+
import { YuNumber } from "./YuNumber.js";
|
|
7
|
+
export class YuChar extends YuValue {
|
|
8
|
+
value;
|
|
9
|
+
constructor(value) {
|
|
10
|
+
super();
|
|
11
|
+
this.value = value;
|
|
12
|
+
if (value.length !== 1)
|
|
13
|
+
throw new Error("YuChar must be a single character");
|
|
14
|
+
}
|
|
15
|
+
get asSummable() {
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
get asComparable() {
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
equals(other) {
|
|
22
|
+
const c = other.asComparable;
|
|
23
|
+
if (!c)
|
|
24
|
+
return boolean(false);
|
|
25
|
+
return c.equalsWithString(this);
|
|
26
|
+
}
|
|
27
|
+
equalsWithNumber() {
|
|
28
|
+
return boolean(false);
|
|
29
|
+
}
|
|
30
|
+
equalsWithBoolean() {
|
|
31
|
+
return boolean(false);
|
|
32
|
+
}
|
|
33
|
+
equalsWithString(left) {
|
|
34
|
+
return boolean(left.toJSON() === this.value);
|
|
35
|
+
}
|
|
36
|
+
equalsWithArray() {
|
|
37
|
+
return boolean(false);
|
|
38
|
+
}
|
|
39
|
+
equalsWithNil() {
|
|
40
|
+
return boolean(false);
|
|
41
|
+
}
|
|
42
|
+
compare(other) {
|
|
43
|
+
const c = other.asComparable;
|
|
44
|
+
if (!c)
|
|
45
|
+
return raise(new UnsupportedOperation(other, "compare"));
|
|
46
|
+
return c.compareWithString(new YuString(this.value));
|
|
47
|
+
}
|
|
48
|
+
compareWithNumber() {
|
|
49
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
50
|
+
}
|
|
51
|
+
compareWithBoolean() {
|
|
52
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
53
|
+
}
|
|
54
|
+
compareWithString(left) {
|
|
55
|
+
return new StepCommand(new YuNumber(left.toJSON().localeCompare(this.value)));
|
|
56
|
+
}
|
|
57
|
+
compareWithArray() {
|
|
58
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
59
|
+
}
|
|
60
|
+
compareWithNil() {
|
|
61
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
62
|
+
}
|
|
63
|
+
plus(other) {
|
|
64
|
+
return new StepCommand(new YuString(this.value + other.toString()));
|
|
65
|
+
}
|
|
66
|
+
plusWithNumber(left) {
|
|
67
|
+
return new StepCommand(new YuString(left.toJSON().toString() + this.value));
|
|
68
|
+
}
|
|
69
|
+
plusWithString(left) {
|
|
70
|
+
return new StepCommand(new YuString(left.toJSON() + this.value));
|
|
71
|
+
}
|
|
72
|
+
toString() {
|
|
73
|
+
return this.value;
|
|
74
|
+
}
|
|
75
|
+
toJSON() {
|
|
76
|
+
return this.value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ExecutionCommand } from "../../components/kernel/commands.js";
|
|
2
|
+
import { Comparable, YuComparable } from "../capabilities.js";
|
|
3
|
+
import { YuValue } from "../YuValue.js";
|
|
4
|
+
export declare class YuNil extends YuValue implements Comparable {
|
|
5
|
+
private static instance;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): YuNil;
|
|
8
|
+
get isNil(): boolean;
|
|
9
|
+
get asComparable(): YuComparable;
|
|
10
|
+
equals(other: YuValue): ExecutionCommand;
|
|
11
|
+
equalsWithNumber(): ExecutionCommand;
|
|
12
|
+
equalsWithBoolean(): ExecutionCommand;
|
|
13
|
+
equalsWithString(): ExecutionCommand;
|
|
14
|
+
equalsWithArray(): ExecutionCommand;
|
|
15
|
+
equalsWithNil(left: YuNil): ExecutionCommand;
|
|
16
|
+
compare(other: YuValue): ExecutionCommand;
|
|
17
|
+
compareWithNumber(): ExecutionCommand;
|
|
18
|
+
compareWithBoolean(): ExecutionCommand;
|
|
19
|
+
compareWithString(): ExecutionCommand;
|
|
20
|
+
compareWithArray(): ExecutionCommand;
|
|
21
|
+
compareWithNil(): ExecutionCommand;
|
|
22
|
+
private unsupportedCompare;
|
|
23
|
+
toString(): string;
|
|
24
|
+
toJSON(): null;
|
|
25
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { StepCommand, } from "../../components/kernel/commands.js";
|
|
2
|
+
import { UnsupportedOperation } from "../../errors.js";
|
|
3
|
+
import { boolean, raise } from "../../utils.js";
|
|
4
|
+
import { YuValue } from "../YuValue.js";
|
|
5
|
+
import { YuNumber } from "./YuNumber.js";
|
|
6
|
+
export class YuNil extends YuValue {
|
|
7
|
+
static instance;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
}
|
|
11
|
+
static getInstance() {
|
|
12
|
+
if (!YuNil.instance)
|
|
13
|
+
YuNil.instance = new YuNil();
|
|
14
|
+
return YuNil.instance;
|
|
15
|
+
}
|
|
16
|
+
get isNil() {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
get asComparable() {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
equals(other) {
|
|
23
|
+
const c = other.asComparable;
|
|
24
|
+
if (!c)
|
|
25
|
+
return boolean(false);
|
|
26
|
+
return c.equalsWithNil(this);
|
|
27
|
+
}
|
|
28
|
+
equalsWithNumber() {
|
|
29
|
+
return boolean(false);
|
|
30
|
+
}
|
|
31
|
+
equalsWithBoolean() {
|
|
32
|
+
return boolean(false);
|
|
33
|
+
}
|
|
34
|
+
equalsWithString() {
|
|
35
|
+
return boolean(false);
|
|
36
|
+
}
|
|
37
|
+
equalsWithArray() {
|
|
38
|
+
return boolean(false);
|
|
39
|
+
}
|
|
40
|
+
equalsWithNil(left) {
|
|
41
|
+
return boolean(true);
|
|
42
|
+
}
|
|
43
|
+
compare(other) {
|
|
44
|
+
const c = other.asComparable;
|
|
45
|
+
if (!c)
|
|
46
|
+
return raise(new UnsupportedOperation(other, "compare"));
|
|
47
|
+
return c.compareWithNil(this);
|
|
48
|
+
}
|
|
49
|
+
compareWithNumber() {
|
|
50
|
+
return this.unsupportedCompare();
|
|
51
|
+
}
|
|
52
|
+
compareWithBoolean() {
|
|
53
|
+
return this.unsupportedCompare();
|
|
54
|
+
}
|
|
55
|
+
compareWithString() {
|
|
56
|
+
return this.unsupportedCompare();
|
|
57
|
+
}
|
|
58
|
+
compareWithArray() {
|
|
59
|
+
return this.unsupportedCompare();
|
|
60
|
+
}
|
|
61
|
+
compareWithNil() {
|
|
62
|
+
return new StepCommand(new YuNumber(0));
|
|
63
|
+
}
|
|
64
|
+
unsupportedCompare() {
|
|
65
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
66
|
+
}
|
|
67
|
+
toString() {
|
|
68
|
+
return "nil";
|
|
69
|
+
}
|
|
70
|
+
toJSON() {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ExecutionCommand } from "../../components/kernel/commands.js";
|
|
2
|
+
import { Comparable, Numeric, Summable, YuComparable, YuNumeric, YuSummable } from "../capabilities.js";
|
|
3
|
+
import { YuString } from "../sequences/YuString.js";
|
|
4
|
+
import { YuValue } from "../YuValue.js";
|
|
5
|
+
export declare class YuNumber extends YuValue implements Summable, Numeric, Comparable {
|
|
6
|
+
readonly value: number;
|
|
7
|
+
constructor(value: number);
|
|
8
|
+
get asSummable(): YuSummable;
|
|
9
|
+
get asNumeric(): YuNumeric;
|
|
10
|
+
get asComparable(): YuComparable;
|
|
11
|
+
round(): ExecutionCommand;
|
|
12
|
+
abs(): ExecutionCommand;
|
|
13
|
+
ceil(): ExecutionCommand;
|
|
14
|
+
floor(): ExecutionCommand;
|
|
15
|
+
negation(): ExecutionCommand;
|
|
16
|
+
sqrt(): ExecutionCommand;
|
|
17
|
+
plus(other: YuValue): ExecutionCommand;
|
|
18
|
+
plusWithNumber(left: YuNumber): ExecutionCommand;
|
|
19
|
+
plusWithString(left: YuString): ExecutionCommand;
|
|
20
|
+
realize(): ExecutionCommand;
|
|
21
|
+
minus(other: YuValue): ExecutionCommand;
|
|
22
|
+
minusWithNumber(left: YuNumber): ExecutionCommand;
|
|
23
|
+
multiply(other: YuValue): ExecutionCommand;
|
|
24
|
+
multiplyWithNumber(left: YuNumber): ExecutionCommand;
|
|
25
|
+
divide(other: YuValue): ExecutionCommand;
|
|
26
|
+
divideWithNumber(left: YuNumber): ExecutionCommand;
|
|
27
|
+
modulo(other: YuValue): ExecutionCommand;
|
|
28
|
+
moduloWithNumber(left: YuNumber): ExecutionCommand;
|
|
29
|
+
power(other: YuValue): ExecutionCommand;
|
|
30
|
+
powerWithNumber(left: YuNumber): ExecutionCommand;
|
|
31
|
+
min(other: YuValue): ExecutionCommand;
|
|
32
|
+
minWithNumber(left: YuNumber): ExecutionCommand;
|
|
33
|
+
max(other: YuValue): ExecutionCommand;
|
|
34
|
+
maxWithNumber(left: YuNumber): ExecutionCommand;
|
|
35
|
+
equals(other: YuValue): ExecutionCommand;
|
|
36
|
+
equalsWithNumber(left: YuNumber): ExecutionCommand;
|
|
37
|
+
equalsWithBoolean(): ExecutionCommand;
|
|
38
|
+
equalsWithString(left: YuString): ExecutionCommand;
|
|
39
|
+
equalsWithArray(): ExecutionCommand;
|
|
40
|
+
equalsWithNil(): ExecutionCommand;
|
|
41
|
+
compare(other: YuValue): ExecutionCommand;
|
|
42
|
+
compareWithNumber(left: YuNumber): ExecutionCommand;
|
|
43
|
+
compareWithBoolean(): ExecutionCommand;
|
|
44
|
+
compareWithString(left: YuString): ExecutionCommand;
|
|
45
|
+
compareWithArray(): ExecutionCommand;
|
|
46
|
+
compareWithNil(): ExecutionCommand;
|
|
47
|
+
toString(): string;
|
|
48
|
+
toJSON(): number;
|
|
49
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { StepCommand, } from "../../components/kernel/commands.js";
|
|
2
|
+
import { UnsupportedOperation } from "../../errors.js";
|
|
3
|
+
import { boolean, number, raise } from "../../utils.js";
|
|
4
|
+
import { YuString } from "../sequences/YuString.js";
|
|
5
|
+
import { YuValue } from "../YuValue.js";
|
|
6
|
+
export class YuNumber extends YuValue {
|
|
7
|
+
value;
|
|
8
|
+
constructor(value) {
|
|
9
|
+
super();
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
get asSummable() {
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
get asNumeric() {
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
get asComparable() {
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
round() {
|
|
22
|
+
return number(Math.round(this.value));
|
|
23
|
+
}
|
|
24
|
+
abs() {
|
|
25
|
+
return number(Math.abs(this.value));
|
|
26
|
+
}
|
|
27
|
+
ceil() {
|
|
28
|
+
return number(Math.ceil(this.value));
|
|
29
|
+
}
|
|
30
|
+
floor() {
|
|
31
|
+
return number(Math.floor(this.value));
|
|
32
|
+
}
|
|
33
|
+
negation() {
|
|
34
|
+
return number(this.value * -1);
|
|
35
|
+
}
|
|
36
|
+
sqrt() {
|
|
37
|
+
return number(Math.sqrt(this.value));
|
|
38
|
+
}
|
|
39
|
+
plus(other) {
|
|
40
|
+
const s = other.asSummable;
|
|
41
|
+
if (!s)
|
|
42
|
+
return raise(new UnsupportedOperation(other, "plus"));
|
|
43
|
+
return s.plusWithNumber(this);
|
|
44
|
+
}
|
|
45
|
+
plusWithNumber(left) {
|
|
46
|
+
return number(left.value + this.value);
|
|
47
|
+
}
|
|
48
|
+
plusWithString(left) {
|
|
49
|
+
return new StepCommand(new YuString(left.toJSON() + this.value.toString()));
|
|
50
|
+
}
|
|
51
|
+
realize() {
|
|
52
|
+
return new StepCommand(this);
|
|
53
|
+
}
|
|
54
|
+
minus(other) {
|
|
55
|
+
const n = other.asNumeric;
|
|
56
|
+
if (!n)
|
|
57
|
+
return raise(new UnsupportedOperation(other, "minus"));
|
|
58
|
+
return n.minusWithNumber(this);
|
|
59
|
+
}
|
|
60
|
+
minusWithNumber(left) {
|
|
61
|
+
return number(left.value - this.value);
|
|
62
|
+
}
|
|
63
|
+
multiply(other) {
|
|
64
|
+
const n = other.asNumeric;
|
|
65
|
+
if (!n)
|
|
66
|
+
return raise(new UnsupportedOperation(other, "multiply"));
|
|
67
|
+
return n.multiplyWithNumber(this);
|
|
68
|
+
}
|
|
69
|
+
multiplyWithNumber(left) {
|
|
70
|
+
return number(left.value * this.value);
|
|
71
|
+
}
|
|
72
|
+
divide(other) {
|
|
73
|
+
const n = other.asNumeric;
|
|
74
|
+
if (!n)
|
|
75
|
+
return raise(new UnsupportedOperation(other, "divide"));
|
|
76
|
+
return n.divideWithNumber(this);
|
|
77
|
+
}
|
|
78
|
+
divideWithNumber(left) {
|
|
79
|
+
return number(left.value / this.value);
|
|
80
|
+
}
|
|
81
|
+
modulo(other) {
|
|
82
|
+
const n = other.asNumeric;
|
|
83
|
+
if (!n)
|
|
84
|
+
return raise(new UnsupportedOperation(other, "modulo"));
|
|
85
|
+
return n.moduloWithNumber(this);
|
|
86
|
+
}
|
|
87
|
+
moduloWithNumber(left) {
|
|
88
|
+
return number(left.value % this.value);
|
|
89
|
+
}
|
|
90
|
+
power(other) {
|
|
91
|
+
const n = other.asNumeric;
|
|
92
|
+
if (!n)
|
|
93
|
+
return raise(new UnsupportedOperation(other, "power"));
|
|
94
|
+
return n.powerWithNumber(this);
|
|
95
|
+
}
|
|
96
|
+
powerWithNumber(left) {
|
|
97
|
+
return number(left.value ** this.value);
|
|
98
|
+
}
|
|
99
|
+
min(other) {
|
|
100
|
+
const n = other.asNumeric;
|
|
101
|
+
if (!n)
|
|
102
|
+
return raise(new UnsupportedOperation(other, "power"));
|
|
103
|
+
return n.minWithNumber(this);
|
|
104
|
+
}
|
|
105
|
+
minWithNumber(left) {
|
|
106
|
+
return number(Math.min(left.value, this.value));
|
|
107
|
+
}
|
|
108
|
+
max(other) {
|
|
109
|
+
const n = other.asNumeric;
|
|
110
|
+
if (!n)
|
|
111
|
+
return raise(new UnsupportedOperation(other, "power"));
|
|
112
|
+
return n.maxWithNumber(this);
|
|
113
|
+
}
|
|
114
|
+
maxWithNumber(left) {
|
|
115
|
+
return number(Math.max(left.value, this.value));
|
|
116
|
+
}
|
|
117
|
+
equals(other) {
|
|
118
|
+
const c = other.asComparable;
|
|
119
|
+
if (!c)
|
|
120
|
+
return boolean(false);
|
|
121
|
+
return c.equalsWithNumber(this);
|
|
122
|
+
}
|
|
123
|
+
equalsWithNumber(left) {
|
|
124
|
+
return boolean(left.value === this.value);
|
|
125
|
+
}
|
|
126
|
+
equalsWithBoolean() {
|
|
127
|
+
return boolean(false);
|
|
128
|
+
}
|
|
129
|
+
equalsWithString(left) {
|
|
130
|
+
return boolean(left.toJSON() === this.value.toString());
|
|
131
|
+
}
|
|
132
|
+
equalsWithArray() {
|
|
133
|
+
return boolean(false);
|
|
134
|
+
}
|
|
135
|
+
equalsWithNil() {
|
|
136
|
+
return boolean(false);
|
|
137
|
+
}
|
|
138
|
+
compare(other) {
|
|
139
|
+
const c = other.asComparable;
|
|
140
|
+
if (!c)
|
|
141
|
+
return raise(new UnsupportedOperation(other, "compare"));
|
|
142
|
+
return c.compareWithNumber(this);
|
|
143
|
+
}
|
|
144
|
+
compareWithNumber(left) {
|
|
145
|
+
return number(left.value - this.value);
|
|
146
|
+
}
|
|
147
|
+
compareWithBoolean() {
|
|
148
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
149
|
+
}
|
|
150
|
+
compareWithString(left) {
|
|
151
|
+
return number(Number(left.toJSON()) - this.value);
|
|
152
|
+
}
|
|
153
|
+
compareWithArray() {
|
|
154
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
155
|
+
}
|
|
156
|
+
compareWithNil() {
|
|
157
|
+
return raise(new UnsupportedOperation(this, "compare"));
|
|
158
|
+
}
|
|
159
|
+
toString() {
|
|
160
|
+
return this.value.toString();
|
|
161
|
+
}
|
|
162
|
+
toJSON() {
|
|
163
|
+
return this.value;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { YuValue } from "../YuValue.js";
|
|
2
|
+
import { ExecutionCommand } from "../../components/kernel/commands.js";
|
|
3
|
+
import { Comparable, Sequence, YuComparable, YuSequence } from "../capabilities.js";
|
|
4
|
+
import { YuString } from "../index.js";
|
|
5
|
+
export declare class YuArray extends YuValue implements Sequence, Comparable {
|
|
6
|
+
readonly items: YuValue[];
|
|
7
|
+
readonly index: number;
|
|
8
|
+
constructor(items: YuValue[], index?: number);
|
|
9
|
+
get asSequence(): YuSequence;
|
|
10
|
+
get asComparable(): YuComparable;
|
|
11
|
+
[Symbol.iterator](): Iterator<YuValue>;
|
|
12
|
+
size(): ExecutionCommand;
|
|
13
|
+
step(): ExecutionCommand;
|
|
14
|
+
concat(other: YuValue): ExecutionCommand;
|
|
15
|
+
concatWithArray(arr: YuArray): ExecutionCommand;
|
|
16
|
+
concatWithString(str: YuString): ExecutionCommand;
|
|
17
|
+
at(index: number): YuValue;
|
|
18
|
+
flat(): YuArray;
|
|
19
|
+
equals(other: YuValue): ExecutionCommand;
|
|
20
|
+
equalsWithNumber(): ExecutionCommand;
|
|
21
|
+
equalsWithBoolean(): ExecutionCommand;
|
|
22
|
+
equalsWithString(): ExecutionCommand;
|
|
23
|
+
equalsWithArray(left: YuArray): ExecutionCommand;
|
|
24
|
+
equalsWithNil(): ExecutionCommand;
|
|
25
|
+
compare(other: YuValue): ExecutionCommand;
|
|
26
|
+
compareWithNumber(): ExecutionCommand;
|
|
27
|
+
compareWithBoolean(): ExecutionCommand;
|
|
28
|
+
compareWithString(): ExecutionCommand;
|
|
29
|
+
compareWithArray(left: YuArray): ExecutionCommand;
|
|
30
|
+
compareWithNil(): ExecutionCommand;
|
|
31
|
+
toJSON(keyOrSeen?: string | Set<YuValue>): unknown;
|
|
32
|
+
toString(seen?: Set<YuValue>): string;
|
|
33
|
+
}
|