Skip to content

Commit

Permalink
Implement a few more code object ops.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Feb 24, 2013
1 parent 90585d7 commit 2a4dea6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,9 @@ QAST::OperationsJAST.add_core_op('setstaticlex', -> $qastcomp, $op {
result($il, $RT_OBJ)
});
QAST::OperationsJAST.map_classlib_core_op('forceouterctx', $TYPE_OPS, 'forceouterctx', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
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);

# language/compiler ops
QAST::OperationsJAST.map_classlib_core_op('getcomp', $TYPE_OPS, 'getcomp', [$RT_STR], $RT_OBJ, :tc);
Expand Down
10 changes: 10 additions & 0 deletions src/org/perl6/nqp/runtime/CodeRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public class CodeRef extends SixModelObject {
*/
public SixModelObject codeObject;

/**
* Is this flagged as a static code ref?
*/
public boolean isStaticCodeRef;

/**
* Is this flagged as a compiler stub?
*/
public boolean isCompilerStub;

/**
* Sets up the code-ref data structure.
*/
Expand Down
19 changes: 19 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,25 @@ public static SixModelObject forceouterctx(SixModelObject code, SixModelObject c
((CodeRef)code).outer = ((ContextRefInstance)ctx).context;
return code;
}
public static SixModelObject freshcoderef(SixModelObject code, ThreadContext tc) {
if (!(code instanceof CodeRef))
throw new RuntimeException("freshcoderef must be used on a CodeRef");
CodeRef clone = (CodeRef)code.clone(tc);
clone.staticInfo = clone.staticInfo.clone();
return clone;
}
public static SixModelObject markcodestatic(SixModelObject code, ThreadContext tc) {
if (!(code instanceof CodeRef))
throw new RuntimeException("freshcoderef must be used on a CodeRef");
((CodeRef)code).isStaticCodeRef = true;
return code;
}
public static SixModelObject markcodestub(SixModelObject code, ThreadContext tc) {
if (!(code instanceof CodeRef))
throw new RuntimeException("freshcoderef must be used on a CodeRef");
((CodeRef)code).isCompilerStub = true;
return code;
}

/* process related opcodes */
public static long exit(final long status) {
Expand Down
14 changes: 13 additions & 1 deletion src/org/perl6/nqp/runtime/StaticCodeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.perl6.nqp.sixmodel.SixModelObject;

public class StaticCodeInfo {
public class StaticCodeInfo implements Cloneable {
/**
* The compilation unit where the code lives.
*/
Expand Down Expand Up @@ -138,4 +138,16 @@ public StaticCodeInfo(CompilationUnit compUnit, int idx, String name, String uni
if (oLexicalNames != null)
this.oLexStatic = new SixModelObject[oLexicalNames.length];
}

public StaticCodeInfo clone() {
try {
StaticCodeInfo result = (StaticCodeInfo)super.clone();
if (result.oLexStatic != null)
result.oLexStatic = result.oLexStatic.clone();
return result;
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 2a4dea6

Please sign in to comment.