Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement nqp::curcode() and nqp::callercode().
  • Loading branch information
jnthn committed Jan 23, 2013
1 parent eb06569 commit aadb6da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -1153,6 +1153,8 @@ QAST::OperationsJAST.add_hll_unbox('', $RT_STR, -> $qastcomp {
QAST::OperationsJAST.map_classlib_core_op('ctx', $TYPE_OPS, 'ctx', [], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('ctxouter', $TYPE_OPS, 'ctxouter', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('ctxcaller', $TYPE_OPS, 'ctxcaller', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('curcode', $TYPE_OPS, 'curcode', [], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('callercode', $TYPE_OPS, 'callercode', [], $RT_OBJ, :tc);

# Default way to do positional and associative lookups.
QAST::OperationsJAST.map_classlib_core_op('positional_get', $TYPE_OPS, 'atpos', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);
Expand Down
7 changes: 7 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -410,6 +410,13 @@ public static SixModelObject ctxcaller(SixModelObject ctx, ThreadContext tc) {
throw new RuntimeException("ctxcaller requires an operand with REPR ContextRef");
}
}
public static SixModelObject curcode(ThreadContext tc) {
return tc.curFrame.codeRef;
}
public static SixModelObject callercode(ThreadContext tc) {
CallFrame caller = tc.curFrame.caller;
return caller == null ? null : caller.codeRef;
}

/* Argument setting. */
public static void arg(long v, long[] args, int i) { args[i] = v; }
Expand Down

0 comments on commit aadb6da

Please sign in to comment.