greybel-interpreter 3.5.0 → 4.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.
Files changed (116) hide show
  1. package/dist/byte-compiler/instruction.d.ts +129 -0
  2. package/dist/byte-compiler/instruction.js +60 -0
  3. package/dist/bytecode-generator.d.ts +61 -0
  4. package/dist/bytecode-generator.js +1165 -0
  5. package/dist/context.d.ts +20 -88
  6. package/dist/context.js +44 -273
  7. package/dist/index.d.ts +5 -29
  8. package/dist/index.js +14 -87
  9. package/dist/interpreter.d.ts +9 -11
  10. package/dist/interpreter.js +75 -87
  11. package/dist/types/function.d.ts +11 -25
  12. package/dist/types/function.js +41 -105
  13. package/dist/types/list.d.ts +4 -5
  14. package/dist/types/list.js +10 -52
  15. package/dist/types/map.d.ts +5 -6
  16. package/dist/types/map.js +15 -74
  17. package/dist/types/number.d.ts +4 -5
  18. package/dist/types/number.js +5 -12
  19. package/dist/types/string.d.ts +4 -5
  20. package/dist/types/string.js +6 -18
  21. package/dist/types/with-intrinsics.d.ts +4 -5
  22. package/dist/utils/error.d.ts +5 -5
  23. package/dist/utils/error.js +4 -5
  24. package/dist/utils/stack.d.ts +10 -0
  25. package/dist/utils/stack.js +30 -0
  26. package/dist/vm/evaluation.d.ts +26 -0
  27. package/dist/vm/evaluation.js +341 -0
  28. package/dist/vm.d.ts +66 -0
  29. package/dist/vm.js +662 -0
  30. package/package.json +1 -1
  31. package/dist/cps.d.ts +0 -16
  32. package/dist/cps.js +0 -202
  33. package/dist/operations/assign-globals.d.ts +0 -11
  34. package/dist/operations/assign-globals.js +0 -31
  35. package/dist/operations/assign-locals.d.ts +0 -11
  36. package/dist/operations/assign-locals.js +0 -31
  37. package/dist/operations/assign-outer.d.ts +0 -11
  38. package/dist/operations/assign-outer.js +0 -31
  39. package/dist/operations/assign-self.d.ts +0 -11
  40. package/dist/operations/assign-self.js +0 -41
  41. package/dist/operations/assign.d.ts +0 -13
  42. package/dist/operations/assign.js +0 -60
  43. package/dist/operations/block.d.ts +0 -13
  44. package/dist/operations/block.js +0 -48
  45. package/dist/operations/break.d.ts +0 -10
  46. package/dist/operations/break.js +0 -21
  47. package/dist/operations/call.d.ts +0 -13
  48. package/dist/operations/call.js +0 -64
  49. package/dist/operations/chunk.d.ts +0 -12
  50. package/dist/operations/chunk.js +0 -31
  51. package/dist/operations/continue.d.ts +0 -10
  52. package/dist/operations/continue.js +0 -21
  53. package/dist/operations/debugger-statement.d.ts +0 -10
  54. package/dist/operations/debugger-statement.js +0 -19
  55. package/dist/operations/envar.d.ts +0 -10
  56. package/dist/operations/envar.js +0 -21
  57. package/dist/operations/evaluate.d.ts +0 -45
  58. package/dist/operations/evaluate.js +0 -369
  59. package/dist/operations/for.d.ts +0 -14
  60. package/dist/operations/for.js +0 -87
  61. package/dist/operations/function-reference.d.ts +0 -12
  62. package/dist/operations/function-reference.js +0 -48
  63. package/dist/operations/function.d.ts +0 -19
  64. package/dist/operations/function.js +0 -84
  65. package/dist/operations/if-statement.d.ts +0 -19
  66. package/dist/operations/if-statement.js +0 -87
  67. package/dist/operations/import.d.ts +0 -20
  68. package/dist/operations/import.js +0 -56
  69. package/dist/operations/include.d.ts +0 -14
  70. package/dist/operations/include.js +0 -40
  71. package/dist/operations/list.d.ts +0 -11
  72. package/dist/operations/list.js +0 -40
  73. package/dist/operations/literal.d.ts +0 -11
  74. package/dist/operations/literal.js +0 -38
  75. package/dist/operations/map.d.ts +0 -11
  76. package/dist/operations/map.js +0 -42
  77. package/dist/operations/negated-binary.d.ts +0 -11
  78. package/dist/operations/negated-binary.js +0 -40
  79. package/dist/operations/new-instance.d.ts +0 -11
  80. package/dist/operations/new-instance.js +0 -37
  81. package/dist/operations/noop.d.ts +0 -7
  82. package/dist/operations/noop.js +0 -14
  83. package/dist/operations/not.d.ts +0 -11
  84. package/dist/operations/not.js +0 -33
  85. package/dist/operations/operation.d.ts +0 -15
  86. package/dist/operations/operation.js +0 -13
  87. package/dist/operations/reference-globals.d.ts +0 -7
  88. package/dist/operations/reference-globals.js +0 -13
  89. package/dist/operations/reference-locals.d.ts +0 -7
  90. package/dist/operations/reference-locals.js +0 -13
  91. package/dist/operations/reference-outer.d.ts +0 -7
  92. package/dist/operations/reference-outer.js +0 -13
  93. package/dist/operations/reference-self.d.ts +0 -7
  94. package/dist/operations/reference-self.js +0 -13
  95. package/dist/operations/reference.d.ts +0 -9
  96. package/dist/operations/reference.js +0 -17
  97. package/dist/operations/resolve-globals.d.ts +0 -5
  98. package/dist/operations/resolve-globals.js +0 -24
  99. package/dist/operations/resolve-locals.d.ts +0 -5
  100. package/dist/operations/resolve-locals.js +0 -24
  101. package/dist/operations/resolve-outer.d.ts +0 -5
  102. package/dist/operations/resolve-outer.js +0 -24
  103. package/dist/operations/resolve-self.d.ts +0 -5
  104. package/dist/operations/resolve-self.js +0 -24
  105. package/dist/operations/resolve.d.ts +0 -55
  106. package/dist/operations/resolve.js +0 -269
  107. package/dist/operations/return.d.ts +0 -11
  108. package/dist/operations/return.js +0 -43
  109. package/dist/operations/while.d.ts +0 -13
  110. package/dist/operations/while.js +0 -70
  111. package/dist/utils/create-assign.d.ts +0 -3
  112. package/dist/utils/create-assign.js +0 -25
  113. package/dist/utils/create-resolve.d.ts +0 -5
  114. package/dist/utils/create-resolve.js +0 -51
  115. package/dist/utils/path.d.ts +0 -10
  116. package/dist/utils/path.js +0 -33
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.FunctionReference = void 0;
13
- const default_1 = require("../types/default");
14
- const create_resolve_1 = require("../utils/create-resolve");
15
- const operation_1 = require("./operation");
16
- const resolve_1 = require("./resolve");
17
- class FunctionReference extends operation_1.Operation {
18
- constructor(item, target) {
19
- super(null, target);
20
- this.item = item;
21
- }
22
- build(visit) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- this.ref = (0, create_resolve_1.createResolve)(this.item.argument, this.target);
25
- yield this.ref.build(visit);
26
- return this;
27
- });
28
- }
29
- handle(ctx) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const exitObserver = ctx.processState.createExitObserver();
32
- const refResult = yield this.ref.getResult(ctx);
33
- exitObserver.close();
34
- if (exitObserver.occured()) {
35
- return default_1.DefaultType.Void;
36
- }
37
- if (!(refResult.handle instanceof resolve_1.ResolveNil)) {
38
- if (refResult.path.count() === 0) {
39
- return refResult.handle;
40
- }
41
- const customValueCtx = refResult.handle;
42
- return customValueCtx.get(refResult.path, ctx.contextTypeIntrinsics);
43
- }
44
- return ctx.get(refResult.path);
45
- });
46
- }
47
- }
48
- exports.FunctionReference = FunctionReference;
@@ -1,19 +0,0 @@
1
- import { ASTFunctionStatement } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CustomString } from '../types/string';
5
- import { CPSVisit, Operation } from './operation';
6
- export declare const SELF_PROPERTY: CustomString;
7
- export declare const SUPER_PROPERTY: CustomString;
8
- export interface FunctionOperationArgument {
9
- name: string;
10
- op: Operation;
11
- }
12
- export declare class FunctionOperation extends Operation {
13
- readonly item: ASTFunctionStatement;
14
- block: Operation;
15
- args: FunctionOperationArgument[];
16
- constructor(item: ASTFunctionStatement, target?: string);
17
- build(visit: CPSVisit): Promise<Operation>;
18
- handle(ctx: OperationContext, assignOuter?: boolean): Promise<CustomValue>;
19
- }
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.FunctionOperation = exports.SUPER_PROPERTY = exports.SELF_PROPERTY = void 0;
13
- const miniscript_core_1 = require("miniscript-core");
14
- const context_1 = require("../context");
15
- const default_1 = require("../types/default");
16
- const function_1 = require("../types/function");
17
- const string_1 = require("../types/string");
18
- const with_intrinsics_1 = require("../types/with-intrinsics");
19
- const block_1 = require("./block");
20
- const operation_1 = require("./operation");
21
- const reference_1 = require("./reference");
22
- exports.SELF_PROPERTY = new string_1.CustomString(function_1.SELF_NAMESPACE);
23
- exports.SUPER_PROPERTY = new string_1.CustomString(function_1.SUPER_NAMESPACE);
24
- class FunctionOperation extends operation_1.Operation {
25
- constructor(item, target) {
26
- super(null, target);
27
- this.item = item;
28
- }
29
- build(visit) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
32
- this.block = new block_1.Block(this.item, stack);
33
- this.args = yield Promise.all(this.item.parameters.map((child) => __awaiter(this, void 0, void 0, function* () {
34
- switch (child.type) {
35
- case miniscript_core_1.ASTType.AssignmentStatement: {
36
- const assignStatement = child;
37
- const assignKey = assignStatement.variable;
38
- return {
39
- name: assignKey.name,
40
- op: yield visit(assignStatement.init)
41
- };
42
- }
43
- case miniscript_core_1.ASTType.Identifier: {
44
- const identifierKey = child;
45
- return {
46
- name: identifierKey.name,
47
- op: new reference_1.Reference(default_1.DefaultType.Void)
48
- };
49
- }
50
- default:
51
- throw new Error('Unexpected operation in arguments.');
52
- }
53
- })));
54
- return this;
55
- });
56
- }
57
- handle(ctx, assignOuter = false) {
58
- const func = new function_1.CustomFunction(ctx, 'anonymous', (fnCtx, self, args) => __awaiter(this, void 0, void 0, function* () {
59
- const functionState = new context_1.FunctionState();
60
- functionState.context = self;
61
- if (self instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
62
- fnCtx.set(exports.SELF_PROPERTY, self);
63
- }
64
- const next = func.getNextContext();
65
- if (next) {
66
- fnCtx.set(exports.SUPER_PROPERTY, next);
67
- functionState.super = next;
68
- }
69
- for (const [key, value] of args) {
70
- if (key === function_1.SELF_NAMESPACE)
71
- continue;
72
- fnCtx.set(new string_1.CustomString(key), value);
73
- }
74
- fnCtx.functionState = functionState;
75
- yield this.block.handle(fnCtx);
76
- return functionState.value;
77
- }), [], assignOuter);
78
- for (const item of this.args) {
79
- func.addArgument(item.name, item.op);
80
- }
81
- return Promise.resolve(func);
82
- }
83
- }
84
- exports.FunctionOperation = FunctionOperation;
@@ -1,19 +0,0 @@
1
- import { ASTElseClause, ASTIfClause, ASTIfStatement } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { Block } from './block';
5
- import { CPSVisit, Operation, OperationBlock } from './operation';
6
- export declare class Clause {
7
- readonly condition: Operation;
8
- readonly block: Block;
9
- constructor(condition: Operation, block: Block);
10
- }
11
- export declare class IfStatement extends OperationBlock {
12
- readonly item: ASTIfStatement;
13
- clauses: Array<Clause>;
14
- constructor(item: ASTIfStatement, target?: string);
15
- buildIfClause(node: ASTIfClause, visit: CPSVisit): Promise<void>;
16
- buildElseClause(node: ASTElseClause, visit: CPSVisit): Promise<void>;
17
- build(visit: CPSVisit): Promise<Operation>;
18
- handle(ctx: OperationContext): Promise<CustomValue>;
19
- }
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.IfStatement = exports.Clause = void 0;
13
- const miniscript_core_1 = require("miniscript-core");
14
- const boolean_1 = require("../types/boolean");
15
- const default_1 = require("../types/default");
16
- const block_1 = require("./block");
17
- const operation_1 = require("./operation");
18
- const reference_1 = require("./reference");
19
- class Clause {
20
- constructor(condition, block) {
21
- this.condition = condition;
22
- this.block = block;
23
- }
24
- }
25
- exports.Clause = Clause;
26
- class IfStatement extends operation_1.OperationBlock {
27
- constructor(item, target) {
28
- super(null, target);
29
- this.item = item;
30
- }
31
- buildIfClause(node, visit) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const condition = yield visit(node.condition);
34
- const stack = yield Promise.all(node.body.map((child) => visit(child)));
35
- const block = new block_1.Block(this.item, stack);
36
- this.clauses.push(new Clause(condition, block));
37
- });
38
- }
39
- buildElseClause(node, visit) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const condition = new reference_1.Reference(new boolean_1.CustomBoolean(true));
42
- const stack = yield Promise.all(node.body.map((child) => visit(child)));
43
- const block = new block_1.Block(this.item, stack);
44
- this.clauses.push(new Clause(condition, block));
45
- });
46
- }
47
- build(visit) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- this.clauses = [];
50
- for (let index = 0; index < this.item.clauses.length; index++) {
51
- const child = this.item.clauses[index];
52
- switch (child.type) {
53
- case miniscript_core_1.ASTType.IfClause:
54
- case miniscript_core_1.ASTType.IfShortcutClause:
55
- case miniscript_core_1.ASTType.ElseifClause:
56
- case miniscript_core_1.ASTType.ElseifShortcutClause:
57
- yield this.buildIfClause(child, visit);
58
- break;
59
- case miniscript_core_1.ASTType.ElseClause:
60
- case miniscript_core_1.ASTType.ElseShortcutClause:
61
- yield this.buildElseClause(child, visit);
62
- break;
63
- }
64
- }
65
- return this;
66
- });
67
- }
68
- handle(ctx) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const exitObserver = ctx.processState.createExitObserver();
71
- for (let index = 0; index < this.clauses.length; index++) {
72
- const clause = this.clauses[index];
73
- const clauseResult = yield ctx.step(clause.condition);
74
- if (exitObserver.occured()) {
75
- break;
76
- }
77
- if (clauseResult.toTruthy()) {
78
- yield clause.block.handle(ctx);
79
- break;
80
- }
81
- }
82
- exitObserver.close();
83
- return default_1.DefaultType.Void;
84
- });
85
- }
86
- }
87
- exports.IfStatement = IfStatement;
@@ -1,20 +0,0 @@
1
- import { ASTFeatureImportExpression } from 'greybel-core';
2
- import { ASTBase } from 'miniscript-core';
3
- import { OperationContext } from '../context';
4
- import { CustomValue } from '../types/base';
5
- import { CustomString } from '../types/string';
6
- import { Path } from '../utils/path';
7
- import { CPSVisit, Operation } from './operation';
8
- export declare const MODULE_PROPERTY: CustomString;
9
- export declare const EXPORTS_PROPERTY: CustomString;
10
- export declare const EXPORTS_PATH: Path<CustomString>;
11
- export declare class Import extends Operation {
12
- readonly item: ASTFeatureImportExpression;
13
- newTarget: string;
14
- code: string;
15
- chunk: ASTBase;
16
- top: Operation;
17
- constructor(item: ASTFeatureImportExpression, target: string, newTarget: string, code: string);
18
- build(visit: CPSVisit): Promise<Operation>;
19
- handle(ctx: OperationContext): Promise<CustomValue>;
20
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Import = exports.EXPORTS_PATH = exports.EXPORTS_PROPERTY = exports.MODULE_PROPERTY = void 0;
13
- const greybel_core_1 = require("greybel-core");
14
- const context_1 = require("../context");
15
- const default_1 = require("../types/default");
16
- const map_1 = require("../types/map");
17
- const string_1 = require("../types/string");
18
- const path_1 = require("../utils/path");
19
- const operation_1 = require("./operation");
20
- exports.MODULE_PROPERTY = new string_1.CustomString('module');
21
- exports.EXPORTS_PROPERTY = new string_1.CustomString('exports');
22
- exports.EXPORTS_PATH = new path_1.Path([exports.MODULE_PROPERTY, exports.EXPORTS_PROPERTY]);
23
- class Import extends operation_1.Operation {
24
- constructor(item, target, newTarget, code) {
25
- super(null, target);
26
- this.newTarget = newTarget;
27
- this.item = item;
28
- this.code = code;
29
- }
30
- build(visit) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const parser = new greybel_core_1.Parser(this.code);
33
- this.chunk = parser.parseChunk();
34
- this.top = yield visit(this.chunk);
35
- return this;
36
- });
37
- }
38
- handle(ctx) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const importCtx = ctx.fork({
41
- type: context_1.ContextType.External,
42
- state: context_1.ContextState.Default,
43
- target: this.newTarget
44
- });
45
- importCtx.locals.scope.set(exports.MODULE_PROPERTY, new map_1.CustomMap());
46
- yield this.top.handle(importCtx);
47
- const item = importCtx.locals.scope.has(exports.EXPORTS_PATH)
48
- ? importCtx.scope.get(exports.EXPORTS_PATH, ctx.contextTypeIntrinsics)
49
- : default_1.DefaultType.Void;
50
- const identifier = this.item.name;
51
- ctx.set(new string_1.CustomString(identifier.name), item);
52
- return default_1.DefaultType.Void;
53
- });
54
- }
55
- }
56
- exports.Import = Import;
@@ -1,14 +0,0 @@
1
- import { ASTBase } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class Include extends Operation {
6
- readonly item: ASTBase;
7
- newTarget: string;
8
- code: string;
9
- chunk: ASTBase;
10
- top: Operation;
11
- constructor(item: ASTBase, target: string, newTarget: string, code: string);
12
- build(visit: CPSVisit): Promise<Operation>;
13
- handle(ctx: OperationContext): Promise<CustomValue>;
14
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Include = void 0;
13
- const greybel_core_1 = require("greybel-core");
14
- const context_1 = require("../context");
15
- const operation_1 = require("./operation");
16
- class Include extends operation_1.Operation {
17
- constructor(item, target, newTarget, code) {
18
- super(null, target);
19
- this.newTarget = newTarget;
20
- this.item = item;
21
- this.code = code;
22
- }
23
- build(visit) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const parser = new greybel_core_1.Parser(this.code);
26
- this.chunk = parser.parseChunk();
27
- this.top = yield visit(this.chunk);
28
- return this;
29
- });
30
- }
31
- handle(ctx) {
32
- const importCtx = ctx.fork({
33
- type: context_1.ContextType.External,
34
- state: context_1.ContextState.Temporary,
35
- target: this.newTarget
36
- });
37
- return this.top.handle(importCtx);
38
- }
39
- }
40
- exports.Include = Include;
@@ -1,11 +0,0 @@
1
- import { ASTListConstructorExpression } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class List extends Operation {
6
- readonly item: ASTListConstructorExpression;
7
- fields: Array<Operation>;
8
- constructor(item: ASTListConstructorExpression, target?: string);
9
- build(visit: CPSVisit): Promise<Operation>;
10
- handle(ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.List = void 0;
13
- const list_1 = require("../types/list");
14
- const operation_1 = require("./operation");
15
- class List extends operation_1.Operation {
16
- constructor(item, target) {
17
- super(null, target);
18
- this.item = item;
19
- }
20
- build(visit) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- this.fields = yield Promise.all(this.item.fields.map((child) => {
23
- const listValue = child;
24
- return visit(listValue.value);
25
- }));
26
- return this;
27
- });
28
- }
29
- handle(ctx) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const fields = [];
32
- for (let index = 0; index < this.fields.length; index++) {
33
- const child = this.fields[index];
34
- fields.push(yield child.handle(ctx));
35
- }
36
- return new list_1.CustomList(fields);
37
- });
38
- }
39
- }
40
- exports.List = List;
@@ -1,11 +0,0 @@
1
- import { ASTLiteral } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class Literal extends Operation {
6
- readonly item: ASTLiteral;
7
- value: CustomValue;
8
- constructor(item: ASTLiteral, target?: string);
9
- build(_visit: CPSVisit): Promise<Operation>;
10
- handle(_ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Literal = void 0;
4
- const miniscript_core_1 = require("miniscript-core");
5
- const boolean_1 = require("../types/boolean");
6
- const default_1 = require("../types/default");
7
- const number_1 = require("../types/number");
8
- const string_1 = require("../types/string");
9
- const operation_1 = require("./operation");
10
- class Literal extends operation_1.Operation {
11
- constructor(item, target) {
12
- super(null, target);
13
- this.item = item;
14
- }
15
- build(_visit) {
16
- switch (this.item.type) {
17
- case miniscript_core_1.ASTType.BooleanLiteral:
18
- this.value = new boolean_1.CustomBoolean(this.item.value);
19
- break;
20
- case miniscript_core_1.ASTType.StringLiteral:
21
- this.value = new string_1.CustomString(this.item.value);
22
- break;
23
- case miniscript_core_1.ASTType.NumericLiteral:
24
- this.value = new number_1.CustomNumber(this.item.value);
25
- break;
26
- case miniscript_core_1.ASTType.NilLiteral:
27
- this.value = default_1.DefaultType.Void;
28
- break;
29
- default:
30
- throw new Error('Unexpected literal type.');
31
- }
32
- return Promise.resolve(this);
33
- }
34
- handle(_ctx) {
35
- return Promise.resolve(this.value);
36
- }
37
- }
38
- exports.Literal = Literal;
@@ -1,11 +0,0 @@
1
- import { ASTMapConstructorExpression } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class MapOperation extends Operation {
6
- readonly item: ASTMapConstructorExpression;
7
- fields: Map<Operation, Operation>;
8
- constructor(item: ASTMapConstructorExpression, target?: string);
9
- build(visit: CPSVisit): Promise<Operation>;
10
- handle(ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MapOperation = void 0;
13
- const map_1 = require("../types/map");
14
- const object_value_1 = require("../utils/object-value");
15
- const operation_1 = require("./operation");
16
- class MapOperation extends operation_1.Operation {
17
- constructor(item, target) {
18
- super(null, target);
19
- this.item = item;
20
- }
21
- build(visit) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- this.fields = new Map();
24
- const defers = this.item.fields.map((child) => __awaiter(this, void 0, void 0, function* () {
25
- const mapKeyString = child;
26
- this.fields.set(yield visit(mapKeyString.key), yield visit(mapKeyString.value));
27
- }));
28
- yield Promise.all(defers);
29
- return this;
30
- });
31
- }
32
- handle(ctx) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const newMap = new object_value_1.ObjectValue();
35
- for (const [key, value] of this.fields) {
36
- newMap.set(yield key.handle(ctx), yield value.handle(ctx));
37
- }
38
- return new map_1.CustomMap(newMap);
39
- });
40
- }
41
- }
42
- exports.MapOperation = MapOperation;
@@ -1,11 +0,0 @@
1
- import { ASTUnaryExpression } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class NegatedBinary extends Operation {
6
- readonly item: ASTUnaryExpression;
7
- arg: Operation;
8
- constructor(item: ASTUnaryExpression, target?: string);
9
- build(visit: CPSVisit): Promise<Operation>;
10
- handle(ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.NegatedBinary = void 0;
13
- const miniscript_core_1 = require("miniscript-core");
14
- const number_1 = require("../types/number");
15
- const operation_1 = require("./operation");
16
- class NegatedBinary extends operation_1.Operation {
17
- constructor(item, target) {
18
- super(null, target);
19
- this.item = item;
20
- }
21
- build(visit) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- this.arg = yield visit(this.item.argument);
24
- return this;
25
- });
26
- }
27
- handle(ctx) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- switch (this.item.operator) {
30
- case miniscript_core_1.Operator.Minus:
31
- return new number_1.CustomNumber(-(yield this.arg.handle(ctx)).toNumber());
32
- case miniscript_core_1.Operator.Plus:
33
- return new number_1.CustomNumber(+(yield this.arg.handle(ctx)).toNumber());
34
- default:
35
- throw new Error('Unexpected negation operator.');
36
- }
37
- });
38
- }
39
- }
40
- exports.NegatedBinary = NegatedBinary;
@@ -1,11 +0,0 @@
1
- import { ASTUnaryExpression } from 'miniscript-core';
2
- import { OperationContext } from '../context';
3
- import { CustomValue } from '../types/base';
4
- import { CPSVisit, Operation } from './operation';
5
- export declare class NewInstance extends Operation {
6
- readonly item: ASTUnaryExpression;
7
- arg: Operation;
8
- constructor(item: ASTUnaryExpression, target?: string);
9
- build(visit: CPSVisit): Promise<Operation>;
10
- handle(ctx: OperationContext): Promise<CustomValue>;
11
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.NewInstance = void 0;
13
- const default_1 = require("../types/default");
14
- const map_1 = require("../types/map");
15
- const operation_1 = require("./operation");
16
- class NewInstance extends operation_1.Operation {
17
- constructor(item, target) {
18
- super(null, target);
19
- this.item = item;
20
- }
21
- build(visit) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- this.arg = yield visit(this.item.argument);
24
- return this;
25
- });
26
- }
27
- handle(ctx) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const resolvedArg = yield this.arg.handle(ctx);
30
- if (resolvedArg instanceof map_1.CustomMap) {
31
- return resolvedArg.createInstance();
32
- }
33
- return default_1.DefaultType.Void;
34
- });
35
- }
36
- }
37
- exports.NewInstance = NewInstance;