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