godprotocol 1.0.771 → 1.0.781
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 +0 -3
- package/Loader_sequence/main.js +460 -65
- package/Objects/Account.js +23 -20
- package/Objects/Block.js +4 -1
- package/Objects/Chain.js +8 -1
- package/Objects/Filesystem.js +11 -15
- package/Objects/Manager.js +15 -7
- package/Objects/Opcodes.js +5 -3
- package/Objects/Oracle.js +10 -0
- package/Objects/Virtual_machine.js +1 -7
- package/framer.js +2 -4
- package/opcodes/std.js +2 -1
- package/opcodes.js +6 -4
- package/package.json +6 -4
- package/readme.md +1 -1
- package/utils/services.js +1 -1
- package/Loader_sequence/functions/parse_expression.js +0 -107
- package/Loader_sequence/functions/parse_to_obj.js +0 -38
- package/Loader_sequence/functions/parse_variable.js +0 -38
- package/Loader_sequence/functions/tokenise.js +0 -135
- package/Loader_sequence/functions/utils.js +0 -14
- package/Loader_sequence/keywords/parse.js +0 -23
- package/Loader_sequence/native_classes/Variable.js +0 -49
- package/Loader_sequence/native_classes/datatypes/Array.js +0 -56
- package/Loader_sequence/native_classes/datatypes/Boolean.js +0 -42
- package/Loader_sequence/native_classes/datatypes/Number.js +0 -42
- package/Loader_sequence/native_classes/datatypes/String.js +0 -42
- package/Loader_sequence/native_classes/datatypes/Twain.js +0 -65
- package/Loader_sequence/native_classes/datatypes/Void.js +0 -42
- package/Loader_sequence/native_classes/global.js +0 -48
- package/Loader_sequence/native_classes/native.js +0 -63
- package/Loader_sequence/native_classes/operators.js +0 -64
- package/Loader_sequence/native_classes/parse.js +0 -54
- package/Loader_sequence/utils/format_instructions.js +0 -52
package/Objects/Filesystem.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
8
7
|
var _hash = require("../utils/hash");
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
8
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
11
9
|
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
12
10
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
@@ -25,7 +23,6 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
|
|
|
25
23
|
if (!datapath) return null;
|
|
26
24
|
var type_folder = _this.account.manager.oracle.get(datapath);
|
|
27
25
|
if (!type_folder) return datapath;
|
|
28
|
-
type_folder.obj = JSON.parse(type_folder.obj);
|
|
29
26
|
var content;
|
|
30
27
|
if (type_folder.type === "twain") {
|
|
31
28
|
content = {};
|
|
@@ -36,7 +33,7 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
|
|
|
36
33
|
} else if (type_folder.type === "array") {
|
|
37
34
|
content = [];
|
|
38
35
|
type_folder.obj.map(function (t) {
|
|
39
|
-
content.push(
|
|
36
|
+
content.push(_this.parse_path(t));
|
|
40
37
|
});
|
|
41
38
|
} else content = type_folder.obj;
|
|
42
39
|
return content;
|
|
@@ -56,17 +53,15 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
|
|
|
56
53
|
obj[_curs] = content[_curs];
|
|
57
54
|
}
|
|
58
55
|
} else if (type === "number") {
|
|
59
|
-
obj = Number(content["-1"])
|
|
56
|
+
obj = Number(content["-1"]);
|
|
57
|
+
if (isNaN(obj)) obj = -1;
|
|
60
58
|
} else {
|
|
61
|
-
|
|
62
|
-
if (content === "True") obj = true;else if (content === "False") obj = false;else obj = null;
|
|
59
|
+
obj = null;
|
|
63
60
|
}
|
|
64
61
|
if (just_obj) return obj;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
encoding: "utf-8"
|
|
69
|
-
});
|
|
62
|
+
addr = "".concat(chain.path, "/").concat((0, _hash.hash)(JSON.stringify(obj)));
|
|
63
|
+
_this;
|
|
64
|
+
if (obj != null) _this.manager.oracle.write(addr, obj);
|
|
70
65
|
_this.manager.oracle.set(addr, {
|
|
71
66
|
obj: obj,
|
|
72
67
|
type: type
|
|
@@ -96,7 +91,7 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
|
|
|
96
91
|
var content = context.get_buffer();
|
|
97
92
|
if (!content || !arg) return;
|
|
98
93
|
content[context.cursor] = arg;
|
|
99
|
-
//
|
|
94
|
+
// console.log(`Writing: ${arg}`);
|
|
100
95
|
});
|
|
101
96
|
_defineProperty(this, "name_hash", function () {
|
|
102
97
|
_this.hash = (0, _hash.hash)(_this.name);
|
|
@@ -107,8 +102,9 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
|
|
|
107
102
|
return;
|
|
108
103
|
}
|
|
109
104
|
chain.path = "".concat(chain.parent ? chain.parent.path : _this.base_address, "/").concat(chain.hash);
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
var fs = _this.manager.oracle.fs;
|
|
106
|
+
if (!fs.existsSync(chain.path)) {
|
|
107
|
+
fs.mkdirSync(chain.path, {
|
|
112
108
|
recursive: true
|
|
113
109
|
});
|
|
114
110
|
}
|
package/Objects/Manager.js
CHANGED
|
@@ -27,23 +27,26 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
27
27
|
var _this = this;
|
|
28
28
|
_classCallCheck(this, Manager);
|
|
29
29
|
_defineProperty(this, "start_clock", function () {
|
|
30
|
-
|
|
30
|
+
var frequency = Number(process.env.HERTS) || 10;
|
|
31
|
+
_this.clock = setInterval(function () {
|
|
31
32
|
for (var account in _this.tracks) {
|
|
32
33
|
var track = _this.tracks[account];
|
|
33
34
|
var instruction = track.sequence[track.pointer];
|
|
34
35
|
track.account.vm.execute(instruction, track);
|
|
35
36
|
track.pointer++;
|
|
36
|
-
if (track.breakpoint.slice(-1)[0] === track.pointer) {
|
|
37
|
-
track.account.flush_buffer(track.pid);
|
|
38
|
-
track.pid = track.pids.splice(-1)[0];
|
|
39
|
-
}
|
|
40
37
|
if (track.pointer === track.sequence.length) {
|
|
41
38
|
_this.running--;
|
|
39
|
+
track.account.chain.mine(track.account.vm);
|
|
40
|
+
track.account.flush_buffer(track.pids.splice(-1)[0]);
|
|
42
41
|
delete _this.tracks[account];
|
|
43
42
|
}
|
|
43
|
+
if (track.breakpoint.slice(-1)[0] === track.pointer) {
|
|
44
|
+
track.account.flush_buffer(track.pids.slice(-1));
|
|
45
|
+
track.pid = track.pids.splice(-1)[0];
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
48
|
!_this.running && clearInterval(_this.clock);
|
|
46
|
-
},
|
|
49
|
+
}, frequency);
|
|
47
50
|
});
|
|
48
51
|
_defineProperty(this, "get_account", function (name) {
|
|
49
52
|
return _this.accounts[name];
|
|
@@ -64,9 +67,14 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
64
67
|
var track = _this.tracks[program.account.name];
|
|
65
68
|
if (track) {
|
|
66
69
|
var _track$sequence;
|
|
67
|
-
track.breakpoint.push(track.pointer
|
|
70
|
+
track.breakpoint.push(track.pointer);
|
|
68
71
|
(_track$sequence = track.sequence).splice.apply(_track$sequence, [track.pointer + 1, 0].concat(_toConsumableArray(program.sequence)));
|
|
69
72
|
track.pids.push(program.pid);
|
|
73
|
+
if (!_this.running) {
|
|
74
|
+
_this.running++;
|
|
75
|
+
_this.tracks[program.account.name] = track;
|
|
76
|
+
_this.start_clock();
|
|
77
|
+
}
|
|
70
78
|
} else {
|
|
71
79
|
track = _objectSpread(_objectSpread({}, program), {}, {
|
|
72
80
|
pointer: 0,
|
package/Objects/Opcodes.js
CHANGED
|
@@ -17,18 +17,20 @@ var Opcodes = /*#__PURE__*/_createClass(function Opcodes() {
|
|
|
17
17
|
_classCallCheck(this, Opcodes);
|
|
18
18
|
_defineProperty(this, "set", function (opcode, circuit) {
|
|
19
19
|
_this.opcodes[opcode] = circuit;
|
|
20
|
+
_this.account.compiler.opcodes.push(opcode);
|
|
20
21
|
});
|
|
21
22
|
_defineProperty(this, "prepare_operation", function (opcode, context) {
|
|
22
23
|
var circ = _this.opcodes[opcode];
|
|
23
24
|
if (typeof circ !== "function") return;
|
|
24
25
|
var buf = context.get_buffer();
|
|
25
|
-
var
|
|
26
|
+
var args = buf && context.account.read(buf.inputs);
|
|
27
|
+
var res = circ(args);
|
|
26
28
|
_this.stdin(res);
|
|
27
29
|
});
|
|
28
30
|
_defineProperty(this, "stdin", function (object) {
|
|
29
|
-
if (
|
|
31
|
+
if (object == null) return;
|
|
30
32
|
var code_string = (0, _functions.transpile_object)(object);
|
|
31
|
-
_this.account.compiler.run(code_string);
|
|
33
|
+
_this.account.compiler.run(code_string, true);
|
|
32
34
|
// console.log(`Writing in: ${code_string}`);
|
|
33
35
|
});
|
|
34
36
|
this.opcodes = new Object();
|
package/Objects/Oracle.js
CHANGED
|
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
7
9
|
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
10
|
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); } }
|
|
9
11
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
@@ -25,6 +27,14 @@ var Oracle = /*#__PURE__*/_createClass(function Oracle(mgr) {
|
|
|
25
27
|
_defineProperty(this, "get", function (path) {
|
|
26
28
|
return _this.datapaths[path];
|
|
27
29
|
});
|
|
30
|
+
_defineProperty(this, "write", function (addr, data) {
|
|
31
|
+
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
32
|
+
encoding: "utf-8"
|
|
33
|
+
};
|
|
34
|
+
if (typeof data !== "string") data = JSON.stringify(data);
|
|
35
|
+
_this.fs.writeFileSync(addr, data, meta);
|
|
36
|
+
});
|
|
37
|
+
this.fs = _fs["default"];
|
|
28
38
|
this.mgr = mgr;
|
|
29
39
|
this.datapaths = new Object();
|
|
30
40
|
});
|
|
@@ -64,9 +64,6 @@ var Virtual_machine = /*#__PURE__*/function (_Opcodes) {
|
|
|
64
64
|
args: args
|
|
65
65
|
};
|
|
66
66
|
});
|
|
67
|
-
_defineProperty(_assertThisInitialized(_this), "run_traverse", function () {
|
|
68
|
-
if (!_this.running) return;
|
|
69
|
-
});
|
|
70
67
|
_defineProperty(_assertThisInitialized(_this), "execute", function (instruction, track) {
|
|
71
68
|
_this.track = track;
|
|
72
69
|
if (!instruction) return;
|
|
@@ -82,19 +79,16 @@ var Virtual_machine = /*#__PURE__*/function (_Opcodes) {
|
|
|
82
79
|
case "chain":
|
|
83
80
|
chain = context.account.add_chain(args, context);
|
|
84
81
|
_this.contexts.push(chain);
|
|
85
|
-
_this.run_traverse();
|
|
86
82
|
chain.append_buffer();
|
|
87
83
|
break;
|
|
88
84
|
case "link":
|
|
89
85
|
chain = context.account.manager.web.get(args);
|
|
90
|
-
var k = Object.keys(context.account.manager.web.physical_addresses);
|
|
91
86
|
if (!chain) {
|
|
92
87
|
console.log("LINKing Failed. - ".concat(args));
|
|
93
88
|
return;
|
|
94
89
|
}
|
|
95
90
|
chain.append_buffer();
|
|
96
91
|
_this.contexts.push(chain);
|
|
97
|
-
_this.run_traverse();
|
|
98
92
|
break;
|
|
99
93
|
case "mine":
|
|
100
94
|
var bloc = context.mine(_assertThisInitialized(_this), true);
|
|
@@ -113,7 +107,7 @@ var Virtual_machine = /*#__PURE__*/function (_Opcodes) {
|
|
|
113
107
|
_this.contexts.pop();
|
|
114
108
|
break;
|
|
115
109
|
case "cursor":
|
|
116
|
-
context.
|
|
110
|
+
context.set_cursor(args);
|
|
117
111
|
break;
|
|
118
112
|
case "write":
|
|
119
113
|
context.account.write(args, context);
|
package/framer.js
CHANGED
|
@@ -20,14 +20,12 @@ var framer = function framer(initiator) {
|
|
|
20
20
|
subtract: null,
|
|
21
21
|
divide: null,
|
|
22
22
|
exp: null
|
|
23
|
-
}, _defineProperty(_Opcodes, "equal", null), _defineProperty(_Opcodes, "not_equal", null), _defineProperty(_Opcodes, "greater_than", null), _defineProperty(_Opcodes, "less_than", null), _defineProperty(_Opcodes, "gte", null), _defineProperty(_Opcodes, "lte", null), _defineProperty(_Opcodes, "send", null), _defineProperty(_Opcodes, "readonly", null), _defineProperty(_Opcodes, "socket_send", null), _defineProperty(_Opcodes, "jmp", null), _defineProperty(_Opcodes, "jmp_if", null), _defineProperty(_Opcodes, "hold", null), _defineProperty(_Opcodes, "stdout", null), _defineProperty(_Opcodes, "stdin", null), _Opcodes),
|
|
23
|
+
}, _defineProperty(_Opcodes, "equal", null), _defineProperty(_Opcodes, "not_equal", null), _defineProperty(_Opcodes, "greater_than", null), _defineProperty(_Opcodes, "less_than", null), _defineProperty(_Opcodes, "gte", null), _defineProperty(_Opcodes, "lte", null), _defineProperty(_Opcodes, "send", null), _defineProperty(_Opcodes, "readonly", null), _defineProperty(_Opcodes, "socket_send", null), _defineProperty(_Opcodes, "jmp", null), _defineProperty(_Opcodes, "jmp_if", null), _defineProperty(_Opcodes, "hold", null), _defineProperty(_Opcodes, "stdout", null), _defineProperty(_Opcodes, "stdin", null), _defineProperty(_Opcodes, "run", null), _defineProperty(_Opcodes, "load", null), _defineProperty(_Opcodes, "parse", null), _defineProperty(_Opcodes, "create_account", null), _Opcodes),
|
|
24
24
|
Datatypes: {
|
|
25
25
|
Number: null,
|
|
26
26
|
String: null,
|
|
27
27
|
Twain: null,
|
|
28
|
-
Array: null
|
|
29
|
-
Void: null,
|
|
30
|
-
Boolean: null
|
|
28
|
+
Array: null
|
|
31
29
|
},
|
|
32
30
|
Objects: {
|
|
33
31
|
Blockchain: {
|
package/opcodes/std.js
CHANGED
package/opcodes.js
CHANGED
|
@@ -14,6 +14,7 @@ var opcodes = function opcodes(account) {
|
|
|
14
14
|
var set = account.vm.set;
|
|
15
15
|
_add.ops.map(function (op) {
|
|
16
16
|
set(op.name, function (args) {
|
|
17
|
+
if (!args) return;
|
|
17
18
|
try {
|
|
18
19
|
var result = eval("".concat(args.op0, " ").concat(op.sign, " ").concat(args.op1));
|
|
19
20
|
return result;
|
|
@@ -31,10 +32,11 @@ var opcodes = function opcodes(account) {
|
|
|
31
32
|
// set("socket_send", socket_send);
|
|
32
33
|
|
|
33
34
|
set("stdout", _std.stdout);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
["run", "load", "parse", "create_account"].map(function (op) {
|
|
36
|
+
return set(op, function (arg) {
|
|
37
|
+
return arg && arg.op0 && account[op](arg && arg.op0);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
38
40
|
};
|
|
39
41
|
var _default = opcodes;
|
|
40
42
|
exports["default"] = _default;
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "godprotocol",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.781",
|
|
4
4
|
"description": "A data mediator.",
|
|
5
5
|
"main": "Index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
9
|
"start": "nodemon -r esm Index.js",
|
|
10
|
-
"
|
|
11
|
-
"prepack": "npmignore --auto"
|
|
10
|
+
"prepack": "npmignore"
|
|
12
11
|
},
|
|
13
12
|
"author": "Savvy",
|
|
14
13
|
"license": "ISC",
|
|
@@ -44,9 +43,12 @@
|
|
|
44
43
|
"godprotocol"
|
|
45
44
|
],
|
|
46
45
|
"dependencies": {
|
|
46
|
+
"@babel/cli": "latest",
|
|
47
|
+
"@babel/core": "^7.19.1",
|
|
47
48
|
"crypto": "^1.0.1",
|
|
48
49
|
"elliptic": "^6.5.5",
|
|
49
|
-
"fs": "^0.0.1-security"
|
|
50
|
+
"fs": "^0.0.1-security",
|
|
51
|
+
"babel-preset-env": "^1.7.0"
|
|
50
52
|
},
|
|
51
53
|
"publishConfig": {
|
|
52
54
|
"ignore": [
|
package/readme.md
CHANGED
|
@@ -30,7 +30,7 @@ let initiator = start(`name`, { private: true || false });
|
|
|
30
30
|
|
|
31
31
|
| `Parameters` | Type | Description |
|
|
32
32
|
| ------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
-
| `name` | string | Account names can be any valid variable string. Such as a
|
|
33
|
+
| `name` | string | Account names can be any valid variable string. Such as a Public Key |
|
|
34
34
|
| `private` | object:boolean | default `false`, if set to true, then any payloads sent to the account must be signed using the private key belonging to the account `name` |
|
|
35
35
|
|
|
36
36
|
## Load Instructions
|
package/utils/services.js
CHANGED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parse_expression = void 0;
|
|
7
|
-
var _parse_to_obj = _interopRequireDefault(require("./parse_to_obj"));
|
|
8
|
-
var _utils = require("./utils");
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
-
var capture_token = function capture_token(tokens) {
|
|
11
|
-
var token,
|
|
12
|
-
pos = 0;
|
|
13
|
-
token = tokens[pos];
|
|
14
|
-
pos++;
|
|
15
|
-
return {
|
|
16
|
-
token: token,
|
|
17
|
-
pos: pos
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
var slice_expression = function slice_expression(tokens, pos, parent) {
|
|
21
|
-
var expr = [];
|
|
22
|
-
if (parent.token.compiler.expr_types.includes(parent.token.type)) {
|
|
23
|
-
expr.push(parent.token);
|
|
24
|
-
}
|
|
25
|
-
while (pos < tokens.length) {
|
|
26
|
-
var _capture_token = capture_token(tokens.slice(pos)),
|
|
27
|
-
token = _capture_token.token,
|
|
28
|
-
pos_ = _capture_token.pos;
|
|
29
|
-
pos += pos_;
|
|
30
|
-
if (token.compiler.expr_types.includes(token.type)) {
|
|
31
|
-
if (expr.length && expr.slice(-1)[0].type !== "operator") break;
|
|
32
|
-
expr.push(token);
|
|
33
|
-
} else if (token.type === "operator") {
|
|
34
|
-
if (expr.length && !token.compiler.expr_types.includes(expr.slice(-1)[0].type)) break;
|
|
35
|
-
expr.push(token);
|
|
36
|
-
} else {
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
expr: expr,
|
|
42
|
-
pos: pos
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
var op_precedence = ["(", ">", "<", "<=", ">=", "==", "**", "/", "*", "+", "-", "~/", "~*", "~+", "~-"];
|
|
46
|
-
var has_op = function has_op(expr, op) {
|
|
47
|
-
var found = null;
|
|
48
|
-
for (var e = 0; e < expr.length; e++) {
|
|
49
|
-
var x = expr[e];
|
|
50
|
-
if (x.value === op) {
|
|
51
|
-
found = e;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return found;
|
|
56
|
-
};
|
|
57
|
-
var resolve_expression = function resolve_expression(expr, parent, params) {
|
|
58
|
-
if (expr.length === 1) {
|
|
59
|
-
expr[0] = (0, _parse_to_obj["default"])(expr[0], parent, {
|
|
60
|
-
is_expr: !params
|
|
61
|
-
});
|
|
62
|
-
} else {
|
|
63
|
-
while (expr.length > 1) {
|
|
64
|
-
for (var i = 0; i < op_precedence.length; i++) {
|
|
65
|
-
var op = op_precedence[i];
|
|
66
|
-
var e = has_op(expr, op);
|
|
67
|
-
while (e != null) {
|
|
68
|
-
var tok_obj = (0, _parse_to_obj["default"])(expr[e], parent);
|
|
69
|
-
tok_obj.push((0, _parse_to_obj["default"])(expr[e - 1], parent, {
|
|
70
|
-
is_expr: !params && tok_obj.token.value !== "="
|
|
71
|
-
}));
|
|
72
|
-
tok_obj.push((0, _parse_to_obj["default"])(expr[e + 1], parent, {
|
|
73
|
-
is_expr: !params
|
|
74
|
-
}));
|
|
75
|
-
expr.splice(e - 1, 3, tok_obj);
|
|
76
|
-
e = has_op(expr, op);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return expr[0];
|
|
82
|
-
};
|
|
83
|
-
var parse_expression = function parse_expression(tokens, parent, no_one, params) {
|
|
84
|
-
var pos = 0,
|
|
85
|
-
obj;
|
|
86
|
-
var _slice_expression = slice_expression(tokens, pos, parent),
|
|
87
|
-
expr = _slice_expression.expr,
|
|
88
|
-
pos_ = _slice_expression.pos;
|
|
89
|
-
if (expr.length <= 1 && no_one) return {
|
|
90
|
-
obj: parent,
|
|
91
|
-
pos: pos_ + 1
|
|
92
|
-
};
|
|
93
|
-
var assign = expr.find(function (ex) {
|
|
94
|
-
return (0, _utils.is_token_value)(ex, "=", "operator");
|
|
95
|
-
});
|
|
96
|
-
if (assign) {
|
|
97
|
-
obj = resolve_expression(expr.slice(2), parent);
|
|
98
|
-
parent.assign(obj);
|
|
99
|
-
obj = parent;
|
|
100
|
-
} else obj = resolve_expression(expr, parent, params);
|
|
101
|
-
pos = pos_;
|
|
102
|
-
return {
|
|
103
|
-
pos: pos,
|
|
104
|
-
obj: obj
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
exports.parse_expression = parse_expression;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _Variable = _interopRequireDefault(require("../native_classes/Variable"));
|
|
8
|
-
var _Array = _interopRequireDefault(require("../native_classes/datatypes/Array"));
|
|
9
|
-
var _Boolean = _interopRequireDefault(require("../native_classes/datatypes/Boolean"));
|
|
10
|
-
var _Number = _interopRequireDefault(require("../native_classes/datatypes/Number"));
|
|
11
|
-
var _String = _interopRequireDefault(require("../native_classes/datatypes/String"));
|
|
12
|
-
var _Twain = _interopRequireDefault(require("../native_classes/datatypes/Twain"));
|
|
13
|
-
var _Void = _interopRequireDefault(require("../native_classes/datatypes/Void"));
|
|
14
|
-
var _operators = _interopRequireDefault(require("../native_classes/operators"));
|
|
15
|
-
var _parse = _interopRequireDefault(require("../native_classes/parse"));
|
|
16
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
17
|
-
var parse_to_obj = function parse_to_obj(token, parent) {
|
|
18
|
-
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
19
|
-
var obj;
|
|
20
|
-
if (token.type === "operator") obj = new _operators["default"](token);else if (token.type === "keyword") {
|
|
21
|
-
if (token.value === "parse") {
|
|
22
|
-
obj = new _parse["default"](token);
|
|
23
|
-
}
|
|
24
|
-
} else if (token.type === "number") obj = new _Number["default"](token);else if (token.type === "string") obj = new _String["default"](token);else if (token.type === "array") obj = new _Array["default"](token);else if (token.type === "void") obj = new _Void["default"](token);else if (token.type === "boolean") obj = new _Boolean["default"](token);else if (token.type === "twain") obj = new _Twain["default"](token);else if (token.type === "variable") {
|
|
25
|
-
obj = new _Variable["default"](token);
|
|
26
|
-
if (meta && meta.is_expr) {
|
|
27
|
-
var declaration = parent.find(obj);
|
|
28
|
-
if (!declaration) {
|
|
29
|
-
throw new Error("Variable is not declared!");
|
|
30
|
-
}
|
|
31
|
-
obj.declaration = declaration;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
obj && obj.set_parent(parent);
|
|
35
|
-
return obj || token;
|
|
36
|
-
};
|
|
37
|
-
var _default = parse_to_obj;
|
|
38
|
-
exports["default"] = _default;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _Variable = _interopRequireDefault(require("../native_classes/Variable"));
|
|
8
|
-
var _parse_expression3 = require("./parse_expression");
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
-
var parse_variable = function parse_variable(token, pos, parent) {
|
|
11
|
-
pos++;
|
|
12
|
-
var obj = new _Variable["default"](token);
|
|
13
|
-
var next_tok = compiler.tokens[pos];
|
|
14
|
-
if (next_tok.type === "operator") {
|
|
15
|
-
if (next_tok.value === "=") {
|
|
16
|
-
pos++;
|
|
17
|
-
var _parse_expression = (0, _parse_expression3.parse_expression)(compiler.tokens.slice(pos), obj),
|
|
18
|
-
obj_ = _parse_expression.obj,
|
|
19
|
-
pos_ = _parse_expression.pos;
|
|
20
|
-
pos = pos_;
|
|
21
|
-
obj.assign(obj_);
|
|
22
|
-
} else {
|
|
23
|
-
// Its an expression
|
|
24
|
-
|
|
25
|
-
var _parse_expression2 = (0, _parse_expression3.parse_expression)(compiler.tokens.slice(pos), parent),
|
|
26
|
-
_obj_ = _parse_expression2.obj,
|
|
27
|
-
_pos_ = _parse_expression2.pos;
|
|
28
|
-
pos = _pos_;
|
|
29
|
-
obj = _obj_;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
obj: obj,
|
|
34
|
-
pos: pos
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
var _default = parse_variable;
|
|
38
|
-
exports["default"] = _default;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var tokenise = function tokenise(code, stop, compiler) {
|
|
8
|
-
var pos = 0,
|
|
9
|
-
col = 1,
|
|
10
|
-
line = 1;
|
|
11
|
-
var keywords = ["arr", "num", "str", "twain", "void", "bool", "parse"];
|
|
12
|
-
var nums = "0123456789";
|
|
13
|
-
var signs = "+-/*=<>!";
|
|
14
|
-
var tokens = new Array();
|
|
15
|
-
var var_chars = "abcdefghijklmnopqrstuvwxyzABCSEFGHUJKLMNOPQRSTUVWXYZ0123456789";
|
|
16
|
-
var separators = ";:";
|
|
17
|
-
var bools = ["False", "True"];
|
|
18
|
-
if (!code) return tokens;
|
|
19
|
-
var token_obj = function token_obj(value, type) {
|
|
20
|
-
var token = {
|
|
21
|
-
value: value,
|
|
22
|
-
type: type,
|
|
23
|
-
pos: pos,
|
|
24
|
-
col: col,
|
|
25
|
-
line: line,
|
|
26
|
-
compiler: compiler
|
|
27
|
-
};
|
|
28
|
-
tokens.push(token);
|
|
29
|
-
return token;
|
|
30
|
-
};
|
|
31
|
-
while (pos < code.length) {
|
|
32
|
-
var curr_char = code[pos];
|
|
33
|
-
if (curr_char === stop) break;
|
|
34
|
-
if (!curr_char) pos++;else if (curr_char === ",") {
|
|
35
|
-
token_obj(curr_char, "separator");
|
|
36
|
-
pos++;
|
|
37
|
-
col++;
|
|
38
|
-
} else if (separators.includes(curr_char)) {
|
|
39
|
-
token_obj(curr_char, "separator");
|
|
40
|
-
pos++;
|
|
41
|
-
col++;
|
|
42
|
-
} else if (signs.includes(curr_char)) {
|
|
43
|
-
var acc = curr_char;
|
|
44
|
-
pos++;
|
|
45
|
-
col++;
|
|
46
|
-
curr_char = code[pos];
|
|
47
|
-
if (curr_char === "=") {
|
|
48
|
-
acc = "".concat(acc).concat(curr_char);
|
|
49
|
-
pos++;
|
|
50
|
-
col++;
|
|
51
|
-
}
|
|
52
|
-
token_obj(acc, "operator");
|
|
53
|
-
} else if (curr_char === "\n") {
|
|
54
|
-
line++;
|
|
55
|
-
col = 1;
|
|
56
|
-
pos++;
|
|
57
|
-
} else if (curr_char === " ") {
|
|
58
|
-
pos++;
|
|
59
|
-
col++;
|
|
60
|
-
} else if ("[]{}()".includes(curr_char)) {
|
|
61
|
-
token_obj(curr_char, "params");
|
|
62
|
-
pos++;
|
|
63
|
-
col++;
|
|
64
|
-
} else if (nums.includes(curr_char)) {
|
|
65
|
-
var _acc = curr_char;
|
|
66
|
-
pos++;
|
|
67
|
-
curr_char = code[pos];
|
|
68
|
-
col++;
|
|
69
|
-
while (nums.includes(curr_char) || curr_char == "." && !_acc.includes(curr_char)) {
|
|
70
|
-
_acc = "".concat(_acc).concat(curr_char);
|
|
71
|
-
col++;
|
|
72
|
-
pos++;
|
|
73
|
-
curr_char = code[pos];
|
|
74
|
-
}
|
|
75
|
-
token_obj(_acc, "number", {
|
|
76
|
-
col: col - _acc.length
|
|
77
|
-
});
|
|
78
|
-
} else if (['"', "'"].includes(curr_char)) {
|
|
79
|
-
var _acc2 = "";
|
|
80
|
-
var opening_quote = curr_char;
|
|
81
|
-
pos++;
|
|
82
|
-
col++;
|
|
83
|
-
curr_char = code[pos];
|
|
84
|
-
while (curr_char !== opening_quote) {
|
|
85
|
-
_acc2 = "".concat(_acc2).concat(curr_char);
|
|
86
|
-
pos++;
|
|
87
|
-
col++;
|
|
88
|
-
curr_char = code[pos];
|
|
89
|
-
}
|
|
90
|
-
pos++;
|
|
91
|
-
col++;
|
|
92
|
-
token_obj(_acc2, "string", {
|
|
93
|
-
col: col - (_acc2.length + 2)
|
|
94
|
-
});
|
|
95
|
-
} else if (var_chars.includes(curr_char)) {
|
|
96
|
-
var _acc3 = curr_char;
|
|
97
|
-
pos++;
|
|
98
|
-
col++;
|
|
99
|
-
curr_char = code[pos];
|
|
100
|
-
while (var_chars.includes(curr_char)) {
|
|
101
|
-
_acc3 = "".concat(_acc3).concat(curr_char);
|
|
102
|
-
pos++;
|
|
103
|
-
col++;
|
|
104
|
-
curr_char = code[pos];
|
|
105
|
-
}
|
|
106
|
-
var type = void 0;
|
|
107
|
-
if (keywords.includes(_acc3)) {
|
|
108
|
-
type = "keyword";
|
|
109
|
-
} else if (bools.includes(_acc3)) type = "boolean";else type = "variable";
|
|
110
|
-
var token = token_obj(_acc3, type);
|
|
111
|
-
if (type === "keyword") {
|
|
112
|
-
var toks = void 0;
|
|
113
|
-
if (["arr", "twain"].includes(_acc3)) {
|
|
114
|
-
token.type = _acc3 === "arr" ? "array" : "twain";
|
|
115
|
-
pos++;
|
|
116
|
-
toks = tokenise(code.slice(pos), ")", compiler);
|
|
117
|
-
token.value = toks.tokens;
|
|
118
|
-
} else continue;
|
|
119
|
-
pos += toks.pos + 1;
|
|
120
|
-
col += toks.col;
|
|
121
|
-
line += toks.line;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// console.log(tokens);
|
|
126
|
-
|
|
127
|
-
return stop ? {
|
|
128
|
-
col: col,
|
|
129
|
-
pos: pos,
|
|
130
|
-
tokens: tokens,
|
|
131
|
-
line: line
|
|
132
|
-
} : tokens;
|
|
133
|
-
};
|
|
134
|
-
var _default = tokenise;
|
|
135
|
-
exports["default"] = _default;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.is_token_value = void 0;
|
|
7
|
-
var is_token_value = function is_token_value(token, value, type) {
|
|
8
|
-
if (!Array.isArray(value)) value = [value];
|
|
9
|
-
if (!Array.isArray(type)) type = [type];
|
|
10
|
-
if (!type.includes(token.type)) return;
|
|
11
|
-
if (!value.includes(token.value)) return;
|
|
12
|
-
return true;
|
|
13
|
-
};
|
|
14
|
-
exports.is_token_value = is_token_value;
|