porffor 0.17.0-f43ba190c → 0.18.3
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/README.md +10 -9
- package/bf +0 -0
- package/compiler/2c.js +98 -15
- package/compiler/assemble.js +19 -4
- package/compiler/builtins/array.ts +102 -9
- package/compiler/builtins/date.ts +104 -106
- package/compiler/builtins/error.js +2 -5
- package/compiler/builtins/set.ts +4 -5
- package/compiler/builtins/string_f64.ts +4 -6
- package/compiler/builtins/symbol.ts +2 -1
- package/compiler/builtins/typedarray.js +58 -6
- package/compiler/builtins/z_ecma262.ts +1 -0
- package/compiler/builtins.js +13 -2
- package/compiler/codegen.js +486 -127
- package/compiler/cyclone.js +36 -0
- package/compiler/decompile.js +2 -2
- package/compiler/generated_builtins.js +2714 -713
- package/compiler/index.js +1 -0
- package/compiler/opt.js +3 -5
- package/compiler/precompile.js +4 -2
- package/compiler/prototype.js +0 -69
- package/package.json +1 -1
- package/rhemyn/README.md +7 -4
- package/rhemyn/compile.js +170 -76
- package/runner/index.js +3 -2
- package/runner/repl.js +1 -2
- package/runner/version.js +0 -12
package/compiler/cyclone.js
CHANGED
@@ -66,6 +66,42 @@ export default wasm => {
|
|
66
66
|
};
|
67
67
|
|
68
68
|
switch (opcode) {
|
69
|
+
case Opcodes.if: {
|
70
|
+
if (stack.length < 1) { empty(); break; }
|
71
|
+
const cond = bool(pop());
|
72
|
+
|
73
|
+
// find else split and end
|
74
|
+
let j = i + 1;
|
75
|
+
let depth = 0, elseStart = 0;
|
76
|
+
for (; j < wasm.length; j++) {
|
77
|
+
const op = wasm[j][0];
|
78
|
+
if (op === Opcodes.if || op === Opcodes.block || op === Opcodes.loop || op === Opcodes.try) depth++;
|
79
|
+
if (op === Opcodes.else && depth === 0) elseStart = j;
|
80
|
+
if (op === Opcodes.end) {
|
81
|
+
depth--;
|
82
|
+
if (depth < 0) break;
|
83
|
+
}
|
84
|
+
if (op === Opcodes.br || op === Opcodes.br_if) wasm[j][1] -= 1;
|
85
|
+
}
|
86
|
+
|
87
|
+
if (cond) {
|
88
|
+
// remove else if it exists, or just remove end
|
89
|
+
if (elseStart) wasm.splice(elseStart, j - elseStart + 1);
|
90
|
+
else wasm.splice(j, 1);
|
91
|
+
} else {
|
92
|
+
// remove truthy conseq and keep else if it exists, or just remove entire thing
|
93
|
+
if (elseStart) {
|
94
|
+
wasm.splice(j, 1); // remove end
|
95
|
+
wasm.splice(i + 1, elseStart - i + 1); // remove truthy conseq
|
96
|
+
} else wasm.splice(i + 1, j - i + 0); // no else, remove entire if
|
97
|
+
}
|
98
|
+
|
99
|
+
// remove this if op
|
100
|
+
wasm.splice(i, 1);
|
101
|
+
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
|
69
105
|
case Opcodes.i32_const: {
|
70
106
|
const n = read_signedLEB128(op.slice(1));
|
71
107
|
push(n);
|
package/compiler/decompile.js
CHANGED
@@ -70,7 +70,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
|
|
70
70
|
} else if (inst[0] === Opcodes.i32_load || inst[0] === Opcodes.i64_load || inst[0] === Opcodes.f64_load || inst[0] === Opcodes.i32_store || inst[0] === Opcodes.i64_store || inst[0] === Opcodes.f64_store || inst[0] === Opcodes.i32_store16 || inst[0] === Opcodes.i32_load16_u) {
|
71
71
|
out += ` ${inst[1]} ${read_unsignedLEB128(inst.slice(2))}`;
|
72
72
|
} else for (const operand of inst.slice(1)) {
|
73
|
-
if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block) {
|
73
|
+
if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block || inst[0] === Opcodes.try) {
|
74
74
|
if (operand === Blocktype.void) continue;
|
75
75
|
out += ` ${invValtype[operand]}`;
|
76
76
|
} else {
|
@@ -80,7 +80,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
|
|
80
80
|
|
81
81
|
if (comments.length > 0) out += ` ;; ${comments.join(' ')}`;
|
82
82
|
|
83
|
-
if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block || inst[0] === Opcodes.else) {
|
83
|
+
if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block || inst[0] === Opcodes.else || inst[0] === Opcodes.try || inst[0] === Opcodes.catch_all) {
|
84
84
|
out += ` ;; label @${depth}`;
|
85
85
|
}
|
86
86
|
|