@jplorg/jpl 1.0.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/README.md +34 -0
- package/lib/applyDefaults.js +34 -0
- package/lib/builtins/funcContains.js +25 -0
- package/lib/builtins/funcEndsWith.js +21 -0
- package/lib/builtins/funcError.js +11 -0
- package/lib/builtins/funcFromJSON.js +26 -0
- package/lib/builtins/funcHas.js +24 -0
- package/lib/builtins/funcIn.js +24 -0
- package/lib/builtins/funcKeys.js +20 -0
- package/lib/builtins/funcLength.js +24 -0
- package/lib/builtins/funcNow.js +10 -0
- package/lib/builtins/funcStartsWith.js +21 -0
- package/lib/builtins/funcToJSON.js +10 -0
- package/lib/builtins/funcToNumber.js +26 -0
- package/lib/builtins/funcToString.js +10 -0
- package/lib/builtins/funcTrim.js +17 -0
- package/lib/builtins/funcTrimEnd.js +17 -0
- package/lib/builtins/funcTrimStart.js +17 -0
- package/lib/builtins/funcType.js +10 -0
- package/lib/builtins/funcVoid.js +10 -0
- package/lib/builtins/index.js +158 -0
- package/lib/builtins/internals.js +8 -0
- package/lib/builtins/math.js +40 -0
- package/lib/builtins/native.js +164 -0
- package/lib/createSingleton.js +14 -0
- package/lib/index.js +80 -0
- package/lib/interpreter/index.js +57 -0
- package/lib/interpreter/parse.js +2377 -0
- package/lib/interpreter/parseFunction.js +24 -0
- package/lib/interpreter/system.js +10 -0
- package/lib/interpreter/util.js +349 -0
- package/lib/library/apply.js +142 -0
- package/lib/library/definition.js +9 -0
- package/lib/library/errors/adaptErrors.js +34 -0
- package/lib/library/errors/enclosure.js +16 -0
- package/lib/library/errors/error.js +18 -0
- package/lib/library/errors/execution.js +20 -0
- package/lib/library/errors/fatal.js +15 -0
- package/lib/library/errors/runtime.js +78 -0
- package/lib/library/errors/syntax.js +15 -0
- package/lib/library/functions.js +82 -0
- package/lib/library/index.js +336 -0
- package/lib/library/mux.js +106 -0
- package/lib/library/ops/index.js +60 -0
- package/lib/library/ops/op.js +180 -0
- package/lib/library/ops/opa.js +41 -0
- package/lib/library/ops/opc.js +59 -0
- package/lib/library/ops/opm.js +50 -0
- package/lib/library/ops/opu.js +77 -0
- package/lib/library/runtimeScope.js +38 -0
- package/lib/library/runtimeSignal.js +72 -0
- package/lib/library/types.js +305 -0
- package/lib/program/index.js +72 -0
- package/lib/program/ops/index.js +61 -0
- package/lib/program/ops/opAccess/index.js +55 -0
- package/lib/program/ops/opAccess/opaField.js +50 -0
- package/lib/program/ops/opAccess/opaFunction.js +50 -0
- package/lib/program/ops/opAccess/opaIter.js +31 -0
- package/lib/program/ops/opAccess/opaSlice.js +44 -0
- package/lib/program/ops/opAnd.js +30 -0
- package/lib/program/ops/opArrayConstructor.js +20 -0
- package/lib/program/ops/opAssignment/index.js +90 -0
- package/lib/program/ops/opAssignment/opaAssignField.js +125 -0
- package/lib/program/ops/opAssignment/opaAssignIter.js +69 -0
- package/lib/program/ops/opAssignment/opaAssignSlice.js +99 -0
- package/lib/program/ops/opAssignment/opuAddition.js +31 -0
- package/lib/program/ops/opAssignment/opuDivision.js +31 -0
- package/lib/program/ops/opAssignment/opuMultiplication.js +31 -0
- package/lib/program/ops/opAssignment/opuNullCoalescence.js +25 -0
- package/lib/program/ops/opAssignment/opuRemainder.js +31 -0
- package/lib/program/ops/opAssignment/opuSet.js +19 -0
- package/lib/program/ops/opAssignment/opuSubtraction.js +31 -0
- package/lib/program/ops/opAssignment/opuUpdate.js +19 -0
- package/lib/program/ops/opCalculation/index.js +57 -0
- package/lib/program/ops/opCalculation/opmAddition.js +49 -0
- package/lib/program/ops/opCalculation/opmDivision.js +42 -0
- package/lib/program/ops/opCalculation/opmMultiplication.js +40 -0
- package/lib/program/ops/opCalculation/opmRemainder.js +34 -0
- package/lib/program/ops/opCalculation/opmSubtraction.js +53 -0
- package/lib/program/ops/opComparison/index.js +59 -0
- package/lib/program/ops/opComparison/opcEqual.js +19 -0
- package/lib/program/ops/opComparison/opcGreater.js +19 -0
- package/lib/program/ops/opComparison/opcGreaterEqual.js +19 -0
- package/lib/program/ops/opComparison/opcLess.js +19 -0
- package/lib/program/ops/opComparison/opcLessEqual.js +19 -0
- package/lib/program/ops/opComparison/opcUnequal.js +19 -0
- package/lib/program/ops/opConstant.js +18 -0
- package/lib/program/ops/opConstantFalse.js +16 -0
- package/lib/program/ops/opConstantNull.js +16 -0
- package/lib/program/ops/opConstantTrue.js +16 -0
- package/lib/program/ops/opFunctionDefinition.js +21 -0
- package/lib/program/ops/opIf.js +38 -0
- package/lib/program/ops/opInterpolatedString.js +24 -0
- package/lib/program/ops/opNegation.js +25 -0
- package/lib/program/ops/opNot.js +16 -0
- package/lib/program/ops/opNullCoalescence.js +34 -0
- package/lib/program/ops/opNumber.js +18 -0
- package/lib/program/ops/opObjectConstructor.js +37 -0
- package/lib/program/ops/opOr.js +30 -0
- package/lib/program/ops/opOutputConcat.js +19 -0
- package/lib/program/ops/opString.js +18 -0
- package/lib/program/ops/opTry.js +37 -0
- package/lib/program/ops/opVariable.js +20 -0
- package/lib/program/ops/opVariableDefinition.js +24 -0
- package/lib/program/ops/opVoid.js +16 -0
- package/lib/program/ops/utils.js +35 -0
- package/lib/runtime/index.js +258 -0
- package/package.json +67 -0
- package/repl.js +212 -0
- package/src/applyDefaults.js +35 -0
- package/src/builtins/funcContains.js +27 -0
- package/src/builtins/funcEndsWith.js +21 -0
- package/src/builtins/funcError.js +7 -0
- package/src/builtins/funcFromJSON.js +24 -0
- package/src/builtins/funcHas.js +25 -0
- package/src/builtins/funcIn.js +25 -0
- package/src/builtins/funcKeys.js +20 -0
- package/src/builtins/funcLength.js +26 -0
- package/src/builtins/funcNow.js +5 -0
- package/src/builtins/funcStartsWith.js +21 -0
- package/src/builtins/funcToJSON.js +5 -0
- package/src/builtins/funcToNumber.js +25 -0
- package/src/builtins/funcToString.js +5 -0
- package/src/builtins/funcTrim.js +16 -0
- package/src/builtins/funcTrimEnd.js +16 -0
- package/src/builtins/funcTrimStart.js +16 -0
- package/src/builtins/funcType.js +5 -0
- package/src/builtins/funcVoid.js +5 -0
- package/src/builtins/index.js +145 -0
- package/src/builtins/internals.js +9 -0
- package/src/builtins/math.js +44 -0
- package/src/builtins/native.js +19 -0
- package/src/createSingleton.js +9 -0
- package/src/index.js +44 -0
- package/src/interpreter/index.js +48 -0
- package/src/interpreter/parse.js +1473 -0
- package/src/interpreter/parseFunction.js +20 -0
- package/src/interpreter/system.js +5 -0
- package/src/interpreter/util.js +237 -0
- package/src/library/apply.js +135 -0
- package/src/library/definition.js +3 -0
- package/src/library/errors/adaptErrors.js +28 -0
- package/src/library/errors/enclosure.js +11 -0
- package/src/library/errors/error.js +14 -0
- package/src/library/errors/execution.js +15 -0
- package/src/library/errors/fatal.js +10 -0
- package/src/library/errors/runtime.js +71 -0
- package/src/library/errors/syntax.js +10 -0
- package/src/library/functions.js +73 -0
- package/src/library/index.js +41 -0
- package/src/library/mux.js +98 -0
- package/src/library/ops/index.js +5 -0
- package/src/library/ops/op.js +174 -0
- package/src/library/ops/opa.js +35 -0
- package/src/library/ops/opc.js +53 -0
- package/src/library/ops/opm.js +44 -0
- package/src/library/ops/opu.js +71 -0
- package/src/library/runtimeScope.js +35 -0
- package/src/library/runtimeSignal.js +67 -0
- package/src/library/types.js +299 -0
- package/src/program/index.js +80 -0
- package/src/program/ops/index.js +82 -0
- package/src/program/ops/opAccess/index.js +55 -0
- package/src/program/ops/opAccess/opaField.js +58 -0
- package/src/program/ops/opAccess/opaFunction.js +52 -0
- package/src/program/ops/opAccess/opaIter.js +31 -0
- package/src/program/ops/opAccess/opaSlice.js +58 -0
- package/src/program/ops/opAnd.js +32 -0
- package/src/program/ops/opArrayConstructor.js +16 -0
- package/src/program/ops/opAssignment/index.js +102 -0
- package/src/program/ops/opAssignment/opaAssignField.js +156 -0
- package/src/program/ops/opAssignment/opaAssignIter.js +74 -0
- package/src/program/ops/opAssignment/opaAssignSlice.js +157 -0
- package/src/program/ops/opAssignment/opuAddition.js +29 -0
- package/src/program/ops/opAssignment/opuDivision.js +29 -0
- package/src/program/ops/opAssignment/opuMultiplication.js +29 -0
- package/src/program/ops/opAssignment/opuNullCoalescence.js +26 -0
- package/src/program/ops/opAssignment/opuRemainder.js +29 -0
- package/src/program/ops/opAssignment/opuSet.js +15 -0
- package/src/program/ops/opAssignment/opuSubtraction.js +29 -0
- package/src/program/ops/opAssignment/opuUpdate.js +15 -0
- package/src/program/ops/opCalculation/index.js +64 -0
- package/src/program/ops/opCalculation/opmAddition.js +63 -0
- package/src/program/ops/opCalculation/opmDivision.js +47 -0
- package/src/program/ops/opCalculation/opmMultiplication.js +52 -0
- package/src/program/ops/opCalculation/opmRemainder.js +49 -0
- package/src/program/ops/opCalculation/opmSubtraction.js +72 -0
- package/src/program/ops/opComparison/index.js +67 -0
- package/src/program/ops/opComparison/opcEqual.js +17 -0
- package/src/program/ops/opComparison/opcGreater.js +17 -0
- package/src/program/ops/opComparison/opcGreaterEqual.js +17 -0
- package/src/program/ops/opComparison/opcLess.js +17 -0
- package/src/program/ops/opComparison/opcLessEqual.js +17 -0
- package/src/program/ops/opComparison/opcUnequal.js +17 -0
- package/src/program/ops/opConstant.js +13 -0
- package/src/program/ops/opConstantFalse.js +11 -0
- package/src/program/ops/opConstantNull.js +11 -0
- package/src/program/ops/opConstantTrue.js +11 -0
- package/src/program/ops/opFunctionDefinition.js +17 -0
- package/src/program/ops/opIf.js +44 -0
- package/src/program/ops/opInterpolatedString.js +27 -0
- package/src/program/ops/opNegation.js +26 -0
- package/src/program/ops/opNot.js +11 -0
- package/src/program/ops/opNullCoalescence.js +36 -0
- package/src/program/ops/opNumber.js +13 -0
- package/src/program/ops/opObjectConstructor.js +40 -0
- package/src/program/ops/opOr.js +32 -0
- package/src/program/ops/opOutputConcat.js +17 -0
- package/src/program/ops/opString.js +13 -0
- package/src/program/ops/opTry.js +38 -0
- package/src/program/ops/opVariable.js +17 -0
- package/src/program/ops/opVariableDefinition.js +18 -0
- package/src/program/ops/opVoid.js +11 -0
- package/src/program/ops/utils.js +19 -0
- package/src/runtime/index.js +309 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../../library");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _opmAddition = _interopRequireDefault(require("./opmAddition"));
|
|
10
|
+
var _opmDivision = _interopRequireDefault(require("./opmDivision"));
|
|
11
|
+
var _opmMultiplication = _interopRequireDefault(require("./opmMultiplication"));
|
|
12
|
+
var _opmRemainder = _interopRequireDefault(require("./opmRemainder"));
|
|
13
|
+
var _opmSubtraction = _interopRequireDefault(require("./opmSubtraction"));
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
var _default = exports.default = {
|
|
16
|
+
/** { pipe: [op], operations: [opm] } */
|
|
17
|
+
op(runtime, input, params, scope, next) {
|
|
18
|
+
const iter = async (from, value) => {
|
|
19
|
+
// 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.
|
|
20
|
+
await undefined;
|
|
21
|
+
scope.signal.checkHealth();
|
|
22
|
+
if (from >= (params.operations?.length ?? 0)) return next(value, scope);
|
|
23
|
+
const {
|
|
24
|
+
op,
|
|
25
|
+
params: opParams
|
|
26
|
+
} = params.operations[from];
|
|
27
|
+
const operator = opms[op];
|
|
28
|
+
if (!operator) throw new _library.JPLFatalError(`invalid OPM '${op}'`);
|
|
29
|
+
return operator.op(runtime, input, value, opParams ?? {}, scope, output => iter(from + 1, output));
|
|
30
|
+
};
|
|
31
|
+
return runtime.executeInstructions(params.pipe ?? [], [input], scope, output => iter(0, output));
|
|
32
|
+
},
|
|
33
|
+
/** { pipe: function, operations: [opm] } */
|
|
34
|
+
map(runtime, params) {
|
|
35
|
+
return {
|
|
36
|
+
pipe: (0, _utils.call)(params.pipe),
|
|
37
|
+
operations: runtime.muxOne([params.operations], ({
|
|
38
|
+
op,
|
|
39
|
+
params: opParams
|
|
40
|
+
}) => {
|
|
41
|
+
const operator = opms[op];
|
|
42
|
+
if (!operator) throw new _library.JPLFatalError(`invalid OPM '${op}'`);
|
|
43
|
+
return {
|
|
44
|
+
op: runtime.assertType(op, 'string'),
|
|
45
|
+
params: operator.map(runtime, opParams)
|
|
46
|
+
};
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const opms = {
|
|
52
|
+
[_library.OPM_ADDITION]: _opmAddition.default,
|
|
53
|
+
[_library.OPM_DIVISION]: _opmDivision.default,
|
|
54
|
+
[_library.OPM_MULTIPLICATION]: _opmMultiplication.default,
|
|
55
|
+
[_library.OPM_REMAINDER]: _opmRemainder.default,
|
|
56
|
+
[_library.OPM_SUBTRACTION]: _opmSubtraction.default
|
|
57
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../../library");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _default = exports.default = {
|
|
10
|
+
/** { by: [op] } */
|
|
11
|
+
op(runtime, input, target, params, scope, next) {
|
|
12
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, async by => next(await runtime.alterValue(target, a => {
|
|
13
|
+
const b = runtime.unwrapValue(by);
|
|
14
|
+
const ta = runtime.type(a);
|
|
15
|
+
const tb = runtime.type(b);
|
|
16
|
+
if (ta === 'null' || tb === 'null') {
|
|
17
|
+
if (ta !== 'null') return a;
|
|
18
|
+
if (tb !== 'null') return b;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
switch (ta) {
|
|
22
|
+
case 'number':
|
|
23
|
+
if (tb === 'number') return a + b;
|
|
24
|
+
break;
|
|
25
|
+
case 'array':
|
|
26
|
+
if (tb === 'array') {
|
|
27
|
+
if (b.length === 0) return a;
|
|
28
|
+
if (a.length === 0) return b;
|
|
29
|
+
return [...a, ...b];
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
case 'string':
|
|
33
|
+
if (tb === 'string') return a + b;
|
|
34
|
+
break;
|
|
35
|
+
case 'object':
|
|
36
|
+
if (tb === 'object') return (0, _library.applyObject)(a, Object.entries(b));
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
}
|
|
40
|
+
throw new _library.JPLTypeError('%s (%*<100v) and %s (%*<100v) cannot be added together', ta, a, tb, b);
|
|
41
|
+
})));
|
|
42
|
+
},
|
|
43
|
+
/** { by: function } */
|
|
44
|
+
map(runtime, params) {
|
|
45
|
+
return {
|
|
46
|
+
by: (0, _utils.call)(params.by)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../../library");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _default = exports.default = {
|
|
10
|
+
/** { by: [op] } */
|
|
11
|
+
op(runtime, input, target, params, scope, next) {
|
|
12
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, async by => next(await runtime.alterValue(target, a => {
|
|
13
|
+
const b = runtime.unwrapValue(by);
|
|
14
|
+
const ta = runtime.type(a);
|
|
15
|
+
const tb = runtime.type(b);
|
|
16
|
+
switch (ta) {
|
|
17
|
+
case 'number':
|
|
18
|
+
if (tb === 'number') {
|
|
19
|
+
if (b === 0) {
|
|
20
|
+
throw new _library.JPLZeroDivisionError('%s (%*<100v) cannot be divided by zero', ta, a);
|
|
21
|
+
}
|
|
22
|
+
return a / b;
|
|
23
|
+
}
|
|
24
|
+
break;
|
|
25
|
+
case 'string':
|
|
26
|
+
if (tb === 'string') {
|
|
27
|
+
if (b === '') return [...a];
|
|
28
|
+
return a.split(b);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
}
|
|
33
|
+
throw new _library.JPLTypeError('%s (%*<100v) cannot be divided by %s (%*<100v)', ta, a, tb, b);
|
|
34
|
+
})));
|
|
35
|
+
},
|
|
36
|
+
/** { by: function } */
|
|
37
|
+
map(runtime, params) {
|
|
38
|
+
return {
|
|
39
|
+
by: (0, _utils.call)(params.by)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../../library");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _default = exports.default = {
|
|
10
|
+
/** { by: [op] } */
|
|
11
|
+
op(runtime, input, target, params, scope, next) {
|
|
12
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, async by => next(await runtime.alterValue(target, a => {
|
|
13
|
+
const b = runtime.unwrapValue(by);
|
|
14
|
+
const ta = runtime.type(a);
|
|
15
|
+
const tb = runtime.type(b);
|
|
16
|
+
switch (ta) {
|
|
17
|
+
case 'number':
|
|
18
|
+
if (tb === 'number') return a * b;
|
|
19
|
+
break;
|
|
20
|
+
case 'string':
|
|
21
|
+
if (tb === 'number') {
|
|
22
|
+
if (b < 1) return null;
|
|
23
|
+
return a.repeat(b);
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
case 'object':
|
|
27
|
+
if (tb === 'object') return runtime.merge(a, b);
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
}
|
|
31
|
+
throw new _library.JPLTypeError('%s (%*<100v) and %s (%*<100v) cannot be multiplied together', ta, a, tb, b);
|
|
32
|
+
})));
|
|
33
|
+
},
|
|
34
|
+
/** { by: function } */
|
|
35
|
+
map(runtime, params) {
|
|
36
|
+
return {
|
|
37
|
+
by: (0, _utils.call)(params.by)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../../library");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _default = exports.default = {
|
|
10
|
+
/** { by: [op] } */
|
|
11
|
+
op(runtime, input, target, params, scope, next) {
|
|
12
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, async by => next(await runtime.alterValue(target, a => {
|
|
13
|
+
const b = runtime.unwrapValue(by);
|
|
14
|
+
const ta = runtime.type(a);
|
|
15
|
+
const tb = runtime.type(b);
|
|
16
|
+
switch (ta) {
|
|
17
|
+
case 'number':
|
|
18
|
+
if (tb === 'number') {
|
|
19
|
+
if (b === 0) throw new _library.JPLZeroDivisionError('%s (%*<100v) cannot be divided by zero (remainder)', ta, a);
|
|
20
|
+
return a % b;
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
}
|
|
25
|
+
throw new _library.JPLTypeError('%s (%*<100v) cannot be divided by %s (%*<100v) (remainder)', ta, a, tb, b);
|
|
26
|
+
})));
|
|
27
|
+
},
|
|
28
|
+
/** { by: function } */
|
|
29
|
+
map(runtime, params) {
|
|
30
|
+
return {
|
|
31
|
+
by: (0, _utils.call)(params.by)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../../library");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _default = exports.default = {
|
|
10
|
+
/** { by: [op] } */
|
|
11
|
+
op(runtime, input, target, params, scope, next) {
|
|
12
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, async by => next(await runtime.alterValue(target, a => {
|
|
13
|
+
const b = runtime.unwrapValue(by);
|
|
14
|
+
const ta = runtime.type(a);
|
|
15
|
+
const tb = runtime.type(b);
|
|
16
|
+
switch (ta) {
|
|
17
|
+
case 'number':
|
|
18
|
+
if (tb === 'number') return a - b;
|
|
19
|
+
break;
|
|
20
|
+
case 'array':
|
|
21
|
+
if (tb === 'array') {
|
|
22
|
+
if (a.length === 0 || b.length === 0) return a;
|
|
23
|
+
const filtered = a.filter(v => !b.some(entry => runtime.equals(v, entry)));
|
|
24
|
+
return a.length === filtered.length ? a : filtered;
|
|
25
|
+
}
|
|
26
|
+
break;
|
|
27
|
+
case 'string':
|
|
28
|
+
if (tb === 'string') return a.replaceAll(b, '');
|
|
29
|
+
break;
|
|
30
|
+
case 'object':
|
|
31
|
+
switch (tb) {
|
|
32
|
+
case 'array':
|
|
33
|
+
{
|
|
34
|
+
if (b.length === 0) return a;
|
|
35
|
+
return (0, _library.applyObject)(a, Object.entries(a).filter(([, v]) => b.some(entry => runtime.equals(v, entry))).map(([k]) => [k]));
|
|
36
|
+
}
|
|
37
|
+
case 'string':
|
|
38
|
+
return (0, _library.applyObject)(a, [[b]]);
|
|
39
|
+
default:
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
}
|
|
44
|
+
throw new _library.JPLTypeError('%s (%*<100v) and %s (%*<100v) cannot be subtracted', ta, a, tb, b);
|
|
45
|
+
})));
|
|
46
|
+
},
|
|
47
|
+
/** { by: function } */
|
|
48
|
+
map(runtime, params) {
|
|
49
|
+
return {
|
|
50
|
+
by: (0, _utils.call)(params.by)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../../library");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _opcEqual = _interopRequireDefault(require("./opcEqual"));
|
|
10
|
+
var _opcGreater = _interopRequireDefault(require("./opcGreater"));
|
|
11
|
+
var _opcGreaterEqual = _interopRequireDefault(require("./opcGreaterEqual"));
|
|
12
|
+
var _opcLess = _interopRequireDefault(require("./opcLess"));
|
|
13
|
+
var _opcLessEqual = _interopRequireDefault(require("./opcLessEqual"));
|
|
14
|
+
var _opcUnequal = _interopRequireDefault(require("./opcUnequal"));
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
var _default = exports.default = {
|
|
17
|
+
/** { pipe: [op], comparisons: [opc] } */
|
|
18
|
+
op(runtime, input, params, scope, next) {
|
|
19
|
+
const iter = async (from, value) => {
|
|
20
|
+
// 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.
|
|
21
|
+
await undefined;
|
|
22
|
+
scope.signal.checkHealth();
|
|
23
|
+
if (from >= (params.comparisons?.length ?? 0)) return next(value, scope);
|
|
24
|
+
const {
|
|
25
|
+
op,
|
|
26
|
+
params: opParams
|
|
27
|
+
} = params.comparisons[from];
|
|
28
|
+
const operator = opcs[op];
|
|
29
|
+
if (!operator) throw new _library.JPLFatalError(`invalid OPC '${op}'`);
|
|
30
|
+
return operator.op(runtime, input, value, opParams ?? {}, scope, output => iter(from + 1, output));
|
|
31
|
+
};
|
|
32
|
+
return runtime.executeInstructions(params.pipe ?? [], [input], scope, output => iter(0, output));
|
|
33
|
+
},
|
|
34
|
+
/** { pipe: function, comparisons: [opc] } */
|
|
35
|
+
map(runtime, params) {
|
|
36
|
+
return {
|
|
37
|
+
pipe: (0, _utils.call)(params.pipe),
|
|
38
|
+
comparisons: runtime.muxOne([params.comparisons], ({
|
|
39
|
+
op,
|
|
40
|
+
params: opParams
|
|
41
|
+
}) => {
|
|
42
|
+
const operator = opcs[op];
|
|
43
|
+
if (!operator) throw new _library.JPLFatalError(`invalid OPC '${op}'`);
|
|
44
|
+
return {
|
|
45
|
+
op: runtime.assertType(op, 'string'),
|
|
46
|
+
params: operator.map(runtime, opParams)
|
|
47
|
+
};
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const opcs = {
|
|
53
|
+
[_library.OPC_EQUAL]: _opcEqual.default,
|
|
54
|
+
[_library.OPC_GREATER]: _opcGreater.default,
|
|
55
|
+
[_library.OPC_GREATEREQUAL]: _opcGreaterEqual.default,
|
|
56
|
+
[_library.OPC_LESS]: _opcLess.default,
|
|
57
|
+
[_library.OPC_LESSEQUAL]: _opcLessEqual.default,
|
|
58
|
+
[_library.OPC_UNEQUAL]: _opcUnequal.default
|
|
59
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** { by: [op] } */
|
|
10
|
+
op(runtime, input, target, params, scope, next) {
|
|
11
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, by => next(runtime.equals(target, by)));
|
|
12
|
+
},
|
|
13
|
+
/** { by: function } */
|
|
14
|
+
map(runtime, params) {
|
|
15
|
+
return {
|
|
16
|
+
by: (0, _utils.call)(params.by)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** { by: [op] } */
|
|
10
|
+
op(runtime, input, target, params, scope, next) {
|
|
11
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, by => next(runtime.compare(target, by) > 0));
|
|
12
|
+
},
|
|
13
|
+
/** { by: function } */
|
|
14
|
+
map(runtime, params) {
|
|
15
|
+
return {
|
|
16
|
+
by: (0, _utils.call)(params.by)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** { by: [op] } */
|
|
10
|
+
op(runtime, input, target, params, scope, next) {
|
|
11
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, by => next(runtime.compare(target, by) >= 0));
|
|
12
|
+
},
|
|
13
|
+
/** { by: function } */
|
|
14
|
+
map(runtime, params) {
|
|
15
|
+
return {
|
|
16
|
+
by: (0, _utils.call)(params.by)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** { by: [op] } */
|
|
10
|
+
op(runtime, input, target, params, scope, next) {
|
|
11
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, by => next(runtime.compare(target, by) < 0));
|
|
12
|
+
},
|
|
13
|
+
/** { by: function } */
|
|
14
|
+
map(runtime, params) {
|
|
15
|
+
return {
|
|
16
|
+
by: (0, _utils.call)(params.by)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** { by: [op] } */
|
|
10
|
+
op(runtime, input, target, params, scope, next) {
|
|
11
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, by => next(runtime.compare(target, by) <= 0));
|
|
12
|
+
},
|
|
13
|
+
/** { by: function } */
|
|
14
|
+
map(runtime, params) {
|
|
15
|
+
return {
|
|
16
|
+
by: (0, _utils.call)(params.by)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** { by: [op] } */
|
|
10
|
+
op(runtime, input, target, params, scope, next) {
|
|
11
|
+
return runtime.executeInstructions(params.by ?? [], [input], scope, by => next(!runtime.equals(target, by)));
|
|
12
|
+
},
|
|
13
|
+
/** { by: function } */
|
|
14
|
+
map(runtime, params) {
|
|
15
|
+
return {
|
|
16
|
+
by: (0, _utils.call)(params.by)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
/** { value: any } */
|
|
9
|
+
op(runtime, input, params, scope, next) {
|
|
10
|
+
return next(params.value ?? null, scope);
|
|
11
|
+
},
|
|
12
|
+
/** { value: any } */
|
|
13
|
+
map(runtime, params) {
|
|
14
|
+
return {
|
|
15
|
+
value: runtime.normalizeValue(params.value)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
/** {} */
|
|
9
|
+
op(runtime, input, params, scope, next) {
|
|
10
|
+
return next(false, scope);
|
|
11
|
+
},
|
|
12
|
+
/** {} */
|
|
13
|
+
map() {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
/** {} */
|
|
9
|
+
op(runtime, input, params, scope, next) {
|
|
10
|
+
return next(null, scope);
|
|
11
|
+
},
|
|
12
|
+
/** {} */
|
|
13
|
+
map() {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
/** {} */
|
|
9
|
+
op(runtime, input, params, scope, next) {
|
|
10
|
+
return next(true, scope);
|
|
11
|
+
},
|
|
12
|
+
/** {} */
|
|
13
|
+
map() {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../library");
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
var _default = exports.default = {
|
|
10
|
+
/** { argNames: [string], pipe: [op] } */
|
|
11
|
+
op(runtime, input, params, scope, next) {
|
|
12
|
+
return next((0, _library.scopedFunction)(params.argNames ?? [], params.pipe ?? [], scope), scope);
|
|
13
|
+
},
|
|
14
|
+
/** { argNames: [string], pipe: function } */
|
|
15
|
+
map(runtime, params) {
|
|
16
|
+
return {
|
|
17
|
+
argNames: runtime.muxOne([params.argNames], entry => runtime.assertType(entry, 'string')),
|
|
18
|
+
pipe: (0, _utils.call)(params.pipe)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("./utils");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** { ifs: [{ if: [op], then: [op] }], else: [op] } */
|
|
10
|
+
op(runtime, input, params, scope, next) {
|
|
11
|
+
const iter = async from => {
|
|
12
|
+
// 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.
|
|
13
|
+
await undefined;
|
|
14
|
+
scope.signal.checkHealth();
|
|
15
|
+
if (from >= (params.ifs?.length ?? 0)) {
|
|
16
|
+
return runtime.executeInstructions(params.else ?? [], [input], scope, output => next(output, scope));
|
|
17
|
+
}
|
|
18
|
+
const condition = params.ifs[from];
|
|
19
|
+
return runtime.executeInstructions(condition.if ?? [], [input], scope, result => {
|
|
20
|
+
if (runtime.truthy(result)) {
|
|
21
|
+
return runtime.executeInstructions(condition.then ?? [], [input], scope, output => next(output, scope));
|
|
22
|
+
}
|
|
23
|
+
return iter(from + 1);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return iter(0);
|
|
27
|
+
},
|
|
28
|
+
/** { ifs: [{ if: function, then: function }], else: function } */
|
|
29
|
+
map(runtime, params) {
|
|
30
|
+
return {
|
|
31
|
+
ifs: runtime.muxOne([params.ifs], entry => ({
|
|
32
|
+
if: (0, _utils.call)(entry.if),
|
|
33
|
+
then: (0, _utils.call)(entry.then)
|
|
34
|
+
})),
|
|
35
|
+
else: (0, _utils.call)(params.else)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("./utils");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** { interpolations: [{ before: string, pipe: [op] }], after: string } */
|
|
10
|
+
async op(runtime, input, params, scope, next) {
|
|
11
|
+
const interpolations = await runtime.muxAsync([params.interpolations ?? []], interpolation => runtime.executeInstructions(interpolation.pipe ?? [], [input], scope, output => [(interpolation.before ?? '') + runtime.stringifyJSON(output, true)]));
|
|
12
|
+
return runtime.muxAll(interpolations, (...parts) => next(parts.join('') + (params.after ?? ''), scope));
|
|
13
|
+
},
|
|
14
|
+
/** { interpolations: [{ before: string, pipe: function }], after: string } */
|
|
15
|
+
map(runtime, params) {
|
|
16
|
+
return {
|
|
17
|
+
interpolations: runtime.muxOne([params.interpolations], entry => ({
|
|
18
|
+
before: runtime.assertType(entry.before, 'string'),
|
|
19
|
+
pipe: (0, _utils.call)(entry.pipe)
|
|
20
|
+
})),
|
|
21
|
+
after: runtime.assertType(params.after, 'string')
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _library = require("../../library");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
/** {} */
|
|
10
|
+
async op(runtime, input, params, scope, next) {
|
|
11
|
+
return next(await runtime.alterValue(input, value => {
|
|
12
|
+
const t = runtime.type(value);
|
|
13
|
+
switch (t) {
|
|
14
|
+
case 'number':
|
|
15
|
+
return -value;
|
|
16
|
+
default:
|
|
17
|
+
}
|
|
18
|
+
throw new _library.JPLTypeError('%s (%*<100v) cannot be negated', t, value);
|
|
19
|
+
}), scope);
|
|
20
|
+
},
|
|
21
|
+
/** {} */
|
|
22
|
+
map() {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
|
+
/** {} */
|
|
9
|
+
op(runtime, input, params, scope, next) {
|
|
10
|
+
return next(!runtime.truthy(input), scope);
|
|
11
|
+
},
|
|
12
|
+
/** {} */
|
|
13
|
+
map() {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
};
|