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 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
- if (data.length > 0) {
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', data.map(x => `memcpy(_memory + ${x.offset}, (unsigned char[]){${x.bytes.join(',')}}, ${x.bytes.length});`).join('\n '));
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', data.map(x => x.bytes.reduce((acc, y, i) => acc + `_memory[${x.offset + i}]=(u8)${y};`, '')).join('\n '));
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
 
@@ -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 = f.index;
103
- f.index -= importDelta;
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.34.0+947ac1287",
4
+ "version": "0.34.1+a499f0fdc",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.34.0+947ac1287';
3
+ globalThis.version = '0.34.1+a499f0fdc';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {