godprotocol 1.1.31 → 1.1.32
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/package.json +1 -1
- package/utils/vm_utils.js +161 -53
package/package.json
CHANGED
package/utils/vm_utils.js
CHANGED
|
@@ -9,95 +9,203 @@ import Bool from "../Datatypes/bool";
|
|
|
9
9
|
import Instance from "../Datatypes/instance";
|
|
10
10
|
import Func from "../Datatypes/func";
|
|
11
11
|
import Cls from "../Datatypes/cls";
|
|
12
|
+
import { ops } from "./ops";
|
|
12
13
|
|
|
13
14
|
class Vm_utils {
|
|
14
15
|
constructor() {
|
|
16
|
+
this.ops = ops;
|
|
15
17
|
this.literal_methods = {
|
|
16
|
-
number: [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
number: [
|
|
19
|
+
"add",
|
|
20
|
+
"sub",
|
|
21
|
+
"div",
|
|
22
|
+
"mul",
|
|
23
|
+
"exp",
|
|
24
|
+
"floordiv",
|
|
25
|
+
"eq",
|
|
26
|
+
"ne",
|
|
27
|
+
"lt",
|
|
28
|
+
"gt",
|
|
29
|
+
"gte",
|
|
30
|
+
"lte",
|
|
31
|
+
"neg",
|
|
32
|
+
"abs",
|
|
33
|
+
"and",
|
|
34
|
+
"or",
|
|
35
|
+
"xor",
|
|
36
|
+
"lshift",
|
|
37
|
+
"rshift",
|
|
38
|
+
"invert",
|
|
39
|
+
]
|
|
40
|
+
.map((i) => `__${i}__`)
|
|
41
|
+
.concat([
|
|
42
|
+
"to_int",
|
|
43
|
+
"to_float",
|
|
44
|
+
"to_string",
|
|
45
|
+
"sqrt",
|
|
46
|
+
"log",
|
|
47
|
+
"sin",
|
|
48
|
+
"sinh",
|
|
49
|
+
"tanh",
|
|
50
|
+
"cosh",
|
|
51
|
+
"atanh",
|
|
52
|
+
"acosh",
|
|
53
|
+
"asinh",
|
|
54
|
+
"atan",
|
|
55
|
+
"acos",
|
|
56
|
+
"asin",
|
|
57
|
+
"cos",
|
|
58
|
+
"tan",
|
|
59
|
+
"round",
|
|
60
|
+
"factorial",
|
|
61
|
+
"ceil",
|
|
62
|
+
"floor",
|
|
63
|
+
"is_prime",
|
|
64
|
+
"is_even",
|
|
65
|
+
"is_odd",
|
|
66
|
+
"is_perfect_square",
|
|
67
|
+
"to_degrees",
|
|
68
|
+
"to_radians",
|
|
69
|
+
]),
|
|
70
|
+
string: [
|
|
71
|
+
"upper",
|
|
72
|
+
"lower",
|
|
73
|
+
"title",
|
|
74
|
+
"slice",
|
|
75
|
+
"concat",
|
|
76
|
+
"find",
|
|
77
|
+
"includes",
|
|
78
|
+
"index",
|
|
79
|
+
"trim",
|
|
80
|
+
"split",
|
|
81
|
+
"padstart",
|
|
82
|
+
"padend",
|
|
83
|
+
"repeat",
|
|
84
|
+
"replace",
|
|
85
|
+
"startswith",
|
|
86
|
+
"endswith",
|
|
87
|
+
"count",
|
|
88
|
+
"length",
|
|
89
|
+
"reverse",
|
|
90
|
+
"is_numeric",
|
|
91
|
+
"is_empty",
|
|
92
|
+
"is_blank",
|
|
93
|
+
"charcode",
|
|
94
|
+
],
|
|
95
|
+
array: [
|
|
96
|
+
"push",
|
|
97
|
+
"pop",
|
|
98
|
+
"length",
|
|
99
|
+
"run",
|
|
100
|
+
"copy",
|
|
101
|
+
"deepcopy",
|
|
102
|
+
"extend",
|
|
103
|
+
"slice",
|
|
104
|
+
"index",
|
|
105
|
+
"includes",
|
|
106
|
+
"replace",
|
|
107
|
+
"map",
|
|
108
|
+
"find",
|
|
109
|
+
"filter",
|
|
110
|
+
"padstart",
|
|
111
|
+
"padend",
|
|
112
|
+
"clear",
|
|
113
|
+
"to_string",
|
|
114
|
+
"reverse",
|
|
115
|
+
"repeat",
|
|
116
|
+
"join",
|
|
117
|
+
"splice",
|
|
20
118
|
],
|
|
21
119
|
twain: [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
120
|
+
"entries",
|
|
121
|
+
"get",
|
|
122
|
+
"set",
|
|
123
|
+
"keys",
|
|
124
|
+
"clear",
|
|
125
|
+
"is_empty",
|
|
126
|
+
"values",
|
|
127
|
+
"copy",
|
|
128
|
+
"deepcopy",
|
|
129
|
+
"remove",
|
|
130
|
+
],
|
|
131
|
+
};
|
|
25
132
|
|
|
26
|
-
this.datatypes = [
|
|
133
|
+
this.datatypes = ["string", "number", "void", "boolean", "array", "twain"];
|
|
27
134
|
}
|
|
28
135
|
|
|
29
|
-
gen_uid = ()=>{
|
|
30
|
-
return `_${Math.random().toString().replace(
|
|
31
|
-
}
|
|
136
|
+
gen_uid = () => {
|
|
137
|
+
return `_${Math.random().toString().replace(".", "")}_${Date.now()}`;
|
|
138
|
+
};
|
|
32
139
|
|
|
33
|
-
parse_dynamic = async(literal, options={})=>{
|
|
34
|
-
let {chain, config} = options;
|
|
140
|
+
parse_dynamic = async (literal, options = {}) => {
|
|
141
|
+
let { chain, config } = options;
|
|
35
142
|
|
|
36
143
|
let aircode = this.account.aircode;
|
|
37
|
-
let sequence = aircode.to_sequence(
|
|
144
|
+
let sequence = aircode.to_sequence(
|
|
145
|
+
JSON.stringify(literal),
|
|
146
|
+
chain.physical_address
|
|
147
|
+
);
|
|
38
148
|
|
|
39
149
|
let res = await chain.add_config(sequence[0].body[0]);
|
|
40
|
-
let address = await this.execute(res, {chain})
|
|
150
|
+
let address = await this.execute(res, { chain });
|
|
41
151
|
|
|
42
152
|
return address;
|
|
43
|
-
}
|
|
153
|
+
};
|
|
44
154
|
|
|
45
|
-
resolve_addr = (addr)=>{
|
|
46
|
-
if (!addr)return addr
|
|
155
|
+
resolve_addr = (addr) => {
|
|
156
|
+
if (!addr) return addr;
|
|
47
157
|
|
|
48
|
-
if (addr.startsWith(
|
|
49
|
-
addr = `${this.account.physical_address}/${addr.slice(2)}
|
|
158
|
+
if (addr.startsWith("@")) {
|
|
159
|
+
addr = `${this.account.physical_address}/${addr.slice(2)}`;
|
|
50
160
|
}
|
|
51
161
|
|
|
52
162
|
return addr;
|
|
53
|
-
}
|
|
163
|
+
};
|
|
54
164
|
|
|
55
|
-
cloth_object = async addr=>{
|
|
56
|
-
|
|
57
|
-
}
|
|
165
|
+
cloth_object = async (addr) => {};
|
|
58
166
|
|
|
59
|
-
cloth_content = async(content, options)=>{
|
|
167
|
+
cloth_content = async (content, options) => {
|
|
60
168
|
let obj;
|
|
61
169
|
|
|
62
|
-
if (content instanceof Instance)return content;
|
|
63
|
-
|
|
64
|
-
switch(content.type){
|
|
65
|
-
case
|
|
66
|
-
obj = new Num(content, this.account)
|
|
170
|
+
if (content instanceof Instance) return content;
|
|
171
|
+
|
|
172
|
+
switch (content.type) {
|
|
173
|
+
case "number":
|
|
174
|
+
obj = new Num(content, this.account);
|
|
175
|
+
break;
|
|
176
|
+
case "string":
|
|
177
|
+
obj = new Str(content, this.account);
|
|
67
178
|
break;
|
|
68
|
-
case
|
|
69
|
-
obj = new
|
|
179
|
+
case "boolean":
|
|
180
|
+
obj = new Bool(content, this.account);
|
|
70
181
|
break;
|
|
71
|
-
case
|
|
72
|
-
obj = new
|
|
182
|
+
case "void":
|
|
183
|
+
obj = new Voi(content, this.account);
|
|
73
184
|
break;
|
|
74
|
-
case
|
|
75
|
-
obj = new
|
|
185
|
+
case "array":
|
|
186
|
+
obj = new Arr(content, this.account);
|
|
76
187
|
break;
|
|
77
|
-
case
|
|
78
|
-
obj = new
|
|
79
|
-
break
|
|
80
|
-
case 'twain':
|
|
81
|
-
obj = new Twa(content, this.account)
|
|
188
|
+
case "twain":
|
|
189
|
+
obj = new Twa(content, this.account);
|
|
82
190
|
break;
|
|
83
|
-
case
|
|
84
|
-
obj = new Instance(content, this.account)
|
|
191
|
+
case "instance":
|
|
192
|
+
obj = new Instance(content, this.account);
|
|
85
193
|
break;
|
|
86
|
-
case
|
|
87
|
-
obj = new Func(content, this.account)
|
|
194
|
+
case "function":
|
|
195
|
+
obj = new Func(content, this.account);
|
|
88
196
|
break;
|
|
89
|
-
case
|
|
90
|
-
obj = new Cls(content, this.account)
|
|
197
|
+
case "class":
|
|
198
|
+
obj = new Cls(content, this.account);
|
|
91
199
|
break;
|
|
92
200
|
default:
|
|
93
|
-
if (content.type ===
|
|
94
|
-
obj = new Func(content, this.account)
|
|
95
|
-
}else obj = content
|
|
96
|
-
|
|
201
|
+
if (content.type === "address") {
|
|
202
|
+
obj = new Func(content, this.account);
|
|
203
|
+
} else obj = content;
|
|
204
|
+
// console.log(content, 'uh')
|
|
97
205
|
}
|
|
98
206
|
|
|
99
|
-
return await obj.sync(options)
|
|
100
|
-
}
|
|
207
|
+
return await obj.sync(options);
|
|
208
|
+
};
|
|
101
209
|
}
|
|
102
210
|
|
|
103
211
|
export default Vm_utils;
|