Skip to content

Commit 28b6851

Browse files
committed
Various sized int box/unbox/coercion cases.
1 parent 2884c8a commit 28b6851

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/vm/moar/QAST/QASTCompilerMAST.nqp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,14 @@ my class MASTCompilerInstance {
410410
$grow.result_reg);
411411
$il := $grow.instructions;
412412
push_ilist($il, $box);
413-
$*REGALLOC.release_register($grow.result_reg, $MVM_reg_num64);
413+
$reg := $box.result_reg;
414+
}
415+
elsif $got == $MVM_reg_int32 || $got == $MVM_reg_int16 || $got == $MVM_reg_int8 {
416+
my $grow := self.coercion($res, $MVM_reg_int64);
417+
my $box := QAST::MASTOperations.box(self, $!hll, $MVM_reg_int64,
418+
$grow.result_reg);
419+
$il := $grow.instructions;
420+
push_ilist($il, $box);
414421
$reg := $box.result_reg;
415422
}
416423
else {
@@ -429,6 +436,13 @@ my class MASTCompilerInstance {
429436
push_ilist($il, $shrink);
430437
$reg := $shrink.result_reg;
431438
}
439+
elsif $desired == $MVM_reg_int32 || $desired == $MVM_reg_int16 || $desired == $MVM_reg_int8 {
440+
my $unbox := QAST::MASTOperations.unbox(self, $!hll, $MVM_reg_int64, $reg);
441+
my $shrink := self.coercion($unbox, $desired);
442+
$il := $unbox.instructions;
443+
push_ilist($il, $shrink);
444+
$reg := $shrink.result_reg;
445+
}
432446
else {
433447
nqp::die("Unknown unboxing case; desired: " ~ $desired);
434448
}
@@ -445,6 +459,15 @@ my class MASTCompilerInstance {
445459
elsif $got == $MVM_reg_void {
446460
push_op($il, 'const_i64', $res_reg, MAST::IVal.new( :value(0) ));
447461
}
462+
elsif $got == $MVM_reg_int32 {
463+
push_op($il, 'extend_i32', $res_reg, $reg);
464+
}
465+
elsif $got == $MVM_reg_int16 {
466+
push_op($il, 'extend_i16', $res_reg, $reg);
467+
}
468+
elsif $got == $MVM_reg_int8 {
469+
push_op($il, 'extend_i8', $res_reg, $reg);
470+
}
448471
else {
449472
nqp::die("Unknown coercion case for int; got: "~$got);
450473
}
@@ -488,6 +511,30 @@ my class MASTCompilerInstance {
488511
nqp::die("Unknown coercion case for num32; got: "~$got);
489512
}
490513
}
514+
elsif $desired == $MVM_reg_int32 {
515+
if $got == $MVM_reg_int64 {
516+
push_op($il, 'trunc_i32', $res_reg, $reg);
517+
}
518+
else {
519+
nqp::die("Unknown coercion case for int32; got: " ~ $got);
520+
}
521+
}
522+
elsif $desired == $MVM_reg_int16 {
523+
if $got == $MVM_reg_int64 {
524+
push_op($il, 'trunc_i16', $res_reg, $reg);
525+
}
526+
else {
527+
nqp::die("Unknown coercion case for int16; got: " ~ $got);
528+
}
529+
}
530+
elsif $desired == $MVM_reg_int8 {
531+
if $got == $MVM_reg_int64 {
532+
push_op($il, 'trunc_i8', $res_reg, $reg);
533+
}
534+
else {
535+
nqp::die("Unknown coercion case for int8; got: " ~ $got);
536+
}
537+
}
491538
else {
492539
nqp::die("Coercion from type '$got' to '$desired' NYI");
493540
}

0 commit comments

Comments
 (0)