Navigation Menu

Skip to content

Commit

Permalink
Ensure return types are set up for nqp:: ops.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed May 2, 2014
1 parent 55c7277 commit 6c1ac9f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/vm/moar/QAST/QASTOperationsMAST.nqp
Expand Up @@ -300,6 +300,7 @@ class QAST::MASTOperations {
$moarop_mapper($qastcomp, $op.op, $op.list)
};
self.set_core_op_inlinability($op, $inlinable);
self.set_core_op_result_type($op, moarop_return_type($moarop));
}

# Adds a HLL op that maps to a Moar op.
Expand All @@ -312,6 +313,7 @@ class QAST::MASTOperations {
$moarop_mapper($qastcomp, $op.op, $op.list)
};
self.set_hll_op_inlinability($hll, $op, $inlinable);
self.set_hll_op_result_type($hll, $op, moarop_return_type($moarop));
}

# Returns a mapper closure for turning an operation into a Moar op.
Expand Down Expand Up @@ -360,6 +362,34 @@ class QAST::MASTOperations {
}
}

# Gets the return type of a MoarVM op, if any.
sub moarop_return_type($moarop) {
if nqp::existskey(%core_op_codes, $moarop) {
my int $op_num := %core_op_codes{$moarop};
my int $num_operands := nqp::atpos_i(@core_operands_counts, $op_num);
if $num_operands {
my int $operands_offset := nqp::atpos_i(@core_operands_offsets, $op_num);
my int $ret_sig := nqp::atpos_i(@core_operands_values, $operands_offset);
if ($ret_sig +& $MVM_operand_rw_mask) == $MVM_operand_write_reg {
return nqp::bitshiftr_i($ret_sig, 3);
}
}
}
elsif MAST::ExtOpRegistry.extop_known($moarop) {
my @operands_values := MAST::ExtOpRegistry.extop_signature($moarop);
if @operands_values {
my int $ret_sig := nqp::atpos_i(@operands_values, 0);
if ($ret_sig +& $MVM_operand_rw_mask) == $MVM_operand_write_reg {
return nqp::bitshiftr_i($ret_sig, 3);
}
}
}
else {
nqp::die("MoarVM op '$moarop' is unknown as a core or extension op");
}
0
}

# Sets op native result type at a core level.
method set_core_op_result_type($op, $type) {
if $type == $MVM_reg_int64 {
Expand Down

0 comments on commit 6c1ac9f

Please sign in to comment.