Skip to content

Commit b04f59f

Browse files
committed
this actually works!
1 parent 1af1098 commit b04f59f

File tree

1 file changed

+108
-20
lines changed

1 file changed

+108
-20
lines changed

src/vm/parrot/QAST/Operations.nqp

Lines changed: 108 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,46 +2128,134 @@ QAST::Operations.add_core_pirop_mapping('r_bindpos_i', 'repr_bind_pos_int', '2Pi
21282128
QAST::Operations.add_core_pirop_mapping('r_bindpos_n', 'repr_bind_pos_num', '2Pin', :inlinable(1));
21292129
QAST::Operations.add_core_pirop_mapping('r_elems', 'repr_elems', 'IP', :inlinable(1));
21302130

2131+
sub str_or_want($op) {
2132+
nqp::istype($op, QAST::SVal) || nqp::istype($op, QAST::Want) && +@($op)[1] eq 'Ss' {
2133+
}
2134+
2135+
sub val_from_str_or_want($op) {
2136+
nqp::istype($op, QAST::SVal)
2137+
?? $op.value
2138+
!! $op[2].value
2139+
}
2140+
21312141
# object opcodes
21322142
QAST::Operations.add_core_pirop_mapping('bindattr', 'setattribute', '3PPsP', :inlinable(1));
2133-
QAST::Operations.add_core_op('bindattr_i', -> $qastcomp, $op {
2143+
QAST::Operations.add_core_pirop_mapping('bindattr_i_nh', 'repr_bind_attr_int', '3PPsi', :inlinable(1));
2144+
QAST::Operations.add_core_pirop_mapping('bindattr_i_h', 'repr_bind_attr_int', '3PPsii', :inlinable(1));
2145+
QAST::Operations.add_core_op('bindattr_i', :inlinable(1), -> $qastcomp, $op {
21342146
if +@($op) != 4 {
21352147
nqp::die('bindattr_i requires four operands');
21362148
}
2137-
if $op[1].has_compile_time_value && $op[2].has_compile_time_value {
2138-
my $hint := -1;
2139-
my $ops := PIRT::Ops.new();
2140-
$hint := pir::repr_hint_for__IPs($op[1].compile_time_value, $op[2].compile_time_value);
2141-
my $hint_reg := $*REGALLOC.fresh_i();
2142-
$hint := $qastcomp.coerce($qastcomp.as_post($hint), 'I');
2143-
$ops.push("# this bind_attr is improved");
2144-
$ops.push($hint);
2145-
$ops.push_pirop('set', $hint_reg, $hint);
2146-
$ops.push($qastcomp.as_post(QAST::VM.new(
2147-
:pirop<repr_bind_attr_int__0PPSII>,
2149+
my $hint := -1;
2150+
if nqp::istype($op[1], QAST::WVal) && str_or_want($op[2]) {
2151+
$hint := pir::repr_hint_for__IPs($op[1].value, val_from_str_or_want($op[2]));
2152+
}
2153+
if $hint != -1 {
2154+
$qastcomp.as_post(QAST::Op.new(
2155+
:op('bindattr_i_h'),
21482156
$op[0],
21492157
$op[1],
21502158
$op[2],
21512159
$op[3],
2152-
$hint_reg
2153-
)));
2154-
$ops;
2160+
QAST::IVal.new(:value($hint))
2161+
));
21552162
} else {
2156-
$qastcomp.as_post(QAST::VM.new(
2157-
:pirop<repr_bind_attr_int__0PPSI>,
2163+
$qastcomp.as_post(QAST::Op.new(
2164+
:op('bindattr_i_nh'),
21582165
$op[0],
21592166
$op[1],
21602167
$op[2],
21612168
$op[3]
2162-
))
2169+
));
21632170
}
21642171
});
21652172
QAST::Operations.add_core_pirop_mapping('bindattr_n', 'repr_bind_attr_num', '3PPsn', :inlinable(1));
21662173
QAST::Operations.add_core_pirop_mapping('bindattr_s', 'repr_bind_attr_str', '3PPss', :inlinable(1));
2174+
QAST::Operations.add_core_pirop_mapping('bindattr_s_nh', 'repr_bind_attr_int', '3PPss', :inlinable(1));
2175+
QAST::Operations.add_core_pirop_mapping('bindattr_s_h', 'repr_bind_attr_int', '3PPssi', :inlinable(1));
2176+
QAST::Operations.add_core_op('bindattr_s', :inlinable(1), -> $qastcomp, $op {
2177+
if +@($op) != 4 {
2178+
nqp::die('bindattr_s requires four operands');
2179+
}
2180+
my $hint := -1;
2181+
if nqp::istype($op[1], QAST::WVal) && str_or_want($op[2]) {
2182+
$hint := pir::repr_hint_for__IPs($op[1].value, val_from_str_or_want($op[2]));
2183+
}
2184+
if $hint != -1 {
2185+
$qastcomp.as_post(QAST::Op.new(
2186+
:op('bindattr_s_h'),
2187+
$op[0],
2188+
$op[1],
2189+
$op[2],
2190+
$op[3],
2191+
QAST::IVal.new(:value($hint))
2192+
));
2193+
} else {
2194+
$qastcomp.as_post(QAST::Op.new(
2195+
:op('bindattr_s_nh'),
2196+
$op[0],
2197+
$op[1],
2198+
$op[2],
2199+
$op[3]
2200+
));
2201+
}
2202+
});
21672203
QAST::Operations.add_core_pirop_mapping('getattr', 'getattribute', 'PPPs', :inlinable(1));
2168-
QAST::Operations.add_core_pirop_mapping('getattr_i', 'repr_get_attr_int', 'IPPs', :inlinable(1));
2204+
QAST::Operations.add_core_pirop_mapping('getattr_i_nh', 'repr_get_attr_int', 'IPPs', :inlinable(1));
2205+
QAST::Operations.add_core_pirop_mapping('getattr_i_h', 'repr_get_attr_int', 'IPPsi', :inlinable(1));
2206+
QAST::Operations.add_core_op('getattr_i', :inlinable(1), -> $qastcomp, $op {
2207+
if +@($op) != 3 {
2208+
nqp::die('getattr_i requires three operands');
2209+
}
2210+
my $hint := -1;
2211+
if nqp::istype($op[1], QAST::WVal) && str_or_want($op[2]) {
2212+
$hint := pir::repr_hint_for__IPs($op[1].value, val_from_str_or_want($op[2]));
2213+
}
2214+
if $hint != -1 {
2215+
$qastcomp.as_post(QAST::Op.new(
2216+
:op('getattr_i_h'),
2217+
$op[0],
2218+
$op[1],
2219+
$op[2],
2220+
QAST::IVal.new(:value($hint))
2221+
));
2222+
} else {
2223+
$qastcomp.as_post(QAST::Op.new(
2224+
:op('getattr_i_nh'),
2225+
$op[0],
2226+
$op[1],
2227+
$op[2]
2228+
));
2229+
}
2230+
});
21692231
QAST::Operations.add_core_pirop_mapping('getattr_n', 'repr_get_attr_num', 'NPPs', :inlinable(1));
2170-
QAST::Operations.add_core_pirop_mapping('getattr_s', 'repr_get_attr_str', 'SPPs', :inlinable(1));
2232+
QAST::Operations.add_core_pirop_mapping('getattr_s_nh', 'repr_get_attr_str', 'SPPs', :inlinable(1));
2233+
QAST::Operations.add_core_pirop_mapping('getattr_s_h', 'repr_get_attr_str', 'SPPsi', :inlinable(1));
2234+
QAST::Operations.add_core_op('getattr_s', :inlinable(1), -> $qastcomp, $op {
2235+
if +@($op) != 3 {
2236+
nqp::die('getattr_s requires three operands');
2237+
}
2238+
my $hint := -1;
2239+
if nqp::istype($op[1], QAST::WVal) && str_or_want($op[2]) {
2240+
$hint := pir::repr_hint_for__IPs($op[1].value, val_from_str_or_want($op[2]));
2241+
}
2242+
if $hint != -1 {
2243+
$qastcomp.as_post(QAST::Op.new(
2244+
:op('getattr_s_h'),
2245+
$op[0],
2246+
$op[1],
2247+
$op[2],
2248+
QAST::IVal.new(:value($hint))
2249+
));
2250+
} else {
2251+
$qastcomp.as_post(QAST::Op.new(
2252+
:op('getattr_s_nh'),
2253+
$op[0],
2254+
$op[1],
2255+
$op[2]
2256+
));
2257+
}
2258+
});
21712259
QAST::Operations.add_core_pirop_mapping('attrinited', 'repr_is_attr_initialized', 'IPPs', :inlinable(1));
21722260
QAST::Operations.add_core_pirop_mapping('create', 'repr_instance_of', 'PP', :inlinable(1));
21732261
QAST::Operations.add_core_pirop_mapping('clone', 'repr_clone', 'PP', :inlinable(1));

0 commit comments

Comments
 (0)