Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement getcodeobj/setcodeobj.
  • Loading branch information
jnthn committed Feb 1, 2013
1 parent 18e278b commit 78376f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -1413,6 +1413,8 @@ QAST::OperationsJAST.map_classlib_core_op('bindlex_s', $TYPE_OPS, 'bindlex_s', [

# code object related opcodes
QAST::OperationsJAST.map_classlib_core_op('takeclosure', $TYPE_OPS, 'takeclosure', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('getcodeobj', $TYPE_OPS, 'getcodeobj', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('setcodeobj', $TYPE_OPS, 'setcodeobj', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('getcodename', $TYPE_OPS, 'getcodename', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('setcodename', $TYPE_OPS, 'setcodename', [$RT_OBJ, $RT_STR], $RT_OBJ, :tc);
QAST::OperationsJAST.add_core_op('setstaticlex', -> $qastcomp, $op {
Expand Down
15 changes: 15 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -1711,6 +1711,21 @@ public static SixModelObject takeclosure(SixModelObject code, ThreadContext tc)
throw new RuntimeException("takeclosure can only be used with a CodeRef");
}
}
public static SixModelObject getcodeobj(SixModelObject code, ThreadContext tc) {
if (code instanceof CodeRef)
return ((CodeRef)code).staticInfo.codeObject;
else
throw new RuntimeException("getcodeobj can only be used with a CodeRef");
}
public static SixModelObject setcodeobj(SixModelObject code, SixModelObject obj, ThreadContext tc) {
if (code instanceof CodeRef) {
((CodeRef)code).staticInfo.codeObject = obj;
return code;
}
else {
throw new RuntimeException("setcodeobj can only be used with a CodeRef");
}
}
public static String getcodename(SixModelObject code, ThreadContext tc) {
if (code instanceof CodeRef)
return ((CodeRef)code).staticInfo.name;
Expand Down
5 changes: 5 additions & 0 deletions src/org/perl6/nqp/runtime/StaticCodeInfo.java
Expand Up @@ -35,6 +35,11 @@ public class StaticCodeInfo {
*/
public CallFrame priorInvocation;

/**
* High level code object, if any.
*/
public SixModelObject codeObject;

/**
* Maximum argument counts by argument type.
*/
Expand Down

0 comments on commit 78376f6

Please sign in to comment.