greybel-interpreter 2.2.14 → 2.2.16
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.
|
@@ -56,7 +56,7 @@ exports.minusString = minusString;
|
|
|
56
56
|
const multiplyString = (a, b) => {
|
|
57
57
|
const factor = b.toNumber();
|
|
58
58
|
if (factor <= 0) {
|
|
59
|
-
return new
|
|
59
|
+
return new string_1.CustomString('');
|
|
60
60
|
}
|
|
61
61
|
let newString = '';
|
|
62
62
|
const max = Math.floor(a.value.length * factor);
|
|
@@ -69,7 +69,7 @@ exports.multiplyString = multiplyString;
|
|
|
69
69
|
const divideString = (a, b) => {
|
|
70
70
|
const factor = 1 / b.toNumber();
|
|
71
71
|
if (factor <= 0) {
|
|
72
|
-
return new
|
|
72
|
+
return new string_1.CustomString('');
|
|
73
73
|
}
|
|
74
74
|
let newString = '';
|
|
75
75
|
const max = Math.floor(a.value.length * factor);
|
|
@@ -29,31 +29,27 @@ class FunctionOperation extends operation_1.Operation {
|
|
|
29
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
30
|
const stack = yield Promise.all(this.item.body.map((child) => visit(child)));
|
|
31
31
|
this.block = new block_1.Block(this.item, stack);
|
|
32
|
-
this.args =
|
|
33
|
-
const defers = this.item.parameters.map((child) => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
this.args = yield Promise.all(this.item.parameters.map((child) => __awaiter(this, void 0, void 0, function* () {
|
|
34
33
|
switch (child.type) {
|
|
35
34
|
case greyscript_core_1.ASTType.AssignmentStatement: {
|
|
36
35
|
const assignStatement = child;
|
|
37
36
|
const assignKey = assignStatement.variable;
|
|
38
|
-
|
|
37
|
+
return {
|
|
39
38
|
name: assignKey.name,
|
|
40
39
|
op: yield visit(assignStatement.init)
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
40
|
+
};
|
|
43
41
|
}
|
|
44
42
|
case greyscript_core_1.ASTType.Identifier: {
|
|
45
43
|
const identifierKey = child;
|
|
46
|
-
|
|
44
|
+
return {
|
|
47
45
|
name: identifierKey.name,
|
|
48
46
|
op: new reference_1.Reference(default_1.DefaultType.Void)
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
47
|
+
};
|
|
51
48
|
}
|
|
52
49
|
default:
|
|
53
50
|
throw new Error('Unexpected operation in arguments.');
|
|
54
51
|
}
|
|
55
|
-
}));
|
|
56
|
-
yield Promise.all(defers);
|
|
52
|
+
})));
|
|
57
53
|
return this;
|
|
58
54
|
});
|
|
59
55
|
}
|
package/dist/types/function.js
CHANGED
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CustomFunction = exports.Argument = exports.SUPER_NAMESPACE = exports.SELF_NAMESPACE = exports.DEFAULT_FUNCTION_NAME = void 0;
|
|
13
13
|
const context_1 = require("../context");
|
|
14
|
+
const literal_1 = require("../operations/literal");
|
|
14
15
|
const operation_1 = require("../operations/operation");
|
|
15
16
|
const reference_1 = require("../operations/reference");
|
|
16
17
|
const object_value_1 = require("../utils/object-value");
|
|
@@ -18,6 +19,7 @@ const base_1 = require("./base");
|
|
|
18
19
|
const default_1 = require("./default");
|
|
19
20
|
const map_1 = require("./map");
|
|
20
21
|
const nil_1 = require("./nil");
|
|
22
|
+
const string_1 = require("./string");
|
|
21
23
|
exports.DEFAULT_FUNCTION_NAME = 'anonymous';
|
|
22
24
|
exports.SELF_NAMESPACE = 'self';
|
|
23
25
|
exports.SUPER_NAMESPACE = 'super';
|
|
@@ -76,7 +78,23 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
76
78
|
return this.toString();
|
|
77
79
|
}
|
|
78
80
|
toString() {
|
|
79
|
-
|
|
81
|
+
let refs = 1;
|
|
82
|
+
const args = this.argumentDefs.map((item) => {
|
|
83
|
+
if (item.defaultValue instanceof literal_1.Literal) {
|
|
84
|
+
const value = item.defaultValue.value;
|
|
85
|
+
if (value instanceof nil_1.CustomNil) {
|
|
86
|
+
return item.name;
|
|
87
|
+
}
|
|
88
|
+
else if (value instanceof string_1.CustomString) {
|
|
89
|
+
return `${item.name}="${value.value}"`;
|
|
90
|
+
}
|
|
91
|
+
return `${item.name}=${value.value}`;
|
|
92
|
+
}
|
|
93
|
+
else if (item.defaultValue.item != null) {
|
|
94
|
+
return `${item.name}=_${refs++}`;
|
|
95
|
+
}
|
|
96
|
+
return item.name;
|
|
97
|
+
});
|
|
80
98
|
return `FUNCTION(${args.join(', ')})`;
|
|
81
99
|
}
|
|
82
100
|
toTruthy() {
|