godprotocol 1.0.81 → 1.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +3 -0
- package/Index.js +8 -19
- package/Loader_sequence/main.js +368 -234
- package/Objects/Account.js +229 -176
- package/Objects/Block.js +64 -61
- package/Objects/Blockweb.js +27 -34
- package/Objects/Chain.js +122 -118
- package/Objects/Explorer.js +30 -37
- package/Objects/Filesystem.js +96 -81
- package/Objects/Frame.js +43 -48
- package/Objects/Manager.js +60 -69
- package/Objects/Opcodes.js +39 -101
- package/Objects/Oracle.js +71 -69
- package/Objects/Virtual_machine.js +135 -132
- package/[object Object]/.GDS/godprotocol/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0100dcacc00a6dc0263290e414f3d199b50f82b4dcbf9232b8a0bad9365d6878/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/03a089ffda6ca7be6e9327749c7417b3f759f4447de4dc1d8508c72571c8a46c/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817~9wMLAwapUgr25rjl~1721561106826 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817~xipvdPqJsd5PneYbcFNbJ0vQxthmu~1721561134383 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/0f4659b04f82c52bf8bf75ae0b4dc407574652ad35c84aa62ff4a52a868c7096/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/14fbd9082d61d0554e4917cb8e1b47966358762689a2bf021fc5e1dc38c7b239/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/221dbfff32f92e889762b6eb632423cbf51439fc16552940ee7ea7a2f92db662/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/2569577431a0c797f7526c5f2c59251343a1131adfd03f53363725951b7fd0d4/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/2743cfe8f897cdd0b22cb93cfd18fc58269705169bf0a01117edd1894cdce537/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402~5BrzgFCkRU4H7Cmlht1UyjorCm~1721561134375 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402~VMHaNZbDCtpoSB~1721561106813 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/3ef66e0b0e059670edfa53a5c505196a5bc451d3c9e3a1b71f58519ca3c86146/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da~GJVjeKlgSCUdKGWUJ~1721561134114 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da~OsMwcPCk8F5SaSUdCGmM6~1721561106561 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/40149a5ceadd07e7cadcbad839efd7e1ac2a14b3d4a17dfa70aeff14778ed820/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/4503206d1cc4cdcef228061891a7a54a6a9838dce526bc4d755b0762d0da896b/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7~8dBekgqAvRnIyZomf~1721561134269 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7~Zc7Fa5AIsUySTCcWEiXmmYg3~1721561106712 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/54b16422271d6924c17c2abf55806035f5f36d4f4edb7f68bdd326bdb0abe500/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/57551ba66193cbc4696ca16cc27e9ccb73b79ddfae6b10fdf382747099033f3f/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/57d351527a4e63d51d13771038ac9ad59810f01960cc74b0f18158de872a20cc/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/5f87c4e573fa678825d72d8009f9aacce94d94bade4a26123db3c9e3a7488dc8/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/60fe28ac093915ec5e5cd08cb71650e3dab0e4c3644c32dd1ab13672f828f073/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/61bdf0593cd727752cb917ab968a08853d45142b8a8e4cdcd0fe03d1616f3586/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/61f3b3350c0c092e4c864b1a8c94f8b9272a132b100f8a5eb3a2e54dd20983be/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/646f04e302b372dc14871693fd87b6f80575c48f0045276f1a2b3ff999ae45fb/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/695853d02abbfe2f2a380598a871741caafa602d096a45adbe863e8f7e72f255/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/75944e73a11a149023ecf3430316a2b301a0b72c00cbd0b129f62b0f96e02f32/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/787456fe235bf126b6299374ecedb92c54e280238e67a2bed7446ff581cb6a6f/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/81e5bdff5d308919377d7d85da689f6888cbdc61b3ca73e18648fd7c365d4684/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/83e0dcafe93e39fa0973ee663d38477b5302704f4aca728b8701a919675340db/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/88f7c75e6701c06b4ffa070f7b4bab01c1aee299140234cf06fd83bf1a6af372/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44~2pZyTBlnZEjqeqLRX49qa~1721561134187 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44~GacmVaFxSmu5yLRhGW4kvf~1721561106631 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/b15dcc79636744d7df8a3e28bfb9551bbb2f766d3e93885964ee4cda0070ec5d/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2~rB45nHr3uT34~1721561106844 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2/b6d738d96a23a2b0638541041328e58895358c5ef9c21e2f8304939bff3e27f2~tmfqGhOsoJv91mdvgo5~1721561134385 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/blocks/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/c9c105370802042618805ccac28f7d9aaaf49db9873e14eb7a4e74a73f3cce89/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/cac2db27e0f3f0e4c80a3c28aea1fee8b935d0a41f2384f4a90acb57a888ac22/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/cbf8ec551d71fc89a73768c65a6c0d630cd3d85fe88dcab7d6b45ea6bd6a9e33/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/d479db3b8a1efa0e6ac5106c1aba0b6b806744df0f6a4730c0b9f6a01cac8a33/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/de551b5a493859e532316cbbf1e4a14eb06e0512556b1c1295ad60ffe07c185b/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f0ffe7cc032479994c0732c6a65b7887c09afafb1b0aa20062ccad2810d25101/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f13022c98357d9d9da982270f21ce304af3d89fecbf9364ab0a00a87e39bde57/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f3184b1d23adf18ef18e5d3f6e6978a77364642eef9edba0240b77d626334235/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f8a165e3f556ca2ea189f4d4401d139b22a6f19d0b38329fe4a5f14599840634/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7~3EOv6CEb1xPUw8~1721561134016 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7~DEp3QlIt6A44WxAccRmf~1721561106464 +1 -0
- package/[object Object]/.GDS/godprotocol/folders/fcc2a595781c53a76c4cd54382d3758d15120d3c4fcfae30f86067f8e6a830a2/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/fce39acf93dd6bdd9bc2e28288fd5b1c3c3c23313fe8527ec1d4d32a0081c94f/.config +1 -0
- package/[object Object]/.GDS/godprotocol/folders/fda5b539dcb04ba96e6e929d05d8df7b42316351de91f2d33b66edb97ede4dc5/.config +1 -0
- package/build/Account.js +187 -0
- package/build/Block.js +68 -0
- package/build/Blockweb.js +36 -0
- package/build/Chain.js +119 -0
- package/build/Explorer.js +47 -0
- package/build/Filesystem.js +127 -0
- package/build/Frame.js +52 -0
- package/build/Index.js +20 -0
- package/build/Manager.js +86 -0
- package/build/Opcodes.js +109 -0
- package/build/Oracle.js +81 -0
- package/build/Virtual_machine.js +136 -0
- package/build/add.js +26 -0
- package/build/create_server.js +132 -0
- package/build/framer.js +59 -0
- package/build/functions.js +82 -0
- package/build/hash.js +14 -0
- package/build/indices.js +31 -0
- package/build/jmp.js +19 -0
- package/build/main.js +327 -0
- package/build/opcodes.js +60 -0
- package/build/privacy.js +27 -0
- package/build/services.js +50 -0
- package/build/std.js +15 -0
- package/framer.js +36 -34
- package/opcodes/add.js +9 -25
- package/opcodes/indices.js +13 -16
- package/opcodes/jmp.js +7 -12
- package/opcodes/std.js +7 -13
- package/opcodes.js +34 -42
- package/package.json +1 -1
- package/readme.md +4 -4
- package/utils/create_server.js +72 -105
- package/utils/functions.js +31 -43
- package/utils/hash.js +10 -11
- package/utils/privacy.js +10 -15
- package/utils/services.js +32 -33
package/Loader_sequence/main.js
CHANGED
|
@@ -1,327 +1,461 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
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; }
|
|
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); } }
|
|
15
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
16
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
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; }
|
|
18
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
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); }
|
|
20
|
-
var num_pattern = /^[+-]?\d+(\.\d+)?$/;
|
|
1
|
+
let num_pattern = /^[+-]?\d+(\.\d+)?$/;
|
|
21
2
|
// let str_pattern = /^["'][^"']*["']$/;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
let var_pattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
4
|
+
|
|
5
|
+
class Loader {
|
|
6
|
+
constructor(account) {
|
|
7
|
+
this.account = account;
|
|
8
|
+
this.opcodes = new Array();
|
|
9
|
+
this.instructions = new Array();
|
|
10
|
+
|
|
11
|
+
this.instruction_indexes = new Array();
|
|
12
|
+
this.instruction_stacks = [[]];
|
|
13
|
+
this.stacks = new Array(account.physical_address);
|
|
14
|
+
this.markers = new Array();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
instruction_index = () => {
|
|
18
|
+
let index = this.instruction_indexes.slice(-1);
|
|
28
19
|
index++;
|
|
29
|
-
|
|
20
|
+
this.instruction_indexes.splice(-1, 1, index);
|
|
21
|
+
|
|
30
22
|
return index;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
stack_instruction = (instruction) => {
|
|
26
|
+
if (Array.isArray(instruction))
|
|
27
|
+
return instruction.map((i) => this.stack_instruction(i));
|
|
28
|
+
|
|
29
|
+
this.instruction_stacks.slice(-1)[0].push(instruction);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
new_stack = (addr) => {
|
|
33
|
+
this.stacks.push(addr);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
push_instruction = (instruction) => {
|
|
37
|
+
if (Array.isArray(instruction))
|
|
38
|
+
return instruction.map((i) => this.push_instruction(i));
|
|
39
|
+
|
|
40
|
+
if (this.pure) {
|
|
41
|
+
this.instructions.push(instruction);
|
|
47
42
|
} else {
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
this.stack_instruction(`cursor ${this.instruction_index()}`);
|
|
44
|
+
this.stack_instruction(`write ${instruction}`);
|
|
50
45
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
parse_tokens = (line, stop_char) => {
|
|
49
|
+
let tokens = new Array();
|
|
50
|
+
let pos = 0,
|
|
55
51
|
line_number = 0;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
line: line_number,
|
|
61
|
-
pos: pos
|
|
62
|
-
});
|
|
63
|
-
};
|
|
52
|
+
|
|
53
|
+
let push_token = (value, type) =>
|
|
54
|
+
tokens.push({ value, type, line: line_number, pos });
|
|
55
|
+
|
|
64
56
|
line = line.trim();
|
|
65
57
|
while (pos < line.length) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!_char) {
|
|
58
|
+
let char = line[pos].trim();
|
|
59
|
+
|
|
60
|
+
if (char === stop_char) return { tokens, pos };
|
|
61
|
+
|
|
62
|
+
if (!char) {
|
|
72
63
|
pos++;
|
|
64
|
+
|
|
73
65
|
continue;
|
|
74
66
|
}
|
|
75
|
-
|
|
67
|
+
|
|
68
|
+
if (char === "\n") {
|
|
76
69
|
line_number++;
|
|
77
70
|
pos++;
|
|
78
|
-
} else if (
|
|
79
|
-
|
|
71
|
+
} else if (char === "@") {
|
|
72
|
+
let acc = "";
|
|
80
73
|
while (line[pos] && line[pos].trim()) {
|
|
81
74
|
acc += line[pos];
|
|
82
75
|
pos++;
|
|
83
76
|
}
|
|
84
77
|
push_token(acc, "address");
|
|
85
|
-
} else if (
|
|
78
|
+
} else if (char === ",") {
|
|
86
79
|
pos++;
|
|
87
|
-
} else if (
|
|
88
|
-
push_token(
|
|
80
|
+
} else if (char === ":") {
|
|
81
|
+
push_token(char, "separator");
|
|
89
82
|
pos++;
|
|
90
|
-
} else if (
|
|
83
|
+
} else if (char === "[") {
|
|
91
84
|
pos++;
|
|
92
|
-
|
|
85
|
+
let toks = this.parse_tokens(line.slice(pos), "]");
|
|
93
86
|
push_token(toks.tokens, "array");
|
|
94
87
|
pos += toks.pos + 1;
|
|
95
|
-
} else if (
|
|
88
|
+
} else if (char === "{") {
|
|
96
89
|
pos++;
|
|
97
|
-
|
|
98
|
-
push_token(
|
|
99
|
-
pos +=
|
|
100
|
-
} else if (
|
|
90
|
+
let toks = this.parse_tokens(line.slice(pos), "}");
|
|
91
|
+
push_token(toks.tokens, "twain");
|
|
92
|
+
pos += toks.pos + 1;
|
|
93
|
+
} else if (char === ">") {
|
|
101
94
|
pos++;
|
|
102
|
-
} else if (
|
|
103
|
-
|
|
95
|
+
} else if (char === "'" || char === '"') {
|
|
96
|
+
let acc = "";
|
|
104
97
|
pos++;
|
|
105
|
-
while (line[pos] !==
|
|
98
|
+
while (line[pos] !== char) {
|
|
106
99
|
if (!line[pos]) break;
|
|
107
|
-
|
|
100
|
+
acc += line[pos];
|
|
108
101
|
pos++;
|
|
109
102
|
}
|
|
110
103
|
pos++;
|
|
111
|
-
push_token(
|
|
112
|
-
} else if (num_pattern.test(
|
|
113
|
-
|
|
104
|
+
push_token(acc, "string");
|
|
105
|
+
} else if (num_pattern.test(char)) {
|
|
106
|
+
let acc = char;
|
|
114
107
|
pos++;
|
|
115
|
-
while (
|
|
108
|
+
while (
|
|
109
|
+
num_pattern.test(line[pos]) ||
|
|
110
|
+
(line[pos] === "." && !acc.includes(line[pos]))
|
|
111
|
+
) {
|
|
116
112
|
if (!line[pos]) break;
|
|
117
|
-
|
|
113
|
+
|
|
114
|
+
acc += line[pos];
|
|
118
115
|
pos++;
|
|
119
116
|
}
|
|
120
|
-
push_token(
|
|
121
|
-
} else if (var_pattern.test(
|
|
122
|
-
|
|
117
|
+
push_token(acc, "number");
|
|
118
|
+
} else if (var_pattern.test(char)) {
|
|
119
|
+
let acc = char;
|
|
123
120
|
pos++;
|
|
124
|
-
while (line[pos] && var_pattern.test(
|
|
125
|
-
|
|
121
|
+
while (line[pos] && var_pattern.test(`${line[pos].trim()}`)) {
|
|
122
|
+
acc += line[pos];
|
|
126
123
|
pos++;
|
|
127
124
|
}
|
|
128
|
-
|
|
125
|
+
|
|
126
|
+
push_token(acc, this.opcodes.includes(acc) ? "opcode" : "variable");
|
|
129
127
|
}
|
|
130
128
|
}
|
|
129
|
+
|
|
131
130
|
return tokens;
|
|
132
|
-
}
|
|
133
|
-
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
parse = (token) => {
|
|
134
134
|
if (token.type === "string" || token.type === "number") {
|
|
135
|
-
|
|
135
|
+
this.push_instruction([
|
|
136
|
+
`link ${
|
|
137
|
+
this.account.physical_address
|
|
138
|
+
}/Datatypes/${`${token.type[0].toUpperCase()}${token.type.slice(1)}`}`,
|
|
139
|
+
`write ${token.value}`,
|
|
140
|
+
`pop ${token.type}`,
|
|
141
|
+
]);
|
|
136
142
|
} else if (token.type === "array") {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
this.push_instruction(
|
|
144
|
+
`link Accounts/${this.account.name}/Datatypes/Array`
|
|
145
|
+
);
|
|
146
|
+
token.value.map((item, i) => {
|
|
147
|
+
this.parse(item);
|
|
148
|
+
|
|
149
|
+
this.push_instruction([
|
|
150
|
+
`cursor ${i}`,
|
|
151
|
+
`write ${
|
|
152
|
+
this.is_not_literal(item.type)
|
|
153
|
+
? "{metadata.output:-1}"
|
|
154
|
+
: "{datapath:-1}"
|
|
155
|
+
}`,
|
|
156
|
+
]);
|
|
141
157
|
});
|
|
142
|
-
|
|
158
|
+
this.push_instruction(`pop Array`);
|
|
143
159
|
} else if (token.type === "twain") {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
_this.push_instruction("cursor {*".concat(_this.is_not_literal(entry.type) ? "metadata.output:-1" : "datapath:-1", "}"));
|
|
160
|
+
this.push_instruction(
|
|
161
|
+
`link Accounts/${this.account.name}/Datatypes/Twain`
|
|
162
|
+
);
|
|
163
|
+
let curs = true;
|
|
164
|
+
|
|
165
|
+
if (token.value)
|
|
166
|
+
token.value.map((entry) => {
|
|
167
|
+
if (entry.type === "separator") {
|
|
168
|
+
curs = false;
|
|
169
|
+
return;
|
|
155
170
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
171
|
+
this.parse(entry);
|
|
172
|
+
if (curs) {
|
|
173
|
+
{
|
|
174
|
+
this.push_instruction(
|
|
175
|
+
`cursor {*${
|
|
176
|
+
this.is_not_literal(entry.type)
|
|
177
|
+
? "metadata.output:-1"
|
|
178
|
+
: "datapath:-1"
|
|
179
|
+
}}`
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
this.push_instruction(
|
|
184
|
+
`write ${
|
|
185
|
+
this.is_not_literal(entry.type)
|
|
186
|
+
? "{metadata.output:-1}"
|
|
187
|
+
: "{datapath:-1}"
|
|
188
|
+
}`
|
|
189
|
+
);
|
|
190
|
+
curs = true;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
this.push_instruction(`pop Twain`);
|
|
162
194
|
} else if (token.type === "variable") {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
195
|
+
this.push_instruction([
|
|
196
|
+
`link ${`${this.stacks.slice(-1)[0]}/${token.value}`}`,
|
|
197
|
+
`pop ${token.value}`,
|
|
198
|
+
]);
|
|
199
|
+
} else if (token.type === "address") this.parse_assignment(token);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
is_not_literal = (type) =>
|
|
203
|
+
!type || ["variable", "opcode", "address"].includes(type);
|
|
204
|
+
|
|
205
|
+
parse_assignment = (line, linked) => {
|
|
206
|
+
let tokens = linked || line.type ? line : this.parse_tokens(line);
|
|
207
|
+
|
|
208
|
+
let identifier = tokens[0];
|
|
172
209
|
if (linked || line.type) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
210
|
+
let line_split = (line.value || line)
|
|
211
|
+
.slice(line.value ? null : 1)
|
|
212
|
+
.trim()
|
|
213
|
+
.split(" ");
|
|
214
|
+
let path = line_split[0].split("/");
|
|
215
|
+
|
|
216
|
+
this.push_instruction(`link ${this.resolve_addr(path.join("/"))}`);
|
|
217
|
+
|
|
218
|
+
tokens = !line.type && this.parse_tokens(line_split.slice(1).join(" "));
|
|
177
219
|
tokens.unshift && tokens.unshift(null);
|
|
178
|
-
if (line.type === "address")
|
|
220
|
+
if (line.type === "address")
|
|
221
|
+
return this.push_instruction(`pop ${path[path.length - 1]}`);
|
|
179
222
|
} else {
|
|
180
|
-
|
|
181
|
-
|
|
223
|
+
this.push_instruction(`chain ${identifier.value}`);
|
|
224
|
+
this.stack_instruction([
|
|
225
|
+
`link ${this.stacks.slice(-1)[0]}`,
|
|
226
|
+
`chain ${identifier.value}`,
|
|
227
|
+
`pop ${identifier.value}`,
|
|
228
|
+
"pop",
|
|
229
|
+
]);
|
|
182
230
|
}
|
|
183
|
-
|
|
231
|
+
|
|
232
|
+
let prev_token;
|
|
184
233
|
if (tokens[1] && tokens[1].type === "opcode") {
|
|
185
|
-
|
|
234
|
+
this.parse_opcode(tokens.slice(1));
|
|
186
235
|
prev_token = tokens[1];
|
|
187
236
|
} else {
|
|
188
|
-
tokens.slice(1).map(
|
|
189
|
-
|
|
237
|
+
tokens.slice(1).map((tok) => {
|
|
238
|
+
this.parse(tok);
|
|
190
239
|
});
|
|
191
240
|
prev_token = tokens.slice(-1)[0];
|
|
192
241
|
}
|
|
242
|
+
|
|
193
243
|
if (tokens.length > 1) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
244
|
+
this.push_instruction([
|
|
245
|
+
"cursor {output}",
|
|
246
|
+
`write ${
|
|
247
|
+
this.is_not_literal(prev_token && prev_token.type)
|
|
248
|
+
? "{metadata.output:-1}"
|
|
249
|
+
: "{datapath:-1}"
|
|
250
|
+
}`,
|
|
251
|
+
`pop ${identifier.value}`,
|
|
252
|
+
]);
|
|
253
|
+
} else this.push_instruction(`pop ${identifier.value}`);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
marker_pattern = /@[a-zA-Z_][a-zA-Z0-9_]*/;
|
|
257
|
+
|
|
258
|
+
parse_opcode = (line) => {
|
|
259
|
+
let tokens = Array.isArray(line) ? line : this.parse_tokens(line);
|
|
260
|
+
|
|
261
|
+
let op = tokens[0];
|
|
262
|
+
|
|
263
|
+
if (op.type !== "opcode") return this.parse(op);
|
|
264
|
+
|
|
265
|
+
this.push_instruction([
|
|
266
|
+
`link Accounts/${this.account.name}/Opcodes/${op.value}`,
|
|
267
|
+
`link Accounts/${this.account.name}/Datatypes/Twain`,
|
|
268
|
+
]);
|
|
269
|
+
|
|
270
|
+
tokens.slice(1).map((tok, i) => {
|
|
271
|
+
if (tok.type === "address" && tok.value.match(this.marker_pattern)) {
|
|
272
|
+
this.push_instruction([
|
|
273
|
+
`link ${this.account.physical_address}/Datatypes/Number`,
|
|
274
|
+
`write ${tok.value}`,
|
|
275
|
+
`pop Number`,
|
|
276
|
+
]);
|
|
277
|
+
} else this.parse(tok);
|
|
278
|
+
|
|
279
|
+
this.push_instruction([
|
|
280
|
+
`cursor op${i}`,
|
|
281
|
+
`write ${
|
|
282
|
+
this.is_not_literal(tok.type) &&
|
|
283
|
+
!(tok.type === "address" && tok.value.match(this.marker_pattern))
|
|
284
|
+
? "{metadata.output:-1}"
|
|
285
|
+
: "{datapath:-1}"
|
|
286
|
+
}`,
|
|
287
|
+
]);
|
|
208
288
|
});
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
289
|
+
|
|
290
|
+
this.push_instruction([
|
|
291
|
+
"pop Twain",
|
|
292
|
+
"cursor inputs",
|
|
293
|
+
`write {datapath:-1}`,
|
|
294
|
+
op.value,
|
|
295
|
+
`cursor {output}`,
|
|
296
|
+
`write {datapath:-1}`,
|
|
297
|
+
`pop ${op.value}`,
|
|
298
|
+
]);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
resolve_addr = (addr) => {
|
|
212
302
|
addr = addr.split("/");
|
|
213
|
-
|
|
303
|
+
|
|
304
|
+
let real_addr = "";
|
|
305
|
+
|
|
214
306
|
if (addr[0] === "@") {
|
|
215
|
-
addr[0] =
|
|
307
|
+
addr[0] = this.account.physical_address;
|
|
216
308
|
real_addr = addr.join("/");
|
|
217
309
|
} else if (addr[0] === ".." || addr[0] === ".") {
|
|
218
|
-
|
|
310
|
+
let curr_addr = this.stacks.slice(-1)[0].split("/");
|
|
219
311
|
while (addr[0] === ".." || addr[0] === ".") {
|
|
220
312
|
if (addr[0] === "..") curr_addr.splice(-1);
|
|
221
313
|
delete addr[0];
|
|
222
314
|
}
|
|
223
|
-
real_addr = curr_addr.join("/") +
|
|
315
|
+
real_addr = curr_addr.join("/") + `${addr.join("/")}`;
|
|
224
316
|
}
|
|
317
|
+
|
|
225
318
|
return real_addr;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
new_stack_instructions = (new_stack) => {
|
|
322
|
+
let curr_stack = this.stacks.slice(-1)[0].split("/");
|
|
229
323
|
new_stack = new_stack.split("/");
|
|
230
|
-
|
|
231
|
-
|
|
324
|
+
|
|
325
|
+
if (curr_stack[1] !== new_stack[1]) {
|
|
326
|
+
} else {
|
|
327
|
+
let i = 0;
|
|
232
328
|
while (curr_stack[i] === new_stack[i]) i++;
|
|
233
|
-
|
|
234
|
-
|
|
329
|
+
|
|
330
|
+
for (let j = 2; j < new_stack.length; j++)
|
|
331
|
+
this.stack_instruction(`chain ${new_stack[j]}`);
|
|
332
|
+
|
|
333
|
+
this.stack_instruction(
|
|
334
|
+
`link ${this.account.physical_address}/Datatypes/Array`
|
|
335
|
+
);
|
|
235
336
|
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
parse_routine = (line) => {
|
|
340
|
+
let addr = this.resolve_addr(line);
|
|
341
|
+
|
|
342
|
+
this.instruction_stacks.push([]);
|
|
343
|
+
this.new_stack_instructions(addr);
|
|
344
|
+
this.new_stack(addr);
|
|
345
|
+
|
|
346
|
+
this.instruction_indexes.push(-1);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
pop = () => {
|
|
350
|
+
let addr = this.stacks.splice(-1)[0].split("/");
|
|
351
|
+
this.stack_instruction([
|
|
352
|
+
`pop Array`,
|
|
353
|
+
`cursor {program}`,
|
|
354
|
+
`write {datapath:-1}`,
|
|
355
|
+
]);
|
|
356
|
+
|
|
357
|
+
for (let j = 2; j < addr.length; j++)
|
|
358
|
+
this.stack_instruction(`pop ${addr[j]}`);
|
|
359
|
+
|
|
360
|
+
this.instructions.push(...this.instruction_stacks.splice(-1)[0]);
|
|
361
|
+
|
|
362
|
+
this.instruction_indexes.pop();
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
revamp_marks = () => {
|
|
366
|
+
let instruction_stack = this.instruction_stacks.slice(-1)[0];
|
|
367
|
+
|
|
368
|
+
instruction_stack = instruction_stack.map((ins) =>
|
|
369
|
+
this.resolve_offset(ins, true)
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
this.instruction_stacks[this.instruction_stacks.length - 1] =
|
|
373
|
+
instruction_stack;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
handle_marker = (line) => {
|
|
377
|
+
let splits = line.slice(1).split(" ");
|
|
378
|
+
let name = splits[0];
|
|
379
|
+
|
|
380
|
+
let curr_stack = this.stacks.slice(-1)[0];
|
|
381
|
+
let markers = this.markers[curr_stack];
|
|
264
382
|
if (!markers) {
|
|
265
383
|
markers = new Object();
|
|
266
|
-
|
|
384
|
+
this.markers[curr_stack] = markers;
|
|
267
385
|
}
|
|
268
|
-
markers[name] =
|
|
269
|
-
|
|
386
|
+
markers[name] = this.instruction_index();
|
|
387
|
+
|
|
388
|
+
this.revamp_marks();
|
|
389
|
+
|
|
270
390
|
return splits.slice(1).join(" ");
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
resolve_offset = (line, revamping) => {
|
|
394
|
+
let matches = line.match(this.marker_pattern),
|
|
274
395
|
value;
|
|
275
396
|
if (matches) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
397
|
+
let match = matches[0].slice(1);
|
|
398
|
+
|
|
399
|
+
let curr_stack = this.stacks.slice(-1)[0];
|
|
400
|
+
let markers = this.markers[curr_stack];
|
|
279
401
|
if (!markers) {
|
|
280
402
|
markers = new Object();
|
|
281
|
-
|
|
403
|
+
this.markers[curr_stack] = markers;
|
|
282
404
|
}
|
|
283
405
|
value = markers[match];
|
|
284
406
|
}
|
|
285
|
-
|
|
407
|
+
|
|
408
|
+
if (typeof value === "number")
|
|
409
|
+
line = line.replace(
|
|
410
|
+
this.marker_pattern,
|
|
411
|
+
(revamping && value > 0 ? value - 1 : value).toString()
|
|
412
|
+
);
|
|
413
|
+
|
|
286
414
|
return line;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
compile = (codes) => {
|
|
418
|
+
let code_array = codes.split("\n");
|
|
419
|
+
|
|
420
|
+
for (let c = 0; c < code_array.length; c++) {
|
|
421
|
+
let line = code_array[c].trim();
|
|
292
422
|
if (!line) continue;
|
|
423
|
+
|
|
293
424
|
if (line.startsWith(":")) {
|
|
294
|
-
line =
|
|
425
|
+
line = this.handle_marker(line);
|
|
426
|
+
|
|
295
427
|
if (!line) continue;
|
|
296
428
|
}
|
|
297
|
-
|
|
298
|
-
|
|
429
|
+
|
|
430
|
+
line = this.resolve_offset(line);
|
|
431
|
+
|
|
432
|
+
if (line === ";") this.pop();
|
|
433
|
+
else if (line.startsWith(".") || line.startsWith("@"))
|
|
434
|
+
this.parse_routine(line);
|
|
435
|
+
else if (line.startsWith("//")) continue;
|
|
436
|
+
else if (line.startsWith(">@")) this.parse_assignment(line, true);
|
|
437
|
+
else if (line.startsWith(">")) this.parse_assignment(line);
|
|
438
|
+
else this.parse_opcode(line);
|
|
299
439
|
}
|
|
300
|
-
}
|
|
301
|
-
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
run = (codes, meta) => {
|
|
302
443
|
if (!meta) meta = {};
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
444
|
+
this.pure = meta && meta.pure;
|
|
445
|
+
|
|
446
|
+
let cb = meta && meta.cb;
|
|
447
|
+
|
|
448
|
+
this.compile(codes);
|
|
306
449
|
|
|
307
450
|
// console.log(JSON.stringify(this.instructions, null, 2), "hiya");
|
|
308
451
|
|
|
309
|
-
|
|
310
|
-
program: {
|
|
311
|
-
|
|
312
|
-
},
|
|
313
|
-
callback: cb
|
|
452
|
+
this.account.load({
|
|
453
|
+
program: { instructions: [...this.instructions] },
|
|
454
|
+
callback: cb,
|
|
314
455
|
});
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
this.instruction_indexes = new Array();
|
|
322
|
-
this.instruction_stacks = [[]];
|
|
323
|
-
this.stacks = new Array(account.physical_address);
|
|
324
|
-
this.markers = new Array();
|
|
325
|
-
});
|
|
326
|
-
var _default = Loader;
|
|
327
|
-
exports["default"] = _default;
|
|
456
|
+
this.instructions = [];
|
|
457
|
+
this.pure = false;
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export default Loader;
|