porffor 0.49.9 → 0.49.11
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/builtins/reflect.ts +10 -0
- package/compiler/builtins_precompiled.js +287 -273
- package/compiler/codegen.js +46 -13
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -50,6 +50,7 @@ const cacheAst = (decl, wasm) => {
|
|
50
50
|
let indirectFuncs = [];
|
51
51
|
const funcRef = func => {
|
52
52
|
func.generate?.();
|
53
|
+
func.referenced = true;
|
53
54
|
|
54
55
|
if (globalThis.precompile) return [
|
55
56
|
[ Opcodes.const, 'funcref', func.name ]
|
@@ -1507,7 +1508,7 @@ const getNodeType = (scope, node) => {
|
|
1507
1508
|
}
|
1508
1509
|
|
1509
1510
|
if (Object.hasOwn(builtinFuncs, name) && !builtinFuncs[name].typedReturns) return builtinFuncs[name].returnType ?? TYPES.number;
|
1510
|
-
if (Object.hasOwn(internalConstrs, name)) return internalConstrs[name].type;
|
1511
|
+
if (Object.hasOwn(internalConstrs, name) && internalConstrs[name].type != null) return internalConstrs[name].type;
|
1511
1512
|
|
1512
1513
|
// check if this is a prototype function
|
1513
1514
|
// if so and there is only one impl (eg charCodeAt)
|
@@ -1929,7 +1930,7 @@ const createThisArg = (scope, decl) => {
|
|
1929
1930
|
const name = decl.callee?.name;
|
1930
1931
|
if (decl._new) {
|
1931
1932
|
// if precompiling or builtin func, just make it null as unused
|
1932
|
-
if (globalThis.precompile || Object.hasOwn(builtinFuncs, name)) return [
|
1933
|
+
if (!decl._forceCreateThis && (globalThis.precompile || Object.hasOwn(builtinFuncs, name))) return [
|
1933
1934
|
...number(NULL),
|
1934
1935
|
...number(TYPES.object, Valtype.i32)
|
1935
1936
|
];
|
@@ -2532,6 +2533,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2532
2533
|
|
2533
2534
|
const func = funcByIndex(idx);
|
2534
2535
|
|
2536
|
+
if (func && !decl._new) func.onlyNew = false;
|
2537
|
+
|
2535
2538
|
// generate func
|
2536
2539
|
if (func) func.generate?.();
|
2537
2540
|
|
@@ -2664,16 +2667,22 @@ const generateThis = (scope, decl) => {
|
|
2664
2667
|
];
|
2665
2668
|
|
2666
2669
|
return [
|
2667
|
-
// default this to globalThis
|
2668
|
-
[
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
2672
|
-
|
2673
|
-
|
2674
|
-
|
2675
|
-
|
2676
|
-
|
2670
|
+
// default this to globalThis unless only new func
|
2671
|
+
[ null, () => {
|
2672
|
+
if (scope.onlyNew !== false && !scope.referenced) return [];
|
2673
|
+
|
2674
|
+
return [
|
2675
|
+
[ Opcodes.local_get, scope.locals['#this#type'].idx ],
|
2676
|
+
...number(TYPES.undefined, Valtype.i32),
|
2677
|
+
[ Opcodes.i32_eq ],
|
2678
|
+
[ Opcodes.if, Blocktype.void ],
|
2679
|
+
...generate(scope, { type: 'Identifier', name: 'globalThis' }),
|
2680
|
+
[ Opcodes.local_set, scope.locals['#this'].idx ],
|
2681
|
+
...getType(scope, 'globalThis'),
|
2682
|
+
[ Opcodes.local_set, scope.locals['#this#type'].idx ],
|
2683
|
+
[ Opcodes.end ]
|
2684
|
+
];
|
2685
|
+
}, 0 ],
|
2677
2686
|
|
2678
2687
|
[ Opcodes.local_get, scope.locals['#this'].idx ],
|
2679
2688
|
...setLastType(scope, [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ])
|
@@ -6094,7 +6103,7 @@ const objectHack = node => {
|
|
6094
6103
|
if (node.computed || node.optional) return;
|
6095
6104
|
|
6096
6105
|
// hack: block these properties as they can be accessed on functions
|
6097
|
-
if (node.property.name === 'length' || node.property.name === 'name' || node.property.name === 'call') return abortOut;
|
6106
|
+
if (node.object.name !== 'Porffor' && (node.property.name === 'length' || node.property.name === 'name' || node.property.name === 'call')) return abortOut;
|
6098
6107
|
|
6099
6108
|
if (node.property.name === '__proto__') return abortOut;
|
6100
6109
|
|
@@ -6605,6 +6614,30 @@ const internalConstrs = {
|
|
6605
6614
|
type: TYPES.bytestring,
|
6606
6615
|
notConstr: true,
|
6607
6616
|
length: 1
|
6617
|
+
},
|
6618
|
+
|
6619
|
+
__Porffor_call: {
|
6620
|
+
// Porffor.call(func, argArray, this, newTarget)
|
6621
|
+
generate: (scope, decl) => generate(scope, {
|
6622
|
+
type: 'CallExpression',
|
6623
|
+
callee: decl.arguments[0],
|
6624
|
+
arguments: [ {
|
6625
|
+
type: 'SpreadElement',
|
6626
|
+
argument: decl.arguments[1],
|
6627
|
+
} ],
|
6628
|
+
_thisWasm: decl.arguments[2].value === null ? null : [
|
6629
|
+
...generate(scope, decl.arguments[2]),
|
6630
|
+
...getNodeType(scope, decl.arguments[2])
|
6631
|
+
],
|
6632
|
+
_newTargetWasm: decl.arguments[3].value === null ? null : [
|
6633
|
+
...generate(scope, decl.arguments[3]),
|
6634
|
+
...getNodeType(scope, decl.arguments[3])
|
6635
|
+
],
|
6636
|
+
_new: decl.arguments[3].value !== null,
|
6637
|
+
_forceCreateThis: true
|
6638
|
+
}),
|
6639
|
+
notConstr: true,
|
6640
|
+
length: 1
|
6608
6641
|
}
|
6609
6642
|
};
|
6610
6643
|
|
package/package.json
CHANGED