@jplorg/jpl 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/main.js +3474 -0
- package/dist/types/applyDefaults.d.ts +2 -0
- package/dist/types/builtins/funcContains.d.ts +3 -0
- package/dist/types/builtins/funcEndsWith.d.ts +3 -0
- package/dist/types/builtins/funcError.d.ts +3 -0
- package/dist/types/builtins/funcFromJSON.d.ts +3 -0
- package/dist/types/builtins/funcHas.d.ts +3 -0
- package/dist/types/builtins/funcIn.d.ts +3 -0
- package/dist/types/builtins/funcKeys.d.ts +3 -0
- package/dist/types/builtins/funcLength.d.ts +3 -0
- package/dist/types/builtins/funcNow.d.ts +3 -0
- package/dist/types/builtins/funcStartsWith.d.ts +3 -0
- package/dist/types/builtins/funcToJSON.d.ts +3 -0
- package/dist/types/builtins/funcToLowerCase.d.ts +3 -0
- package/dist/types/builtins/funcToNumber.d.ts +3 -0
- package/dist/types/builtins/funcToString.d.ts +3 -0
- package/dist/types/builtins/funcToUpperCase.d.ts +3 -0
- package/dist/types/builtins/funcTrim.d.ts +3 -0
- package/dist/types/builtins/funcTrimEnd.d.ts +3 -0
- package/dist/types/builtins/funcTrimStart.d.ts +3 -0
- package/dist/types/builtins/funcType.d.ts +3 -0
- package/dist/types/builtins/funcVoid.d.ts +3 -0
- package/dist/types/builtins/index.d.ts +2 -0
- package/dist/types/builtins/internals.d.ts +1 -0
- package/dist/types/builtins/math.d.ts +17 -0
- package/dist/types/createSingleton.d.ts +1 -0
- package/dist/types/interpreter/index.d.ts +21 -0
- package/dist/types/interpreter/parse.d.ts +194 -0
- package/{src/interpreter/parseFunction.js → dist/types/interpreter/parseFunction.d.ts} +2 -10
- package/dist/types/interpreter/system.d.ts +3 -0
- package/dist/types/interpreter/util.d.ts +89 -0
- package/dist/types/library/apply.d.ts +32 -0
- package/dist/types/library/definition.d.ts +79 -0
- package/dist/types/library/errors/adaptErrors.d.ts +6 -0
- package/dist/types/library/errors/enclosure.d.ts +6 -0
- package/dist/types/library/errors/error.d.ts +6 -0
- package/dist/types/library/errors/execution.d.ts +12 -0
- package/dist/types/library/errors/fatal.d.ts +4 -0
- package/dist/types/library/errors/runtime.d.ts +46 -0
- package/dist/types/library/errors/syntax.d.ts +7 -0
- package/{src/library/functions.js → dist/types/library/functions.d.ts} +9 -30
- package/dist/types/library/index.d.ts +18 -0
- package/dist/types/library/mux.d.ts +19 -0
- package/{src/library/ops/op.js → dist/types/library/ops/op.d.ts} +25 -49
- package/{src/library/ops/opa.js → dist/types/library/ops/opa.d.ts} +4 -7
- package/{src/library/ops/opc.js → dist/types/library/ops/opc.d.ts} +6 -11
- package/{src/library/ops/opm.js → dist/types/library/ops/opm.d.ts} +5 -9
- package/{src/library/ops/opu.js → dist/types/library/ops/opu.d.ts} +8 -15
- package/dist/types/library/runtimeScope.d.ts +23 -0
- package/dist/types/library/runtimeSignal.d.ts +25 -0
- package/dist/types/library/types.d.ts +97 -0
- package/dist/types/main.d.ts +19 -0
- package/dist/types/program/handler.d.ts +12 -0
- package/dist/types/program/index.d.ts +40 -0
- package/dist/types/program/ops/index.d.ts +5 -0
- package/dist/types/program/ops/opAccess/index.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaField.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaFunction.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaIter.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaSlice.d.ts +11 -0
- package/dist/types/program/ops/opAnd.d.ts +11 -0
- package/dist/types/program/ops/opArrayConstructor.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/index.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuAddition.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuDivision.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuSet.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/index.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmAddition.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmDivision.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +11 -0
- package/dist/types/program/ops/opComparison/index.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcGreater.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcLess.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcUnequal.d.ts +11 -0
- package/dist/types/program/ops/opConstant.d.ts +11 -0
- package/dist/types/program/ops/opConstantFalse.d.ts +11 -0
- package/dist/types/program/ops/opConstantNull.d.ts +11 -0
- package/dist/types/program/ops/opConstantTrue.d.ts +11 -0
- package/dist/types/program/ops/opFunctionDefinition.d.ts +11 -0
- package/dist/types/program/ops/opIf.d.ts +11 -0
- package/dist/types/program/ops/opInterpolatedString.d.ts +11 -0
- package/dist/types/program/ops/opNegation.d.ts +11 -0
- package/dist/types/program/ops/opNot.d.ts +11 -0
- package/dist/types/program/ops/opNullCoalescence.d.ts +11 -0
- package/dist/types/program/ops/opNumber.d.ts +11 -0
- package/dist/types/program/ops/opObjectConstructor.d.ts +11 -0
- package/dist/types/program/ops/opOr.d.ts +11 -0
- package/dist/types/program/ops/opOutputConcat.d.ts +11 -0
- package/dist/types/program/ops/opString.d.ts +11 -0
- package/dist/types/program/ops/opTry.d.ts +11 -0
- package/dist/types/program/ops/opVariable.d.ts +11 -0
- package/dist/types/program/ops/opVariableDefinition.d.ts +11 -0
- package/dist/types/program/ops/opVoid.d.ts +11 -0
- package/dist/types/program/ops/utils.d.ts +5 -0
- package/dist/types/program/params.d.ts +68 -0
- package/dist/types/runtime/index.d.ts +83 -0
- package/package.json +66 -49
- package/{repl.js → repl.ts} +85 -39
- package/lib/applyDefaults.js +0 -34
- package/lib/builtins/funcContains.js +0 -25
- package/lib/builtins/funcEndsWith.js +0 -21
- package/lib/builtins/funcError.js +0 -11
- package/lib/builtins/funcFromJSON.js +0 -26
- package/lib/builtins/funcHas.js +0 -24
- package/lib/builtins/funcIn.js +0 -24
- package/lib/builtins/funcKeys.js +0 -20
- package/lib/builtins/funcLength.js +0 -24
- package/lib/builtins/funcNow.js +0 -10
- package/lib/builtins/funcStartsWith.js +0 -21
- package/lib/builtins/funcToJSON.js +0 -10
- package/lib/builtins/funcToLowerCase.js +0 -17
- package/lib/builtins/funcToNumber.js +0 -26
- package/lib/builtins/funcToString.js +0 -10
- package/lib/builtins/funcToUpperCase.js +0 -17
- package/lib/builtins/funcTrim.js +0 -17
- package/lib/builtins/funcTrimEnd.js +0 -17
- package/lib/builtins/funcTrimStart.js +0 -17
- package/lib/builtins/funcType.js +0 -10
- package/lib/builtins/funcVoid.js +0 -10
- package/lib/builtins/index.js +0 -205
- package/lib/builtins/internals.js +0 -8
- package/lib/builtins/math.js +0 -40
- package/lib/builtins/native.js +0 -180
- package/lib/createSingleton.js +0 -14
- package/lib/index.js +0 -79
- package/lib/interpreter/index.js +0 -56
- package/lib/interpreter/parse.js +0 -2377
- package/lib/interpreter/parseFunction.js +0 -24
- package/lib/interpreter/system.js +0 -10
- package/lib/interpreter/util.js +0 -349
- package/lib/library/apply.js +0 -142
- package/lib/library/definition.js +0 -9
- package/lib/library/errors/adaptErrors.js +0 -34
- package/lib/library/errors/enclosure.js +0 -16
- package/lib/library/errors/error.js +0 -18
- package/lib/library/errors/execution.js +0 -20
- package/lib/library/errors/fatal.js +0 -15
- package/lib/library/errors/runtime.js +0 -78
- package/lib/library/errors/syntax.js +0 -17
- package/lib/library/functions.js +0 -82
- package/lib/library/index.js +0 -335
- package/lib/library/mux.js +0 -106
- package/lib/library/ops/index.js +0 -60
- package/lib/library/ops/op.js +0 -180
- package/lib/library/ops/opa.js +0 -41
- package/lib/library/ops/opc.js +0 -59
- package/lib/library/ops/opm.js +0 -50
- package/lib/library/ops/opu.js +0 -77
- package/lib/library/runtimeScope.js +0 -38
- package/lib/library/runtimeSignal.js +0 -72
- package/lib/library/types.js +0 -304
- package/lib/program/index.js +0 -101
- package/lib/program/ops/index.js +0 -61
- package/lib/program/ops/opAccess/index.js +0 -55
- package/lib/program/ops/opAccess/opaField.js +0 -50
- package/lib/program/ops/opAccess/opaFunction.js +0 -50
- package/lib/program/ops/opAccess/opaIter.js +0 -33
- package/lib/program/ops/opAccess/opaSlice.js +0 -46
- package/lib/program/ops/opAnd.js +0 -30
- package/lib/program/ops/opArrayConstructor.js +0 -20
- package/lib/program/ops/opAssignment/index.js +0 -90
- package/lib/program/ops/opAssignment/opaAssignField.js +0 -125
- package/lib/program/ops/opAssignment/opaAssignIter.js +0 -71
- package/lib/program/ops/opAssignment/opaAssignSlice.js +0 -101
- package/lib/program/ops/opAssignment/opuAddition.js +0 -31
- package/lib/program/ops/opAssignment/opuDivision.js +0 -31
- package/lib/program/ops/opAssignment/opuMultiplication.js +0 -31
- package/lib/program/ops/opAssignment/opuNullCoalescence.js +0 -25
- package/lib/program/ops/opAssignment/opuRemainder.js +0 -31
- package/lib/program/ops/opAssignment/opuSet.js +0 -19
- package/lib/program/ops/opAssignment/opuSubtraction.js +0 -31
- package/lib/program/ops/opAssignment/opuUpdate.js +0 -19
- package/lib/program/ops/opCalculation/index.js +0 -57
- package/lib/program/ops/opCalculation/opmAddition.js +0 -49
- package/lib/program/ops/opCalculation/opmDivision.js +0 -42
- package/lib/program/ops/opCalculation/opmMultiplication.js +0 -40
- package/lib/program/ops/opCalculation/opmRemainder.js +0 -34
- package/lib/program/ops/opCalculation/opmSubtraction.js +0 -53
- package/lib/program/ops/opComparison/index.js +0 -59
- package/lib/program/ops/opComparison/opcEqual.js +0 -19
- package/lib/program/ops/opComparison/opcGreater.js +0 -19
- package/lib/program/ops/opComparison/opcGreaterEqual.js +0 -19
- package/lib/program/ops/opComparison/opcLess.js +0 -19
- package/lib/program/ops/opComparison/opcLessEqual.js +0 -19
- package/lib/program/ops/opComparison/opcUnequal.js +0 -19
- package/lib/program/ops/opConstant.js +0 -18
- package/lib/program/ops/opConstantFalse.js +0 -16
- package/lib/program/ops/opConstantNull.js +0 -16
- package/lib/program/ops/opConstantTrue.js +0 -16
- package/lib/program/ops/opFunctionDefinition.js +0 -21
- package/lib/program/ops/opIf.js +0 -38
- package/lib/program/ops/opInterpolatedString.js +0 -24
- package/lib/program/ops/opNegation.js +0 -25
- package/lib/program/ops/opNot.js +0 -16
- package/lib/program/ops/opNullCoalescence.js +0 -34
- package/lib/program/ops/opNumber.js +0 -18
- package/lib/program/ops/opObjectConstructor.js +0 -37
- package/lib/program/ops/opOr.js +0 -30
- package/lib/program/ops/opOutputConcat.js +0 -19
- package/lib/program/ops/opString.js +0 -18
- package/lib/program/ops/opTry.js +0 -37
- package/lib/program/ops/opVariable.js +0 -20
- package/lib/program/ops/opVariableDefinition.js +0 -24
- package/lib/program/ops/opVoid.js +0 -16
- package/lib/program/ops/utils.js +0 -35
- package/lib/runtime/index.js +0 -258
- package/src/applyDefaults.js +0 -35
- package/src/builtins/funcContains.js +0 -27
- package/src/builtins/funcEndsWith.js +0 -21
- package/src/builtins/funcError.js +0 -7
- package/src/builtins/funcFromJSON.js +0 -24
- package/src/builtins/funcHas.js +0 -25
- package/src/builtins/funcIn.js +0 -25
- package/src/builtins/funcKeys.js +0 -20
- package/src/builtins/funcLength.js +0 -26
- package/src/builtins/funcNow.js +0 -5
- package/src/builtins/funcStartsWith.js +0 -21
- package/src/builtins/funcToJSON.js +0 -5
- package/src/builtins/funcToLowerCase.js +0 -20
- package/src/builtins/funcToNumber.js +0 -25
- package/src/builtins/funcToString.js +0 -5
- package/src/builtins/funcToUpperCase.js +0 -20
- package/src/builtins/funcTrim.js +0 -16
- package/src/builtins/funcTrimEnd.js +0 -16
- package/src/builtins/funcTrimStart.js +0 -16
- package/src/builtins/funcType.js +0 -5
- package/src/builtins/funcVoid.js +0 -5
- package/src/builtins/index.js +0 -193
- package/src/builtins/internals.js +0 -9
- package/src/builtins/math.js +0 -44
- package/src/createSingleton.js +0 -9
- package/src/index.js +0 -44
- package/src/interpreter/index.js +0 -48
- package/src/interpreter/parse.js +0 -1473
- package/src/interpreter/system.js +0 -5
- package/src/interpreter/util.js +0 -237
- package/src/library/apply.js +0 -135
- package/src/library/definition.js +0 -3
- package/src/library/errors/adaptErrors.js +0 -28
- package/src/library/errors/enclosure.js +0 -11
- package/src/library/errors/error.js +0 -14
- package/src/library/errors/execution.js +0 -15
- package/src/library/errors/fatal.js +0 -10
- package/src/library/errors/runtime.js +0 -71
- package/src/library/errors/syntax.js +0 -12
- package/src/library/index.js +0 -41
- package/src/library/mux.js +0 -98
- package/src/library/runtimeScope.js +0 -35
- package/src/library/runtimeSignal.js +0 -67
- package/src/library/types.js +0 -299
- package/src/program/index.js +0 -114
- package/src/program/ops/index.js +0 -82
- package/src/program/ops/opAccess/index.js +0 -55
- package/src/program/ops/opAccess/opaField.js +0 -58
- package/src/program/ops/opAccess/opaFunction.js +0 -52
- package/src/program/ops/opAccess/opaIter.js +0 -34
- package/src/program/ops/opAccess/opaSlice.js +0 -61
- package/src/program/ops/opAnd.js +0 -32
- package/src/program/ops/opArrayConstructor.js +0 -16
- package/src/program/ops/opAssignment/index.js +0 -102
- package/src/program/ops/opAssignment/opaAssignField.js +0 -156
- package/src/program/ops/opAssignment/opaAssignIter.js +0 -77
- package/src/program/ops/opAssignment/opaAssignSlice.js +0 -160
- package/src/program/ops/opAssignment/opuAddition.js +0 -29
- package/src/program/ops/opAssignment/opuDivision.js +0 -29
- package/src/program/ops/opAssignment/opuMultiplication.js +0 -29
- package/src/program/ops/opAssignment/opuNullCoalescence.js +0 -26
- package/src/program/ops/opAssignment/opuRemainder.js +0 -29
- package/src/program/ops/opAssignment/opuSet.js +0 -15
- package/src/program/ops/opAssignment/opuSubtraction.js +0 -29
- package/src/program/ops/opAssignment/opuUpdate.js +0 -15
- package/src/program/ops/opCalculation/index.js +0 -64
- package/src/program/ops/opCalculation/opmAddition.js +0 -63
- package/src/program/ops/opCalculation/opmDivision.js +0 -47
- package/src/program/ops/opCalculation/opmMultiplication.js +0 -52
- package/src/program/ops/opCalculation/opmRemainder.js +0 -49
- package/src/program/ops/opCalculation/opmSubtraction.js +0 -72
- package/src/program/ops/opComparison/index.js +0 -67
- package/src/program/ops/opComparison/opcEqual.js +0 -17
- package/src/program/ops/opComparison/opcGreater.js +0 -17
- package/src/program/ops/opComparison/opcGreaterEqual.js +0 -17
- package/src/program/ops/opComparison/opcLess.js +0 -17
- package/src/program/ops/opComparison/opcLessEqual.js +0 -17
- package/src/program/ops/opComparison/opcUnequal.js +0 -17
- package/src/program/ops/opConstant.js +0 -13
- package/src/program/ops/opConstantFalse.js +0 -11
- package/src/program/ops/opConstantNull.js +0 -11
- package/src/program/ops/opConstantTrue.js +0 -11
- package/src/program/ops/opFunctionDefinition.js +0 -17
- package/src/program/ops/opIf.js +0 -44
- package/src/program/ops/opInterpolatedString.js +0 -27
- package/src/program/ops/opNegation.js +0 -26
- package/src/program/ops/opNot.js +0 -11
- package/src/program/ops/opNullCoalescence.js +0 -36
- package/src/program/ops/opNumber.js +0 -13
- package/src/program/ops/opObjectConstructor.js +0 -40
- package/src/program/ops/opOr.js +0 -32
- package/src/program/ops/opOutputConcat.js +0 -17
- package/src/program/ops/opString.js +0 -13
- package/src/program/ops/opTry.js +0 -38
- package/src/program/ops/opVariable.js +0 -17
- package/src/program/ops/opVariableDefinition.js +0 -18
- package/src/program/ops/opVoid.js +0 -11
- package/src/program/ops/utils.js +0 -19
- package/src/runtime/index.js +0 -309
- /package/{src/builtins/native.js → dist/types/builtins/native.d.ts} +0 -0
- /package/{src/library/ops/index.js → dist/types/library/ops/index.d.ts} +0 -0
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { JPLRuntimeError, JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
function builtin(runtime, signal, next, input) {
|
|
4
|
-
const value = runtime.unwrapValue(input);
|
|
5
|
-
const t = runtime.type(value);
|
|
6
|
-
|
|
7
|
-
switch (t) {
|
|
8
|
-
case 'string': {
|
|
9
|
-
let result;
|
|
10
|
-
try {
|
|
11
|
-
result = JSON.parse(value);
|
|
12
|
-
} catch (err) {
|
|
13
|
-
throw new JPLRuntimeError(err.message);
|
|
14
|
-
}
|
|
15
|
-
return next(result);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
default:
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
throw new JPLTypeError('%s (%*<100v) cannot be parsed as JSON', t, value);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default builtin;
|
package/src/builtins/funcHas.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
function builtin(runtime, signal, next, input, arg0) {
|
|
4
|
-
const value = runtime.unwrapValue(input);
|
|
5
|
-
const tv = runtime.type(value);
|
|
6
|
-
|
|
7
|
-
const key = runtime.unwrapValue(arg0 ?? null);
|
|
8
|
-
const tk = runtime.type(key);
|
|
9
|
-
|
|
10
|
-
switch (tv) {
|
|
11
|
-
case 'array':
|
|
12
|
-
if (tk === 'number') return next(key >= 0 && key < value.length);
|
|
13
|
-
break;
|
|
14
|
-
|
|
15
|
-
case 'object':
|
|
16
|
-
if (tk === 'string') return next(Object.hasOwn(value, key));
|
|
17
|
-
break;
|
|
18
|
-
|
|
19
|
-
default:
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
throw new JPLTypeError('%s (%*<100v) cannot have %s (%*<100v) as key', tv, value, tk, key);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default builtin;
|
package/src/builtins/funcIn.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
function builtin(runtime, signal, next, input, arg0) {
|
|
4
|
-
const key = runtime.unwrapValue(input);
|
|
5
|
-
const tk = runtime.type(key);
|
|
6
|
-
|
|
7
|
-
const value = runtime.unwrapValue(arg0 ?? null);
|
|
8
|
-
const tv = runtime.type(value);
|
|
9
|
-
|
|
10
|
-
switch (tv) {
|
|
11
|
-
case 'array':
|
|
12
|
-
if (tk === 'number') return next(key >= 0 && key < value.length);
|
|
13
|
-
break;
|
|
14
|
-
|
|
15
|
-
case 'object':
|
|
16
|
-
if (tk === 'string') return next(Object.hasOwn(value, key));
|
|
17
|
-
break;
|
|
18
|
-
|
|
19
|
-
default:
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
throw new JPLTypeError('%s (%*<100v) cannot have %s (%*<100v) as key', tv, value, tk, key);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default builtin;
|
package/src/builtins/funcKeys.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
function builtin(runtime, signal, next, input) {
|
|
4
|
-
const value = runtime.unwrapValue(input);
|
|
5
|
-
const t = runtime.type(value);
|
|
6
|
-
|
|
7
|
-
switch (t) {
|
|
8
|
-
case 'array':
|
|
9
|
-
return next(value.map((_, i) => i));
|
|
10
|
-
|
|
11
|
-
case 'object':
|
|
12
|
-
return next(Object.keys(value));
|
|
13
|
-
|
|
14
|
-
default:
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
throw new JPLTypeError('%s (%*<100v) has no keys', t, value);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default builtin;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
function builtin(runtime, signal, next, input) {
|
|
4
|
-
const value = runtime.unwrapValue(input);
|
|
5
|
-
const t = runtime.type(value);
|
|
6
|
-
|
|
7
|
-
switch (t) {
|
|
8
|
-
case 'null':
|
|
9
|
-
return next(0);
|
|
10
|
-
|
|
11
|
-
case 'array':
|
|
12
|
-
return next(value.length);
|
|
13
|
-
|
|
14
|
-
case 'string':
|
|
15
|
-
return next([...value].length);
|
|
16
|
-
|
|
17
|
-
case 'object':
|
|
18
|
-
return next(Object.keys(value).length);
|
|
19
|
-
|
|
20
|
-
default:
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
throw new JPLTypeError('%s (%*<100v) has no length', t, value);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default builtin;
|
package/src/builtins/funcNow.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
function builtin(runtime, signal, next, input, arg0) {
|
|
4
|
-
const value = runtime.unwrapValue(input);
|
|
5
|
-
const t = runtime.type(value);
|
|
6
|
-
|
|
7
|
-
const token = runtime.unwrapValue(arg0 ?? null);
|
|
8
|
-
const tt = runtime.type(token);
|
|
9
|
-
|
|
10
|
-
switch (t) {
|
|
11
|
-
case 'string':
|
|
12
|
-
if (tt === 'string') return next(value.startsWith(token));
|
|
13
|
-
break;
|
|
14
|
-
|
|
15
|
-
default:
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
throw new JPLTypeError('%s (%*<100v) cannot start with %s (%*<100v)', t, value, tt, token);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default builtin;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
async function builtin(runtime, signal, next, input) {
|
|
4
|
-
const t = runtime.type(input);
|
|
5
|
-
|
|
6
|
-
switch (t) {
|
|
7
|
-
case 'string':
|
|
8
|
-
return next(await runtime.alterValue(input, (value) => value.toLowerCase()));
|
|
9
|
-
|
|
10
|
-
default:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
throw new JPLTypeError(
|
|
14
|
-
'%s (%*<100v) cannot be converted to lower case',
|
|
15
|
-
t,
|
|
16
|
-
runtime.unwrapValue(input),
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default builtin;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { JPLTypeConversionError, JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
function builtin(runtime, signal, next, input) {
|
|
4
|
-
const value = runtime.unwrapValue(input);
|
|
5
|
-
const t = runtime.type(value);
|
|
6
|
-
|
|
7
|
-
switch (t) {
|
|
8
|
-
case 'number':
|
|
9
|
-
return next(value);
|
|
10
|
-
|
|
11
|
-
case 'string': {
|
|
12
|
-
const result = runtime.normalizeValue(+value);
|
|
13
|
-
if (value === '' || runtime.type(result) !== 'number') {
|
|
14
|
-
throw new JPLTypeConversionError('%s (%*<100v) does not contain a valid number', t, value);
|
|
15
|
-
}
|
|
16
|
-
return next(result);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
default:
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
throw new JPLTypeError('%s (%*<100v) cannot be parsed as a number', t, value);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default builtin;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
async function builtin(runtime, signal, next, input) {
|
|
4
|
-
const t = runtime.type(input);
|
|
5
|
-
|
|
6
|
-
switch (t) {
|
|
7
|
-
case 'string':
|
|
8
|
-
return next(await runtime.alterValue(input, (value) => value.toUpperCase()));
|
|
9
|
-
|
|
10
|
-
default:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
throw new JPLTypeError(
|
|
14
|
-
'%s (%*<100v) cannot be converted to upper case',
|
|
15
|
-
t,
|
|
16
|
-
runtime.unwrapValue(input),
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default builtin;
|
package/src/builtins/funcTrim.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
async function builtin(runtime, signal, next, input) {
|
|
4
|
-
const t = runtime.type(input);
|
|
5
|
-
|
|
6
|
-
switch (t) {
|
|
7
|
-
case 'string':
|
|
8
|
-
return next(await runtime.alterValue(input, (value) => value.trim()));
|
|
9
|
-
|
|
10
|
-
default:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
throw new JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default builtin;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
async function builtin(runtime, signal, next, input) {
|
|
4
|
-
const t = runtime.type(input);
|
|
5
|
-
|
|
6
|
-
switch (t) {
|
|
7
|
-
case 'string':
|
|
8
|
-
return next(await runtime.alterValue(input, (value) => value.trimEnd()));
|
|
9
|
-
|
|
10
|
-
default:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
throw new JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default builtin;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
async function builtin(runtime, signal, next, input) {
|
|
4
|
-
const t = runtime.type(input);
|
|
5
|
-
|
|
6
|
-
switch (t) {
|
|
7
|
-
case 'string':
|
|
8
|
-
return next(await runtime.alterValue(input, (value) => value.trimStart()));
|
|
9
|
-
|
|
10
|
-
default:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
throw new JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default builtin;
|
package/src/builtins/funcType.js
DELETED
package/src/builtins/funcVoid.js
DELETED
package/src/builtins/index.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import createSingleton from '../createSingleton';
|
|
2
|
-
import systemInterpreter from '../interpreter/system';
|
|
3
|
-
import { applyObject } from '../library';
|
|
4
|
-
import * as internals from './internals';
|
|
5
|
-
import * as native from './native';
|
|
6
|
-
|
|
7
|
-
const builtins = `
|
|
8
|
-
# There are additional builtins that are implemented directly in the corresponding languages.
|
|
9
|
-
# Also the functions in the "internals" namespace are not exposed to the public and are only to be used by the builtins below.
|
|
10
|
-
|
|
11
|
-
func map(f): ([.[] | f()])
|
|
12
|
-
| func mapValues(f): (.[] |= f())
|
|
13
|
-
| func select(f): (if f() then . else void() end)
|
|
14
|
-
| func reduce(f, s): (
|
|
15
|
-
l = length()
|
|
16
|
-
| func i(i, n, c): (if n < l then i(i, n + 1, f->(.[n], c, n)) else c end)
|
|
17
|
-
| i(i, 0, s)
|
|
18
|
-
)
|
|
19
|
-
| func while(cond, f): (
|
|
20
|
-
func i(i): (if cond() then ., i->(f(), i) else void() end)
|
|
21
|
-
| i(i)
|
|
22
|
-
)
|
|
23
|
-
| func until(cond, f): (
|
|
24
|
-
func i(i): (if cond() then . else i->(f(), i) end)
|
|
25
|
-
| i(i)
|
|
26
|
-
)
|
|
27
|
-
| func range(from, to, step): (
|
|
28
|
-
t = type->(from) | if t != "number" then error->("cannot use \\(t) as a number") end
|
|
29
|
-
| t = type->(to) | if t != "number" then error->("cannot use \\(t) as a number") end
|
|
30
|
-
| s = (step | if . != 0 and . != null then abs() else 1 end)
|
|
31
|
-
| while->(
|
|
32
|
-
from,
|
|
33
|
-
if from <= to then func (): (. < to) else func (): (. > to) end,
|
|
34
|
-
if from <= to then func (): (. + s) else func (): (. - s) end
|
|
35
|
-
)
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
# type selectors:
|
|
40
|
-
| func isArray(): (type() == "array")
|
|
41
|
-
| func arrays(): (select(isArray))
|
|
42
|
-
| func isObject(): (type() == "object")
|
|
43
|
-
| func objects(): (select(isObject))
|
|
44
|
-
| func isIterable(): (contains->(["array", "object"], type()))
|
|
45
|
-
| func iterables(): (select(isIterable))
|
|
46
|
-
| func isScalar(): (not contains->(["array", "object"], type()))
|
|
47
|
-
| func scalars(): (select(isScalar))
|
|
48
|
-
| func isBoolean(): (type() == "boolean")
|
|
49
|
-
| func booleans(): (select(isBoolean))
|
|
50
|
-
| func isNumber(): (type() == "number")
|
|
51
|
-
| func numbers(): (select(isNumber))
|
|
52
|
-
| func isString(): (type() == "string")
|
|
53
|
-
| func strings(): (select(isString))
|
|
54
|
-
| func isNull(): (type() == "null")
|
|
55
|
-
| func nulls(): (select(isNull))
|
|
56
|
-
| func isFunction(): (type() == "function")
|
|
57
|
-
| func functions(): (select(isFunction))
|
|
58
|
-
| func isNullLike(): (contains->(["null", "function"], type()))
|
|
59
|
-
| func nullLikes(): (select(isNullLike))
|
|
60
|
-
| func isValue(): (not contains->(["null", "function"], type()))
|
|
61
|
-
| func values(): (select(isValue))
|
|
62
|
-
| func isContent(): (isValue() and not contains->([[], {}, ""], .))
|
|
63
|
-
| func contents(): (select(isContent))
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
| func toEntries(): (o = . | keys() | map(func (): ({ key: ., value: o[.] })))
|
|
67
|
-
| func fromEntries(): (
|
|
68
|
-
reduce(
|
|
69
|
-
func (s): (s + { (.key ?? .Key ?? .name ?? .Name): if has("value") then .value else .Value end }),
|
|
70
|
-
{}
|
|
71
|
-
)
|
|
72
|
-
)
|
|
73
|
-
| func withEntries(f): (toEntries() | map(f) | fromEntries())
|
|
74
|
-
|
|
75
|
-
| func add(): (reduce(func (sum): (sum + .)))
|
|
76
|
-
| func join(sep): (
|
|
77
|
-
reduce(
|
|
78
|
-
func (sum): (
|
|
79
|
-
if sum == null then "" else sum + sep end
|
|
80
|
-
+ (. | toString())
|
|
81
|
-
)
|
|
82
|
-
) ?? ""
|
|
83
|
-
)
|
|
84
|
-
| func sortBy(f): ([.[] | [[f()], .]] | internals.sortEntries() | [.[][1]])
|
|
85
|
-
| func sort(): (sortBy(func (): (.)))
|
|
86
|
-
| func groupBy(f): (
|
|
87
|
-
key = 0 | value = 1
|
|
88
|
-
| [.[] | [[f()], [.]]] | internals.sortEntries()
|
|
89
|
-
| if . == []
|
|
90
|
-
then .
|
|
91
|
-
else
|
|
92
|
-
reduce->(
|
|
93
|
-
.[1:],
|
|
94
|
-
func (sum): (if sum[-1][key] == .[key] then (sum)[-1][value] += .[value] else sum + [.] end),
|
|
95
|
-
.[:1]
|
|
96
|
-
)
|
|
97
|
-
| [.[][value]]
|
|
98
|
-
end
|
|
99
|
-
)
|
|
100
|
-
| func group(): (groupBy(func (): (.)))
|
|
101
|
-
| func uniqueBy(f): (groupBy(f) | map(func (): (.[0])))
|
|
102
|
-
| func unique(): (group() | map(func (): (.[0])))
|
|
103
|
-
| func recurseBy(f, cond): (
|
|
104
|
-
c = cond ?? func (): (. != null)
|
|
105
|
-
| func r(r): (., (f() | select(c) | r(r)))
|
|
106
|
-
| r(r)
|
|
107
|
-
)
|
|
108
|
-
| func recurse(cond): (recurseBy(func (): ((arrays(), objects()) | .[]), cond))
|
|
109
|
-
| func reverse(): ([.[length() - 1 - range(0, length())]])
|
|
110
|
-
| func minBy(f): (
|
|
111
|
-
key = 0 | value = 1
|
|
112
|
-
| [.[] | [[f()], .]]
|
|
113
|
-
| reduce->(.[1:], func (sum): (if .[key] < sum[key] then . else sum end), .[0])
|
|
114
|
-
| .[value]
|
|
115
|
-
)
|
|
116
|
-
| func min(): (reduce->(.[1:], func (sum): (if . < sum then . else sum end), .[0]))
|
|
117
|
-
| func maxBy(f): (
|
|
118
|
-
key = 0 | value = 1
|
|
119
|
-
| [.[] | [[f()], .]]
|
|
120
|
-
| reduce->(.[1:], func (sum): (if .[key] > sum[key] then . else sum end), .[0])
|
|
121
|
-
| .[value]
|
|
122
|
-
)
|
|
123
|
-
| func max(): (reduce->(.[1:], func (sum): (if . > sum then . else sum end), .[0]))
|
|
124
|
-
| func first(f): ([f()][0])
|
|
125
|
-
| func nth(which, f): (
|
|
126
|
-
[f()]
|
|
127
|
-
| .[if which | type() == "number" then which else length() | which() end]
|
|
128
|
-
)
|
|
129
|
-
| func last(f): ([f()][-1])
|
|
130
|
-
| func isEmpty(f): (first(func (): ((f() | false), true)))
|
|
131
|
-
| func allBy(f, cond): (isEmpty(func (): (f() | cond() and void())))
|
|
132
|
-
| func all(cond): (allBy(func (): (.[]), cond))
|
|
133
|
-
| func anyBy(f, cond): (not isEmpty(func (): (f() | cond() or void())))
|
|
134
|
-
| func any(cond): (anyBy(func (): (.[]), cond))
|
|
135
|
-
|
|
136
|
-
| func getPath(path): (
|
|
137
|
-
fields = (path | if type() == 'string' then . / '.' end)
|
|
138
|
-
| reduce->(fields, func (sum): sum[if type->(sum) == 'array' then toNumber() else toString() end], .)
|
|
139
|
-
)
|
|
140
|
-
| func updatePath(path, update): (
|
|
141
|
-
fields = (path | if type() == 'string' then (. / '.')[] |= (v = . | try toNumber() catch v) end)
|
|
142
|
-
| reduce->(
|
|
143
|
-
reverse->(fields),
|
|
144
|
-
func (sum): (
|
|
145
|
-
field = .
|
|
146
|
-
| func (): (
|
|
147
|
-
if type() == 'array'
|
|
148
|
-
then (
|
|
149
|
-
input = .
|
|
150
|
-
| try toNumber->(field) catch toString->(field)
|
|
151
|
-
| if type() == 'number'
|
|
152
|
-
then input[.] |= sum()
|
|
153
|
-
else {}[.] |= sum()
|
|
154
|
-
end
|
|
155
|
-
) elif type() == 'object'
|
|
156
|
-
then (
|
|
157
|
-
.[toString->(field)] |= sum()
|
|
158
|
-
) elif type->(field) == 'number'
|
|
159
|
-
then (
|
|
160
|
-
[][field] |= sum()
|
|
161
|
-
) else (
|
|
162
|
-
{}[toString->(field)] |= sum()
|
|
163
|
-
)
|
|
164
|
-
end
|
|
165
|
-
)
|
|
166
|
-
),
|
|
167
|
-
update
|
|
168
|
-
)->(.)
|
|
169
|
-
)
|
|
170
|
-
| func setPath(path, value): (
|
|
171
|
-
updatePath(path, func (): value)
|
|
172
|
-
)
|
|
173
|
-
`;
|
|
174
|
-
|
|
175
|
-
const getBuiltins = createSingleton(async () => {
|
|
176
|
-
await undefined;
|
|
177
|
-
|
|
178
|
-
let result = { ...native };
|
|
179
|
-
const program = await systemInterpreter.parse(builtins, {
|
|
180
|
-
runtime: {
|
|
181
|
-
vars: { internals, ...native },
|
|
182
|
-
adjustResult: (value, scope) => {
|
|
183
|
-
const { internals: _, ...vars } = scope.vars;
|
|
184
|
-
result = applyObject(result, Object.entries(vars));
|
|
185
|
-
return [];
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
await program.run([null]);
|
|
190
|
-
return result;
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
export default getBuiltins;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { nativeFunction } from '../library';
|
|
2
|
-
|
|
3
|
-
export const sortEntries = nativeFunction(async (runtime, input) => [
|
|
4
|
-
await runtime.alterValue(input, (value) =>
|
|
5
|
-
[...value].sort((a, b) =>
|
|
6
|
-
runtime.compareArrays(runtime.unwrapValue(a)[0], runtime.unwrapValue(b)[0]),
|
|
7
|
-
),
|
|
8
|
-
),
|
|
9
|
-
]);
|
package/src/builtins/math.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { JPLTypeError } from '../library';
|
|
2
|
-
|
|
3
|
-
function unwrapNumber(runtime, v) {
|
|
4
|
-
const t = runtime.type(v);
|
|
5
|
-
const u = runtime.unwrapValue(v);
|
|
6
|
-
if (t !== 'number') {
|
|
7
|
-
throw new JPLTypeError('%s (%*<100v) cannot be used for mathematical operations', t, u);
|
|
8
|
-
}
|
|
9
|
-
return u;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function funcMath(alter) {
|
|
13
|
-
return async function builtin(runtime, signal, next, input, ...args) {
|
|
14
|
-
const t = runtime.type(input);
|
|
15
|
-
if (t !== 'number') {
|
|
16
|
-
throw new JPLTypeError(
|
|
17
|
-
'%s (%*<100v) cannot be used for mathematical operations',
|
|
18
|
-
t,
|
|
19
|
-
runtime.unwrapValue(input),
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return next(await runtime.alterValue(input, (value) => alter(runtime, value, ...args)));
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const pow = funcMath((runtime, value, arg0) => value ** unwrapNumber(runtime, arg0 ?? null));
|
|
27
|
-
export const sqrt = funcMath((runtime, value) => Math.sqrt(value));
|
|
28
|
-
export const exp = funcMath((runtime, value) => Math.exp(value));
|
|
29
|
-
export const log = funcMath((runtime, value) => Math.log(value));
|
|
30
|
-
export const log10 = funcMath((runtime, value) => Math.log10(value));
|
|
31
|
-
|
|
32
|
-
export const sin = funcMath((runtime, value) => Math.sin(value));
|
|
33
|
-
export const cos = funcMath((runtime, value) => Math.cos(value));
|
|
34
|
-
export const tan = funcMath((runtime, value) => Math.tan(value));
|
|
35
|
-
export const asin = funcMath((runtime, value) => Math.asin(value));
|
|
36
|
-
export const acos = funcMath((runtime, value) => Math.acos(value));
|
|
37
|
-
export const atan = funcMath((runtime, value) => Math.atan(value));
|
|
38
|
-
|
|
39
|
-
export const ceil = funcMath((runtime, value) => Math.ceil(value));
|
|
40
|
-
export const floor = funcMath((runtime, value) => Math.floor(value));
|
|
41
|
-
export const round = funcMath((runtime, value) => Math.round(value));
|
|
42
|
-
export const trunc = funcMath((runtime, value) => Math.trunc(value));
|
|
43
|
-
|
|
44
|
-
export const abs = funcMath((runtime, value) => Math.abs(value));
|
package/src/createSingleton.js
DELETED
package/src/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import getBuiltins from './builtins';
|
|
2
|
-
import createSingleton from './createSingleton';
|
|
3
|
-
import JPLInterpreter, { applyInterpreterDefaults } from './interpreter';
|
|
4
|
-
import parseFunction from './interpreter/parseFunction';
|
|
5
|
-
import * as library from './library';
|
|
6
|
-
import { applyProgramDefaults } from './program';
|
|
7
|
-
import { applyRuntimeDefaults } from './runtime';
|
|
8
|
-
|
|
9
|
-
const getGlobalOptions = createSingleton(async () => ({
|
|
10
|
-
interpreter: {},
|
|
11
|
-
|
|
12
|
-
program: {},
|
|
13
|
-
|
|
14
|
-
runtime: {
|
|
15
|
-
vars: { ...(await getBuiltins()) },
|
|
16
|
-
},
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
const parse = async (source, options) => {
|
|
20
|
-
const globalOptions = await getGlobalOptions();
|
|
21
|
-
const interpreter = new JPLInterpreter({
|
|
22
|
-
interpreter: applyInterpreterDefaults(options?.interpreter, globalOptions.interpreter),
|
|
23
|
-
program: applyProgramDefaults(options?.program, globalOptions.program),
|
|
24
|
-
runtime: applyRuntimeDefaults(options?.runtime, globalOptions.runtime),
|
|
25
|
-
});
|
|
26
|
-
return interpreter.parse(source);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const run = async (source, inputs, options) => {
|
|
30
|
-
const program = await parse(source, options);
|
|
31
|
-
return program.run(inputs);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default {
|
|
35
|
-
...library,
|
|
36
|
-
run,
|
|
37
|
-
parse,
|
|
38
|
-
parseFunction,
|
|
39
|
-
getBuiltins,
|
|
40
|
-
getOptions: getGlobalOptions,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export * from './library';
|
|
44
|
-
export { getBuiltins, getGlobalOptions as getOptions, parse, parseFunction, run };
|
package/src/interpreter/index.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import applyDefaults from '../applyDefaults';
|
|
2
|
-
import { DEFINITION_VERSION } from '../library';
|
|
3
|
-
import JPLProgram, { applyProgramDefaults } from '../program';
|
|
4
|
-
import { applyRuntimeDefaults } from '../runtime';
|
|
5
|
-
import { parseEntrypoint } from './parse';
|
|
6
|
-
|
|
7
|
-
const defaultOptions = {};
|
|
8
|
-
|
|
9
|
-
export function applyInterpreterDefaults(options = {}, defaults = {}) {
|
|
10
|
-
return applyDefaults(options, defaults);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** JPL interpreter */
|
|
14
|
-
class JPLInterpreter {
|
|
15
|
-
constructor(options) {
|
|
16
|
-
this._options = applyInterpreterDefaults(options?.interpreter, defaultOptions);
|
|
17
|
-
this._programOptions = options?.program;
|
|
18
|
-
this._runtimeOptions = options?.runtime;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Return the interpreter's options */
|
|
22
|
-
get options() {
|
|
23
|
-
return this._options;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Parse the specified source program string into a reusable JPLProgram instance */
|
|
27
|
-
parse = async (source, options) => {
|
|
28
|
-
const instructions = await this.parseInstructions(source);
|
|
29
|
-
|
|
30
|
-
const programDefinition = {
|
|
31
|
-
version: DEFINITION_VERSION,
|
|
32
|
-
instructions,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return new JPLProgram(programDefinition, {
|
|
36
|
-
program: applyProgramDefaults(options?.program, this._programOptions),
|
|
37
|
-
runtime: applyRuntimeDefaults(options?.runtime, this._runtimeOptions),
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/** Parse the specified source program string */
|
|
42
|
-
parseInstructions = async (source) => {
|
|
43
|
-
const { ops: instructions } = await parseEntrypoint(source, 0, { interpreter: this });
|
|
44
|
-
return instructions;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default JPLInterpreter;
|