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