Skip to content

Commit

Permalink
codegen: fix duplicated params making malformed wasm
Browse files Browse the repository at this point in the history
halves malformed wasm errors again!

test262: 51.07% (+0.02) | πŸ§ͺ 48381 | 🀠 24709 (+11) | ❌ 6979 (+25) | πŸ’€ 15269 | πŸ—οΈ 25 (-36) | πŸ’₯ 329 | ⏰ 134 | πŸ“ 936
  • Loading branch information
CanadaHonk committed Dec 7, 2024
1 parent 2000e08 commit 5d854ec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
15 changes: 9 additions & 6 deletions compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3055,15 +3055,18 @@ const typeIsNotOneOf = (type, types, valtype = Valtype.i32) => {
return out;
};

const allocVar = (scope, name, global = false, type = true) => {
const allocVar = (scope, name, global = false, type = true, redecl = false) => {
const target = global ? globals : scope.locals;

// already declared
if (Object.hasOwn(target, name)) {
// parser should catch this but sanity check anyway
// if (decl.kind !== 'var') return internalThrow(scope, 'SyntaxError', `Identifier '${unhackName(name)}' has already been declared`);

return target[name].idx;
if (redecl) {
// force change old local name(s)
target['#redecl_' + name + uniqId()] = target[name];
if (type) target['#redecl_' + name + '#type' + uniqId()] = target[name + '#type'];
} else {
return target[name].idx;
}
}

let idx = global ? globals['#ind']++ : scope.localInd++;
Expand Down Expand Up @@ -6515,7 +6518,7 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
const { name, def, destr, type } = args[i];

func.localInd = i * 2;
allocVar(func, name, false);
allocVar(func, name, false, true, true);

func.localInd = localInd;
if (type) {
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.50.19",
"version": "0.50.20",
"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.50.19';
globalThis.version = '0.50.20';

// 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 5d854ec

Please sign in to comment.