greybel-interpreter 1.7.1 → 1.7.3

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.
Files changed (97) hide show
  1. package/dist/context.d.ts +9 -9
  2. package/dist/context.js +19 -22
  3. package/dist/cps.d.ts +3 -3
  4. package/dist/cps.js +110 -71
  5. package/dist/handler/output.d.ts +4 -4
  6. package/dist/handler/output.js +2 -2
  7. package/dist/handler-container.d.ts +1 -1
  8. package/dist/handler-container.js +2 -1
  9. package/dist/index.d.ts +43 -42
  10. package/dist/index.js +47 -47
  11. package/dist/interpreter.d.ts +9 -9
  12. package/dist/interpreter.js +55 -62
  13. package/dist/operations/assign.d.ts +5 -5
  14. package/dist/operations/assign.js +9 -11
  15. package/dist/operations/block.d.ts +4 -4
  16. package/dist/operations/block.js +6 -8
  17. package/dist/operations/break.d.ts +4 -4
  18. package/dist/operations/break.js +6 -8
  19. package/dist/operations/call.d.ts +5 -5
  20. package/dist/operations/call.js +12 -14
  21. package/dist/operations/chunk.d.ts +6 -6
  22. package/dist/operations/chunk.js +8 -10
  23. package/dist/operations/continue.d.ts +4 -4
  24. package/dist/operations/continue.js +6 -8
  25. package/dist/operations/debugger-statement.d.ts +5 -5
  26. package/dist/operations/debugger-statement.js +6 -8
  27. package/dist/operations/envar.d.ts +5 -5
  28. package/dist/operations/envar.js +6 -8
  29. package/dist/operations/evaluate.d.ts +6 -5
  30. package/dist/operations/evaluate.js +109 -112
  31. package/dist/operations/for.d.ts +6 -6
  32. package/dist/operations/for.js +15 -17
  33. package/dist/operations/function-reference.d.ts +5 -5
  34. package/dist/operations/function-reference.js +8 -10
  35. package/dist/operations/function.d.ts +5 -5
  36. package/dist/operations/function.js +17 -20
  37. package/dist/operations/if-statement.d.ts +6 -6
  38. package/dist/operations/if-statement.js +12 -15
  39. package/dist/operations/import.d.ts +7 -7
  40. package/dist/operations/import.js +15 -18
  41. package/dist/operations/include.d.ts +5 -5
  42. package/dist/operations/include.js +4 -6
  43. package/dist/operations/list.d.ts +5 -5
  44. package/dist/operations/list.js +6 -8
  45. package/dist/operations/literal.d.ts +5 -5
  46. package/dist/operations/literal.js +12 -14
  47. package/dist/operations/map.d.ts +5 -5
  48. package/dist/operations/map.js +8 -10
  49. package/dist/operations/negated-binary.d.ts +5 -5
  50. package/dist/operations/negated-binary.js +7 -9
  51. package/dist/operations/new-instance.d.ts +5 -5
  52. package/dist/operations/new-instance.js +8 -10
  53. package/dist/operations/noop.d.ts +5 -5
  54. package/dist/operations/noop.js +6 -8
  55. package/dist/operations/not.d.ts +5 -5
  56. package/dist/operations/not.js +6 -8
  57. package/dist/operations/operation.d.ts +3 -3
  58. package/dist/operations/operation.js +2 -1
  59. package/dist/operations/reference.d.ts +4 -4
  60. package/dist/operations/reference.js +4 -6
  61. package/dist/operations/resolve.d.ts +6 -6
  62. package/dist/operations/resolve.js +27 -30
  63. package/dist/operations/return.d.ts +5 -5
  64. package/dist/operations/return.js +8 -10
  65. package/dist/operations/while.d.ts +6 -6
  66. package/dist/operations/while.js +9 -11
  67. package/dist/types/base.d.ts +1 -1
  68. package/dist/types/base.js +2 -1
  69. package/dist/types/boolean.d.ts +2 -2
  70. package/dist/types/boolean.js +4 -7
  71. package/dist/types/default.d.ts +7 -7
  72. package/dist/types/default.js +9 -8
  73. package/dist/types/function.d.ts +5 -5
  74. package/dist/types/function.js +27 -30
  75. package/dist/types/interface.d.ts +4 -4
  76. package/dist/types/interface.js +10 -13
  77. package/dist/types/list.d.ts +4 -4
  78. package/dist/types/list.js +21 -24
  79. package/dist/types/map.d.ts +5 -5
  80. package/dist/types/map.js +26 -29
  81. package/dist/types/nil.d.ts +2 -2
  82. package/dist/types/nil.js +4 -7
  83. package/dist/types/number.d.ts +4 -4
  84. package/dist/types/number.js +8 -11
  85. package/dist/types/string.d.ts +4 -4
  86. package/dist/types/string.js +19 -22
  87. package/dist/types/with-intrinsics.d.ts +4 -4
  88. package/dist/types/with-intrinsics.js +2 -5
  89. package/dist/utils/deep-equal.d.ts +1 -1
  90. package/dist/utils/deep-equal.js +4 -3
  91. package/dist/utils/error.d.ts +23 -0
  92. package/dist/utils/error.js +29 -0
  93. package/dist/utils/object-value.d.ts +2 -2
  94. package/dist/utils/object-value.js +6 -8
  95. package/dist/utils/path.d.ts +1 -1
  96. package/dist/utils/path.js +2 -1
  97. package/package.json +2 -2
package/dist/context.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ASTBase } from 'greyscript-core';
2
- import CPS from './cps';
3
- import HandlerContainer from './handler-container';
4
- import Operation from './operations/operation';
5
- import CustomValue from './types/base';
6
- import CustomMap from './types/map';
7
- import CustomNil from './types/nil';
8
- import ObjectValue from './utils/object-value';
9
- import Path from './utils/path';
2
+ import { CPS } from './cps';
3
+ import { HandlerContainer } from './handler-container';
4
+ import { Operation } from './operations/operation';
5
+ import { CustomValue } from './types/base';
6
+ import { CustomMap } from './types/map';
7
+ import { CustomNil } from './types/nil';
8
+ import { ObjectValue } from './utils/object-value';
9
+ import { Path } from './utils/path';
10
10
  export declare enum ContextType {
11
11
  Api = 0,
12
12
  Global = 1,
@@ -71,7 +71,7 @@ export interface ContextForkOptions {
71
71
  target?: string;
72
72
  injected?: boolean;
73
73
  }
74
- export default class OperationContext {
74
+ export declare class OperationContext {
75
75
  target: string;
76
76
  stackItem: ASTBase;
77
77
  debugger: Debugger;
package/dist/context.js CHANGED
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
7
- const handler_container_1 = __importDefault(require("./handler-container"));
8
- const base_1 = __importDefault(require("./types/base"));
9
- const default_1 = __importDefault(require("./types/default"));
10
- const map_1 = __importDefault(require("./types/map"));
11
- const path_1 = __importDefault(require("./utils/path"));
3
+ exports.OperationContext = exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
4
+ const handler_container_1 = require("./handler-container");
5
+ const base_1 = require("./types/base");
6
+ const default_1 = require("./types/default");
7
+ const map_1 = require("./types/map");
8
+ const path_1 = require("./utils/path");
12
9
  var ContextType;
13
10
  (function (ContextType) {
14
11
  ContextType[ContextType["Api"] = 0] = "Api";
@@ -24,14 +21,14 @@ var ContextState;
24
21
  ContextState[ContextState["Temporary"] = 0] = "Temporary";
25
22
  ContextState[ContextState["Default"] = 1] = "Default";
26
23
  })(ContextState = exports.ContextState || (exports.ContextState = {}));
27
- class Scope extends map_1.default {
24
+ class Scope extends map_1.CustomMap {
28
25
  constructor(context) {
29
26
  super();
30
27
  this.context = context;
31
28
  }
32
29
  get(path) {
33
- if (path instanceof base_1.default) {
34
- return this.get(new path_1.default([path]));
30
+ if (path instanceof base_1.CustomValue) {
31
+ return this.get(new path_1.Path([path]));
35
32
  }
36
33
  if (path.count() === 0) {
37
34
  return this;
@@ -44,8 +41,8 @@ class Scope extends map_1.default {
44
41
  else if (this.context.api.scope.has(path)) {
45
42
  return this.context.api.scope.get(path);
46
43
  }
47
- else if (path.count() === 1 && map_1.default.getIntrinsics().has(current)) {
48
- return map_1.default.getIntrinsics().get(current);
44
+ else if (path.count() === 1 && map_1.CustomMap.getIntrinsics().has(current)) {
45
+ return map_1.CustomMap.getIntrinsics().get(current);
49
46
  }
50
47
  else if (this.context.previous !== null) {
51
48
  return this.context.previous.get(path);
@@ -66,7 +63,7 @@ class Debugger {
66
63
  }
67
64
  debug(...segments) {
68
65
  console.debug(...segments);
69
- return default_1.default.Void;
66
+ return default_1.DefaultType.Void;
70
67
  }
71
68
  setBreakpoint(breakpoint) {
72
69
  this.breakpoint = breakpoint;
@@ -125,7 +122,7 @@ class LoopState {
125
122
  exports.LoopState = LoopState;
126
123
  class FunctionState {
127
124
  constructor() {
128
- this.value = default_1.default.Void;
125
+ this.value = default_1.DefaultType.Void;
129
126
  this.isReturn = false;
130
127
  this.context = null;
131
128
  this.super = null;
@@ -143,7 +140,7 @@ class OperationContext {
143
140
  this.isProtected = options.isProtected || false;
144
141
  this.injected = options.injected || false;
145
142
  this.debugger = options.debugger || new Debugger();
146
- this.handler = options.handler || new handler_container_1.default();
143
+ this.handler = options.handler || new handler_container_1.HandlerContainer();
147
144
  this.cps = options.cps || null;
148
145
  this.processState = options.processState || new ProcessState();
149
146
  this.environmentVariables = options.environmentVariables || new Map();
@@ -252,8 +249,8 @@ class OperationContext {
252
249
  }
253
250
  set(path, value) {
254
251
  var _a;
255
- if (path instanceof base_1.default) {
256
- this.set(new path_1.default([path]), value);
252
+ if (path instanceof base_1.CustomValue) {
253
+ this.set(new path_1.Path([path]), value);
257
254
  return;
258
255
  }
259
256
  if (this.state === ContextState.Temporary) {
@@ -265,8 +262,8 @@ class OperationContext {
265
262
  }
266
263
  get(path) {
267
264
  var _a;
268
- if (path instanceof base_1.default) {
269
- return this.get(new path_1.default([path]));
265
+ if (path instanceof base_1.CustomValue) {
266
+ return this.get(new path_1.Path([path]));
270
267
  }
271
268
  if (path.count() === 0) {
272
269
  return this.scope;
@@ -299,7 +296,6 @@ class OperationContext {
299
296
  return newContext;
300
297
  }
301
298
  }
302
- exports.default = OperationContext;
303
299
  OperationContext.lookupApiType = [ContextType.Api];
304
300
  OperationContext.lookupGlobalsType = [
305
301
  ContextType.Global
@@ -308,3 +304,4 @@ OperationContext.lookupLocalsType = [
308
304
  ContextType.Global,
309
305
  ContextType.Function
310
306
  ];
307
+ exports.OperationContext = OperationContext;
package/dist/cps.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ASTBase } from 'greyscript-core';
2
- import HandlerContainer from './handler-container';
3
- import Operation from './operations/operation';
2
+ import { HandlerContainer } from './handler-container';
3
+ import { Operation } from './operations/operation';
4
4
  export declare class CPSContext {
5
5
  readonly target: string;
6
6
  readonly handler: HandlerContainer;
7
7
  constructor(target: string, handler: HandlerContainer);
8
8
  }
9
- export default class CPS {
9
+ export declare class CPS {
10
10
  private readonly context;
11
11
  private __visit;
12
12
  constructor(context: CPSContext);
package/dist/cps.js CHANGED
@@ -8,37 +8,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.CPSContext = void 0;
12
+ exports.CPS = exports.CPSContext = void 0;
16
13
  const greybel_core_1 = require("greybel-core");
17
14
  const greyscript_core_1 = require("greyscript-core");
18
- const assign_1 = __importDefault(require("./operations/assign"));
19
- const break_1 = __importDefault(require("./operations/break"));
20
- const call_1 = __importDefault(require("./operations/call"));
21
- const chunk_1 = __importDefault(require("./operations/chunk"));
22
- const continue_1 = __importDefault(require("./operations/continue"));
23
- const debugger_statement_1 = __importDefault(require("./operations/debugger-statement"));
24
- const envar_1 = __importDefault(require("./operations/envar"));
25
- const evaluate_1 = __importDefault(require("./operations/evaluate"));
26
- const for_1 = __importDefault(require("./operations/for"));
27
- const function_1 = __importDefault(require("./operations/function"));
28
- const function_reference_1 = __importDefault(require("./operations/function-reference"));
29
- const if_statement_1 = __importDefault(require("./operations/if-statement"));
30
- const import_1 = __importDefault(require("./operations/import"));
31
- const include_1 = __importDefault(require("./operations/include"));
32
- const list_1 = __importDefault(require("./operations/list"));
33
- const literal_1 = __importDefault(require("./operations/literal"));
34
- const map_1 = __importDefault(require("./operations/map"));
35
- const negated_binary_1 = __importDefault(require("./operations/negated-binary"));
36
- const new_instance_1 = __importDefault(require("./operations/new-instance"));
37
- const noop_1 = __importDefault(require("./operations/noop"));
38
- const not_1 = __importDefault(require("./operations/not"));
39
- const resolve_1 = __importDefault(require("./operations/resolve"));
40
- const return_1 = __importDefault(require("./operations/return"));
41
- const while_1 = __importDefault(require("./operations/while"));
15
+ const assign_1 = require("./operations/assign");
16
+ const break_1 = require("./operations/break");
17
+ const call_1 = require("./operations/call");
18
+ const chunk_1 = require("./operations/chunk");
19
+ const continue_1 = require("./operations/continue");
20
+ const debugger_statement_1 = require("./operations/debugger-statement");
21
+ const envar_1 = require("./operations/envar");
22
+ const evaluate_1 = require("./operations/evaluate");
23
+ const for_1 = require("./operations/for");
24
+ const function_1 = require("./operations/function");
25
+ const function_reference_1 = require("./operations/function-reference");
26
+ const if_statement_1 = require("./operations/if-statement");
27
+ const import_1 = require("./operations/import");
28
+ const include_1 = require("./operations/include");
29
+ const list_1 = require("./operations/list");
30
+ const literal_1 = require("./operations/literal");
31
+ const map_1 = require("./operations/map");
32
+ const negated_binary_1 = require("./operations/negated-binary");
33
+ const new_instance_1 = require("./operations/new-instance");
34
+ const noop_1 = require("./operations/noop");
35
+ const not_1 = require("./operations/not");
36
+ const resolve_1 = require("./operations/resolve");
37
+ const return_1 = require("./operations/return");
38
+ const while_1 = require("./operations/while");
39
+ const error_1 = require("./utils/error");
42
40
  class CPSContext {
43
41
  constructor(target, handler) {
44
42
  this.target = target;
@@ -51,34 +49,34 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
51
49
  const defaultVisit = visit.bind(null, context, stack);
52
50
  switch (item.type) {
53
51
  case greyscript_core_1.ASTType.MapConstructorExpression:
54
- return new map_1.default(item, currentTarget).build(defaultVisit);
52
+ return new map_1.MapOperation(item, currentTarget).build(defaultVisit);
55
53
  case greyscript_core_1.ASTType.ListConstructorExpression:
56
- return new list_1.default(item, currentTarget).build(defaultVisit);
54
+ return new list_1.List(item, currentTarget).build(defaultVisit);
57
55
  case greyscript_core_1.ASTType.AssignmentStatement:
58
- return new assign_1.default(item, currentTarget).build(defaultVisit);
56
+ return new assign_1.Assign(item, currentTarget).build(defaultVisit);
59
57
  case greyscript_core_1.ASTType.MemberExpression:
60
58
  case greyscript_core_1.ASTType.Identifier:
61
59
  case greyscript_core_1.ASTType.IndexExpression:
62
- return new resolve_1.default(item, currentTarget).build(defaultVisit);
60
+ return new resolve_1.Resolve(item, currentTarget).build(defaultVisit);
63
61
  case greyscript_core_1.ASTType.FunctionDeclaration:
64
- return new function_1.default(item, currentTarget).build(defaultVisit);
62
+ return new function_1.FunctionOperation(item, currentTarget).build(defaultVisit);
65
63
  case greyscript_core_1.ASTType.InvalidCodeExpression:
66
- return new noop_1.default(item, currentTarget).build(defaultVisit);
64
+ return new noop_1.Noop(item, currentTarget).build(defaultVisit);
67
65
  case greyscript_core_1.ASTType.WhileStatement:
68
- return new while_1.default(item, currentTarget).build(defaultVisit);
66
+ return new while_1.While(item, currentTarget).build(defaultVisit);
69
67
  case greyscript_core_1.ASTType.ForGenericStatement:
70
- return new for_1.default(item, currentTarget).build(defaultVisit);
68
+ return new for_1.For(item, currentTarget).build(defaultVisit);
71
69
  case greyscript_core_1.ASTType.IfStatement:
72
70
  case greyscript_core_1.ASTType.IfShortcutStatement:
73
- return new if_statement_1.default(item, currentTarget).build(defaultVisit);
71
+ return new if_statement_1.IfStatement(item, currentTarget).build(defaultVisit);
74
72
  case greyscript_core_1.ASTType.ReturnStatement:
75
- return new return_1.default(item, currentTarget).build(defaultVisit);
73
+ return new return_1.Return(item, currentTarget).build(defaultVisit);
76
74
  case greyscript_core_1.ASTType.BreakStatement:
77
- return new break_1.default(item, currentTarget).build(defaultVisit);
75
+ return new break_1.Break(item, currentTarget).build(defaultVisit);
78
76
  case greyscript_core_1.ASTType.ContinueStatement:
79
- return new continue_1.default(item, currentTarget).build(defaultVisit);
77
+ return new continue_1.Continue(item, currentTarget).build(defaultVisit);
80
78
  case greyscript_core_1.ASTType.CallExpression:
81
- return new call_1.default(item, currentTarget).build(defaultVisit);
79
+ return new call_1.Call(item, currentTarget).build(defaultVisit);
82
80
  case greyscript_core_1.ASTType.CallStatement:
83
81
  return defaultVisit(item.expression);
84
82
  case greybel_core_1.ASTType.FeatureImportExpression: {
@@ -86,83 +84,124 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
86
84
  const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.path);
87
85
  if (stack.includes(target)) {
88
86
  console.warn('Found circluar dependency. Using noop operation.');
89
- return new noop_1.default(item, target);
87
+ return new noop_1.Noop(item, target);
90
88
  }
91
89
  const code = yield context.handler.resourceHandler.get(target);
92
90
  if (code == null) {
93
- throw new Error(`Cannot find import ${currentTarget}.`);
91
+ throw new error_1.PrepareError(`Cannot find import ${currentTarget}.`, {
92
+ target: currentTarget,
93
+ item
94
+ });
95
+ }
96
+ try {
97
+ const subVisit = visit.bind(null, context, [...stack, target]);
98
+ const importStatement = yield new import_1.Import(importExpr, target, code).build(subVisit);
99
+ return importStatement;
100
+ }
101
+ catch (err) {
102
+ throw new error_1.PrepareError(err.message, {
103
+ target: currentTarget,
104
+ item
105
+ });
94
106
  }
95
- const subVisit = visit.bind(null, context, [...stack, target]);
96
- const importStatement = yield new import_1.default(importExpr, target, code).build(subVisit);
97
- return importStatement;
98
107
  }
99
108
  case greybel_core_1.ASTType.FeatureIncludeExpression: {
100
109
  const includeExpr = item;
101
110
  const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, includeExpr.path);
102
111
  if (stack.includes(target)) {
103
112
  console.warn('Found circluar dependency. Using noop operation.');
104
- return new noop_1.default(item, target);
113
+ return new noop_1.Noop(item, target);
105
114
  }
106
115
  const code = yield context.handler.resourceHandler.get(target);
107
116
  if (code == null) {
108
- throw new Error(`Cannot find include ${currentTarget}.`);
117
+ throw new error_1.PrepareError(`Cannot find include ${currentTarget}.`, {
118
+ target: currentTarget,
119
+ item
120
+ });
121
+ }
122
+ try {
123
+ const subVisit = visit.bind(null, context, [...stack, target]);
124
+ const importStatement = yield new include_1.Include(includeExpr, target, code).build(subVisit);
125
+ return importStatement;
126
+ }
127
+ catch (err) {
128
+ throw new error_1.PrepareError(err.message, {
129
+ target: currentTarget,
130
+ item
131
+ });
109
132
  }
110
- const subVisit = visit.bind(null, context, [...stack, target]);
111
- const importStatement = yield new include_1.default(includeExpr, target, code).build(subVisit);
112
- return importStatement;
113
133
  }
114
134
  case greyscript_core_1.ASTType.ImportCodeExpression: {
115
135
  const importExpr = item;
136
+ if (importExpr.fileSystemDirectory === null) {
137
+ console.warn(`Ignoring dependency in ${currentTarget}. Using noop operation.`);
138
+ return new noop_1.Noop(item, currentTarget);
139
+ }
116
140
  const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.fileSystemDirectory);
117
141
  if (stack.includes(target)) {
118
- console.warn('Found circluar dependency. Using noop operation.');
119
- return new noop_1.default(item, target);
142
+ console.warn(`Found circluar dependency in ${currentTarget}. Using noop operation.`);
143
+ return new noop_1.Noop(item, target);
120
144
  }
121
145
  const code = yield context.handler.resourceHandler.get(target);
122
146
  if (code == null) {
123
- throw new Error(`Cannot find native import ${currentTarget}.`);
147
+ throw new error_1.PrepareError(`Cannot find native import ${currentTarget}.`, {
148
+ target: currentTarget,
149
+ item
150
+ });
151
+ }
152
+ try {
153
+ const subVisit = visit.bind(null, context, [...stack, target]);
154
+ const importStatement = yield new include_1.Include(importExpr, target, code).build(subVisit);
155
+ return importStatement;
156
+ }
157
+ catch (err) {
158
+ throw new error_1.PrepareError(err.message, {
159
+ target: currentTarget,
160
+ item
161
+ });
124
162
  }
125
- const subVisit = visit.bind(null, context, [...stack, target]);
126
- const importStatement = yield new include_1.default(importExpr, target, code).build(subVisit);
127
- return importStatement;
128
163
  }
129
164
  case greybel_core_1.ASTType.FeatureDebuggerExpression:
130
- return new debugger_statement_1.default(item, currentTarget);
165
+ return new debugger_statement_1.DebuggerStatement(item, currentTarget);
131
166
  case greybel_core_1.ASTType.FeatureEnvarExpression:
132
- return new envar_1.default(item, currentTarget);
167
+ return new envar_1.EnvarExpression(item, currentTarget);
133
168
  case greyscript_core_1.ASTType.BooleanLiteral:
134
169
  case greyscript_core_1.ASTType.StringLiteral:
135
170
  case greyscript_core_1.ASTType.NumericLiteral:
136
171
  case greyscript_core_1.ASTType.NilLiteral:
137
- return new literal_1.default(item, currentTarget).build(defaultVisit);
172
+ return new literal_1.Literal(item, currentTarget).build(defaultVisit);
138
173
  case greyscript_core_1.ASTType.EmptyExpression:
139
- return new noop_1.default(item, currentTarget).build(defaultVisit);
174
+ return new noop_1.Noop(item, currentTarget).build(defaultVisit);
140
175
  case greyscript_core_1.ASTType.IsaExpression:
141
176
  case greyscript_core_1.ASTType.BinaryExpression:
142
177
  case greyscript_core_1.ASTType.LogicalExpression:
143
- return new evaluate_1.default(item, currentTarget).build(defaultVisit);
178
+ return new evaluate_1.Evaluate(item, currentTarget).build(defaultVisit);
144
179
  case greyscript_core_1.ASTType.NegationExpression:
145
- return new not_1.default(item, currentTarget).build(defaultVisit);
180
+ return new not_1.Not(item, currentTarget).build(defaultVisit);
146
181
  case greyscript_core_1.ASTType.BinaryNegatedExpression:
147
- return new negated_binary_1.default(item, currentTarget).build(defaultVisit);
182
+ return new negated_binary_1.NegatedBinary(item, currentTarget).build(defaultVisit);
148
183
  case greyscript_core_1.ASTType.UnaryExpression: {
149
184
  const unaryExpr = item;
150
185
  if (unaryExpr.operator === 'new') {
151
- return new new_instance_1.default(unaryExpr).build(defaultVisit);
186
+ return new new_instance_1.NewInstance(unaryExpr).build(defaultVisit);
152
187
  }
153
188
  else if (unaryExpr.operator === '@') {
154
- return new function_reference_1.default(unaryExpr).build(defaultVisit);
189
+ return new function_reference_1.FunctionReference(unaryExpr).build(defaultVisit);
155
190
  }
156
- throw new Error('Unknown unary expression.');
191
+ throw new error_1.RuntimeError('Unknown unary expression.', {
192
+ target: currentTarget
193
+ });
157
194
  }
158
195
  case greyscript_core_1.ASTType.Chunk:
159
- return new chunk_1.default(item, currentTarget).build(defaultVisit);
196
+ return new chunk_1.Chunk(item, currentTarget).build(defaultVisit);
160
197
  case greyscript_core_1.ASTType.Comment:
161
- return new noop_1.default(item, currentTarget);
198
+ return new noop_1.Noop(item, currentTarget);
162
199
  case greyscript_core_1.ASTType.ParenthesisExpression:
163
200
  return defaultVisit(item.expression);
164
201
  default:
165
- throw new Error(`Unexpected AST type ${item.type}.`);
202
+ throw new error_1.RuntimeError(`Unexpected AST type ${item.type}.`, {
203
+ target: currentTarget
204
+ });
166
205
  }
167
206
  });
168
207
  class CPS {
@@ -174,4 +213,4 @@ class CPS {
174
213
  return this.__visit(item);
175
214
  }
176
215
  }
177
- exports.default = CPS;
216
+ exports.CPS = CPS;
@@ -5,14 +5,14 @@ export interface KeyEvent {
5
5
  export declare abstract class OutputHandler {
6
6
  abstract print(message: string, appendNewLine?: boolean): void;
7
7
  abstract progress(timeout: number): PromiseLike<void>;
8
- abstract waitForInput(isPassword: boolean): PromiseLike<string>;
9
- abstract waitForKeyPress(): PromiseLike<KeyEvent>;
8
+ abstract waitForInput(isPassword: boolean, message?: string): PromiseLike<string>;
9
+ abstract waitForKeyPress(message?: string): PromiseLike<KeyEvent>;
10
10
  abstract clear(): void;
11
11
  }
12
12
  export declare class DefaultOutputHandler extends OutputHandler {
13
13
  print(message: string, appendNewLine?: boolean): void;
14
14
  progress(timeout: number): PromiseLike<void>;
15
- waitForInput(_isPassword: boolean): PromiseLike<string>;
16
- waitForKeyPress(): PromiseLike<KeyEvent>;
15
+ waitForInput(_isPassword: boolean, _message?: string): PromiseLike<string>;
16
+ waitForKeyPress(_message?: string): PromiseLike<KeyEvent>;
17
17
  clear(): void;
18
18
  }
@@ -18,10 +18,10 @@ class DefaultOutputHandler extends OutputHandler {
18
18
  setTimeout(resolve, timeout);
19
19
  });
20
20
  }
21
- waitForInput(_isPassword) {
21
+ waitForInput(_isPassword, _message) {
22
22
  return Promise.resolve('test');
23
23
  }
24
- waitForKeyPress() {
24
+ waitForKeyPress(_message) {
25
25
  return Promise.resolve({
26
26
  keyCode: 13,
27
27
  code: 'Enter'
@@ -6,7 +6,7 @@ export interface HandlerContainerOptions {
6
6
  outputHandler?: OutputHandler;
7
7
  errorHandler?: ErrorHandler;
8
8
  }
9
- export default class HandlerContainer {
9
+ export declare class HandlerContainer {
10
10
  readonly resourceHandler: ResourceHandler;
11
11
  readonly outputHandler: OutputHandler;
12
12
  readonly errorHandler: ErrorHandler;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HandlerContainer = void 0;
3
4
  const error_1 = require("./handler/error");
4
5
  const output_1 = require("./handler/output");
5
6
  const resource_1 = require("./handler/resource");
@@ -11,4 +12,4 @@ class HandlerContainer {
11
12
  this.errorHandler = (options === null || options === void 0 ? void 0 : options.errorHandler) || new error_1.DefaultErrorHandler();
12
13
  }
13
14
  }
14
- exports.default = HandlerContainer;
15
+ exports.HandlerContainer = HandlerContainer;
package/dist/index.d.ts CHANGED
@@ -1,46 +1,47 @@
1
- export { ContextForkOptions, ContextOptions, ContextState, ContextType, Debugger, FunctionState, LoopState, default as OperationContext, ProcessState, Scope } from './context';
2
- export { default as CPS, CPSContext } from './cps';
1
+ export { ContextForkOptions, ContextOptions, ContextState, ContextType, Debugger, FunctionState, LoopState, OperationContext, ProcessState, Scope } from './context';
2
+ export { CPS, CPSContext } from './cps';
3
3
  export { DefaultErrorHandler, ErrorHandler } from './handler/error';
4
4
  export { DefaultOutputHandler, KeyEvent, OutputHandler } from './handler/output';
5
5
  export { DefaultResourceHandler, ResourceHandler } from './handler/resource';
6
- export { default as HandlerContainer } from './handler-container';
7
- export { default as Interpreter, InterpreterOptions } from './interpreter';
8
- export { default as Assign } from './operations/assign';
9
- export { default as Block, IsEOL } from './operations/block';
10
- export { default as Break } from './operations/break';
11
- export { default as Call } from './operations/call';
12
- export { default as Chunk } from './operations/chunk';
13
- export { default as Continue } from './operations/continue';
14
- export { default as DebuggerStatement } from './operations/debugger-statement';
15
- export { default as Evaluate, GenericProcessorHandler, handle, handleInterface, handleList, handleMap, handleNumber, handleString, ListProcessorHandler, MapProcessorHandler, NumberProcessorHandler, ProcessorHandler, ProcessorHandlerFunction, StringProcessorHandler } from './operations/evaluate';
16
- export { default as For } from './operations/for';
17
- export { default as FunctionOpertion } from './operations/function';
18
- export { Clause, default as IfStatement } from './operations/if-statement';
19
- export { default as Import } from './operations/import';
20
- export { default as Include } from './operations/include';
21
- export { default as List } from './operations/list';
22
- export { default as Literal } from './operations/literal';
23
- export { default as MapOperation } from './operations/map';
24
- export { default as NegatedBinary } from './operations/negated-binary';
25
- export { default as NewInstance } from './operations/new-instance';
26
- export { default as Noop } from './operations/noop';
27
- export { default as Not } from './operations/not';
28
- export { CPSVisit, default as Operation } from './operations/operation';
29
- export { default as Reference } from './operations/reference';
30
- export { IdentifierSegment, IndexSegment, OperationSegment, default as Resolve, ResolveResult, Segment } from './operations/resolve';
31
- export { default as Return } from './operations/return';
32
- export { default as While } from './operations/while';
33
- export { default as CustomValue } from './types/base';
34
- export { default as CustomBoolean } from './types/boolean';
35
- export { default as DefaultType } from './types/default';
36
- export { Argument, Callback, default as CustomFunction } from './types/function';
37
- export { default as CustomInterface, CustomInterfaceIterator } from './types/interface';
38
- export { default as CustomList, CustomListIterator } from './types/list';
39
- export { default as CustomMap, CustomMapIterator } from './types/map';
40
- export { default as CustomNil } from './types/nil';
41
- export { default as CustomNumber } from './types/number';
42
- export { default as CustomString, CustomStringIterator } from './types/string';
6
+ export { HandlerContainer } from './handler-container';
7
+ export { Interpreter, InterpreterOptions } from './interpreter';
8
+ export { Assign } from './operations/assign';
9
+ export { Block, IsEOL } from './operations/block';
10
+ export { Break } from './operations/break';
11
+ export { Call } from './operations/call';
12
+ export { Chunk } from './operations/chunk';
13
+ export { Continue } from './operations/continue';
14
+ export { DebuggerStatement } from './operations/debugger-statement';
15
+ export { Evaluate, GenericProcessorHandler, handle, handleInterface, handleList, handleMap, handleNumber, handleString, ListProcessorHandler, MapProcessorHandler, NumberProcessorHandler, ProcessorHandler, ProcessorHandlerFunction, StringProcessorHandler } from './operations/evaluate';
16
+ export { For } from './operations/for';
17
+ export { FunctionOperation } from './operations/function';
18
+ export { Clause, IfStatement } from './operations/if-statement';
19
+ export { Import } from './operations/import';
20
+ export { Include } from './operations/include';
21
+ export { List } from './operations/list';
22
+ export { Literal } from './operations/literal';
23
+ export { MapOperation } from './operations/map';
24
+ export { NegatedBinary } from './operations/negated-binary';
25
+ export { NewInstance } from './operations/new-instance';
26
+ export { Noop } from './operations/noop';
27
+ export { Not } from './operations/not';
28
+ export { CPSVisit, Operation } from './operations/operation';
29
+ export { Reference } from './operations/reference';
30
+ export { IdentifierSegment, IndexSegment, OperationSegment, Resolve, ResolveResult, Segment } from './operations/resolve';
31
+ export { Return } from './operations/return';
32
+ export { While } from './operations/while';
33
+ export { CustomValue } from './types/base';
34
+ export { CustomBoolean } from './types/boolean';
35
+ export { DefaultType } from './types/default';
36
+ export { Argument, Callback, CustomFunction } from './types/function';
37
+ export { CustomInterface, CustomInterfaceIterator } from './types/interface';
38
+ export { CustomList, CustomListIterator } from './types/list';
39
+ export { CustomMap, CustomMapIterator } from './types/map';
40
+ export { CustomNil } from './types/nil';
41
+ export { CustomNumber } from './types/number';
42
+ export { CustomString, CustomStringIterator } from './types/string';
43
43
  export { CustomObject, CustomValueWithIntrinsics } from './types/with-intrinsics';
44
- export { default as deepEqual } from './utils/deep-equal';
45
- export { default as ObjectValue } from './utils/object-value';
46
- export { default as Path } from './utils/path';
44
+ export { deepEqual } from './utils/deep-equal';
45
+ export { PrepareError, RuntimeError } from './utils/error';
46
+ export { ObjectValue } from './utils/object-value';
47
+ export { Path } from './utils/path';