godprotocol 1.0.841 → 1.0.842

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.
@@ -1,403 +1,558 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _functions = require("generalised-datastore/utils/functions");
8
- var _repository = _interopRequireDefault(require("./repository"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
12
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
- function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
15
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
16
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
17
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
18
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
19
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
20
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
21
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
22
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
- var num_pattern = /^[+-]?\d+(\.\d+)?$/;
1
+ import { _id } from "generalised-datastore/utils/functions";
2
+ import Repository from "./repository";
3
+
4
+ let num_pattern = /^[+-]?\d+(\.\d+)?$/;
24
5
  // let str_pattern = /^["'][^"']*["']$/;
25
- var var_pattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
26
- var Loader = /*#__PURE__*/_createClass(function Loader(account) {
27
- var _this = this;
28
- _classCallCheck(this, Loader);
29
- _defineProperty(this, "instruction_index", function () {
30
- var index = _this.instruction_indexes.slice(-1);
6
+ let var_pattern = /^[a-zA-Z_][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
+ // Code Repository
22
+ this.repository = new Repository(this);
23
+ }
24
+
25
+ instruction_index = () => {
26
+ let index = this.instruction_indexes.slice(-1);
31
27
  index++;
32
- _this.instruction_indexes.splice(-1, 1, index);
28
+ this.instruction_indexes.splice(-1, 1, index);
29
+
33
30
  return index;
34
- });
35
- _defineProperty(this, "stack_instruction", function (instruction) {
36
- if (Array.isArray(instruction)) return instruction.map(function (i) {
37
- return _this.stack_instruction(i);
38
- });
39
- _this.instruction_stacks.slice(-1)[0].push(instruction);
40
- });
41
- _defineProperty(this, "new_stack", function (addr) {
42
- _this.stacks.push(addr);
43
- });
44
- _defineProperty(this, "push_instruction", function (instruction) {
45
- if (Array.isArray(instruction)) return instruction.map(function (i) {
46
- return _this.push_instruction(i);
47
- });
48
- if (_this.pure) {
49
- _this.instructions.push(instruction);
31
+ };
32
+
33
+ stack_instruction = (instruction) => {
34
+ if (Array.isArray(instruction))
35
+ return instruction.map((i) => this.stack_instruction(i));
36
+
37
+ this.instruction_stacks.slice(-1)[0].push(instruction);
38
+ };
39
+
40
+ new_stack = (addr) => {
41
+ this.stacks.push(addr);
42
+ };
43
+
44
+ push_instruction = (instruction) => {
45
+ if (Array.isArray(instruction))
46
+ return instruction.map((i) => this.push_instruction(i));
47
+
48
+ if (this.pure) {
49
+ this.instructions.push(instruction);
50
50
  } else {
51
- _this.stack_instruction("cursor ".concat(_this.instruction_index()));
52
- _this.stack_instruction("write ".concat(instruction));
51
+ this.stack_instruction(`cursor ${this.instruction_index()}`);
52
+ this.stack_instruction(`write ${instruction}`);
53
53
  }
54
- });
55
- _defineProperty(this, "parse_tokens", function (line, stop_char) {
56
- var tokens = new Array();
57
- var pos = 0,
54
+ };
55
+
56
+ parse_tokens = (line, stop_char) => {
57
+ let tokens = new Array();
58
+ let pos = 0,
58
59
  line_number = 0;
59
- var push_token = function push_token(value, type) {
60
- return tokens.push({
61
- value: value,
62
- type: type,
63
- line: line_number,
64
- pos: pos
65
- });
66
- };
60
+
61
+ let push_token = (value, type) =>
62
+ tokens.push({ value, type, line: line_number, pos });
63
+
67
64
  line = line.trim();
68
65
  while (pos < line.length) {
69
- var _char = line[pos].trim();
70
- console.log(_char);
71
- if (_char === stop_char) return {
72
- tokens: tokens,
73
- pos: pos
74
- };
75
- if (!_char) {
66
+ let char = line[pos].trim();
67
+
68
+ console.log(char);
69
+ if (char === stop_char) return { tokens, pos };
70
+
71
+ if (!char) {
76
72
  pos++;
73
+
77
74
  continue;
78
75
  }
79
- if (_char === "\n") {
76
+
77
+ if (char === "\n") {
80
78
  line_number++;
81
79
  pos++;
82
- } else if (_char === "@" || _char === ".") {
83
- var acc = "";
80
+ } else if (char === "@" || char === ".") {
81
+ let acc = "";
84
82
  while (line[pos] && line[pos].trim()) {
85
83
  acc += line[pos];
86
84
  pos++;
87
85
  }
88
86
  push_token(acc, "address");
89
- } else if (_char === ",") {
87
+ } else if (char === ",") {
90
88
  pos++;
91
- } else if (_char === ":") {
92
- push_token(_char, "separator");
89
+ } else if (char === ":") {
90
+ push_token(char, "separator");
93
91
  pos++;
94
- } else if (_char === "[") {
92
+ } else if (char === "[") {
95
93
  pos++;
96
- var toks = _this.parse_tokens(line.slice(pos), "]");
94
+ let toks = this.parse_tokens(line.slice(pos), "]");
97
95
  push_token(toks.tokens, "array");
98
96
  pos += toks.pos + 1;
99
- } else if (_char === "{") {
97
+ } else if (char === "{") {
100
98
  pos++;
101
- var _toks = _this.parse_tokens(line.slice(pos), "}");
102
- push_token(_toks.tokens, "twain");
103
- pos += _toks.pos + 1;
104
- } else if (_char === ">") {
99
+ let toks = this.parse_tokens(line.slice(pos), "}");
100
+ push_token(toks.tokens, "twain");
101
+ pos += toks.pos + 1;
102
+ } else if (char === ">") {
105
103
  pos++;
106
- } else if (_char === "'" || _char === '"') {
107
- var _acc = "";
104
+ } else if (char === "'" || char === '"') {
105
+ let acc = "";
108
106
  pos++;
109
- while (line[pos] !== _char) {
107
+ while (line[pos] !== char) {
110
108
  if (!line[pos]) break;
111
- _acc += line[pos];
109
+ acc += line[pos];
112
110
  pos++;
113
111
  }
114
112
  pos++;
115
- push_token(_acc, "string");
116
- } else if (num_pattern.test(_char) || _char === "-") {
117
- var _acc2 = _char;
113
+ push_token(acc, "string");
114
+ } else if (num_pattern.test(char) || char === "-") {
115
+ let acc = char;
118
116
  pos++;
119
- while (num_pattern.test(line[pos]) || line[pos] === "." && !_acc2.includes(line[pos])) {
117
+ while (
118
+ num_pattern.test(line[pos]) ||
119
+ (line[pos] === "." && !acc.includes(line[pos]))
120
+ ) {
120
121
  if (!line[pos]) break;
121
- _acc2 += line[pos];
122
+
123
+ acc += line[pos];
122
124
  pos++;
123
125
  }
124
- push_token(_acc2, "number");
125
- } else if (var_pattern.test(_char)) {
126
- var _acc3 = _char;
126
+ push_token(acc, "number");
127
+ } else if (var_pattern.test(char)) {
128
+ let acc = char;
127
129
  pos++;
128
- while (line[pos] && var_pattern.test("".concat(line[pos].trim()))) {
129
- _acc3 += line[pos];
130
+ while (line[pos] && var_pattern.test(`${line[pos].trim()}`)) {
131
+ acc += line[pos];
130
132
  pos++;
131
133
  }
132
- push_token(_acc3, _this.opcodes.includes(_acc3) ? "opcode" : "variable");
134
+
135
+ push_token(acc, this.opcodes.includes(acc) ? "opcode" : "variable");
133
136
  }
134
137
  }
138
+
135
139
  return tokens;
136
- });
137
- _defineProperty(this, "parse", function (token) {
140
+ };
141
+
142
+ parse = (token) => {
138
143
  if (token.type === "string" || token.type === "number") {
139
- _this.push_instruction(["link ".concat(_this.account.physical_address, "/Datatypes/", "".concat(token.type[0].toUpperCase()).concat(token.type.slice(1))), "write ".concat(token.value), "pop ".concat(token.type)]);
144
+ this.push_instruction([
145
+ `link ${
146
+ this.account.physical_address
147
+ }/Datatypes/${`${token.type[0].toUpperCase()}${token.type.slice(1)}`}`,
148
+ `write ${token.value}`,
149
+ `pop ${token.type}`,
150
+ ]);
140
151
  } else if (token.type === "array") {
141
- _this.push_instruction("link Accounts/".concat(_this.account.name, "/Datatypes/Array"));
142
- token.value.map(function (item, i) {
143
- _this.parse(item);
144
- _this.push_instruction(["cursor ".concat(i), "write ".concat(_this.is_not_literal(item.type) ? "{metadata.output:-1}" : "{datapath:-1}")]);
152
+ this.push_instruction(
153
+ `link Accounts/${this.account.name}/Datatypes/Array`
154
+ );
155
+ token.value.map((item, i) => {
156
+ this.parse(item);
157
+
158
+ this.push_instruction([
159
+ `cursor ${i}`,
160
+ `write ${
161
+ this.is_not_literal(item.type)
162
+ ? "{metadata.output:-1}"
163
+ : "{datapath:-1}"
164
+ }`,
165
+ ]);
145
166
  });
146
- _this.push_instruction("pop Array");
167
+ this.push_instruction(`pop Array`);
147
168
  } else if (token.type === "twain") {
148
- _this.push_instruction("link Accounts/".concat(_this.account.name, "/Datatypes/Twain"));
149
- var curs = true;
150
- if (token.value) token.value.map(function (entry) {
151
- if (entry.type === "separator") {
152
- curs = false;
153
- return;
154
- }
155
- _this.parse(entry);
156
- if (curs) {
157
- {
158
- _this.push_instruction("cursor {*".concat(_this.is_not_literal(entry.type) ? "metadata.output:-1" : "datapath:-1", "}"));
169
+ this.push_instruction(
170
+ `link Accounts/${this.account.name}/Datatypes/Twain`
171
+ );
172
+ let curs = true;
173
+
174
+ if (token.value)
175
+ token.value.map((entry) => {
176
+ if (entry.type === "separator") {
177
+ curs = false;
178
+ return;
159
179
  }
160
- } else {
161
- _this.push_instruction("write ".concat(_this.is_not_literal(entry.type) ? "{metadata.output:-1}" : "{datapath:-1}"));
162
- curs = true;
163
- }
164
- });
165
- _this.push_instruction("pop Twain");
180
+ this.parse(entry);
181
+ if (curs) {
182
+ {
183
+ this.push_instruction(
184
+ `cursor {*${
185
+ this.is_not_literal(entry.type)
186
+ ? "metadata.output:-1"
187
+ : "datapath:-1"
188
+ }}`
189
+ );
190
+ }
191
+ } else {
192
+ this.push_instruction(
193
+ `write ${
194
+ this.is_not_literal(entry.type)
195
+ ? "{metadata.output:-1}"
196
+ : "{datapath:-1}"
197
+ }`
198
+ );
199
+ curs = true;
200
+ }
201
+ });
202
+ this.push_instruction(`pop Twain`);
166
203
  } else if (token.type === "variable") {
167
- _this.push_instruction(["link ".concat("".concat(_this.stacks.slice(-1)[0], "/").concat(token.value)), "pop ".concat(token.value)]);
168
- } else if (token.type === "address") _this.parse_assignment(token);
169
- });
170
- _defineProperty(this, "is_not_literal", function (type) {
171
- return !type || ["variable", "opcode", "address"].includes(type);
172
- });
173
- _defineProperty(this, "parse_assignment", function (line, linked) {
174
- var tokens = linked || line.type ? line : _this.parse_tokens(line);
175
- var identifier = tokens[0];
204
+ this.push_instruction([
205
+ `link ${`${this.stacks.slice(-1)[0]}/${token.value}`}`,
206
+ `pop ${token.value}`,
207
+ ]);
208
+ } else if (token.type === "address") this.parse_assignment(token);
209
+ };
210
+
211
+ is_not_literal = (type) =>
212
+ !type || ["variable", "opcode", "address"].includes(type);
213
+
214
+ parse_assignment = (line, linked) => {
215
+ let tokens = linked || line.type ? line : this.parse_tokens(line);
216
+
217
+ let identifier = tokens[0];
176
218
  if (linked || line.type) {
177
- var line_split = (line.value || line).slice(line.value ? null : 1).trim().split(" ");
178
- var path = line_split[0].split("/");
179
- _this.push_instruction("link ".concat(_this.resolve_addr(path.join("/"))));
180
- tokens = !line.type && _this.parse_tokens(line_split.slice(1).join(" "));
219
+ let line_split = (line.value || line)
220
+ .slice(line.value ? null : 1)
221
+ .trim()
222
+ .split(" ");
223
+ let path = line_split[0].split("/");
224
+
225
+ this.push_instruction(`link ${this.resolve_addr(path.join("/"))}`);
226
+
227
+ tokens = !line.type && this.parse_tokens(line_split.slice(1).join(" "));
181
228
  tokens.unshift && tokens.unshift(null);
182
- if (line.type === "address") return _this.push_instruction("pop ".concat(path[path.length - 1]));
229
+ if (line.type === "address")
230
+ return this.push_instruction(`pop ${path[path.length - 1]}`);
183
231
  } else {
184
- var curr_program = _this.current_program();
185
- curr_program && curr_program.dimensions.push({
186
- name: identifier.value
187
- });
188
- _this.push_instruction("chain ".concat(identifier.value));
189
- _this.stack_instruction(["link ".concat(_this.stacks.slice(-1)[0]), "chain ".concat(identifier.value), "pop ".concat(identifier.value), "pop"]);
232
+ let curr_program = this.current_program();
233
+ curr_program && curr_program.dimensions.push({ name: identifier.value });
234
+
235
+ this.push_instruction(`chain ${identifier.value}`);
236
+ this.stack_instruction([
237
+ `link ${this.stacks.slice(-1)[0]}`,
238
+ `chain ${identifier.value}`,
239
+ `pop ${identifier.value}`,
240
+ "pop",
241
+ ]);
190
242
  }
191
- var prev_token;
243
+
244
+ let prev_token;
192
245
  if (tokens[1] && tokens[1].type === "opcode") {
193
- _this.parse_opcode(tokens.slice(1));
246
+ this.parse_opcode(tokens.slice(1));
194
247
  prev_token = tokens[1];
195
248
  } else {
196
- tokens.slice(1).map(function (tok) {
197
- _this.parse(tok);
249
+ tokens.slice(1).map((tok) => {
250
+ this.parse(tok);
198
251
  });
199
252
  prev_token = tokens.slice(-1)[0];
200
253
  }
254
+
201
255
  if (tokens.length > 1) {
202
- _this.push_instruction(["cursor {output}", "write ".concat(_this.is_not_literal(prev_token && prev_token.type) ? "{metadata.output:-1}" : "{datapath:-1}"), "pop ".concat(identifier.value)]);
203
- } else _this.push_instruction("pop ".concat(identifier.value));
204
- });
205
- _defineProperty(this, "current_program", function () {
206
- return _this.program_configs[_this.programs_index];
207
- });
208
- _defineProperty(this, "marker_pattern", /@[a-zA-Z_][a-zA-Z0-9_]*/);
209
- _defineProperty(this, "parse_opcode", function (line) {
210
- var tokens = Array.isArray(line) ? line : _this.parse_tokens(line);
211
- var op = tokens[0];
212
- if (op.type !== "opcode") return _this.parse(op);
213
- _this.push_instruction(["link Accounts/".concat(_this.account.name, "/Opcodes/").concat(op.value), "link Accounts/".concat(_this.account.name, "/Datatypes/Twain")]);
214
- tokens.slice(1).map(function (tok, i) {
215
- if (tok.type === "address") tok.value = _this.resolve_addr(tok.value);
216
- if (tok.type === "address" && tok.value.match(_this.marker_pattern)) {
217
- _this.push_instruction(["link ".concat(_this.account.physical_address, "/Datatypes/Number"), "write ".concat(tok.value), "pop Number"]);
218
- } else _this.parse(tok);
219
- _this.push_instruction(["cursor op".concat(i), "write ".concat(_this.is_not_literal(tok.type) && !(tok.type === "address" && tok.value.match(_this.marker_pattern)) ? "{metadata.output:-1}" : "{datapath:-1}")]);
256
+ this.push_instruction([
257
+ "cursor {output}",
258
+ `write ${
259
+ this.is_not_literal(prev_token && prev_token.type)
260
+ ? "{metadata.output:-1}"
261
+ : "{datapath:-1}"
262
+ }`,
263
+ `pop ${identifier.value}`,
264
+ ]);
265
+ } else this.push_instruction(`pop ${identifier.value}`);
266
+ };
267
+
268
+ current_program = () => {
269
+ return this.program_configs[this.programs_index];
270
+ };
271
+
272
+ marker_pattern = /@[a-zA-Z_][a-zA-Z0-9_]*/;
273
+
274
+ parse_opcode = (line) => {
275
+ let tokens = Array.isArray(line) ? line : this.parse_tokens(line);
276
+
277
+ let op = tokens[0];
278
+
279
+ if (op.type !== "opcode") return this.parse(op);
280
+
281
+ this.push_instruction([
282
+ `link Accounts/${this.account.name}/Opcodes/${op.value}`,
283
+ `link Accounts/${this.account.name}/Datatypes/Twain`,
284
+ ]);
285
+
286
+ tokens.slice(1).map((tok, i) => {
287
+ if (tok.type === "address") tok.value = this.resolve_addr(tok.value);
288
+
289
+ if (tok.type === "address" && tok.value.match(this.marker_pattern)) {
290
+ this.push_instruction([
291
+ `link ${this.account.physical_address}/Datatypes/Number`,
292
+ `write ${tok.value}`,
293
+ `pop Number`,
294
+ ]);
295
+ } else this.parse(tok);
296
+
297
+ this.push_instruction([
298
+ `cursor op${i}`,
299
+ `write ${
300
+ this.is_not_literal(tok.type) &&
301
+ !(tok.type === "address" && tok.value.match(this.marker_pattern))
302
+ ? "{metadata.output:-1}"
303
+ : "{datapath:-1}"
304
+ }`,
305
+ ]);
220
306
  });
221
- _this.push_instruction(["pop Twain", "cursor inputs", "write {datapath:-1}", op.value, "cursor {output}", "write {datapath:-1}", "pop ".concat(op.value)]);
222
- });
223
- _defineProperty(this, "resolve_addr", function (addr) {
307
+
308
+ this.push_instruction([
309
+ "pop Twain",
310
+ "cursor inputs",
311
+ `write {datapath:-1}`,
312
+ op.value,
313
+ `cursor {output}`,
314
+ `write {datapath:-1}`,
315
+ `pop ${op.value}`,
316
+ ]);
317
+ };
318
+
319
+ resolve_addr = (addr) => {
224
320
  addr = addr.split("/");
225
- var real_addr = "";
321
+
322
+ let real_addr = "";
323
+
226
324
  if (addr[0] === "@") {
227
- addr[0] = _this.account.physical_address;
325
+ addr[0] = this.account.physical_address;
228
326
  real_addr = addr.join("/");
229
327
  } else if (addr[0] === ".." || addr[0] === ".") {
230
- var curr_addr = _this.stacks.slice(-1)[0].split("/");
328
+ let curr_addr = this.stacks.slice(-1)[0].split("/");
231
329
  while (addr[0] === ".." || addr[0] === ".") {
232
330
  if (addr[0] === "..") curr_addr.splice(-1);
233
331
  delete addr[0];
234
332
  }
235
- real_addr = curr_addr.join("/") + "".concat(addr.join("/"));
333
+ real_addr = curr_addr.join("/") + `${addr.join("/")}`;
236
334
  }
335
+
237
336
  return real_addr;
238
- });
239
- _defineProperty(this, "new_stack_instructions", function (new_stack) {
240
- var curr_stack = _this.stacks.slice(-1)[0].split("/");
337
+ };
338
+
339
+ new_stack_instructions = (new_stack) => {
340
+ let curr_stack = this.stacks.slice(-1)[0].split("/");
241
341
  new_stack = new_stack.split("/");
242
- var physical_address = new_stack.join("/");
243
- var program = {
342
+
343
+ let physical_address = new_stack.join("/");
344
+ let program = {
244
345
  program_name: new_stack[new_stack.length - 1],
245
- physical_address: physical_address,
346
+ physical_address,
246
347
  codes: [],
247
348
  dimensions: [],
248
349
  sub_programs: [],
249
- _id: (0, _functions._id)("programs")
350
+ _id: _id("programs"),
250
351
  };
251
- var curr_program = _this.current_program();
352
+ let curr_program = this.current_program();
252
353
  if (curr_program) curr_program.sub_programs.push(program._id);
253
- _this.programs_index++;
254
- _this.program_configs.push(program);
255
- if (curr_stack[1] !== new_stack[1]) {} else {
256
- for (var j = 2; j < new_stack.length; j++) _this.stack_instruction("chain ".concat(new_stack[j]));
257
- _this.stack_instruction("link ".concat(_this.account.physical_address, "/Datatypes/Array"));
354
+
355
+ this.programs_index++;
356
+ this.program_configs.push(program);
357
+
358
+ if (curr_stack[1] !== new_stack[1]) {
359
+ } else {
360
+ for (let j = 2; j < new_stack.length; j++)
361
+ this.stack_instruction(`chain ${new_stack[j]}`);
362
+
363
+ this.stack_instruction(
364
+ `link ${this.account.physical_address}/Datatypes/Array`
365
+ );
258
366
  }
259
- });
260
- _defineProperty(this, "parse_routine", function (line) {
261
- var addr = _this.resolve_addr(line);
262
- _this.instruction_stacks.push([]);
263
- _this.new_stack_instructions(addr);
264
- _this.new_stack(addr);
265
- _this.instruction_indexes.push(-1);
266
- });
267
- _defineProperty(this, "pop", function () {
268
- var _this$instructions;
269
- var addr = _this.stacks.splice(-1)[0].split("/");
270
- _this.stack_instruction(["pop Array", "cursor {program}", "write {datapath:-1}"]);
271
- for (var j = 2; j < addr.length; j++) _this.stack_instruction("pop ".concat(addr[j]));
272
- (_this$instructions = _this.instructions).push.apply(_this$instructions, _toConsumableArray(_this.instruction_stacks.splice(-1)[0]));
273
- _this.programs_index--;
274
- _this.instruction_indexes.pop();
275
- });
276
- _defineProperty(this, "revamp_marks", function () {
277
- var instruction_stack = _this.instruction_stacks.slice(-1)[0];
278
- instruction_stack = instruction_stack.map(function (ins) {
279
- return _this.resolve_offset(ins, true);
280
- });
281
- _this.instruction_stacks[_this.instruction_stacks.length - 1] = instruction_stack;
282
- });
283
- _defineProperty(this, "handle_marker", function (line) {
284
- var splits = line.slice(1).split(" ");
285
- var name = splits[0];
286
- var curr_stack = _this.stacks.slice(-1)[0];
287
- var markers = _this.markers[curr_stack];
367
+ };
368
+
369
+ parse_routine = (line) => {
370
+ let addr = this.resolve_addr(line);
371
+
372
+ this.instruction_stacks.push([]);
373
+ this.new_stack_instructions(addr);
374
+ this.new_stack(addr);
375
+
376
+ this.instruction_indexes.push(-1);
377
+ };
378
+
379
+ pop = () => {
380
+ let addr = this.stacks.splice(-1)[0].split("/");
381
+ this.stack_instruction([
382
+ `pop Array`,
383
+ `cursor {program}`,
384
+ `write {datapath:-1}`,
385
+ ]);
386
+
387
+ for (let j = 2; j < addr.length; j++)
388
+ this.stack_instruction(`pop ${addr[j]}`);
389
+
390
+ this.instructions.push(...this.instruction_stacks.splice(-1)[0]);
391
+ this.programs_index--;
392
+
393
+ this.instruction_indexes.pop();
394
+ };
395
+
396
+ revamp_marks = () => {
397
+ let instruction_stack = this.instruction_stacks.slice(-1)[0];
398
+
399
+ instruction_stack = instruction_stack.map((ins) =>
400
+ this.resolve_offset(ins, true)
401
+ );
402
+
403
+ this.instruction_stacks[this.instruction_stacks.length - 1] =
404
+ instruction_stack;
405
+ };
406
+
407
+ handle_marker = (line) => {
408
+ let splits = line.slice(1).split(" ");
409
+ let name = splits[0];
410
+
411
+ let curr_stack = this.stacks.slice(-1)[0];
412
+ let markers = this.markers[curr_stack];
288
413
  if (!markers) {
289
414
  markers = new Object();
290
- _this.markers[curr_stack] = markers;
415
+ this.markers[curr_stack] = markers;
291
416
  }
292
- markers[name] = _this.instruction_index();
293
- _this.revamp_marks();
417
+ markers[name] = this.instruction_index();
418
+
419
+ this.revamp_marks();
420
+
294
421
  return splits.slice(1).join(" ");
295
- });
296
- _defineProperty(this, "resolve_offset", function (line, revamping) {
297
- var matches = line.match(_this.marker_pattern),
422
+ };
423
+
424
+ resolve_offset = (line, revamping) => {
425
+ let matches = line.match(this.marker_pattern),
298
426
  value;
299
427
  if (matches) {
300
- var match = matches[0].slice(1);
301
- var curr_stack = _this.stacks.slice(-1)[0];
302
- var markers = _this.markers[curr_stack];
428
+ let match = matches[0].slice(1);
429
+
430
+ let curr_stack = this.stacks.slice(-1)[0];
431
+ let markers = this.markers[curr_stack];
303
432
  if (!markers) {
304
433
  markers = new Object();
305
- _this.markers[curr_stack] = markers;
434
+ this.markers[curr_stack] = markers;
306
435
  }
307
436
  value = markers[match];
308
437
  }
309
- if (typeof value === "number") line = line.replace(_this.marker_pattern, (revamping && value > 0 ? value - 1 : value).toString());
438
+
439
+ if (typeof value === "number")
440
+ line = line.replace(
441
+ this.marker_pattern,
442
+ (revamping && value > 0 ? value - 1 : value).toString()
443
+ );
444
+
310
445
  return line;
311
- });
312
- _defineProperty(this, "parse_comment", function (line) {
446
+ };
447
+
448
+ parse_comment = (line) => {
313
449
  line = line.split(":");
314
450
  if (line.length <= 1) return;
315
- var curr_program = _this.current_program();
316
- var line1 = line[0].split(".");
317
- var obj = curr_program;
318
- for (var l = 0; l < line1.length - 1; l++) {
319
- var term = line1[l];
451
+
452
+ let curr_program = this.current_program();
453
+ let line1 = line[0].split(".");
454
+ let obj = curr_program;
455
+
456
+ for (let l = 0; l < line1.length - 1; l++) {
457
+ let term = line1[l];
458
+
320
459
  if (term.trim() === "_id") break;
321
- var n_term = Number(term);
460
+
461
+ let n_term = Number(term);
462
+
322
463
  if (n_term) {
323
464
  obj = obj[n_term];
324
465
  } else obj = obj[term];
325
466
  }
326
467
  if (!obj) return;
327
- var index = line1[line1.length - 1];
328
- var n_indx = Number(index);
468
+
469
+ let index = line1[line1.length - 1];
470
+ let n_indx = Number(index);
329
471
  if (!isNaN(n_indx)) index = n_indx;
472
+
330
473
  if (index === "_id") return;
474
+
331
475
  obj[index] = line.slice(1).join(":").trim();
332
- });
333
- _defineProperty(this, "spawn", function () {
334
- return new Loader(_this.account);
335
- });
336
- _defineProperty(this, "compile", function (codes) {
337
- var code_array = codes.split("\n");
338
- for (var c = 0; c < code_array.length; c++) {
339
- var line = code_array[c].trim();
340
- var curr_program = _this.current_program();
341
- _this.is_routine = line.startsWith(".") || line.startsWith("@");
342
- _this.handle_codes(line, curr_program);
476
+ };
477
+
478
+ spawn = () => {
479
+ return new Loader(this.account);
480
+ };
481
+
482
+ compile = (codes) => {
483
+ let code_array = codes.split("\n");
484
+
485
+ for (let c = 0; c < code_array.length; c++) {
486
+ let line = code_array[c].trim();
487
+
488
+ let curr_program = this.current_program();
489
+ this.is_routine = line.startsWith(".") || line.startsWith("@");
490
+
491
+ this.handle_codes(line, curr_program);
492
+
343
493
  if (!line) continue;
494
+
344
495
  if (line.startsWith(":")) {
345
- line = _this.handle_marker(line);
496
+ line = this.handle_marker(line);
497
+
346
498
  if (!line) continue;
347
499
  }
348
- line = _this.resolve_offset(line);
349
- if (line === ";") _this.pop();else if (_this.is_routine) _this.parse_routine(line);else if (line.startsWith("//")) _this.parse_comment(line.slice(2).trim());else if (line.startsWith(">@") || line.startsWith(">.")) _this.parse_assignment(line, true);else if (line.startsWith(">")) _this.parse_assignment(line);else _this.parse_opcode(line);
350
- (!curr_program || _this.is_routine) && _this.handle_codes(line, _this.current_program());
500
+
501
+ line = this.resolve_offset(line);
502
+
503
+ if (line === ";") this.pop();
504
+ else if (this.is_routine) this.parse_routine(line);
505
+ else if (line.startsWith("//")) this.parse_comment(line.slice(2).trim());
506
+ else if (line.startsWith(">@") || line.startsWith(">."))
507
+ this.parse_assignment(line, true);
508
+ else if (line.startsWith(">")) this.parse_assignment(line);
509
+ else this.parse_opcode(line);
510
+
511
+ (!curr_program || this.is_routine) &&
512
+ this.handle_codes(line, this.current_program());
351
513
  }
352
- });
353
- _defineProperty(this, "handle_codes", function (line, curr_program) {
354
- if (_this.is_routine) {
355
- var tilline = "~".concat(line);
356
- var prev_program = _this.program_configs[_this.programs_index - 1];
514
+ };
515
+
516
+ handle_codes = (line, curr_program) => {
517
+ if (this.is_routine) {
518
+ let tilline = `~${line}`;
519
+ let prev_program = this.program_configs[this.programs_index - 1];
357
520
  prev_program && prev_program.codes.push(tilline);
358
- curr_program && !curr_program.codes.find(function (line) {
359
- return !!line.trim();
360
- }) && curr_program.codes.push(line);
521
+
522
+ curr_program &&
523
+ !curr_program.codes.find((line) => !!line.trim()) &&
524
+ curr_program.codes.push(line);
361
525
  }
362
- !_this.is_routine && curr_program && curr_program.codes.push(line);
363
- });
364
- _defineProperty(this, "run", function (codes, meta) {
526
+
527
+ !this.is_routine && curr_program && curr_program.codes.push(line);
528
+ };
529
+
530
+ run = (codes, meta) => {
365
531
  if (!meta) meta = {};
366
- _this.pure = meta && meta.pure;
367
- var cb = meta && meta.cb;
368
- _this.compile(codes);
369
- if (meta.instructions) return _toConsumableArray(_this.instructions);
532
+ this.pure = meta && meta.pure;
533
+
534
+ let cb = meta && meta.cb;
535
+
536
+ this.compile(codes);
537
+
538
+ if (meta.instructions) return [...this.instructions];
370
539
 
371
540
  // console.log(JSON.stringify(this.instructions, null, 2), "hiya");
372
541
 
373
- _this.account.load({
374
- program: {
375
- instructions: _toConsumableArray(_this.instructions)
376
- },
377
- callback: cb
378
- });
379
- var pragma = _this.program_configs[0];
380
- if (pragma) pragma.main = _this.repository.oracle.hash(codes);
381
- console.log(_this.program_configs);
382
- _this.program_configs.map(function (config) {
383
- return _this.repository.add_program(config);
542
+ this.account.load({
543
+ program: { instructions: [...this.instructions] },
544
+ callback: cb,
384
545
  });
385
- _this.program_configs = [];
386
- _this.instructions = [];
387
- _this.pure = false;
388
- });
389
- this.account = account;
390
- this.opcodes = new Array();
391
- this.instructions = new Array();
392
- this.instruction_indexes = new Array();
393
- this.instruction_stacks = [[]];
394
- this.stacks = new Array(account.physical_address);
395
- this.markers = new Array();
396
- this.program_configs = new Array();
397
- this.programs_index = -1;
398
-
399
- // Code Repository
400
- this.repository = new _repository["default"](this);
401
- });
402
- var _default = Loader;
403
- exports["default"] = _default;
546
+
547
+ let pragma = this.program_configs[0];
548
+ if (pragma) pragma.main = this.repository.oracle.hash(codes);
549
+ console.log(this.program_configs);
550
+ this.program_configs.map((config) => this.repository.add_program(config));
551
+
552
+ this.program_configs = [];
553
+ this.instructions = [];
554
+ this.pure = false;
555
+ };
556
+ }
557
+
558
+ export default Loader;