porffor 0.20.6 → 0.20.8
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/compiler/builtins/_internal_object.ts +131 -0
- package/compiler/builtins/console.ts +1 -1
- package/compiler/builtins/error.js +2 -2
- package/compiler/builtins/object.ts +107 -13
- package/compiler/builtins/set.ts +1 -15
- package/compiler/builtins/weakref.ts +1 -1
- package/compiler/builtins/z_ecma262.ts +6 -5
- package/compiler/builtins/z_map.ts +2 -4
- package/compiler/builtins/z_weakmap.ts +3 -5
- package/compiler/builtins/z_weakset.ts +2 -5
- package/compiler/builtins.js +16 -16
- package/compiler/codegen.js +305 -285
- package/compiler/generated_builtins.js +725 -694
- package/compiler/precompile.js +13 -1
- package/compiler/types.js +32 -17
- package/compiler/wrap.js +23 -9
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/precompile.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Opcodes } from './wasmSpec.js';
|
1
|
+
import { Opcodes, Valtype } from './wasmSpec.js';
|
2
2
|
import { read_unsignedLEB128 } from './encoding.js';
|
3
3
|
import { TYPES } from './types.js';
|
4
4
|
|
@@ -41,6 +41,15 @@ const compile = async (file, _funcs) => {
|
|
41
41
|
return acc;
|
42
42
|
}, {});
|
43
43
|
|
44
|
+
const returnOverrides = {
|
45
|
+
__Porffor_object_get: [ Valtype.f64, Valtype.i32 ],
|
46
|
+
__Porffor_object_set: [ Valtype.f64, Valtype.i32 ]
|
47
|
+
};
|
48
|
+
|
49
|
+
const paramOverrides = {
|
50
|
+
__Porffor_object_set: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32 ],
|
51
|
+
};
|
52
|
+
|
44
53
|
const main = funcs.find(x => x.name === 'main');
|
45
54
|
const exports = funcs.filter(x => x.export && x.name !== 'main');
|
46
55
|
for (const x of exports) {
|
@@ -59,6 +68,9 @@ const compile = async (file, _funcs) => {
|
|
59
68
|
}).filter(x => x);
|
60
69
|
}
|
61
70
|
|
71
|
+
if (returnOverrides[x.name]) x.returns = returnOverrides[x.name];
|
72
|
+
if (paramOverrides[x.name]) x.params = paramOverrides[x.name];
|
73
|
+
|
62
74
|
const rewriteWasm = (x, wasm, rewriteLocals = false) => {
|
63
75
|
const locals = Object.keys(x.locals).reduce((acc, y) => {
|
64
76
|
acc[x.locals[y].idx] = { ...x.locals[y], name: y };
|
package/compiler/types.js
CHANGED
@@ -1,26 +1,22 @@
|
|
1
|
-
|
2
|
-
empty: 0x00,
|
3
|
-
number: 0x01,
|
4
|
-
boolean: 0x02,
|
5
|
-
string: 0x03,
|
6
|
-
undefined: 0x04,
|
7
|
-
object: 0x05,
|
8
|
-
function: 0x06,
|
9
|
-
symbol: 0x07,
|
10
|
-
bigint: 0x08
|
11
|
-
};
|
1
|
+
import Prefs from './prefs.js';
|
12
2
|
|
13
|
-
// flags
|
14
3
|
export const TYPE_FLAGS = {
|
15
|
-
// iterable: 0b10000000,
|
16
4
|
parity: 0b10000000,
|
17
5
|
length: 0b01000000,
|
18
6
|
};
|
19
7
|
|
20
|
-
|
21
|
-
|
8
|
+
export const TYPES = {
|
9
|
+
empty: 0x00,
|
10
|
+
number: 0x01,
|
11
|
+
boolean: 0x02,
|
12
|
+
string: 0x03 | TYPE_FLAGS.length,
|
13
|
+
bigint: 0x04,
|
14
|
+
symbol: 0x05,
|
15
|
+
function: 0x06,
|
16
|
+
object: 0x07,
|
22
17
|
|
23
|
-
|
18
|
+
undefined: 0x00 | TYPE_FLAGS.parity,
|
19
|
+
};
|
24
20
|
|
25
21
|
export const TYPE_NAMES = {
|
26
22
|
[TYPES.empty]: 'empty',
|
@@ -74,4 +70,23 @@ registerInternalType('Float64Array', ['iterable', 'length']);
|
|
74
70
|
|
75
71
|
registerInternalType('WeakRef');
|
76
72
|
registerInternalType('WeakSet');
|
77
|
-
registerInternalType('WeakMap');
|
73
|
+
registerInternalType('WeakMap');
|
74
|
+
|
75
|
+
if (Prefs.largestTypes) {
|
76
|
+
const typeKeys = Object.keys(TYPES);
|
77
|
+
const typeVals = Object.values(TYPES);
|
78
|
+
|
79
|
+
const largestType = (vals, keys) => {
|
80
|
+
const val = Math.max(...vals);
|
81
|
+
const key = keys[vals.indexOf(val)];
|
82
|
+
return [ val, key ];
|
83
|
+
};
|
84
|
+
|
85
|
+
const unflag = val => val & 0b00111111;
|
86
|
+
|
87
|
+
const logType = (label, val, key) => console.log(`${label} ${key} - ${val} (0x${val.toString(16)}, 0b${val.toString(2).padStart(8, '0')})`);
|
88
|
+
|
89
|
+
logType(`largest type: `, ...largestType(typeVals.map(unflag), typeKeys));
|
90
|
+
logType(`largest type w/ flags:`, ...largestType(typeVals, typeKeys));
|
91
|
+
console.log();
|
92
|
+
}
|
package/compiler/wrap.js
CHANGED
@@ -45,23 +45,37 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
|
|
45
45
|
case TYPES.object: {
|
46
46
|
if (value === 0 || checkOOB(memory, value)) return null;
|
47
47
|
|
48
|
-
const
|
49
|
-
if (checkOOB(memory, keysPtr) || checkOOB(memory, valsPtr)) return null;
|
50
|
-
|
51
|
-
const size = read(Uint32Array, memory, keysPtr, 1);
|
48
|
+
const size = read(Uint32Array, memory, value, 1)[0];
|
52
49
|
|
53
50
|
const out = {};
|
54
51
|
for (let i = 0; i < size; i++) {
|
55
|
-
const offset = 4 + (i *
|
52
|
+
const offset = 4 + (i * 14);
|
56
53
|
|
57
|
-
const
|
58
|
-
const kType =
|
54
|
+
const kRaw = read(Uint32Array, memory, value + offset, 1)[0];
|
55
|
+
const kType = kRaw >>> 31 ? TYPES.string : TYPES.bytestring;
|
56
|
+
const kValue = kRaw & 0x7fffffff;
|
59
57
|
const k = porfToJSValue({ memory, funcs, pages }, kValue, kType);
|
60
58
|
|
61
|
-
const
|
62
|
-
|
59
|
+
const tail = read(Uint16Array, memory, value + offset + 12, 1)[0];
|
60
|
+
|
61
|
+
const vValue = read(Float64Array, memory, value + offset + 4, 1)[0];
|
62
|
+
const vType = tail >>> 8;
|
63
63
|
const v = porfToJSValue({ memory, funcs, pages }, vValue, vType);
|
64
64
|
|
65
|
+
const flags = tail & 0xff;
|
66
|
+
|
67
|
+
if (Prefs.d) {
|
68
|
+
console.log(`\x1b[4m\x1b[1m${k}\x1b[0m \x1B[90m(${TYPE_NAMES[kType]})\x1B[0m
|
69
|
+
value: \x1B[92m${v}\x1B[0m \x1B[90m(${TYPE_NAMES[vType]})\x1B[0m
|
70
|
+
flags: 0b\x1B[93m${flags.toString(2)}\x1B[0m\x1B[90m
|
71
|
+
accessor: ${!!(flags & 0b0001)}
|
72
|
+
configurable: ${!!(flags & 0b0010)}
|
73
|
+
enumerable: ${!!(flags & 0b0100)}
|
74
|
+
writable: ${!!(flags & 0b1000)}
|
75
|
+
\x1B[0m`);
|
76
|
+
}
|
77
|
+
|
78
|
+
// todo: use object.defineproperty
|
65
79
|
out[k] = v;
|
66
80
|
}
|
67
81
|
|
package/package.json
CHANGED