greybel-interpreter 4.0.15 → 4.0.16

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.
@@ -26,7 +26,7 @@ export declare class BytecodeGenerator {
26
26
  parse(code: string): ASTBase | import("greybel-core").ASTChunkAdvanced;
27
27
  compile(code: string): Promise<BytecodeCompileResult>;
28
28
  protected getCurrentPointer(): number;
29
- protected getSourceLocation(node: ASTBase): SourceLocation;
29
+ protected getSourceLocation(node: ASTBase, name?: string): SourceLocation;
30
30
  protected getInternalLocation(): SourceLocation;
31
31
  protected pushContext(): void;
32
32
  protected popContext(): BytecodeGeneratorContext;
@@ -72,10 +72,10 @@ class BytecodeGenerator {
72
72
  getCurrentPointer() {
73
73
  return this.context.peek().code.length - 1;
74
74
  }
75
- getSourceLocation(node) {
75
+ getSourceLocation(node, name) {
76
76
  const target = this.target.peek();
77
77
  return {
78
- name: node.type,
78
+ name: name !== null && name !== void 0 ? name : node.type,
79
79
  path: target,
80
80
  start: node.start,
81
81
  end: node.end
@@ -375,7 +375,7 @@ class BytecodeGenerator {
375
375
  yield this.processSubNode(node.index);
376
376
  this.push({
377
377
  op: instruction_1.OpCode.GET_SUPER_PROPERTY,
378
- source: this.getSourceLocation(node.index),
378
+ source: this.getSourceLocation(node.index, node.type),
379
379
  invoke: isInvoke
380
380
  });
381
381
  }
@@ -384,7 +384,7 @@ class BytecodeGenerator {
384
384
  yield this.processSubNode(node.index);
385
385
  this.push({
386
386
  op: instruction_1.OpCode.GET_PROPERTY,
387
- source: this.getSourceLocation(node.index),
387
+ source: this.getSourceLocation(node.index, node.type),
388
388
  invoke: isInvoke
389
389
  });
390
390
  }
@@ -898,7 +898,7 @@ class BytecodeGenerator {
898
898
  yield pushArgs();
899
899
  this.push({
900
900
  op: instruction_1.OpCode.CALL_SUPER_PROPERTY,
901
- source: this.getSourceLocation(node.base),
901
+ source: this.getSourceLocation(node.base, node.type),
902
902
  length: node.arguments.length
903
903
  });
904
904
  }
@@ -912,7 +912,7 @@ class BytecodeGenerator {
912
912
  yield pushArgs();
913
913
  this.push({
914
914
  op: instruction_1.OpCode.CALL_WITH_CONTEXT,
915
- source: this.getSourceLocation(left.identifier),
915
+ source: this.getSourceLocation(left.identifier, node.type),
916
916
  length: node.arguments.length
917
917
  });
918
918
  }
@@ -924,7 +924,7 @@ class BytecodeGenerator {
924
924
  yield pushArgs();
925
925
  this.push({
926
926
  op: instruction_1.OpCode.CALL_SUPER_PROPERTY,
927
- source: this.getSourceLocation(left.index),
927
+ source: this.getSourceLocation(left.index, node.type),
928
928
  length: node.arguments.length
929
929
  });
930
930
  }
@@ -934,7 +934,7 @@ class BytecodeGenerator {
934
934
  yield pushArgs();
935
935
  this.push({
936
936
  op: instruction_1.OpCode.CALL_WITH_CONTEXT,
937
- source: this.getSourceLocation(left.index),
937
+ source: this.getSourceLocation(left.index, node.type),
938
938
  length: node.arguments.length
939
939
  });
940
940
  }
@@ -944,7 +944,7 @@ class BytecodeGenerator {
944
944
  yield pushArgs();
945
945
  this.push({
946
946
  op: instruction_1.OpCode.CALL,
947
- source: this.getSourceLocation(left),
947
+ source: this.getSourceLocation(left, node.type),
948
948
  length: node.arguments.length
949
949
  });
950
950
  }
@@ -953,7 +953,7 @@ class BytecodeGenerator {
953
953
  yield pushArgs();
954
954
  this.push({
955
955
  op: instruction_1.OpCode.CALL,
956
- source: this.getSourceLocation(left),
956
+ source: this.getSourceLocation(left, node.type),
957
957
  length: node.arguments.length
958
958
  });
959
959
  }
@@ -148,9 +148,8 @@ class Interpreter extends events_1.EventEmitter {
148
148
  start() {
149
149
  return __awaiter(this, void 0, void 0, function* () {
150
150
  try {
151
- const process = this.vm.exec();
152
151
  this.emit('start', this);
153
- yield process;
152
+ yield this.vm.exec();
154
153
  }
155
154
  catch (err) {
156
155
  if (err instanceof error_1.PrepareError || err instanceof error_1.RuntimeError) {
package/dist/vm.d.ts CHANGED
@@ -37,9 +37,11 @@ export interface VMOptions {
37
37
  environmentVariables?: Map<string, string>;
38
38
  imports?: Map<string, Instruction[]>;
39
39
  externalFrames?: Stack<OperationContext>;
40
+ maxActionsPerLoop?: number;
40
41
  }
41
42
  export declare class VM {
42
43
  private readonly ACTIONS_PER_LOOP;
44
+ private maxActionsPerLoop;
43
45
  private actionCount;
44
46
  private state;
45
47
  private frames;
@@ -60,6 +62,7 @@ export declare class VM {
60
62
  getTime(): number;
61
63
  isPending(): boolean;
62
64
  getStacktrace(): Instruction[];
65
+ setMaxActionsPerLoop(actions: number): this;
63
66
  getOpenHandles(): number;
64
67
  getSignal(): EventEmitter;
65
68
  exit(): void;
package/dist/vm.js CHANGED
@@ -85,12 +85,13 @@ var VMState;
85
85
  })(VMState = exports.VMState || (exports.VMState = {}));
86
86
  class VM {
87
87
  constructor(options) {
88
- var _a, _b, _c;
89
- this.ACTIONS_PER_LOOP = 120;
88
+ var _a, _b, _c, _d;
89
+ this.ACTIONS_PER_LOOP = 1200;
90
90
  this.STACK_LIMIT = 512;
91
91
  this.stack = new Array(this.STACK_LIMIT);
92
92
  this.signal = new events_1.default();
93
93
  this.state = VMState.PREPARATION;
94
+ this.maxActionsPerLoop = (_a = options.maxActionsPerLoop) !== null && _a !== void 0 ? _a : this.ACTIONS_PER_LOOP;
94
95
  this.actionCount = 0;
95
96
  this.sp = 0;
96
97
  this.time = -1;
@@ -99,10 +100,10 @@ class VM {
99
100
  this.contextTypeIntrinsics = options.contextTypeIntrinsics;
100
101
  this.handler = options.handler;
101
102
  this.debugger = options.debugger;
102
- this.environmentVariables = (_a = options.environmentVariables) !== null && _a !== void 0 ? _a : new Map();
103
+ this.environmentVariables = (_b = options.environmentVariables) !== null && _b !== void 0 ? _b : new Map();
103
104
  this.iterators = new stack_1.Stack();
104
- this.imports = (_b = options.imports) !== null && _b !== void 0 ? _b : new Map();
105
- this.externalFrames = (_c = options.externalFrames) !== null && _c !== void 0 ? _c : new stack_1.Stack();
105
+ this.imports = (_c = options.imports) !== null && _c !== void 0 ? _c : new Map();
106
+ this.externalFrames = (_d = options.externalFrames) !== null && _d !== void 0 ? _d : new stack_1.Stack();
106
107
  }
107
108
  getTime() {
108
109
  return this.time;
@@ -122,6 +123,10 @@ class VM {
122
123
  }
123
124
  return stacktrace;
124
125
  }
126
+ setMaxActionsPerLoop(actions) {
127
+ this.maxActionsPerLoop = actions;
128
+ return this;
129
+ }
125
130
  getOpenHandles() {
126
131
  return this.sp;
127
132
  }
@@ -683,7 +688,7 @@ class VM {
683
688
  return;
684
689
  }
685
690
  }
686
- if (this.actionCount++ === this.ACTIONS_PER_LOOP) {
691
+ if (this.actionCount++ === this.maxActionsPerLoop) {
687
692
  this.actionCount = 0;
688
693
  yield (0, next_tick_1.nextTick)();
689
694
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "4.0.15",
3
+ "version": "4.0.16",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",