Skip to content

Commit

Permalink
Add some ops for capture manipulation.
Browse files Browse the repository at this point in the history
This will enable porting of most of the multi-dispatch code to NQP.
  • Loading branch information
jnthn committed Feb 7, 2013
1 parent a0bba92 commit 3089165
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/QAST/Operations.nqp
Expand Up @@ -1034,6 +1034,35 @@ QAST::Operations.add_core_op('lexprimspec', -> $qastcomp, $op {
))
});

# Argument capture processing, for writing things like multi-dispatchers in
# high level languages.
QAST::Operations.add_core_op('usecapture', -> $qastcomp, $op {
# On Parrot, the current CallContext has the current args, so just use it.
my $reg := $*REGALLOC.fresh_p();
my $ops := PIRT::Ops.new();
$ops.push_pirop('getinterp', $reg);
$ops.push_pirop('set', $reg, $reg ~ "['context']");
$ops.result($reg);
$ops
});
QAST::Operations.add_core_op('savecapture', -> $qastcomp, $op {
# On Parrot, CallContext contains the args and is immutable, so we
# don't need to do anything more than map this to returning the
# current context.
my $reg := $*REGALLOC.fresh_p();
my $ops := PIRT::Ops.new();
$ops.push_pirop('getinterp', $reg);
$ops.push_pirop('set', $reg, $reg ~ "['context']");
$ops.result($reg);
$ops
});
QAST::Operations.add_core_pirop_mapping('captueposelems', 'elements', 'IP');
QAST::Operations.add_core_pirop_mapping('captueposarg', 'set', 'PQi');
QAST::Operations.add_core_pirop_mapping('captueposarg_i', 'set', 'IQi');
QAST::Operations.add_core_pirop_mapping('captueposarg_n', 'set', 'NQi');
QAST::Operations.add_core_pirop_mapping('captueposarg_s', 'set', 'SQi');
QAST::Operations.add_core_pirop_mapping('captueposprimspec', 'captueposprimspec', 'IPi');

# Exception handling/munging.
my $exc_exclude := 0;
my $exc_include := 1;
Expand Down

0 comments on commit 3089165

Please sign in to comment.