porffor 0.16.0-8107e135a → 0.16.0-97bb4f33b

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/index.js CHANGED
@@ -27,10 +27,7 @@ const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs'))
27
27
  const execSync = (typeof process?.version !== 'undefined' ? (await import('node:child_process')).execSync : undefined);
28
28
 
29
29
  export default (code, flags) => {
30
- let target = Prefs.target ?? 'wasm';
31
- if (Prefs.native) target = 'native';
32
-
33
- let outFile = Prefs.o;
30
+ const target = Prefs.target ?? 'wasm';
34
31
 
35
32
  globalThis.valtype = 'f64';
36
33
  const valtypeOpt = process.argv.find(x => x.startsWith('--valtype='));
@@ -116,6 +113,8 @@ export default (code, flags) => {
116
113
 
117
114
  const out = { wasm, funcs, globals, tags, exceptions, pages, data };
118
115
 
116
+ const outFile = Prefs.o;
117
+
119
118
  if (target === 'wasm' && outFile) {
120
119
  fs.writeFileSync(outFile, Buffer.from(wasm));
121
120
 
@@ -136,8 +135,6 @@ export default (code, flags) => {
136
135
  }
137
136
 
138
137
  if (target === 'native') {
139
- outFile ??= Prefs.native ? './porffor_tmp' : file.split('/').at(-1).split('.').at(0, -1).join('.');
140
-
141
138
  let compiler = Prefs.compiler ?? 'clang';
142
139
  const cO = Prefs._cO ?? 'Ofast';
143
140
 
@@ -156,29 +153,7 @@ export default (code, flags) => {
156
153
 
157
154
  fs.unlinkSync(tmpfile);
158
155
 
159
- if (process.version) {
160
- if (Prefs.native) {
161
- const cleanup = () => {
162
- try {
163
- fs.unlinkSync(outFile);
164
- } catch {}
165
- };
166
-
167
- process.on('exit', cleanup);
168
- process.on('beforeExit', cleanup);
169
- process.on('SIGINT', () => {
170
- cleanup();
171
- process.exit();
172
- });
173
-
174
- const runArgs = process.argv.slice(2).filter(x => !x.startsWith('-'));
175
- try {
176
- execSync([ outFile, ...runArgs.slice(1) ].join(' '), { stdio: 'inherit' });
177
- } catch {}
178
- }
179
-
180
- process.exit();
181
- }
156
+ if (process.version) process.exit();
182
157
  }
183
158
 
184
159
  return out;
package/compiler/opt.js CHANGED
@@ -125,8 +125,6 @@ export default (funcs, globals, pages, tags, exceptions) => {
125
125
  // main pass
126
126
  for (let i = 0; i < wasm.length; i++) {
127
127
  let inst = wasm[i];
128
- inst = [ ...inst ];
129
- wasm[i] = inst;
130
128
 
131
129
  if (inst[0] === Opcodes.if || inst[0] === Opcodes.loop || inst[0] === Opcodes.block) depth.push(inst[0]);
132
130
  if (inst[0] === Opcodes.end) depth.pop();
@@ -174,14 +172,14 @@ export default (funcs, globals, pages, tags, exceptions) => {
174
172
  }
175
173
  }
176
174
 
177
- if (inst[inst.length - 1] === 'string_only' && !pages.hasAnyString && Prefs.rmUnusedTypes) {
175
+ if (inst[inst.length - 1] === 'string_only' && !pages.hasAnyString && !Prefs.noRmUnusedTypes) {
178
176
  // remove this inst
179
177
  wasm.splice(i, 1);
180
178
  if (i > 0) i--;
181
179
  inst = wasm[i];
182
180
  }
183
181
 
184
- if (inst[inst.length - 1] === 'string_only|start' && !pages.hasAnyString && Prefs.rmUnusedTypes) {
182
+ if (inst[inst.length - 1] === 'string_only|start' && !pages.hasAnyString&& !Prefs.noRmUnusedTypes) {
185
183
  let j = i;
186
184
  for (; j < wasm.length; j++) {
187
185
  const op = wasm[j];
@@ -195,7 +193,7 @@ export default (funcs, globals, pages, tags, exceptions) => {
195
193
  inst = wasm[i];
196
194
  }
197
195
 
198
- if (inst[0] === Opcodes.if && typeof inst[2] === 'string' && Prefs.rmUnusedTypes) {
196
+ if (inst[0] === Opcodes.if && typeof inst[2] === 'string' && !Prefs.noRmUnusedTypes) {
199
197
  // remove unneeded typeswitch checks
200
198
 
201
199
  const type = inst[2].split('|')[1];
@@ -223,7 +221,7 @@ export default (funcs, globals, pages, tags, exceptions) => {
223
221
  }
224
222
  }
225
223
 
226
- if (inst[0] === Opcodes.end && inst[1] === 'TYPESWITCH_end' && Prefs.rmUnusedTypes) {
224
+ if (inst[0] === Opcodes.end && inst[1] === 'TYPESWITCH_end') {
227
225
  // remove unneeded entire typeswitch
228
226
 
229
227
  let j = i - 1, depth = -1, checks = 0;
@@ -371,7 +369,7 @@ export default (funcs, globals, pages, tags, exceptions) => {
371
369
  continue;
372
370
  }
373
371
 
374
- if (lastInst[0] === Opcodes.i32_const && (inst[0] === Opcodes.i32_from[0] || inst[0] === Opcodes.i32_from_u[0])) {
372
+ if (lastInst[0] === Opcodes.i32_const && (inst === Opcodes.i32_from || inst === Opcodes.i32_from_u)) {
375
373
  // change i32 const and immediate convert to const (opposite way of previous)
376
374
  // i32.const 0
377
375
  // f64.convert_i32_s || f64.convert_i32_u
package/compiler/parse.js CHANGED
@@ -43,7 +43,7 @@ export default (input, flags) => {
43
43
  webcompat: true,
44
44
 
45
45
  // babel
46
- plugins: types || flags.includes('typed') ? ['estree', 'typescript'] : ['estree'],
46
+ plugins: types ? ['estree', 'typescript'] : ['estree'],
47
47
 
48
48
  // multiple
49
49
  sourceType: flags.includes('module') ? 'module' : 'script',
package/compiler/pgo.js CHANGED
@@ -11,7 +11,7 @@ export const setup = () => {
11
11
 
12
12
  // enable these prefs by default for pgo
13
13
  Prefs.typeswitchUniqueTmp = Prefs.typeswitchUniqueTmp === false ? false : true;
14
- Prefs.cyclone = Prefs.cyclone === false ? false : true;
14
+ Prefs.cyclone = Prefs.cyclone === false ? false : true;;
15
15
  };
16
16
 
17
17
  export const run = obj => {
@@ -87,10 +87,9 @@ export const run = obj => {
87
87
  localData[activeFunc][i].push(n);
88
88
  },
89
89
  w: (ind, outPtr) => { // readArgv
90
- const pgoInd = process.argv.indexOf('--pgo');
91
- const args = process.argv.slice(pgoInd).filter(x => !x.startsWith('-'));
90
+ const args = process.argv.slice(process.argv.indexOf('--pgo')).filter(x => !x.startsWith('-'));
92
91
  const str = args[ind - 1];
93
- if (pgoInd === -1 || !str) {
92
+ if (!str) {
94
93
  if (Prefs.pgoLog) console.log('\nPGO warning: script was expecting arguments, please specify args to use for PGO after --pgo arg');
95
94
  return -1;
96
95
  }
@@ -131,18 +130,16 @@ export const run = obj => {
131
130
  func.localValues = localValues;
132
131
 
133
132
  let counts = new Array(10).fill(0);
134
- const consistents = localData[i].map((x, j) => {
135
- if (j < func.params.length) return false; // param
136
- if (x.length === 0 || !x.every((y, i) => i < 1 ? true : y === x[i - 1])) return false; // not consistent
133
+ const consistents = localData[i].map(x => {
134
+ if (x.length === 0 || !x.every((y, i) => i < 1 ? true : y === x[i - 1])) return false;
137
135
 
138
136
  counts[0]++;
139
137
  return x[0];
140
138
  });
141
139
 
142
140
  const integerOnlyF64s = localData[i].map((x, j) => {
143
- if (j < func.params.length) return false; // param
144
141
  if (localValues[j].type === Valtype.i32) return false; // already i32
145
- if (x.length === 0 || !x.every(y => Number.isInteger(y))) return false; // not all integer values
142
+ if (x.length === 0 || !x.every(y => Number.isInteger(y))) return false;
146
143
 
147
144
  counts[1]++;
148
145
  return true;
@@ -153,14 +150,14 @@ export const run = obj => {
153
150
 
154
151
  log += ` ${func.name}: identified ${counts[0]}/${total} locals as consistent${Prefs.verbosePgo ? ':' : ''}\n`;
155
152
  if (Prefs.verbosePgo) {
156
- for (let j = func.params.length; j < localData[i].length; j++) {
153
+ for (let j = 0; j < localData[i].length; j++) {
157
154
  log += ` ${consistents[j] !== false ? '\u001b[92m' : '\u001b[91m'}${localKeys[j]}\u001b[0m: ${new Set(localData[i][j]).size} unique values set\n`;
158
155
  }
159
156
  }
160
157
 
161
158
  log += ` ${func.name}: identified ${counts[1]}/${localValues.reduce((acc, x) => acc + (x.type === Valtype.f64 ? 1 : 0), 0)} f64 locals as integer usage only${Prefs.verbosePgo ? ':' : ''}\n`;
162
159
  if (Prefs.verbosePgo) {
163
- for (let j = func.params.length; j < localData[i].length; j++) {
160
+ for (let j = 0; j < localData[i].length; j++) {
164
161
  if (localValues[j].type !== Valtype.f64) continue;
165
162
  log += ` ${integerOnlyF64s[j] ? '\u001b[92m' : '\u001b[91m'}${localKeys[j]}\u001b[0m\n`;
166
163
  }
@@ -180,6 +177,7 @@ export const run = obj => {
180
177
  for (let i = 0; i < x.integerOnlyF64s.length; i++) {
181
178
  const c = x.integerOnlyF64s[i];
182
179
  if (c === false) continue;
180
+ if (i < x.params.length) continue;
183
181
 
184
182
  targets.push(i);
185
183
  }
@@ -192,6 +190,7 @@ export const run = obj => {
192
190
  for (let i = 0; i < x.consistents.length; i++) {
193
191
  const c = x.consistents[i];
194
192
  if (c === false) continue;
193
+ if (i < x.params.length) continue;
195
194
 
196
195
  targets.push(i);
197
196
 
@@ -26,7 +26,7 @@ const compile = async (file, [ _funcs, _globals ]) => {
26
26
 
27
27
  const porfCompile = (await import(`./index.js?_=${Date.now()}`)).default;
28
28
 
29
- let { funcs, globals, data, exceptions } = porfCompile(source, ['module', 'typed']);
29
+ let { funcs, globals, data, exceptions } = porfCompile(source, ['module']);
30
30
 
31
31
  const allocated = new Set();
32
32
 
@@ -35,17 +35,14 @@ const compile = async (file, [ _funcs, _globals ]) => {
35
35
  if (x.data) {
36
36
  x.data = x.data.map(x => data[x]);
37
37
  for (const y in x.data) {
38
- if (x.data[y].offset != null) x.data[y].offset -= x.data[0].offset;
38
+ x.data[y].offset -= x.data[0].offset;
39
39
  }
40
40
  }
41
-
42
- if (x.exceptions) {
43
- x.exceptions = x.exceptions.map(x => {
44
- const obj = exceptions[x];
45
- if (obj) obj.exceptId = x;
46
- return obj;
47
- }).filter(x => x);
48
- }
41
+ if (x.exceptions) x.exceptions = x.exceptions.map(x => {
42
+ const obj = exceptions[x];
43
+ if (obj) obj.exceptId = x;
44
+ return obj;
45
+ }).filter(x => x);
49
46
 
50
47
  const locals = Object.keys(x.locals).reduce((acc, y) => {
51
48
  acc[x.locals[y].idx] = { ...x.locals[y], name: y };
@@ -90,8 +87,6 @@ const compile = async (file, [ _funcs, _globals ]) => {
90
87
  };
91
88
 
92
89
  const precompile = async () => {
93
- if (globalThis._porf_loadParser) await globalThis._porf_loadParser('@babel/parser');
94
-
95
90
  const dir = join(__dirname, 'builtins');
96
91
 
97
92
  let funcs = [], globals = [];
package/compiler/prefs.js CHANGED
@@ -1,4 +1,4 @@
1
- const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'rmUnusedTypes' ];
1
+ const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused' ];
2
2
 
3
3
  let cache = {};
4
4
  const obj = new Proxy({}, {
@@ -1,5 +1,6 @@
1
1
  import { Opcodes, Blocktype, Valtype, ValtypeSize } from './wasmSpec.js';
2
2
  import { number } from './embedding.js';
3
+ import { unsignedLEB128 } from './encoding.js';
3
4
  import { UNDEFINED } from './builtins.js';
4
5
  import { TYPES } from './types.js';
5
6
  import Prefs from './prefs.js';
@@ -54,10 +55,10 @@ export const PrototypeFuncs = function() {
54
55
 
55
56
  // read from memory
56
57
  [ Opcodes.local_get, iTmp ],
57
- [ Opcodes.load, 0, ValtypeSize.i32 ],
58
+ [ Opcodes.load, 0, ...unsignedLEB128(ValtypeSize.i32) ],
58
59
 
59
60
  [ Opcodes.local_get, iTmp ],
60
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
61
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(ValtypeSize.i32 + ValtypeSize[valtype]) ]
61
62
  ],
62
63
 
63
64
  // todo: only for 1 argument
@@ -73,12 +74,12 @@ export const PrototypeFuncs = function() {
73
74
  // store value
74
75
  [ Opcodes.local_get, iTmp ],
75
76
  ...wNewMember,
76
- [ Opcodes.store, 0, ValtypeSize.i32 ],
77
+ [ Opcodes.store, 0, ...unsignedLEB128(ValtypeSize.i32) ],
77
78
 
78
79
  // store type
79
80
  [ Opcodes.local_get, iTmp ],
80
81
  ...wType,
81
- [ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
82
+ [ Opcodes.i32_store8, 0, ...unsignedLEB128(ValtypeSize.i32 + ValtypeSize[valtype]) ],
82
83
 
83
84
  // bump array length by 1 and return it
84
85
  ...length.setI32([
@@ -136,10 +137,10 @@ export const PrototypeFuncs = function() {
136
137
  [ Opcodes.local_set, iTmp ],
137
138
 
138
139
  [ Opcodes.local_get, iTmp ],
139
- [ Opcodes.load, 0, ValtypeSize.i32 ],
140
+ [ Opcodes.load, 0, ...unsignedLEB128(ValtypeSize.i32) ],
140
141
 
141
142
  [ Opcodes.local_get, iTmp ],
142
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
143
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(ValtypeSize.i32 + ValtypeSize[valtype]) ]
143
144
  ])
144
145
  ],
145
146
 
@@ -167,10 +168,10 @@ export const PrototypeFuncs = function() {
167
168
  // load first element
168
169
  // todo/perf: unusedValue opt
169
170
  ...pointer,
170
- [ Opcodes.load, 0, ValtypeSize.i32 ],
171
+ [ Opcodes.load, 0, ...unsignedLEB128(ValtypeSize.i32) ],
171
172
 
172
173
  ...pointer,
173
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
174
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(ValtypeSize.i32 + ValtypeSize[valtype]) ],
174
175
 
175
176
  // offset page by -1 ind
176
177
  // ...number(pointer + ValtypeSize.i32, Valtype.i32), // dst = base array index + length size
@@ -249,12 +250,12 @@ export const PrototypeFuncs = function() {
249
250
  // store value
250
251
  [ Opcodes.local_get, iTmp2 ],
251
252
  [ Opcodes.local_get, iTmp ],
252
- [ Opcodes.store, 0, ValtypeSize.i32 ],
253
+ [ Opcodes.store, 0, ...unsignedLEB128(ValtypeSize.i32) ],
253
254
 
254
255
  // store type
255
256
  [ Opcodes.local_get, iTmp2 ],
256
257
  ...wType,
257
- [ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
258
+ [ Opcodes.i32_store8, 0, ...unsignedLEB128(ValtypeSize.i32 + ValtypeSize[valtype]) ],
258
259
 
259
260
  // pointer - sizeof value
260
261
  ...length.getCachedI32(),
@@ -291,8 +292,11 @@ export const PrototypeFuncs = function() {
291
292
  const [ newOut, newPointer ] = arrayShell(1, 'i16');
292
293
 
293
294
  return [
294
- // setup new/out array and use pointer for store
295
+ // setup new/out array
295
296
  ...newOut,
297
+ [ Opcodes.drop ],
298
+
299
+ ...number(0, Valtype.i32), // base 0 for store later
296
300
 
297
301
  ...wIndex,
298
302
  Opcodes.i32_to_u,
@@ -331,14 +335,13 @@ export const PrototypeFuncs = function() {
331
335
  [ Opcodes.i32_add ],
332
336
 
333
337
  // load current string ind {arg}
334
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
338
+ [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(ValtypeSize.i32) ],
335
339
 
336
340
  // store to new string ind 0
337
- [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
341
+ [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(newPointer + ValtypeSize.i32) ],
338
342
 
339
343
  // return new string (pointer)
340
- ...newPointer,
341
- Opcodes.i32_from_u
344
+ ...number(newPointer)
342
345
  ];
343
346
  },
344
347
 
@@ -347,8 +350,11 @@ export const PrototypeFuncs = function() {
347
350
  const [ newOut, newPointer ] = arrayShell(1, 'i16');
348
351
 
349
352
  return [
350
- // setup new/out array and use as pointer for store
353
+ // setup new/out array
351
354
  ...newOut,
355
+ [ Opcodes.drop ],
356
+
357
+ ...number(0, Valtype.i32), // base 0 for store later
352
358
 
353
359
  ...wIndex,
354
360
  Opcodes.i32_to,
@@ -360,14 +366,13 @@ export const PrototypeFuncs = function() {
360
366
  [ Opcodes.i32_add ],
361
367
 
362
368
  // load current string ind {arg}
363
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
369
+ [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(ValtypeSize.i32) ],
364
370
 
365
371
  // store to new string ind 0
366
- [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
372
+ [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(newPointer + ValtypeSize.i32) ],
367
373
 
368
374
  // return new string (page)
369
- ...newPointer,
370
- Opcodes.i32_from_u
375
+ ...number(newPointer)
371
376
  ];
372
377
  },
373
378
 
@@ -406,7 +411,7 @@ export const PrototypeFuncs = function() {
406
411
  [ Opcodes.i32_add ],
407
412
 
408
413
  // load current string ind {arg}
409
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
414
+ [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(ValtypeSize.i32) ],
410
415
  Opcodes.i32_from_u
411
416
  ],
412
417
 
@@ -428,7 +433,7 @@ export const PrototypeFuncs = function() {
428
433
  [ Opcodes.block, Blocktype.void ],
429
434
 
430
435
  [ Opcodes.local_get, iTmp ],
431
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
436
+ [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(ValtypeSize.i32) ],
432
437
  [ Opcodes.local_set, iTmp2 ],
433
438
 
434
439
  // if not surrogate, continue
@@ -450,7 +455,7 @@ export const PrototypeFuncs = function() {
450
455
 
451
456
  // if not followed by trailing surrogate, return false
452
457
  [ Opcodes.local_get, iTmp ],
453
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 + ValtypeSize.i16 ],
458
+ [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(ValtypeSize.i32 + ValtypeSize.i16) ],
454
459
  ...number(0xFC00, Valtype.i32),
455
460
  [ Opcodes.i32_and ],
456
461
  ...number(0xDC00, Valtype.i32),
@@ -502,8 +507,11 @@ export const PrototypeFuncs = function() {
502
507
  const [ newOut, newPointer ] = arrayShell(1, 'i8');
503
508
 
504
509
  return [
505
- // setup new/out array and use pointer for store later
510
+ // setup new/out array
506
511
  ...newOut,
512
+ [ Opcodes.drop ],
513
+
514
+ ...number(0, Valtype.i32), // base 0 for store later
507
515
 
508
516
  ...wIndex,
509
517
  Opcodes.i32_to_u,
@@ -540,14 +548,13 @@ export const PrototypeFuncs = function() {
540
548
  [ Opcodes.i32_add ],
541
549
 
542
550
  // load current string ind {arg}
543
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
551
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(ValtypeSize.i32) ],
544
552
 
545
553
  // store to new string ind 0
546
- [ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
554
+ [ Opcodes.i32_store8, 0, ...unsignedLEB128(newPointer + ValtypeSize.i32) ],
547
555
 
548
556
  // return new string (pointer)
549
- ...newPointer,
550
- Opcodes.i32_from_u
557
+ ...number(newPointer)
551
558
  ];
552
559
  },
553
560
 
@@ -556,8 +563,11 @@ export const PrototypeFuncs = function() {
556
563
  const [ newOut, newPointer ] = arrayShell(1, 'i8');
557
564
 
558
565
  return [
559
- // setup new/out array and use pointer for later
566
+ // setup new/out array
560
567
  ...newOut,
568
+ [ Opcodes.drop ],
569
+
570
+ ...number(0, Valtype.i32), // base 0 for store later
561
571
 
562
572
  ...wIndex,
563
573
  Opcodes.i32_to,
@@ -566,14 +576,13 @@ export const PrototypeFuncs = function() {
566
576
  [ Opcodes.i32_add ],
567
577
 
568
578
  // load current string ind {arg}
569
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
579
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(ValtypeSize.i32) ],
570
580
 
571
581
  // store to new string ind 0
572
- [ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
582
+ [ Opcodes.i32_store8, 0, ...unsignedLEB128(newPointer + ValtypeSize.i32) ],
573
583
 
574
584
  // return new string (page)
575
- ...newPointer,
576
- Opcodes.i32_from_u
585
+ ...number(newPointer)
577
586
  ];
578
587
  },
579
588
 
@@ -609,7 +618,7 @@ export const PrototypeFuncs = function() {
609
618
  [ Opcodes.i32_add ],
610
619
 
611
620
  // load current string ind {arg}
612
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
621
+ [ Opcodes.i32_load8_u, 0, ...unsignedLEB128(ValtypeSize.i32) ],
613
622
  Opcodes.i32_from_u
614
623
  ],
615
624
 
@@ -191,8 +191,6 @@ export const Opcodes = {
191
191
  i32_trunc_sat_f64_s: [ 0xfc, 0x02 ],
192
192
  i32_trunc_sat_f64_u: [ 0xfc, 0x03 ],
193
193
 
194
- memory_init: [ 0xfc, 0x08 ],
195
- data_drop: [ 0xfc, 0x09 ],
196
194
  memory_copy: [ 0xfc, 0x0a ],
197
195
 
198
196
  // simd insts are 0xFD simdop: varuint32
@@ -211,6 +209,8 @@ export const Opcodes = {
211
209
  i32x4_add: [ 0xfd, 0xae, 0x01 ],
212
210
  i32x4_sub: [ 0xfd, 0xb1, 0x01 ],
213
211
  i32x4_mul: [ 0xfd, 0xb5, 0x01 ],
212
+
213
+ i32x4_dot_i16x8_s: [ 0xfd, 0xba, 0x01 ],
214
214
  };
215
215
 
216
216
  export const FuncType = 0x60;
package/compiler/wrap.js CHANGED
@@ -104,14 +104,13 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
104
104
 
105
105
  case TYPES.symbol: {
106
106
  const descStore = pages.get('bytestring: __Porffor_symbol_descStore/ptr').ind * pageSize;
107
- if (!descStore) return Symbol();
108
-
109
107
  const offset = descStore + 4 + ((value - 1) * 9);
110
108
 
111
109
  const v = (new Float64Array(memory.buffer.slice(offset, offset + 8), 0, 1))[0];
112
110
  const t = (new Uint8Array(memory.buffer, offset + 8, 1))[0];
113
111
 
114
112
  const desc = porfToJSValue({ memory, funcs, pages }, v, t);
113
+
115
114
  return Symbol(desc);
116
115
  }
117
116
 
@@ -129,7 +128,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
129
128
 
130
129
  if (source.includes?.('export ')) flags.push('module');
131
130
 
132
- // fs.writeFileSync('out.wasm', Buffer.from(wasm));
131
+ fs.writeFileSync('out.wasm', Buffer.from(wasm));
133
132
 
134
133
  times.push(performance.now() - t1);
135
134
  if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));