@@ -1386,29 +1386,6 @@ const generateLogicExp = (scope, decl) => {
1386
1386
return performLogicOp ( scope , decl . operator , generate ( scope , decl . left ) , generate ( scope , decl . right ) , getNodeType ( scope , decl . left ) , getNodeType ( scope , decl . right ) ) ;
1387
1387
} ;
1388
1388
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
-
1412
1389
const isExistingProtoFunc = name => {
1413
1390
if ( name . startsWith ( '__Array_prototype' ) ) return ! ! prototypeFuncs [ TYPES . array ] [ name . slice ( 18 ) ] ;
1414
1391
if ( name . startsWith ( '__String_prototype_' ) ) return ! ! prototypeFuncs [ TYPES . string ] [ name . slice ( 19 ) ] ;
@@ -2750,18 +2727,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2750
2727
}
2751
2728
2752
2729
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 ) ) ;
2765
2731
2766
2732
if (
2767
2733
func ?. returns ?. length === 0 ||
@@ -5418,7 +5384,7 @@ const makeData = (scope, elements, page = null, itemType = 'i8') => {
5418
5384
5419
5385
const length = elements . length ;
5420
5386
5421
- // if length is 0 memory/data will just be 0000... anyway
5387
+ // if length is 0, memory/data will just be 0000... anyway
5422
5388
if ( length === 0 ) return false ;
5423
5389
5424
5390
let bytes = compileBytes ( length , 'i32' ) ;
@@ -5432,7 +5398,6 @@ const makeData = (scope, elements, page = null, itemType = 'i8') => {
5432
5398
}
5433
5399
5434
5400
const obj = { bytes, page } ;
5435
-
5436
5401
const idx = data . push ( obj ) - 1 ;
5437
5402
5438
5403
scope . data ??= [ ] ;
@@ -5456,63 +5421,6 @@ const printStaticStr = str => {
5456
5421
return out ;
5457
5422
} ;
5458
5423
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
-
5516
5424
const byteStringable = str => {
5517
5425
for ( let i = 0 ; i < str . length ; i ++ ) {
5518
5426
if ( str . charCodeAt ( i ) > 0xFF ) return false ;
@@ -5957,8 +5865,21 @@ const generateMember = (scope, decl, _global, _name) => {
5957
5865
const out = typeSwitch ( scope , getNodeType ( scope , object ) , {
5958
5866
...( decl . computed ? {
5959
5867
[ 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
+ ] )
5962
5883
] ,
5963
5884
5964
5885
[ TYPES . string ] : ( ) => [
0 commit comments