Skip to content

Commit d1a15a1

Browse files
committed
Make QAST -> MAST respect size differences.
1 parent 028062f commit d1a15a1

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

src/vm/moar/QAST/QASTCompilerMAST.nqp

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ my class MASTCompilerInstance {
2828
my class RegAlloc {
2929
has $!frame;
3030
has @!objs;
31-
has @!ints;
32-
has @!nums;
31+
has @!int64s;
32+
has @!int32s;
33+
has @!int16s;
34+
has @!int8s;
35+
has @!num64s;
36+
has @!num32s;
3337
has @!strs;
3438
has %!released_indexes;
3539

3640
method new($frame) {
3741
my $obj := nqp::create(self);
3842
nqp::bindattr($obj, RegAlloc, '$!frame', $frame);
3943
nqp::bindattr($obj, RegAlloc, '@!objs', []);
40-
nqp::bindattr($obj, RegAlloc, '@!ints', []);
41-
nqp::bindattr($obj, RegAlloc, '@!nums', []);
44+
nqp::bindattr($obj, RegAlloc, '@!int64s', []);
45+
nqp::bindattr($obj, RegAlloc, '@!int32s', []);
46+
nqp::bindattr($obj, RegAlloc, '@!int16s', []);
47+
nqp::bindattr($obj, RegAlloc, '@!int8s', []);
48+
nqp::bindattr($obj, RegAlloc, '@!num64s', []);
49+
nqp::bindattr($obj, RegAlloc, '@!num32s', []);
4250
nqp::bindattr($obj, RegAlloc, '@!strs', []);
4351
nqp::bindattr($obj, RegAlloc, '%!released_indexes', {});
4452
$obj
@@ -57,10 +65,14 @@ my class MASTCompilerInstance {
5765
# set $new to 1 here if you suspect a problem with the allocator,
5866
# or if you suspect a register is being double-released somewhere.
5967
# $new := 1;
60-
if $kind == $MVM_reg_int64 { @arr := @!ints; $type := int }
61-
elsif $kind == $MVM_reg_num64 { @arr := @!nums; $type := num }
68+
if $kind == $MVM_reg_int64 { @arr := @!int64s; $type := int }
69+
elsif $kind == $MVM_reg_num64 { @arr := @!num64s; $type := num }
6270
elsif $kind == $MVM_reg_str { @arr := @!strs; $type := str }
6371
elsif $kind == $MVM_reg_obj { @arr := @!objs; $type := NQPMu }
72+
elsif $kind == $MVM_reg_int32 { @arr := @!int32s; $type := int32 }
73+
elsif $kind == $MVM_reg_int16 { @arr := @!int16s; $type := int16 }
74+
elsif $kind == $MVM_reg_int8 { @arr := @!int8s; $type := int8 }
75+
elsif $kind == $MVM_reg_num32 { @arr := @!num32s; $type := num32 }
6476
else { nqp::die("unhandled reg kind $kind") }
6577

6678
my $reg;
@@ -83,10 +95,14 @@ my class MASTCompilerInstance {
8395
return 1 if $kind == $MVM_reg_void || !$force && $*BLOCK.is_var($reg)
8496
|| nqp::existskey(%!released_indexes, $reg.index);
8597
%!released_indexes{$reg.index} := 1;
86-
return nqp::push(@!ints, $reg) if $kind == $MVM_reg_int64;
87-
return nqp::push(@!nums, $reg) if $kind == $MVM_reg_num64;
98+
return nqp::push(@!int64s, $reg) if $kind == $MVM_reg_int64;
99+
return nqp::push(@!num64s, $reg) if $kind == $MVM_reg_num64;
88100
return nqp::push(@!strs, $reg) if $kind == $MVM_reg_str;
89101
return nqp::push(@!objs, $reg) if $kind == $MVM_reg_obj;
102+
return nqp::push(@!int32s, $reg) if $kind == $MVM_reg_int32;
103+
return nqp::push(@!int16s, $reg) if $kind == $MVM_reg_int16;
104+
return nqp::push(@!int8s, $reg) if $kind == $MVM_reg_int8;
105+
return nqp::push(@!num32s, $reg) if $kind == $MVM_reg_num32;
90106
nqp::die("unhandled reg kind $kind");
91107
}
92108
}
@@ -1814,7 +1830,32 @@ my class MASTCompilerInstance {
18141830

18151831
my @prim_to_reg := [$MVM_reg_obj, $MVM_reg_int64, $MVM_reg_num64, $MVM_reg_str];
18161832
method type_to_register_kind($type) {
1817-
@prim_to_reg[nqp::isnull($type) ?? 0 !! nqp::objprimspec($type)]
1833+
if nqp::isnull($type) {
1834+
$MVM_reg_obj
1835+
}
1836+
else {
1837+
my int $primspec := nqp::objprimspec($type);
1838+
if $primspec == 0 {
1839+
$MVM_reg_obj
1840+
}
1841+
elsif $primspec == 1 {
1842+
my int $size := nqp::objprimbits($type);
1843+
if $size == 64 { $MVM_reg_int64 }
1844+
elsif $size == 32 { $MVM_reg_int32 }
1845+
elsif $size == 16 { $MVM_reg_int16 }
1846+
elsif $size == 8 { $MVM_reg_int8 }
1847+
else { nqp::die("Unknown int size $size") }
1848+
}
1849+
elsif $primspec == 2 {
1850+
my int $size := nqp::objprimbits($type);
1851+
if $size == 64 { $MVM_reg_num64 }
1852+
elsif $size == 32 { $MVM_reg_num32 }
1853+
else { nqp::die("Unknown num size $size") }
1854+
}
1855+
else {
1856+
$MVM_reg_str
1857+
}
1858+
}
18181859
}
18191860
}
18201861

0 commit comments

Comments
 (0)