Skip to content

Commit

Permalink
codegen: better proto switching
Browse files Browse the repository at this point in the history
test262: 55.11% | πŸ§ͺ 50254 | 🀠 27693 | ❌ 7204 (-3) | πŸ’€ 14009 (+2) | πŸ—οΈ 32 | πŸ’₯ 176 | ⏰ 141 (+1) | πŸ“ 999
  • Loading branch information
CanadaHonk committed Dec 21, 2024
1 parent 326d8ee commit e9cd293
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
8 changes: 4 additions & 4 deletions compiler/builtins_precompiled.js

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2382,24 +2382,22 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
}

if (Object.keys(protoBC).length > 0) {
let def = internalThrow(scope, 'TypeError', `'${protoName}' proto func tried to be called on a type without an impl`, true);
protoBC.default = decl.optional ?
withType(scope, [ number(UNDEFINED) ], TYPES.undefined) :
internalThrow(scope, 'TypeError', `'${protoName}' proto func tried to be called on a type without an impl`, true);

// fallback to object prototype impl as a basic prototype chain hack
if (protoBC[TYPES.object]) def = protoBC[TYPES.object];
if (protoBC[TYPES.object]) {
protoBC[TYPES.undefined] = protoBC[TYPES.null] = protoBC.default;
protoBC.default = protoBC[TYPES.object];
}

// alias primitive prototype with primitive object types
aliasPrimObjsBC(protoBC);

return [
...out,

...typeSwitch(scope, getNodeType(scope, target), {
...protoBC,

// TODO: error better
default: decl.optional ? withType(scope, [ number(UNDEFINED) ], TYPES.undefined)
: def
}, valtypeBinary)
...typeSwitch(scope, getNodeType(scope, target), protoBC, valtypeBinary)
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "porffor",
"description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
"version": "0.55.8",
"version": "0.55.9",
"author": "CanadaHonk",
"license": "MIT",
"scripts": {},
Expand Down
2 changes: 1 addition & 1 deletion runner/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import fs from 'node:fs';
globalThis.version = '0.55.8';
globalThis.version = '0.55.9';

// deno compat
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion test262/history.json

Large diffs are not rendered by default.

0 comments on commit e9cd293

Please sign in to comment.