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