greybel-interpreter 0.6.3 → 0.6.7

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 CHANGED
@@ -1,4 +1,6 @@
1
1
  import CustomMap from './custom-types/map';
2
+ import { Operation } from './types/operation';
3
+ import { Expression } from './types/expression';
2
4
  import { Callable } from './types/custom-type';
3
5
  import { ASTBase } from 'greybel-core';
4
6
  import CPS from './cps';
@@ -32,7 +34,7 @@ export declare class Debugger {
32
34
  getBreakpoint(operationContext: OperationContext): boolean;
33
35
  next(): Debugger;
34
36
  resume(): Promise<void>;
35
- interact(operationContext: OperationContext, item: ASTBase): void;
37
+ interact(operationContext: OperationContext, item: ASTBase, entity: Operation | Expression): void;
36
38
  }
37
39
  export interface OperationContextProcessState {
38
40
  exit: boolean;
@@ -73,7 +75,7 @@ export declare class OperationContext {
73
75
  locals: OperationContext | null;
74
76
  globals: OperationContext | null;
75
77
  constructor(options: OperationContextOptions);
76
- step(item: ASTBase): Promise<void>;
78
+ step(entity: Operation | Expression): Promise<void>;
77
79
  setLastActive(opc: OperationContext): OperationContext;
78
80
  getLastActive(): OperationContext | null;
79
81
  isExit(): boolean;
package/dist/context.js CHANGED
@@ -238,7 +238,7 @@ var Debugger = /** @class */ (function () {
238
238
  setTimeout(check, 10);
239
239
  });
240
240
  };
241
- Debugger.prototype.interact = function (operationContext, item) {
241
+ Debugger.prototype.interact = function (operationContext, item, entity) {
242
242
  var me = this;
243
243
  console.warn("Debugger is not setup.");
244
244
  console.info(operationContext);
@@ -270,14 +270,15 @@ var OperationContext = /** @class */ (function () {
270
270
  me.globals = me.lookupGlobals();
271
271
  me.locals = me.lookupLocals() || me;
272
272
  }
273
- OperationContext.prototype.step = function (item) {
273
+ OperationContext.prototype.step = function (entity) {
274
274
  var me = this;
275
275
  var dbgr = me.debugger;
276
276
  if (!me.injected) {
277
- me.stackItem = item;
277
+ me.stackItem = entity.ast;
278
+ me.target = entity.target || me.target;
278
279
  me.setLastActive(me);
279
280
  if (dbgr.getBreakpoint(me)) {
280
- dbgr.interact(me, item);
281
+ dbgr.interact(me, entity.ast, entity);
281
282
  return dbgr.resume();
282
283
  }
283
284
  }
package/dist/cps.d.ts CHANGED
@@ -6,10 +6,12 @@ export interface CPSMapType {
6
6
  export interface CPSMapContext {
7
7
  target: string;
8
8
  resourceHandler: ResourceHandler;
9
+ currentTarget?: string;
9
10
  }
10
11
  export declare const CPSMap: (visit: (o: ASTBase) => any, context: CPSMapContext) => CPSMapType;
11
12
  export default class CPS {
12
13
  cpsMap: CPSMapType;
14
+ context: CPSMapContext;
13
15
  constructor(context: CPSMapContext);
14
16
  visit(o: ASTBase): Promise<any>;
15
17
  }
package/dist/cps.js CHANGED
@@ -80,6 +80,8 @@ var boolean_1 = __importDefault(require("./custom-types/boolean"));
80
80
  var number_1 = __importDefault(require("./custom-types/number"));
81
81
  var string_1 = __importDefault(require("./custom-types/string"));
82
82
  var nil_1 = __importDefault(require("./custom-types/nil"));
83
+ var expression_1 = require("./types/expression");
84
+ var operation_1 = require("./types/operation");
83
85
  var CPSMap = function (visit, context) {
84
86
  return {
85
87
  'AssignmentStatement': function (item) {
@@ -669,7 +671,7 @@ var CPSMap = function (visit, context) {
669
671
  },
670
672
  'FeatureImportExpression': function (item) {
671
673
  return __awaiter(this, void 0, void 0, function () {
672
- var resourceHandler, target, code;
674
+ var resourceHandler, target, code, chunk;
673
675
  return __generator(this, function (_a) {
674
676
  switch (_a.label) {
675
677
  case 0:
@@ -682,14 +684,19 @@ var CPSMap = function (visit, context) {
682
684
  return [4 /*yield*/, context.resourceHandler.get(target)];
683
685
  case 2:
684
686
  code = _a.sent();
685
- return [2 /*return*/, new import_1.default(item, target, code).prepare(visit)];
687
+ context.currentTarget = target;
688
+ return [4 /*yield*/, (new import_1.default(item, target, code).prepare(visit))];
689
+ case 3:
690
+ chunk = _a.sent();
691
+ context.currentTarget = context.target;
692
+ return [2 /*return*/, chunk];
686
693
  }
687
694
  });
688
695
  });
689
696
  },
690
697
  'FeatureIncludeExpression': function (item) {
691
698
  return __awaiter(this, void 0, void 0, function () {
692
- var resourceHandler, target, code;
699
+ var resourceHandler, target, code, chunk;
693
700
  return __generator(this, function (_a) {
694
701
  switch (_a.label) {
695
702
  case 0:
@@ -702,14 +709,19 @@ var CPSMap = function (visit, context) {
702
709
  return [4 /*yield*/, context.resourceHandler.get(target)];
703
710
  case 2:
704
711
  code = _a.sent();
705
- return [2 /*return*/, new include_1.default(item, target, code).prepare(visit)];
712
+ context.currentTarget = target;
713
+ return [4 /*yield*/, (new include_1.default(item, target, code).prepare(visit))];
714
+ case 3:
715
+ chunk = _a.sent();
716
+ context.currentTarget = context.target;
717
+ return [2 /*return*/, chunk];
706
718
  }
707
719
  });
708
720
  });
709
721
  },
710
722
  'ImportCodeExpression': function (item) {
711
723
  return __awaiter(this, void 0, void 0, function () {
712
- var resourceHandler, target, code;
724
+ var resourceHandler, target, code, chunk;
713
725
  return __generator(this, function (_a) {
714
726
  switch (_a.label) {
715
727
  case 0:
@@ -722,7 +734,12 @@ var CPSMap = function (visit, context) {
722
734
  return [4 /*yield*/, context.resourceHandler.get(target)];
723
735
  case 2:
724
736
  code = _a.sent();
725
- return [2 /*return*/, new include_1.default(item, target, code).prepare(visit)];
737
+ context.currentTarget = target;
738
+ return [4 /*yield*/, (new include_1.default(item, target, code).prepare(visit))];
739
+ case 3:
740
+ chunk = _a.sent();
741
+ context.currentTarget = context.target;
742
+ return [2 /*return*/, chunk];
726
743
  }
727
744
  });
728
745
  });
@@ -817,6 +834,8 @@ var CPS = /** @class */ (function () {
817
834
  function CPS(context) {
818
835
  var me = this;
819
836
  me.cpsMap = (0, exports.CPSMap)(me.visit.bind(me), context);
837
+ me.context = context;
838
+ context.currentTarget = context.target;
820
839
  }
821
840
  CPS.prototype.visit = function (o) {
822
841
  return __awaiter(this, void 0, void 0, function () {
@@ -839,6 +858,9 @@ var CPS = /** @class */ (function () {
839
858
  return [4 /*yield*/, fn.call(me, o)];
840
859
  case 1:
841
860
  result = _a.sent();
861
+ if (result instanceof operation_1.Operation || result instanceof expression_1.Expression) {
862
+ result.target = me.context.currentTarget;
863
+ }
842
864
  return [2 /*return*/, result];
843
865
  }
844
866
  });
@@ -96,7 +96,7 @@ var CustomList = /** @class */ (function (_super) {
96
96
  function CustomList(value) {
97
97
  var _this = _super.call(this) || this;
98
98
  _this.slice = function (a, b) {
99
- return new CustomList(this.value.slice(a.toNumber(), b.toNumber()));
99
+ return new CustomList(this.value.slice(a === null || a === void 0 ? void 0 : a.toNumber(), b === null || b === void 0 ? void 0 : b.toNumber()));
100
100
  };
101
101
  _this.value = value;
102
102
  return _this;
@@ -100,7 +100,7 @@ var BodyOperation = /** @class */ (function (_super) {
100
100
  case 2:
101
101
  if (!!_b.done) return [3 /*break*/, 9];
102
102
  entity = _b.value;
103
- return [4 /*yield*/, operationContext.step(entity.ast)];
103
+ return [4 /*yield*/, operationContext.step(entity)];
104
104
  case 3:
105
105
  _d.sent();
106
106
  if (!(entity instanceof expression_1.Expression)) return [3 /*break*/, 5];
@@ -2,5 +2,6 @@ import { OperationContext } from '../context';
2
2
  export declare abstract class Expression {
3
3
  ast: any;
4
4
  expr: any;
5
+ target?: string;
5
6
  abstract get(operationContext: OperationContext, parentExpr?: any): any;
6
7
  }
@@ -1,6 +1,7 @@
1
1
  import { OperationContext } from '../context';
2
2
  export declare abstract class Operation {
3
3
  ast: any;
4
+ target?: string;
4
5
  get(operationContext: OperationContext): any;
5
6
  run(operationContext: OperationContext): any | void;
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "0.6.3",
3
+ "version": "0.6.7",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",
@@ -34,8 +34,8 @@
34
34
  "typescript": "^4.5.4"
35
35
  },
36
36
  "dependencies": {
37
- "greybel-core": "^0.2.4",
38
- "greyscript-core": "^0.2.5",
37
+ "greybel-core": "^0.2.5",
38
+ "greyscript-core": "^0.2.6",
39
39
  "uuid": "^8.3.2"
40
40
  },
41
41
  "keywords": [