porffor 0.58.18 → 0.59.0
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/AGENT.md +22 -0
- package/compiler/assemble.js +2 -13
- package/compiler/builtins/array.ts +48 -0
- package/compiler/builtins/regexp.ts +61 -14
- package/compiler/builtins/string.ts +70 -42
- package/compiler/builtins/string_f64.ts +116 -0
- package/compiler/builtins.js +30 -37
- package/compiler/builtins_precompiled.js +617 -557
- package/compiler/codegen.js +65 -111
- package/compiler/pgo.js +21 -43
- package/compiler/precompile.js +1 -1
- package/compiler/wrap.js +3 -8
- package/fuzz/index.js +1 -1
- package/package.json +1 -1
- package/runtime/debug.js +1 -1
- package/runtime/index.js +1 -1
- package/runtime/profile.js +1 -1
- package/runtime/repl.js +1 -1
- package/compiler/prototype.js +0 -407
package/compiler/codegen.js
CHANGED
@@ -2,7 +2,6 @@ import { Blocktype, Opcodes, Valtype, ValtypeSize } from './wasmSpec.js';
|
|
2
2
|
import { number, ieee754_binary64, signedLEB128, unsignedLEB128, encodeVector, read_signedLEB128 } from './encoding.js';
|
3
3
|
import { operatorOpcode } from './expression.js';
|
4
4
|
import { BuiltinFuncs, BuiltinVars, importedFuncs, NULL, UNDEFINED } from './builtins.js';
|
5
|
-
import { PrototypeFuncs } from './prototype.js';
|
6
5
|
import { TYPES, TYPE_FLAGS, TYPE_NAMES } from './types.js';
|
7
6
|
import parse from './parse.js';
|
8
7
|
import { log } from './log.js';
|
@@ -556,7 +555,7 @@ const lookup = (scope, name, failEarly = false) => {
|
|
556
555
|
includeBuiltin(scope, name);
|
557
556
|
}
|
558
557
|
|
559
|
-
if (
|
558
|
+
if (Object.hasOwn(internalConstrs, name)) {
|
560
559
|
// todo: return an actual something
|
561
560
|
return [ number(1) ];
|
562
561
|
}
|
@@ -1506,6 +1505,7 @@ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTy
|
|
1506
1505
|
typeUsed(func, returnType);
|
1507
1506
|
}
|
1508
1507
|
|
1508
|
+
func.jsLength = countLength(func);
|
1509
1509
|
func.wasm = wasm;
|
1510
1510
|
return func;
|
1511
1511
|
};
|
@@ -1520,13 +1520,6 @@ const includeBuiltin = (scope, builtin) => {
|
|
1520
1520
|
const generateLogicExp = (scope, decl) =>
|
1521
1521
|
performLogicOp(scope, decl.operator, generate(scope, decl.left), generate(scope, decl.right), getNodeType(scope, decl.left), getNodeType(scope, decl.right));
|
1522
1522
|
|
1523
|
-
const isExistingProtoFunc = name => {
|
1524
|
-
if (name.startsWith('__Array_prototype')) return Object.hasOwn(prototypeFuncs[TYPES.array], name.slice(18));
|
1525
|
-
if (name.startsWith('__String_prototype_')) return Object.hasOwn(prototypeFuncs[TYPES.string], name.slice(19));
|
1526
|
-
|
1527
|
-
return false;
|
1528
|
-
};
|
1529
|
-
|
1530
1523
|
const getInferred = (scope, name, global = false) => {
|
1531
1524
|
if (global) {
|
1532
1525
|
if (globalInfer.has(name) && inferLoopPrev.length === 0) return globalInfer.get(name);
|
@@ -1595,7 +1588,7 @@ const getType = (scope, name, failEarly = false) => {
|
|
1595
1588
|
[ global ? Opcodes.global_get : Opcodes.local_get, typeLocal.idx ]
|
1596
1589
|
];
|
1597
1590
|
|
1598
|
-
if (hasFuncWithName(name)
|
1591
|
+
if (hasFuncWithName(name)) {
|
1599
1592
|
return [ number(TYPES.function, Valtype.i32) ];
|
1600
1593
|
}
|
1601
1594
|
|
@@ -1830,6 +1823,12 @@ const getNodeType = (scope, node) => {
|
|
1830
1823
|
case '__Porffor_bs': return TYPES.bytestring;
|
1831
1824
|
case '__Porffor_s': return TYPES.string;
|
1832
1825
|
}
|
1826
|
+
|
1827
|
+
return getNodeType(scope, {
|
1828
|
+
type: 'CallExpression',
|
1829
|
+
callee: node.tag,
|
1830
|
+
arguments: []
|
1831
|
+
});
|
1833
1832
|
}
|
1834
1833
|
|
1835
1834
|
if (node.type === 'ThisExpression') {
|
@@ -2294,9 +2293,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2294
2293
|
});
|
2295
2294
|
}
|
2296
2295
|
|
2297
|
-
const protoBC = {};
|
2298
2296
|
const builtinProtoCands = Object.keys(builtinFuncs).filter(x => x.startsWith('__') && x.endsWith('_prototype_' + protoName));
|
2299
|
-
|
2300
2297
|
if (!decl._protoInternalCall && builtinProtoCands.length > 0) {
|
2301
2298
|
out.push(
|
2302
2299
|
...generate(scope, target),
|
@@ -2315,6 +2312,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2315
2312
|
);
|
2316
2313
|
}
|
2317
2314
|
|
2315
|
+
const protoBC = {};
|
2318
2316
|
for (const x of builtinProtoCands) {
|
2319
2317
|
const name = x.split('_prototype_')[0].toLowerCase();
|
2320
2318
|
const type = TYPES[name.slice(2)] ?? TYPES[name];
|
@@ -2338,88 +2336,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2338
2336
|
_protoInternalCall: true
|
2339
2337
|
});
|
2340
2338
|
}
|
2341
|
-
}
|
2342
|
-
|
2343
|
-
const protoCands = Object.keys(prototypeFuncs).reduce((acc, x) => {
|
2344
|
-
if (Object.hasOwn(prototypeFuncs[x], protoName)) acc[x] = prototypeFuncs[x][protoName];
|
2345
|
-
return acc;
|
2346
|
-
}, {});
|
2347
|
-
|
2348
|
-
if (Object.keys(protoCands).length > 0) {
|
2349
|
-
// use local for cached i32 length as commonly used
|
2350
|
-
const lengthLocal = localTmp(scope, '__proto_length_cache', Valtype.i32);
|
2351
|
-
const pointerLocal = localTmp(scope, '__proto_pointer_cache', Valtype.i32);
|
2352
|
-
|
2353
|
-
if (out.length === 0) {
|
2354
|
-
out.push(
|
2355
|
-
...generate(scope, target),
|
2356
|
-
Opcodes.i32_to_u,
|
2357
|
-
[ Opcodes.local_set, pointerLocal ]
|
2358
|
-
);
|
2359
|
-
} else {
|
2360
|
-
out.push(
|
2361
|
-
[ Opcodes.local_get, localTmp(scope, '#proto_target') ],
|
2362
|
-
Opcodes.i32_to_u,
|
2363
|
-
[ Opcodes.local_set, pointerLocal ]
|
2364
|
-
);
|
2365
|
-
}
|
2366
|
-
|
2367
|
-
for (const x in protoCands) {
|
2368
|
-
const protoFunc = protoCands[x];
|
2369
|
-
const getPointer = [ [ Opcodes.local_get, pointerLocal ] ];
|
2370
|
-
|
2371
|
-
if (protoFunc.noArgRetLength && decl.arguments.length === 0) {
|
2372
|
-
protoBC[x] = [
|
2373
|
-
...ArrayUtil.getLength(getPointer),
|
2374
|
-
...setLastType(scope, TYPES.number)
|
2375
|
-
];
|
2376
|
-
continue;
|
2377
|
-
}
|
2378
|
-
|
2379
|
-
protoBC[x] = () => {
|
2380
|
-
const protoLocal = protoFunc.local ? localTmp(scope, `__${protoName}_tmp`, protoFunc.local) : -1;
|
2381
|
-
const protoLocal2 = protoFunc.local2 ? localTmp(scope, `__${protoName}_tmp2`, protoFunc.local2) : -1;
|
2382
|
-
|
2383
|
-
let optUnused = false;
|
2384
|
-
const protoOut = protoFunc({
|
2385
|
-
pointer: getPointer,
|
2386
|
-
length: {
|
2387
|
-
getCachedI32: () => [ [ Opcodes.local_get, lengthLocal ] ],
|
2388
|
-
setCachedI32: () => [ [ Opcodes.local_set, lengthLocal ] ],
|
2389
|
-
get: () => ArrayUtil.getLength(getPointer),
|
2390
|
-
getI32: () => ArrayUtil.getLengthI32(getPointer),
|
2391
|
-
set: value => ArrayUtil.setLength(getPointer, value),
|
2392
|
-
setI32: value => ArrayUtil.setLengthI32(getPointer, value)
|
2393
|
-
},
|
2394
|
-
arg: generate(scope, decl.arguments[0] ?? DEFAULT_VALUE()),
|
2395
|
-
argType: getNodeType(scope, decl.arguments[0] ?? DEFAULT_VALUE()),
|
2396
|
-
iTmp: protoLocal,
|
2397
|
-
iTmp2: protoLocal2,
|
2398
|
-
alloc: bytes => [
|
2399
|
-
number(bytes, Valtype.i32),
|
2400
|
-
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocateBytes').index ]
|
2401
|
-
],
|
2402
|
-
unusedValue: () => {
|
2403
|
-
optUnused = true;
|
2404
|
-
return unusedValue;
|
2405
|
-
},
|
2406
|
-
setType: type => setLastType(scope, type)
|
2407
|
-
});
|
2408
|
-
|
2409
|
-
return [
|
2410
|
-
...ArrayUtil.getLengthI32(getPointer),
|
2411
|
-
[ Opcodes.local_set, lengthLocal ],
|
2412
|
-
|
2413
|
-
[ Opcodes.block, unusedValue && optUnused ? Blocktype.void : valtypeBinary ],
|
2414
|
-
...protoOut,
|
2415
|
-
[ Opcodes.end ],
|
2416
|
-
...(unusedValue && optUnused ? [ number(UNDEFINED) ] : [])
|
2417
|
-
];
|
2418
|
-
};
|
2419
|
-
}
|
2420
|
-
}
|
2421
2339
|
|
2422
|
-
if (Object.keys(protoBC).length > 0) {
|
2423
2340
|
protoBC.default = decl.optional ?
|
2424
2341
|
withType(scope, [ number(UNDEFINED) ], TYPES.undefined) :
|
2425
2342
|
internalThrow(scope, 'TypeError', `'${protoName}' proto func tried to be called on a type without an impl`, true);
|
@@ -5850,7 +5767,24 @@ const countLength = (func, name = undefined) => {
|
|
5850
5767
|
|
5851
5768
|
let count = countParams(func, name);
|
5852
5769
|
if (builtinFuncs[name] && name.includes('_prototype_')) count--;
|
5853
|
-
|
5770
|
+
if (func.hasRestArgument) count--;
|
5771
|
+
|
5772
|
+
if (func.internal) {
|
5773
|
+
// some js built-ins have an old non-standard length
|
5774
|
+
const override = ({
|
5775
|
+
Array: 1,
|
5776
|
+
String: 1,
|
5777
|
+
__Object_assign: 2,
|
5778
|
+
__String_fromCharCode: 1,
|
5779
|
+
__String_fromCodePoint: 1,
|
5780
|
+
__Array_prototype_concat: 1,
|
5781
|
+
__Array_prototype_push: 1,
|
5782
|
+
__Array_prototype_unshift: 1,
|
5783
|
+
__String_prototype_concat: 1,
|
5784
|
+
__ByteString_prototype_concat: 1
|
5785
|
+
})[name];
|
5786
|
+
if (override != null) return override;
|
5787
|
+
}
|
5854
5788
|
return count;
|
5855
5789
|
};
|
5856
5790
|
|
@@ -6671,20 +6605,41 @@ const generateTaggedTemplate = (scope, decl, global = false, name = undefined, v
|
|
6671
6605
|
return cacheAst(decl, intrinsics[decl.tag.name](str));
|
6672
6606
|
}
|
6673
6607
|
|
6674
|
-
|
6675
|
-
|
6676
|
-
|
6677
|
-
|
6678
|
-
|
6679
|
-
|
6680
|
-
|
6681
|
-
|
6682
|
-
|
6683
|
-
|
6684
|
-
|
6685
|
-
|
6686
|
-
|
6687
|
-
|
6608
|
+
const tmp = localTmp(scope, '#tagged_template_strings');
|
6609
|
+
const tmpIdent = {
|
6610
|
+
type: 'Identifier',
|
6611
|
+
name: '#tagged_template_strings',
|
6612
|
+
_type: TYPES.array
|
6613
|
+
};
|
6614
|
+
|
6615
|
+
return [
|
6616
|
+
...generate(scope, {
|
6617
|
+
type: 'ArrayExpression',
|
6618
|
+
elements: quasis.map(x => ({
|
6619
|
+
type: 'Literal',
|
6620
|
+
value: x.value.cooked
|
6621
|
+
}))
|
6622
|
+
}),
|
6623
|
+
[ Opcodes.local_set, tmp ],
|
6624
|
+
|
6625
|
+
...generate(scope, setObjProp(tmpIdent, 'raw', {
|
6626
|
+
type: 'ArrayExpression',
|
6627
|
+
elements: quasis.map(x => ({
|
6628
|
+
type: 'Literal',
|
6629
|
+
value: x.value.raw
|
6630
|
+
}))
|
6631
|
+
})),
|
6632
|
+
[ Opcodes.drop ],
|
6633
|
+
|
6634
|
+
...generate(scope, {
|
6635
|
+
type: 'CallExpression',
|
6636
|
+
callee: decl.tag,
|
6637
|
+
arguments: [
|
6638
|
+
tmpIdent,
|
6639
|
+
...expressions
|
6640
|
+
]
|
6641
|
+
})
|
6642
|
+
];
|
6688
6643
|
};
|
6689
6644
|
|
6690
6645
|
globalThis._uniqId = 0;
|
@@ -6717,7 +6672,7 @@ const objectHack = node => {
|
|
6717
6672
|
if (objectName !== 'Object_prototype' && (node.property.name === 'propertyIsEnumerable' || node.property.name === 'hasOwnProperty' || node.property.name === 'isPrototypeOf')) return abortOut;
|
6718
6673
|
|
6719
6674
|
const name = '__' + objectName + '_' + node.property.name;
|
6720
|
-
if ((!hasFuncWithName(name) && !Object.hasOwn(builtinVars, name) && !
|
6675
|
+
if ((!hasFuncWithName(name) && !Object.hasOwn(builtinVars, name) && !hasFuncWithName(name + '$get')) && (hasFuncWithName(objectName) || Object.hasOwn(builtinVars, objectName) || hasFuncWithName('__' + objectName) || Object.hasOwn(builtinVars, '__' + objectName))) return abortOut;
|
6721
6676
|
|
6722
6677
|
if (Prefs.codeLog) log('codegen', `object hack! ${node.object.name}.${node.property.name} -> ${name}`);
|
6723
6678
|
|
@@ -7294,7 +7249,7 @@ const internalConstrs = {
|
|
7294
7249
|
}
|
7295
7250
|
};
|
7296
7251
|
|
7297
|
-
let globals, tags, exceptions, funcs, indirectFuncs, funcIndex, currentFuncIndex, depth, pages, data, typeswitchDepth, usedTypes, coctc, globalInfer, builtinFuncs, builtinVars,
|
7252
|
+
let globals, tags, exceptions, funcs, indirectFuncs, funcIndex, currentFuncIndex, depth, pages, data, typeswitchDepth, usedTypes, coctc, globalInfer, builtinFuncs, builtinVars, lastValtype;
|
7298
7253
|
export default program => {
|
7299
7254
|
globals = { ['#ind']: 0 };
|
7300
7255
|
tags = [];
|
@@ -7333,7 +7288,6 @@ export default program => {
|
|
7333
7288
|
lastValtype = valtypeBinary;
|
7334
7289
|
builtinFuncs = new BuiltinFuncs();
|
7335
7290
|
builtinVars = new BuiltinVars({ builtinFuncs });
|
7336
|
-
prototypeFuncs = new PrototypeFuncs();
|
7337
7291
|
|
7338
7292
|
const getObjectName = x => x.startsWith('__') && x.slice(2, x.indexOf('_', 2));
|
7339
7293
|
objectHackers = ['assert', 'compareArray', 'Test262Error', ...new Set(Object.keys(builtinFuncs).map(getObjectName).concat(Object.keys(builtinVars).map(getObjectName)).filter(x => x))];
|
package/compiler/pgo.js
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
import { Opcodes, Valtype } from './wasmSpec.js';
|
2
2
|
import { number } from './encoding.js';
|
3
|
-
import { createImport, importedFuncs } from './builtins.js';
|
3
|
+
import { createImport, importedFuncs, setImports } from './builtins.js';
|
4
4
|
import assemble from './assemble.js';
|
5
5
|
import wrap from './wrap.js';
|
6
6
|
import * as Havoc from './havoc.js';
|
7
7
|
import './prefs.js';
|
8
|
+
import fs from 'node:fs';
|
8
9
|
|
10
|
+
let activeFunc, localData;
|
9
11
|
export const setup = () => {
|
10
12
|
// enable these prefs by default for pgo
|
11
13
|
for (const x of [
|
12
14
|
'typeswitchUniqueTmp', // use unique tmps for typeswitches
|
13
|
-
'
|
14
|
-
'cyclone', // enable cyclone pre-evaler
|
15
|
+
// 'cyclone', // enable cyclone pre-evaler
|
15
16
|
]) {
|
16
17
|
Prefs[x] = Prefs[x] === false ? false : true;
|
17
18
|
}
|
19
|
+
|
20
|
+
createImport('profileLocalSet', [ Valtype.i32, Valtype.i32, Valtype.f64 ], 0, (activeFunc, i, n) => {
|
21
|
+
if (activeFunc == null) throw 'fail';
|
22
|
+
localData[activeFunc][i].push(n);
|
23
|
+
});
|
18
24
|
};
|
19
25
|
|
20
26
|
export const run = obj => {
|
@@ -34,15 +40,7 @@ export const run = obj => {
|
|
34
40
|
|
35
41
|
time(0, `injecting PGO logging...`);
|
36
42
|
|
37
|
-
let
|
38
|
-
createImport('profile1', [ Valtype.i32 ], 0, n => {
|
39
|
-
activeFunc = n;
|
40
|
-
});
|
41
|
-
createImport('profile2', [ Valtype.i32, Valtype.f64 ], 0, (i, n) => {
|
42
|
-
if (activeFunc == null) throw 'fail';
|
43
|
-
localData[activeFunc][i].push(n);
|
44
|
-
});
|
45
|
-
|
43
|
+
let abort = false;
|
46
44
|
let funcs = [];
|
47
45
|
for (let i = 0; i < wasmFuncs.length; i++) {
|
48
46
|
const { name, internal, params, locals, wasm } = wasmFuncs[i];
|
@@ -55,16 +53,13 @@ export const run = obj => {
|
|
55
53
|
funcs.push({ name, id, locals, params, invLocals });
|
56
54
|
|
57
55
|
wasm.unshift(
|
58
|
-
// mark active func
|
59
|
-
number(i, Valtype.i32),
|
60
|
-
[ Opcodes.call, importedFuncs.profile1 ],
|
61
|
-
|
62
56
|
// log args
|
63
57
|
...params.flatMap((_, i) => [
|
58
|
+
number(id, Valtype.i32),
|
64
59
|
number(i, Valtype.i32),
|
65
60
|
[ Opcodes.local_get, i ],
|
66
61
|
...(invLocals[i].type !== Valtype.f64 ? [ Opcodes.i32_from ] : []),
|
67
|
-
[ Opcodes.call, importedFuncs.
|
62
|
+
[ Opcodes.call, importedFuncs.profileLocalSet ]
|
68
63
|
])
|
69
64
|
);
|
70
65
|
|
@@ -72,49 +67,32 @@ export const run = obj => {
|
|
72
67
|
const inst = wasm[j];
|
73
68
|
if (inst[0] === Opcodes.local_set || inst[0] === Opcodes.local_tee) {
|
74
69
|
wasm.splice(j + 1, 0,
|
70
|
+
number(id, Valtype.i32),
|
75
71
|
number(inst[1], Valtype.i32),
|
76
72
|
[ Opcodes.local_get, inst[1] ],
|
77
73
|
...(invLocals[inst[1]].type !== Valtype.f64 ? [ Opcodes.i32_from ] : []),
|
78
|
-
[ Opcodes.call, importedFuncs.
|
74
|
+
[ Opcodes.call, importedFuncs.profileLocalSet ]
|
79
75
|
);
|
80
76
|
}
|
81
77
|
}
|
82
78
|
}
|
83
79
|
|
84
|
-
|
80
|
+
localData = funcs.map(x => new Array(Object.keys(x.locals).length).fill(0).map(() => []));
|
85
81
|
|
86
82
|
time(0, `injected PGO logging`);
|
87
83
|
time(1, `running with PGO logging...`);
|
88
84
|
|
89
|
-
|
90
85
|
try {
|
91
86
|
obj.wasm = assemble(obj.funcs, obj.globals, obj.tags, obj.pages, obj.data, true);
|
92
87
|
|
93
88
|
Prefs._profileCompiler = Prefs.profileCompiler;
|
94
89
|
Prefs.profileCompiler = false;
|
95
90
|
|
96
|
-
const
|
97
|
-
|
98
|
-
// const pgoInd = process.argv.indexOf('--pgo');
|
99
|
-
// let args = process.argv.slice(pgoInd);
|
100
|
-
// args = args.slice(args.findIndex(x => !x.startsWith('-')) + 1);
|
101
|
-
|
102
|
-
// const str = args[ind - 1];
|
103
|
-
// if (pgoInd === -1 || !str) {
|
104
|
-
// if (Prefs.pgoLog) console.log('\nPGO warning: script was expecting arguments, please specify args to use for PGO after --pgo arg');
|
105
|
-
// return -1;
|
106
|
-
// }
|
107
|
-
|
108
|
-
// writeByteStr(exports.$, outPtr, str);
|
109
|
-
// return str.length;
|
110
|
-
return -1;
|
111
|
-
},
|
112
|
-
readFile: (pathPtr, outPtr) => {
|
113
|
-
return -1;
|
114
|
-
}
|
115
|
-
}, () => {});
|
116
|
-
|
91
|
+
const priorImports = { ...importedFuncs };
|
92
|
+
const { exports } = wrap(obj, undefined, () => {});
|
117
93
|
exports.main();
|
94
|
+
|
95
|
+
setImports(priorImports);
|
118
96
|
} catch (e) {
|
119
97
|
throw e;
|
120
98
|
}
|
@@ -242,8 +220,8 @@ export const run = obj => {
|
|
242
220
|
consts.push(number(c, valtype));
|
243
221
|
}
|
244
222
|
|
245
|
-
log += ` ${x.name}: replaced ${targets.length} locals with consts\n`;
|
246
|
-
if (targets.length > 0) Havoc.localsToConsts(wasmFunc, targets, consts, { localKeys: x.localKeys });
|
223
|
+
// log += ` ${x.name}: replaced ${targets.length} locals with consts\n`;
|
224
|
+
// if (targets.length > 0) Havoc.localsToConsts(wasmFunc, targets, consts, { localKeys: x.localKeys });
|
247
225
|
}
|
248
226
|
|
249
227
|
time(3, 'optimized using PGO data\n' + log);
|
package/compiler/precompile.js
CHANGED
@@ -57,7 +57,7 @@ const compile = async (file, _funcs) => {
|
|
57
57
|
first = source.slice(0, source.indexOf('\n'));
|
58
58
|
}
|
59
59
|
|
60
|
-
let args = ['--module', '--todo-time=compile', '--truthy=no_nan_negative', '--no-rm-unused-types', '--scoped-page-names', '--
|
60
|
+
let args = ['--module', '--todo-time=compile', '--truthy=no_nan_negative', '--no-rm-unused-types', '--scoped-page-names', '--fast-length', '--parse-types', '--opt-types', '--no-passive-data', '--active-data', '--no-treeshake-wasm-imports', '--no-coctc'];
|
61
61
|
if (first.startsWith('// @porf')) {
|
62
62
|
args = first.slice('// @porf '.length).split(' ').concat(args);
|
63
63
|
}
|
package/compiler/wrap.js
CHANGED
@@ -481,10 +481,9 @@ export { createImport };
|
|
481
481
|
*
|
482
482
|
* @param {string} source - JavaScript source code to compile
|
483
483
|
* @param {boolean} module - If the source is a module or not (default: false)
|
484
|
-
* @param {object} customImports - Custom imports
|
485
484
|
* @param {(str: string) => void} print - Function to use for printing (used by console.log etc)
|
486
485
|
*/
|
487
|
-
export default (source, module = undefined,
|
486
|
+
export default (source, module = undefined, print = str => process.stdout.write(str)) => {
|
488
487
|
createImport('print', 1, 0, i => print(i.toString()));
|
489
488
|
createImport('printChar', 1, 0, i => print(String.fromCharCode(i)));
|
490
489
|
createImport('time', 0, 1, () => performance.now());
|
@@ -512,12 +511,6 @@ export default (source, module = undefined, customImports = {}, print = str => p
|
|
512
511
|
}
|
513
512
|
});
|
514
513
|
|
515
|
-
for (const x in customImports) {
|
516
|
-
const custom = customImports[x];
|
517
|
-
// todo: make a simpler api for just js functions at some point using function.length etc
|
518
|
-
createImport(x, custom.params, custom.returns, custom.js, custom.c);
|
519
|
-
}
|
520
|
-
|
521
514
|
const times = [];
|
522
515
|
|
523
516
|
const t1 = performance.now();
|
@@ -575,6 +568,8 @@ export default (source, module = undefined, customImports = {}, print = str => p
|
|
575
568
|
instance = new WebAssembly.Instance(module, {
|
576
569
|
'': Object.keys(importedFuncs).reduce((acc, y) => {
|
577
570
|
const x = importedFuncs[y];
|
571
|
+
if (!x.import) return acc;
|
572
|
+
|
578
573
|
acc[x.import] = x.js ?? (() => {});
|
579
574
|
return acc;
|
580
575
|
}, {})
|
package/fuzz/index.js
CHANGED
package/package.json
CHANGED
package/runtime/debug.js
CHANGED
@@ -109,7 +109,7 @@ createImport('profile2', 1, 0, n => {
|
|
109
109
|
});
|
110
110
|
|
111
111
|
try {
|
112
|
-
const { exports } = compile(source, undefined,
|
112
|
+
const { exports } = compile(source, undefined, s => output += s);
|
113
113
|
exports.main();
|
114
114
|
} catch (e) {
|
115
115
|
console.error(e);
|
package/runtime/index.js
CHANGED
package/runtime/profile.js
CHANGED
@@ -94,7 +94,7 @@ globalThis.compileCallback = ({ funcs }) => {
|
|
94
94
|
};
|
95
95
|
|
96
96
|
console.log('Compiling...');
|
97
|
-
const { exports } = compile(source, undefined,
|
97
|
+
const { exports } = compile(source, undefined, () => {});
|
98
98
|
|
99
99
|
// --- Execution with Progress Spinner ---
|
100
100
|
|
package/runtime/repl.js
CHANGED
@@ -95,7 +95,7 @@ const run = (source, _context, _filename, callback, run = true) => {
|
|
95
95
|
|
96
96
|
let shouldPrint = !prev;
|
97
97
|
try {
|
98
|
-
const { exports, pages } = compile(toRun, undefined,
|
98
|
+
const { exports, pages } = compile(toRun, undefined, str => {
|
99
99
|
if (shouldPrint) process.stdout.write(str);
|
100
100
|
if (str === '-4919') shouldPrint = true;
|
101
101
|
});
|