greybel-interpreter 2.2.4 → 2.2.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.js CHANGED
@@ -144,36 +144,38 @@ class FunctionState {
144
144
  exports.FunctionState = FunctionState;
145
145
  class OperationContext {
146
146
  constructor(options = {}) {
147
- this.target = options.target || 'unknown';
148
- this.stackTrace = options.stackTrace || [];
149
- this.previous = options.previous || null;
150
- this.type = options.type || ContextType.Api;
151
- this.state = options.state || ContextState.Default;
147
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
148
+ this.target = (_a = options.target) !== null && _a !== void 0 ? _a : 'unknown';
149
+ this.stackTrace = (_b = options.stackTrace) !== null && _b !== void 0 ? _b : [];
150
+ this.previous = (_c = options.previous) !== null && _c !== void 0 ? _c : null;
151
+ this.type = (_d = options.type) !== null && _d !== void 0 ? _d : ContextType.Api;
152
+ this.state = (_e = options.state) !== null && _e !== void 0 ? _e : ContextState.Default;
152
153
  this.scope = new Scope(this);
153
- this.isProtected = options.isProtected || false;
154
- this.injected = options.injected || false;
155
- this.debugger = options.debugger || new Debugger();
156
- this.handler = options.handler || new handler_container_1.HandlerContainer();
157
- this.cps = options.cps || null;
158
- this.processState = options.processState || new ProcessState();
159
- this.environmentVariables = options.environmentVariables || new Map();
154
+ this.isProtected = (_f = options.isProtected) !== null && _f !== void 0 ? _f : false;
155
+ this.injected = (_g = options.injected) !== null && _g !== void 0 ? _g : false;
156
+ this.debugger = (_h = options.debugger) !== null && _h !== void 0 ? _h : new Debugger();
157
+ this.handler = (_j = options.handler) !== null && _j !== void 0 ? _j : new handler_container_1.HandlerContainer();
158
+ this.cps = (_k = options.cps) !== null && _k !== void 0 ? _k : null;
159
+ this.processState = (_l = options.processState) !== null && _l !== void 0 ? _l : new ProcessState();
160
+ this.environmentVariables = (_m = options.environmentVariables) !== null && _m !== void 0 ? _m : new Map();
160
161
  this.functionState = new FunctionState();
161
162
  this.loopState = new LoopState();
162
163
  this.api = this.lookupApi();
163
164
  this.globals = this.lookupGlobals();
164
- this.locals = this.lookupLocals() || this;
165
+ this.locals = (_o = this.lookupLocals()) !== null && _o !== void 0 ? _o : this;
165
166
  }
166
167
  isIgnoredInDebugging(op) {
167
168
  return op instanceof operation_1.OperationBlock || op instanceof noop_1.Noop;
168
169
  }
169
170
  step(op) {
171
+ var _a;
170
172
  return __awaiter(this, void 0, void 0, function* () {
171
173
  if (this.isIgnoredInDebugging(op)) {
172
174
  return op.handle(this);
173
175
  }
174
176
  this.stackTrace.unshift(op);
175
177
  if (!this.injected) {
176
- this.target = op.target || this.target;
178
+ this.target = (_a = op.target) !== null && _a !== void 0 ? _a : this.target;
177
179
  this.setLastActive(this);
178
180
  if (this.debugger.getBreakpoint(this)) {
179
181
  this.processState.emit('breakpoint');
@@ -301,8 +303,9 @@ class OperationContext {
301
303
  return this.locals.scope.get(path);
302
304
  }
303
305
  fork(options) {
306
+ var _a;
304
307
  const newContext = new OperationContext({
305
- target: options.target || this.target,
308
+ target: (_a = options.target) !== null && _a !== void 0 ? _a : this.target,
306
309
  stackTrace: this.stackTrace,
307
310
  previous: this,
308
311
  type: options.type,
@@ -6,10 +6,11 @@ const output_1 = require("./handler/output");
6
6
  const resource_1 = require("./handler/resource");
7
7
  class HandlerContainer {
8
8
  constructor(options = {}) {
9
+ var _a, _b, _c;
9
10
  this.resourceHandler =
10
- (options === null || options === void 0 ? void 0 : options.resourceHandler) || new resource_1.DefaultResourceHandler();
11
- this.outputHandler = (options === null || options === void 0 ? void 0 : options.outputHandler) || new output_1.DefaultOutputHandler();
12
- this.errorHandler = (options === null || options === void 0 ? void 0 : options.errorHandler) || new error_1.DefaultErrorHandler();
11
+ (_a = options === null || options === void 0 ? void 0 : options.resourceHandler) !== null && _a !== void 0 ? _a : new resource_1.DefaultResourceHandler();
12
+ this.outputHandler = (_b = options === null || options === void 0 ? void 0 : options.outputHandler) !== null && _b !== void 0 ? _b : new output_1.DefaultOutputHandler();
13
+ this.errorHandler = (_c = options === null || options === void 0 ? void 0 : options.errorHandler) !== null && _c !== void 0 ? _c : new error_1.DefaultErrorHandler();
13
14
  }
14
15
  }
15
16
  exports.HandlerContainer = HandlerContainer;
@@ -27,15 +27,16 @@ const object_value_1 = require("./utils/object-value");
27
27
  exports.PARAMS_PROPERTY = new string_1.CustomString('params');
28
28
  class Interpreter extends events_1.EventEmitter {
29
29
  constructor(options) {
30
+ var _a, _b, _c, _d, _e, _f;
30
31
  super();
31
- this.handler = options.handler || new handler_container_1.HandlerContainer();
32
- this.debugger = options.debugger || new context_1.Debugger();
33
- this.api = options.api || new object_value_1.ObjectValue();
34
- this.params = options.params || [];
35
- this.environmentVariables = options.environmentVariables || new Map();
32
+ this.handler = (_a = options.handler) !== null && _a !== void 0 ? _a : new handler_container_1.HandlerContainer();
33
+ this.debugger = (_b = options.debugger) !== null && _b !== void 0 ? _b : new context_1.Debugger();
34
+ this.api = (_c = options.api) !== null && _c !== void 0 ? _c : new object_value_1.ObjectValue();
35
+ this.params = (_d = options.params) !== null && _d !== void 0 ? _d : [];
36
+ this.environmentVariables = (_e = options.environmentVariables) !== null && _e !== void 0 ? _e : new Map();
36
37
  this.apiContext = null;
37
38
  this.globalContext = null;
38
- this.setTarget(options.target || 'unknown');
39
+ this.setTarget((_f = options.target) !== null && _f !== void 0 ? _f : 'unknown');
39
40
  }
40
41
  setTarget(target) {
41
42
  if (this.apiContext !== null && this.apiContext.isPending()) {
@@ -106,7 +107,7 @@ class Interpreter extends events_1.EventEmitter {
106
107
  return __awaiter(this, void 0, void 0, function* () {
107
108
  try {
108
109
  const top = yield this.prepare(code);
109
- const injectionCtx = (context || this.globalContext).fork({
110
+ const injectionCtx = (context !== null && context !== void 0 ? context : this.globalContext).fork({
110
111
  type: context_1.ContextType.Call,
111
112
  state: context_1.ContextState.Temporary,
112
113
  injected: true
@@ -135,7 +136,7 @@ class Interpreter extends events_1.EventEmitter {
135
136
  }
136
137
  run(customCode) {
137
138
  return __awaiter(this, void 0, void 0, function* () {
138
- const code = customCode || (yield this.handler.resourceHandler.get(this.target));
139
+ const code = customCode !== null && customCode !== void 0 ? customCode : (yield this.handler.resourceHandler.get(this.target));
139
140
  const top = yield this.prepare(code);
140
141
  return this.start(top);
141
142
  });
@@ -42,7 +42,6 @@ class For extends operation_1.OperationBlock {
42
42
  return Promise.resolve(default_1.DefaultType.Void);
43
43
  }
44
44
  const loopState = new context_1.LoopState();
45
- let index = 0;
46
45
  forCtx.loopState = loopState;
47
46
  return new Promise((resolve, reject) => {
48
47
  const iterator = iteratorValue[Symbol.iterator]();
@@ -57,7 +56,7 @@ class For extends operation_1.OperationBlock {
57
56
  }
58
57
  const current = iteratorResult.value;
59
58
  loopState.isContinue = false;
60
- forCtx.set(idxIdentifier, new number_1.CustomNumber(index++));
59
+ forCtx.set(idxIdentifier, new number_1.CustomNumber(iterator.index - 1));
61
60
  forCtx.set(varIdentifier, current);
62
61
  yield this.block.handle(forCtx);
63
62
  if (loopState.isBreak ||
@@ -66,6 +65,8 @@ class For extends operation_1.OperationBlock {
66
65
  resolve(default_1.DefaultType.Void);
67
66
  return;
68
67
  }
68
+ const idxValue = forCtx.get(idxIdentifier).toNumber();
69
+ iterator.index += idxValue - (iterator.index - 1);
69
70
  iteratorResult = iterator.next();
70
71
  process.nextTick(iteration);
71
72
  }
@@ -86,7 +86,7 @@ class CustomFunction extends base_1.CustomValue {
86
86
  return v.value === CustomFunction.intrinsics;
87
87
  }
88
88
  run(self, args, callContext, next) {
89
- var _a;
89
+ var _a, _b;
90
90
  return __awaiter(this, void 0, void 0, function* () {
91
91
  const fnCtx = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.fork({
92
92
  type: context_1.ContextType.Function,
@@ -113,13 +113,13 @@ class CustomFunction extends base_1.CustomValue {
113
113
  argIndex++;
114
114
  continue;
115
115
  }
116
- argMap.set(item.name, args[argIndex++] || (yield item.defaultValue.handle(fnCtx)));
116
+ argMap.set(item.name, (_b = args[argIndex++]) !== null && _b !== void 0 ? _b : (yield item.defaultValue.handle(fnCtx)));
117
117
  }
118
118
  if (!isSelfNull) {
119
119
  argMap.set(exports.SELF_NAMESPACE, self);
120
120
  }
121
- const isa = next || (self instanceof map_1.CustomMap ? self.isa : null);
122
- return this.value(fnCtx || callContext, self, argMap, isa);
121
+ const isa = next !== null && next !== void 0 ? next : (self instanceof map_1.CustomMap ? self.isa : null);
122
+ return this.value(fnCtx !== null && fnCtx !== void 0 ? fnCtx : callContext, self, argMap, isa);
123
123
  });
124
124
  }
125
125
  }
@@ -3,6 +3,7 @@ import { CustomValue } from './base';
3
3
  import { CustomFunction } from './function';
4
4
  import { CustomObject } from './with-intrinsics';
5
5
  export declare class CustomInterfaceIterator implements Iterator<CustomValue> {
6
+ index: number;
6
7
  next(): IteratorResult<CustomValue>;
7
8
  }
8
9
  export declare class CustomInterface extends CustomObject {
@@ -6,6 +6,9 @@ const base_1 = require("./base");
6
6
  const default_1 = require("./default");
7
7
  const with_intrinsics_1 = require("./with-intrinsics");
8
8
  class CustomInterfaceIterator {
9
+ constructor() {
10
+ this.index = 0;
11
+ }
9
12
  next() {
10
13
  return {
11
14
  value: default_1.DefaultType.Void,
@@ -14,7 +14,7 @@ class CustomListIterator {
14
14
  }
15
15
  next() {
16
16
  const me = this;
17
- if (me.index === me.value.length) {
17
+ if (me.index >= me.value.length) {
18
18
  return {
19
19
  value: null,
20
20
  done: true
package/dist/types/map.js CHANGED
@@ -14,13 +14,13 @@ exports.CUSTOM_MAP_MAX_DEPTH_VALUE = '{...}';
14
14
  class CustomMapIterator {
15
15
  constructor(value) {
16
16
  const me = this;
17
- me.value = new object_value_1.ObjectValue(value);
17
+ me.value = value;
18
18
  me.index = 0;
19
19
  }
20
20
  next() {
21
21
  const me = this;
22
22
  const keys = Array.from(me.value.keys());
23
- if (me.index === keys.length) {
23
+ if (me.index >= keys.length) {
24
24
  return {
25
25
  value: nil_1.Void,
26
26
  done: true
@@ -3,6 +3,7 @@ import { Path } from '../utils/path';
3
3
  import { CustomValue } from './base';
4
4
  import { CustomValueWithIntrinsics } from './with-intrinsics';
5
5
  export declare class CustomNumberIterator implements Iterator<CustomValue> {
6
+ index: number;
6
7
  next(): IteratorResult<CustomValue>;
7
8
  }
8
9
  export declare class CustomNumber extends CustomValueWithIntrinsics {
@@ -7,6 +7,9 @@ const base_1 = require("./base");
7
7
  const nil_1 = require("./nil");
8
8
  const with_intrinsics_1 = require("./with-intrinsics");
9
9
  class CustomNumberIterator {
10
+ constructor() {
11
+ this.index = 0;
12
+ }
10
13
  next() {
11
14
  return {
12
15
  value: null,
@@ -15,7 +15,7 @@ class CustomStringIterator {
15
15
  }
16
16
  next() {
17
17
  const me = this;
18
- if (me.index === me.value.length) {
18
+ if (me.index >= me.value.length) {
19
19
  return {
20
20
  value: null,
21
21
  done: true
@@ -6,7 +6,9 @@ export declare abstract class CustomValueWithIntrinsics extends CustomValue {
6
6
  abstract has(path: Path<CustomValue> | CustomValue): boolean;
7
7
  abstract set(path: Path<CustomValue> | CustomValue, value: CustomValue): void;
8
8
  abstract get(path: Path<CustomValue> | CustomValue): CustomValue;
9
- abstract [Symbol.iterator](): Iterator<CustomValue>;
9
+ abstract [Symbol.iterator](): Iterator<CustomValue> & {
10
+ index: number;
11
+ };
10
12
  static readonly intrinsics: ObjectValue;
11
13
  static getIntrinsics(): ObjectValue;
12
14
  static addIntrinsic(key: CustomValue, fn: CustomFunction): void;
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PrepareError = exports.RuntimeError = void 0;
4
4
  class RuntimeError extends Error {
5
5
  constructor(message, context, source) {
6
+ var _a;
6
7
  super(message);
7
8
  this.target = context.target;
8
- this.stackTrace = context.stackTrace || [];
9
+ this.stackTrace = (_a = context.stackTrace) !== null && _a !== void 0 ? _a : [];
9
10
  this.stack = this.createTrace();
10
11
  this.source = source;
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",
@@ -48,8 +48,8 @@
48
48
  "typescript": "^5.0.4"
49
49
  },
50
50
  "dependencies": {
51
- "greybel-core": "^0.9.6",
52
- "greyscript-core": "^0.9.9"
51
+ "greybel-core": "^0.9.7",
52
+ "greyscript-core": "^0.9.10"
53
53
  },
54
54
  "keywords": [
55
55
  "greyscript",