greybel-interpreter 0.5.7 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.d.ts +9 -9
- package/dist/context.js +156 -102
- package/dist/custom-types/boolean.d.ts +2 -1
- package/dist/custom-types/boolean.js +6 -3
- package/dist/custom-types/list.d.ts +3 -3
- package/dist/custom-types/list.js +17 -67
- package/dist/custom-types/map.d.ts +3 -2
- package/dist/custom-types/map.js +45 -41
- package/dist/custom-types/nil.d.ts +2 -1
- package/dist/custom-types/nil.js +5 -2
- package/dist/custom-types/number.d.ts +2 -1
- package/dist/custom-types/number.js +6 -3
- package/dist/custom-types/string.d.ts +6 -3
- package/dist/custom-types/string.js +96 -58
- package/dist/expressions/binary-negated-expression.d.ts +0 -1
- package/dist/expressions/binary-negated-expression.js +3 -7
- package/dist/expressions/call.js +22 -21
- package/dist/expressions/logical-and-binary.d.ts +0 -1
- package/dist/expressions/logical-and-binary.js +43 -46
- package/dist/expressions/map.js +20 -13
- package/dist/expressions/path.js +27 -22
- package/dist/operations/argument.js +15 -15
- package/dist/operations/function.d.ts +2 -0
- package/dist/operations/function.js +6 -0
- package/dist/operations/if-statement.js +73 -39
- package/dist/operations/not.js +2 -2
- package/dist/operations/return.js +5 -1
- package/dist/operations/while.js +20 -11
- package/dist/types/custom-type.d.ts +3 -1
- package/dist/types/custom-type.js +8 -2
- package/package.json +1 -1
|
@@ -50,10 +50,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
50
50
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
53
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
57
|
var operation_1 = require("../types/operation");
|
|
55
58
|
var expression_1 = require("../types/expression");
|
|
56
59
|
var typer_1 = require("../typer");
|
|
60
|
+
var nil_1 = __importDefault(require("../custom-types/nil"));
|
|
57
61
|
var ReturnOperation = /** @class */ (function (_super) {
|
|
58
62
|
__extends(ReturnOperation, _super);
|
|
59
63
|
function ReturnOperation(ast, options) {
|
|
@@ -87,7 +91,7 @@ var ReturnOperation = /** @class */ (function (_super) {
|
|
|
87
91
|
arg = _a.sent();
|
|
88
92
|
return [3 /*break*/, 6];
|
|
89
93
|
case 5:
|
|
90
|
-
|
|
94
|
+
arg = new nil_1.default();
|
|
91
95
|
_a.label = 6;
|
|
92
96
|
case 6:
|
|
93
97
|
functionContext.value = arg;
|
package/dist/operations/while.js
CHANGED
|
@@ -80,24 +80,33 @@ var WhileOperation = /** @class */ (function (_super) {
|
|
|
80
80
|
isBreak: false,
|
|
81
81
|
isContinue: false
|
|
82
82
|
};
|
|
83
|
-
resolveCondition = function () {
|
|
83
|
+
resolveCondition = function (item) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
var value;
|
|
85
|
+
var value, value;
|
|
86
86
|
return __generator(this, function (_a) {
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0:
|
|
89
|
-
if (!(
|
|
90
|
-
return [4 /*yield*/,
|
|
89
|
+
if (!(item instanceof expression_1.Expression)) return [3 /*break*/, 2];
|
|
90
|
+
return [4 /*yield*/, item.get(opc)];
|
|
91
91
|
case 1:
|
|
92
92
|
value = _a.sent();
|
|
93
|
-
return [2 /*return*/, value
|
|
93
|
+
return [2 /*return*/, resolveCondition(value)];
|
|
94
94
|
case 2:
|
|
95
|
-
if ((
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
_a.label = 3;
|
|
95
|
+
if (!(item instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
96
|
+
return [4 /*yield*/, item.get(opc)];
|
|
99
97
|
case 3:
|
|
100
|
-
|
|
98
|
+
value = _a.sent();
|
|
99
|
+
return [2 /*return*/, resolveCondition(value)];
|
|
100
|
+
case 4:
|
|
101
|
+
if ((0, typer_1.isCustomValue)(item)) {
|
|
102
|
+
return [2 /*return*/, item.toTruthy()];
|
|
103
|
+
}
|
|
104
|
+
else if (typeof item === 'boolean') {
|
|
105
|
+
return [2 /*return*/, item];
|
|
106
|
+
}
|
|
107
|
+
_a.label = 5;
|
|
108
|
+
case 5:
|
|
109
|
+
operationContext.debugger.raise('Unexpected condition', me, item);
|
|
101
110
|
return [2 /*return*/];
|
|
102
111
|
}
|
|
103
112
|
});
|
|
@@ -105,7 +114,7 @@ var WhileOperation = /** @class */ (function (_super) {
|
|
|
105
114
|
};
|
|
106
115
|
opc.setMemory('loopContext', loopContext);
|
|
107
116
|
_a.label = 1;
|
|
108
|
-
case 1: return [4 /*yield*/, resolveCondition()];
|
|
117
|
+
case 1: return [4 /*yield*/, resolveCondition(me.condition)];
|
|
109
118
|
case 2:
|
|
110
119
|
if (!_a.sent()) return [3 /*break*/, 4];
|
|
111
120
|
loopContext.isContinue = false;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export declare abstract class CustomType {
|
|
2
2
|
static intrinsics: Map<string, Function>;
|
|
3
3
|
getType(): string;
|
|
4
|
-
|
|
4
|
+
toNumber(): number;
|
|
5
5
|
toString(): string;
|
|
6
|
+
toTruthy(): boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare abstract class CustomLiteralType extends CustomType {
|
|
8
9
|
value: any;
|
|
9
10
|
}
|
|
10
11
|
export declare abstract class CustomObjectType extends CustomType {
|
|
11
12
|
value: any;
|
|
13
|
+
has(path: any[]): Promise<boolean>;
|
|
12
14
|
set(path: any[], value: any): Promise<void>;
|
|
13
15
|
get(path: any[]): Promise<any>;
|
|
14
16
|
getCallable(path: any[]): Promise<Callable>;
|
|
@@ -22,12 +22,15 @@ var CustomType = /** @class */ (function () {
|
|
|
22
22
|
CustomType.prototype.getType = function () {
|
|
23
23
|
throw new Error('Implentation of "getType" missing');
|
|
24
24
|
};
|
|
25
|
-
CustomType.prototype.
|
|
26
|
-
throw new Error('Implentation of "
|
|
25
|
+
CustomType.prototype.toNumber = function () {
|
|
26
|
+
throw new Error('Implentation of "toNumber" missing');
|
|
27
27
|
};
|
|
28
28
|
CustomType.prototype.toString = function () {
|
|
29
29
|
throw new Error('Implentation of "toString" missing');
|
|
30
30
|
};
|
|
31
|
+
CustomType.prototype.toTruthy = function () {
|
|
32
|
+
throw new Error('Implentation of "toTruthy" missing');
|
|
33
|
+
};
|
|
31
34
|
return CustomType;
|
|
32
35
|
}());
|
|
33
36
|
exports.CustomType = CustomType;
|
|
@@ -44,6 +47,9 @@ var CustomObjectType = /** @class */ (function (_super) {
|
|
|
44
47
|
function CustomObjectType() {
|
|
45
48
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
46
49
|
}
|
|
50
|
+
CustomObjectType.prototype.has = function (path) {
|
|
51
|
+
throw new Error('Implentation of "has" missing');
|
|
52
|
+
};
|
|
47
53
|
CustomObjectType.prototype.set = function (path, value) {
|
|
48
54
|
throw new Error('Implentation of "set" missing');
|
|
49
55
|
};
|