@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,17 @@
|
|
|
1
|
+
import { scopedFunction } from '../../library';
|
|
2
|
+
import { call } from './utils';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
/** { argNames: [string], pipe: [op] } */
|
|
6
|
+
op(runtime, input, params, scope, next) {
|
|
7
|
+
return next(scopedFunction(params.argNames ?? [], params.pipe ?? [], scope), scope);
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
/** { argNames: [string], pipe: function } */
|
|
11
|
+
map(runtime, params) {
|
|
12
|
+
return {
|
|
13
|
+
argNames: runtime.muxOne([params.argNames], (entry) => runtime.assertType(entry, 'string')),
|
|
14
|
+
pipe: call(params.pipe),
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { call } from './utils';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/** { ifs: [{ if: [op], then: [op] }], else: [op] } */
|
|
5
|
+
op(runtime, input, params, scope, next) {
|
|
6
|
+
const iter = async (from) => {
|
|
7
|
+
// 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.
|
|
8
|
+
await undefined;
|
|
9
|
+
|
|
10
|
+
scope.signal.checkHealth();
|
|
11
|
+
|
|
12
|
+
if (from >= (params.ifs?.length ?? 0)) {
|
|
13
|
+
return runtime.executeInstructions(params.else ?? [], [input], scope, (output) =>
|
|
14
|
+
next(output, scope),
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const condition = params.ifs[from];
|
|
19
|
+
|
|
20
|
+
return runtime.executeInstructions(condition.if ?? [], [input], scope, (result) => {
|
|
21
|
+
if (runtime.truthy(result)) {
|
|
22
|
+
return runtime.executeInstructions(condition.then ?? [], [input], scope, (output) =>
|
|
23
|
+
next(output, scope),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return iter(from + 1);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return iter(0);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
/** { ifs: [{ if: function, then: function }], else: function } */
|
|
35
|
+
map(runtime, params) {
|
|
36
|
+
return {
|
|
37
|
+
ifs: runtime.muxOne([params.ifs], (entry) => ({
|
|
38
|
+
if: call(entry.if),
|
|
39
|
+
then: call(entry.then),
|
|
40
|
+
})),
|
|
41
|
+
else: call(params.else),
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { call } from './utils';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/** { interpolations: [{ before: string, pipe: [op] }], after: string } */
|
|
5
|
+
async op(runtime, input, params, scope, next) {
|
|
6
|
+
const interpolations = await runtime.muxAsync([params.interpolations ?? []], (interpolation) =>
|
|
7
|
+
runtime.executeInstructions(interpolation.pipe ?? [], [input], scope, (output) => [
|
|
8
|
+
(interpolation.before ?? '') + runtime.stringifyJSON(output, true),
|
|
9
|
+
]),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
return runtime.muxAll(interpolations, (...parts) =>
|
|
13
|
+
next(parts.join('') + (params.after ?? ''), scope),
|
|
14
|
+
);
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
/** { interpolations: [{ before: string, pipe: function }], after: string } */
|
|
18
|
+
map(runtime, params) {
|
|
19
|
+
return {
|
|
20
|
+
interpolations: runtime.muxOne([params.interpolations], (entry) => ({
|
|
21
|
+
before: runtime.assertType(entry.before, 'string'),
|
|
22
|
+
pipe: call(entry.pipe),
|
|
23
|
+
})),
|
|
24
|
+
after: runtime.assertType(params.after, 'string'),
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { JPLTypeError } from '../../library';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/** {} */
|
|
5
|
+
async op(runtime, input, params, scope, next) {
|
|
6
|
+
return next(
|
|
7
|
+
await runtime.alterValue(input, (value) => {
|
|
8
|
+
const t = runtime.type(value);
|
|
9
|
+
switch (t) {
|
|
10
|
+
case 'number':
|
|
11
|
+
return -value;
|
|
12
|
+
|
|
13
|
+
default:
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new JPLTypeError('%s (%*<100v) cannot be negated', t, value);
|
|
17
|
+
}),
|
|
18
|
+
scope,
|
|
19
|
+
);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
/** {} */
|
|
23
|
+
map() {
|
|
24
|
+
return {};
|
|
25
|
+
},
|
|
26
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { call } from './utils';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/** { pipes: [[op]] } */
|
|
5
|
+
op(runtime, input, params, scope, next) {
|
|
6
|
+
const iter = async (from) => {
|
|
7
|
+
// 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.
|
|
8
|
+
await undefined;
|
|
9
|
+
|
|
10
|
+
scope.signal.checkHealth();
|
|
11
|
+
|
|
12
|
+
if (from >= (params.pipes?.length ?? 0)) return next(null, scope);
|
|
13
|
+
|
|
14
|
+
const pipe = params.pipes[from];
|
|
15
|
+
|
|
16
|
+
return runtime.executeInstructions(pipe ?? [], [input], scope, (output) => {
|
|
17
|
+
switch (runtime.type(output)) {
|
|
18
|
+
case 'null':
|
|
19
|
+
return iter(from + 1);
|
|
20
|
+
|
|
21
|
+
default:
|
|
22
|
+
return next(output, scope);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return iter(0);
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
/** { pipes: [function] } */
|
|
31
|
+
map(runtime, params) {
|
|
32
|
+
return {
|
|
33
|
+
pipes: runtime.muxOne([params.pipes], (pipe) => call(pipe)),
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
/** { number: number } */
|
|
3
|
+
op(runtime, input, params, scope, next) {
|
|
4
|
+
return next(params.number ?? 0, scope);
|
|
5
|
+
},
|
|
6
|
+
|
|
7
|
+
/** { number: number } */
|
|
8
|
+
map(runtime, params) {
|
|
9
|
+
return {
|
|
10
|
+
number: runtime.assertType(params.number, 'number'),
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { JPLTypeError } from '../../library';
|
|
2
|
+
import { call } from './utils';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
/** { fields: [{ key: [op], value: [op], optional: boolean }] } */
|
|
6
|
+
async op(runtime, input, params, scope, next) {
|
|
7
|
+
const fields = await runtime.muxAsync([params.fields ?? []], async (field) => {
|
|
8
|
+
const [keys, values] = await Promise.all([
|
|
9
|
+
runtime.executeInstructions(field.key ?? [], [input], scope),
|
|
10
|
+
runtime.executeInstructions(field.value ?? [], [input], scope),
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
return runtime.muxAll([runtime.unwrapValues(keys), values], (key, value) => {
|
|
14
|
+
const t = runtime.type(key);
|
|
15
|
+
switch (t) {
|
|
16
|
+
case 'string':
|
|
17
|
+
return [[key, value]];
|
|
18
|
+
|
|
19
|
+
default:
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (field.optional) return [];
|
|
23
|
+
throw new JPLTypeError('cannot use %s (%*<100v) as object key', t, key);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return runtime.muxAll(fields, (...entries) => next(Object.fromEntries(entries), scope));
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
/** { fields: [{ key: function, value: function, optional: boolean }] } */
|
|
31
|
+
map(runtime, params) {
|
|
32
|
+
return {
|
|
33
|
+
fields: runtime.muxOne([params.fields], (entry) => ({
|
|
34
|
+
key: call(entry.key),
|
|
35
|
+
value: call(entry.value),
|
|
36
|
+
optional: runtime.assertType(entry.optional, 'boolean'),
|
|
37
|
+
})),
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { call } from './utils';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/** { pipes: [[op]] } */
|
|
5
|
+
op(runtime, input, params, scope, next) {
|
|
6
|
+
const iter = async (from) => {
|
|
7
|
+
// 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.
|
|
8
|
+
await undefined;
|
|
9
|
+
|
|
10
|
+
scope.signal.checkHealth();
|
|
11
|
+
|
|
12
|
+
if (from >= (params.pipes?.length ?? 0)) return next(false, scope);
|
|
13
|
+
|
|
14
|
+
const pipe = params.pipes[from];
|
|
15
|
+
|
|
16
|
+
return runtime.executeInstructions(pipe ?? [], [input], scope, (output) => {
|
|
17
|
+
if (runtime.truthy(output)) return next(true, scope);
|
|
18
|
+
|
|
19
|
+
return iter(from + 1);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return iter(0);
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
/** { pipes: [function] } */
|
|
27
|
+
map(runtime, params) {
|
|
28
|
+
return {
|
|
29
|
+
pipes: runtime.muxOne([params.pipes], (pipe) => call(pipe)),
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { call } from './utils';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/** { pipes: [[op]] } */
|
|
5
|
+
op(runtime, input, params, scope, next) {
|
|
6
|
+
return runtime.muxAll([params.pipes ?? []], (pipe) =>
|
|
7
|
+
runtime.executeInstructions(pipe ?? [], [input], scope, (output) => next(output, scope)),
|
|
8
|
+
);
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
/** { pipes: [function] } */
|
|
12
|
+
map(runtime, params) {
|
|
13
|
+
return {
|
|
14
|
+
pipes: runtime.muxOne([params.pipes], (value) => call(value)),
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
/** { string: string } */
|
|
3
|
+
op(runtime, input, params, scope, next) {
|
|
4
|
+
return next(params.string ?? '', scope);
|
|
5
|
+
},
|
|
6
|
+
|
|
7
|
+
/** { string: string } */
|
|
8
|
+
map(runtime, params) {
|
|
9
|
+
return {
|
|
10
|
+
string: runtime.assertType(params.string, 'string'),
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { JPLErrorEnclosure, JPLExecutionError } from '../../library';
|
|
2
|
+
import { call } from './utils';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
/** { try: [op], catch: [op] } */
|
|
6
|
+
async op(runtime, input, params, scope, next) {
|
|
7
|
+
const nextScope = scope.next({ signal: scope.signal.next() });
|
|
8
|
+
try {
|
|
9
|
+
return await runtime.executeInstructions(
|
|
10
|
+
params.try ?? [],
|
|
11
|
+
[input],
|
|
12
|
+
nextScope,
|
|
13
|
+
async (output) => {
|
|
14
|
+
try {
|
|
15
|
+
return await next(output, scope);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
throw new JPLErrorEnclosure(err);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
if (JPLErrorEnclosure.is(err)) throw err.inner;
|
|
23
|
+
if (!JPLExecutionError.is(err)) throw err;
|
|
24
|
+
nextScope.signal.exit();
|
|
25
|
+
return runtime.executeInstructions(params.catch ?? [], [err.value], scope, (output) =>
|
|
26
|
+
next(output, scope),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/** { try: function, catch: function } */
|
|
32
|
+
map(runtime, params) {
|
|
33
|
+
return {
|
|
34
|
+
try: call(params.try),
|
|
35
|
+
catch: call(params.catch),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { JPLReferenceError } from '../../library';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/** { name: string } */
|
|
5
|
+
op(runtime, input, params, scope, next) {
|
|
6
|
+
if (!Object.hasOwn(scope.vars, params.name ?? ''))
|
|
7
|
+
throw new JPLReferenceError('%s is not defined', params.name ?? '');
|
|
8
|
+
return next(scope.vars[params.name ?? ''], scope);
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
/** { name: string } */
|
|
12
|
+
map(runtime, params) {
|
|
13
|
+
return {
|
|
14
|
+
name: runtime.assertType(params.name, 'string'),
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { call } from './utils';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
/** { name: string, pipe: [op] } */
|
|
5
|
+
op(runtime, input, params, scope, next) {
|
|
6
|
+
return runtime.executeInstructions(params.pipe ?? [], [input], scope, (output) =>
|
|
7
|
+
next(input, scope.next({ vars: { [params.name ?? '']: output } })),
|
|
8
|
+
);
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
/** { name: string, pipe: function } */
|
|
12
|
+
map(runtime, params) {
|
|
13
|
+
return {
|
|
14
|
+
name: runtime.assertType(params.name, 'string'),
|
|
15
|
+
pipe: call(params.pipe),
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|