@@ -534,15 +534,16 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
534
534
$ type == $ T_INT8
535
535
|| $ type == $ T_INT16
536
536
|| $ type == $ T_UINT8
537
- || $ type == $ T_UINT16 ;
537
+ || $ type == $ T_UINT16
538
+ || $ type == $ T_UINT32 ;
538
539
}
539
540
540
541
# = Convert a 32bit integer which is a result of js expr $expr into integer type $type for storage
541
542
method int_to_fancy_int (int $ type , str $ expr ) {
542
543
if $ type == $ T_INT8 || $ type == $ T_INT16 {
543
544
my int $ shift := 32 - self . bits($ type );
544
545
" ($ expr << $ shift >> $ shift )" ;
545
- } elsif $ type == $ T_UINT8 || $ type == $ T_UINT16 {
546
+ } elsif $ type == $ T_UINT8 || $ type == $ T_UINT16 || $ type == $ T_UINT32 {
546
547
my int $ shift := 32 - self . bits($ type );
547
548
" ($ expr << $ shift >>> $ shift )" ;
548
549
} else {
@@ -552,17 +553,19 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
552
553
553
554
method bits (int $ type ) {
554
555
if $ type == $ T_INT8 || $ type == $ T_UINT8 {
555
- 8
556
+ 8 ;
556
557
} elsif $ type == $ T_INT16 || $ type == $ T_UINT16 {
557
- 16
558
+ 16 ;
559
+ } elsif $ type == $ T_INT || $ type == $ T_UINT32 {
560
+ 32 ;
558
561
} else {
559
562
nqp ::die(" We can't determine the number of bits for $ type" );
560
563
}
561
564
}
562
565
563
566
method coerce (Chunk $ chunk , $ desired ) {
564
567
my int $ got := $ chunk . type;
565
- my int $ got_int := $ got == $ T_INT || self . is_fancy_int($ got );
568
+ my int $ got_int := $ got == $ T_INT || ( self . is_fancy_int($ got ) && $ got != $ T_UINT32 );
566
569
567
570
if $ got != $ desired {
568
571
if $ desired == $ T_VOID {
@@ -579,6 +582,9 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
579
582
if $ got_int {
580
583
return Chunk. new ($ T_RETVAL , $ chunk . expr, $ chunk );
581
584
}
585
+ if $ got == $ T_UINT32 {
586
+ return Chunk. new ($ T_RETVAL , " new nqp.NativeUIntRet({ $ chunk . expr} )" , $ chunk );
587
+ }
582
588
if $ got == $ T_NUM {
583
589
return Chunk. new ($ T_RETVAL , " new nqp.NativeNumRet({ $ chunk . expr} )" , $ chunk );
584
590
}
@@ -600,6 +606,9 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
600
606
if $ got_int {
601
607
return Chunk. new ($ T_CALL_ARG , " new nqp.NativeIntArg({ $ chunk . expr} )" , $ chunk );
602
608
}
609
+ if $ got == $ T_UINT32 {
610
+ return Chunk. new ($ T_CALL_ARG , " new nqp.NativeUIntArg({ $ chunk . expr} )" , $ chunk );
611
+ }
603
612
if $ got == $ T_NUM {
604
613
return Chunk. new ($ T_CALL_ARG , " new nqp.NativeNumArg({ $ chunk . expr} )" , $ chunk );
605
614
}
@@ -609,7 +618,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
609
618
}
610
619
611
620
if $ desired == $ T_NUM {
612
- if $ got_int {
621
+ if $ got_int || $ got == $ T_UINT32 {
613
622
# we store both as a javascript number, and 32bit integers fit into doubles
614
623
return Chunk. new ($ T_NUM , $ chunk . expr, $ chunk );
615
624
}
@@ -625,7 +634,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
625
634
if $ got == $ T_STR {
626
635
return Chunk. new ($ T_INT , " parseInt({ $ chunk . expr} )" , $ chunk );
627
636
}
628
- if $ got == $ T_NUM {
637
+ if $ got == $ T_NUM || $ got == $ T_UINT32 {
629
638
return Chunk. new ($ T_INT , " ({ $ chunk . expr} |0)" , $ chunk );
630
639
}
631
640
if $ got == $ T_BOOL {
@@ -645,7 +654,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
645
654
}
646
655
647
656
if $ desired == $ T_STR {
648
- if $ got_int {
657
+ if $ got_int || $ got == $ T_UINT32 {
649
658
return Chunk. new ($ T_STR , $ chunk . expr ~ ' .toString()' , $ chunk );
650
659
}
651
660
elsif $ got == $ T_NUM {
@@ -684,6 +693,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
684
693
% convert {$ T_INT16 } := ' intToObj' ;
685
694
% convert {$ T_UINT8 } := ' intToObj' ;
686
695
% convert {$ T_UINT16 } := ' intToObj' ;
696
+ % convert {$ T_UINT32 } := ' intToObj' ;
687
697
% convert {$ T_NUM } := ' numToObj' ;
688
698
% convert {$ T_STR } := ' strToObj' ;
689
699
% convert {$ T_RETVAL } := ' retval' ;
@@ -693,7 +703,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
693
703
}
694
704
695
705
if $ desired == $ T_BOOL {
696
- if $ got_int {
706
+ if $ got_int || $ got == $ T_UINT32 {
697
707
return Chunk. new ($ T_BOOL , $ chunk . expr, $ chunk );
698
708
} elsif $ got == $ T_NUM {
699
709
return Chunk. new ($ T_BOOL , " ({ $ chunk . expr} !== 0)" , $ chunk );
@@ -1593,6 +1603,9 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
1593
1603
elsif $ bits == 16 {
1594
1604
$ unsigned ?? $ T_UINT16 !! $ T_INT16 ;
1595
1605
}
1606
+ elsif $ bits == 32 {
1607
+ $ unsigned ?? $ T_UINT32 !! $ T_INT ;
1608
+ }
1596
1609
else {
1597
1610
$ T_INT ;
1598
1611
}
@@ -1703,7 +1716,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
1703
1716
Chunk. void ($ check , " if (!{ $ check . expr} ) return nqp.paramcheckfailed(HLL, $ * CTX , Array.prototype.slice.call(arguments));\n " );
1704
1717
}
1705
1718
1706
- my % default_value := nqp ::hash($ T_OBJ , ' nqp.Null' , $ T_INT , ' 0' , $ T_NUM , ' 0' , $ T_STR , ' nqp.null_s' , $ T_INT16 , ' 0' , $ T_INT8 , ' 0' , $ T_UINT8 , ' 0' , $ T_UINT16 , ' 0' );
1719
+ my % default_value := nqp ::hash($ T_OBJ , ' nqp.Null' , $ T_INT , ' 0' , $ T_NUM , ' 0' , $ T_STR , ' nqp.null_s' , $ T_INT16 , ' 0' , $ T_INT8 , ' 0' , $ T_UINT8 , ' 0' , $ T_UINT16 , ' 0' , $ T_UINT32 , ' 0 ' );
1707
1720
1708
1721
method declare_var (QAST ::Var $ node ) {
1709
1722
my int $ type := self . type_from_typeobj($ node . returns );
0 commit comments