greybel-interpreter 0.4.0 → 0.4.4

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
@@ -6,7 +6,6 @@ export declare enum ContextType {
6
6
  API = "API",
7
7
  GLOBAL = "GLOBAL",
8
8
  FUNCTION = "FUNCTION",
9
- INJECTION = "INJECTION",
10
9
  EXTERNAL = "EXTERNAL",
11
10
  LOOP = "LOOP",
12
11
  MAP = "MAP",
@@ -44,6 +43,7 @@ export interface OperationContextProcessState {
44
43
  export interface OperationContextOptions {
45
44
  target?: string;
46
45
  isProtected?: boolean;
46
+ injected?: boolean;
47
47
  type?: ContextType;
48
48
  state?: ContextState;
49
49
  previous?: OperationContext;
@@ -55,6 +55,7 @@ export interface OperationContextForkOptions {
55
55
  type: ContextType;
56
56
  state: ContextState;
57
57
  target?: string;
58
+ injected?: boolean;
58
59
  }
59
60
  export declare class OperationContext {
60
61
  target: string;
@@ -64,10 +65,11 @@ export declare class OperationContext {
64
65
  type: ContextType;
65
66
  state: ContextState;
66
67
  scope: Scope;
67
- isProtected: boolean;
68
68
  memory: Map<string, any>;
69
69
  cps: CPS | null;
70
70
  processState: OperationContextProcessState;
71
+ isProtected: boolean;
72
+ injected: boolean;
71
73
  api: Scope | null;
72
74
  locals: Scope | null;
73
75
  globals: Scope | null;
@@ -90,5 +92,5 @@ export declare class OperationContext {
90
92
  getCallable(path: string[]): Promise<Callable>;
91
93
  setMemory(key: string, value: any): OperationContext;
92
94
  getMemory(key: string): any;
93
- fork({ type, state, target }: OperationContextForkOptions): OperationContext;
95
+ fork({ type, state, target, injected }: OperationContextForkOptions): OperationContext;
94
96
  }
package/dist/context.js CHANGED
@@ -50,7 +50,6 @@ var ContextType;
50
50
  ContextType["API"] = "API";
51
51
  ContextType["GLOBAL"] = "GLOBAL";
52
52
  ContextType["FUNCTION"] = "FUNCTION";
53
- ContextType["INJECTION"] = "INJECTION";
54
53
  ContextType["EXTERNAL"] = "EXTERNAL";
55
54
  ContextType["LOOP"] = "LOOP";
56
55
  ContextType["MAP"] = "MAP";
@@ -181,7 +180,7 @@ var Debugger = /** @class */ (function () {
181
180
  return me;
182
181
  };
183
182
  Debugger.prototype.getBreakpoint = function (operationContext) {
184
- return operationContext.type !== ContextType.INJECTION && this.breakpoint;
183
+ return this.breakpoint;
185
184
  };
186
185
  Debugger.prototype.next = function () {
187
186
  var me = this;
@@ -228,6 +227,7 @@ var OperationContext = /** @class */ (function () {
228
227
  me.state = options.state || ContextState.DEFAULT;
229
228
  me.scope = new Scope(me);
230
229
  me.isProtected = options.isProtected || false;
230
+ me.injected = options.injected || false;
231
231
  me.memory = new Map();
232
232
  me.debugger = options.debugger || new Debugger();
233
233
  me.cps = options.cps;
@@ -243,17 +243,19 @@ var OperationContext = /** @class */ (function () {
243
243
  OperationContext.prototype.step = function (item) {
244
244
  var me = this;
245
245
  var dbgr = me.debugger;
246
- me.stackItem = item;
247
- me.setLastActive(me);
248
- if (dbgr.getBreakpoint(me)) {
249
- dbgr.interact(me, item);
250
- return dbgr.resume();
246
+ if (!me.injected) {
247
+ me.stackItem = item;
248
+ me.setLastActive(me);
249
+ if (dbgr.getBreakpoint(me)) {
250
+ dbgr.interact(me, item);
251
+ return dbgr.resume();
252
+ }
251
253
  }
252
254
  return Promise.resolve();
253
255
  };
254
256
  OperationContext.prototype.setLastActive = function (opc) {
255
257
  var me = this;
256
- if (opc.type !== ContextType.INJECTION) {
258
+ if (!opc.injected) {
257
259
  me.processState.last = opc;
258
260
  }
259
261
  return me;
@@ -361,7 +363,7 @@ var OperationContext = /** @class */ (function () {
361
363
  return me.memory.get(key);
362
364
  };
363
365
  OperationContext.prototype.fork = function (_a) {
364
- var type = _a.type, state = _a.state, target = _a.target;
366
+ var type = _a.type, state = _a.state, target = _a.target, injected = _a.injected;
365
367
  var me = this;
366
368
  var opc = new OperationContext({
367
369
  target: target || me.target,
@@ -370,7 +372,8 @@ var OperationContext = /** @class */ (function () {
370
372
  state: state,
371
373
  debugger: me.debugger,
372
374
  cps: me.cps,
373
- processState: me.processState
375
+ processState: me.processState,
376
+ injected: injected || me.injected
374
377
  });
375
378
  if (type !== ContextType.FUNCTION) {
376
379
  if (type !== ContextType.LOOP) {
@@ -115,10 +115,11 @@ var Interpreter = /** @class */ (function (_super) {
115
115
  case 2:
116
116
  body = _a.sent();
117
117
  injectionCtx = (context || me.globalContext).fork({
118
- type: context_1.ContextType.INJECTION,
119
- state: context_1.ContextState.TEMPORARY
118
+ type: context_1.ContextType.CALL,
119
+ state: context_1.ContextState.TEMPORARY,
120
+ injected: true
120
121
  });
121
- return [4 /*yield*/, body.run(context)];
122
+ return [4 /*yield*/, body.run(injectionCtx)];
122
123
  case 3:
123
124
  _a.sent();
124
125
  return [3 /*break*/, 5];
@@ -138,7 +139,7 @@ var Interpreter = /** @class */ (function (_super) {
138
139
  me = this;
139
140
  last = me.apiContext.getLastActive();
140
141
  if (me.apiContext.isPending()) {
141
- me.inject(code, last);
142
+ return [2 /*return*/, me.inject(code, last)];
142
143
  }
143
144
  return [2 /*return*/, me];
144
145
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "0.4.0",
3
+ "version": "0.4.4",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",