porffor 0.42.4 → 0.42.5
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/assemble.js +5 -6
- package/compiler/builtins_objects.js +7 -16
- package/compiler/codegen.js +12 -3
- package/compiler/wrap.js +1 -2
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/assemble.js
CHANGED
@@ -121,20 +121,19 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
121
121
|
|
122
122
|
const nameSection = Prefs.d ? customSection('name', encodeNames(funcs)) : [];
|
123
123
|
|
124
|
-
const
|
124
|
+
const indirectFuncs = funcs.filter(x => x.indirect);
|
125
125
|
const tableSection = !funcs.table ? [] : createSection(
|
126
126
|
Section.table,
|
127
|
-
encodeVector([ [ Reftype.funcref, 0x00, ...unsignedLEB128(
|
127
|
+
encodeVector([ [ Reftype.funcref, 0x00, ...unsignedLEB128(indirectFuncs.length) ] ])
|
128
128
|
);
|
129
129
|
time('table section');
|
130
130
|
|
131
|
-
const emptyWrapperFunc = funcs.find(x => x.name === '#indirect#empty');
|
132
131
|
const elementSection = !funcs.table ? [] : createSection(
|
133
132
|
Section.element,
|
134
133
|
encodeVector([ [
|
135
134
|
0x00,
|
136
135
|
Opcodes.i32_const, 0, Opcodes.end,
|
137
|
-
...encodeVector(
|
136
|
+
...encodeVector(indirectFuncs.map(x => unsignedLEB128(x.asmIndex)))
|
138
137
|
] ])
|
139
138
|
);
|
140
139
|
time('element section');
|
@@ -147,8 +146,8 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
147
146
|
|
148
147
|
// generate func lut data
|
149
148
|
const bytes = [];
|
150
|
-
for (let i = 0; i <
|
151
|
-
const func =
|
149
|
+
for (let i = 0; i < indirectFuncs.length; i++) {
|
150
|
+
const func = indirectFuncs[i].wrapperOf;
|
152
151
|
let name = func.name;
|
153
152
|
|
154
153
|
// userland exposed .length
|
@@ -18,14 +18,14 @@ export default function({ builtinFuncs }, Prefs) {
|
|
18
18
|
locals: [],
|
19
19
|
returns: [ Valtype.i32 ],
|
20
20
|
returnType: TYPES.object,
|
21
|
-
wasm: (scope, { allocPage, makeString, generate, getNodeType, builtin, glbl }) => {
|
21
|
+
wasm: (scope, { allocPage, makeString, generate, getNodeType, builtin, funcRef, glbl }) => {
|
22
22
|
if (globalThis.precompile) return [ [ 'get object', name ] ];
|
23
23
|
|
24
24
|
// todo/perf: precompute bytes here instead of calling real funcs if we really care about perf later
|
25
25
|
|
26
26
|
let ptr;
|
27
27
|
if (existingFunc) {
|
28
|
-
ptr =
|
28
|
+
ptr = funcRef(name)[0][1];
|
29
29
|
} else {
|
30
30
|
ptr = allocPage(scope, `builtin object: ${name}`);
|
31
31
|
}
|
@@ -86,20 +86,11 @@ export default function({ builtinFuncs }, Prefs) {
|
|
86
86
|
}
|
87
87
|
};
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
];
|
95
|
-
this[name].type = TYPES.function;
|
96
|
-
} else {
|
97
|
-
this[name] = (scope, { builtin }) => [
|
98
|
-
[ Opcodes.call, builtin('#get_' + name) ],
|
99
|
-
Opcodes.i32_from_u
|
100
|
-
];
|
101
|
-
this[name].type = TYPES.object;
|
102
|
-
}
|
89
|
+
this[name] = (scope, { builtin }) => [
|
90
|
+
[ Opcodes.call, builtin('#get_' + name) ],
|
91
|
+
Opcodes.i32_from_u
|
92
|
+
];
|
93
|
+
this[name].type = existingFunc ? TYPES.function : TYPES.object;
|
103
94
|
|
104
95
|
for (const x in props) {
|
105
96
|
const d = props[x];
|
package/compiler/codegen.js
CHANGED
@@ -79,7 +79,12 @@ const funcRef = func => {
|
|
79
79
|
],
|
80
80
|
constr: true,
|
81
81
|
internal: true,
|
82
|
-
indirect: true
|
82
|
+
indirect: true,
|
83
|
+
wrapperOf: {
|
84
|
+
name: '',
|
85
|
+
jsLength: 0
|
86
|
+
},
|
87
|
+
indirectIndex: indirectFuncs.length
|
83
88
|
};
|
84
89
|
|
85
90
|
// check not being constructed
|
@@ -91,6 +96,8 @@ const funcRef = func => {
|
|
91
96
|
[ Opcodes.end ]
|
92
97
|
);
|
93
98
|
|
99
|
+
// have empty func as indirect funcs 0 and 1
|
100
|
+
indirectFuncs.push(emptyFunc);
|
94
101
|
indirectFuncs.push(emptyFunc);
|
95
102
|
}
|
96
103
|
|
@@ -142,7 +149,9 @@ const funcRef = func => {
|
|
142
149
|
wasm,
|
143
150
|
constr: true,
|
144
151
|
internal: true,
|
145
|
-
indirect: true
|
152
|
+
indirect: true,
|
153
|
+
wrapperOf: func,
|
154
|
+
indirectIndex: indirectFuncs.length
|
146
155
|
};
|
147
156
|
|
148
157
|
indirectFuncs.push(wrapperFunc);
|
@@ -163,7 +172,7 @@ const funcRef = func => {
|
|
163
172
|
}
|
164
173
|
|
165
174
|
return [
|
166
|
-
[ Opcodes.const, func.
|
175
|
+
[ Opcodes.const, func.wrapperFunc.indirectIndex ]
|
167
176
|
];
|
168
177
|
};
|
169
178
|
|
package/compiler/wrap.js
CHANGED
@@ -132,8 +132,7 @@ ${flags & 0b0001 ? ` get func idx: ${get}
|
|
132
132
|
if (value < 0) {
|
133
133
|
func = importedFuncs[value + importedFuncs.length];
|
134
134
|
} else {
|
135
|
-
|
136
|
-
func = funcs.find(x => x.index === value);
|
135
|
+
func = funcs.find(x => x.wrapperFunc?.indirectIndex === value);
|
137
136
|
}
|
138
137
|
|
139
138
|
if (!func) return function () {};
|
package/package.json
CHANGED