porffor 0.24.0 → 0.24.2
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 +6 -0
- package/compiler/allocators.js +6 -2
- package/compiler/assemble.js +38 -33
- package/compiler/builtins_objects.js +39 -11
- package/compiler/builtins_precompiled.js +23 -23
- package/compiler/codegen.js +29 -5
- package/compiler/index.js +10 -5
- package/compiler/precompile.js +1 -1
- package/compiler/prefs.js +1 -1
- package/compiler/wrap.js +5 -1
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -3142,6 +3142,8 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3142
3142
|
]
|
3143
3143
|
}),
|
3144
3144
|
|
3145
|
+
[TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot set property of undefined', true),
|
3146
|
+
|
3145
3147
|
// default: internalThrow(scope, 'TypeError', `Cannot assign member with this type`)
|
3146
3148
|
default: [
|
3147
3149
|
...objectWasm,
|
@@ -4376,7 +4378,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
4376
4378
|
return [ out, pointer ];
|
4377
4379
|
}
|
4378
4380
|
} else {
|
4379
|
-
const rawPtr =
|
4381
|
+
const rawPtr = allocator.lastPtr;
|
4380
4382
|
|
4381
4383
|
scope.arrays ??= new Map();
|
4382
4384
|
const firstAssign = !scope.arrays.has(uniqueName);
|
@@ -4384,14 +4386,34 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
4384
4386
|
|
4385
4387
|
const local = global ? globals[name] : scope.locals?.[name];
|
4386
4388
|
if (
|
4387
|
-
Prefs.data &&
|
4389
|
+
Prefs.data && useRawElements &&
|
4388
4390
|
name !== '#member_prop' && name !== '#member_prop_assign' &&
|
4389
4391
|
(!globalThis.precompile || !global)
|
4390
4392
|
) {
|
4391
|
-
|
4393
|
+
if (Prefs.activeData && firstAssign) {
|
4394
|
+
makeData(scope, elements, rawPtr, itemType, initEmpty);
|
4395
|
+
|
4396
|
+
// local value as pointer
|
4397
|
+
return [ number(rawPtr, intOut ? Valtype.i32 : valtypeBinary), pointer ];
|
4398
|
+
}
|
4399
|
+
|
4400
|
+
if (Prefs.passiveData) {
|
4401
|
+
const data = makeData(scope, elements, null, itemType, initEmpty);
|
4402
|
+
if (data) {
|
4403
|
+
// init data
|
4404
|
+
out.push(
|
4405
|
+
...pointer,
|
4406
|
+
...number(0, Valtype.i32),
|
4407
|
+
...number(data.size, Valtype.i32),
|
4408
|
+
[ ...Opcodes.memory_init, ...unsignedLEB128(data.idx), 0 ]
|
4409
|
+
);
|
4410
|
+
}
|
4411
|
+
|
4412
|
+
// return pointer in out
|
4413
|
+
out.push(...number(rawPtr, intOut ? Valtype.i32 : valtypeBinary));
|
4392
4414
|
|
4393
|
-
|
4394
|
-
|
4415
|
+
return [ out, pointer ];
|
4416
|
+
}
|
4395
4417
|
}
|
4396
4418
|
|
4397
4419
|
if (local != null) {
|
@@ -4920,6 +4942,8 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4920
4942
|
postlude: setLastType(scope, TYPES.number)
|
4921
4943
|
}),
|
4922
4944
|
|
4945
|
+
[TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot read property of undefined', true),
|
4946
|
+
|
4923
4947
|
// default: internalThrow(scope, 'TypeError', 'Unsupported member expression object', true)
|
4924
4948
|
default: [
|
4925
4949
|
...number(0),
|
package/compiler/index.js
CHANGED
@@ -41,8 +41,12 @@ export default (code, flags) => {
|
|
41
41
|
const pageSizeOpt = process.argv.find(x => x.startsWith('--page-size='));
|
42
42
|
if (pageSizeOpt) pageSize = parseInt(pageSizeOpt.split('=')[1]) * 1024;
|
43
43
|
|
44
|
-
//
|
45
|
-
if (target !== 'wasm')
|
44
|
+
// change some prefs by default for c/native
|
45
|
+
if (target !== 'wasm') {
|
46
|
+
Prefs.pgo = Prefs.pgo === false ? false : true;
|
47
|
+
Prefs.passiveData = false;
|
48
|
+
}
|
49
|
+
|
46
50
|
if (Prefs.pgo) pgo.setup();
|
47
51
|
|
48
52
|
if (Prefs.profileCompiler) console.log(`0. began compilation (host runtime startup) in ${performance.now().toFixed(2)}ms`);
|
@@ -104,8 +108,11 @@ export default (code, flags) => {
|
|
104
108
|
|
105
109
|
if (Prefs.profileCompiler) console.log(`3. optimized in ${(performance.now() - t2).toFixed(2)}ms`);
|
106
110
|
|
111
|
+
const out = { funcs, globals, tags, exceptions, pages, data };
|
112
|
+
if (globalThis.precompile) return out;
|
113
|
+
|
107
114
|
const t3 = performance.now();
|
108
|
-
const wasm = assemble(funcs, globals, tags, pages, data, flags);
|
115
|
+
const wasm = out.wasm = assemble(funcs, globals, tags, pages, data, flags);
|
109
116
|
if (Prefs.profileCompiler) console.log(`4. assembled in ${(performance.now() - t3).toFixed(2)}ms`);
|
110
117
|
|
111
118
|
if (Prefs.optFuncs) logFuncs(funcs, globals, exceptions);
|
@@ -117,8 +124,6 @@ export default (code, flags) => {
|
|
117
124
|
console.log([...pages.keys()].map(x => `\x1B[36m - ${x}\x1B[0m`).join('\n') + '\n');
|
118
125
|
}
|
119
126
|
|
120
|
-
const out = { wasm, funcs, globals, tags, exceptions, pages, data };
|
121
|
-
|
122
127
|
if (target === 'wasm' && outFile) {
|
123
128
|
fs.writeFileSync(outFile, Buffer.from(wasm));
|
124
129
|
|
package/compiler/precompile.js
CHANGED
@@ -24,7 +24,7 @@ const compile = async (file, _funcs) => {
|
|
24
24
|
first = source.slice(0, source.indexOf('\n'));
|
25
25
|
}
|
26
26
|
|
27
|
-
let args = ['--bytestring', '--todo-time=compile', '--truthy=no_nan_negative', '--no-
|
27
|
+
let args = ['--bytestring', '--todo-time=compile', '--truthy=no_nan_negative', '--no-rm-unused-types', '--scoped-page-names', '--funsafe-no-unlikely-proto-checks', '--fast-length', '--parse-types', '--opt-types', '--no-passive-data', '--active-data'];
|
28
28
|
if (first.startsWith('// @porf')) {
|
29
29
|
args = first.slice('// @porf '.length).split(' ').concat(args);
|
30
30
|
}
|
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', 'data', 'passiveData', 'rmUnusedTypes' ];
|
2
2
|
|
3
3
|
let cache = {};
|
4
4
|
const obj = new Proxy({}, {
|
package/compiler/wrap.js
CHANGED
@@ -116,8 +116,12 @@ ${flags & 0b0001 ? ` get func idx: ${get}
|
|
116
116
|
|
117
117
|
if (!func) return function () {};
|
118
118
|
|
119
|
+
let name = func.name;
|
120
|
+
// eg: __String_prototype_toLowerCase -> toLowerCase
|
121
|
+
if (name.startsWith('__')) name = name.split('_').pop();
|
122
|
+
|
119
123
|
// make fake empty func for repl/etc
|
120
|
-
return {[
|
124
|
+
return {[name]() {}}[name];
|
121
125
|
}
|
122
126
|
|
123
127
|
case TYPES.string: {
|
package/package.json
CHANGED