Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement nqp::getstaticcode.
  • Loading branch information
jnthn committed Mar 9, 2013
1 parent ce2ff53 commit c7ef5f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -1843,6 +1843,7 @@ QAST::OperationsJAST.map_classlib_core_op('forceouterctx', $TYPE_OPS, 'forceoute
QAST::OperationsJAST.map_classlib_core_op('freshcoderef', $TYPE_OPS, 'freshcoderef', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('markcodestatic', $TYPE_OPS, 'markcodestatic', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('markcodestub', $TYPE_OPS, 'markcodestub', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('getstaticcode', $TYPE_OPS, 'getstaticcode', [$RT_OBJ], $RT_OBJ, :tc);

# language/compiler ops
QAST::OperationsJAST.map_classlib_core_op('getcomp', $TYPE_OPS, 'getcomp', [$RT_STR], $RT_OBJ, :tc);
Expand Down
2 changes: 1 addition & 1 deletion src/org/perl6/nqp/runtime/CodeRef.java
Expand Up @@ -43,7 +43,7 @@ public CodeRef(CompilationUnit compUnit, MethodHandle mh,
long[][] handlers) {
staticInfo = new StaticCodeInfo(compUnit, mh, name,uniqueId,
oLexicalNames, iLexicalNames, nLexicalNames, sLexicalNames,
handlers);
handlers, this);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -2621,6 +2621,12 @@ public static SixModelObject markcodestub(SixModelObject code, ThreadContext tc)
((CodeRef)code).isCompilerStub = true;
return code;
}
public static SixModelObject getstaticcode(SixModelObject code, ThreadContext tc) {
if (code instanceof CodeRef)
return ((CodeRef)code).staticInfo.staticCode;
else
throw ExceptionHandling.dieInternal(tc, "getstaticcode can only be used with a CodeRef");
}

/* process related opcodes */
public static long exit(final long status) {
Expand Down
8 changes: 7 additions & 1 deletion src/org/perl6/nqp/runtime/StaticCodeInfo.java
Expand Up @@ -54,6 +54,11 @@ public class StaticCodeInfo implements Cloneable {
*/
public long[][] handlers;

/**
* Static code object (base of any clones).
*/
public SixModelObject staticCode;

/**
* Lexical name maps (produced lazily on first use). Note they are only
* used when we do lexical lookup by name.
Expand Down Expand Up @@ -114,7 +119,7 @@ public StaticCodeInfo(CompilationUnit compUnit, MethodHandle mh,
String name, String uniqueId,
String[] oLexicalNames, String[] iLexicalNames,
String[] nLexicalNames, String[] sLexicalNames,
long[][] handlers) {
long[][] handlers, SixModelObject staticCode) {
this.compUnit = compUnit;
this.mh = mh;
this.name = name;
Expand All @@ -124,6 +129,7 @@ public StaticCodeInfo(CompilationUnit compUnit, MethodHandle mh,
this.nLexicalNames = nLexicalNames;
this.sLexicalNames = sLexicalNames;
this.handlers = handlers;
this.staticCode = staticCode;
if (oLexicalNames != null)
this.oLexStatic = new SixModelObject[oLexicalNames.length];
}
Expand Down

0 comments on commit c7ef5f0

Please sign in to comment.