godprotocol 1.1.32 → 1.2.0
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/Datatypes/arr.js +559 -254
- package/Datatypes/bool.js +8 -5
- package/Datatypes/callable.js +1 -1
- package/Datatypes/cls.js +193 -24
- package/Datatypes/conf.js +2 -2
- package/Datatypes/err.js +25 -0
- package/Datatypes/func.js +89 -13
- package/Datatypes/functions/storage.js +572 -12
- package/Datatypes/functions/wallet.js +49 -0
- package/Datatypes/instance.js +87 -122
- package/Datatypes/num.js +192 -153
- package/Datatypes/str.js +188 -122
- package/Datatypes/twa.js +346 -71
- package/Datatypes/voi.js +9 -4
- package/Index.js +1 -1
- package/Instances/account.js +0 -0
- package/Instances/event.js +0 -0
- package/Instances/fold.js +103 -0
- package/Instances/folder_queries.js +46 -0
- package/Instances/response.js +31 -0
- package/Objects/Account.js +160 -110
- package/Objects/Blockweb.js +6 -11
- package/Objects/Callable.js +223 -188
- package/Objects/Chain.js +127 -142
- package/Objects/Datatypes.js +114 -588
- package/Objects/Manager.js +349 -39
- package/Objects/Oracle.js +283 -210
- package/Objects/Repository.js +12 -33
- package/Objects/Trinity.js +9 -7
- package/Objects/Utils.js +8 -8
- package/Objects/Virtual_machine.js +320 -320
- package/README.md +0 -0
- package/callables/functions/assert.js +10 -0
- package/callables/functions/display.js +2 -3
- package/callables/functions/env.js +5 -0
- package/callables/functions/event.js +14 -0
- package/callables/functions/exit.js +3 -2
- package/callables/functions/folder.js +15 -0
- package/callables/functions/get_uid.js +6 -0
- package/callables/functions/hash.js +7 -0
- package/callables/functions/import_.js +62 -0
- package/callables/functions/local.js +9 -0
- package/callables/functions/net.js +33 -18
- package/callables/functions/parse.js +35 -0
- package/callables/functions/query.js +12 -0
- package/callables/functions/render.js +9 -13
- package/callables/functions/servers.js +10 -0
- package/callables/functions/spawn.js +7 -0
- package/callables/functions/store.js +75 -0
- package/callables/functions/super_.js +24 -0
- package/callables/functions/typeof.js +32 -0
- package/callables/functions/wait.js +9 -0
- package/callables/register.js +193 -8
- package/html/create.js +110 -0
- package/html/index.js +114 -0
- package/html/load.js +165 -0
- package/html/parse.js +171 -0
- package/html/run.js +151 -0
- package/html/util.js +5 -0
- package/package.json +5 -3
- package/repos/fs.js +114 -0
- package/repos/github.js +73 -0
- package/repos/ram.js +47 -0
- package/utils/create_server.js +66 -26
- package/utils/hash.js +3 -2
- package/utils/ops.js +2 -0
- package/utils/oracle_handlers.js +7 -0
- package/utils/services.js +18 -51
- package/utils/socket_server.js +36 -0
- package/utils/vm_utils.js +241 -137
- package/callables/functions/assign.js +0 -6
package/Datatypes/arr.js
CHANGED
|
@@ -1,284 +1,589 @@
|
|
|
1
|
-
import Storage from "./functions/storage";
|
|
1
|
+
import Storage from "./functions/storage.js";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
An Array is constructed by a parent config which holds
|
|
5
|
+
properties such as length, and a value which is basically the
|
|
6
|
+
last item in the array.
|
|
7
|
+
|
|
8
|
+
The array stores its entries by using a parent address
|
|
9
|
+
with a subfolder of item index
|
|
10
|
+
so for a array address at /places/things
|
|
11
|
+
First entry would be at
|
|
12
|
+
> places/things/0
|
|
13
|
+
|
|
14
|
+
and second at
|
|
15
|
+
>places/things/1
|
|
16
|
+
|
|
17
|
+
The native routines of an array are index, insert and pop.
|
|
18
|
+
Which those 3 are all its super methods constructed.
|
|
19
|
+
|
|
20
|
+
Now lets explain the `pop` native method and interface.
|
|
21
|
+
It takes in the arr config, and the index.
|
|
22
|
+
The index should always be less than the arr.length
|
|
23
|
+
Unless its an empty array, because the index also would not be less than zero.
|
|
24
|
+
|
|
25
|
+
It would access the index value by subfoldering.
|
|
26
|
+
Then it would read the next
|
|
27
|
+
*/
|
|
2
28
|
|
|
3
29
|
class Arr extends Storage {
|
|
4
|
-
constructor(
|
|
5
|
-
super(
|
|
30
|
+
constructor(config, account) {
|
|
31
|
+
super(account);
|
|
6
32
|
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
|
|
33
|
+
this.config = config;
|
|
34
|
+
this.type = "array";
|
|
35
|
+
|
|
36
|
+
this.methods = {
|
|
37
|
+
...this.methods,
|
|
38
|
+
'replace': {args: [['index', 'number'], ['item', 'object']], ret: ['empty', 'void']},
|
|
39
|
+
'pop': {args: [['name', 'number']], ret: ['item', 'object']},
|
|
40
|
+
'insert': {args: [['item', 'object'], ['index', 'number']], ret: ['arr.length', 'number']},
|
|
41
|
+
'push': {args: [['item', 'object']], ret: ['arr.length', 'number']},
|
|
42
|
+
|
|
43
|
+
call: {args: [['handler', 'function'], ['callback', 'function']], ret: ['results', 'array']},
|
|
44
|
+
// 'map': {args: [['handler', 'function']], ret: ['items', 'array']},
|
|
45
|
+
// 'filter': {args: [['handler', 'function']], ret: ['pass_items', 'array']},
|
|
46
|
+
// 'find': {args: [['handler', 'function']], ret: ['item', 'object']},
|
|
47
|
+
|
|
48
|
+
'clear': {args: [], ret: ['empty', 'array']},
|
|
49
|
+
'len': {args: [], ret: ['length', 'number']},
|
|
50
|
+
'extend': {args: [['other', 'array']], ret: ['concatenated', 'array']},
|
|
51
|
+
'padstart': {args: [['filler', 'object'], ['length', 'number']], ret: ['items', 'array']},
|
|
52
|
+
'padend': {args: [['filler', 'object'], ['length', 'number']], ret: ['items', 'array']},
|
|
53
|
+
'index': {args: [['index', 'number']], ret: ['item', 'object']},
|
|
54
|
+
'to_string': {args: [['glue|ascii', 'object|string']], ret: ['chars', 'string']},
|
|
55
|
+
'is_empty': {args: [[]], ret: ['isit', 'boolean']},
|
|
56
|
+
'reverse': {args: [[]], ret: ['items', 'array']},
|
|
57
|
+
'join': {args: [['other', 'object']], ret: ['concatenated_items', 'string']},
|
|
58
|
+
'slice': {args: [['start', 'number'], ['stop', 'number']], ret: ['sub_arr', 'array']},
|
|
59
|
+
'splice': {args: [['start', 'number'], ['stop', 'number']], ret: ['deleted_items', 'array']},
|
|
60
|
+
'includes': {args: [['item', 'object']], ret: ['yes', 'boolean']},
|
|
61
|
+
'repeat': {args: [['count', 'number']], ret: ['items', 'array']}
|
|
62
|
+
}
|
|
10
63
|
}
|
|
11
64
|
|
|
12
|
-
|
|
13
|
-
let
|
|
14
|
-
|
|
65
|
+
swap_ = async (item, position) => {
|
|
66
|
+
let chain = await this.chain();
|
|
67
|
+
await chain.pop({ arr: this.config, index: position });
|
|
68
|
+
await chain.insert({ arr: this.config, item, index: position });
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
replace = async (index, args) => {
|
|
72
|
+
index = await index.literal();
|
|
73
|
+
if (index >= this.config.length) return;
|
|
15
74
|
|
|
16
|
-
|
|
75
|
+
let item = args[1];
|
|
76
|
+
item = await item.to_address();
|
|
77
|
+
await this.swap_(item, index);
|
|
78
|
+
|
|
79
|
+
return index >=0 && index < this.config.length
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
retrieve =async (items)=>{
|
|
83
|
+
let ds = this.account.manager.ds
|
|
84
|
+
|
|
85
|
+
delete this.config.items
|
|
86
|
+
await (await ds.folder(this.config.location)).write(this.config, {replace: true})
|
|
17
87
|
|
|
18
|
-
let
|
|
19
|
-
|
|
88
|
+
for (let i=0; i< this.config.length; i++){
|
|
89
|
+
let addr = `${this.config.location}/${i}`;
|
|
90
|
+
let item_ref = this.account.vm._split_datapath(items[i])
|
|
20
91
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
result = me.push( await this.account.vm.instance_address(other))
|
|
24
|
-
store = true;
|
|
92
|
+
let item_folder = await ds.folder(item_ref[0], {account: this.account.physical_address})
|
|
93
|
+
let item = await item_folder.readone({_id: item_ref[1]})
|
|
25
94
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if(result){
|
|
38
|
-
result = {type:'address',value: result}
|
|
39
|
-
}
|
|
40
|
-
break
|
|
41
|
-
case 'extend':
|
|
42
|
-
result = me.push(...other)
|
|
43
|
-
store = true
|
|
44
|
-
|
|
45
|
-
break;
|
|
46
|
-
case 'slice':
|
|
47
|
-
let start = args[0] && await args[0].literal()
|
|
48
|
-
let end = args[1] && await args[1].literal()
|
|
95
|
+
if(!item && item_ref[0].endsWith('/instances')){
|
|
96
|
+
let adr = item_ref[0].split('/').slice(0,-1).join('/')
|
|
97
|
+
item = await (await ds.folder(adr, {account: this.account.physical_address})).readone({_id: item_ref[1]})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
await (await ds.folder(addr)).write({
|
|
101
|
+
type: 'address',
|
|
102
|
+
value: item.location,
|
|
103
|
+
_id: item._id
|
|
104
|
+
}, {replace: true})
|
|
49
105
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
store = true;
|
|
60
|
-
break;
|
|
61
|
-
case 'replace':
|
|
62
|
-
me[await args[0].literal()] = await this.account.vm.instance_address(await args[1].statics_())
|
|
63
|
-
store = true;
|
|
64
|
-
break
|
|
65
|
-
case 'index':
|
|
66
|
-
let i = args[0] && await args[0].literal()
|
|
67
|
-
if (i< 0){
|
|
68
|
-
result = me.slice(i)[0]
|
|
69
|
-
}else result = me[i]
|
|
70
|
-
if (result)result = {type:'address', value: result}
|
|
71
|
-
else result = null
|
|
72
|
-
break;
|
|
73
|
-
case 'copy':
|
|
74
|
-
result = me;
|
|
75
|
-
break;
|
|
76
|
-
case 'deepcopy':
|
|
77
|
-
break;
|
|
78
|
-
case 'reverse':
|
|
79
|
-
me = [...me].reverse()
|
|
80
|
-
result = {type:'address', value: await this.account.vm.instance_address(this.instance_object)}
|
|
81
|
-
|
|
82
|
-
if (other){
|
|
83
|
-
store = true;
|
|
84
|
-
}else {
|
|
85
|
-
result = me
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
case "is_empty":
|
|
89
|
-
result = !me.length
|
|
90
|
-
break;
|
|
91
|
-
case 'clear':
|
|
92
|
-
me = []
|
|
93
|
-
store = true;
|
|
94
|
-
break;
|
|
95
|
-
case 'join':
|
|
96
|
-
let str_val = ''
|
|
97
|
-
let separator = (other && await args[0].literal()) || ','
|
|
98
|
-
for (let i=0; i< me.length; i++){
|
|
99
|
-
let item = me[i]
|
|
100
|
-
let val = await this.account.vm.cloth_object(item)
|
|
101
|
-
|
|
102
|
-
if (['number', 'string', 'void', 'boolean'].includes(val.type))str_val = `${str_val}${i ? separator: ''}${await val.literal()}`
|
|
103
|
-
}
|
|
104
|
-
result = str_val
|
|
105
|
-
break;
|
|
106
|
-
case 'repeat':
|
|
107
|
-
me = Array.from({ length: other? await args[0].literal(): 0 }, () => me).flat()
|
|
108
|
-
|
|
109
|
-
store = true;
|
|
110
|
-
result = me.length;
|
|
111
|
-
break;
|
|
112
|
-
case 'padstart':
|
|
113
|
-
let p_length = args[0] && await args[0].literal()
|
|
114
|
-
let value = args[1] && args[1]
|
|
115
|
-
if (me.length >= p_length){ me = me;
|
|
116
|
-
}else {
|
|
117
|
-
let padding = Array(p_length - me.length).fill(['array', 'twain'].includes(value && value.type) ? value.value.address : value.instance_object.address);
|
|
118
|
-
me = [...padding, ...me];
|
|
119
|
-
|
|
120
|
-
store = true;
|
|
121
|
-
}
|
|
122
|
-
result = {type:'address', value: await this.account.vm.instance_address(this.instance_object)}
|
|
106
|
+
if (['array', 'twain'].includes(item.type)){
|
|
107
|
+
await (await this.account.vm.cloth_content(item)).retrieve(item.items || item.entries)
|
|
108
|
+
} else if (item.type === 'instance'){
|
|
109
|
+
await this.account.vm.retrieve(item)
|
|
110
|
+
} else {
|
|
111
|
+
await (await ds.folder(item.location)).write(item, {replace: true})
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
123
115
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
let ps_length = args[0] && await args[0].literal()
|
|
127
|
-
let svalue = args[1] && args[1]
|
|
128
|
-
if (me.length >= ps_length) {me = me;
|
|
129
|
-
}else {
|
|
130
|
-
let spadding = Array(ps_length - me.length).fill(['array', 'twain'].includes(svalue && svalue.type) ? svalue.value.address : svalue.instance_object.address);
|
|
131
|
-
me = [...me, ...spadding];
|
|
132
|
-
|
|
133
|
-
store = true;
|
|
134
|
-
}
|
|
135
|
-
result = {type:'address', value: await this.account.vm.instance_address(this.instance_object)}
|
|
136
|
-
|
|
137
|
-
break;
|
|
138
|
-
case 'to_string':
|
|
139
|
-
let str = ''
|
|
140
|
-
if(other){
|
|
141
|
-
other = await args[0].literal()
|
|
142
|
-
}
|
|
143
|
-
for (let a=0; a< me.length; a++){
|
|
144
|
-
let item = me[a]
|
|
145
|
-
let val = await this.account.vm.cloth_object(item)
|
|
146
|
-
if (other === 'ascii'){
|
|
147
|
-
if (val.type!=='number'){
|
|
148
|
-
str = `${str}void`
|
|
149
|
-
}else {
|
|
150
|
-
val = await val.literal()
|
|
151
|
-
str = `${str}${String.fromCharCode(val)}`
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
result = str
|
|
156
|
-
break;
|
|
157
|
-
case 'map':
|
|
158
|
-
result = new Array()
|
|
159
|
-
for (let a=0; a< me.length; a++){
|
|
160
|
-
let item = me[a]
|
|
161
|
-
let res = await this.account.vm.execute({
|
|
162
|
-
type: 'call',
|
|
163
|
-
arguments: [
|
|
164
|
-
{type:'address', value: item},
|
|
165
|
-
{type: 'number', value: a, location: `${config.location}/${await this.account.manager.oracle.hash(a)}`}
|
|
166
|
-
],
|
|
167
|
-
identifier: args[0].value.address,
|
|
168
|
-
location: config.location,
|
|
169
|
-
}, {chain})
|
|
116
|
+
store = async ({store, addresses, thread})=>{
|
|
117
|
+
let chain = await this.chain();
|
|
170
118
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
result = {type:'address', value: res. type === 'instance'? res.address: res.value}
|
|
209
|
-
break
|
|
210
|
-
}
|
|
211
|
-
}
|
|
119
|
+
let data = {...this.config, items:[]}
|
|
120
|
+
|
|
121
|
+
for (let i=0; i < this.config.length; i++){
|
|
122
|
+
let item = await chain.index({arr: this.config, i})
|
|
123
|
+
|
|
124
|
+
await store({object: await this.account.vm.cloth(item)}, {vm: this.account.vm, addresses, thread})
|
|
125
|
+
|
|
126
|
+
data.items.push(`${item.value}/${item._id}`)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return data;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
find = async (func) => {
|
|
133
|
+
let chain = await this.chain(),
|
|
134
|
+
result = new Array();
|
|
135
|
+
for (let i = 0; i < this.config.length; i++) {
|
|
136
|
+
let item = await chain.index({ arr: this.config, i });
|
|
137
|
+
let res = await func.invoke(
|
|
138
|
+
[
|
|
139
|
+
item,
|
|
140
|
+
await this.account.vm.instantiate(
|
|
141
|
+
{
|
|
142
|
+
type: "number",
|
|
143
|
+
value: i.toString(),
|
|
144
|
+
location: this.spawn_address(),
|
|
145
|
+
},
|
|
146
|
+
{ chain }
|
|
147
|
+
),
|
|
148
|
+
],
|
|
149
|
+
{ chain, cloth: true }
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
let res_lit = await res.literal();
|
|
153
|
+
|
|
154
|
+
if (!!res_lit) {
|
|
155
|
+
result = i;
|
|
212
156
|
break;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return result;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
filter = async (func, pure) => {
|
|
164
|
+
let chain = await this.chain(),
|
|
165
|
+
result = new Array();
|
|
166
|
+
for (let i = 0; i < this.config.length; i++) {
|
|
167
|
+
let item = await chain.index({ arr: this.config, i });
|
|
168
|
+
let res = await func.invoke(
|
|
169
|
+
[
|
|
170
|
+
item,
|
|
171
|
+
await this.account.vm.instantiate(
|
|
172
|
+
{
|
|
173
|
+
type: "number",
|
|
174
|
+
value: i.toString(),
|
|
175
|
+
location: this.spawn_address(),
|
|
176
|
+
},
|
|
177
|
+
{ chain }
|
|
178
|
+
),
|
|
179
|
+
],
|
|
180
|
+
{ chain, cloth: true }
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
let res_lit = await res.literal();
|
|
184
|
+
|
|
185
|
+
if (res_lit) {
|
|
186
|
+
if (pure) {
|
|
187
|
+
result.push(i);
|
|
188
|
+
} else result.push(item);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (pure) return result;
|
|
192
|
+
|
|
193
|
+
result = await this.account.vm.instantiate(
|
|
194
|
+
{
|
|
195
|
+
type: "array",
|
|
196
|
+
value: result,
|
|
197
|
+
location: this.spawn_address(),
|
|
198
|
+
},
|
|
199
|
+
{ chain }
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
return result;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
__or__ = async (other) => {
|
|
206
|
+
if (!this.config.length) {
|
|
207
|
+
return await other.to_address();
|
|
208
|
+
}
|
|
209
|
+
return await this.to_address();
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
__and__ = async (other) => {
|
|
213
|
+
if (!this.config.length) {
|
|
214
|
+
return await this.to_address();
|
|
215
|
+
}
|
|
216
|
+
return await other.to_address();
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
call_ = async (func, args) => {
|
|
220
|
+
let chain = await this.chain(),
|
|
221
|
+
result = new Array();
|
|
222
|
+
|
|
223
|
+
for (let i = 0; i < this.config.length; i++) {
|
|
224
|
+
let item = await chain.index({arr: this.config, i})
|
|
225
|
+
let index = await this.account.vm.instantiate({
|
|
226
|
+
type:'number',
|
|
227
|
+
value: i.toString(),
|
|
228
|
+
location: this.spawn_address()
|
|
229
|
+
}, {chain})
|
|
230
|
+
|
|
231
|
+
await func.invoke([item, index], {no_wait: true, callback: async (res)=>{
|
|
232
|
+
if (res.__interrupt__){
|
|
233
|
+
res = await this.account.vm.instantiate({
|
|
234
|
+
type:'error',
|
|
235
|
+
payload: res.payload,
|
|
236
|
+
location: this.spawn_address()
|
|
237
|
+
}, {chain})
|
|
230
238
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
let obj = await this.account.vm.cloth_object(item)
|
|
241
|
-
|
|
242
|
-
if(['array', 'twain'].includes(obj.type)){
|
|
243
|
-
result = false
|
|
244
|
-
}
|
|
245
|
-
else if(await obj.literal() === search){
|
|
246
|
-
result = true;
|
|
247
|
-
break
|
|
248
|
-
}else result = false
|
|
249
|
-
}
|
|
250
|
-
}
|
|
239
|
+
result[i] = res
|
|
240
|
+
if (result.filter(r=>!!r).length === this.config.length){
|
|
241
|
+
await args[1].invoke([
|
|
242
|
+
await this.account.vm.instantiate({
|
|
243
|
+
type: 'array',
|
|
244
|
+
value: result,
|
|
245
|
+
location: this.spawn_address()
|
|
246
|
+
}, {chain})
|
|
247
|
+
], {no_wait: true})
|
|
251
248
|
}
|
|
252
|
-
|
|
249
|
+
}})
|
|
253
250
|
}
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
|
|
252
|
+
return result;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
extend = async (other) => {
|
|
256
|
+
let other_chain = await other.chain();
|
|
257
|
+
let chain = await this.chain();
|
|
258
|
+
for (let i = 0; i < other.config.length; i++) {
|
|
259
|
+
let obj = await other_chain.index({ arr: other.config, i });
|
|
260
|
+
await chain.insert({
|
|
261
|
+
arr: this.config,
|
|
262
|
+
item: obj,
|
|
263
|
+
index: this.config.length,
|
|
264
|
+
});
|
|
256
265
|
}
|
|
266
|
+
return this.config.length;
|
|
267
|
+
};
|
|
257
268
|
|
|
258
|
-
|
|
259
|
-
|
|
269
|
+
len = () => {
|
|
270
|
+
return this.config.length;
|
|
271
|
+
};
|
|
260
272
|
|
|
261
|
-
|
|
262
|
-
let
|
|
263
|
-
|
|
264
|
-
}}
|
|
273
|
+
padstart = async (filler, args) => {
|
|
274
|
+
let index = args[1],
|
|
275
|
+
chain = await this.chain();
|
|
265
276
|
|
|
266
|
-
|
|
267
|
-
|
|
277
|
+
while (this.config.length < await index.literal()) {
|
|
278
|
+
await chain.insert({
|
|
279
|
+
arr: this.config,
|
|
280
|
+
index: 0,
|
|
281
|
+
item: await filler.to_address(),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return this.config.length;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
padend = async (filler, args) => {
|
|
289
|
+
let index = await args[1].literal()
|
|
290
|
+
let chain = await this.chain();
|
|
291
|
+
|
|
292
|
+
while (this.config.length < index) {
|
|
293
|
+
await chain.insert({
|
|
294
|
+
arr: this.config,
|
|
295
|
+
index: this.config.length,
|
|
296
|
+
item: await filler.to_address(),
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return this.config.length;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
to_string = async (other) => {
|
|
304
|
+
other = other && (await other.literal());
|
|
305
|
+
let length = this.config.length,
|
|
306
|
+
result = "",
|
|
307
|
+
chain = await this.chain();
|
|
308
|
+
|
|
309
|
+
for (let k = 0; k < length; k++) {
|
|
310
|
+
let item = await chain.index({ arr: this.config, i: k });
|
|
311
|
+
item = await this.account.vm.cloth(item);
|
|
312
|
+
item = await item.literal();
|
|
313
|
+
if (other === "ascii") {
|
|
314
|
+
result = `${result}${String.fromCharCode(item)}`;
|
|
315
|
+
} else {
|
|
316
|
+
result = k ? `${result},${item.toString()}` : item.toString();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
268
319
|
|
|
269
|
-
|
|
270
|
-
|
|
320
|
+
return result;
|
|
321
|
+
};
|
|
271
322
|
|
|
272
|
-
|
|
323
|
+
copy = async () => {
|
|
324
|
+
let result = new Array(),
|
|
325
|
+
chain = await this.chain(),
|
|
326
|
+
length = this.config.length;
|
|
327
|
+
|
|
328
|
+
for (let i = 0; i < length; i++)
|
|
329
|
+
result.push(await chain.index({ arr: this.config, i }));
|
|
330
|
+
|
|
331
|
+
return await this.account.vm.instantiate(
|
|
332
|
+
{
|
|
333
|
+
type: "array",
|
|
334
|
+
value: result,
|
|
335
|
+
location: this.spawn_address(),
|
|
336
|
+
},
|
|
337
|
+
{ chain }
|
|
338
|
+
);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
reverse = async () => {
|
|
342
|
+
let chain = await this.chain(),
|
|
343
|
+
result = new Array(),
|
|
344
|
+
length = this.config.length,
|
|
345
|
+
i = 0;
|
|
346
|
+
|
|
347
|
+
while (i < this.config.length) {
|
|
348
|
+
let pop = await chain.pop({
|
|
349
|
+
arr: this.config,
|
|
350
|
+
index: i,
|
|
351
|
+
});
|
|
352
|
+
result.unshift(pop);
|
|
353
|
+
}
|
|
273
354
|
|
|
274
|
-
|
|
355
|
+
for (let i = 0; i < length; i++) {
|
|
356
|
+
await chain.insert({
|
|
357
|
+
arr: this.config,
|
|
358
|
+
item: result[i],
|
|
359
|
+
index: this.config.length,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return await this.to_address()
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
join = async (other) => {
|
|
367
|
+
other = other ? await other.literal() : "";
|
|
368
|
+
let chain = await this.chain(),
|
|
369
|
+
result;
|
|
370
|
+
|
|
371
|
+
for (let i = 0; i < this.config.length; i++) {
|
|
372
|
+
let item = await chain.index({ arr: this.config, i });
|
|
373
|
+
let obj = await this.account.vm.cloth(item);
|
|
374
|
+
|
|
375
|
+
result = result
|
|
376
|
+
? `${result}${other}${await obj.literal()}`
|
|
377
|
+
: `${await obj.literal()}`;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return result;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
slice = async (other, args) => {
|
|
384
|
+
let i = await other.literal();
|
|
385
|
+
let stop = args[1] ? await args[1].literal() : this.config.length;
|
|
386
|
+
let skip = args[2] ? await args[2].literal() : 1;
|
|
387
|
+
|
|
388
|
+
let res = new Array(),
|
|
389
|
+
chain = await this.chain();
|
|
390
|
+
while (i < stop) {
|
|
391
|
+
let obj = await chain.index({ arr: this.config, i });
|
|
392
|
+
if (!obj) break;
|
|
393
|
+
|
|
394
|
+
res.push(obj);
|
|
395
|
+
i += skip;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return await this.account.vm.instantiate(
|
|
399
|
+
{
|
|
400
|
+
value: res,
|
|
401
|
+
location: this.spawn_address(),
|
|
402
|
+
type: "array",
|
|
403
|
+
},
|
|
404
|
+
{ chain }
|
|
405
|
+
);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
splice = async (other, args) => {
|
|
409
|
+
let i = await other.literal();
|
|
410
|
+
let count = args[1] ? await args[1].literal() : this.config.length - i;
|
|
411
|
+
|
|
412
|
+
let replacement = args[2];
|
|
413
|
+
|
|
414
|
+
let res = new Array(),
|
|
415
|
+
chain = await this.chain();
|
|
416
|
+
|
|
417
|
+
if (i < 0) {
|
|
418
|
+
i = this.config.length + i;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
while (this.config.length > i && count) {
|
|
422
|
+
let obj = await chain.pop({ arr: this.config, index: i });
|
|
423
|
+
if (!obj) break;
|
|
424
|
+
res.push(obj);
|
|
425
|
+
count--;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (replacement) {
|
|
429
|
+
await chain.insert({
|
|
430
|
+
arr: this.config,
|
|
431
|
+
index: i,
|
|
432
|
+
item: await replacement.to_address(),
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return await this.account.vm.instantiate(
|
|
437
|
+
{
|
|
438
|
+
value: res,
|
|
439
|
+
location: this.spawn_address(),
|
|
440
|
+
type: "array",
|
|
441
|
+
},
|
|
442
|
+
{ chain }
|
|
443
|
+
);
|
|
444
|
+
};
|
|
275
445
|
|
|
276
|
-
|
|
446
|
+
is_empty = () => {
|
|
447
|
+
return !this.config.length;
|
|
448
|
+
};
|
|
277
449
|
|
|
278
|
-
|
|
450
|
+
includes = async (other) => {
|
|
451
|
+
other = await other.literal();
|
|
452
|
+
let result = false,
|
|
453
|
+
chain = await this.chain();
|
|
454
|
+
for (let i = 0; i < this.config.length; i++) {
|
|
455
|
+
let item = await chain.index({ arr: this.config, i });
|
|
456
|
+
let obj = await this.account.vm.cloth(item);
|
|
457
|
+
if ((await obj.literal()) === other) {
|
|
458
|
+
result = true;
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return result;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
repeat = async (other) => {
|
|
467
|
+
other = await other.literal();
|
|
468
|
+
let chain = await this.chain();
|
|
469
|
+
let length = this.config.length;
|
|
470
|
+
for (let i = 1; i < other; i++) {
|
|
471
|
+
for (let k = 0; k < length; k++) {
|
|
472
|
+
let item = await chain.index({ arr: this.config, i: k });
|
|
473
|
+
await chain.insert({
|
|
474
|
+
arr: this.config,
|
|
475
|
+
item,
|
|
476
|
+
index: this.config.length,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
return this.config.length;
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
clear = async () => {
|
|
485
|
+
let chain = await this.chain();
|
|
486
|
+
while (this.config.length) {
|
|
487
|
+
await chain.pop({ arr: this.config, index: this.config.length - 1 });
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
index = async (other) => {
|
|
492
|
+
if (other == null) return;
|
|
493
|
+
|
|
494
|
+
let chain = await this.chain();
|
|
495
|
+
let i = other.literal ? await other.literal() : other;
|
|
279
496
|
|
|
280
|
-
|
|
497
|
+
i = await this.normalise_index_(i)
|
|
498
|
+
if (i.__interrupt__) return i
|
|
499
|
+
|
|
500
|
+
return await chain.index({ arr: this.config, i });
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
normalise_index_ = async(i)=>{
|
|
504
|
+
if (i < 0) {
|
|
505
|
+
i = this.config.length + i;
|
|
506
|
+
}
|
|
507
|
+
if (i >= this.config.length || i < 0){
|
|
508
|
+
return await this.account.vm.throw_error({type:"IndexError", message: `Index value out of range 0-${this.config.length-1}`})
|
|
509
|
+
}
|
|
510
|
+
return i
|
|
281
511
|
}
|
|
512
|
+
pop = async (other) => {
|
|
513
|
+
let chain = await this.chain();
|
|
514
|
+
|
|
515
|
+
if (other.type !== 'number'){
|
|
516
|
+
return await this.account.vm.throw_error({type:"TypeError", message: 'Array.pop method expects a numeric index'})
|
|
517
|
+
}
|
|
518
|
+
let index = await other.literal()
|
|
519
|
+
|
|
520
|
+
index = await this.normalise_index_(index)
|
|
521
|
+
if (index.__interrupt__) return index
|
|
522
|
+
|
|
523
|
+
let res = await chain.pop({ arr: this.config, index });
|
|
524
|
+
|
|
525
|
+
return res;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
insert = async (other, args) => {
|
|
529
|
+
let item = await other.to_address();
|
|
530
|
+
if (other.object) item.object = other.object;
|
|
531
|
+
|
|
532
|
+
let chain = await this.chain();
|
|
533
|
+
let index = await args[1].literal();
|
|
534
|
+
if (index === -1) {
|
|
535
|
+
index = this.config.length - 1;
|
|
536
|
+
} else {
|
|
537
|
+
if (index < 0) {
|
|
538
|
+
index = this.config.length + index;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (index >= this.config.length){
|
|
542
|
+
index = this.config.length
|
|
543
|
+
}
|
|
544
|
+
await chain.insert({ arr: this.config, item, index });
|
|
545
|
+
|
|
546
|
+
return this.config.length;
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
push = async (other) => {
|
|
550
|
+
let chain = await this.chain();
|
|
551
|
+
let item = await other.to_address();
|
|
552
|
+
if (other.object) item.object = other.object;
|
|
553
|
+
|
|
554
|
+
await chain.insert({ arr: this.config, item, index: this.config.length });
|
|
555
|
+
|
|
556
|
+
return this.config.length;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
literal = async () => {
|
|
560
|
+
if (this.value) return this.value;
|
|
561
|
+
|
|
562
|
+
let value = new Array();
|
|
563
|
+
|
|
564
|
+
let folder = await this._folder();
|
|
565
|
+
for (let i = 0; i < this.config.length; i++) {
|
|
566
|
+
let item_folder = await folder.folder(i.toString());
|
|
567
|
+
let item = (await item_folder.readone());
|
|
568
|
+
|
|
569
|
+
let obj = await this.account.vm.cloth(item);
|
|
570
|
+
|
|
571
|
+
value.push(await obj.literal());
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
this.value = value;
|
|
575
|
+
return value;
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
configs = (name) => {
|
|
579
|
+
let conf = {
|
|
580
|
+
push: {
|
|
581
|
+
parameters: [{ name: "item", position: 0 }],
|
|
582
|
+
},
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
return conf[name];
|
|
586
|
+
};
|
|
282
587
|
}
|
|
283
588
|
|
|
284
589
|
export default Arr;
|