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.
@@ -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
- operationContext.debugger.raise('Unexpected return value', me, me.arg);
94
+ arg = new nil_1.default();
91
95
  _a.label = 6;
92
96
  case 6:
93
97
  functionContext.value = arg;
@@ -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 (!(me.condition instanceof expression_1.Expression)) return [3 /*break*/, 2];
90
- return [4 /*yield*/, me.condition.get(opc)];
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.valueOf()];
93
+ return [2 /*return*/, resolveCondition(value)];
94
94
  case 2:
95
- if ((0, typer_1.isCustomValue)(me.condition)) {
96
- return [2 /*return*/, me.condition.valueOf()];
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
- operationContext.debugger.raise('Unexpected condition', me, me.condition);
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
- valueOf(): any;
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.valueOf = function () {
26
- throw new Error('Implentation of "valueOf" missing');
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "0.5.7",
3
+ "version": "0.6.1",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",