porffor 0.47.6 → 0.47.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/index.js CHANGED
@@ -8,7 +8,7 @@ import decompile from './decompile.js';
8
8
  import toc from './2c.js';
9
9
  import * as pgo from './pgo.js';
10
10
  import cyclone from './cyclone.js';
11
- import {} from './prefs.js';
11
+ import './prefs.js';
12
12
  import * as Diagram from './diagram.js';
13
13
 
14
14
  globalThis.decompile = decompile;
@@ -31,6 +31,8 @@ const execSync = (typeof process?.version !== 'undefined' ? (await import('node:
31
31
  let progressLines = 0, progressInterval;
32
32
  let spinner = ['-', '\\', '|', '/'], spin = 0;
33
33
  const progressStart = msg => {
34
+ if (globalThis.onProgress) return;
35
+
34
36
  const log = (extra, after) => {
35
37
  const pre = extra ? `${extra}` : spinner[spin++ % 4];
36
38
  process.stdout.write(`\r\u001b[90m${' '.repeat(10 - pre.length)}${pre} ${msg}${after ?? ''}\u001b[0m`);
@@ -41,6 +43,8 @@ const progressStart = msg => {
41
43
  progressInterval = setInterval(log, 100);
42
44
  };
43
45
  const progressDone = (msg, start) => {
46
+ if (globalThis.onProgress) return globalThis.onProgress(msg, performance.now() - start);
47
+
44
48
  clearInterval(progressInterval);
45
49
 
46
50
  const timeStr = (performance.now() - start).toFixed(0);
@@ -48,6 +52,8 @@ const progressDone = (msg, start) => {
48
52
  progressLines++;
49
53
  };
50
54
  const progressClear = () => {
55
+ if (globalThis.onProgress) return;
56
+
51
57
  process.stdout.write(`\u001b[${progressLines}F\u001b[0J`);
52
58
  progressLines = 0;
53
59
  };
package/compiler/opt.js CHANGED
@@ -2,7 +2,7 @@ import { Opcodes, Valtype } from './wasmSpec.js';
2
2
  import { number } from './embedding.js';
3
3
  import { read_signedLEB128, read_ieee754_binary64 } from './encoding.js';
4
4
  import { log } from './log.js';
5
- import {} from './prefs.js';
5
+ import './prefs.js';
6
6
 
7
7
  export default (funcs, globals, pages, tags, exceptions) => {
8
8
  const optLevel = parseInt(process.argv.find(x => x.startsWith('-O'))?.[2] ?? 1);
package/compiler/parse.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { log } from './log.js';
2
- import {} from './prefs.js';
2
+ import './prefs.js';
3
3
 
4
4
  const file = process.argv.slice(2).find(x => x[0] !== '-' && !['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(x));
5
5
 
package/compiler/pgo.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Opcodes, Valtype } from './wasmSpec.js';
2
2
  import { number } from './embedding.js';
3
3
  import { importedFuncs } from './builtins.js';
4
- import {} from './prefs.js';
4
+ import './prefs.js';
5
5
  import assemble from './assemble.js';
6
6
  import wrap, { writeByteStr } from './wrap.js';
7
7
  import * as Havoc from './havoc.js';
@@ -126,30 +126,24 @@ const compile = async (file, _funcs) => {
126
126
 
127
127
  if (!n) continue;
128
128
 
129
- if (y[0] === Opcodes.const &&(n[0] === Opcodes.local_set || n[0] === Opcodes.local_tee)) {
130
- const l = locals[n[1]];
131
- if (!l) continue;
132
- if (!['#member_prop'].includes(l.name) && ![TYPES.string, TYPES.array, TYPES.bytestring].includes(l.metadata?.type)) continue;
133
- if (!x.pages) continue;
129
+ const alloc = l => {
130
+ if (!l) return;
131
+ if (!['#member_prop'].includes(l.name) && ![TYPES.array].includes(l.metadata?.type)) return;
132
+ if (!x.pages) return;
134
133
 
135
134
  const pageName = [...x.pages.keys()].find(z => z.endsWith(l.name));
136
- if (!pageName || allocated.has(pageName)) continue;
135
+ if (!pageName || allocated.has(pageName)) return;
137
136
  allocated.add(pageName);
138
137
 
139
- y.splice(0, 10, 'alloc', pageName, x.pages.get(pageName).type, valtypeBinary);
138
+ y.splice(0, 10, 'alloc', pageName, valtypeBinary);
139
+ };
140
+
141
+ if (y[0] === Opcodes.const &&(n[0] === Opcodes.local_set || n[0] === Opcodes.local_tee)) {
142
+ alloc(locals[n[1]]);
140
143
  }
141
144
 
142
145
  if (y[0] === Opcodes.const && n[0] === Opcodes.global_set) {
143
- const l = invGlobals[n[1]];
144
- if (!l) continue;
145
- if (![TYPES.string, TYPES.array, TYPES.bytestring].includes(l.metadata?.type)) continue;
146
- if (!x.pages) continue;
147
-
148
- const pageName = [...x.pages.keys()].find(z => z.endsWith(l.name));
149
- if (!pageName || allocated.has(pageName)) continue;
150
- allocated.add(pageName);
151
-
152
- y.splice(0, 10, 'alloc', pageName, x.pages.get(pageName).type, valtypeBinary);
146
+ alloc(invGlobals[n[1]]);
153
147
  }
154
148
 
155
149
  if (n[0] === Opcodes.throw) {
@@ -220,11 +214,12 @@ ${funcs.map(x => {
220
214
  if (Number.isNaN(v) || v === Infinity || v === -Infinity) return v.toString();
221
215
  return v;
222
216
  })
223
- .replace(/\["alloc","(.*?)","(.*?)",(.*?)\]/g, (_, reason, type, valtype) => `...number(allocPage(_,'${reason}','${type}'),${valtype})`)
217
+ .replace(/\["alloc","(.*?)",(.*?)\]/g, (_, reason, valtype) => `...number(allocPage(_,'${reason}'),${valtype})`)
224
218
  .replace(/\["global",(.*?),"(.*?)",(.*?)\]/g, (_, opcode, name, valtype) => `...glbl(${opcode},'${name}',${valtype})`)
225
219
  .replace(/\"local","(.*?)",(.*?)\]/g, (_, name, valtype) => `loc('${name}',${valtype})]`)
226
220
  .replace(/\[16,"(.*?)"]/g, (_, name) => `[16,builtin('${name}')]`)
227
- .replace(/\[68,"funcref","(.*?)"]/g, (_, name) => `...funcRef('${name}')`)
221
+ .replace(/\[(68|65),"funcref","(.*?)"]/g, (_1, op, name) => op === '65' ? `...i32ify(funcRef('${name}'))` : `...funcRef('${name}')`)
222
+ .replace(/\[(68|65),"str","(.*?)",(.*?)]/g, (_1, op, str, forceBytestring) => op === '65' ? `...i32ify(makeString(_,${JSON.stringify(str)},${forceBytestring ? 1 : 0}))` : `...makeString(_,${JSON.stringify(str)},${forceBytestring ? 1 : 0})`)
228
223
  .replace(/\["throw","(.*?)","(.*?)"\]/g, (_, constructor, message) => `...internalThrow(_,'${constructor}',\`${message}\`)`)
229
224
  .replace(/\["get object","(.*?)"\]/g, (_, objName) => `...generateIdent(_,{name:'${objName}'})`)
230
225
  .replace(/\[null,"typeswitch case start",\[(.*?)\]\],/g, (_, types) => `...t([${types}],()=>[`)
@@ -240,7 +235,7 @@ ${funcs.map(x => {
240
235
  return `[null,()=>{if(${comptimeFlagChecks[id](extra)}){const r=()=>{valtype=Prefs.valtype??'f64';valtypeBinary=Valtype[valtype];const valtypeInd=['i32','i64','f64'].indexOf(valtype);Opcodes.i32_to=[[],[Opcodes.i32_wrap_i64],Opcodes.i32_trunc_sat_f64_s][valtypeInd];Opcodes.i32_to_u=[[],[Opcodes.i32_wrap_i64],Opcodes.i32_trunc_sat_f64_u][valtypeInd];Opcodes.i32_from=[[],[Opcodes.i64_extend_i32_s],[Opcodes.f64_convert_i32_s]][valtypeInd];Opcodes.i32_from_u=[[],[Opcodes.i64_extend_i32_u],[ Opcodes.f64_convert_i32_u]][valtypeInd]};const a=Prefs;Prefs=${prefs};r();const b=generate(_,${ast});Prefs=a;r();return b;}return []}]`;
241
236
  });
242
237
 
243
- return `(_,{${str.includes('hasFunc(') ? 'hasFunc,' : ''}${str.includes('Valtype[') ? 'Valtype,' : ''}${str.includes('Opcodes.') ? 'Opcodes,' : ''}${str.includes('...t(') ? 't,' : ''}${`${str.includes('allocPage(') ? 'allocPage,' : ''}${str.includes('glbl(') ? 'glbl,' : ''}${str.includes('loc(') ? 'loc,' : ''}${str.includes('builtin(') ? 'builtin,' : ''}${str.includes('funcRef(') ? 'funcRef,' : ''}${str.includes('internalThrow(') ? 'internalThrow,' : ''}${str.includes('generateIdent(') ? 'generateIdent,' : ''}${str.includes('generate(') ? 'generate,' : ''}`.slice(0, -1)}})=>`.replace('_,{}', '') + str;
238
+ return `(_,{${str.includes('hasFunc(') ? 'hasFunc,' : ''}${str.includes('Valtype[') ? 'Valtype,' : ''}${str.includes('i32ify') ? 'i32ify,' : ''}${str.includes('Opcodes.') ? 'Opcodes,' : ''}${str.includes('...t(') ? 't,' : ''}${`${str.includes('allocPage(') ? 'allocPage,' : ''}${str.includes('makeString(') ? 'makeString,' : ''}${str.includes('glbl(') ? 'glbl,' : ''}${str.includes('loc(') ? 'loc,' : ''}${str.includes('builtin(') ? 'builtin,' : ''}${str.includes('funcRef(') ? 'funcRef,' : ''}${str.includes('internalThrow(') ? 'internalThrow,' : ''}${str.includes('generateIdent(') ? 'generateIdent,' : ''}${str.includes('generate(') ? 'generate,' : ''}`.slice(0, -1)}})=>`.replace('_,{}', '') + str;
244
239
  };
245
240
 
246
241
  const locals = Object.entries(x.locals).sort((a,b) => a[1].idx - b[1].idx)
@@ -2,7 +2,7 @@ import { Opcodes, Blocktype, Valtype, ValtypeSize } from './wasmSpec.js';
2
2
  import { number } from './embedding.js';
3
3
  import { UNDEFINED } from './builtins.js';
4
4
  import { TYPES } from './types.js';
5
- import {} from './prefs.js';
5
+ import './prefs.js';
6
6
 
7
7
  // todo: turn these into built-ins once arrays and these become less hacky
8
8
 
@@ -175,89 +175,93 @@ export const PrototypeFuncs = function() {
175
175
  this[TYPES.array].pop.local = Valtype.i32;
176
176
 
177
177
  this[TYPES.string] = {
178
- at: (pointer, length, wIndex, wType, iTmp, _, arrayShell) => {
179
- const [ newOut, newPointer ] = arrayShell(1, 'i16');
178
+ at: (pointer, length, wIndex, wType, iTmp, iOut, alloc) => [
179
+ // setup new/out array and use pointer for store
180
+ ...alloc(8),
181
+ [ Opcodes.local_tee, iOut ],
180
182
 
181
- return [
182
- // setup new/out array and use pointer for store
183
- ...newOut,
183
+ // out.length = 1
184
+ [ Opcodes.local_get, iOut ],
185
+ ...number(1, Valtype.i32),
186
+ [ Opcodes.i32_store, 0, 0 ],
184
187
 
185
- ...wIndex,
186
- Opcodes.i32_to_u,
187
- [ Opcodes.local_tee, iTmp ],
188
+ ...wIndex,
189
+ Opcodes.i32_to_u,
190
+ [ Opcodes.local_tee, iTmp ],
188
191
 
189
- // if index < 0: access index + array length
190
- ...number(0, Valtype.i32),
191
- [ Opcodes.i32_lt_s ],
192
- [ Opcodes.if, Blocktype.void ],
193
- [ Opcodes.local_get, iTmp ],
194
- ...length.getCachedI32(),
195
- [ Opcodes.i32_add ],
196
- [ Opcodes.local_set, iTmp ],
197
- [ Opcodes.end ],
192
+ // if index < 0: access index + array length
193
+ ...number(0, Valtype.i32),
194
+ [ Opcodes.i32_lt_s ],
195
+ [ Opcodes.if, Blocktype.void ],
196
+ [ Opcodes.local_get, iTmp ],
197
+ ...length.getCachedI32(),
198
+ [ Opcodes.i32_add ],
199
+ [ Opcodes.local_set, iTmp ],
200
+ [ Opcodes.end ],
198
201
 
199
- // if still < 0 or >= length: return undefined
200
- [ Opcodes.local_get, iTmp ],
201
- ...number(0, Valtype.i32),
202
- [ Opcodes.i32_lt_s ],
202
+ // if still < 0 or >= length: return undefined
203
+ [ Opcodes.local_get, iTmp ],
204
+ ...number(0, Valtype.i32),
205
+ [ Opcodes.i32_lt_s ],
203
206
 
204
- [ Opcodes.local_get, iTmp ],
205
- ...length.getCachedI32(),
206
- [ Opcodes.i32_ge_s ],
207
- [ Opcodes.i32_or ],
207
+ [ Opcodes.local_get, iTmp ],
208
+ ...length.getCachedI32(),
209
+ [ Opcodes.i32_ge_s ],
210
+ [ Opcodes.i32_or ],
208
211
 
209
- [ Opcodes.if, Blocktype.void ],
210
- ...number(UNDEFINED),
211
- [ Opcodes.br, 1 ],
212
- [ Opcodes.end ],
212
+ [ Opcodes.if, Blocktype.void ],
213
+ ...number(UNDEFINED),
214
+ [ Opcodes.br, 1 ],
215
+ [ Opcodes.end ],
213
216
 
214
- [ Opcodes.local_get, iTmp ],
215
- ...number(ValtypeSize.i16, Valtype.i32),
216
- [ Opcodes.i32_mul ],
217
+ [ Opcodes.local_get, iTmp ],
218
+ ...number(ValtypeSize.i16, Valtype.i32),
219
+ [ Opcodes.i32_mul ],
217
220
 
218
- ...pointer,
219
- [ Opcodes.i32_add ],
221
+ ...pointer,
222
+ [ Opcodes.i32_add ],
220
223
 
221
- // load current string ind {arg}
222
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
224
+ // load current string ind {arg}
225
+ [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
223
226
 
224
- // store to new string ind 0
225
- [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
227
+ // store to new string ind 0
228
+ [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
226
229
 
227
- // return new string (pointer)
228
- ...newPointer,
229
- Opcodes.i32_from_u
230
- ];
231
- },
230
+ // return new string (pointer)
231
+ [ Opcodes.local_get, iOut ],
232
+ Opcodes.i32_from_u
233
+ ],
232
234
 
233
235
  // todo: out of bounds properly
234
- charAt: (pointer, length, wIndex, wType, _1, _2, arrayShell) => {
235
- const [ newOut, newPointer ] = arrayShell(1, 'i16');
236
+ charAt: (pointer, length, wIndex, wType, iTmp, _, alloc) => [
237
+ // setup new/out array and use as pointer for store
238
+ ...alloc(8),
239
+ [ Opcodes.local_tee, iTmp ],
236
240
 
237
- return [
238
- // setup new/out array and use as pointer for store
239
- ...newOut,
241
+ // out.length = 1
242
+ [ Opcodes.local_get, iTmp ],
243
+ ...number(1, Valtype.i32),
244
+ [ Opcodes.i32_store, 0, 0 ],
240
245
 
241
- ...wIndex,
242
- Opcodes.i32_to,
246
+ ...wIndex,
247
+ Opcodes.i32_to,
243
248
 
244
- ...number(ValtypeSize.i16, Valtype.i32),
245
- [ Opcodes.i32_mul ],
249
+ ...number(ValtypeSize.i16, Valtype.i32),
250
+ [ Opcodes.i32_mul ],
246
251
 
247
- ...pointer,
248
- [ Opcodes.i32_add ],
252
+ ...pointer,
253
+ [ Opcodes.i32_add ],
249
254
 
250
- // load current string ind {arg}
251
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
255
+ // load current string ind {arg}
256
+ [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
252
257
 
253
- // store to new string ind 0
254
- [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
258
+ // store to new string ind 0
259
+ [ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
255
260
 
256
- // return new string (page)
257
- ...newPointer,
258
- Opcodes.i32_from_u
259
- ];
260
- },
261
+ // return new string (page)
262
+ [ Opcodes.local_get, iTmp ],
263
+ Opcodes.i32_from_u
264
+ ],
261
265
 
262
266
  charCodeAt: (pointer, length, wIndex, wType, iTmp) => [
263
267
  ...wIndex,
@@ -300,91 +304,97 @@ export const PrototypeFuncs = function() {
300
304
  };
301
305
 
302
306
  this[TYPES.string].at.local = Valtype.i32;
307
+ this[TYPES.string].at.local2 = Valtype.i32;
303
308
  this[TYPES.string].at.returnType = TYPES.string;
309
+ this[TYPES.string].charAt.local = Valtype.i32;
304
310
  this[TYPES.string].charAt.returnType = TYPES.string;
305
311
  this[TYPES.string].charCodeAt.returnType = TYPES.number;
306
312
  this[TYPES.string].charCodeAt.local = Valtype.i32;
307
313
  this[TYPES.string].charCodeAt.noPointerCache = zeroChecks.charcodeat;
308
314
 
309
315
  this[TYPES.bytestring] = {
310
- at: (pointer, length, wIndex, wType, iTmp, _, arrayShell) => {
311
- const [ newOut, newPointer ] = arrayShell(1, 'i8');
316
+ at: (pointer, length, wIndex, wType, iTmp, iOut, alloc) => [
317
+ // setup new/out array and use pointer for store
318
+ ...alloc(8),
319
+ [ Opcodes.local_tee, iOut ],
312
320
 
313
- return [
314
- // setup new/out array and use pointer for store later
315
- ...newOut,
321
+ // out.length = 1
322
+ [ Opcodes.local_get, iOut ],
323
+ ...number(1, Valtype.i32),
324
+ [ Opcodes.i32_store, 0, 0 ],
316
325
 
317
- ...wIndex,
318
- Opcodes.i32_to_u,
319
- [ Opcodes.local_tee, iTmp ],
326
+ ...wIndex,
327
+ Opcodes.i32_to_u,
328
+ [ Opcodes.local_tee, iTmp ],
320
329
 
321
- // if index < 0: access index + array length
322
- ...number(0, Valtype.i32),
323
- [ Opcodes.i32_lt_s ],
324
- [ Opcodes.if, Blocktype.void ],
325
- [ Opcodes.local_get, iTmp ],
326
- ...length.getCachedI32(),
327
- [ Opcodes.i32_add ],
328
- [ Opcodes.local_set, iTmp ],
329
- [ Opcodes.end ],
330
+ // if index < 0: access index + array length
331
+ ...number(0, Valtype.i32),
332
+ [ Opcodes.i32_lt_s ],
333
+ [ Opcodes.if, Blocktype.void ],
334
+ [ Opcodes.local_get, iTmp ],
335
+ ...length.getCachedI32(),
336
+ [ Opcodes.i32_add ],
337
+ [ Opcodes.local_set, iTmp ],
338
+ [ Opcodes.end ],
330
339
 
331
- // if still < 0 or >= length: return undefined
332
- [ Opcodes.local_get, iTmp ],
333
- ...number(0, Valtype.i32),
334
- [ Opcodes.i32_lt_s ],
340
+ // if still < 0 or >= length: return undefined
341
+ [ Opcodes.local_get, iTmp ],
342
+ ...number(0, Valtype.i32),
343
+ [ Opcodes.i32_lt_s ],
335
344
 
336
- [ Opcodes.local_get, iTmp ],
337
- ...length.getCachedI32(),
338
- [ Opcodes.i32_ge_s ],
339
- [ Opcodes.i32_or ],
345
+ [ Opcodes.local_get, iTmp ],
346
+ ...length.getCachedI32(),
347
+ [ Opcodes.i32_ge_s ],
348
+ [ Opcodes.i32_or ],
340
349
 
341
- [ Opcodes.if, Blocktype.void ],
342
- ...number(UNDEFINED),
343
- [ Opcodes.br, 1 ],
344
- [ Opcodes.end ],
350
+ [ Opcodes.if, Blocktype.void ],
351
+ ...number(UNDEFINED),
352
+ [ Opcodes.br, 1 ],
353
+ [ Opcodes.end ],
345
354
 
346
- [ Opcodes.local_get, iTmp ],
355
+ [ Opcodes.local_get, iTmp ],
347
356
 
348
- ...pointer,
349
- [ Opcodes.i32_add ],
357
+ ...pointer,
358
+ [ Opcodes.i32_add ],
350
359
 
351
- // load current string ind {arg}
352
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
360
+ // load current string ind {arg}
361
+ [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
353
362
 
354
- // store to new string ind 0
355
- [ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
363
+ // store to new string ind 0
364
+ [ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
356
365
 
357
- // return new string (pointer)
358
- ...newPointer,
359
- Opcodes.i32_from_u
360
- ];
361
- },
366
+ // return new string (pointer)
367
+ [ Opcodes.local_get, iOut ],
368
+ Opcodes.i32_from_u
369
+ ],
362
370
 
363
371
  // todo: out of bounds properly
364
- charAt: (pointer, length, wIndex, wType, _1, _2, arrayShell) => {
365
- const [ newOut, newPointer ] = arrayShell(1, 'i8');
372
+ charAt: (pointer, length, wIndex, wType, iTmp, _, alloc) => [
373
+ // setup new/out array and use as pointer for store
374
+ ...alloc(8),
375
+ [ Opcodes.local_tee, iTmp ],
366
376
 
367
- return [
368
- // setup new/out array and use pointer for later
369
- ...newOut,
377
+ // out.length = 1
378
+ [ Opcodes.local_get, iTmp ],
379
+ ...number(1, Valtype.i32),
380
+ [ Opcodes.i32_store, 0, 0 ],
370
381
 
371
- ...wIndex,
372
- Opcodes.i32_to,
382
+ ...wIndex,
383
+ Opcodes.i32_to,
373
384
 
374
- ...pointer,
375
- [ Opcodes.i32_add ],
385
+ ...pointer,
386
+ [ Opcodes.i32_add ],
376
387
 
377
- // load current string ind {arg}
378
- [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
388
+ // load current string ind {arg}
389
+ [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
379
390
 
380
- // store to new string ind 0
381
- [ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
391
+ // store to new string ind 0
392
+ [ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
382
393
 
383
- // return new string (page)
384
- ...newPointer,
385
- Opcodes.i32_from_u
386
- ];
387
- },
394
+ // return new string (page)
395
+ [ Opcodes.local_get, iTmp ],
396
+ Opcodes.i32_from_u
397
+ ],
388
398
 
389
399
  charCodeAt: (pointer, length, wIndex, wType, iTmp) => [
390
400
  ...wIndex,
@@ -424,7 +434,9 @@ export const PrototypeFuncs = function() {
424
434
  };
425
435
 
426
436
  this[TYPES.bytestring].at.local = Valtype.i32;
437
+ this[TYPES.bytestring].at.local2 = Valtype.i32;
427
438
  this[TYPES.bytestring].at.returnType = TYPES.bytestring;
439
+ this[TYPES.bytestring].charAt.local = Valtype.i32;
428
440
  this[TYPES.bytestring].charAt.returnType = TYPES.bytestring;
429
441
  this[TYPES.bytestring].charCodeAt.returnType = TYPES.number;
430
442
  this[TYPES.bytestring].charCodeAt.local = Valtype.i32;
package/compiler/types.js CHANGED
@@ -1,4 +1,4 @@
1
- import {} from './prefs.js';
1
+ import './prefs.js';
2
2
 
3
3
  export const TYPE_FLAGS = {
4
4
  parity: 0b10000000,
package/compiler/wrap.js CHANGED
@@ -4,7 +4,7 @@ import compile from './index.js';
4
4
  import decompile from './decompile.js';
5
5
  import { TYPES, TYPE_NAMES } from './types.js';
6
6
  import { log } from './log.js';
7
- import {} from './prefs.js';
7
+ import './prefs.js';
8
8
 
9
9
  const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs')) : undefined);
10
10
 
@@ -183,10 +183,10 @@ ${flags & 0b0001 ? ` get func idx: ${get}
183
183
  }
184
184
 
185
185
  case TYPES.symbol: {
186
- const page = pages.get('array: symbol.ts/descStore');
186
+ const page = pages.get('symbol.ts/descStore');
187
187
  if (!page) return Symbol();
188
188
 
189
- const descStore = page.ind * pageSize;
189
+ const descStore = page * pageSize;
190
190
  const offset = descStore + 4 + ((value - 1) * 9);
191
191
 
192
192
  const v = read(Float64Array, memory, offset, 1)[0];
@@ -352,7 +352,7 @@ export default (source, module = undefined, customImports = {}, print = str => p
352
352
  // fs.writeFileSync('out.wasm', Buffer.from(wasm));
353
353
 
354
354
  times.push(performance.now() - t1);
355
- if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
355
+ if (Prefs.profileCompiler && !globalThis.onProgress) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
356
356
 
357
357
  const printDecomp = (middleIndex, func, funcs, globals, exceptions) => {
358
358
  console.log(`\x1B[35m\x1B[1mporffor backtrace\u001b[0m`);
@@ -489,7 +489,7 @@ export default (source, module = undefined, customImports = {}, print = str => p
489
489
  }
490
490
 
491
491
  times.push(performance.now() - t2);
492
- if (Prefs.profileCompiler) console.log(`instantiated in ${times[1].toFixed(2)}ms`);
492
+ if (Prefs.profileCompiler && !globalThis.onProgress) console.log(`instantiated in ${times[1].toFixed(2)}ms`);
493
493
 
494
494
  const exports = {};
495
495
  const rawValues = Prefs.d;
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.47.6",
4
+ "version": "0.47.8",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/rhemyn/compile.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Blocktype, Opcodes, Valtype, ValtypeSize } from '../compiler/wasmSpec.js';
2
2
  import { number } from '../compiler/embedding.js';
3
3
  import parse from './parse.js';
4
- import {} from '../compiler/prefs.js';
4
+ import '../compiler/prefs.js';
5
5
  import { TYPES } from '../compiler/types.js';
6
6
 
7
7
  // local indexes
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.47.6';
3
+ globalThis.version = '0.47.8';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
package/runner/repl.js CHANGED
@@ -4,7 +4,7 @@ import parse from '../compiler/parse.js';
4
4
 
5
5
  import util from 'node:util';
6
6
 
7
- process.argv.push('--no-opt-unused');
7
+ Prefs.optUnused = false;
8
8
 
9
9
  let repl;
10
10
  try {
@@ -142,9 +142,9 @@ replServer.defineCommand('asm', {
142
142
  this.clearBufferedCommand();
143
143
 
144
144
  try {
145
- process.argv.push('--opt-funcs');
145
+ Prefs.optFuncs = true;
146
146
  run('', null, null, () => {}, false);
147
- process.argv.pop();
147
+ Prefs.optFuncs = false;
148
148
  } catch { }
149
149
 
150
150
  this.displayPrompt();