Skip to content

Commit 2884c8a

Browse files
committed
Fill out sized num box/unbox handling.
1 parent 1fbfd04 commit 2884c8a

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/vm/moar/QAST/QASTCompilerMAST.nqp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,41 @@ my class MASTCompilerInstance {
397397
}
398398
elsif $desired == $MVM_reg_void {
399399
$reg := MAST::VOID;
400-
$got := $MVM_reg_void;
401400
}
402401
elsif $desired == $MVM_reg_obj {
403-
return QAST::MASTOperations.box(self, $!hll, $got, $reg);
402+
# See if we already have full-width native.
403+
if $got == $MVM_reg_int64 || $got == $MVM_reg_num64 ||
404+
$got == $MVM_reg_str || $got == $MVM_reg_void {
405+
return QAST::MASTOperations.box(self, $!hll, $got, $reg);
406+
}
407+
elsif $got == $MVM_reg_num32 {
408+
my $grow := self.coercion($res, $MVM_reg_num64);
409+
my $box := QAST::MASTOperations.box(self, $!hll, $MVM_reg_num64,
410+
$grow.result_reg);
411+
$il := $grow.instructions;
412+
push_ilist($il, $box);
413+
$*REGALLOC.release_register($grow.result_reg, $MVM_reg_num64);
414+
$reg := $box.result_reg;
415+
}
416+
else {
417+
nqp::die("Unknown boxing case; got: " ~ $got);
418+
}
404419
}
405420
elsif $got == $MVM_reg_obj {
406-
return QAST::MASTOperations.unbox(self, $!hll, $desired, $reg);
421+
# See if we want a full-width native.
422+
if $desired == $MVM_reg_int64 || $desired == $MVM_reg_num64 || $desired == $MVM_reg_str {
423+
return QAST::MASTOperations.unbox(self, $!hll, $desired, $reg);
424+
}
425+
elsif $desired == $MVM_reg_num32 {
426+
my $unbox := QAST::MASTOperations.unbox(self, $!hll, $MVM_reg_num64, $reg);
427+
my $shrink := self.coercion($unbox, $desired);
428+
$il := $unbox.instructions;
429+
push_ilist($il, $shrink);
430+
$reg := $shrink.result_reg;
431+
}
432+
else {
433+
nqp::die("Unknown unboxing case; desired: " ~ $desired);
434+
}
407435
}
408436
else {
409437
my $res_reg := $*REGALLOC.fresh_register($desired);

0 commit comments

Comments
 (0)