godprotocol 1.0.77 → 1.0.78

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 (71) hide show
  1. package/Index.js +0 -3
  2. package/Loader_sequence/main.js +250 -54
  3. package/Objects/Account.js +23 -20
  4. package/Objects/Block.js +4 -1
  5. package/Objects/Chain.js +8 -1
  6. package/Objects/Filesystem.js +11 -15
  7. package/Objects/Manager.js +15 -7
  8. package/Objects/Opcodes.js +5 -3
  9. package/Objects/Oracle.js +10 -0
  10. package/Objects/Virtual_machine.js +1 -7
  11. package/framer.js +2 -4
  12. package/opcodes/std.js +2 -1
  13. package/opcodes.js +6 -4
  14. package/package.json +17 -4
  15. package/readme.md +2 -2
  16. package/utils/services.js +1 -1
  17. package/.github/workflows/npm-publish-github-packages.yml +0 -36
  18. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
  19. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
  20. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
  21. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
  22. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/12cd650efa4f63b7c61c3345db3daa0534f4c370a003ea6d8ae0d29a49f6f928/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
  23. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
  24. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/de551b5a493859e532316cbbf1e4a14eb06e0512556b1c1295ad60ffe07c185b/19270ea4f98808a63fbb99bc26a5ee6f0fe8df9c8182cf1d710b115d57250578 +0 -1
  25. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/f8a165e3f556ca2ea189f4d4401d139b22a6f19d0b38329fe4a5f14599840634/4f52f1dc77e0233034c6566fc73c30234de85d2298ff90885a7c56502dffa0b2 +0 -1
  26. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/f8a165e3f556ca2ea189f4d4401d139b22a6f19d0b38329fe4a5f14599840634/8d3c916f9c93a6f4c8be9c3f4493b1c02d3eb7516eac153a98320924b27739d8 +0 -1
  27. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/61bdf0593cd727752cb917ab968a08853d45142b8a8e4cdcd0fe03d1616f3586/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
  28. package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
  29. package/Loader_sequence/functions/parse_expression.js +0 -107
  30. package/Loader_sequence/functions/parse_to_obj.js +0 -38
  31. package/Loader_sequence/functions/parse_variable.js +0 -38
  32. package/Loader_sequence/functions/tokenise.js +0 -135
  33. package/Loader_sequence/functions/utils.js +0 -14
  34. package/Loader_sequence/keywords/parse.js +0 -23
  35. package/Loader_sequence/native_classes/Variable.js +0 -49
  36. package/Loader_sequence/native_classes/datatypes/Array.js +0 -56
  37. package/Loader_sequence/native_classes/datatypes/Boolean.js +0 -42
  38. package/Loader_sequence/native_classes/datatypes/Number.js +0 -42
  39. package/Loader_sequence/native_classes/datatypes/String.js +0 -42
  40. package/Loader_sequence/native_classes/datatypes/Twain.js +0 -65
  41. package/Loader_sequence/native_classes/datatypes/Void.js +0 -42
  42. package/Loader_sequence/native_classes/global.js +0 -48
  43. package/Loader_sequence/native_classes/native.js +0 -63
  44. package/Loader_sequence/native_classes/operators.js +0 -64
  45. package/Loader_sequence/native_classes/parse.js +0 -54
  46. package/Loader_sequence/utils/format_instructions.js +0 -52
  47. package/build/Account.js +0 -245
  48. package/build/Array.js +0 -142
  49. package/build/Block.js +0 -100
  50. package/build/Blockweb.js +0 -78
  51. package/build/Boolean.js +0 -128
  52. package/build/Chain.js +0 -198
  53. package/build/Explorer.js +0 -85
  54. package/build/Filesystem.js +0 -173
  55. package/build/Frame.js +0 -108
  56. package/build/Index.js +0 -31
  57. package/build/Manager.js +0 -167
  58. package/build/Number.js +0 -128
  59. package/build/Opcodes.js +0 -75
  60. package/build/Oracle.js +0 -70
  61. package/build/String.js +0 -128
  62. package/build/Twain.js +0 -151
  63. package/build/Variable.js +0 -135
  64. package/build/Virtual_machine.js +0 -220
  65. package/build/Void.js +0 -128
  66. package/build/format_instructions.js +0 -52
  67. package/build/framer.js +0 -90
  68. package/build/global.js +0 -134
  69. package/build/main.js +0 -83
  70. package/build/native.js +0 -101
  71. package/build/operators.js +0 -150
package/Index.js CHANGED
@@ -20,8 +20,5 @@ var start = function start(name, meta) {
20
20
  var initiator = start(process.env.INITIATOR || "initiator");
21
21
  exports.initiator = initiator;
22
22
  (0, _create_server["default"])(initiator);
23
- setTimeout(function () {
24
- initiator.compiler.run("\n greeting = 'Hello, world!' \n parse greeting\n");
25
- }, 1500);
26
23
  var _default = start;
27
24
  exports["default"] = _default;
@@ -4,80 +4,276 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _parse_to_obj = _interopRequireDefault(require("./functions/parse_to_obj"));
8
- var _tokenise = _interopRequireDefault(require("./functions/tokenise"));
9
- var _global = _interopRequireDefault(require("./native_classes/global"));
10
- var _format_instructions = _interopRequireDefault(require("./utils/format_instructions"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
7
  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); }
8
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
9
+ 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."); }
10
+ 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; } }
11
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
12
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
13
+ 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; }
13
14
  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); } }
14
15
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
15
16
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
16
17
  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; }
17
18
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
18
19
  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); }
19
- var Loader_sequence = /*#__PURE__*/_createClass(function Loader_sequence(account) {
20
+ var num_pattern = /^[+-]?\d+(\.\d+)?$/;
21
+ // let str_pattern = /^["'][^"']*["']$/;
22
+ var var_pattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
23
+ var Loader = /*#__PURE__*/_createClass(function Loader(account) {
20
24
  var _this = this;
21
- _classCallCheck(this, Loader_sequence);
22
- _defineProperty(this, "curr_namespace", function () {
23
- return _this.namestack.slice(-1)[0];
25
+ _classCallCheck(this, Loader);
26
+ _defineProperty(this, "instruction_index", function () {
27
+ var index = _this.instruction_indexes.slice(-1);
28
+ index++;
29
+ _this.instruction_indexes.splice(-1, 1, index);
30
+ return index;
24
31
  });
25
- _defineProperty(this, "tokenise", function (code) {
26
- _this.tokens = (0, _tokenise["default"])(code, null, _this);
32
+ _defineProperty(this, "stack_instruction", function (instruction) {
33
+ if (Array.isArray(instruction)) return instruction.map(function (i) {
34
+ return _this.stack_instruction(i);
35
+ });
36
+ _this.instruction_stacks.slice(-1)[0].push(instruction);
27
37
  });
28
- _defineProperty(this, "parse", function (tokens, stop_token) {
29
- tokens = tokens || _this.tokens;
38
+ _defineProperty(this, "new_stack", function (addr) {
39
+ _this.stacks.push(addr);
40
+ });
41
+ _defineProperty(this, "push_instruction", function (instruction) {
42
+ if (Array.isArray(instruction)) return instruction.map(function (i) {
43
+ return _this.push_instruction(i);
44
+ });
45
+ if (_this.pure) {
46
+ _this.instructions.push(instruction);
47
+ } else {
48
+ _this.stack_instruction("cursor ".concat(_this.instruction_index()));
49
+ _this.stack_instruction("write ".concat(instruction));
50
+ }
51
+ });
52
+ _defineProperty(this, "parse_tokens", function (line, stop_char) {
53
+ var tokens = new Array();
30
54
  var pos = 0,
31
- recent_token;
32
- while (pos < tokens.length) {
33
- var token = tokens[pos];
34
- if (stop_token) {
35
- if (token.type === stop_token.type && token.value === stop_token.value) break;
36
- }
37
- if (recent_token && token.pos === recent_token.pos) throw new Error("Token recursion: ".concat(token.pos, ", ").concat(token.col, ", ").concat(token.value));
38
- recent_token = token;
39
- var curr_obj = _this.curr_namespace();
40
- var token_obj = (0, _parse_to_obj["default"])(token, curr_obj, {
55
+ line_number = 0;
56
+ var push_token = function push_token(value, type) {
57
+ return tokens.push({
58
+ value: value,
59
+ type: type,
60
+ line: line_number,
61
+ pos: pos
62
+ });
63
+ };
64
+ line = line.trim();
65
+ while (pos < line.length) {
66
+ var _char = line[pos].trim();
67
+ if (_char === stop_char) return {
41
68
  tokens: tokens,
42
69
  pos: pos
70
+ };
71
+ if (!_char) {
72
+ pos++;
73
+ continue;
74
+ }
75
+ if (_char === "\n") {
76
+ line_number++;
77
+ pos++;
78
+ } else if (_char === "@") {
79
+ var acc = "";
80
+ while (line[pos] && line[pos].trim()) {
81
+ acc += line[pos];
82
+ pos++;
83
+ }
84
+ push_token(acc, "address");
85
+ } else if (_char === ",") {
86
+ pos++;
87
+ } else if (_char === ":") {
88
+ push_token(_char, "separator");
89
+ pos++;
90
+ } else if (_char === "[") {
91
+ pos++;
92
+ var toks = _this.parse_tokens(line.slice(pos), "]");
93
+ push_token(toks.tokens, "array");
94
+ pos += toks.pos + 1;
95
+ } else if (_char === "{") {
96
+ pos++;
97
+ var _toks = _this.parse_tokens(line.slice(pos), "}");
98
+ push_token(_toks.tokens, "twain");
99
+ pos += _toks.pos + 1;
100
+ } else if (_char === ">") {
101
+ pos++;
102
+ } else if (_char === "'" || _char === '"') {
103
+ var _acc = "";
104
+ pos++;
105
+ while (line[pos] !== _char) {
106
+ if (!line[pos]) break;
107
+ _acc += line[pos];
108
+ pos++;
109
+ }
110
+ pos++;
111
+ push_token(_acc, "string");
112
+ } else if (num_pattern.test(_char)) {
113
+ var _acc2 = _char;
114
+ pos++;
115
+ while (num_pattern.test(line[pos]) || line[pos] === "." && !_acc2.includes(line[pos])) {
116
+ if (!line[pos]) break;
117
+ _acc2 += line[pos];
118
+ pos++;
119
+ }
120
+ push_token(_acc2, "number");
121
+ } else if (var_pattern.test(_char)) {
122
+ var _acc3 = _char;
123
+ pos++;
124
+ while (line[pos] && var_pattern.test("".concat(line[pos].trim()))) {
125
+ _acc3 += line[pos];
126
+ pos++;
127
+ }
128
+ push_token(_acc3, _this.opcodes.includes(_acc3) ? "opcode" : "variable");
129
+ }
130
+ }
131
+ return tokens;
132
+ });
133
+ _defineProperty(this, "parse", function (token) {
134
+ if (token.type === "string" || token.type === "number") {
135
+ _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)]);
136
+ } else if (token.type === "array") {
137
+ _this.push_instruction("link Accounts/".concat(_this.account.name, "/Datatypes/Array"));
138
+ token.value.map(function (item, i) {
139
+ _this.parse(item);
140
+ _this.push_instruction(["cursor ".concat(i), "write ".concat(_this.is_not_literal(item.type) ? "{metadata.output:-1}" : "{datapath:-1}")]);
141
+ });
142
+ _this.push_instruction("pop Array");
143
+ } else if (token.type === "twain") {
144
+ _this.push_instruction("link Accounts/".concat(_this.account.name, "/Datatypes/Twain"));
145
+ var curs = true;
146
+ if (token.value) token.value.map(function (entry) {
147
+ if (entry.type === "separator") {
148
+ curs = false;
149
+ return;
150
+ }
151
+ _this.parse(entry);
152
+ if (curs) {
153
+ {
154
+ _this.push_instruction("cursor {*".concat(_this.is_not_literal(entry.type) ? "metadata.output:-1" : "datapath:-1", "}"));
155
+ }
156
+ } else {
157
+ _this.push_instruction("write ".concat(_this.is_not_literal(entry.type) ? "{metadata.output:-1}" : "{datapath:-1}"));
158
+ curs = true;
159
+ }
43
160
  });
44
- curr_obj.children.push(token_obj);
45
- var greeds = token_obj.greedy(tokens.slice(pos));
46
- curr_obj.children.splice(-1);
47
- curr_obj.push(greeds.obj);
48
- pos += greeds.pos;
161
+ _this.push_instruction("pop Twain");
162
+ } else if (token.type === "variable") {
163
+ _this.push_instruction(["link ".concat("".concat(_this.stacks.slice(-1)[0], "/").concat(token.value)), "pop ".concat(token.value)]);
164
+ } else if (token.type === "address") _this.parse_assignment(token);
165
+ });
166
+ _defineProperty(this, "is_not_literal", function (type) {
167
+ return !type || ["variable", "opcode", "address"].includes(type);
168
+ });
169
+ _defineProperty(this, "parse_assignment", function (line, linked) {
170
+ var tokens = linked || line.type ? line : _this.parse_tokens(line);
171
+ var identifier = tokens[0];
172
+ if (linked || line.type) {
173
+ var line_split = (line.value || line).slice(line.value ? null : 1).trim().split(" ");
174
+ var path = line_split[0].split("/");
175
+ _this.push_instruction("link ".concat(_this.resolve_addr(path.join("/"))));
176
+ tokens = !line.type && _this.parse_tokens(line_split.slice(1).join(" "));
177
+ tokens.unshift && tokens.unshift(null);
178
+ if (line.type === "address") return _this.push_instruction("pop ".concat(path[path.length - 1]));
179
+ } else {
180
+ _this.push_instruction("chain ".concat(identifier.value));
181
+ _this.stack_instruction(["link ".concat(_this.stacks.slice(-1)[0]), "chain ".concat(identifier.value), "pop ".concat(identifier.value), "pop"]);
49
182
  }
50
- stop_token && _this.namestack.pop();
51
- return {
52
- pos: pos
53
- };
183
+ var prev_token;
184
+ if (tokens[1] && tokens[1].type === "opcode") {
185
+ _this.parse_opcode(tokens.slice(1));
186
+ prev_token = tokens[1];
187
+ } else {
188
+ tokens.slice(1).map(function (tok) {
189
+ _this.parse(tok);
190
+ });
191
+ prev_token = tokens.slice(-1)[0];
192
+ }
193
+ if (tokens.length > 1) {
194
+ _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)]);
195
+ } else _this.push_instruction("pop ".concat(identifier.value));
196
+ });
197
+ _defineProperty(this, "parse_opcode", function (line) {
198
+ var tokens = Array.isArray(line) ? line : _this.parse_tokens(line);
199
+ var op = tokens[0];
200
+ if (op.type !== "opcode") return _this.parse(op);
201
+ _this.push_instruction(["link Accounts/".concat(_this.account.name, "/Opcodes/").concat(op.value), "link Accounts/".concat(_this.account.name, "/Datatypes/Twain")]);
202
+ tokens.slice(1).map(function (tok, i) {
203
+ _this.parse(tok);
204
+ _this.push_instruction(["cursor op".concat(i), "write ".concat(_this.is_not_literal(tok.type) ? "{metadata.output:-1}" : "{datapath:-1}")]);
205
+ });
206
+ _this.push_instruction(["pop Twain", "cursor inputs", "write {datapath:-1}", op.value, "cursor {output}", "write {datapath:-1}", "pop ".concat(op.value)]);
207
+ });
208
+ _defineProperty(this, "resolve_addr", function (addr) {
209
+ addr = addr.split("/");
210
+ var real_addr = "";
211
+ if (addr[0] === "@") {
212
+ addr[0] = _this.account.physical_address;
213
+ real_addr = addr.join("/");
214
+ } else if (addr[0] === ".." || addr[0] === ".") {
215
+ var curr_addr = _this.stacks.slice(-1)[0].split("/");
216
+ while (addr[0] === ".." || addr[0] === ".") {
217
+ if (addr[0] === "..") curr_addr.splice(-1);
218
+ delete addr[0];
219
+ }
220
+ real_addr = curr_addr.join("/") + "".concat(addr.join("/"));
221
+ }
222
+ return real_addr;
223
+ });
224
+ _defineProperty(this, "new_stack_instructions", function (new_stack) {
225
+ var curr_stack = _this.stacks.slice(-1)[0].split("/");
226
+ new_stack = new_stack.split("/");
227
+ if (curr_stack[1] !== new_stack[1]) {} else {
228
+ var i = 0;
229
+ while (curr_stack[i] === new_stack[i]) i++;
230
+ for (var j = 2; j < new_stack.length; j++) _this.stack_instruction("chain ".concat(new_stack[j]));
231
+ _this.stack_instruction("link ".concat(_this.account.physical_address, "/Datatypes/Array"));
232
+ }
233
+ });
234
+ _defineProperty(this, "parse_routine", function (line) {
235
+ var addr = _this.resolve_addr(line);
236
+ _this.instruction_stacks.push([]);
237
+ _this.new_stack_instructions(addr);
238
+ _this.new_stack(addr);
239
+ _this.instruction_indexes.push(-1);
54
240
  });
55
- _defineProperty(this, "compile", function (obj) {
56
- obj = obj || _this.globe;
57
- var instructions = new Array();
58
- obj.generate_assembly(instructions);
59
- obj.children = [];
60
- return (0, _format_instructions["default"])(instructions, 1);
241
+ _defineProperty(this, "pop", function () {
242
+ var _this$instructions;
243
+ var addr = _this.stacks.splice(-1)[0].split("/");
244
+ _this.stack_instruction(["pop Array", "cursor {program}", "write {datapath:-1}"]);
245
+ for (var j = 2; j < addr.length; j++) _this.stack_instruction("pop ".concat(addr[j]));
246
+ (_this$instructions = _this.instructions).push.apply(_this$instructions, _toConsumableArray(_this.instruction_stacks.splice(-1)[0]));
247
+ _this.instruction_indexes.pop();
248
+ });
249
+ _defineProperty(this, "compile", function (codes) {
250
+ var code_array = codes.split("\n");
251
+ for (var c = 0; c < code_array.length; c++) {
252
+ var line = code_array[c].trim();
253
+ if (!line) continue;
254
+ if (line === ";") _this.pop();else if (line.startsWith("link ")) _this.parse_routine(line);else if (line.startsWith(".") || line.startsWith("@")) _this.parse_routine(line);else if (line.startsWith("//")) continue;else if (line.startsWith(">@")) _this.parse_assignment(line, true);else if (line.startsWith(">")) _this.parse_assignment(line);else _this.parse_opcode(line);
255
+ }
61
256
  });
62
- _defineProperty(this, "run", function (code, cb, no_run) {
63
- _this.tokenise(code);
64
- _this.parse();
65
- var payload = {
257
+ _defineProperty(this, "run", function (codes, pure) {
258
+ _this.pure = pure;
259
+ _this.compile(codes);
260
+
261
+ // console.log(JSON.stringify(this.instructions, null, 2), "hiya");
262
+
263
+ _this.account.load({
66
264
  program: {
67
- instructions: _this.compile()
265
+ instructions: _toConsumableArray(_this.instructions)
68
266
  }
69
- };
70
- !no_run && _this.account.load(payload, cb);
71
- // console.log(payload.instructions, "hiya");
267
+ });
268
+ _this.instructions = [];
269
+ _this.pure = null;
72
270
  });
73
271
  this.account = account;
74
- this.name = this.account.name;
75
- this.globe = new _global["default"](this);
76
- this.namestack = new Array(this.globe);
77
- this.expr_types = ["number", "string", "twain", "array", "boolean", "variable"];
78
- this.datatypes = ["array", "string", "number", "boolean", "twain", "void"];
79
- this.open_parens = "([{";
80
- this.close_parens = ")]}";
272
+ this.opcodes = new Array();
273
+ this.instructions = new Array();
274
+ this.instruction_indexes = new Array();
275
+ this.instruction_stacks = [[]];
276
+ this.stacks = new Array(account.physical_address);
81
277
  });
82
- var _default = Loader_sequence;
278
+ var _default = Loader;
83
279
  exports["default"] = _default;
@@ -43,13 +43,14 @@ var Account = /*#__PURE__*/function (_Filesystem) {
43
43
  return call_session;
44
44
  });
45
45
  _defineProperty(_assertThisInitialized(_this), "buff", function (block, pid) {
46
- var bf = _this.mine_buffer[pid];
47
- if (!bf) return;
48
- bf.blocks.push(block.stringify());
46
+ var buffer = _this.mine_buffer[pid];
47
+ if (!buffer) return;
48
+ buffer.blocks.push(block.stringify());
49
49
  });
50
50
  _defineProperty(_assertThisInitialized(_this), "flush_buffer", function (pid) {
51
51
  var buff = _this.mine_buffer[pid];
52
- buff.callback && buff.callback(buff.blocks);
52
+ if (!buff) return;
53
+ buff.callback && _this.run_callback(buff.callback, buff.blocks);
53
54
  delete _this.mine_buffer[pid];
54
55
  });
55
56
  _defineProperty(_assertThisInitialized(_this), "load", function (_ref) {
@@ -84,35 +85,37 @@ var Account = /*#__PURE__*/function (_Filesystem) {
84
85
  var data = query ? chain.explore(query) : chain;
85
86
  _this.run_callback(callback, data && data.stringify());
86
87
  });
87
- _defineProperty(_assertThisInitialized(_this), "run", function (_ref3) {
88
- var payload = _ref3.payload,
89
- signature = _ref3.signature,
90
- callback = _ref3.callback;
88
+ _defineProperty(_assertThisInitialized(_this), "run", function (request) {
89
+ var payload = request.payload,
90
+ signature = request.signature,
91
+ callback = request.callback;
91
92
  var physical_address = payload.physical_address,
92
93
  account = payload.account,
93
94
  query = payload.query;
94
95
  account = _this.get_account(account);
95
96
  if (!account.validate(payload, signature)) return;
96
97
  var pid = account.manage_buffer(callback);
97
- var context = physical_address ? _this.manager.web.get({
98
- physical_address: physical_address
99
- }, true) : account.vm.get_context();
98
+ var context = physical_address ? _this.manager.web.get(physical_address) : account.vm.get_context();
100
99
  if (!context) return account.flush_buffer(pid);
101
- var blk = query ? context.explore(query) : context.get_block(0);
102
- if (blk) {
103
- _this.vm.stack.push(blk.hash);
104
- _this.manager.push({
105
- sequence: blk.data,
100
+ var blk = query ? context.explore(query) : context.get_latest_block();
101
+ if (blk && blk.metadata && blk.metadata.program) {
102
+ var program = _this.read(blk.metadata.program);
103
+ account.vm.contexts.push(context);
104
+ program.push("pop");
105
+ Array.isArray(program) && program.length && _this.manager.push({
106
+ sequence: program,
106
107
  account: account,
107
108
  pid: pid
108
109
  });
109
110
  }
110
111
  });
111
112
  _defineProperty(_assertThisInitialized(_this), "run_callback", function (callback, payload) {
112
- if (!callback) return;
113
- if (typeof callback === "function") return callback(payload);
114
- _this.vm.stdin(payload);
115
- callback.physical_address && _this.run(callback);
113
+ setTimeout(function () {
114
+ if (!callback) return;
115
+ if (typeof callback === "function") return callback(payload);
116
+ _this.vm.stdin(payload);
117
+ callback.payload && callback.payload.physical_address && _this.run(callback);
118
+ }, 0);
116
119
  });
117
120
  _defineProperty(_assertThisInitialized(_this), "validate", function (payload, signature) {
118
121
  if (!_this["private"]) return true;
package/Objects/Block.js CHANGED
@@ -49,7 +49,10 @@ var Block = /*#__PURE__*/_createClass(function Block(chain) {
49
49
  chain: ch.chain.hash
50
50
  });
51
51
  });
52
- obj.chain = _this.chain.hash;
52
+ obj.chain = {
53
+ hash: _this.chain.hash,
54
+ physical_address: _this.chain.physical_address
55
+ };
53
56
  return str ? JSON.stringify(obj) : obj;
54
57
  });
55
58
  this.chain = chain;
package/Objects/Chain.js CHANGED
@@ -34,7 +34,12 @@ var Chain = /*#__PURE__*/function (_Explorer) {
34
34
  _this.cursors.push(_this.cursor);
35
35
  _this.cursor = -1;
36
36
  });
37
+ _defineProperty(_assertThisInitialized(_this), "set_cursor", function (cursor) {
38
+ _this.cursor = cursor;
39
+ _this.cursors.push(cursor);
40
+ });
37
41
  _defineProperty(_assertThisInitialized(_this), "get_buffer", function () {
42
+ _this.cursor = _this.cursors.pop();
38
43
  return _this.buffs.slice(-1)[0];
39
44
  });
40
45
  _defineProperty(_assertThisInitialized(_this), "generate_hash", function () {
@@ -64,7 +69,8 @@ var Chain = /*#__PURE__*/function (_Explorer) {
64
69
  return block;
65
70
  });
66
71
  _defineProperty(_assertThisInitialized(_this), "add_block", function (block) {
67
- return _this.blocks.push(block);
72
+ _this.blocks.push(block);
73
+ _this.height = _this.blocks.length;
68
74
  });
69
75
  _defineProperty(_assertThisInitialized(_this), "get_latest_block", function () {
70
76
  return _this.blocks.slice(-1)[0];
@@ -99,6 +105,7 @@ var Chain = /*#__PURE__*/function (_Explorer) {
99
105
  _this.connections = new Array();
100
106
  _this.blocks = new Array();
101
107
  _this.txs = new Array();
108
+ _this.height = 0;
102
109
  _this.cursor = -1;
103
110
  _this.cursors = new Array();
104
111
  _this.buffs = new Array();
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _fs = _interopRequireDefault(require("fs"));
8
7
  var _hash = require("../utils/hash");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
8
  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
9
  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); } }
12
10
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -25,7 +23,6 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
25
23
  if (!datapath) return null;
26
24
  var type_folder = _this.account.manager.oracle.get(datapath);
27
25
  if (!type_folder) return datapath;
28
- type_folder.obj = JSON.parse(type_folder.obj);
29
26
  var content;
30
27
  if (type_folder.type === "twain") {
31
28
  content = {};
@@ -36,7 +33,7 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
36
33
  } else if (type_folder.type === "array") {
37
34
  content = [];
38
35
  type_folder.obj.map(function (t) {
39
- content.push(type_folder.parse_path(t));
36
+ content.push(_this.parse_path(t));
40
37
  });
41
38
  } else content = type_folder.obj;
42
39
  return content;
@@ -56,17 +53,15 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
56
53
  obj[_curs] = content[_curs];
57
54
  }
58
55
  } else if (type === "number") {
59
- obj = Number(content["-1"]) || -1;
56
+ obj = Number(content["-1"]);
57
+ if (isNaN(obj)) obj = -1;
60
58
  } else {
61
- content = content["-1"];
62
- if (content === "True") obj = true;else if (content === "False") obj = false;else obj = null;
59
+ obj = null;
63
60
  }
64
61
  if (just_obj) return obj;
65
- obj = JSON.stringify(obj);
66
- addr = "".concat(chain.path, "/").concat((0, _hash.hash)(obj));
67
- _fs["default"].writeFileSync(addr, obj, {
68
- encoding: "utf-8"
69
- });
62
+ addr = "".concat(chain.path, "/").concat((0, _hash.hash)(JSON.stringify(obj)));
63
+ _this;
64
+ if (obj != null) _this.manager.oracle.write(addr, obj);
70
65
  _this.manager.oracle.set(addr, {
71
66
  obj: obj,
72
67
  type: type
@@ -96,7 +91,7 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
96
91
  var content = context.get_buffer();
97
92
  if (!content || !arg) return;
98
93
  content[context.cursor] = arg;
99
- // console.log(`Writing: ${arg}`);
94
+ // console.log(`Writing: ${arg}`);
100
95
  });
101
96
  _defineProperty(this, "name_hash", function () {
102
97
  _this.hash = (0, _hash.hash)(_this.name);
@@ -107,8 +102,9 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
107
102
  return;
108
103
  }
109
104
  chain.path = "".concat(chain.parent ? chain.parent.path : _this.base_address, "/").concat(chain.hash);
110
- if (!_fs["default"].existsSync(chain.path)) {
111
- _fs["default"].mkdirSync(chain.path, {
105
+ var fs = _this.manager.oracle.fs;
106
+ if (!fs.existsSync(chain.path)) {
107
+ fs.mkdirSync(chain.path, {
112
108
  recursive: true
113
109
  });
114
110
  }
@@ -27,23 +27,26 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
27
27
  var _this = this;
28
28
  _classCallCheck(this, Manager);
29
29
  _defineProperty(this, "start_clock", function () {
30
- return _this.clock = setInterval(function () {
30
+ var frequency = Number(process.env.HERTS) || 10;
31
+ _this.clock = setInterval(function () {
31
32
  for (var account in _this.tracks) {
32
33
  var track = _this.tracks[account];
33
34
  var instruction = track.sequence[track.pointer];
34
35
  track.account.vm.execute(instruction, track);
35
36
  track.pointer++;
36
- if (track.breakpoint.slice(-1)[0] === track.pointer) {
37
- track.account.flush_buffer(track.pid);
38
- track.pid = track.pids.splice(-1)[0];
39
- }
40
37
  if (track.pointer === track.sequence.length) {
41
38
  _this.running--;
39
+ track.account.chain.mine(track.account.vm);
40
+ track.account.flush_buffer(track.pids.splice(-1)[0]);
42
41
  delete _this.tracks[account];
43
42
  }
43
+ if (track.breakpoint.slice(-1)[0] === track.pointer) {
44
+ track.account.flush_buffer(track.pids.slice(-1));
45
+ track.pid = track.pids.splice(-1)[0];
46
+ }
44
47
  }
45
48
  !_this.running && clearInterval(_this.clock);
46
- }, Number(process.env.HERTS) || 10);
49
+ }, frequency);
47
50
  });
48
51
  _defineProperty(this, "get_account", function (name) {
49
52
  return _this.accounts[name];
@@ -64,9 +67,14 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
64
67
  var track = _this.tracks[program.account.name];
65
68
  if (track) {
66
69
  var _track$sequence;
67
- track.breakpoint.push(track.pointer + 1);
70
+ track.breakpoint.push(track.pointer);
68
71
  (_track$sequence = track.sequence).splice.apply(_track$sequence, [track.pointer + 1, 0].concat(_toConsumableArray(program.sequence)));
69
72
  track.pids.push(program.pid);
73
+ if (!_this.running) {
74
+ _this.running++;
75
+ _this.tracks[program.account.name] = track;
76
+ _this.start_clock();
77
+ }
70
78
  } else {
71
79
  track = _objectSpread(_objectSpread({}, program), {}, {
72
80
  pointer: 0,
@@ -17,18 +17,20 @@ var Opcodes = /*#__PURE__*/_createClass(function Opcodes() {
17
17
  _classCallCheck(this, Opcodes);
18
18
  _defineProperty(this, "set", function (opcode, circuit) {
19
19
  _this.opcodes[opcode] = circuit;
20
+ _this.account.compiler.opcodes.push(opcode);
20
21
  });
21
22
  _defineProperty(this, "prepare_operation", function (opcode, context) {
22
23
  var circ = _this.opcodes[opcode];
23
24
  if (typeof circ !== "function") return;
24
25
  var buf = context.get_buffer();
25
- var res = circ(context.account.read(buf.inputs));
26
+ var args = buf && context.account.read(buf.inputs);
27
+ var res = circ(args);
26
28
  _this.stdin(res);
27
29
  });
28
30
  _defineProperty(this, "stdin", function (object) {
29
- if (!object) return;
31
+ if (object == null) return;
30
32
  var code_string = (0, _functions.transpile_object)(object);
31
- _this.account.compiler.run(code_string);
33
+ _this.account.compiler.run(code_string, true);
32
34
  // console.log(`Writing in: ${code_string}`);
33
35
  });
34
36
  this.opcodes = new Object();
package/Objects/Oracle.js CHANGED
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
7
9
  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); }
8
10
  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); } }
9
11
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -25,6 +27,14 @@ var Oracle = /*#__PURE__*/_createClass(function Oracle(mgr) {
25
27
  _defineProperty(this, "get", function (path) {
26
28
  return _this.datapaths[path];
27
29
  });
30
+ _defineProperty(this, "write", function (addr, data) {
31
+ var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
32
+ encoding: "utf-8"
33
+ };
34
+ if (typeof data !== "string") data = JSON.stringify(data);
35
+ _this.fs.writeFileSync(addr, data, meta);
36
+ });
37
+ this.fs = _fs["default"];
28
38
  this.mgr = mgr;
29
39
  this.datapaths = new Object();
30
40
  });