godprotocol 1.0.842 → 1.1.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/Executables/callables.js +131 -0
- package/Executables/executables.js +230 -0
- package/Executables/functions/adminstrator/adm_register.js +29 -0
- package/Executables/functions/adminstrator/native_components.js +10 -0
- package/Executables/functions/adminstrator/query_selectors.js +10 -0
- package/Executables/functions/adminstrator/render.js +24 -0
- package/Executables/functions/array_register.js +161 -0
- package/Executables/functions/assign.js +19 -0
- package/Executables/functions/display.js +55 -0
- package/Executables/functions/folder.js +95 -0
- package/Executables/functions/folder_register.js +87 -0
- package/Executables/functions/importcheck.js +13 -0
- package/Executables/functions/indices.js +56 -0
- package/Executables/functions/len.js +22 -0
- package/Executables/functions/methods/array.js +272 -0
- package/Executables/functions/methods/string.js +197 -0
- package/Executables/functions/methods/twain.js +148 -0
- package/Executables/functions/op.js +15 -0
- package/Executables/functions/price_register.js +30 -0
- package/Executables/functions/pricing.js +26 -0
- package/Executables/functions/servers/account.js +81 -0
- package/Executables/functions/servers/account_register.js +56 -0
- package/Executables/functions/servers/block.js +21 -0
- package/Executables/functions/servers/block_register.js +18 -0
- package/Executables/functions/servers/chain.js +42 -0
- package/Executables/functions/servers/chain_register.js +28 -0
- package/Executables/functions/set_error_catch.js +34 -0
- package/Executables/functions/string_register.js +130 -0
- package/Executables/functions/twain_register.js +56 -0
- package/Executables/functions/typecast.js +43 -0
- package/Executables/functions/utils.js +9 -0
- package/Executables/stack.js +53 -0
- package/Index.js +2 -55
- package/Loader_sequence/main.js +371 -124
- package/Loader_sequence/repository.js +1 -1
- package/Objects/Account.js +101 -34
- package/Objects/Block.js +24 -18
- package/Objects/Blockweb.js +1 -1
- package/Objects/Chain.js +127 -29
- package/Objects/Explorer.js +3 -17
- package/Objects/Fee.js +33 -0
- package/Objects/Filesystem.js +98 -25
- package/Objects/Frame.js +10 -3
- package/Objects/Manager.js +193 -23
- package/Objects/Opcodes.js +48 -10
- package/Objects/Oracle.js +11 -8
- package/Objects/Protocol.js +5 -0
- package/Objects/Virtual_machine.js +130 -59
- package/Trinity.js +20 -0
- package/callables.js +172 -0
- package/framer.js +65 -12
- package/opcodes/add.js +6 -1
- package/opcodes/indices.js +60 -6
- package/opcodes/jmp.js +2 -0
- package/opcodes/std.js +5 -2
- package/opcodes.js +56 -18
- package/package.json +2 -2
- package/starter_scripts/constants.seq +11 -0
- package/utils/create_server.js +15 -7
- package/utils/hash.js +2 -2
- package/utils/logger.js +79 -0
- package/utils/services.js +5 -3
- package/utils/type_coersion.js +3 -0
- package/utils/vm_utils.js +292 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
class Callables{
|
|
2
|
+
constructor(){
|
|
3
|
+
this.callables = new Object()
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
prepare_callable_args = (config, payload)=>{
|
|
7
|
+
|
|
8
|
+
let {arguments:args} = payload;
|
|
9
|
+
let {argv} = args;
|
|
10
|
+
|
|
11
|
+
let arg_obj = {}, spreading;
|
|
12
|
+
|
|
13
|
+
for (let a=0;a< argv.length;a++){
|
|
14
|
+
let arg = argv[a]
|
|
15
|
+
|
|
16
|
+
let param, content = arg.static_value || this.read_chain(arg.address)
|
|
17
|
+
if(spreading){
|
|
18
|
+
arg_obj[spreading].push(content)
|
|
19
|
+
} else {
|
|
20
|
+
if (arg.name){
|
|
21
|
+
arg_obj[arg.name] = content;
|
|
22
|
+
param = config.parameters.find(p=>p.name === arg.name)
|
|
23
|
+
}else {
|
|
24
|
+
param = config.parameters[arg.position]
|
|
25
|
+
if(!param)continue
|
|
26
|
+
arg_obj[param.name] = content
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (param.spread){
|
|
30
|
+
spreading = param.name;
|
|
31
|
+
arg_obj[spreading] = [arg_obj[spreading]]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return arg_obj
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
callable = (payload)=>{
|
|
40
|
+
let {executable, metadata, location} = payload;
|
|
41
|
+
if (!metadata)metadata = {}
|
|
42
|
+
|
|
43
|
+
let call = this.callables[executable];
|
|
44
|
+
if(!call)return this.stderr(`Callable:${executable} is not set`)
|
|
45
|
+
|
|
46
|
+
let callable = call.callable;
|
|
47
|
+
let config = call.config
|
|
48
|
+
|
|
49
|
+
if (typeof callable !== 'function') return this.stderr(`Callable:${executable} must be a callable type.`)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
let args;
|
|
53
|
+
if (config) {
|
|
54
|
+
args = this.prepare_callable_args(config, payload)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let result = callable(args, this, {...payload, location})
|
|
58
|
+
if (!metadata.raw )
|
|
59
|
+
result && this.write_chain(result.result,result.address|| location, {is_callable: result.is_callable})
|
|
60
|
+
|
|
61
|
+
return metadata.raw ? result : {
|
|
62
|
+
estimated_time: '-ms',
|
|
63
|
+
callback: location
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
write_chain = (result, location, options)=>{
|
|
68
|
+
if (result==null)return
|
|
69
|
+
let {is_callable}=options || {};
|
|
70
|
+
|
|
71
|
+
let loc_chain = this.handle_chain(location)
|
|
72
|
+
|
|
73
|
+
if(is_callable){
|
|
74
|
+
loc_chain.set_obj_config(result)
|
|
75
|
+
}else {
|
|
76
|
+
loc_chain.forge_block({metadata: {output: this.account.save(result)}})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
add_callable = (name, callable_config)=>{
|
|
81
|
+
this.callables[name] = callable_config
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
composite_depth = 3
|
|
85
|
+
|
|
86
|
+
display = (values, options )=>{
|
|
87
|
+
let {buff, depth, include_address} = options || {}, value;
|
|
88
|
+
if (!buff) buff = new Object()
|
|
89
|
+
|
|
90
|
+
if (!values)return values
|
|
91
|
+
|
|
92
|
+
if (values.__print__ ){
|
|
93
|
+
let stat = this.static_value(values, true)
|
|
94
|
+
if(!stat)return values;
|
|
95
|
+
value = stat
|
|
96
|
+
}else value = values
|
|
97
|
+
|
|
98
|
+
let hash = this.account.manager.oracle.hash(value);
|
|
99
|
+
if (buff[hash]) return buff[hash]
|
|
100
|
+
|
|
101
|
+
if(value.type === 'array'){
|
|
102
|
+
let arr = []
|
|
103
|
+
for (let a=0; a< value.static_value.length; a++){
|
|
104
|
+
arr.push(this.display(this.read_chain(value.static_value[a]), {buff}))
|
|
105
|
+
}
|
|
106
|
+
value = arr;
|
|
107
|
+
}else if (value.type === 'twain'){
|
|
108
|
+
let keys = Object.keys(value.static_value)
|
|
109
|
+
let obj = {}
|
|
110
|
+
for (let s=0; s< keys.length; s++){
|
|
111
|
+
let key = keys[s]
|
|
112
|
+
let pair = value.static_value[key]
|
|
113
|
+
|
|
114
|
+
let prop = this.display(this.read_chain(pair[0]), {buff})
|
|
115
|
+
|
|
116
|
+
obj[prop] = this.display(this.read_chain(pair[1]), {buff})
|
|
117
|
+
}
|
|
118
|
+
value = obj
|
|
119
|
+
}else if (['string', 'number', 'boolean'].includes(value.type)){
|
|
120
|
+
value = value.static_value
|
|
121
|
+
}else value = (value && value.__address__) || value
|
|
122
|
+
|
|
123
|
+
buff[hash] = value;
|
|
124
|
+
|
|
125
|
+
if (depth == null){
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export default Callables
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { generate_random_string } from "generalised-datastore/utils/functions";
|
|
2
|
+
import Callables from "./callables";
|
|
3
|
+
import Stack from "./stack";
|
|
4
|
+
import { post_request } from "godprotocol/utils/services";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Executables extends Callables{
|
|
8
|
+
constructor(){
|
|
9
|
+
super()
|
|
10
|
+
|
|
11
|
+
this.stack = new Stack(this)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exec = (request)=>{
|
|
15
|
+
let payload = request.op0 || request;
|
|
16
|
+
|
|
17
|
+
let {executable, url_callback, location} = payload;
|
|
18
|
+
console.log(request)
|
|
19
|
+
|
|
20
|
+
if (!executable && request.op1) executable = request.op1.static_value
|
|
21
|
+
|
|
22
|
+
if(typeof executable !== 'string' && executable){
|
|
23
|
+
executable = executable.static_value || executable.__address__
|
|
24
|
+
}
|
|
25
|
+
if(!executable)return this.stderr({name: 'Call_error', message:"Executable cannot be undefined"})
|
|
26
|
+
|
|
27
|
+
if (!executable.includes('/')){
|
|
28
|
+
let result = this.callable(payload)
|
|
29
|
+
if (url_callback) post_request({options:url_callback, data: result})
|
|
30
|
+
return result
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if(executable.includes('undefined')){
|
|
34
|
+
console.log(executable)
|
|
35
|
+
let err_obj = {name:'Type_error', message: `executable cannot have an undefined config`}
|
|
36
|
+
return this.stderr(err_obj)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// console.log(payload)
|
|
40
|
+
let config = this.get_config(executable)
|
|
41
|
+
if (!config){
|
|
42
|
+
return this.stderr({name:'Name_error', message:'Callable config not existing'})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
switch(config.type){
|
|
46
|
+
case "class":
|
|
47
|
+
this.execute_class(config, payload)
|
|
48
|
+
break;
|
|
49
|
+
case "function":
|
|
50
|
+
this.execute_function(config, payload)
|
|
51
|
+
break;
|
|
52
|
+
case "module":
|
|
53
|
+
this.execute_module(config, payload)
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
this.stderr(`Unknown call type`)
|
|
57
|
+
;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
estimated_time: `-ms`,
|
|
62
|
+
callback: location,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
execute_class = (config, payload)=>{
|
|
67
|
+
let {methods, base_classes} = config;
|
|
68
|
+
let {location, local_address, url_callback, executable} = payload;
|
|
69
|
+
|
|
70
|
+
let object = {__classifier__:executable, __type__: `${this.account.physical_address}/CONSTANTS/types/instance`}
|
|
71
|
+
let object_id = generate_random_string(12, 'alnum')
|
|
72
|
+
object.__id__ = object_id
|
|
73
|
+
|
|
74
|
+
let real_path = `${local_address || location}_${object_id}`
|
|
75
|
+
let object_chain = this.handle_chain(real_path)
|
|
76
|
+
|
|
77
|
+
let location_height = object_chain.height;
|
|
78
|
+
|
|
79
|
+
for (let b=0; b< base_classes.length; b++){
|
|
80
|
+
let cls = base_classes[b]
|
|
81
|
+
let cls_config = this.get_config(cls);
|
|
82
|
+
|
|
83
|
+
if(!cls_config || (cls_config && cls_config.type !== 'class')){
|
|
84
|
+
return this.stderr(`Base must be a 'class' type`)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let {methods: b_methods} = cls_config;
|
|
88
|
+
for(let name in b_methods){
|
|
89
|
+
let method_addr = b_methods[name]
|
|
90
|
+
|
|
91
|
+
this.handle_method_config({name, method_addr, object, location: real_path, location_height})
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for(let name in methods){
|
|
95
|
+
let method_addr = methods[name]
|
|
96
|
+
|
|
97
|
+
this.handle_method_config({name, method_addr, object, location: real_path, location_height})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
object.__address__ = real_path;
|
|
101
|
+
|
|
102
|
+
object_chain.forge_block({metadata:{output: this.account.save(object)}})
|
|
103
|
+
|
|
104
|
+
if (object.__init__){
|
|
105
|
+
this.execute_function(this.get_config(object.__init__), {...payload, executable: object.__init__})
|
|
106
|
+
}else {
|
|
107
|
+
if (url_callback) post_request({options:url_callback, data: object})
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
execute_function = (config, payload)=>{
|
|
112
|
+
let {arguments: args, location, url_callback, executable, metadata}=payload;
|
|
113
|
+
let {argv, argc} = args ||{};
|
|
114
|
+
argv = argv || []
|
|
115
|
+
let {parameters, object, __address__, method_address} = config;
|
|
116
|
+
|
|
117
|
+
let exec_address = method_address || __address__
|
|
118
|
+
|
|
119
|
+
this.stack.initiate(exec_address)
|
|
120
|
+
|
|
121
|
+
let arg_object = {}
|
|
122
|
+
parameters.map((p, i)=>{
|
|
123
|
+
arg_object[p.name] = {address: p.address, name: p.name, position: p.position || i}
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
for (let a =0; a< (argc || argv.length); a++){
|
|
127
|
+
let arg = argv[a]
|
|
128
|
+
let param;
|
|
129
|
+
if (arg.name) {
|
|
130
|
+
param = parameters.find(p=>p.name === arg.name)
|
|
131
|
+
} else {
|
|
132
|
+
param = parameters[arg.position]
|
|
133
|
+
arg.name = param.name
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
arg_object[arg.name].address = arg.address
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if(object){
|
|
140
|
+
arg_object.this = {
|
|
141
|
+
position:-1,
|
|
142
|
+
address: object,
|
|
143
|
+
name:'this'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
for (let a in arg_object) {
|
|
148
|
+
let arg = arg_object[a]
|
|
149
|
+
let param_addr = `${exec_address}/${a}`
|
|
150
|
+
let param_chain = this.handle_chain(param_addr);
|
|
151
|
+
|
|
152
|
+
let arg_chain = this.handle_chain(arg.address)
|
|
153
|
+
|
|
154
|
+
if(arg_chain.datapath){
|
|
155
|
+
param_chain.set_obj_config(arg_chain.datapath)
|
|
156
|
+
}else {
|
|
157
|
+
let val = this.read_chain(arg_chain)
|
|
158
|
+
param_chain.forge_block({metadata: {output: this.account.save(val)}})
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.account.run({payload: {physical_address: method_address || __address__}, callback: ({ret})=>{
|
|
163
|
+
this.stack.pop(exec_address)
|
|
164
|
+
this.pop_context()
|
|
165
|
+
|
|
166
|
+
let res;
|
|
167
|
+
|
|
168
|
+
if (typeof location === 'function'){
|
|
169
|
+
res = this.read_chain(ret)
|
|
170
|
+
if(metadata && metadata.loop){
|
|
171
|
+
|
|
172
|
+
if (!metadata.loop.conditioner(res, metadata) && (metadata.loop.index+1) < metadata.loop.array.length){
|
|
173
|
+
metadata.loop.index ++
|
|
174
|
+
|
|
175
|
+
this.exec({executable, location, metadata, arguments: {argv: [{
|
|
176
|
+
address: metadata.loop.array[metadata.loop.index],
|
|
177
|
+
position: 0
|
|
178
|
+
}], argc: 1}})
|
|
179
|
+
|
|
180
|
+
return metadata.callback && metadata.callback(res)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
location(res, metadata)
|
|
184
|
+
|
|
185
|
+
}else if(ret){
|
|
186
|
+
let chain = this.handle_chain(ret)
|
|
187
|
+
let loc_chain = this.handle_chain(location)
|
|
188
|
+
|
|
189
|
+
if(chain.datapath){
|
|
190
|
+
res = chain.datapath;
|
|
191
|
+
loc_chain.set_obj_config(res)
|
|
192
|
+
}else {
|
|
193
|
+
res = this.read_chain(chain)
|
|
194
|
+
if (url_callback) post_request({options:url_callback, data: res})
|
|
195
|
+
|
|
196
|
+
loc_chain.forge_block({metadata: {output: this.account.save(res)}})
|
|
197
|
+
loc_chain.set_obj_config('')
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if(metadata && metadata.callback){
|
|
202
|
+
metadata.callback(res)
|
|
203
|
+
}
|
|
204
|
+
}})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
handle_method_config = ({name, method_addr, location, object})=>{
|
|
208
|
+
let conf = this.get_config(method_addr);
|
|
209
|
+
|
|
210
|
+
let obj_method_addr = `${location}/${name}`
|
|
211
|
+
let chain = this.handle_chain(obj_method_addr)
|
|
212
|
+
|
|
213
|
+
conf.method_address = conf.__address__
|
|
214
|
+
conf.__address__ = obj_method_addr
|
|
215
|
+
conf.object = location;
|
|
216
|
+
chain.set_obj_config(conf)
|
|
217
|
+
|
|
218
|
+
object[name] = obj_method_addr;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
get_config = exe =>{
|
|
222
|
+
let chn = this.handle_chain(exe);
|
|
223
|
+
|
|
224
|
+
if (!chn || (chn&& !chn.datapath))return this.stderr(`Executable:${exe} is not callable`)
|
|
225
|
+
|
|
226
|
+
return this.account.read(chn.datapath)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export default Executables
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { render } from "./render";
|
|
2
|
+
import native_components, { natives } from "./native_components";
|
|
3
|
+
|
|
4
|
+
const adm_register = (account)=>{
|
|
5
|
+
let add_callable = account.vm.add_callable;
|
|
6
|
+
|
|
7
|
+
add_callable('render', {
|
|
8
|
+
callable:render,
|
|
9
|
+
config: {
|
|
10
|
+
parameters:[
|
|
11
|
+
{name:'object', position:0}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
natives.map(name=>{
|
|
17
|
+
add_callable(name, {
|
|
18
|
+
callable:(args, vm, options)=>native_components(args, vm, {...options, name}),
|
|
19
|
+
config: {
|
|
20
|
+
parameters:[
|
|
21
|
+
{name:'props', position:0}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default adm_register;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const render = (args, vm, options) => {
|
|
2
|
+
let {object, page} = args;
|
|
3
|
+
|
|
4
|
+
if (!object.render){
|
|
5
|
+
return vm.stderr({name:'Name_error', message:"A render method is neccessary for Adm display"})
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let config = vm.read_chain(object.config)
|
|
9
|
+
config = vm.display(config);
|
|
10
|
+
|
|
11
|
+
console.log(config)
|
|
12
|
+
|
|
13
|
+
vm.exec({executable: object.render, location: result=>{
|
|
14
|
+
let raw = vm.display(result, {include_address:true})
|
|
15
|
+
|
|
16
|
+
raw.address = object.__address__
|
|
17
|
+
raw.page = page;
|
|
18
|
+
|
|
19
|
+
vm.air_object(raw, options)
|
|
20
|
+
}})
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {render}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { concat, repeat, slice, pop, index, clear, insert, replace, map, find, copy, filter } from "./methods/array";
|
|
2
|
+
|
|
3
|
+
const array_register = (account)=>{
|
|
4
|
+
let add_callable = account.vm.add_callable;
|
|
5
|
+
|
|
6
|
+
add_callable('insert_', {
|
|
7
|
+
callable: insert,
|
|
8
|
+
config: {
|
|
9
|
+
parameters: [
|
|
10
|
+
{name:'arr', position:0},
|
|
11
|
+
{name:'value', position:1},
|
|
12
|
+
{name:'index', position:2},
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
add_callable('arr_slice_', {
|
|
18
|
+
callable: slice,
|
|
19
|
+
config: {
|
|
20
|
+
parameters: [
|
|
21
|
+
{name:'arr', position:0},
|
|
22
|
+
{name:'start', position:1},
|
|
23
|
+
{name:'end', position:2},
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
add_callable('arr_concat_', {
|
|
29
|
+
callable: concat,
|
|
30
|
+
config: {
|
|
31
|
+
parameters: [
|
|
32
|
+
{name:'arr', position:0},
|
|
33
|
+
{name:'other', position:1},
|
|
34
|
+
{name:'index', position:2},
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
add_callable('extend_',{
|
|
40
|
+
callable: (args, vm, options) => concat(args, vm, {...options, spread:true}),
|
|
41
|
+
config: {
|
|
42
|
+
parameters: [
|
|
43
|
+
{name:'arr', position:0},
|
|
44
|
+
{name:'other', position:1},
|
|
45
|
+
{name:'index', position:2},
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
add_callable('index_', {
|
|
51
|
+
callable: index,
|
|
52
|
+
config: {
|
|
53
|
+
parameters: [
|
|
54
|
+
{name:'arr', position:0},
|
|
55
|
+
{name:'n', position:1},
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
add_callable('pop_', {
|
|
61
|
+
callable: pop,
|
|
62
|
+
config: {
|
|
63
|
+
parameters: [
|
|
64
|
+
{name:'arr', position:0},
|
|
65
|
+
{name:'index', position:1},
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
add_callable('replace_', {
|
|
71
|
+
callable: replace,
|
|
72
|
+
config: {
|
|
73
|
+
parameters: [
|
|
74
|
+
{name:'arr', position:0},
|
|
75
|
+
{name:'index', position:1},
|
|
76
|
+
{name:'value', position:1},
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
add_callable('repeat_', {
|
|
83
|
+
callable: repeat,
|
|
84
|
+
config: {
|
|
85
|
+
parameters: [
|
|
86
|
+
{name: 'arr', position:0},
|
|
87
|
+
{name: 'n', position:1},
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
add_callable('clear_', {
|
|
93
|
+
callable: clear,
|
|
94
|
+
config: {
|
|
95
|
+
parameters: [
|
|
96
|
+
{name: 'arr', position:0},
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
add_callable('findindex_', {
|
|
102
|
+
callable:(args, vm, options)=> find(args, vm, {...options, index: true}),
|
|
103
|
+
config: {
|
|
104
|
+
parameters: [
|
|
105
|
+
{name: 'arr', position:0},
|
|
106
|
+
{name: 'executable', position:1},
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
add_callable('map_', {
|
|
112
|
+
callable: map,
|
|
113
|
+
config: {
|
|
114
|
+
parameters: [
|
|
115
|
+
{name: 'arr', position:0},
|
|
116
|
+
{name: 'executable', position:1},
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
add_callable('find_', {
|
|
122
|
+
callable: find,
|
|
123
|
+
config: {
|
|
124
|
+
parameters: [
|
|
125
|
+
{name: 'arr', position:0},
|
|
126
|
+
{name: 'executable', position:1},
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
add_callable('filter_', {
|
|
132
|
+
callable: filter,
|
|
133
|
+
config: {
|
|
134
|
+
parameters: [
|
|
135
|
+
{name:'arr', position:0},
|
|
136
|
+
{name:'executable', position:1},
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
add_callable('copy_', {
|
|
142
|
+
callable: copy,
|
|
143
|
+
config: {
|
|
144
|
+
parameters: [
|
|
145
|
+
{name:'arr', position:0},
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
add_callable('deepcopy_', {
|
|
151
|
+
callable: (args, vm, options)=>copy(args, vm, {...options, deep:true}),
|
|
152
|
+
config: {
|
|
153
|
+
parameters: [
|
|
154
|
+
{name:'arr', position:0},
|
|
155
|
+
{name:'depth', position:1},
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default array_register
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const assign = (args, vm, options)=>{
|
|
2
|
+
let {location, arguments: argg} = options;
|
|
3
|
+
let {value} = args;
|
|
4
|
+
|
|
5
|
+
let value_addr = argg.argv[0].address;
|
|
6
|
+
let value_chain = vm.handle_chain(value_addr);
|
|
7
|
+
|
|
8
|
+
let loc_chain = vm.handle_chain(location)
|
|
9
|
+
if(value_chain.datapath){
|
|
10
|
+
loc_chain.set_obj_config(value_chain.datapath)
|
|
11
|
+
}else {
|
|
12
|
+
|
|
13
|
+
loc_chain.forge_block({metadata:{output: vm.account.save(value)}})
|
|
14
|
+
loc_chain.set_obj_config('')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export default assign
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const display = (args, vm, options) => {
|
|
2
|
+
let { data } = args;
|
|
3
|
+
|
|
4
|
+
// console.log(args, 'display.args')
|
|
5
|
+
if (!Array.isArray(data)) data = [data];
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if (options.metadata && options.metadata.raw){
|
|
9
|
+
return vm.display(vm.static_value(data[0]))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let val = new Array(data.length),
|
|
13
|
+
d = 0;
|
|
14
|
+
|
|
15
|
+
for (d = 0; d < data.length; d++) {
|
|
16
|
+
let dat = data[d];
|
|
17
|
+
|
|
18
|
+
if(!dat){continue}
|
|
19
|
+
if (dat.static_value) {
|
|
20
|
+
val[d] = dat.static_value;
|
|
21
|
+
} else if (dat.__print__) {
|
|
22
|
+
vm.exec({
|
|
23
|
+
executable: dat.__print__,
|
|
24
|
+
metadata: { index: d },
|
|
25
|
+
location: (result, metadata) => {
|
|
26
|
+
if (result.__print__) {
|
|
27
|
+
result = vm.static_value(result, true);
|
|
28
|
+
if (!result) {
|
|
29
|
+
this.stderr({
|
|
30
|
+
name: "Type_error",
|
|
31
|
+
message: `class.__print__ must return one of type boolean | string | number | twain | array | void`,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
val[metadata.index] = result;
|
|
36
|
+
|
|
37
|
+
if (val.filter((v) => !!v).length === data.length) {
|
|
38
|
+
vm.display(val)
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
val[d] = JSON.stringify(dat);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (val.filter((v) => !!v).length === data.length) {
|
|
48
|
+
vm.display(val)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (options.metadata && options.metadata.raw)
|
|
52
|
+
return JSON.parse(val[0])
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { display };
|