greybel-interpreter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/context.d.ts +68 -0
- package/dist/context.js +399 -0
- package/dist/cps.d.ts +15 -0
- package/dist/cps.js +438 -0
- package/dist/custom-types/boolean.d.ts +10 -0
- package/dist/custom-types/boolean.js +41 -0
- package/dist/custom-types/list.d.ts +25 -0
- package/dist/custom-types/list.js +281 -0
- package/dist/custom-types/map.d.ts +28 -0
- package/dist/custom-types/map.js +289 -0
- package/dist/custom-types/nil.d.ts +8 -0
- package/dist/custom-types/nil.js +38 -0
- package/dist/custom-types/number.d.ts +10 -0
- package/dist/custom-types/number.js +41 -0
- package/dist/custom-types/string.d.ts +21 -0
- package/dist/custom-types/string.js +132 -0
- package/dist/expressions/assign.d.ts +12 -0
- package/dist/expressions/assign.js +156 -0
- package/dist/expressions/binary-negated-expression.d.ts +18 -0
- package/dist/expressions/binary-negated-expression.js +115 -0
- package/dist/expressions/call.d.ts +13 -0
- package/dist/expressions/call.js +177 -0
- package/dist/expressions/list.d.ts +13 -0
- package/dist/expressions/list.js +119 -0
- package/dist/expressions/logical-and-binary.d.ts +22 -0
- package/dist/expressions/logical-and-binary.js +188 -0
- package/dist/expressions/map.d.ts +18 -0
- package/dist/expressions/map.js +171 -0
- package/dist/expressions/path.d.ts +30 -0
- package/dist/expressions/path.js +310 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +82 -0
- package/dist/interpreter.d.ts +20 -0
- package/dist/interpreter.js +55 -0
- package/dist/operations/argument.d.ts +8 -0
- package/dist/operations/argument.js +129 -0
- package/dist/operations/body.d.ts +8 -0
- package/dist/operations/body.js +144 -0
- package/dist/operations/break.d.ts +7 -0
- package/dist/operations/break.js +34 -0
- package/dist/operations/continue.d.ts +7 -0
- package/dist/operations/continue.js +34 -0
- package/dist/operations/debugger.d.ts +7 -0
- package/dist/operations/debugger.js +32 -0
- package/dist/operations/else-if.d.ts +12 -0
- package/dist/operations/else-if.js +31 -0
- package/dist/operations/else.d.ts +10 -0
- package/dist/operations/else.js +30 -0
- package/dist/operations/for.d.ts +16 -0
- package/dist/operations/for.js +139 -0
- package/dist/operations/function.d.ts +21 -0
- package/dist/operations/function.js +125 -0
- package/dist/operations/if-statement.d.ts +8 -0
- package/dist/operations/if-statement.js +138 -0
- package/dist/operations/if.d.ts +12 -0
- package/dist/operations/if.js +31 -0
- package/dist/operations/new.d.ts +11 -0
- package/dist/operations/new.js +96 -0
- package/dist/operations/not.d.ts +11 -0
- package/dist/operations/not.js +95 -0
- package/dist/operations/reference.d.ts +11 -0
- package/dist/operations/reference.js +102 -0
- package/dist/operations/return.d.ts +11 -0
- package/dist/operations/return.js +102 -0
- package/dist/operations/top.d.ts +12 -0
- package/dist/operations/top.js +84 -0
- package/dist/operations/while.d.ts +14 -0
- package/dist/operations/while.js +123 -0
- package/dist/resource.d.ts +9 -0
- package/dist/resource.js +29 -0
- package/dist/typer.d.ts +6 -0
- package/dist/typer.js +99 -0
- package/dist/types/custom-type.d.ts +19 -0
- package/dist/types/custom-type.js +58 -0
- package/dist/types/expression.d.ts +6 -0
- package/dist/types/expression.js +9 -0
- package/dist/types/operation.d.ts +9 -0
- package/dist/types/operation.js +38 -0
- package/package.json +45 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
54
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
55
|
+
if (!m) return o;
|
|
56
|
+
var i = m.call(o), r, ar = [], e;
|
|
57
|
+
try {
|
|
58
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
59
|
+
}
|
|
60
|
+
catch (error) { e = { error: error }; }
|
|
61
|
+
finally {
|
|
62
|
+
try {
|
|
63
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
64
|
+
}
|
|
65
|
+
finally { if (e) throw e.error; }
|
|
66
|
+
}
|
|
67
|
+
return ar;
|
|
68
|
+
};
|
|
69
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
70
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
71
|
+
if (ar || !(i in from)) {
|
|
72
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
73
|
+
ar[i] = from[i];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
77
|
+
};
|
|
78
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
+
exports.ExpressionSegment = void 0;
|
|
80
|
+
var greyscript_core_1 = require("greyscript-core");
|
|
81
|
+
var expression_1 = require("../types/expression");
|
|
82
|
+
var operation_1 = require("../types/operation");
|
|
83
|
+
var typer_1 = require("../typer");
|
|
84
|
+
var context_1 = require("../context");
|
|
85
|
+
var ExpressionSegment = /** @class */ (function () {
|
|
86
|
+
function ExpressionSegment(path, args) {
|
|
87
|
+
var me = this;
|
|
88
|
+
me.path = path;
|
|
89
|
+
me.args = args;
|
|
90
|
+
}
|
|
91
|
+
ExpressionSegment.prototype.resolveArgs = function (operationContext) {
|
|
92
|
+
var _this = this;
|
|
93
|
+
var me = this;
|
|
94
|
+
return Promise.all(me.args.map(function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
if ((0, typer_1.isCustomValue)(item)) {
|
|
97
|
+
return [2 /*return*/, item];
|
|
98
|
+
}
|
|
99
|
+
return [2 /*return*/, item.get(operationContext)];
|
|
100
|
+
});
|
|
101
|
+
}); }));
|
|
102
|
+
};
|
|
103
|
+
return ExpressionSegment;
|
|
104
|
+
}());
|
|
105
|
+
exports.ExpressionSegment = ExpressionSegment;
|
|
106
|
+
var CallExpression = /** @class */ (function (_super) {
|
|
107
|
+
__extends(CallExpression, _super);
|
|
108
|
+
function CallExpression(ast, visit) {
|
|
109
|
+
var _this = _super.call(this) || this;
|
|
110
|
+
var me = _this;
|
|
111
|
+
var buildExpression = function (node) {
|
|
112
|
+
if (greyscript_core_1.ASTType.CallStatement === node.type) {
|
|
113
|
+
return buildExpression(node.expression);
|
|
114
|
+
}
|
|
115
|
+
return new ExpressionSegment(visit(node.base), node.arguments.map(function (item) { return visit(item); }));
|
|
116
|
+
};
|
|
117
|
+
me.ast = ast;
|
|
118
|
+
me.expr = buildExpression(ast);
|
|
119
|
+
return _this;
|
|
120
|
+
}
|
|
121
|
+
CallExpression.prototype.get = function (operationContext, parentExpr) {
|
|
122
|
+
var me = this;
|
|
123
|
+
var opc = operationContext.fork(context_1.ContextType.CALL, context_1.ContextState.TEMPORARY);
|
|
124
|
+
var evaluate = function (node) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
var args, pathExpr, callable_1, callable, _a;
|
|
127
|
+
var _b, _c, _d;
|
|
128
|
+
return __generator(this, function (_e) {
|
|
129
|
+
switch (_e.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
if (node instanceof expression_1.Expression) {
|
|
132
|
+
return [2 /*return*/, node.get(opc)];
|
|
133
|
+
}
|
|
134
|
+
return [4 /*yield*/, node.resolveArgs(operationContext)];
|
|
135
|
+
case 1:
|
|
136
|
+
args = _e.sent();
|
|
137
|
+
return [4 /*yield*/, node.path.get(opc, me.expr)];
|
|
138
|
+
case 2:
|
|
139
|
+
pathExpr = _e.sent();
|
|
140
|
+
operationContext.debugger.debug('CallExpression', 'pathExpr', pathExpr);
|
|
141
|
+
if (!pathExpr.handle) return [3 /*break*/, 5];
|
|
142
|
+
if (!(0, typer_1.isCustomMap)(pathExpr.handle)) return [3 /*break*/, 4];
|
|
143
|
+
return [4 /*yield*/, pathExpr.handle.getCallable(pathExpr.path)];
|
|
144
|
+
case 3:
|
|
145
|
+
callable_1 = _e.sent();
|
|
146
|
+
if (callable_1.origin instanceof operation_1.Operation) {
|
|
147
|
+
opc.setMemory('args', args);
|
|
148
|
+
return [2 /*return*/, callable_1.origin.run(opc)];
|
|
149
|
+
}
|
|
150
|
+
else if (callable_1.origin instanceof Function) {
|
|
151
|
+
return [2 /*return*/, (_b = callable_1.origin).call.apply(_b, __spreadArray([pathExpr.handle], __read(args), false))];
|
|
152
|
+
}
|
|
153
|
+
operationContext.debugger.raise('Unexpected handle call', me, callable_1);
|
|
154
|
+
_e.label = 4;
|
|
155
|
+
case 4: return [2 /*return*/, (0, typer_1.cast)((_c = pathExpr.handle).callMethod.apply(_c, __spreadArray([pathExpr.path], __read(args), false)))];
|
|
156
|
+
case 5: return [4 /*yield*/, opc.getCallable(pathExpr.path)];
|
|
157
|
+
case 6:
|
|
158
|
+
callable = _e.sent();
|
|
159
|
+
opc.setMemory('args', args);
|
|
160
|
+
if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/, 7];
|
|
161
|
+
return [2 /*return*/, callable.origin.run(opc)];
|
|
162
|
+
case 7:
|
|
163
|
+
if (!(callable.origin instanceof Function)) return [3 /*break*/, 9];
|
|
164
|
+
_a = typer_1.cast;
|
|
165
|
+
return [4 /*yield*/, (_d = callable.origin).call.apply(_d, __spreadArray([callable.context], __read(args), false))];
|
|
166
|
+
case 8: return [2 /*return*/, _a.apply(void 0, [_e.sent()])];
|
|
167
|
+
case 9: return [2 /*return*/, (0, typer_1.cast)(callable.origin)];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
operationContext.debugger.debug('CallExpression', 'get', 'expr', me.expr);
|
|
173
|
+
return evaluate(me.expr);
|
|
174
|
+
};
|
|
175
|
+
return CallExpression;
|
|
176
|
+
}(expression_1.Expression));
|
|
177
|
+
exports.default = CallExpression;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ASTListConstructorExpression } from 'greybel-core';
|
|
2
|
+
import { Expression } from '../types/expression';
|
|
3
|
+
import CustomList from '../custom-types/list';
|
|
4
|
+
import { OperationContext } from '../context';
|
|
5
|
+
export declare class ExpressionSegment {
|
|
6
|
+
values: any[];
|
|
7
|
+
constructor(values: any[]);
|
|
8
|
+
}
|
|
9
|
+
export default class ListExpression extends Expression {
|
|
10
|
+
expr: ExpressionSegment;
|
|
11
|
+
constructor(ast: ASTListConstructorExpression, visit: Function);
|
|
12
|
+
get(operationContext: OperationContext, parentExpr: any): Promise<CustomList>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.ExpressionSegment = void 0;
|
|
58
|
+
var expression_1 = require("../types/expression");
|
|
59
|
+
var list_1 = __importDefault(require("../custom-types/list"));
|
|
60
|
+
var typer_1 = require("../typer");
|
|
61
|
+
var ExpressionSegment = /** @class */ (function () {
|
|
62
|
+
function ExpressionSegment(values) {
|
|
63
|
+
this.values = values;
|
|
64
|
+
}
|
|
65
|
+
return ExpressionSegment;
|
|
66
|
+
}());
|
|
67
|
+
exports.ExpressionSegment = ExpressionSegment;
|
|
68
|
+
var ListExpression = /** @class */ (function (_super) {
|
|
69
|
+
__extends(ListExpression, _super);
|
|
70
|
+
function ListExpression(ast, visit) {
|
|
71
|
+
var _this = _super.call(this) || this;
|
|
72
|
+
var me = _this;
|
|
73
|
+
var buildExpression = function (node) {
|
|
74
|
+
return new ExpressionSegment(node.fields.map(function (item) {
|
|
75
|
+
return visit(item.value);
|
|
76
|
+
}));
|
|
77
|
+
};
|
|
78
|
+
me.ast = ast;
|
|
79
|
+
me.expr = buildExpression(ast);
|
|
80
|
+
return _this;
|
|
81
|
+
}
|
|
82
|
+
ListExpression.prototype.get = function (operationContext, parentExpr) {
|
|
83
|
+
var me = this;
|
|
84
|
+
var evaluate = function (node) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
var traverselPath, list, current, _a, _b;
|
|
87
|
+
return __generator(this, function (_c) {
|
|
88
|
+
switch (_c.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
traverselPath = [].concat(node);
|
|
91
|
+
list = [];
|
|
92
|
+
_c.label = 1;
|
|
93
|
+
case 1:
|
|
94
|
+
if (!(current = traverselPath.shift())) return [3 /*break*/, 6];
|
|
95
|
+
if (!(0, typer_1.isCustomValue)(current)) return [3 /*break*/, 2];
|
|
96
|
+
list.push(current);
|
|
97
|
+
return [3 /*break*/, 5];
|
|
98
|
+
case 2:
|
|
99
|
+
if (!(current instanceof expression_1.Expression)) return [3 /*break*/, 4];
|
|
100
|
+
_b = (_a = list).push;
|
|
101
|
+
return [4 /*yield*/, current.get(operationContext)];
|
|
102
|
+
case 3:
|
|
103
|
+
_b.apply(_a, [_c.sent()]);
|
|
104
|
+
return [3 /*break*/, 5];
|
|
105
|
+
case 4:
|
|
106
|
+
operationContext.debugger.raise('Unexpected handle', me, current);
|
|
107
|
+
_c.label = 5;
|
|
108
|
+
case 5: return [3 /*break*/, 1];
|
|
109
|
+
case 6: return [2 /*return*/, new list_1.default(list)];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
operationContext.debugger.debug('ListExpression', 'get', 'expr', me.expr);
|
|
115
|
+
return evaluate(me.expr.values);
|
|
116
|
+
};
|
|
117
|
+
return ListExpression;
|
|
118
|
+
}(expression_1.Expression));
|
|
119
|
+
exports.default = ListExpression;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ASTEvaluationExpression } from 'greybel-core';
|
|
2
|
+
import { Expression } from '../types/expression';
|
|
3
|
+
import { OperationContext } from '../context';
|
|
4
|
+
import { CustomType } from '../types/custom-type';
|
|
5
|
+
export declare const toPrimitive: (v: CustomType | any) => any;
|
|
6
|
+
export declare const multiplyString: (a: CustomType, b: CustomType) => string;
|
|
7
|
+
export declare type OperationMap = {
|
|
8
|
+
[key: string]: (a: CustomType, b: CustomType) => any;
|
|
9
|
+
};
|
|
10
|
+
export declare const OPERATIONS: OperationMap;
|
|
11
|
+
export declare class ExpressionSegment {
|
|
12
|
+
type: string;
|
|
13
|
+
operator: string;
|
|
14
|
+
left: any;
|
|
15
|
+
right: any;
|
|
16
|
+
constructor(type: string, operator: string, left: any, right: any);
|
|
17
|
+
}
|
|
18
|
+
export default class LogicalAndBinaryExpression extends Expression {
|
|
19
|
+
expr: ExpressionSegment;
|
|
20
|
+
constructor(ast: ASTEvaluationExpression, visit: Function);
|
|
21
|
+
get(operationContext: OperationContext): Promise<any>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var _a;
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.ExpressionSegment = exports.OPERATIONS = exports.multiplyString = exports.toPrimitive = void 0;
|
|
56
|
+
var greybel_core_1 = require("greybel-core");
|
|
57
|
+
var greyscript_core_1 = require("greyscript-core");
|
|
58
|
+
var expression_1 = require("../types/expression");
|
|
59
|
+
var typer_1 = require("../typer");
|
|
60
|
+
var toPrimitive = function (v) {
|
|
61
|
+
return (0, typer_1.isCustomValue)(v) ? v.valueOf() : v;
|
|
62
|
+
};
|
|
63
|
+
exports.toPrimitive = toPrimitive;
|
|
64
|
+
var multiplyString = function (a, b) {
|
|
65
|
+
var aVal = a.valueOf() || '';
|
|
66
|
+
var bVal = b.valueOf();
|
|
67
|
+
return new Array(bVal)
|
|
68
|
+
.fill(aVal)
|
|
69
|
+
.join('');
|
|
70
|
+
};
|
|
71
|
+
exports.multiplyString = multiplyString;
|
|
72
|
+
exports.OPERATIONS = (_a = {},
|
|
73
|
+
_a[greybel_core_1.Operator.Plus] = function (a, b) {
|
|
74
|
+
if ((0, typer_1.isCustomList)(a) || (0, typer_1.isCustomList)(b)) {
|
|
75
|
+
return a.concat(b);
|
|
76
|
+
}
|
|
77
|
+
var aVal = (0, typer_1.isCustomString)(a) ? (a.valueOf() || '') : (0, exports.toPrimitive)(a);
|
|
78
|
+
var bVal = (0, typer_1.isCustomString)(b) ? (b.valueOf() || '') : (0, exports.toPrimitive)(b);
|
|
79
|
+
return aVal + bVal;
|
|
80
|
+
},
|
|
81
|
+
_a[greybel_core_1.Operator.Minus] = function (a, b) { return (0, exports.toPrimitive)(a) - (0, exports.toPrimitive)(b); },
|
|
82
|
+
_a[greybel_core_1.Operator.Slash] = function (a, b) { return (0, exports.toPrimitive)(a) / (0, exports.toPrimitive)(b); },
|
|
83
|
+
_a[greybel_core_1.Operator.Asterik] = function (a, b) {
|
|
84
|
+
if ((0, typer_1.isCustomString)(a) && (0, typer_1.isCustomNumber)(b)) {
|
|
85
|
+
return (0, exports.multiplyString)(a, b);
|
|
86
|
+
}
|
|
87
|
+
else if ((0, typer_1.isCustomString)(b) && (0, typer_1.isCustomNumber)(a)) {
|
|
88
|
+
return (0, exports.multiplyString)(b, a);
|
|
89
|
+
}
|
|
90
|
+
var aVal = (0, exports.toPrimitive)(a);
|
|
91
|
+
var bVal = (0, exports.toPrimitive)(b);
|
|
92
|
+
return aVal * bVal;
|
|
93
|
+
},
|
|
94
|
+
_a[greybel_core_1.Operator.Xor] = function (a, b) { return (0, exports.toPrimitive)(a) ^ (0, exports.toPrimitive)(b); },
|
|
95
|
+
_a[greybel_core_1.Operator.BitwiseOr] = function (a, b) { return (0, exports.toPrimitive)(a) | (0, exports.toPrimitive)(b); },
|
|
96
|
+
_a[greybel_core_1.Operator.LessThan] = function (a, b) { return (0, exports.toPrimitive)(a) < (0, exports.toPrimitive)(b); },
|
|
97
|
+
_a[greybel_core_1.Operator.GreaterThan] = function (a, b) { return (0, exports.toPrimitive)(a) > (0, exports.toPrimitive)(b); },
|
|
98
|
+
_a[greybel_core_1.Operator.LeftShift] = function (a, b) { return (0, exports.toPrimitive)(a) << (0, exports.toPrimitive)(b); },
|
|
99
|
+
_a[greybel_core_1.Operator.RightShift] = function (a, b) { return (0, exports.toPrimitive)(a) >> (0, exports.toPrimitive)(b); },
|
|
100
|
+
_a[greybel_core_1.Operator.UnsignedRightShift] = function (a, b) { return (0, exports.toPrimitive)(a) >>> (0, exports.toPrimitive)(b); },
|
|
101
|
+
_a[greybel_core_1.Operator.BitwiseAnd] = function (a, b) { return (0, exports.toPrimitive)(a) & (0, exports.toPrimitive)(b); },
|
|
102
|
+
_a[greybel_core_1.Operator.PercentSign] = function (a, b) { return (0, exports.toPrimitive)(a) % (0, exports.toPrimitive)(b); },
|
|
103
|
+
_a[greybel_core_1.Operator.GreaterThanOrEqual] = function (a, b) { return (0, exports.toPrimitive)(a) >= (0, exports.toPrimitive)(b); },
|
|
104
|
+
_a[greybel_core_1.Operator.Equal] = function (a, b) { return (0, exports.toPrimitive)(a) == (0, exports.toPrimitive)(b); },
|
|
105
|
+
_a[greybel_core_1.Operator.LessThanOrEqual] = function (a, b) { return (0, exports.toPrimitive)(a) <= (0, exports.toPrimitive)(b); },
|
|
106
|
+
_a[greybel_core_1.Operator.NotEqual] = function (a, b) { return (0, exports.toPrimitive)(a) != (0, exports.toPrimitive)(b); },
|
|
107
|
+
_a[greybel_core_1.Operator.And] = function (a, b) { return (0, exports.toPrimitive)(a) && (0, exports.toPrimitive)(b); },
|
|
108
|
+
_a[greybel_core_1.Operator.Or] = function (a, b) { return (0, exports.toPrimitive)(a) || (0, exports.toPrimitive)(b); },
|
|
109
|
+
_a);
|
|
110
|
+
var ExpressionSegment = /** @class */ (function () {
|
|
111
|
+
function ExpressionSegment(type, operator, left, right) {
|
|
112
|
+
var me = this;
|
|
113
|
+
me.type = type;
|
|
114
|
+
me.operator = operator;
|
|
115
|
+
me.left = left;
|
|
116
|
+
me.right = right;
|
|
117
|
+
}
|
|
118
|
+
return ExpressionSegment;
|
|
119
|
+
}());
|
|
120
|
+
exports.ExpressionSegment = ExpressionSegment;
|
|
121
|
+
var LogicalAndBinaryExpression = /** @class */ (function (_super) {
|
|
122
|
+
__extends(LogicalAndBinaryExpression, _super);
|
|
123
|
+
function LogicalAndBinaryExpression(ast, visit) {
|
|
124
|
+
var _this = _super.call(this) || this;
|
|
125
|
+
var me = _this;
|
|
126
|
+
var buildExpression = function (node) {
|
|
127
|
+
return new ExpressionSegment(node.type, node.operator, visit(node.left), visit(node.right));
|
|
128
|
+
};
|
|
129
|
+
me.ast = ast;
|
|
130
|
+
me.expr = buildExpression(ast);
|
|
131
|
+
return _this;
|
|
132
|
+
}
|
|
133
|
+
LogicalAndBinaryExpression.prototype.get = function (operationContext) {
|
|
134
|
+
var _this = this;
|
|
135
|
+
var me = this;
|
|
136
|
+
var resolve = function (value) {
|
|
137
|
+
if ((0, typer_1.isCustomValue)(value)) {
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
return value.get(operationContext);
|
|
141
|
+
};
|
|
142
|
+
var evaluate = function (node) { return __awaiter(_this, void 0, void 0, function () {
|
|
143
|
+
var left, right, _a;
|
|
144
|
+
return __generator(this, function (_b) {
|
|
145
|
+
switch (_b.label) {
|
|
146
|
+
case 0:
|
|
147
|
+
_a = node.type;
|
|
148
|
+
switch (_a) {
|
|
149
|
+
case greyscript_core_1.ASTType.BinaryExpression: return [3 /*break*/, 1];
|
|
150
|
+
case greyscript_core_1.ASTType.LogicalExpression: return [3 /*break*/, 4];
|
|
151
|
+
}
|
|
152
|
+
return [3 /*break*/, 7];
|
|
153
|
+
case 1: return [4 /*yield*/, resolve(node.left)];
|
|
154
|
+
case 2:
|
|
155
|
+
left = _b.sent();
|
|
156
|
+
return [4 /*yield*/, resolve(node.right)];
|
|
157
|
+
case 3:
|
|
158
|
+
right = _b.sent();
|
|
159
|
+
return [2 /*return*/, (0, typer_1.cast)(exports.OPERATIONS[node.operator](left, right))];
|
|
160
|
+
case 4: return [4 /*yield*/, resolve(node.left)];
|
|
161
|
+
case 5:
|
|
162
|
+
left = _b.sent();
|
|
163
|
+
if ((0, typer_1.isCustomList)(left) && !left.valueOf()) {
|
|
164
|
+
left = false;
|
|
165
|
+
}
|
|
166
|
+
if (node.operator === greybel_core_1.Operator.And && !(0, exports.toPrimitive)(left)) {
|
|
167
|
+
return [2 /*return*/, false];
|
|
168
|
+
}
|
|
169
|
+
else if (node.operator === greybel_core_1.Operator.Or && (0, exports.toPrimitive)(left)) {
|
|
170
|
+
return [2 /*return*/, true];
|
|
171
|
+
}
|
|
172
|
+
return [4 /*yield*/, resolve(node.right)];
|
|
173
|
+
case 6:
|
|
174
|
+
right = _b.sent();
|
|
175
|
+
return [2 /*return*/, exports.OPERATIONS[node.operator](left, right)];
|
|
176
|
+
case 7:
|
|
177
|
+
operationContext.debugger.raise('Unexpected expression type', me, node);
|
|
178
|
+
_b.label = 8;
|
|
179
|
+
case 8: return [2 /*return*/];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}); };
|
|
183
|
+
operationContext.debugger.debug('LogicalAndBinaryExpression', 'get', 'expr', me.expr);
|
|
184
|
+
return evaluate(me.expr);
|
|
185
|
+
};
|
|
186
|
+
return LogicalAndBinaryExpression;
|
|
187
|
+
}(expression_1.Expression));
|
|
188
|
+
exports.default = LogicalAndBinaryExpression;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ASTMapConstructorExpression } from 'greybel-core';
|
|
2
|
+
import { Expression } from '../types/expression';
|
|
3
|
+
import CustomMap from '../custom-types/map';
|
|
4
|
+
import { OperationContext } from '../context';
|
|
5
|
+
export declare class ValuesSegment {
|
|
6
|
+
key: any;
|
|
7
|
+
value: any;
|
|
8
|
+
constructor(key: any, value: any);
|
|
9
|
+
}
|
|
10
|
+
export declare class ExpressionSegment {
|
|
11
|
+
values: ValuesSegment[];
|
|
12
|
+
constructor(values: ValuesSegment[]);
|
|
13
|
+
}
|
|
14
|
+
export default class MapExpression extends Expression {
|
|
15
|
+
expr: ExpressionSegment;
|
|
16
|
+
constructor(ast: ASTMapConstructorExpression, visit: Function);
|
|
17
|
+
get(operationContext: OperationContext, parentExpr: any): Promise<CustomMap>;
|
|
18
|
+
}
|