greybel-interpreter 0.1.5 → 0.1.6

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
@@ -39,6 +39,9 @@ export declare class Debugger {
39
39
  interact(operationContext: OperationContext, item: Operation | Expression): void;
40
40
  run(code: string): Promise<void>;
41
41
  }
42
+ export interface OperationContextProcessState {
43
+ exit: boolean;
44
+ }
42
45
  export interface OperationContextOptions {
43
46
  isProtected?: boolean;
44
47
  type?: string;
@@ -46,6 +49,7 @@ export interface OperationContextOptions {
46
49
  previous?: OperationContext;
47
50
  debugger?: Debugger;
48
51
  cps?: CPS;
52
+ processState?: OperationContextProcessState;
49
53
  }
50
54
  export declare class OperationContext {
51
55
  debugger: Debugger;
@@ -56,6 +60,7 @@ export declare class OperationContext {
56
60
  isProtected: boolean;
57
61
  memory: Map<string, any>;
58
62
  cps: CPS | null;
63
+ processState: OperationContextProcessState;
59
64
  constructor(options: OperationContextOptions);
60
65
  valueOf(): Map<string, any>;
61
66
  extend(map: Map<string, any>): OperationContext;
package/dist/context.js CHANGED
@@ -312,6 +312,9 @@ var OperationContext = /** @class */ (function () {
312
312
  me.memory = new Map();
313
313
  me.debugger = options.debugger || new Debugger();
314
314
  me.cps = options.cps;
315
+ me.processState = options.processState || {
316
+ exit: false
317
+ };
315
318
  }
316
319
  OperationContext.prototype.valueOf = function () {
317
320
  return this.scope.valueOf();
@@ -381,7 +384,8 @@ var OperationContext = /** @class */ (function () {
381
384
  type: type,
382
385
  state: state,
383
386
  debugger: me.debugger,
384
- cps: me.cps
387
+ cps: me.cps,
388
+ processState: me.processState
385
389
  });
386
390
  if (me.type === ContextType.FUNCTION || me.type === ContextType.GLOBAL) {
387
391
  opc.scope.refs.set('locals', opc.scope);
@@ -1,4 +1,4 @@
1
- import { Debugger } from './context';
1
+ import { OperationContext, Debugger } from './context';
2
2
  import { ResourceHandler } from './resource';
3
3
  export interface InterpreterOptions {
4
4
  target?: string;
@@ -15,6 +15,8 @@ export default class Interpreter {
15
15
  params: any[];
16
16
  resourceHandler: ResourceHandler;
17
17
  debugger: Debugger;
18
+ context: OperationContext | null;
18
19
  constructor(options: InterpreterOptions);
19
20
  digest(): Promise<any>;
21
+ exit(): void;
20
22
  }
@@ -17,6 +17,7 @@ var Interpreter = /** @class */ (function () {
17
17
  me.debugger = options.debugger || new context_1.Debugger();
18
18
  me.api = options.api || new Map();
19
19
  me.params = options.params || [];
20
+ me.context = null;
20
21
  if (options.target) {
21
22
  me.target = options.target;
22
23
  me.code = me.resourceHandler.get(options.target);
@@ -44,12 +45,20 @@ var Interpreter = /** @class */ (function () {
44
45
  });
45
46
  mainContext.extend(me.api);
46
47
  mainContext.scope.refs.set('params', (0, typer_1.cast)(me.params));
48
+ me.context = mainContext;
47
49
  return topOperation.run(mainContext)
48
50
  .catch(function (err) {
49
51
  console.error(err);
50
52
  throw err;
51
53
  });
52
54
  };
55
+ Interpreter.prototype.exit = function () {
56
+ var me = this;
57
+ if (me.context == null) {
58
+ throw new Error('Unexpected exit signal.');
59
+ }
60
+ me.context.processState.exit = true;
61
+ };
53
62
  return Interpreter;
54
63
  }());
55
64
  exports.default = Interpreter;
@@ -117,7 +117,7 @@ var BodyOperation = /** @class */ (function (_super) {
117
117
  _d.sent();
118
118
  _d.label = 8;
119
119
  case 8:
120
- if (isEOL())
120
+ if (isEOL() || operationContext.processState.exit)
121
121
  return [3 /*break*/, 10];
122
122
  _d.label = 9;
123
123
  case 9:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",