greybel-interpreter 2.1.4 → 2.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/cps.js CHANGED
@@ -208,12 +208,13 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
208
208
  return new noop_1.Noop(item, currentTarget);
209
209
  case greyscript_core_1.ASTType.ParenthesisExpression:
210
210
  return defaultVisit(item.expression);
211
- default:
211
+ default: {
212
212
  const range = new greyscript_core_1.ASTRange(item.start, item.end);
213
213
  throw new error_1.PrepareError(`Unexpected AST type ${item.type}`, {
214
214
  target: currentTarget,
215
215
  range
216
216
  });
217
+ }
217
218
  }
218
219
  });
219
220
  class CPS {
@@ -2,6 +2,7 @@ import { ASTEvaluationExpression } from 'greyscript-core';
2
2
  import { OperationContext } from '../context';
3
3
  import { CustomValue } from '../types/base';
4
4
  import { CustomBoolean } from '../types/boolean';
5
+ import { CustomList } from '../types/list';
5
6
  import { CPSVisit, Operation } from './operation';
6
7
  export interface ProcessorHandlerFunction {
7
8
  (op: string, a: CustomValue, b: CustomValue): CustomValue;
@@ -13,6 +14,8 @@ export declare const GenericProcessorHandler: ProcessorHandler;
13
14
  export declare const NumberProcessorHandler: ProcessorHandler;
14
15
  export declare const multiplyString: (a: CustomValue, b: CustomValue) => CustomValue;
15
16
  export declare const StringProcessorHandler: ProcessorHandler;
17
+ export declare const multiplyList: (a: CustomList, b: CustomValue) => CustomValue;
18
+ export declare const divideList: (a: CustomList, b: CustomValue) => CustomValue;
16
19
  export declare const ListProcessorHandler: ProcessorHandler;
17
20
  export declare const MapProcessorHandler: ProcessorHandler;
18
21
  export declare const InterfaceProcessorHandler: ProcessorHandler;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Evaluate = exports.handle = exports.handleFunction = exports.handleNil = exports.handleInterface = exports.handleMap = exports.handleList = exports.handleString = exports.handleNumber = exports.FunctionProcessorHandler = exports.NilProcessorHandler = exports.InterfaceProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.StringProcessorHandler = exports.multiplyString = exports.NumberProcessorHandler = exports.GenericProcessorHandler = void 0;
12
+ exports.Evaluate = exports.handle = exports.handleFunction = exports.handleNil = exports.handleInterface = exports.handleMap = exports.handleList = exports.handleString = exports.handleNumber = exports.FunctionProcessorHandler = exports.NilProcessorHandler = exports.InterfaceProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.divideList = exports.multiplyList = exports.StringProcessorHandler = exports.multiplyString = exports.NumberProcessorHandler = exports.GenericProcessorHandler = void 0;
13
13
  const greyscript_core_1 = require("greyscript-core");
14
14
  const boolean_1 = require("../types/boolean");
15
15
  const default_1 = require("../types/default");
@@ -60,6 +60,32 @@ exports.StringProcessorHandler = {
60
60
  [greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString().length <= b.toString().length),
61
61
  [greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString() !== b.toString())
62
62
  };
63
+ const multiplyList = (a, b) => {
64
+ const factor = b.toNumber();
65
+ if (factor <= 0) {
66
+ return new list_1.CustomList();
67
+ }
68
+ const newListValue = [];
69
+ const max = Math.floor(a.value.length * factor);
70
+ for (let index = 0; index < max; index++) {
71
+ newListValue.push(a.value[index % a.value.length]);
72
+ }
73
+ return new list_1.CustomList(newListValue);
74
+ };
75
+ exports.multiplyList = multiplyList;
76
+ const divideList = (a, b) => {
77
+ const factor = 1 / b.toNumber();
78
+ if (factor <= 0) {
79
+ return new list_1.CustomList();
80
+ }
81
+ const newListValue = [];
82
+ const max = Math.floor(a.value.length * factor);
83
+ for (let index = 0; index < max; index++) {
84
+ newListValue.push(a.value[index % a.value.length]);
85
+ }
86
+ return new list_1.CustomList(newListValue);
87
+ };
88
+ exports.divideList = divideList;
63
89
  exports.ListProcessorHandler = {
64
90
  [greyscript_core_1.Operator.Plus]: (left, right) => {
65
91
  if (right instanceof list_1.CustomList) {
@@ -102,7 +128,9 @@ exports.ListProcessorHandler = {
102
128
  return new boolean_1.CustomBoolean(!(0, deep_equal_1.deepEqual)(left, right));
103
129
  }
104
130
  return default_1.DefaultType.Void;
105
- }
131
+ },
132
+ [greyscript_core_1.Operator.Asterik]: (left, right) => (0, exports.multiplyList)(left, right),
133
+ [greyscript_core_1.Operator.Slash]: (left, right) => (0, exports.divideList)(left, right)
106
134
  };
107
135
  exports.MapProcessorHandler = {
108
136
  [greyscript_core_1.Operator.Plus]: (left, right) => {
@@ -250,12 +278,16 @@ const handle = (op, a, b) => {
250
278
  a.getCustomType() !== b.getCustomType()) {
251
279
  return default_1.DefaultType.True;
252
280
  }
253
- if (a instanceof string_1.CustomString || b instanceof string_1.CustomString) {
254
- return (0, exports.handleString)(op, a, b);
281
+ if ((a instanceof string_1.CustomString || b instanceof string_1.CustomString) &&
282
+ op === greyscript_core_1.Operator.Plus) {
283
+ return exports.StringProcessorHandler[op](a, b);
255
284
  }
256
- else if (a instanceof number_1.CustomNumber || b instanceof number_1.CustomNumber) {
285
+ else if (a instanceof number_1.CustomNumber) {
257
286
  return (0, exports.handleNumber)(op, a, b);
258
287
  }
288
+ else if (a instanceof string_1.CustomString) {
289
+ return (0, exports.handleString)(op, a, b);
290
+ }
259
291
  else if (a instanceof list_1.CustomList) {
260
292
  return (0, exports.handleList)(op, a, b);
261
293
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "2.1.4",
3
+ "version": "2.1.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.3",
52
- "greyscript-core": "^0.9.5"
51
+ "greybel-core": "^0.9.4",
52
+ "greyscript-core": "^0.9.6"
53
53
  },
54
54
  "keywords": [
55
55
  "greyscript",