Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some context introspection nqp:: ops.

Whatever VM we target, we'll need to be able to talk about these in a
first class way, and it'll be the same basic operations (chase the
outer or caller chain, look at lexicals, etc.)
  • Loading branch information...
commit acab2e79d406067ca21fdbfd3c07856296146e3c 1 parent 323c6fa
@jnthn jnthn authored
Showing with 43 additions and 0 deletions.
  1. +43 −0 src/QAST/Operations.nqp
View
43 src/QAST/Operations.nqp
@@ -965,6 +965,41 @@ QAST::Operations.add_core_op('lexotic', -> $qastcomp, $op {
});
# Context introspection
+QAST::Operations.add_core_op('ctx', -> $qastcomp, $op {
+ 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('ctxouter', -> $qastcomp, $op {
+ my $reg := $*REGALLOC.fresh_p();
+ my $ops := PIRT::Ops.new();
+ my $ctxpost := $qastcomp.coerce($qastcomp.as_post($op[0]), 'P');
+ $ops.push($ctxpost);
+ $ops.push_pirop('getattribute', $reg, $ctxpost, "'outer_ctx'");
+ $ops.result($reg);
+ $ops
+});
+QAST::Operations.add_core_op('ctxcaller', -> $qastcomp, $op {
+ my $reg := $*REGALLOC.fresh_p();
+ my $ops := PIRT::Ops.new();
+ my $ctxpost := $qastcomp.coerce($qastcomp.as_post($op[0]), 'P');
+ $ops.push($ctxpost);
+ $ops.push_pirop('getattribute', $reg, $ctxpost, "'caller_ctx'");
+ $ops.result($reg);
+ $ops
+});
+QAST::Operations.add_core_op('ctxlexpad', -> $qastcomp, $op {
+ my $reg := $*REGALLOC.fresh_p();
+ my $ops := PIRT::Ops.new();
+ my $ctxpost := $qastcomp.coerce($qastcomp.as_post($op[0]), 'P');
+ $ops.push($ctxpost);
+ $ops.push_pirop('getattribute', $reg, $ctxpost, "'lex_pad'");
+ $ops.result($reg);
+ $ops
+});
QAST::Operations.add_core_op('curlexpad', -> $qastcomp, $op {
my $reg := $*REGALLOC.fresh_p();
my $ops := PIRT::Ops.new();
@@ -981,6 +1016,14 @@ QAST::Operations.add_core_op('curcode', -> $qastcomp, $op {
$ops.result($reg);
$ops
});
+QAST::Operations.add_core_op('callercode', -> $qastcomp, $op {
+ my $reg := $*REGALLOC.fresh_p();
+ my $ops := PIRT::Ops.new();
+ $ops.push_pirop('getinterp', $reg);
+ $ops.push_pirop('set', $reg, $reg ~ "['sub';1]");
+ $ops.result($reg);
+ $ops
+});
# Exception handling/munging.
my $exc_exclude := 0;
Please sign in to comment.
Something went wrong with that request. Please try again.