Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add and start writing out code ref annotation.
Not yet being used for anything.
  • Loading branch information
jnthn committed May 18, 2013
1 parent 43cd500 commit 66f45f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/jast2bc/JASTToJVMBytecode.java
Expand Up @@ -14,6 +14,7 @@
import java.util.Map;
import java.util.Stack;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
Expand Down Expand Up @@ -241,6 +242,36 @@ else if (curLine.startsWith("++ handlers ")) {
? Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC
: Opcodes.ACC_PUBLIC),
methodName, desc, null, null);

// Add code ref info annotation.
if (crName != null) {
Type crAnnType = Type.getType("Lorg/perl6/nqp/runtime/CodeRefAnnotation;");
AnnotationVisitor av = m.visitAnnotation(crAnnType.getDescriptor(), true);
av.visit("name", crName);
av.visit("cuid", crCuid);
av.visit("outerCuid", crOuter);

AnnotationVisitor avLex;
avLex = av.visitArray("oLexicalNames");
for (int i = 0; i < croLex.size(); i++)
avLex.visit(null, croLex.get(i));
avLex.visitEnd();
avLex = av.visitArray("iLexicalNames");
for (int i = 0; i < criLex.size(); i++)
avLex.visit(null, criLex.get(i));
avLex.visitEnd();
avLex = av.visitArray("nLexicalNames");
for (int i = 0; i < crnLex.size(); i++)
avLex.visit(null, crnLex.get(i));
avLex.visitEnd();
avLex = av.visitArray("sLexicalNames");
for (int i = 0; i < crsLex.size(); i++)
avLex.visit(null, crsLex.get(i));
avLex.visitEnd();

av.visit("handlers", crHandlers);
av.visitEnd();
}

// Add locals.
for (Map.Entry<String, VariableDef> e : localVariables.entrySet()) {
Expand Down
17 changes: 17 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/CodeRefAnnotation.java
@@ -0,0 +1,17 @@
package org.perl6.nqp.runtime;

import java.lang.annotation.*;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CodeRefAnnotation
{
String name();
String cuid();
String outerCuid();
String[] oLexicalNames();
String[] iLexicalNames();
String[] nLexicalNames();
String[] sLexicalNames();
long[] handlers();
}

0 comments on commit 66f45f7

Please sign in to comment.