Skip to content

Commit 55a2ffb

Browse files
committed
codegen: cleanup
test262: 56.49% | πŸ§ͺ 50259 | 🀠 28390 | ❌ 7231 | πŸ’€ 13701 | πŸ—οΈ 32 | πŸ’₯ 177 | ⏰ 11 | πŸ“ 717
1 parent 77cf9dc commit 55a2ffb

File tree

4 files changed

+20
-99
lines changed

4 files changed

+20
-99
lines changed

β€Žcompiler/codegen.js

+17-96
Original file line numberDiff line numberDiff line change
@@ -1386,29 +1386,6 @@ const generateLogicExp = (scope, decl) => {
13861386
return performLogicOp(scope, decl.operator, generate(scope, decl.left), generate(scope, decl.right), getNodeType(scope, decl.left), getNodeType(scope, decl.right));
13871387
};
13881388

1389-
// potential future ideas for nan boxing (unused):
1390-
// T = JS type, V = value/pointer
1391-
// 0bTTT
1392-
// qNAN: 0 11111111111 1000000000000000000000000000000000000000000000000001
1393-
// 50 bits usable: 0 11111111111 11??????????????????????????????????????????????????
1394-
// js type: 4 bits
1395-
// internal type: ? bits
1396-
// pointer: 32 bits
1397-
// https://piotrduperas.com/posts/nan-boxing
1398-
// 0x7ffc000000000000
1399-
// budget: 50 bits
1400-
// js type: 4 bits
1401-
// internal type: ? bits
1402-
// pointer: 32 bits
1403-
// generic
1404-
// 1 23 4 5
1405-
// 0 11111111111 11TTTTIIII??????????PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
1406-
// 1: regular iEEE 754 double NaN
1407-
// 2: extra 1 bit to identify NaN box
1408-
// 3: js type
1409-
// 4: internal type
1410-
// 5: pointer
1411-
14121389
const isExistingProtoFunc = name => {
14131390
if (name.startsWith('__Array_prototype')) return !!prototypeFuncs[TYPES.array][name.slice(18)];
14141391
if (name.startsWith('__String_prototype_')) return !!prototypeFuncs[TYPES.string][name.slice(19)];
@@ -2750,18 +2727,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
27502727
}
27512728

27522729
out.push([ Opcodes.call, idx ]);
2753-
2754-
if (!typedReturns) {
2755-
// let type;
2756-
// if (builtinFuncs[name]) type = TYPES[builtinFuncs[name].returnType ?? 'number'];
2757-
// if (internalConstrs[name]) type = internalConstrs[name].type;
2758-
// if (importedFuncs[name] && importedFuncs[]) type =
2759-
2760-
// if (type) out.push(
2761-
// number(type, Valtype.i32),
2762-
// [ Opcodes.local_set, localTmp(scope, '#last_type', Valtype.i32) ]
2763-
// );
2764-
} else out.push(...setLastType(scope));
2730+
if (typedReturns) out.push(...setLastType(scope));
27652731

27662732
if (
27672733
func?.returns?.length === 0 ||
@@ -5418,7 +5384,7 @@ const makeData = (scope, elements, page = null, itemType = 'i8') => {
54185384

54195385
const length = elements.length;
54205386

5421-
// if length is 0 memory/data will just be 0000... anyway
5387+
// if length is 0, memory/data will just be 0000... anyway
54225388
if (length === 0) return false;
54235389

54245390
let bytes = compileBytes(length, 'i32');
@@ -5432,7 +5398,6 @@ const makeData = (scope, elements, page = null, itemType = 'i8') => {
54325398
}
54335399

54345400
const obj = { bytes, page };
5435-
54365401
const idx = data.push(obj) - 1;
54375402

54385403
scope.data ??= [];
@@ -5456,63 +5421,6 @@ const printStaticStr = str => {
54565421
return out;
54575422
};
54585423

5459-
const storeArray = (scope, array, index, element) => {
5460-
if (!Array.isArray(element)) element = generate(scope, element);
5461-
if (typeof index === 'number') index = [ number(index) ];
5462-
5463-
const offset = localTmp(scope, '#storeArray_offset', Valtype.i32);
5464-
5465-
return [
5466-
// calculate offset
5467-
...index,
5468-
Opcodes.i32_to_u,
5469-
number(ValtypeSize[valtype] + 1, Valtype.i32),
5470-
[ Opcodes.i32_mul ],
5471-
5472-
...array,
5473-
Opcodes.i32_to_u,
5474-
[ Opcodes.i32_add ],
5475-
[ Opcodes.local_set, offset ],
5476-
5477-
// store value
5478-
[ Opcodes.local_get, offset ],
5479-
...generate(scope, element),
5480-
[ Opcodes.store, 0, ValtypeSize.i32 ],
5481-
5482-
// store type
5483-
[ Opcodes.local_get, offset ],
5484-
...getNodeType(scope, element),
5485-
[ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
5486-
];
5487-
};
5488-
5489-
const loadArray = (scope, array, index) => {
5490-
if (typeof index === 'number') index = [ number(index) ];
5491-
5492-
const offset = localTmp(scope, '#loadArray_offset', Valtype.i32);
5493-
5494-
return [
5495-
// calculate offset
5496-
...index,
5497-
Opcodes.i32_to_u,
5498-
number(ValtypeSize[valtype] + 1, Valtype.i32),
5499-
[ Opcodes.i32_mul ],
5500-
5501-
...array,
5502-
Opcodes.i32_to_u,
5503-
[ Opcodes.i32_add ],
5504-
[ Opcodes.local_set, offset ],
5505-
5506-
// load value
5507-
[ Opcodes.local_get, offset ],
5508-
[ Opcodes.load, 0, ValtypeSize.i32 ],
5509-
5510-
// load type
5511-
[ Opcodes.local_get, offset ],
5512-
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
5513-
];
5514-
};
5515-
55165424
const byteStringable = str => {
55175425
for (let i = 0; i < str.length; i++) {
55185426
if (str.charCodeAt(i) > 0xFF) return false;
@@ -5957,8 +5865,21 @@ const generateMember = (scope, decl, _global, _name) => {
59575865
const out = typeSwitch(scope, getNodeType(scope, object), {
59585866
...(decl.computed ? {
59595867
[TYPES.array]: () => [
5960-
...loadArray(scope, [ objectGet ], [ propertyGet ]),
5961-
...setLastType(scope)
5868+
propertyGet,
5869+
Opcodes.i32_to_u,
5870+
number(ValtypeSize[valtype] + 1, Valtype.i32),
5871+
[ Opcodes.i32_mul ],
5872+
5873+
objectGet,
5874+
Opcodes.i32_to_u,
5875+
[ Opcodes.i32_add ],
5876+
[ Opcodes.local_tee, localTmp(scope, '#loadArray_offset', Valtype.i32) ],
5877+
[ Opcodes.load, 0, ValtypeSize.i32 ],
5878+
5879+
...setLastType(scope, [
5880+
[ Opcodes.local_get, localTmp(scope, '#loadArray_offset', Valtype.i32) ],
5881+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
5882+
])
59625883
],
59635884

59645885
[TYPES.string]: () => [

β€Žpackage.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "porffor",
33
"description": "An ahead-of-time JavaScript compiler",
4-
"version": "0.55.20",
4+
"version": "0.55.21",
55
"author": "Oliver Medhurst <[email protected]>",
66
"license": "MIT",
77
"scripts": {},

β€Žrunner/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
import fs from 'node:fs';
3-
globalThis.version = '0.55.20';
3+
globalThis.version = '0.55.21';
44

55
// deno compat
66
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {

β€Žtest262/history.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
Β (0)