Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a (per-HLL configurable) to do positional and associative lookup/…
…binding using a QAST::Var. This may mean that even Rakudo can use this approach for its array/hash accesses, by configuring them to call the appropriate methods. Doing things that way come in highly useful with analysis/optimization of native array accesses.
  • Loading branch information
jnthn committed Aug 7, 2012
1 parent 64f922a commit 207256a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/QAST/Compiler.nqp
Expand Up @@ -825,6 +825,16 @@ class QAST::Compiler is HLL::Compiler {
$ops.result($res_reg);
}
}
elsif $scope eq 'positional' {
$ops := self.as_post_clear_bindval($*BINDVAL
?? QAST::Op.new( :op('positional_bind'), |$node.list, $*BINDVAL)
!! QAST::Op.new( :op('positional_get'), |$node.list));
}
elsif $scope eq 'associative' {
$ops := self.as_post_clear_bindval($*BINDVAL
?? QAST::Op.new( :op('associative_bind'), |$node.list, $*BINDVAL)
!! QAST::Op.new( :op('associative_get'), |$node.list));
}
else {
pir::die("QAST::Var with scope '$scope' NYI");
}
Expand Down
6 changes: 6 additions & 0 deletions src/QAST/Operations.nqp
Expand Up @@ -1121,6 +1121,12 @@ QAST::Operations.add_hll_unbox('nqp', 's', -> $qastcomp, $post {
$ops
});

# Default way to do positional and associative lookups.
QAST::Operations.add_core_pirop_mapping('positional_get', 'set', 'PQi', :inlinable(1));
QAST::Operations.add_core_pirop_mapping('positional_bind', 'set', '1QiP', :inlinable(1));
QAST::Operations.add_core_pirop_mapping('associative_get', 'set', 'PQs', :inlinable(1));
QAST::Operations.add_core_pirop_mapping('associative_bind', 'set', '1QsP', :inlinable(1));

# I/O opcodes
QAST::Operations.add_core_pirop_mapping('print', 'print', '0s', :inlinable(1));
QAST::Operations.add_core_pirop_mapping('say', 'say', '0s', :inlinable(1));
Expand Down

0 comments on commit 207256a

Please sign in to comment.