Skip to content

Commit

Permalink
codegen: support map in for..of
Browse files Browse the repository at this point in the history
test262: 50.94% (+0.01) | πŸ§ͺ 48381 | 🀠 24645 (+6) | ❌ 6946 | πŸ’€ 15246 (-6) | πŸ—οΈ 147 | πŸ’₯ 329 | ⏰ 132 | πŸ“ 936
  • Loading branch information
CanadaHonk committed Nov 10, 2024
1 parent 8b1c0d2 commit 73da51d
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 148 deletions.
290 changes: 145 additions & 145 deletions compiler/builtins_precompiled.js

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4569,6 +4569,77 @@ const generateForOf = (scope, decl) => {
[ Opcodes.br, depth.length - prevDepth ]
] ],

[ TYPES.map, () => [
// length is actually keys pointer
// if counter == length then break
[ Opcodes.local_get, counter ],
[ Opcodes.local_get, length ],
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
[ Opcodes.i32_eq ],
[ Opcodes.br_if, depth.length - prevDepth ],

// allocate out array
...number(128, Valtype.i32),
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocateBytes').index ],
[ Opcodes.local_tee, localTmp(scope, '#forof_allocd', Valtype.i32) ],

// set length to 2
...number(2, Valtype.i32),
[ Opcodes.i32_store, 0, 0 ],

// use as pointer for stores later
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],

// set [0] as key
[ Opcodes.local_get, length ],
[ Opcodes.local_get, counter ],
[ Opcodes.i32_const, 9 ],
[ Opcodes.i32_mul ],
[ Opcodes.i32_add ],
[ Opcodes.local_set, localTmp(scope, '#forof_mapptr', Valtype.i32) ],

[ Opcodes.local_get, localTmp(scope, '#forof_mapptr', Valtype.i32) ],
[ Opcodes.f64_load, 0, 4 ],
[ Opcodes.f64_store, 0, 4 ],

[ Opcodes.local_get, localTmp(scope, '#forof_mapptr', Valtype.i32) ],
[ Opcodes.i32_load8_u, 0, 12 ],
[ Opcodes.i32_store8, 0, 12 ],

// set [1] as value
[ Opcodes.local_get, pointer ],
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 4 ],
[ Opcodes.local_get, counter ],
[ Opcodes.i32_const, 9 ],
[ Opcodes.i32_mul ],
[ Opcodes.i32_add ],
[ Opcodes.local_set, localTmp(scope, '#forof_mapptr', Valtype.i32) ],

[ Opcodes.local_get, localTmp(scope, '#forof_mapptr', Valtype.i32) ],
[ Opcodes.f64_load, 0, 4 ],
[ Opcodes.f64_store, 0, 13 ],

[ Opcodes.local_get, localTmp(scope, '#forof_mapptr', Valtype.i32) ],
[ Opcodes.i32_load8_u, 0, 12 ],
[ Opcodes.i32_store8, 0, 21 ],

// increment counter
[ Opcodes.local_get, counter ],
...number(1, Valtype.i32),
[ Opcodes.i32_add ],
[ Opcodes.local_set, counter ],

// get new array (page)
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],
Opcodes.i32_from_u,

// set type to array
...setLastType(scope, TYPES.array)
] ],

// note: should be impossible to reach?
[ 'default', [ [ Opcodes.unreachable ] ] ]
], 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.50.4",
"version": "0.50.5",
"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.4';
globalThis.version = '0.50.5';

// 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 73da51d

Please sign in to comment.