godprotocol 1.0.77 → 1.0.79
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/Index.js +3 -15
- package/Loader_sequence/main.js +255 -55
- package/Objects/Account.js +24 -21
- package/Objects/Block.js +4 -1
- package/Objects/Chain.js +8 -1
- package/Objects/Filesystem.js +11 -15
- package/Objects/Manager.js +19 -8
- package/Objects/Opcodes.js +5 -3
- package/Objects/Oracle.js +10 -0
- package/Objects/Virtual_machine.js +1 -7
- package/framer.js +2 -4
- package/opcodes/std.js +2 -1
- package/opcodes.js +6 -4
- package/package.json +13 -3
- package/readme.md +2 -2
- package/utils/create_server.js +23 -3
- package/.github/workflows/npm-publish-github-packages.yml +0 -36
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/30dc10d3485923c0c19083559094fe636f9491bff9c997306ffdbf3e1618a402/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/4dc569813ce0a2f446a3eec01358f5774f8564641ef8d579ff5b6d94b4d031a7/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/0ee263de3fb9e3e08e7d5abe21db8c0fe66188829979996dcddd3533d855a817/a965464a6d9f981543ce3aede226bd0fb989d9300cd8468f41cd1fc0139c8f44/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/12cd650efa4f63b7c61c3345db3daa0534f4c370a003ea6d8ae0d29a49f6f928/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/de551b5a493859e532316cbbf1e4a14eb06e0512556b1c1295ad60ffe07c185b/19270ea4f98808a63fbb99bc26a5ee6f0fe8df9c8182cf1d710b115d57250578 +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/f8a165e3f556ca2ea189f4d4401d139b22a6f19d0b38329fe4a5f14599840634/4f52f1dc77e0233034c6566fc73c30234de85d2298ff90885a7c56502dffa0b2 +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/3ff3661353ccadcaf9c6759a539d8d31e19c07ed0dd888170b9e55c7a18721da/f8a165e3f556ca2ea189f4d4401d139b22a6f19d0b38329fe4a5f14599840634/8d3c916f9c93a6f4c8be9c3f4493b1c02d3eb7516eac153a98320924b27739d8 +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/61bdf0593cd727752cb917ab968a08853d45142b8a8e4cdcd0fe03d1616f3586/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
- package/Accounts/59eb3cb130074f7b1ddb99c8fe14f27e1dbca735bb3da82e1ff0305340a32419/f968ed8cf7958218d4604b3de0bf074f09bac7925e86f7d1f495f8b2c67f31a7/74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b +0 -1
- package/Loader_sequence/functions/parse_expression.js +0 -107
- package/Loader_sequence/functions/parse_to_obj.js +0 -38
- package/Loader_sequence/functions/parse_variable.js +0 -38
- package/Loader_sequence/functions/tokenise.js +0 -135
- package/Loader_sequence/functions/utils.js +0 -14
- package/Loader_sequence/keywords/parse.js +0 -23
- package/Loader_sequence/native_classes/Variable.js +0 -49
- package/Loader_sequence/native_classes/datatypes/Array.js +0 -56
- package/Loader_sequence/native_classes/datatypes/Boolean.js +0 -42
- package/Loader_sequence/native_classes/datatypes/Number.js +0 -42
- package/Loader_sequence/native_classes/datatypes/String.js +0 -42
- package/Loader_sequence/native_classes/datatypes/Twain.js +0 -65
- package/Loader_sequence/native_classes/datatypes/Void.js +0 -42
- package/Loader_sequence/native_classes/global.js +0 -48
- package/Loader_sequence/native_classes/native.js +0 -63
- package/Loader_sequence/native_classes/operators.js +0 -64
- package/Loader_sequence/native_classes/parse.js +0 -54
- package/Loader_sequence/utils/format_instructions.js +0 -52
- package/build/Account.js +0 -245
- package/build/Array.js +0 -142
- package/build/Block.js +0 -100
- package/build/Blockweb.js +0 -78
- package/build/Boolean.js +0 -128
- package/build/Chain.js +0 -198
- package/build/Explorer.js +0 -85
- package/build/Filesystem.js +0 -173
- package/build/Frame.js +0 -108
- package/build/Index.js +0 -31
- package/build/Manager.js +0 -167
- package/build/Number.js +0 -128
- package/build/Opcodes.js +0 -75
- package/build/Oracle.js +0 -70
- package/build/String.js +0 -128
- package/build/Twain.js +0 -151
- package/build/Variable.js +0 -135
- package/build/Virtual_machine.js +0 -220
- package/build/Void.js +0 -128
- package/build/format_instructions.js +0 -52
- package/build/framer.js +0 -90
- package/build/global.js +0 -134
- package/build/main.js +0 -83
- package/build/native.js +0 -101
- package/build/operators.js +0 -150
package/Index.js
CHANGED
|
@@ -3,25 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.initiator = exports["default"] = void 0;
|
|
7
7
|
var _Manager = _interopRequireDefault(require("./Objects/Manager"));
|
|
8
|
-
var _framer = _interopRequireDefault(require("./framer"));
|
|
9
|
-
var _opcodes = _interopRequireDefault(require("./opcodes"));
|
|
10
8
|
var _create_server = _interopRequireDefault(require("./utils/create_server"));
|
|
11
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
10
|
var manager = new _Manager["default"]();
|
|
13
|
-
|
|
14
|
-
var start = function start(name, meta) {
|
|
15
|
-
var account = manager.add_account(name, meta);
|
|
16
|
-
(0, _framer["default"])(account);
|
|
17
|
-
(0, _opcodes["default"])(account);
|
|
18
|
-
return account;
|
|
19
|
-
};
|
|
20
|
-
var initiator = start(process.env.INITIATOR || "initiator");
|
|
11
|
+
var initiator = manager.add_account(process.env.INITIATOR || "initiator");
|
|
21
12
|
exports.initiator = initiator;
|
|
22
13
|
(0, _create_server["default"])(initiator);
|
|
23
|
-
|
|
24
|
-
initiator.compiler.run("\n greeting = 'Hello, world!' \n parse greeting\n");
|
|
25
|
-
}, 1500);
|
|
26
|
-
var _default = start;
|
|
14
|
+
var _default = manager;
|
|
27
15
|
exports["default"] = _default;
|
package/Loader_sequence/main.js
CHANGED
|
@@ -4,80 +4,280 @@ 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
|
|
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,
|
|
22
|
-
_defineProperty(this, "
|
|
23
|
-
|
|
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, "
|
|
26
|
-
|
|
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, "
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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));
|
|
54
196
|
});
|
|
55
|
-
_defineProperty(this, "
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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)]);
|
|
61
207
|
});
|
|
62
|
-
_defineProperty(this, "
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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];
|
|
68
219
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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);
|
|
240
|
+
});
|
|
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
|
+
}
|
|
256
|
+
});
|
|
257
|
+
_defineProperty(this, "run", function (codes, cb) {
|
|
258
|
+
if (typeof cb === "boolean") {
|
|
259
|
+
_this.pure = cb;
|
|
260
|
+
cb = null;
|
|
261
|
+
}
|
|
262
|
+
_this.compile(codes);
|
|
263
|
+
|
|
264
|
+
// console.log(JSON.stringify(this.instructions, null, 2), "hiya");
|
|
265
|
+
|
|
266
|
+
_this.account.load({
|
|
267
|
+
program: {
|
|
268
|
+
instructions: _toConsumableArray(_this.instructions)
|
|
269
|
+
},
|
|
270
|
+
callback: cb
|
|
271
|
+
});
|
|
272
|
+
_this.instructions = [];
|
|
273
|
+
_this.pure = false;
|
|
72
274
|
});
|
|
73
275
|
this.account = account;
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
79
|
-
this.open_parens = "([{";
|
|
80
|
-
this.close_parens = ")]}";
|
|
276
|
+
this.opcodes = new Array();
|
|
277
|
+
this.instructions = new Array();
|
|
278
|
+
this.instruction_indexes = new Array();
|
|
279
|
+
this.instruction_stacks = [[]];
|
|
280
|
+
this.stacks = new Array(account.physical_address);
|
|
81
281
|
});
|
|
82
|
-
var _default =
|
|
282
|
+
var _default = Loader;
|
|
83
283
|
exports["default"] = _default;
|
package/Objects/Account.js
CHANGED
|
@@ -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
|
|
47
|
-
if (!
|
|
48
|
-
|
|
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
|
-
|
|
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 (
|
|
88
|
-
var payload =
|
|
89
|
-
signature =
|
|
90
|
-
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.
|
|
102
|
-
if (blk) {
|
|
103
|
-
_this.
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
} else account.flush_buffer(pid);
|
|
110
111
|
});
|
|
111
112
|
_defineProperty(_assertThisInitialized(_this), "run_callback", function (callback, payload) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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 =
|
|
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
|
-
|
|
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();
|
package/Objects/Filesystem.js
CHANGED
|
@@ -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(
|
|
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"])
|
|
56
|
+
obj = Number(content["-1"]);
|
|
57
|
+
if (isNaN(obj)) obj = -1;
|
|
60
58
|
} else {
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
111
|
-
|
|
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
|
}
|
package/Objects/Manager.js
CHANGED
|
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
+
var _framer = _interopRequireDefault(require("../framer"));
|
|
8
|
+
var _opcodes = _interopRequireDefault(require("../opcodes"));
|
|
7
9
|
var _Account = _interopRequireDefault(require("./Account"));
|
|
8
10
|
var _Blockweb = _interopRequireDefault(require("./Blockweb"));
|
|
9
11
|
var _Oracle = _interopRequireDefault(require("./Oracle"));
|
|
@@ -27,23 +29,25 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
27
29
|
var _this = this;
|
|
28
30
|
_classCallCheck(this, Manager);
|
|
29
31
|
_defineProperty(this, "start_clock", function () {
|
|
30
|
-
|
|
32
|
+
var frequency = Number(process.env.HERTS) || 10;
|
|
33
|
+
_this.clock = setInterval(function () {
|
|
31
34
|
for (var account in _this.tracks) {
|
|
32
35
|
var track = _this.tracks[account];
|
|
33
36
|
var instruction = track.sequence[track.pointer];
|
|
34
37
|
track.account.vm.execute(instruction, track);
|
|
35
38
|
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
39
|
if (track.pointer === track.sequence.length) {
|
|
41
40
|
_this.running--;
|
|
41
|
+
track.account.chain.mine(track.account.vm);
|
|
42
|
+
track.account.flush_buffer(track.pids.splice(-1)[0]);
|
|
42
43
|
delete _this.tracks[account];
|
|
43
44
|
}
|
|
45
|
+
if (track.breakpoint.slice(-1)[0] === track.pointer) {
|
|
46
|
+
track.account.flush_buffer(track.pids.splice(-1)[0]);
|
|
47
|
+
}
|
|
44
48
|
}
|
|
45
49
|
!_this.running && clearInterval(_this.clock);
|
|
46
|
-
},
|
|
50
|
+
}, frequency);
|
|
47
51
|
});
|
|
48
52
|
_defineProperty(this, "get_account", function (name) {
|
|
49
53
|
return _this.accounts[name];
|
|
@@ -54,7 +58,9 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
54
58
|
account = new _Account["default"](name, _objectSpread(_objectSpread({}, meta), {}, {
|
|
55
59
|
manager: _this
|
|
56
60
|
}));
|
|
57
|
-
|
|
61
|
+
(0, _framer["default"])(account);
|
|
62
|
+
(0, _opcodes["default"])(account);
|
|
63
|
+
_this.accounts[account.name] = account;
|
|
58
64
|
} else if (meta && meta["private"] && !account["private"]) {
|
|
59
65
|
account["private"] = true;
|
|
60
66
|
}
|
|
@@ -64,9 +70,14 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
64
70
|
var track = _this.tracks[program.account.name];
|
|
65
71
|
if (track) {
|
|
66
72
|
var _track$sequence;
|
|
67
|
-
track.breakpoint.push(track.pointer + 1);
|
|
73
|
+
track.breakpoint.push(track.pointer + program.sequence.length + 1);
|
|
68
74
|
(_track$sequence = track.sequence).splice.apply(_track$sequence, [track.pointer + 1, 0].concat(_toConsumableArray(program.sequence)));
|
|
69
75
|
track.pids.push(program.pid);
|
|
76
|
+
if (!_this.running) {
|
|
77
|
+
_this.running++;
|
|
78
|
+
_this.tracks[program.account.name] = track;
|
|
79
|
+
_this.start_clock();
|
|
80
|
+
}
|
|
70
81
|
} else {
|
|
71
82
|
track = _objectSpread(_objectSpread({}, program), {}, {
|
|
72
83
|
pointer: 0,
|
package/Objects/Opcodes.js
CHANGED
|
@@ -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
|
|
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 (
|
|
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();
|