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