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/2c.js +4 -4
- package/compiler/allocator.js +64 -0
- package/compiler/assemble.js +2 -2
- package/compiler/builtins/__internal_string.ts +117 -34
- package/compiler/builtins/boolean.ts +2 -5
- package/compiler/builtins/function.ts +12 -3
- package/compiler/builtins/object.ts +10 -12
- package/compiler/builtins/z_ecma262.ts +4 -6
- package/compiler/builtins.js +2 -2
- package/compiler/builtins_objects.js +2 -2
- package/compiler/builtins_precompiled.js +722 -787
- package/compiler/cache.js +44 -0
- package/compiler/codegen.js +193 -306
- package/compiler/index.js +7 -1
- package/compiler/opt.js +1 -1
- package/compiler/parse.js +1 -1
- package/compiler/pgo.js +1 -1
- package/compiler/precompile.js +15 -20
- package/compiler/prototype.js +135 -123
- package/compiler/types.js +1 -1
- package/compiler/wrap.js +5 -5
- package/package.json +1 -1
- package/rhemyn/compile.js +1 -1
- package/runner/index.js +1 -1
- package/runner/repl.js +3 -3
- package/compiler/allocators.js +0 -130
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
|
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
|
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
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
|
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';
|
package/compiler/precompile.js
CHANGED
@@ -126,30 +126,24 @@ const compile = async (file, _funcs) => {
|
|
126
126
|
|
127
127
|
if (!n) continue;
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
if (!l)
|
132
|
-
if (!
|
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))
|
135
|
+
if (!pageName || allocated.has(pageName)) return;
|
137
136
|
allocated.add(pageName);
|
138
137
|
|
139
|
-
y.splice(0, 10, 'alloc', pageName,
|
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
|
-
|
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","(.*?)",
|
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, (
|
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)
|
package/compiler/prototype.js
CHANGED
@@ -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
|
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,
|
179
|
-
|
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
|
-
|
182
|
-
|
183
|
-
|
183
|
+
// out.length = 1
|
184
|
+
[ Opcodes.local_get, iOut ],
|
185
|
+
...number(1, Valtype.i32),
|
186
|
+
[ Opcodes.i32_store, 0, 0 ],
|
184
187
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
+
...wIndex,
|
189
|
+
Opcodes.i32_to_u,
|
190
|
+
[ Opcodes.local_tee, iTmp ],
|
188
191
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
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
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
207
|
+
[ Opcodes.local_get, iTmp ],
|
208
|
+
...length.getCachedI32(),
|
209
|
+
[ Opcodes.i32_ge_s ],
|
210
|
+
[ Opcodes.i32_or ],
|
208
211
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
212
|
+
[ Opcodes.if, Blocktype.void ],
|
213
|
+
...number(UNDEFINED),
|
214
|
+
[ Opcodes.br, 1 ],
|
215
|
+
[ Opcodes.end ],
|
213
216
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
+
[ Opcodes.local_get, iTmp ],
|
218
|
+
...number(ValtypeSize.i16, Valtype.i32),
|
219
|
+
[ Opcodes.i32_mul ],
|
217
220
|
|
218
|
-
|
219
|
-
|
221
|
+
...pointer,
|
222
|
+
[ Opcodes.i32_add ],
|
220
223
|
|
221
|
-
|
222
|
-
|
224
|
+
// load current string ind {arg}
|
225
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
223
226
|
|
224
|
-
|
225
|
-
|
227
|
+
// store to new string ind 0
|
228
|
+
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
226
229
|
|
227
|
-
|
228
|
-
|
229
|
-
|
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,
|
235
|
-
|
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
|
-
|
238
|
-
|
239
|
-
|
241
|
+
// out.length = 1
|
242
|
+
[ Opcodes.local_get, iTmp ],
|
243
|
+
...number(1, Valtype.i32),
|
244
|
+
[ Opcodes.i32_store, 0, 0 ],
|
240
245
|
|
241
|
-
|
242
|
-
|
246
|
+
...wIndex,
|
247
|
+
Opcodes.i32_to,
|
243
248
|
|
244
|
-
|
245
|
-
|
249
|
+
...number(ValtypeSize.i16, Valtype.i32),
|
250
|
+
[ Opcodes.i32_mul ],
|
246
251
|
|
247
|
-
|
248
|
-
|
252
|
+
...pointer,
|
253
|
+
[ Opcodes.i32_add ],
|
249
254
|
|
250
|
-
|
251
|
-
|
255
|
+
// load current string ind {arg}
|
256
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
252
257
|
|
253
|
-
|
254
|
-
|
258
|
+
// store to new string ind 0
|
259
|
+
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
255
260
|
|
256
|
-
|
257
|
-
|
258
|
-
|
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,
|
311
|
-
|
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
|
-
|
314
|
-
|
315
|
-
|
321
|
+
// out.length = 1
|
322
|
+
[ Opcodes.local_get, iOut ],
|
323
|
+
...number(1, Valtype.i32),
|
324
|
+
[ Opcodes.i32_store, 0, 0 ],
|
316
325
|
|
317
|
-
|
318
|
-
|
319
|
-
|
326
|
+
...wIndex,
|
327
|
+
Opcodes.i32_to_u,
|
328
|
+
[ Opcodes.local_tee, iTmp ],
|
320
329
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
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
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
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
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
345
|
+
[ Opcodes.local_get, iTmp ],
|
346
|
+
...length.getCachedI32(),
|
347
|
+
[ Opcodes.i32_ge_s ],
|
348
|
+
[ Opcodes.i32_or ],
|
340
349
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
350
|
+
[ Opcodes.if, Blocktype.void ],
|
351
|
+
...number(UNDEFINED),
|
352
|
+
[ Opcodes.br, 1 ],
|
353
|
+
[ Opcodes.end ],
|
345
354
|
|
346
|
-
|
355
|
+
[ Opcodes.local_get, iTmp ],
|
347
356
|
|
348
|
-
|
349
|
-
|
357
|
+
...pointer,
|
358
|
+
[ Opcodes.i32_add ],
|
350
359
|
|
351
|
-
|
352
|
-
|
360
|
+
// load current string ind {arg}
|
361
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
|
353
362
|
|
354
|
-
|
355
|
-
|
363
|
+
// store to new string ind 0
|
364
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
|
356
365
|
|
357
|
-
|
358
|
-
|
359
|
-
|
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,
|
365
|
-
|
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
|
-
|
368
|
-
|
369
|
-
|
377
|
+
// out.length = 1
|
378
|
+
[ Opcodes.local_get, iTmp ],
|
379
|
+
...number(1, Valtype.i32),
|
380
|
+
[ Opcodes.i32_store, 0, 0 ],
|
370
381
|
|
371
|
-
|
372
|
-
|
382
|
+
...wIndex,
|
383
|
+
Opcodes.i32_to,
|
373
384
|
|
374
|
-
|
375
|
-
|
385
|
+
...pointer,
|
386
|
+
[ Opcodes.i32_add ],
|
376
387
|
|
377
|
-
|
378
|
-
|
388
|
+
// load current string ind {arg}
|
389
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
|
379
390
|
|
380
|
-
|
381
|
-
|
391
|
+
// store to new string ind 0
|
392
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
|
382
393
|
|
383
|
-
|
384
|
-
|
385
|
-
|
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
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
|
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('
|
186
|
+
const page = pages.get('symbol.ts/descStore');
|
187
187
|
if (!page) return Symbol();
|
188
188
|
|
189
|
-
const descStore = page
|
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
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
|
4
|
+
import '../compiler/prefs.js';
|
5
5
|
import { TYPES } from '../compiler/types.js';
|
6
6
|
|
7
7
|
// local indexes
|
package/runner/index.js
CHANGED
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
|
-
|
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
|
-
|
145
|
+
Prefs.optFuncs = true;
|
146
146
|
run('', null, null, () => {}, false);
|
147
|
-
|
147
|
+
Prefs.optFuncs = false;
|
148
148
|
} catch { }
|
149
149
|
|
150
150
|
this.displayPrompt();
|