greybel-interpreter 4.0.11 → 4.0.13

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.
@@ -65,6 +65,7 @@ export interface FunctionDefinitionInstructionArgument {
65
65
  defaultValue: CustomValue;
66
66
  }
67
67
  export type SourceLocation = {
68
+ name: string;
68
69
  path: string;
69
70
  start: ASTPosition;
70
71
  end: ASTPosition;
@@ -30,7 +30,7 @@ export declare class BytecodeGenerator {
30
30
  protected getInternalLocation(): SourceLocation;
31
31
  protected pushContext(): void;
32
32
  protected popContext(): BytecodeGeneratorContext;
33
- protected getLastJumpoint(): [Instruction, Instruction];
33
+ protected getLastJumpPoint(): [Instruction, Instruction];
34
34
  protected pushJumppoint(start: Instruction, end: Instruction): void;
35
35
  protected popJumppoint(): [Instruction, Instruction];
36
36
  protected push(item: Instruction): void;
@@ -75,6 +75,7 @@ class BytecodeGenerator {
75
75
  getSourceLocation(node) {
76
76
  const target = this.target.peek();
77
77
  return {
78
+ name: node.type,
78
79
  path: target,
79
80
  start: node.start,
80
81
  end: node.end
@@ -82,6 +83,7 @@ class BytecodeGenerator {
82
83
  }
83
84
  getInternalLocation() {
84
85
  return {
86
+ name: 'internal',
85
87
  path: 'internal',
86
88
  start: { line: 0, character: 0 },
87
89
  end: { line: 0, character: 0 }
@@ -96,8 +98,11 @@ class BytecodeGenerator {
96
98
  popContext() {
97
99
  return this.context.pop();
98
100
  }
99
- getLastJumpoint() {
101
+ getLastJumpPoint() {
100
102
  const jumpPoints = this.context.peek().jumpPoints;
103
+ if (jumpPoints.length === 0) {
104
+ return null;
105
+ }
101
106
  return jumpPoints[jumpPoints.length - 1];
102
107
  }
103
108
  pushJumppoint(start, end) {
@@ -703,7 +708,10 @@ class BytecodeGenerator {
703
708
  }
704
709
  processBreak(node) {
705
710
  return __awaiter(this, void 0, void 0, function* () {
706
- const [_, end] = this.getLastJumpoint();
711
+ const jumpPoint = this.getLastJumpPoint();
712
+ if (jumpPoint === null)
713
+ return;
714
+ const [_, end] = jumpPoint;
707
715
  this.push({
708
716
  op: instruction_1.OpCode.GOTO_A,
709
717
  source: this.getSourceLocation(node),
@@ -713,7 +721,10 @@ class BytecodeGenerator {
713
721
  }
714
722
  processContinue(node) {
715
723
  return __awaiter(this, void 0, void 0, function* () {
716
- const [start] = this.getLastJumpoint();
724
+ const jumpPoint = this.getLastJumpPoint();
725
+ if (jumpPoint === null)
726
+ return;
727
+ const [start] = jumpPoint;
717
728
  this.push({
718
729
  op: instruction_1.OpCode.GOTO_A,
719
730
  source: this.getSourceLocation(node),
@@ -999,6 +1010,7 @@ class BytecodeGenerator {
999
1010
  op: instruction_1.OpCode.POP_ITERATOR,
1000
1011
  source: this.getSourceLocation(node.iterator)
1001
1012
  };
1013
+ this.pushJumppoint(start, end);
1002
1014
  this.push({
1003
1015
  op: instruction_1.OpCode.GET_LOCALS,
1004
1016
  source: this.getSourceLocation(node)
@@ -1037,6 +1049,7 @@ class BytecodeGenerator {
1037
1049
  goto: start
1038
1050
  });
1039
1051
  this.push(end);
1052
+ this.popJumppoint();
1040
1053
  });
1041
1054
  }
1042
1055
  processEnvarExpression(node) {
package/dist/index.d.ts CHANGED
@@ -19,5 +19,6 @@ export { ObjectValue } from './utils/object-value';
19
19
  export { deepEqual } from './utils/deep-equal';
20
20
  export { deepHash } from './utils/deep-hash';
21
21
  export { Debugger, VM, VMOptions } from './vm';
22
- export { Instruction } from './byte-compiler/instruction';
22
+ export { Instruction, OpCode } from './byte-compiler/instruction';
23
23
  export { BytecodeGenerator, BytecodeCompileResult, BytecodeConverterOptions, BytecodeGeneratorContext } from './bytecode-generator';
24
+ export { Stack } from './utils/stack';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BytecodeGenerator = exports.VM = exports.Debugger = exports.deepHash = exports.deepEqual = exports.ObjectValue = exports.RuntimeError = exports.PrepareError = exports.CustomValueWithIntrinsics = exports.CustomObject = exports.CustomStringIterator = exports.CustomString = exports.CustomNumber = exports.CustomNil = exports.CustomMapIterator = exports.CustomMap = exports.CustomListIterator = exports.CustomList = exports.CustomFunction = exports.DefaultType = exports.CustomBoolean = exports.CustomValue = exports.Interpreter = exports.HandlerContainer = exports.ResourceHandler = exports.DefaultResourceHandler = exports.OutputHandler = exports.DefaultOutputHandler = exports.ErrorHandler = exports.DefaultErrorHandler = exports.Scope = exports.OperationContext = exports.ContextType = void 0;
3
+ exports.Stack = exports.BytecodeGenerator = exports.OpCode = exports.VM = exports.Debugger = exports.deepHash = exports.deepEqual = exports.ObjectValue = exports.RuntimeError = exports.PrepareError = exports.CustomValueWithIntrinsics = exports.CustomObject = exports.CustomStringIterator = exports.CustomString = exports.CustomNumber = exports.CustomNil = exports.CustomMapIterator = exports.CustomMap = exports.CustomListIterator = exports.CustomList = exports.CustomFunction = exports.DefaultType = exports.CustomBoolean = exports.CustomValue = exports.Interpreter = exports.HandlerContainer = exports.ResourceHandler = exports.DefaultResourceHandler = exports.OutputHandler = exports.DefaultOutputHandler = exports.ErrorHandler = exports.DefaultErrorHandler = exports.Scope = exports.OperationContext = exports.ContextType = void 0;
4
4
  var context_1 = require("./context");
5
5
  Object.defineProperty(exports, "ContextType", { enumerable: true, get: function () { return context_1.ContextType; } });
6
6
  Object.defineProperty(exports, "OperationContext", { enumerable: true, get: function () { return context_1.OperationContext; } });
@@ -54,5 +54,9 @@ Object.defineProperty(exports, "deepHash", { enumerable: true, get: function ()
54
54
  var vm_1 = require("./vm");
55
55
  Object.defineProperty(exports, "Debugger", { enumerable: true, get: function () { return vm_1.Debugger; } });
56
56
  Object.defineProperty(exports, "VM", { enumerable: true, get: function () { return vm_1.VM; } });
57
+ var instruction_1 = require("./byte-compiler/instruction");
58
+ Object.defineProperty(exports, "OpCode", { enumerable: true, get: function () { return instruction_1.OpCode; } });
57
59
  var bytecode_generator_1 = require("./bytecode-generator");
58
60
  Object.defineProperty(exports, "BytecodeGenerator", { enumerable: true, get: function () { return bytecode_generator_1.BytecodeGenerator; } });
61
+ var stack_1 = require("./utils/stack");
62
+ Object.defineProperty(exports, "Stack", { enumerable: true, get: function () { return stack_1.Stack; } });
@@ -16,6 +16,7 @@ class CustomFunction extends base_1.CustomValue {
16
16
  {
17
17
  op: instruction_1.OpCode.CALL_INTERNAL,
18
18
  source: {
19
+ name: 'internal',
19
20
  path: 'internal',
20
21
  start: { line: 0, character: 0 },
21
22
  end: { line: 0, character: 0 }
@@ -26,6 +27,7 @@ class CustomFunction extends base_1.CustomValue {
26
27
  {
27
28
  op: instruction_1.OpCode.RETURN,
28
29
  source: {
30
+ name: 'internal',
29
31
  path: 'internal',
30
32
  start: { line: 0, character: 0 },
31
33
  end: { line: 0, character: 0 }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "4.0.11",
3
+ "version": "4.0.13",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",
@@ -1,3 +0,0 @@
1
- import { CustomValue } from '../types/base';
2
- import { CustomMap } from '../types/map';
3
- export declare function getSuper(item: CustomValue): CustomMap;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSuper = void 0;
4
- const map_1 = require("../types/map");
5
- function getSuper(item) {
6
- var _a;
7
- if (item instanceof map_1.CustomMap) {
8
- return (_a = item.getIsa()) !== null && _a !== void 0 ? _a : new map_1.CustomMap();
9
- }
10
- return null;
11
- }
12
- exports.getSuper = getSuper;