porffor 0.34.0 → 0.34.1
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/2c.js +5 -3
- package/compiler/assemble.js +26 -26
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/2c.js
CHANGED
@@ -217,12 +217,14 @@ export default ({ funcs, globals, tags, data, exceptions, pages }) => {
|
|
217
217
|
if (Prefs['2cMemcpy']) includes.set('string.h', true);
|
218
218
|
}
|
219
219
|
|
220
|
-
|
220
|
+
const activeData = data.filter(x => x.page != null);
|
221
|
+
if (activeData.length > 0) {
|
222
|
+
const dataOffset = x => pages.get(x.page).ind * pageSize;
|
221
223
|
if (Prefs['2cMemcpy']) {
|
222
|
-
prependMain.set('_data',
|
224
|
+
prependMain.set('_data', activeData.map(x => `memcpy(_memory + ${dataOffset(x)}, (unsigned char[]){${x.bytes.join(',')}}, ${x.bytes.length});`).join('\n '));
|
223
225
|
includes.set('string.h', true);
|
224
226
|
} else {
|
225
|
-
prependMain.set('_data',
|
227
|
+
prependMain.set('_data', activeData.map(x => x.bytes.reduce((acc, y, i) => acc + `_memory[${dataOffset(x) + i}]=(u8)${y};`, '')).join('\n '));
|
226
228
|
}
|
227
229
|
}
|
228
230
|
|
package/compiler/assemble.js
CHANGED
@@ -99,32 +99,9 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
99
99
|
// also fix call_indirect types
|
100
100
|
// also encode call indexes
|
101
101
|
for (const f of funcs) {
|
102
|
-
f.originalIndex
|
103
|
-
|
104
|
-
|
105
|
-
for (const inst of f.wasm) {
|
106
|
-
if ((inst[0] === Opcodes.call || inst[0] === Opcodes.return_call) && inst[1] >= importedFuncs.length) {
|
107
|
-
const idx = inst[1] - importDelta;
|
108
|
-
inst.pop(); // remove idx
|
109
|
-
unsignedLEB128_into(idx, inst); // add unsigned leb128 encoded index to inst
|
110
|
-
}
|
111
|
-
|
112
|
-
if (inst[0] === Opcodes.call_indirect) {
|
113
|
-
if (!funcs.table) funcs.table = true;
|
114
|
-
|
115
|
-
const params = [];
|
116
|
-
for (let i = 0; i < inst[1]; i++) {
|
117
|
-
params.push(valtypeBinary, Valtype.i32);
|
118
|
-
}
|
119
|
-
|
120
|
-
let returns = [ valtypeBinary, Valtype.i32 ];
|
121
|
-
if (inst.at(-1) === 'no_type_return') {
|
122
|
-
inst.pop();
|
123
|
-
returns = [ valtypeBinary ];
|
124
|
-
}
|
125
|
-
|
126
|
-
inst[1] = getType(params, returns);
|
127
|
-
}
|
102
|
+
if (f.originalIndex == null) {
|
103
|
+
f.originalIndex = f.index;
|
104
|
+
f.index -= importDelta;
|
128
105
|
}
|
129
106
|
}
|
130
107
|
|
@@ -333,6 +310,29 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
333
310
|
ieee754_binary64_into(n, o);
|
334
311
|
}
|
335
312
|
|
313
|
+
if ((o[0] === Opcodes.call || o[0] === Opcodes.return_call) && o[1] >= importedFuncs.length) {
|
314
|
+
const n = o[1] - importDelta;
|
315
|
+
o = [...o];
|
316
|
+
o.pop();
|
317
|
+
unsignedLEB128_into(n, o);
|
318
|
+
}
|
319
|
+
|
320
|
+
if (o[0] === Opcodes.call_indirect) {
|
321
|
+
o = [...o];
|
322
|
+
const params = [];
|
323
|
+
for (let i = 0; i < o[1]; i++) {
|
324
|
+
params.push(valtypeBinary, Valtype.i32);
|
325
|
+
}
|
326
|
+
|
327
|
+
let returns = [ valtypeBinary, Valtype.i32 ];
|
328
|
+
if (o.at(-1) === 'no_type_return') {
|
329
|
+
o.pop();
|
330
|
+
returns = [ valtypeBinary ];
|
331
|
+
}
|
332
|
+
|
333
|
+
o[1] = getType(params, returns);
|
334
|
+
}
|
335
|
+
|
336
336
|
for (let j = 0; j < o.length; j++) {
|
337
337
|
const x = o[j];
|
338
338
|
if (x == null || !(x <= 0xff)) continue;
|
package/package.json
CHANGED