godprotocol 1.1.0 → 1.1.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.
Files changed (98) hide show
  1. package/Datatypes/arr.js +11 -0
  2. package/Datatypes/bool.js +11 -0
  3. package/Datatypes/callable.js +11 -0
  4. package/Datatypes/functions/storage.js +5 -0
  5. package/Datatypes/num.js +11 -0
  6. package/Datatypes/str.js +11 -0
  7. package/Datatypes/twa.js +11 -0
  8. package/Datatypes/voi.js +11 -0
  9. package/Index.js +36 -2
  10. package/Objects/Account.js +35 -322
  11. package/Objects/Block.js +7 -80
  12. package/Objects/Blockweb.js +19 -26
  13. package/Objects/Callable.js +40 -0
  14. package/Objects/Chain.js +20 -244
  15. package/Objects/GDS/Arena_classic/.config +1 -0
  16. package/Objects/GDS/Arena_classic/Accounts/lola/.config +1 -0
  17. package/Objects/Manager.js +28 -294
  18. package/Objects/Oracle.js +67 -84
  19. package/Objects/Repository.js +67 -0
  20. package/Objects/Trinity.js +24 -0
  21. package/Objects/Virtual_machine.js +16 -206
  22. package/callables/functions/assign.js +6 -0
  23. package/callables/functions/display.js +3 -0
  24. package/callables/register.js +22 -0
  25. package/package.json +24 -43
  26. package/utils/create_server.js +35 -88
  27. package/utils/functions.js +0 -70
  28. package/utils/server.cert +23 -0
  29. package/utils/server.key +28 -0
  30. package/utils/services.js +61 -21
  31. package/utils/vm_utils.js +53 -275
  32. package/Executables/callables.js +0 -131
  33. package/Executables/executables.js +0 -230
  34. package/Executables/functions/adminstrator/adm_register.js +0 -29
  35. package/Executables/functions/adminstrator/native_components.js +0 -10
  36. package/Executables/functions/adminstrator/query_selectors.js +0 -10
  37. package/Executables/functions/adminstrator/render.js +0 -24
  38. package/Executables/functions/array_register.js +0 -161
  39. package/Executables/functions/assign.js +0 -19
  40. package/Executables/functions/display.js +0 -55
  41. package/Executables/functions/folder.js +0 -95
  42. package/Executables/functions/folder_register.js +0 -87
  43. package/Executables/functions/importcheck.js +0 -13
  44. package/Executables/functions/indices.js +0 -56
  45. package/Executables/functions/len.js +0 -22
  46. package/Executables/functions/methods/array.js +0 -272
  47. package/Executables/functions/methods/string.js +0 -197
  48. package/Executables/functions/methods/twain.js +0 -148
  49. package/Executables/functions/op.js +0 -15
  50. package/Executables/functions/price_register.js +0 -30
  51. package/Executables/functions/pricing.js +0 -26
  52. package/Executables/functions/servers/account.js +0 -81
  53. package/Executables/functions/servers/account_register.js +0 -56
  54. package/Executables/functions/servers/block.js +0 -21
  55. package/Executables/functions/servers/block_register.js +0 -18
  56. package/Executables/functions/servers/chain.js +0 -42
  57. package/Executables/functions/servers/chain_register.js +0 -28
  58. package/Executables/functions/set_error_catch.js +0 -34
  59. package/Executables/functions/string_register.js +0 -130
  60. package/Executables/functions/twain_register.js +0 -56
  61. package/Executables/functions/typecast.js +0 -43
  62. package/Executables/functions/utils.js +0 -9
  63. package/Executables/stack.js +0 -53
  64. package/Loader_sequence/main.js +0 -805
  65. package/Loader_sequence/repository.js +0 -33
  66. package/Objects/Explorer.js +0 -40
  67. package/Objects/Fee.js +0 -33
  68. package/Objects/Filesystem.js +0 -216
  69. package/Objects/Frame.js +0 -54
  70. package/Objects/Opcodes.js +0 -87
  71. package/Objects/Protocol.js +0 -5
  72. package/Trinity.js +0 -20
  73. package/callables.js +0 -172
  74. package/framer.js +0 -124
  75. package/opcodes/add.js +0 -15
  76. package/opcodes/indices.js +0 -82
  77. package/opcodes/jmp.js +0 -16
  78. package/opcodes/std.js +0 -12
  79. package/opcodes.js +0 -96
  80. package/readme.md +0 -133
  81. package/starter_scripts/constants.seq +0 -11
  82. package/tsconfig.json +0 -8
  83. package/types/Account.d.ts +0 -73
  84. package/types/Block.d.ts +0 -22
  85. package/types/Blockweb.d.ts +0 -14
  86. package/types/Chain.d.ts +0 -35
  87. package/types/Explorer.d.ts +0 -9
  88. package/types/Filesystem.d.ts +0 -23
  89. package/types/Frame.d.ts +0 -14
  90. package/types/Manager.d.ts +0 -21
  91. package/types/Opcodes.d.ts +0 -11
  92. package/types/Oracle.d.ts +0 -17
  93. package/types/Virtual_machine.d.ts +0 -20
  94. package/types/index.d.ts +0 -4
  95. package/utils/hash.js +0 -13
  96. package/utils/logger.js +0 -79
  97. package/utils/privacy.js +0 -22
  98. package/utils/type_coersion.js +0 -3
@@ -1,805 +0,0 @@
1
- import { _id } from "generalised-datastore/utils/functions";
2
- import Repository from "./repository";
3
-
4
- let num_pattern = /^\d+(\.\d+)?$/;
5
- let var_pattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
6
- let addr_pattern = /^(@\/|\.\.\/|\.\/)?([A-Za-z0-9_\-]+\/)*[A-Za-z0-9_\-]+$/
7
-
8
- class Loader {
9
- constructor(account) {
10
- this.account = account;
11
- this.opcodes = new Array();
12
- this.instructions = new Array();
13
-
14
- this.instruction_indexes = new Array();
15
- this.instruction_stacks = [[]];
16
- this.stacks = new Array(account.physical_address);
17
- this.markers = new Array();
18
- this.program_configs = new Array();
19
- this.programs_index = -1;
20
-
21
- this.datatypes = new Array('twain', 'string','void', 'boolean', 'array', 'number')
22
- this.configs = new Object()
23
-
24
- // Code Repository
25
- this.repository = new Repository(this);
26
- }
27
-
28
- instruction_index = () => {
29
- let len = this.instruction_indexes.length -1
30
- this.instruction_indexes[len]++
31
-
32
- return this.instruction_indexes[len]
33
- };
34
-
35
- stack_instruction = (instruction) => {
36
- if (Array.isArray(instruction))
37
- return instruction.map((i) => this.stack_instruction(i));
38
-
39
- this.instruction_stacks.slice(-1)[0].push(instruction);
40
- };
41
-
42
- new_stack = (addr) => {
43
- this.stacks.push(addr);
44
- };
45
-
46
- push_instruction = (instruction) => {
47
- if (Array.isArray(instruction))
48
- return instruction.map((i) => this.push_instruction(i));
49
-
50
- if (this.pure) {
51
- this.instructions.push(instruction);
52
- } else {
53
- this.stack_instruction(`cursor ${this.instruction_index()}`);
54
-
55
- this.stack_instruction(`write ${instruction}`);
56
- }
57
- };
58
-
59
- parse_tokens = (line, options) => {
60
- options = options ||{}
61
- let {stop_char, all_static, inline} = options;
62
-
63
- let tokens = new Array();
64
- let pos = 0;
65
- all_static = this.pure || this.no_static?false: all_static == undefined? true: all_static;
66
-
67
- let push_token = (value, type) =>{
68
- if (stop_char){
69
- if (['variable','address', 'inline_address'].includes(type)) {
70
- all_static = false
71
- }
72
- }
73
- let tok_obj = { value, type, line: this.line_count, pos : pos-value.length}
74
- if (['twain', 'array'].includes(type)){
75
- tok_obj.all_static = all_static
76
- }
77
-
78
- tokens.push(tok_obj);
79
- };
80
-
81
- line = line.trim();
82
- while (pos < line.length) {
83
- let char = line[pos].trim();
84
-
85
- if (char === stop_char) return { tokens, pos, all_static};
86
-
87
- if (!char) {
88
- pos++;
89
-
90
- continue;
91
- }
92
-
93
- if (char === "\n") {
94
- pos++;
95
- } else if (char === '/' && line[pos+1]==='/'){
96
- pos = line.length
97
- }else if (char === '%' && inline){
98
- pos++
99
- let acc = line[pos]
100
- pos++
101
- while (line[pos] && var_pattern.test(`${acc}${line[pos]}`)) {
102
- acc += line[pos];
103
- pos++;
104
- }
105
- push_token(acc, "inline_address");
106
- } else if (char === "@" || char === ".") {
107
- let acc = "";
108
- while (line[pos] && line[pos].trim() && (line[pos] !== stop_char) && ![','].includes(line[pos]) ) {
109
- acc += line[pos];
110
- pos++;
111
- }
112
- push_token(acc, "address");
113
- } else if (char === ",") {
114
- pos++;
115
- } else if (char === ":") {
116
-
117
- push_token(char, "separator");
118
- pos++;
119
- } else if (char === "[") {
120
- pos++;
121
- let pre_stat = all_static
122
- if(!stop_char && !this.pure)all_static = true;
123
-
124
- let toks = this.parse_tokens(line.slice(pos),{stop_char: "]", all_static});
125
- if(stop_char) all_static = toks.all_static && all_static
126
- else all_static = toks.all_static
127
-
128
- push_token([...toks.tokens], "array");
129
- all_static = pre_stat
130
-
131
- pos += toks.pos + 1;
132
- } else if (char === "{") {
133
- pos++;
134
- let pre_stat = all_static
135
- if(!stop_char && !this.pure)all_static = true;
136
-
137
- let toks = this.parse_tokens(line.slice(pos), {stop_char: "}", all_static});
138
- if(stop_char) all_static = toks.all_static && all_static
139
- else all_static = toks.all_static
140
-
141
- push_token([...toks.tokens], "twain");
142
- all_static = pre_stat
143
- pos += toks.pos + 1;
144
- } else if (char === ">") {
145
- pos++;
146
- } else if (char === "'" || char === '"') {
147
- let acc = "";
148
- pos++;
149
- while (line[pos] !== char) {
150
- if (!line[pos]) break;
151
- acc += line[pos];
152
- pos++;
153
- }
154
- pos++;
155
- push_token(acc, "string");
156
- } else if (num_pattern.test(char) || char === "-") {
157
- let acc = char;
158
- pos++;
159
- while (
160
- num_pattern.test(line[pos]) ||
161
- (line[pos] === "." && !acc.includes(line[pos]))
162
- ) {
163
- if (!line[pos]) break;
164
-
165
- acc += line[pos];
166
- pos++;
167
- }
168
- push_token(acc, "number");
169
- } else if (var_pattern.test(char) || char === '(') {
170
- let depthed = char==='('
171
- let acc;
172
- if (depthed){
173
- pos++
174
- acc =line[pos]
175
- }else acc = char
176
-
177
- pos++;
178
- while (line[pos] && var_pattern.test(`${acc}${line[pos]}`)) {
179
- acc += line[pos];
180
- pos++;
181
- }
182
-
183
- if (depthed){
184
- if (line[pos] !== ')')throw new Error('Unbounded')
185
- acc = `(${acc})`
186
- pos++
187
- }
188
-
189
- acc = acc.trim()
190
- push_token(acc, ['True', 'False'].includes(acc)?'boolean': acc ==='Void'?'void':this.opcodes.includes(acc) ? "opcode" : "variable");
191
-
192
- }
193
- }
194
-
195
- return tokens;
196
- };
197
-
198
- static_parse = ({token, previous_pure, options, identifier}, fn)=>{
199
- this.pure = token.all_static?'stack':previous_pure
200
-
201
- let physical_address = this.stacks.slice(-1)[0]
202
- if(!identifier && token.all_static && !options.all_static){
203
- identifier = {value: this.account.manager.oracle.hash(token, 'sha-1')}
204
- if (!isNaN(Number(identifier.value[0]))){
205
- identifier.value = `_${identifier.value}`
206
- }
207
- }
208
- if (token.all_static && !options.all_static){
209
- this.push_instruction(`link ${physical_address}/${identifier.value}`)
210
- }
211
-
212
- fn()
213
-
214
- if (token.all_static && identifier &&!options.all_static){
215
- this.push_instruction([
216
- 'cursor {output}',
217
- 'write {datapath:-1}'
218
- ])
219
- this.push_instruction(`pop ${identifier.value}`)
220
- }
221
-
222
- this.pure = previous_pure
223
-
224
- !options.all_static && token.all_static && !options.identifier &&
225
- this.push_instruction([`link ${physical_address}/${identifier.value}`, `pop ${identifier.value}`])
226
- }
227
-
228
- parse = (token, options) => {
229
- options = options || {}
230
- let {identifier} = options;
231
-
232
- let previous_pure = this.pure;
233
- if (token.type === "string" || token.type === "number") {
234
- this.static_parse({options, previous_pure, token, identifier}, ()=>{
235
- this.push_instruction([
236
- `link ${
237
- this.account.physical_address
238
- }/Datatypes/${`${token.type[0].toUpperCase()}${token.type.slice(1)}`}`,
239
- `write ${token.value}`,
240
- `pop ${token.type}`,
241
- ]);
242
- })
243
-
244
- } else if (token.type === "array") {
245
-
246
- this.static_parse({token, previous_pure, options, identifier}, ()=>{
247
- this.push_instruction(
248
- `link Accounts/${this.account.name}/Datatypes/Array`
249
- );
250
- if (token.value.length){
251
- token.value.map((item, i) => {
252
- this.parse(item, {all_static: this.pure === 'stack'});
253
-
254
- this.push_instruction([
255
- `cursor ${i}`,
256
- `write ${
257
- this.is_not_literal(item.type)
258
- ? "{metadata.output:-1}"
259
- : "{datapath:-1}"
260
- }`,
261
- ]);
262
- });
263
- }
264
-
265
- this.push_instruction(`pop Array`);
266
- })
267
-
268
- } else if (token.type === "twain") {
269
-
270
- this.static_parse({token, previous_pure, options, identifier}, ()=>{
271
- this.push_instruction(
272
- `link Accounts/${this.account.name}/Datatypes/Twain`
273
- );
274
-
275
- if (token.value.length){
276
- let curs = true;
277
- token.value.map((entry) => {
278
- if (entry.type === "separator") {
279
- curs = false;
280
- return;
281
- }
282
- this.parse(entry, {all_static: this.pure === 'stack'});
283
- if (curs) {
284
- {
285
- this.push_instruction(
286
- `cursor {*${
287
- this.is_not_literal(entry.type)
288
- ? "metadata.output:-1"
289
- : "datapath:-1"
290
- }}`
291
- );
292
- }
293
- } else {
294
- this.push_instruction(
295
- `write ${
296
- this.is_not_literal(entry.type)
297
- ? "{metadata.output:-1}"
298
- : "{datapath:-1}"
299
- }`
300
- );
301
- curs = true;
302
- }
303
- });
304
- }
305
-
306
- this.push_instruction(`pop Twain`);
307
-
308
- })
309
-
310
- } else if (token.type === "variable") {
311
- let tok_value = token.value;
312
-
313
- let is_nested = this.handle_nested(tok_value)
314
-
315
- this.push_instruction([
316
- `link ${is_nested?'{metadata.output:-1}': `${this.stacks.slice(-1)[0]}/${tok_value}`}`,
317
- `pop ${tok_value}`,
318
- ]);
319
- }else if(token.type==='void'){
320
- this.push_instruction([`link ${this.account.physical_address}/Datatypes/Void`, 'pop Void'])
321
- }else if (token.type === 'boolean'){
322
- this.push_instruction([`link ${this.account.physical_address}/Datatypes/Boolean`, `write ${token.value}`, 'pop Boolean'])
323
- } else if (token.type === "address") this.parse_assignment(token);
324
- };
325
-
326
- handle_nested = tok_value=>{
327
- let is_nested= tok_value.startsWith('(')
328
- if (is_nested){
329
- let val = tok_value.slice(1,-1)
330
- if(val.startsWith('@') || val.startsWith('.')){
331
- val = this.resolve_addr(val)
332
- this.push_instruction([`link ${val}`, 'pop'])
333
- } else this.push_instruction([`link ${`${this.current_program().physical_address}/${val}`}`, `pop ${val}`])
334
- }
335
-
336
- return is_nested
337
- }
338
-
339
- throw_error=(msg, token)=>{
340
- let pth = this.current_program()
341
- pth = pth.physical_address
342
- throw new Error(`${msg}:${this.line_count}/col:${token.pos}\n\t${pth||''}`)
343
- }
344
-
345
- is_not_literal = (type) =>
346
- !type || ["variable", "opcode", "address"].includes(type);
347
-
348
- parse_assignment = (line, linked) => {
349
- let tokens = linked || line.type ? line : this.parse_tokens(line);
350
-
351
- let identifier = tokens[0], is_nested, curr_program;
352
-
353
- if (linked || line.type) {
354
- let line_split = (line.value || line)
355
- .slice(line.value ? null : 1)
356
- .trim()
357
- .split(" ");
358
- let path = line_split[0].split("/");
359
-
360
- this.push_instruction(`link ${this.resolve_addr(path.join("/"))}`);
361
-
362
- tokens = !line.type && this.parse_tokens(line_split.slice(1).join(" "));
363
- tokens.unshift && tokens.unshift(null);
364
- if (line.type === "address")
365
- return this.push_instruction(`pop ${path[path.length - 1]}`);
366
- } else {
367
- curr_program = this.current_program();
368
- curr_program && curr_program.dimensions.push({ name: identifier.value });
369
-
370
- is_nested = this.handle_nested(identifier.value)
371
-
372
- this.push_instruction(`chain ${is_nested?'{metadata.output:-1}': identifier.value}`);
373
-
374
-
375
- if (tokens.length > 1){
376
- let pre_tok = tokens.slice(-1)[0]
377
- if (pre_tok.all_static){}
378
- else
379
- !is_nested && this.stack_instruction([
380
- `link ${this.stacks.slice(-1)[0]}`,
381
- `chain ${identifier.value}`,
382
- `pop ${identifier.value}`,
383
- "pop",
384
- ]);
385
- }
386
-
387
- }
388
-
389
- let prev_token;
390
- if (tokens[1] && tokens[1].type === "opcode") {
391
- this.parse_opcode(tokens.slice(1));
392
- prev_token = tokens[1];
393
- } else {
394
- tokens.slice(1).map((tok) => {
395
- this.parse(tok, {identifier});
396
- });
397
- prev_token = tokens.slice(-1)[0];
398
- }
399
-
400
- if (!this.pure&& !is_nested && identifier.type === 'variable'){
401
- let config = this.configs[curr_program.physical_address]
402
- if(!config){
403
- config = {
404
- parameters:[],
405
- identifiers: [],
406
- name: curr_program.program_name,
407
- __address__: curr_program.physical_address,
408
- type:'module'
409
- }
410
- this.configs[curr_program.physical_address] = config;
411
- }else {
412
- // console.log(config, 'conff')
413
- }
414
-
415
- if (tokens[1]&& this.datatypes.includes(tokens[1].type)){
416
- config.parameters.push({name: identifier.value, object: tokens[1].static_value, position: config.parameters.length})
417
- }else if (!tokens[1]){
418
- config.parameters.push({name: identifier.value, address: `${this.account.physical_address}/Datatypes/Void`, position:config.parameters.length})
419
- }
420
- config.identifiers.push(identifier.value)
421
- }
422
-
423
- if (tokens.length > 1) {
424
- if (prev_token && prev_token.all_static){
425
- this.push_instruction([`pop ${identifier.value}`])
426
- }else {
427
- this.push_instruction([
428
- "cursor {output}",
429
- `write ${
430
- this.is_not_literal(prev_token && prev_token.type)
431
- ? "{metadata.output:-1}"
432
- : "{datapath:-1}"
433
- }`,
434
- `pop ${identifier.value}`,
435
- ]);
436
- }
437
-
438
- } else this.push_instruction(`pop ${identifier.value}`);
439
-
440
-
441
- };
442
-
443
- current_program = () => {
444
- return this.program_configs[this.programs_index];
445
- };
446
-
447
- marker_pattern = /@[a-zA-Z_][a-zA-Z0-9_]*/;
448
-
449
- parse_opcode = (line, assign) => {
450
- let tokens = Array.isArray(line) ? line : this.parse_tokens(line);
451
-
452
- let op = tokens[0];
453
-
454
- if (op.type !== "opcode") return this.parse(op);
455
-
456
- this.push_instruction([
457
- `link Accounts/${this.account.name}/Opcodes/${op.value}`,
458
- `link Accounts/${this.account.name}/Datatypes/Twain`,
459
- ]);
460
-
461
- tokens.slice(1).map((tok, i) => {
462
- if (tok.type === "address" && tok.value.match(this.marker_pattern)) {
463
- this.push_instruction([
464
- `link ${this.account.physical_address}/Datatypes/Number`,
465
- `write ${tok.value}`,
466
- `pop Number`,
467
- ]);
468
- } else this.parse(tok);
469
-
470
- this.push_instruction([
471
- `cursor op${i}`,
472
- `write ${
473
- tok.all_static || (this.is_not_literal(tok.type) &&
474
- !(tok.type === "address" && tok.value.match(this.marker_pattern)))
475
- ? "{metadata.output:-1}"
476
- : "{datapath:-1}"
477
- }`,
478
- ]);
479
- });
480
-
481
- this.push_instruction([
482
- "pop Twain",
483
- "cursor inputs",
484
- `write {datapath:-1}`,
485
- op.value,
486
- `cursor {output}`,
487
- `write {datapath:-1}`,
488
- `pop ${op.value}`,
489
- ]);
490
- };
491
-
492
- resolve_addr = (addr) => {
493
- let real_addr = addr;
494
- addr = addr.split("/");
495
-
496
- if (addr.length === 1){
497
- real_addr = addr.join('')
498
- }
499
- else if (addr[0] === "@") {
500
- addr[0] = this.account.physical_address;
501
- real_addr = addr.join("/");
502
- } else if (addr[0] === ".." || addr[0] === ".") {
503
- let curr_addr = this.stacks.slice(-1)[0].split("/");
504
- while (addr[0] === ".." || addr[0] === ".") {
505
- if (addr[0] === "..") curr_addr.splice(-1);
506
- delete addr[0];
507
- }
508
- real_addr = curr_addr.join("/") + `${addr.join("/")}`;
509
- }
510
-
511
- return real_addr;
512
- };
513
-
514
- new_stack_instructions = (new_stack) => {
515
- let curr_stack = this.stacks.slice(-1)[0].split("/");
516
- new_stack = new_stack.split("/");
517
-
518
- let physical_address = new_stack.join("/");
519
- let program = {
520
- program_name: new_stack[new_stack.length - 1],
521
- physical_address,
522
- codes: [],
523
- dimensions: [],
524
- sub_programs: [],
525
- _id: _id("programs"),
526
- };
527
- let curr_program = this.current_program();
528
- if (curr_program) curr_program.sub_programs.push(program._id);
529
-
530
- this.programs_index++;
531
- this.program_configs.push(program);
532
-
533
- if (curr_stack[1] !== new_stack[1]) {
534
- } else {
535
- for (let j = 2; j < new_stack.length; j++)
536
- this.stack_instruction(`chain ${new_stack[j]}`);
537
-
538
- this.stack_instruction(
539
- `link ${this.account.physical_address}/Datatypes/Array`
540
- );
541
- }
542
- };
543
-
544
- parse_routine = (line) => {
545
- let addr = this.resolve_addr(line);
546
-
547
- this.instruction_stacks.push([]);
548
- this.new_stack_instructions(addr);
549
- this.new_stack(addr);
550
-
551
- this.instruction_indexes.push(-1);
552
- };
553
-
554
- pop = () => {
555
- let addr = this.stacks.splice(-1)[0].split("/");
556
- this.stack_instruction([
557
- `pop Array`,
558
- `cursor {program}`,
559
- `write {datapath:-1}`,
560
- ]);
561
-
562
- for (let j = 2; j < addr.length; j++)
563
- this.stack_instruction(`pop ${addr[j]}`);
564
-
565
- this.instructions.push(...this.instruction_stacks.splice(-1)[0]);
566
- this.programs_index--;
567
-
568
- this.instruction_indexes.pop();
569
- };
570
-
571
- revamp_marks = () => {
572
- let instruction_stack = this.instruction_stacks.slice(-1)[0];
573
-
574
- instruction_stack = instruction_stack.map((ins) =>
575
- this.resolve_offset(ins, true)
576
- );
577
-
578
- this.instruction_stacks[this.instruction_stacks.length - 1] =
579
- instruction_stack;
580
- };
581
-
582
- handle_marker = (line) => {
583
- let splits = line.slice(1).split(" ");
584
- let name = splits[0];
585
-
586
- let curr_stack = this.stacks.slice(-1)[0];
587
- let markers = this.markers[curr_stack];
588
- if (!markers) {
589
- markers = new Object();
590
- this.markers[curr_stack] = markers;
591
- }
592
-
593
- markers[name] = this.instruction_indexes.slice(-1)[0];
594
-
595
- this.revamp_marks();
596
-
597
- return splits.slice(1).join(" ");
598
- };
599
-
600
- resolve_offset = (line, revamping) => {
601
- let matches = line.match(this.marker_pattern),
602
- value;
603
- if (matches) {
604
- let match = matches[0].slice(1);
605
-
606
- let curr_stack = this.stacks.slice(-1)[0];
607
- let markers = this.markers[curr_stack];
608
- if (!markers) {
609
- markers = new Object();
610
- this.markers[curr_stack] = markers;
611
- }
612
- value = markers[match];
613
- }
614
-
615
- if (typeof value === "number")
616
- {line = line.replace(
617
- this.marker_pattern,
618
- (revamping&&value>0?value+1: value+1).toString()
619
- );
620
-
621
- }
622
-
623
- return line;
624
- };
625
-
626
- parse_comment = (line) => {
627
- line = line.split(":");
628
- if (line.length <= 1) return;
629
-
630
- let curr_program = this.current_program();
631
- let line1 = line[0].split(".");
632
- let obj = curr_program;
633
-
634
- for (let l = 0; l < line1.length - 1; l++) {
635
- let term = line1[l];
636
-
637
- if (term.trim() === "_id") break;
638
-
639
- let n_term = Number(term);
640
-
641
- if (n_term) {
642
- obj = obj[n_term];
643
- } else obj = obj[term];
644
- }
645
- if (!obj) return;
646
-
647
- let index = line1[line1.length - 1];
648
- let n_indx = Number(index);
649
- if (!isNaN(n_indx)) index = n_indx;
650
-
651
- if (index === "_id") return;
652
-
653
- obj[index] = line.slice(1).join(":").trim();
654
- };
655
-
656
- spawn = () => {
657
- let spaw = new Loader(this.account);
658
- spaw.opcodes = [...this.opcodes];
659
-
660
- return spaw;
661
- };
662
-
663
- line_count = 0
664
-
665
- compile = (codes) => {
666
- let code_array = codes.split("\n");
667
-
668
- for (let c = 0; c < code_array.length; c++) {
669
- let line = code_array[c].trim();
670
- this.line_count++
671
-
672
- let curr_program = this.current_program();
673
- this.is_routine = line.startsWith(".") || line.startsWith("@");
674
-
675
- this.handle_codes(line, curr_program);
676
-
677
- if (!line) continue;
678
-
679
- if (line.startsWith(":")) {
680
- line = this.handle_marker(line);
681
- if (!line) continue;
682
- }
683
-
684
- if (this.config_flag){
685
- this.handle_config(line)
686
- this.config_flag = false;
687
- continue;
688
- }
689
-
690
- line = this.resolve_offset(line);
691
- if(line.startsWith('$')){
692
- this.handle_decor(line)
693
- continue
694
- } else if (line === ";") this.pop();
695
- else if (this.is_routine) this.parse_routine(line);
696
- else if (line.startsWith("//")) this.parse_comment(line.slice(2).trim());
697
- else if (line.startsWith(">@") || line.startsWith(">."))
698
- this.parse_assignment(line, true);
699
- else if (line.startsWith(">")){
700
- let res =this.check_recursive(line)
701
- this.parse_assignment(res);
702
- } else this.parse_opcode(line);
703
-
704
- (!curr_program || this.is_routine) &&
705
- this.handle_codes(line, this.current_program());
706
-
707
- if (this.pure> 0)this.pure--
708
- }
709
-
710
- this.no_static = false
711
- };
712
-
713
- handle_config = config=>{
714
- this.pure = true
715
- this.parse_opcode(`config ${config}`)
716
- this.pure = false
717
- }
718
-
719
- check_recursive=line=>{
720
- line = line.slice(1).split(' ').filter(l=>!!l)
721
-
722
- let identifier = line[0]
723
-
724
- let recurse = line.slice(1).find(l=>l===identifier);
725
- if (recurse){
726
- let new_var = `temp_${identifier}_${this.account.manager.oracle.hash(identifier, 'sha1')}`
727
- this.parse_assignment(`>${new_var} ${identifier}`)
728
- line = line.slice(1).map(l=>{
729
- if(l===identifier)return new_var
730
- return l
731
- })
732
- line.unshift(identifier)
733
- }
734
-
735
- line =`>${line.join(' ')}`
736
-
737
- return line
738
- }
739
-
740
- handle_decor = line=>{
741
- line= line.slice(1).split(' ')
742
-
743
- this[line[0]] = Number(line[1]) || 1
744
- }
745
-
746
- handle_codes = (line, curr_program) => {
747
- if (this.is_routine) {
748
- let tilline = `~${line}`;
749
- let prev_program = this.program_configs[this.programs_index - 1];
750
- prev_program && prev_program.codes.push(tilline);
751
-
752
- curr_program &&
753
- !curr_program.codes.find((line) => !!line.trim()) &&
754
- curr_program.codes.push(line);
755
- }
756
-
757
- !this.is_routine && curr_program && curr_program.codes.push(line);
758
- };
759
-
760
- run = (codes, meta) => {
761
- if (!meta) meta = {};
762
- let { pure, cb, options , unshift} = meta;
763
- let{main, configs}=options ||{}
764
- this.pure = pure? -1:0;
765
-
766
- this.compile(codes);
767
-
768
- if (meta.instructions) return [...this.instructions];
769
-
770
- // console.log(JSON.stringify(this.instructions, null, 2), "hiya");
771
- if(this.pure)this.account.log_output(this.instructions)
772
-
773
- this.account.load({
774
- program: { instructions: [...this.instructions], unshift: !!unshift},
775
- callback: cb,
776
- });
777
-
778
- let pragma = this.program_configs[0];
779
- if (pragma)
780
- pragma.main =
781
- (main) || this.repository.oracle.hash(codes);
782
- this.program_configs.map((config) => this.repository.add_program(config));
783
-
784
- if(configs === 'pragma_only'){
785
- this.set_config(this.configs[pragma.physical_address])
786
- }else {
787
- for (let addr in this.configs){
788
- let config = this.configs[addr]
789
- this.set_config(config)
790
- }
791
- }
792
- this.configs = new Object()
793
-
794
- this.program_configs = new Array();
795
- this.instructions = new Array();
796
- this.pure = false;
797
- };
798
-
799
- set_config = (config)=>{
800
- config&&
801
- this.account.execute('config', {op0: config})
802
- }
803
- }
804
-
805
- export default Loader;