greybel-interpreter 1.7.0 → 1.7.2
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.d.ts +9 -9
- package/dist/context.js +19 -22
- package/dist/cps.d.ts +3 -3
- package/dist/cps.js +56 -59
- package/dist/handler/output.d.ts +6 -7
- package/dist/handler/output.js +6 -11
- package/dist/handler-container.d.ts +1 -1
- package/dist/handler-container.js +2 -1
- package/dist/index.d.ts +42 -42
- package/dist/index.js +43 -46
- package/dist/interpreter.d.ts +9 -9
- package/dist/interpreter.js +33 -59
- package/dist/operations/assign.d.ts +5 -5
- package/dist/operations/assign.js +9 -11
- package/dist/operations/block.d.ts +4 -4
- package/dist/operations/block.js +6 -8
- package/dist/operations/break.d.ts +4 -4
- package/dist/operations/break.js +6 -8
- package/dist/operations/call.d.ts +5 -5
- package/dist/operations/call.js +12 -14
- package/dist/operations/chunk.d.ts +6 -6
- package/dist/operations/chunk.js +8 -10
- package/dist/operations/continue.d.ts +4 -4
- package/dist/operations/continue.js +6 -8
- package/dist/operations/debugger-statement.d.ts +5 -5
- package/dist/operations/debugger-statement.js +6 -8
- package/dist/operations/envar.d.ts +5 -5
- package/dist/operations/envar.js +6 -8
- package/dist/operations/evaluate.d.ts +6 -5
- package/dist/operations/evaluate.js +109 -112
- package/dist/operations/for.d.ts +6 -6
- package/dist/operations/for.js +15 -17
- package/dist/operations/function-reference.d.ts +5 -5
- package/dist/operations/function-reference.js +8 -10
- package/dist/operations/function.d.ts +5 -5
- package/dist/operations/function.js +17 -20
- package/dist/operations/if-statement.d.ts +6 -6
- package/dist/operations/if-statement.js +12 -15
- package/dist/operations/import.d.ts +7 -7
- package/dist/operations/import.js +15 -18
- package/dist/operations/include.d.ts +5 -5
- package/dist/operations/include.js +4 -6
- package/dist/operations/list.d.ts +5 -5
- package/dist/operations/list.js +6 -8
- package/dist/operations/literal.d.ts +5 -5
- package/dist/operations/literal.js +12 -14
- package/dist/operations/map.d.ts +5 -5
- package/dist/operations/map.js +8 -10
- package/dist/operations/negated-binary.d.ts +5 -5
- package/dist/operations/negated-binary.js +7 -9
- package/dist/operations/new-instance.d.ts +5 -5
- package/dist/operations/new-instance.js +8 -10
- package/dist/operations/noop.d.ts +5 -5
- package/dist/operations/noop.js +6 -8
- package/dist/operations/not.d.ts +5 -5
- package/dist/operations/not.js +6 -8
- package/dist/operations/operation.d.ts +3 -3
- package/dist/operations/operation.js +2 -1
- package/dist/operations/reference.d.ts +4 -4
- package/dist/operations/reference.js +4 -6
- package/dist/operations/resolve.d.ts +6 -6
- package/dist/operations/resolve.js +27 -30
- package/dist/operations/return.d.ts +5 -5
- package/dist/operations/return.js +8 -10
- package/dist/operations/while.d.ts +6 -6
- package/dist/operations/while.js +9 -11
- package/dist/types/base.d.ts +1 -1
- package/dist/types/base.js +2 -1
- package/dist/types/boolean.d.ts +2 -2
- package/dist/types/boolean.js +4 -7
- package/dist/types/default.d.ts +7 -7
- package/dist/types/default.js +9 -8
- package/dist/types/function.d.ts +5 -5
- package/dist/types/function.js +27 -30
- package/dist/types/interface.d.ts +4 -4
- package/dist/types/interface.js +10 -13
- package/dist/types/list.d.ts +4 -4
- package/dist/types/list.js +21 -24
- package/dist/types/map.d.ts +5 -5
- package/dist/types/map.js +26 -29
- package/dist/types/nil.d.ts +2 -2
- package/dist/types/nil.js +4 -7
- package/dist/types/number.d.ts +4 -4
- package/dist/types/number.js +8 -11
- package/dist/types/string.d.ts +4 -4
- package/dist/types/string.js +19 -22
- package/dist/types/with-intrinsics.d.ts +4 -4
- package/dist/types/with-intrinsics.js +2 -5
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +4 -3
- package/dist/utils/object-value.d.ts +2 -2
- package/dist/utils/object-value.js +6 -8
- package/dist/utils/path.d.ts +1 -1
- package/dist/utils/path.js +2 -1
- package/package.json +2 -3
package/dist/operations/chunk.js
CHANGED
|
@@ -8,14 +8,12 @@ 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
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
12
|
+
exports.Chunk = void 0;
|
|
13
|
+
const string_1 = require("../types/string");
|
|
14
|
+
const block_1 = require("./block");
|
|
15
|
+
const operation_1 = require("./operation");
|
|
16
|
+
class Chunk extends operation_1.Operation {
|
|
19
17
|
constructor(item, target) {
|
|
20
18
|
super(null, target);
|
|
21
19
|
this.item = item;
|
|
@@ -23,13 +21,13 @@ class Chunk extends operation_1.default {
|
|
|
23
21
|
build(visit) {
|
|
24
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
23
|
const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
|
|
26
|
-
this.block = new block_1.
|
|
24
|
+
this.block = new block_1.Block(this.item, stack);
|
|
27
25
|
return this;
|
|
28
26
|
});
|
|
29
27
|
}
|
|
30
28
|
handle(ctx) {
|
|
31
|
-
ctx.set(new string_1.
|
|
29
|
+
ctx.set(new string_1.CustomString('locals'), ctx.locals.scope);
|
|
32
30
|
return this.block.handle(ctx);
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
|
-
exports.
|
|
33
|
+
exports.Chunk = Chunk;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ASTBase } from 'greyscript-core';
|
|
2
|
-
import OperationContext from '../context';
|
|
3
|
-
import CustomValue from '../types/base';
|
|
4
|
-
import
|
|
5
|
-
export
|
|
2
|
+
import { OperationContext } from '../context';
|
|
3
|
+
import { CustomValue } from '../types/base';
|
|
4
|
+
import { CPSVisit, Operation } from './operation';
|
|
5
|
+
export declare class Continue extends Operation {
|
|
6
6
|
readonly item: ASTBase;
|
|
7
7
|
constructor(item: ASTBase, target?: string);
|
|
8
8
|
build(_visit: CPSVisit): Promise<Continue>;
|
|
@@ -1,11 +1,9 @@
|
|
|
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
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
3
|
+
exports.Continue = void 0;
|
|
4
|
+
const default_1 = require("../types/default");
|
|
5
|
+
const operation_1 = require("./operation");
|
|
6
|
+
class Continue extends operation_1.Operation {
|
|
9
7
|
constructor(item, target) {
|
|
10
8
|
super(null, target);
|
|
11
9
|
this.item = item;
|
|
@@ -17,7 +15,7 @@ class Continue extends operation_1.default {
|
|
|
17
15
|
if (ctx.loopState !== null) {
|
|
18
16
|
ctx.loopState.isContinue = true;
|
|
19
17
|
}
|
|
20
|
-
return Promise.resolve(default_1.
|
|
18
|
+
return Promise.resolve(default_1.DefaultType.Void);
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
exports.
|
|
21
|
+
exports.Continue = Continue;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ASTBase } from 'greyscript-core';
|
|
2
|
-
import
|
|
3
|
-
import CustomValue from '../types/base';
|
|
4
|
-
import
|
|
5
|
-
export
|
|
2
|
+
import { OperationContext } from '../context';
|
|
3
|
+
import { CustomValue } from '../types/base';
|
|
4
|
+
import { CPSVisit, Operation } from './operation';
|
|
5
|
+
export declare class DebuggerStatement extends Operation {
|
|
6
6
|
readonly item: ASTBase;
|
|
7
7
|
constructor(item: ASTBase, target?: string);
|
|
8
8
|
build(_visit: CPSVisit): Promise<DebuggerStatement>;
|
|
9
|
-
handle(ctx:
|
|
9
|
+
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
10
10
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
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
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
3
|
+
exports.DebuggerStatement = void 0;
|
|
4
|
+
const default_1 = require("../types/default");
|
|
5
|
+
const operation_1 = require("./operation");
|
|
6
|
+
class DebuggerStatement extends operation_1.Operation {
|
|
9
7
|
constructor(item, target) {
|
|
10
8
|
super(null, target);
|
|
11
9
|
this.item = item;
|
|
@@ -15,7 +13,7 @@ class DebuggerStatement extends operation_1.default {
|
|
|
15
13
|
}
|
|
16
14
|
handle(ctx) {
|
|
17
15
|
ctx.debugger.setBreakpoint(true);
|
|
18
|
-
return Promise.resolve(default_1.
|
|
16
|
+
return Promise.resolve(default_1.DefaultType.Void);
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
|
-
exports.
|
|
19
|
+
exports.DebuggerStatement = DebuggerStatement;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ASTFeatureEnvarExpression } from 'greybel-core';
|
|
2
|
-
import
|
|
3
|
-
import CustomValue from '../types/base';
|
|
4
|
-
import
|
|
5
|
-
export
|
|
2
|
+
import { OperationContext } from '../context';
|
|
3
|
+
import { CustomValue } from '../types/base';
|
|
4
|
+
import { CPSVisit, Operation } from './operation';
|
|
5
|
+
export declare class EnvarExpression extends Operation {
|
|
6
6
|
readonly item: ASTFeatureEnvarExpression;
|
|
7
7
|
constructor(item: ASTFeatureEnvarExpression, target?: string);
|
|
8
8
|
build(_visit: CPSVisit): Promise<Operation>;
|
|
9
|
-
handle(ctx:
|
|
9
|
+
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
10
10
|
}
|
package/dist/operations/envar.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
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
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
3
|
+
exports.EnvarExpression = void 0;
|
|
4
|
+
const string_1 = require("../types/string");
|
|
5
|
+
const operation_1 = require("./operation");
|
|
6
|
+
class EnvarExpression extends operation_1.Operation {
|
|
9
7
|
constructor(item, target) {
|
|
10
8
|
super(null, target);
|
|
11
9
|
this.item = item;
|
|
@@ -15,9 +13,9 @@ class EnvarExpression extends operation_1.default {
|
|
|
15
13
|
}
|
|
16
14
|
handle(ctx) {
|
|
17
15
|
if (ctx.environmentVariables.has(this.item.name)) {
|
|
18
|
-
return Promise.resolve(new string_1.
|
|
16
|
+
return Promise.resolve(new string_1.CustomString(ctx.environmentVariables.get(this.item.name)));
|
|
19
17
|
}
|
|
20
18
|
throw new Error('Unknown environment variable.');
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
exports.
|
|
21
|
+
exports.EnvarExpression = EnvarExpression;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ASTEvaluationExpression } from 'greyscript-core';
|
|
2
|
-
import OperationContext from '../context';
|
|
3
|
-
import CustomValue from '../types/base';
|
|
4
|
-
import
|
|
2
|
+
import { OperationContext } from '../context';
|
|
3
|
+
import { CustomValue } from '../types/base';
|
|
4
|
+
import { CustomBoolean } from '../types/boolean';
|
|
5
|
+
import { CPSVisit, Operation } from './operation';
|
|
5
6
|
export interface ProcessorHandlerFunction {
|
|
6
7
|
(op: string, a: CustomValue, b: CustomValue): CustomValue;
|
|
7
8
|
}
|
|
@@ -25,7 +26,7 @@ export declare const handleInterface: ProcessorHandlerFunction;
|
|
|
25
26
|
export declare const handleNil: ProcessorHandlerFunction;
|
|
26
27
|
export declare const handleFunction: ProcessorHandlerFunction;
|
|
27
28
|
export declare const handle: (op: string, a: CustomValue, b: CustomValue) => CustomValue;
|
|
28
|
-
export
|
|
29
|
+
export declare class Evaluate extends Operation {
|
|
29
30
|
readonly item: ASTEvaluationExpression;
|
|
30
31
|
type: string;
|
|
31
32
|
op: string;
|
|
@@ -34,7 +35,7 @@ export default class Evaluate extends Operation {
|
|
|
34
35
|
constructor(item: ASTEvaluationExpression, target?: string);
|
|
35
36
|
build(visit: CPSVisit): Promise<Operation>;
|
|
36
37
|
resolveBinaryExpression(ctx: OperationContext, expr: Evaluate): Promise<CustomValue>;
|
|
37
|
-
resolveLogicalExpression(ctx: OperationContext, expr: Evaluate): Promise<CustomValue>;
|
|
38
|
+
resolveLogicalExpression(ctx: OperationContext, expr: Evaluate): Promise<CustomValue | CustomBoolean>;
|
|
38
39
|
resolve(ctx: OperationContext, op: Operation): Promise<CustomValue>;
|
|
39
40
|
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
40
41
|
}
|
|
@@ -8,160 +8,157 @@ 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.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.StringProcessorHandler = exports.multiplyString = exports.NumberProcessorHandler = exports.GenericProcessorHandler = void 0;
|
|
16
13
|
const greyscript_core_1 = require("greyscript-core");
|
|
17
|
-
const boolean_1 =
|
|
18
|
-
const default_1 =
|
|
19
|
-
const function_1 =
|
|
20
|
-
const interface_1 =
|
|
21
|
-
const list_1 =
|
|
22
|
-
const map_1 =
|
|
23
|
-
const nil_1 =
|
|
24
|
-
const number_1 =
|
|
25
|
-
const string_1 =
|
|
26
|
-
const deep_equal_1 =
|
|
27
|
-
const operation_1 =
|
|
14
|
+
const boolean_1 = require("../types/boolean");
|
|
15
|
+
const default_1 = require("../types/default");
|
|
16
|
+
const function_1 = require("../types/function");
|
|
17
|
+
const interface_1 = require("../types/interface");
|
|
18
|
+
const list_1 = require("../types/list");
|
|
19
|
+
const map_1 = require("../types/map");
|
|
20
|
+
const nil_1 = require("../types/nil");
|
|
21
|
+
const number_1 = require("../types/number");
|
|
22
|
+
const string_1 = require("../types/string");
|
|
23
|
+
const deep_equal_1 = require("../utils/deep-equal");
|
|
24
|
+
const operation_1 = require("./operation");
|
|
28
25
|
exports.GenericProcessorHandler = {
|
|
29
|
-
[greyscript_core_1.Operator.And]: (a, b) => new boolean_1.
|
|
30
|
-
[greyscript_core_1.Operator.Or]: (a, b) => new boolean_1.
|
|
26
|
+
[greyscript_core_1.Operator.And]: (a, b) => new boolean_1.CustomBoolean(a.toTruthy() && b.toTruthy()),
|
|
27
|
+
[greyscript_core_1.Operator.Or]: (a, b) => new boolean_1.CustomBoolean(a.toTruthy() || b.toTruthy())
|
|
31
28
|
};
|
|
32
29
|
exports.NumberProcessorHandler = {
|
|
33
|
-
[greyscript_core_1.Operator.Plus]: (a, b) => new number_1.
|
|
34
|
-
[greyscript_core_1.Operator.Minus]: (a, b) => new number_1.
|
|
35
|
-
[greyscript_core_1.Operator.Slash]: (a, b) => new number_1.
|
|
36
|
-
[greyscript_core_1.Operator.Asterik]: (a, b) => new number_1.
|
|
37
|
-
[greyscript_core_1.Operator.Power]: (a, b) => new number_1.
|
|
38
|
-
[greyscript_core_1.Operator.BitwiseOr]: (a, b) => new number_1.
|
|
39
|
-
[greyscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.
|
|
40
|
-
[greyscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.
|
|
41
|
-
[greyscript_core_1.Operator.LeftShift]: (a, b) => new number_1.
|
|
42
|
-
[greyscript_core_1.Operator.RightShift]: (a, b) => new number_1.
|
|
43
|
-
[greyscript_core_1.Operator.UnsignedRightShift]: (a, b) => new number_1.
|
|
44
|
-
[greyscript_core_1.Operator.BitwiseAnd]: (a, b) => new number_1.
|
|
45
|
-
[greyscript_core_1.Operator.PercentSign]: (a, b) => new number_1.
|
|
46
|
-
[greyscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.
|
|
47
|
-
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.
|
|
48
|
-
[greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.
|
|
49
|
-
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.
|
|
30
|
+
[greyscript_core_1.Operator.Plus]: (a, b) => new number_1.CustomNumber(a.toNumber() + b.toNumber()),
|
|
31
|
+
[greyscript_core_1.Operator.Minus]: (a, b) => new number_1.CustomNumber(a.toNumber() - b.toNumber()),
|
|
32
|
+
[greyscript_core_1.Operator.Slash]: (a, b) => new number_1.CustomNumber(a.toNumber() / b.toNumber()),
|
|
33
|
+
[greyscript_core_1.Operator.Asterik]: (a, b) => new number_1.CustomNumber(a.toNumber() * b.toNumber()),
|
|
34
|
+
[greyscript_core_1.Operator.Power]: (a, b) => new number_1.CustomNumber(Math.pow(a.toNumber(), b.toNumber())),
|
|
35
|
+
[greyscript_core_1.Operator.BitwiseOr]: (a, b) => new number_1.CustomNumber(a.toInt() | b.toInt()),
|
|
36
|
+
[greyscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() < b.toNumber()),
|
|
37
|
+
[greyscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() > b.toNumber()),
|
|
38
|
+
[greyscript_core_1.Operator.LeftShift]: (a, b) => new number_1.CustomNumber(a.toInt() << b.toInt()),
|
|
39
|
+
[greyscript_core_1.Operator.RightShift]: (a, b) => new number_1.CustomNumber(a.toInt() >> b.toInt()),
|
|
40
|
+
[greyscript_core_1.Operator.UnsignedRightShift]: (a, b) => new number_1.CustomNumber(a.toInt() >> b.toInt()),
|
|
41
|
+
[greyscript_core_1.Operator.BitwiseAnd]: (a, b) => new number_1.CustomNumber(a.toInt() & b.toInt()),
|
|
42
|
+
[greyscript_core_1.Operator.PercentSign]: (a, b) => new number_1.CustomNumber(a.toNumber() % b.toNumber()),
|
|
43
|
+
[greyscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() >= b.toNumber()),
|
|
44
|
+
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() === b.toNumber()),
|
|
45
|
+
[greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() <= b.toNumber()),
|
|
46
|
+
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() !== b.toNumber())
|
|
50
47
|
};
|
|
51
48
|
const multiplyString = (a, b) => {
|
|
52
49
|
const multiStr = new Array(b.toNumber()).fill(a.toString()).join('');
|
|
53
|
-
return new string_1.
|
|
50
|
+
return new string_1.CustomString(multiStr);
|
|
54
51
|
};
|
|
55
52
|
exports.multiplyString = multiplyString;
|
|
56
53
|
exports.StringProcessorHandler = {
|
|
57
|
-
[greyscript_core_1.Operator.Plus]: (a, b) => new string_1.
|
|
54
|
+
[greyscript_core_1.Operator.Plus]: (a, b) => new string_1.CustomString(a.toString() + b.toString()),
|
|
58
55
|
[greyscript_core_1.Operator.Asterik]: (a, b) => (0, exports.multiplyString)(a, b),
|
|
59
|
-
[greyscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.
|
|
60
|
-
[greyscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.
|
|
61
|
-
[greyscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.
|
|
62
|
-
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.
|
|
63
|
-
[greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.
|
|
64
|
-
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.
|
|
56
|
+
[greyscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.CustomBoolean(a.toString().length < b.toString().length),
|
|
57
|
+
[greyscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.CustomBoolean(a.toString().length > b.toString().length),
|
|
58
|
+
[greyscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString().length >= b.toString().length),
|
|
59
|
+
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.CustomBoolean(a.toString() === b.toString()),
|
|
60
|
+
[greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString().length <= b.toString().length),
|
|
61
|
+
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString() !== b.toString())
|
|
65
62
|
};
|
|
66
63
|
exports.ListProcessorHandler = {
|
|
67
64
|
[greyscript_core_1.Operator.Plus]: (left, right) => {
|
|
68
|
-
if (right instanceof list_1.
|
|
65
|
+
if (right instanceof list_1.CustomList) {
|
|
69
66
|
return left.fork().extend(right);
|
|
70
67
|
}
|
|
71
68
|
return left;
|
|
72
69
|
},
|
|
73
70
|
[greyscript_core_1.Operator.LessThan]: (left, right) => {
|
|
74
|
-
if (right instanceof list_1.
|
|
75
|
-
return new boolean_1.
|
|
71
|
+
if (right instanceof list_1.CustomList) {
|
|
72
|
+
return new boolean_1.CustomBoolean(left.value.length < right.value.length);
|
|
76
73
|
}
|
|
77
|
-
return default_1.
|
|
74
|
+
return default_1.DefaultType.Void;
|
|
78
75
|
},
|
|
79
76
|
[greyscript_core_1.Operator.GreaterThan]: (left, right) => {
|
|
80
|
-
if (right instanceof list_1.
|
|
81
|
-
return new boolean_1.
|
|
77
|
+
if (right instanceof list_1.CustomList) {
|
|
78
|
+
return new boolean_1.CustomBoolean(left.value.length > right.value.length);
|
|
82
79
|
}
|
|
83
|
-
return default_1.
|
|
80
|
+
return default_1.DefaultType.Void;
|
|
84
81
|
},
|
|
85
82
|
[greyscript_core_1.Operator.GreaterThanOrEqual]: (left, right) => {
|
|
86
|
-
if (right instanceof list_1.
|
|
87
|
-
return new boolean_1.
|
|
83
|
+
if (right instanceof list_1.CustomList) {
|
|
84
|
+
return new boolean_1.CustomBoolean(left.value.length >= right.value.length);
|
|
88
85
|
}
|
|
89
|
-
return default_1.
|
|
86
|
+
return default_1.DefaultType.Void;
|
|
90
87
|
},
|
|
91
88
|
[greyscript_core_1.Operator.Equal]: (left, right) => {
|
|
92
|
-
if (right instanceof list_1.
|
|
93
|
-
return new boolean_1.
|
|
89
|
+
if (right instanceof list_1.CustomList) {
|
|
90
|
+
return new boolean_1.CustomBoolean((0, deep_equal_1.deepEqual)(left, right));
|
|
94
91
|
}
|
|
95
|
-
return default_1.
|
|
92
|
+
return default_1.DefaultType.Void;
|
|
96
93
|
},
|
|
97
94
|
[greyscript_core_1.Operator.LessThanOrEqual]: (left, right) => {
|
|
98
|
-
if (right instanceof list_1.
|
|
99
|
-
return new boolean_1.
|
|
95
|
+
if (right instanceof list_1.CustomList) {
|
|
96
|
+
return new boolean_1.CustomBoolean(left.value.length <= right.value.length);
|
|
100
97
|
}
|
|
101
|
-
return default_1.
|
|
98
|
+
return default_1.DefaultType.Void;
|
|
102
99
|
},
|
|
103
100
|
[greyscript_core_1.Operator.NotEqual]: (left, right) => {
|
|
104
|
-
if (right instanceof list_1.
|
|
105
|
-
return new boolean_1.
|
|
101
|
+
if (right instanceof list_1.CustomList) {
|
|
102
|
+
return new boolean_1.CustomBoolean(!(0, deep_equal_1.deepEqual)(left, right));
|
|
106
103
|
}
|
|
107
|
-
return default_1.
|
|
104
|
+
return default_1.DefaultType.Void;
|
|
108
105
|
}
|
|
109
106
|
};
|
|
110
107
|
exports.MapProcessorHandler = {
|
|
111
108
|
[greyscript_core_1.Operator.Plus]: (left, right) => {
|
|
112
|
-
if (right instanceof map_1.
|
|
109
|
+
if (right instanceof map_1.CustomMap) {
|
|
113
110
|
return left.fork().extend(right);
|
|
114
111
|
}
|
|
115
112
|
return left;
|
|
116
113
|
},
|
|
117
114
|
[greyscript_core_1.Operator.LessThan]: (left, right) => {
|
|
118
|
-
if (right instanceof map_1.
|
|
119
|
-
return new boolean_1.
|
|
115
|
+
if (right instanceof map_1.CustomMap) {
|
|
116
|
+
return new boolean_1.CustomBoolean(left.value.size < right.value.size);
|
|
120
117
|
}
|
|
121
|
-
return default_1.
|
|
118
|
+
return default_1.DefaultType.Void;
|
|
122
119
|
},
|
|
123
120
|
[greyscript_core_1.Operator.GreaterThan]: (left, right) => {
|
|
124
|
-
if (right instanceof map_1.
|
|
125
|
-
return new boolean_1.
|
|
121
|
+
if (right instanceof map_1.CustomMap) {
|
|
122
|
+
return new boolean_1.CustomBoolean(left.value.size > right.value.size);
|
|
126
123
|
}
|
|
127
|
-
return default_1.
|
|
124
|
+
return default_1.DefaultType.Void;
|
|
128
125
|
},
|
|
129
126
|
[greyscript_core_1.Operator.GreaterThanOrEqual]: (left, right) => {
|
|
130
|
-
if (right instanceof map_1.
|
|
131
|
-
return new boolean_1.
|
|
127
|
+
if (right instanceof map_1.CustomMap) {
|
|
128
|
+
return new boolean_1.CustomBoolean(left.value.size >= right.value.size);
|
|
132
129
|
}
|
|
133
|
-
return default_1.
|
|
130
|
+
return default_1.DefaultType.Void;
|
|
134
131
|
},
|
|
135
132
|
[greyscript_core_1.Operator.Equal]: (left, right) => {
|
|
136
|
-
if (right instanceof map_1.
|
|
137
|
-
return new boolean_1.
|
|
133
|
+
if (right instanceof map_1.CustomMap) {
|
|
134
|
+
return new boolean_1.CustomBoolean((0, deep_equal_1.deepEqual)(left, right));
|
|
138
135
|
}
|
|
139
|
-
return default_1.
|
|
136
|
+
return default_1.DefaultType.Void;
|
|
140
137
|
},
|
|
141
138
|
[greyscript_core_1.Operator.LessThanOrEqual]: (left, right) => {
|
|
142
|
-
if (right instanceof map_1.
|
|
143
|
-
return new boolean_1.
|
|
139
|
+
if (right instanceof map_1.CustomMap) {
|
|
140
|
+
return new boolean_1.CustomBoolean(left.value.size <= right.value.size);
|
|
144
141
|
}
|
|
145
|
-
return default_1.
|
|
142
|
+
return default_1.DefaultType.Void;
|
|
146
143
|
},
|
|
147
144
|
[greyscript_core_1.Operator.NotEqual]: (left, right) => {
|
|
148
|
-
if (right instanceof map_1.
|
|
149
|
-
return new boolean_1.
|
|
145
|
+
if (right instanceof map_1.CustomMap) {
|
|
146
|
+
return new boolean_1.CustomBoolean(!(0, deep_equal_1.deepEqual)(left, right));
|
|
150
147
|
}
|
|
151
|
-
return default_1.
|
|
148
|
+
return default_1.DefaultType.Void;
|
|
152
149
|
}
|
|
153
150
|
};
|
|
154
151
|
exports.InterfaceProcessorHandler = {
|
|
155
|
-
[greyscript_core_1.Operator.Equal]: (left, right) => new boolean_1.
|
|
156
|
-
[greyscript_core_1.Operator.NotEqual]: (left, right) => new boolean_1.
|
|
152
|
+
[greyscript_core_1.Operator.Equal]: (left, right) => new boolean_1.CustomBoolean(left.value === right.value),
|
|
153
|
+
[greyscript_core_1.Operator.NotEqual]: (left, right) => new boolean_1.CustomBoolean(left.value !== right.value)
|
|
157
154
|
};
|
|
158
155
|
exports.NilProcessorHandler = {
|
|
159
|
-
[greyscript_core_1.Operator.Equal]: (_a, b) => new boolean_1.
|
|
160
|
-
[greyscript_core_1.Operator.NotEqual]: (_a, b) => new boolean_1.
|
|
156
|
+
[greyscript_core_1.Operator.Equal]: (_a, b) => new boolean_1.CustomBoolean(b instanceof nil_1.CustomNil),
|
|
157
|
+
[greyscript_core_1.Operator.NotEqual]: (_a, b) => new boolean_1.CustomBoolean(!(b instanceof nil_1.CustomNil))
|
|
161
158
|
};
|
|
162
159
|
exports.FunctionProcessorHandler = {
|
|
163
|
-
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.
|
|
164
|
-
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.
|
|
160
|
+
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.CustomBoolean(a === b),
|
|
161
|
+
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a !== b)
|
|
165
162
|
};
|
|
166
163
|
const handleNumber = (op, a, b) => {
|
|
167
164
|
if (op in exports.NumberProcessorHandler) {
|
|
@@ -170,7 +167,7 @@ const handleNumber = (op, a, b) => {
|
|
|
170
167
|
else if (op in exports.GenericProcessorHandler) {
|
|
171
168
|
return exports.GenericProcessorHandler[op](a, b);
|
|
172
169
|
}
|
|
173
|
-
return default_1.
|
|
170
|
+
return default_1.DefaultType.Void;
|
|
174
171
|
};
|
|
175
172
|
exports.handleNumber = handleNumber;
|
|
176
173
|
const handleString = (op, a, b) => {
|
|
@@ -180,7 +177,7 @@ const handleString = (op, a, b) => {
|
|
|
180
177
|
else if (op in exports.GenericProcessorHandler) {
|
|
181
178
|
return exports.GenericProcessorHandler[op](a, b);
|
|
182
179
|
}
|
|
183
|
-
return default_1.
|
|
180
|
+
return default_1.DefaultType.Void;
|
|
184
181
|
};
|
|
185
182
|
exports.handleString = handleString;
|
|
186
183
|
const handleList = (op, a, b) => {
|
|
@@ -192,7 +189,7 @@ const handleList = (op, a, b) => {
|
|
|
192
189
|
else if (op in exports.GenericProcessorHandler) {
|
|
193
190
|
return exports.GenericProcessorHandler[op](a, b);
|
|
194
191
|
}
|
|
195
|
-
return default_1.
|
|
192
|
+
return default_1.DefaultType.Void;
|
|
196
193
|
};
|
|
197
194
|
exports.handleList = handleList;
|
|
198
195
|
const handleMap = (op, a, b) => {
|
|
@@ -204,7 +201,7 @@ const handleMap = (op, a, b) => {
|
|
|
204
201
|
else if (op in exports.GenericProcessorHandler) {
|
|
205
202
|
return exports.GenericProcessorHandler[op](a, b);
|
|
206
203
|
}
|
|
207
|
-
return default_1.
|
|
204
|
+
return default_1.DefaultType.Void;
|
|
208
205
|
};
|
|
209
206
|
exports.handleMap = handleMap;
|
|
210
207
|
const handleInterface = (op, a, b) => {
|
|
@@ -216,7 +213,7 @@ const handleInterface = (op, a, b) => {
|
|
|
216
213
|
else if (op in exports.GenericProcessorHandler) {
|
|
217
214
|
return exports.GenericProcessorHandler[op](a, b);
|
|
218
215
|
}
|
|
219
|
-
return default_1.
|
|
216
|
+
return default_1.DefaultType.Void;
|
|
220
217
|
};
|
|
221
218
|
exports.handleInterface = handleInterface;
|
|
222
219
|
const handleNil = (op, a, b) => {
|
|
@@ -226,7 +223,7 @@ const handleNil = (op, a, b) => {
|
|
|
226
223
|
else if (op in exports.GenericProcessorHandler) {
|
|
227
224
|
return exports.GenericProcessorHandler[op](a, b);
|
|
228
225
|
}
|
|
229
|
-
return default_1.
|
|
226
|
+
return default_1.DefaultType.Void;
|
|
230
227
|
};
|
|
231
228
|
exports.handleNil = handleNil;
|
|
232
229
|
const handleFunction = (op, a, b) => {
|
|
@@ -236,48 +233,48 @@ const handleFunction = (op, a, b) => {
|
|
|
236
233
|
else if (op in exports.GenericProcessorHandler) {
|
|
237
234
|
return exports.GenericProcessorHandler[op](a, b);
|
|
238
235
|
}
|
|
239
|
-
return default_1.
|
|
236
|
+
return default_1.DefaultType.Void;
|
|
240
237
|
};
|
|
241
238
|
exports.handleFunction = handleFunction;
|
|
242
239
|
const handle = (op, a, b) => {
|
|
243
|
-
if (a instanceof boolean_1.
|
|
244
|
-
a = new number_1.
|
|
240
|
+
if (a instanceof boolean_1.CustomBoolean) {
|
|
241
|
+
a = new number_1.CustomNumber(a.toInt());
|
|
245
242
|
}
|
|
246
|
-
if (b instanceof boolean_1.
|
|
247
|
-
b = new number_1.
|
|
243
|
+
if (b instanceof boolean_1.CustomBoolean) {
|
|
244
|
+
b = new number_1.CustomNumber(b.toInt());
|
|
248
245
|
}
|
|
249
246
|
if (op === greyscript_core_1.Operator.Equal && a.getCustomType() !== b.getCustomType()) {
|
|
250
|
-
return default_1.
|
|
247
|
+
return default_1.DefaultType.False;
|
|
251
248
|
}
|
|
252
249
|
else if (op === greyscript_core_1.Operator.NotEqual &&
|
|
253
250
|
a.getCustomType() !== b.getCustomType()) {
|
|
254
|
-
return default_1.
|
|
251
|
+
return default_1.DefaultType.True;
|
|
255
252
|
}
|
|
256
|
-
if (a instanceof string_1.
|
|
253
|
+
if (a instanceof string_1.CustomString || b instanceof string_1.CustomString) {
|
|
257
254
|
return (0, exports.handleString)(op, a, b);
|
|
258
255
|
}
|
|
259
|
-
else if (a instanceof number_1.
|
|
256
|
+
else if (a instanceof number_1.CustomNumber || b instanceof number_1.CustomNumber) {
|
|
260
257
|
return (0, exports.handleNumber)(op, a, b);
|
|
261
258
|
}
|
|
262
|
-
else if (a instanceof list_1.
|
|
259
|
+
else if (a instanceof list_1.CustomList) {
|
|
263
260
|
return (0, exports.handleList)(op, a, b);
|
|
264
261
|
}
|
|
265
|
-
else if (a instanceof map_1.
|
|
262
|
+
else if (a instanceof map_1.CustomMap) {
|
|
266
263
|
return (0, exports.handleMap)(op, a, b);
|
|
267
264
|
}
|
|
268
|
-
else if (a instanceof interface_1.
|
|
265
|
+
else if (a instanceof interface_1.CustomInterface) {
|
|
269
266
|
return (0, exports.handleInterface)(op, a, b);
|
|
270
267
|
}
|
|
271
|
-
else if (a instanceof function_1.
|
|
268
|
+
else if (a instanceof function_1.CustomFunction) {
|
|
272
269
|
return (0, exports.handleFunction)(op, a, b);
|
|
273
270
|
}
|
|
274
|
-
else if (a instanceof nil_1.
|
|
271
|
+
else if (a instanceof nil_1.CustomNil) {
|
|
275
272
|
return (0, exports.handleNil)(op, a, b);
|
|
276
273
|
}
|
|
277
|
-
return default_1.
|
|
274
|
+
return default_1.DefaultType.Void;
|
|
278
275
|
};
|
|
279
276
|
exports.handle = handle;
|
|
280
|
-
class Evaluate extends operation_1.
|
|
277
|
+
class Evaluate extends operation_1.Operation {
|
|
281
278
|
constructor(item, target) {
|
|
282
279
|
super(null, target);
|
|
283
280
|
this.item = item;
|
|
@@ -302,10 +299,10 @@ class Evaluate extends operation_1.default {
|
|
|
302
299
|
return __awaiter(this, void 0, void 0, function* () {
|
|
303
300
|
const left = yield this.resolve(ctx, expr.left);
|
|
304
301
|
if (expr.op === greyscript_core_1.Operator.And && !left.toTruthy()) {
|
|
305
|
-
return new boolean_1.
|
|
302
|
+
return new boolean_1.CustomBoolean(false);
|
|
306
303
|
}
|
|
307
304
|
else if (expr.op === greyscript_core_1.Operator.Or && left.toTruthy()) {
|
|
308
|
-
return new boolean_1.
|
|
305
|
+
return new boolean_1.CustomBoolean(true);
|
|
309
306
|
}
|
|
310
307
|
const right = yield this.resolve(ctx, expr.right);
|
|
311
308
|
return (0, exports.handle)(expr.op, left, right);
|
|
@@ -319,7 +316,7 @@ class Evaluate extends operation_1.default {
|
|
|
319
316
|
case greyscript_core_1.ASTType.IsaExpression: {
|
|
320
317
|
const left = yield this.resolve(ctx, expr.left);
|
|
321
318
|
const right = yield this.resolve(ctx, expr.right);
|
|
322
|
-
return new boolean_1.
|
|
319
|
+
return new boolean_1.CustomBoolean(left.instanceOf(right));
|
|
323
320
|
}
|
|
324
321
|
case greyscript_core_1.ASTType.BinaryExpression:
|
|
325
322
|
return this.resolveBinaryExpression(ctx, expr);
|
|
@@ -336,4 +333,4 @@ class Evaluate extends operation_1.default {
|
|
|
336
333
|
return this.resolve(ctx, this);
|
|
337
334
|
}
|
|
338
335
|
}
|
|
339
|
-
exports.
|
|
336
|
+
exports.Evaluate = Evaluate;
|
package/dist/operations/for.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ASTForGenericStatement, ASTIdentifier } from 'greyscript-core';
|
|
2
|
-
import
|
|
3
|
-
import CustomValue from '../types/base';
|
|
4
|
-
import Block from './block';
|
|
5
|
-
import
|
|
6
|
-
export
|
|
2
|
+
import { OperationContext } from '../context';
|
|
3
|
+
import { CustomValue } from '../types/base';
|
|
4
|
+
import { Block } from './block';
|
|
5
|
+
import { CPSVisit, Operation } from './operation';
|
|
6
|
+
export declare class For extends Operation {
|
|
7
7
|
readonly item: ASTForGenericStatement;
|
|
8
8
|
block: Block;
|
|
9
9
|
variable: ASTIdentifier;
|
|
10
10
|
iterator: Operation;
|
|
11
11
|
constructor(item: ASTForGenericStatement, target?: string);
|
|
12
12
|
build(visit: CPSVisit): Promise<Operation>;
|
|
13
|
-
handle(ctx:
|
|
13
|
+
handle(ctx: OperationContext): Promise<CustomValue>;
|
|
14
14
|
}
|