@jplorg/jpl 2.0.0 → 2.1.1
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 +19 -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 +11 -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 +10 -0
- package/dist/types/program/ops/opAccess/opaField.d.ts +10 -0
- package/dist/types/program/ops/opAccess/opaFunction.d.ts +10 -0
- package/dist/types/program/ops/opAccess/opaIter.d.ts +10 -0
- package/dist/types/program/ops/opAccess/opaSlice.d.ts +10 -0
- package/dist/types/program/ops/opAnd.d.ts +10 -0
- package/dist/types/program/ops/opArrayConstructor.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/index.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opuAddition.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opuDivision.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opuSet.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +10 -0
- package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +10 -0
- package/dist/types/program/ops/opCalculation/index.d.ts +10 -0
- package/dist/types/program/ops/opCalculation/opmAddition.d.ts +10 -0
- package/dist/types/program/ops/opCalculation/opmDivision.d.ts +10 -0
- package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +10 -0
- package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +10 -0
- package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +10 -0
- package/dist/types/program/ops/opComparison/index.d.ts +10 -0
- package/dist/types/program/ops/opComparison/opcEqual.d.ts +10 -0
- package/dist/types/program/ops/opComparison/opcGreater.d.ts +10 -0
- package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +10 -0
- package/dist/types/program/ops/opComparison/opcLess.d.ts +10 -0
- package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +10 -0
- package/dist/types/program/ops/opComparison/opcUnequal.d.ts +10 -0
- package/dist/types/program/ops/opConstant.d.ts +10 -0
- package/dist/types/program/ops/opConstantFalse.d.ts +10 -0
- package/dist/types/program/ops/opConstantNull.d.ts +10 -0
- package/dist/types/program/ops/opConstantTrue.d.ts +10 -0
- package/dist/types/program/ops/opFunctionDefinition.d.ts +10 -0
- package/dist/types/program/ops/opIf.d.ts +10 -0
- package/dist/types/program/ops/opInterpolatedString.d.ts +10 -0
- package/dist/types/program/ops/opNegation.d.ts +10 -0
- package/dist/types/program/ops/opNot.d.ts +10 -0
- package/dist/types/program/ops/opNullCoalescence.d.ts +10 -0
- package/dist/types/program/ops/opNumber.d.ts +10 -0
- package/dist/types/program/ops/opObjectConstructor.d.ts +10 -0
- package/dist/types/program/ops/opOr.d.ts +10 -0
- package/dist/types/program/ops/opOutputConcat.d.ts +10 -0
- package/dist/types/program/ops/opString.d.ts +10 -0
- package/dist/types/program/ops/opTry.d.ts +10 -0
- package/dist/types/program/ops/opVariable.d.ts +10 -0
- package/dist/types/program/ops/opVariableDefinition.d.ts +10 -0
- package/dist/types/program/ops/opVoid.d.ts +10 -0
- package/dist/types/program/ops/utils.d.ts +5 -0
- package/dist/types/program/params.d.ts +67 -0
- package/dist/types/runtime/index.d.ts +82 -0
- package/package.json +59 -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
package/src/program/ops/utils.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { OPA_FUNCTION, OP_ACCESS, OP_CONSTANT, assertType } from '../../library';
|
|
2
|
-
|
|
3
|
-
/** Create OP_CONSTANT operation for the specified normalized value */
|
|
4
|
-
export function constant(value) {
|
|
5
|
-
return [{ op: OP_CONSTANT, params: { value: value ?? null } }];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/** Create OPA_FUNCTION operation for the specified function */
|
|
9
|
-
export function call(value) {
|
|
10
|
-
return [
|
|
11
|
-
{
|
|
12
|
-
op: OP_ACCESS,
|
|
13
|
-
params: {
|
|
14
|
-
pipe: constant(assertType(value, 'function')),
|
|
15
|
-
selectors: [{ op: OPA_FUNCTION, params: { args: [], bound: false, optional: false } }],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
];
|
|
19
|
-
}
|
package/src/runtime/index.js
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import applyDefaults from '../applyDefaults';
|
|
2
|
-
import {
|
|
3
|
-
JPLFatalError,
|
|
4
|
-
JPLType,
|
|
5
|
-
JPLRuntimeScope,
|
|
6
|
-
adaptErrorsAsync,
|
|
7
|
-
applyObject,
|
|
8
|
-
assertType,
|
|
9
|
-
mux,
|
|
10
|
-
muxAll,
|
|
11
|
-
muxAsync,
|
|
12
|
-
muxOne,
|
|
13
|
-
normalize,
|
|
14
|
-
stringify,
|
|
15
|
-
strip,
|
|
16
|
-
typeOf,
|
|
17
|
-
typeOrder,
|
|
18
|
-
unwrap,
|
|
19
|
-
} from '../library';
|
|
20
|
-
|
|
21
|
-
const defaultOptions = {
|
|
22
|
-
vars: {},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export function applyRuntimeDefaults(options = {}, defaults = {}) {
|
|
26
|
-
return applyDefaults(options, defaults, 'vars');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** JPL runtime */
|
|
30
|
-
class JPLRuntime {
|
|
31
|
-
constructor(program, options) {
|
|
32
|
-
this._options = applyRuntimeDefaults(options?.runtime, defaultOptions);
|
|
33
|
-
|
|
34
|
-
this._program = program;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Return the runtime's options */
|
|
38
|
-
get options() {
|
|
39
|
-
return this._options;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Return the runtime's program */
|
|
43
|
-
get program() {
|
|
44
|
-
return this._program;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Create a new orphan scope */
|
|
48
|
-
createScope = (presets) => new JPLRuntimeScope(presets);
|
|
49
|
-
|
|
50
|
-
/** Execute a new dedicated program */
|
|
51
|
-
execute = async (inputs) => {
|
|
52
|
-
const scope = this.createScope({
|
|
53
|
-
vars: Object.fromEntries(
|
|
54
|
-
this.muxOne([Object.entries(this.options.vars)], ([name, value]) => [
|
|
55
|
-
name,
|
|
56
|
-
this.normalizeValue(value),
|
|
57
|
-
]),
|
|
58
|
-
),
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
return await this.executeInstructions(
|
|
63
|
-
this.program.definition.instructions ?? [],
|
|
64
|
-
inputs,
|
|
65
|
-
scope,
|
|
66
|
-
this.options.adjustResult,
|
|
67
|
-
);
|
|
68
|
-
} finally {
|
|
69
|
-
scope.signal.exit();
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/** Execute the specified instructions */
|
|
74
|
-
executeInstructions = (instructions, inputs, scope, next = (output) => [output]) => {
|
|
75
|
-
const iter = async (from, input, currentScope) => {
|
|
76
|
-
// Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
|
|
77
|
-
await undefined;
|
|
78
|
-
|
|
79
|
-
currentScope.signal.checkHealth();
|
|
80
|
-
|
|
81
|
-
if (from >= instructions.length) return next(input, currentScope);
|
|
82
|
-
|
|
83
|
-
const { op, params } = instructions[from];
|
|
84
|
-
const operator = this.program.ops[op];
|
|
85
|
-
if (!operator) throw new JPLFatalError(`invalid OP '${op}'`);
|
|
86
|
-
|
|
87
|
-
return operator.op(this, input, params ?? {}, currentScope, (output, nextScope) =>
|
|
88
|
-
iter(from + 1, output, nextScope),
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return this.muxAll([inputs], (input) => iter(0, input, scope));
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/** Execute the specified OP */
|
|
96
|
-
op(op, params, inputs, scope, next = (output) => [output]) {
|
|
97
|
-
const operator = this.program.ops[op];
|
|
98
|
-
if (!operator) throw new JPLFatalError(`invalid OP '${op}'`);
|
|
99
|
-
|
|
100
|
-
const opParams = operator.map(this, params);
|
|
101
|
-
return this.muxAll([inputs], (input) => operator.op(this, input, opParams ?? {}, scope, next));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Normalize the specified external value */
|
|
105
|
-
normalizeValue = normalize;
|
|
106
|
-
|
|
107
|
-
/** Normalize the specified array of external values */
|
|
108
|
-
normalizeValues = (values = [], name = 'values') => {
|
|
109
|
-
if (!Array.isArray(values)) throw new JPLFatalError(`expected ${name} to be an array`);
|
|
110
|
-
return this.normalizeValue(values);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/** Unwrap the specified normalized value for usage in JPL operations */
|
|
114
|
-
unwrapValue = unwrap;
|
|
115
|
-
|
|
116
|
-
/** Unwrap the specified array of normalized values for usage in JPL operations */
|
|
117
|
-
unwrapValues = (values = [], name = 'values') => {
|
|
118
|
-
if (!Array.isArray(values)) throw new JPLFatalError(`expected ${name} to be an array`);
|
|
119
|
-
return this.muxOne([values], (value) => this.unwrapValue(value));
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
/** Strip the specified normalized value for usage in JPL operations */
|
|
123
|
-
stripValue = (value) => strip(value, (k, v) => this.unwrapValue(v));
|
|
124
|
-
|
|
125
|
-
/** Strip the specified array of normalized values for usage in JPL operations */
|
|
126
|
-
stripValues = (values = [], name = 'values') => {
|
|
127
|
-
if (!Array.isArray(values)) throw new JPLFatalError(`expected ${name} to be an array`);
|
|
128
|
-
return this.muxOne([values], (value) => this.stripValue(value));
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/** Alter the specified normalized value using the specified updater */
|
|
132
|
-
alterValue = async (value, updater) =>
|
|
133
|
-
JPLType.is(value)
|
|
134
|
-
? adaptErrorsAsync(() => value.alter(updater))
|
|
135
|
-
: this.normalizeValue(await updater(value));
|
|
136
|
-
|
|
137
|
-
/** Resolve the type of the specified normalized value for JPL operations */
|
|
138
|
-
type = typeOf;
|
|
139
|
-
|
|
140
|
-
/** Assert the type for the specified unwrapped value for JPL operations */
|
|
141
|
-
assertType = assertType;
|
|
142
|
-
|
|
143
|
-
/** Determine whether the specified normalized value should be considered as truthy in JPL operations */
|
|
144
|
-
truthy = (value) => {
|
|
145
|
-
const raw = this.unwrapValue(value);
|
|
146
|
-
return raw !== null && raw !== false;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/** Compare the specified normalized values */
|
|
150
|
-
compare = compare.bind(this);
|
|
151
|
-
|
|
152
|
-
/** Compare the specified normalized strings based on their unicode code points */
|
|
153
|
-
compareStrings = (a, b) => {
|
|
154
|
-
const ta = this.type(a);
|
|
155
|
-
if (ta !== 'string') throw new JPLFatalError(`unexpected type ${ta}`);
|
|
156
|
-
const tb = this.type(b);
|
|
157
|
-
if (tb !== 'string') throw new JPLFatalError(`unexpected type ${tb}`);
|
|
158
|
-
return compareStrings(this.unwrapValue(a), this.unwrapValue(b));
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/** Compare the specified normalized arrays based on their lexical order */
|
|
162
|
-
compareArrays = (a, b) => {
|
|
163
|
-
const ta = this.type(a);
|
|
164
|
-
if (ta !== 'array') throw new JPLFatalError(`unexpected type ${ta}`);
|
|
165
|
-
const tb = this.type(b);
|
|
166
|
-
if (tb !== 'array') throw new JPLFatalError(`unexpected type ${tb}`);
|
|
167
|
-
|
|
168
|
-
return compareArrays.call(this, this.unwrapValue(a), this.unwrapValue(b));
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/** Compare the specified normalized objects */
|
|
172
|
-
compareObjects = (a, b) => {
|
|
173
|
-
const ta = this.type(a);
|
|
174
|
-
if (ta !== 'object') throw new JPLFatalError(`unexpected type ${ta}`);
|
|
175
|
-
const tb = this.type(b);
|
|
176
|
-
if (tb !== 'object') throw new JPLFatalError(`unexpected type ${tb}`);
|
|
177
|
-
|
|
178
|
-
return compareObjects.call(this, this.unwrapValue(a), this.unwrapValue(b));
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
/** Determine if the specified normalized values can be considered to be equal */
|
|
182
|
-
equals = (a, b) => this.compare(a, b) === 0;
|
|
183
|
-
|
|
184
|
-
/** Deep merge the specified normalized values */
|
|
185
|
-
merge = async (a, b) => {
|
|
186
|
-
// Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
|
|
187
|
-
await undefined;
|
|
188
|
-
|
|
189
|
-
if (this.type(a) !== 'object' || this.type(b) !== 'object') return b;
|
|
190
|
-
|
|
191
|
-
return this.alterValue(a, async (value) => {
|
|
192
|
-
const changes = await Promise.all(
|
|
193
|
-
Object.entries(this.unwrapValue(b)).map(async ([k, v]) => [
|
|
194
|
-
k,
|
|
195
|
-
await this.merge(value[k] ?? null, v),
|
|
196
|
-
]),
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
return applyObject(value, changes);
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
/** Stringify the specified normalized value for usage in program outputs */
|
|
204
|
-
stringifyJSON = (value, unescapeString) => stringify(value, unescapeString);
|
|
205
|
-
|
|
206
|
-
/** Strip the specified normalized value for usage in program outputs */
|
|
207
|
-
stripJSON = (value) => strip(value);
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Multiplex the specified array of arguments by calling cb for all possible combinations of arguments.
|
|
211
|
-
*
|
|
212
|
-
* `mux([[1,2], [3,4]], cb)` for example yields:
|
|
213
|
-
* - `cb(1, 3)`
|
|
214
|
-
* - `cb(1, 4)`
|
|
215
|
-
* - `cb(2, 3)`
|
|
216
|
-
* - `cb(2, 4)`
|
|
217
|
-
*/
|
|
218
|
-
mux = mux;
|
|
219
|
-
|
|
220
|
-
/** Multiplex the specified array of arguments and return the results produced by the callbacks */
|
|
221
|
-
muxOne = muxOne;
|
|
222
|
-
|
|
223
|
-
/** Multiplex the specified array of arguments asynchronously and return the results produced by the callbacks */
|
|
224
|
-
muxAsync = muxAsync;
|
|
225
|
-
|
|
226
|
-
/** Multiplex the specified array of arguments asynchronously and return a single array of all merged result arrays produced by the callbacks */
|
|
227
|
-
muxAll = muxAll;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export default JPLRuntime;
|
|
231
|
-
|
|
232
|
-
/** Compare the specified normalized values */
|
|
233
|
-
function compare(a, b) {
|
|
234
|
-
const ta = this.type(a);
|
|
235
|
-
const tb = this.type(b);
|
|
236
|
-
|
|
237
|
-
if (ta !== tb) return typeOrder.indexOf(ta) - typeOrder.indexOf(tb);
|
|
238
|
-
|
|
239
|
-
const ua = this.unwrapValue(a);
|
|
240
|
-
const ub = this.unwrapValue(b);
|
|
241
|
-
|
|
242
|
-
switch (ta) {
|
|
243
|
-
case 'null':
|
|
244
|
-
case 'function':
|
|
245
|
-
return 0;
|
|
246
|
-
|
|
247
|
-
case 'boolean':
|
|
248
|
-
case 'number':
|
|
249
|
-
return +ua - +ub;
|
|
250
|
-
|
|
251
|
-
case 'string':
|
|
252
|
-
return compareStrings(ua, ub);
|
|
253
|
-
|
|
254
|
-
case 'array':
|
|
255
|
-
return compareArrays.call(this, ua, ub);
|
|
256
|
-
|
|
257
|
-
case 'object':
|
|
258
|
-
return compareObjects.call(this, ua, ub);
|
|
259
|
-
|
|
260
|
-
default:
|
|
261
|
-
throw new JPLFatalError(`unexpected type ${ta}`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/** Compare the specified normalized strings based on their unicode code points */
|
|
266
|
-
function compareStrings(a, b) {
|
|
267
|
-
const min = Math.min(a.length, b.length);
|
|
268
|
-
let i = 0;
|
|
269
|
-
// eslint-disable-next-line no-unused-vars
|
|
270
|
-
for (const _ of a) {
|
|
271
|
-
if (i >= min) {
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
const cp1 = a.codePointAt(i);
|
|
275
|
-
const cp2 = b.codePointAt(i);
|
|
276
|
-
const order = cp1 - cp2;
|
|
277
|
-
if (order !== 0) {
|
|
278
|
-
return order;
|
|
279
|
-
}
|
|
280
|
-
i += 1;
|
|
281
|
-
if (cp1 > 0xffff) {
|
|
282
|
-
i += 1;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return a.length - b.length;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/** Compare the specified normalized arrays based on their lexical order */
|
|
289
|
-
function compareArrays(a, b) {
|
|
290
|
-
const min = Math.min(a.length, b.length);
|
|
291
|
-
for (let i = 0; i < min; i += 1) {
|
|
292
|
-
const c = compare.call(this, a[i], b[i]);
|
|
293
|
-
if (c !== 0) return c;
|
|
294
|
-
}
|
|
295
|
-
return a.length - b.length;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/** Compare the specified normalized objects */
|
|
299
|
-
function compareObjects(a, b) {
|
|
300
|
-
const aKeys = Object.keys(a).sort(compareStrings);
|
|
301
|
-
const bKeys = Object.keys(b).sort(compareStrings);
|
|
302
|
-
let order = compareArrays.call(this, aKeys, bKeys);
|
|
303
|
-
if (order !== 0) return order;
|
|
304
|
-
for (const key of aKeys) {
|
|
305
|
-
order = compare.call(this, a[key], b[key]);
|
|
306
|
-
if (order !== 0) return order;
|
|
307
|
-
}
|
|
308
|
-
return 0;
|
|
309
|
-
}
|
|
File without changes
|
|
File without changes
|