Skip to content

Instantly share code, notes, and snippets.

@diakopter
Forked from timo/gist:1805bb7bbbc6c2aa5140
Last active January 4, 2016 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diakopter/b2522f054f633fc4cc0a to your computer and use it in GitHub Desktop.
Save diakopter/b2522f054f633fc4cc0a to your computer and use it in GitHub Desktop.
sub add_bindattr_op($nqpop, $hintedop, $namedop, $want) {
QAST::MASTOperations.add_core_op($nqpop, -> $qastcomp, $op {
my $val_mast := $qastcomp.as_mast( :$want, $op[3] );
my $obj_mast := $qastcomp.as_mast( $op[0] );
my $type_mast := $qastcomp.as_mast( $op[1] );
my int $hint := -1;
my @ins;
push_ilist(@ins, $obj_mast);
push_ilist(@ins, $val_mast);
push_ilist(@ins, $type_mast);
push_op(@ins, 'decont', $type_mast.result_reg, $type_mast.result_reg);
if nqp::istype($op[2], QAST::SVal) {
if nqp::istype($op[1], QAST::WVal) {
$hint := nqp::hintfor($op[1].value, $op[2].value);
}
push_op(@ins, $hintedop, $obj_mast.result_reg, $type_mast.result_reg,
MAST::SVal.new( :value($op[2].value) ),
$val_mast.result_reg, MAST::IVal.new( :value($hint) ));
} else {
my $name_mast := $qastcomp.as_mast( :want($MVM_reg_str), $op[2] );
push_op(@ins, $namedop, $obj_mast.result_reg, $type_mast.result_reg,
$name_mast.result_reg, $val_mast.result_reg);
$*REGALLOC.release_register($name_mast.result_reg, $MVM_reg_str);
}
$*REGALLOC.release_register($obj_mast.result_reg, $MVM_reg_obj);
$*REGALLOC.release_register($type_mast.result_reg, $MVM_reg_obj);
MAST::InstructionList.new(@ins, $val_mast.result_reg, $want)
})
}
add_bindattr_op('bindattr', 'bindattr_o', 'bindattrs_o', $MVM_reg_obj);
add_bindattr_op('bindattr_i', 'bindattr_i', 'bindattrs_i', $MVM_reg_int64);
add_bindattr_op('bindattr_n', 'bindattr_n', 'bindattrs_n', $MVM_reg_num64);
add_bindattr_op('bindattr_s', 'bindattr_s', 'bindattrs_s', $MVM_reg_str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment