Skip to content

Commit

Permalink
codegen: basic spread element as last arg
Browse files Browse the repository at this point in the history
test262: 42.33% (+0.01) | πŸ§ͺ 48414 | 🀠 20494 (+6) | ❌ 7102 (-4) | πŸ’€ 17375 | πŸ—οΈ 151 | πŸ’₯ 296 | ⏰ 27 (-1) | πŸ“ 2969 (-1)
  • Loading branch information
CanadaHonk committed Sep 21, 2024
1 parent 4512252 commit ed9ba50
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,31 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
paramOffset += 4;
}

if (args.at(-1)?.type === 'SpreadElement') {
// hack: support spread element if last by doing essentially:
// const foo = (a, b, c, d) => ...
// foo(a, b, ...c) -> _ = c; foo(a, b, _[0], _[1])
const arg = args.at(-1).argument;
out.push(
...generate(scope, arg),
[ Opcodes.local_set, localTmp(scope, '#spread') ],
...getNodeType(scope, arg),
[ Opcodes.local_set, localTmp(scope, '#spread#type', Valtype.i32) ]
);

args.pop();
const leftover = paramCount - args.length;
for (let i = 0; i < leftover; i++) {
args.push({
type: 'MemberExpression',
object: { type: 'Identifier', name: '#spread' },
property: { type: 'Literal', value: i },
computed: true,
optional: false
});
}
}

if (func && args.length < paramCount) {
// too little args, push undefineds
args = args.concat(new Array(paramCount - (func.hasRestArgument ? 1 : 0) - args.length).fill(DEFAULT_VALUE()));
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.42.6+d8f9d3f11",
"version": "0.42.7+5472762e8",
"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.42.6+d8f9d3f11';
globalThis.version = '0.42.7+5472762e8';

// 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 ed9ba50

Please sign in to comment.