Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start preparing to kill off getCodeRefs().
Will attempt to use annotations to convey this information instead.
  • Loading branch information
jnthn committed May 18, 2013
1 parent 9756183 commit 99dbf54
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/vm/jvm/QAST/JASTNodes.nqp
Expand Up @@ -57,7 +57,7 @@ class JAST::Field {
method name(*@value) { @value ?? ($!name := @value[0]) !! $!name }
method type(*@value) { @value ?? ($!type := @value[0]) !! $!type }
method static(*@value) { @value ?? ($!static := @value[0]) !! $!static }

method dump() {
"+ field $!name $!type " ~ ($!static ?? 'static' !! 'instance')
}
Expand Down Expand Up @@ -112,6 +112,14 @@ class JAST::Method is JAST::Node {
has @!arguments;
has @!locals;
has @!instructions;
has str $!cr_name;
has str $!cr_cuid;
has str $!cr_outer;
has @!cr_olex;
has @!cr_ilex;
has @!cr_nlex;
has @!cr_slex;
has @!cr_handlers;

method BUILD(:$name!, :$returns!, :$static = 1) {
$!name := $name;
Expand All @@ -120,6 +128,11 @@ class JAST::Method is JAST::Node {
@!arguments := [];
@!locals := [];
@!instructions := [];
@!cr_olex := [];
@!cr_ilex := [];
@!cr_nlex := [];
@!cr_slex := [];
@!cr_handlers := [];
}

method add_argument($name, $type) {
Expand Down Expand Up @@ -150,6 +163,15 @@ class JAST::Method is JAST::Node {
method locals() { @!locals }
method instructions() { @!instructions }

method cr_name(*@value) { @value ?? ($!cr_name := @value[0]) !! $!cr_name }
method cr_cuid(*@value) { @value ?? ($!cr_cuid := @value[0]) !! $!cr_cuid }
method cr_outer(*@value) { @value ?? ($!cr_outer := @value[0]) !! $!cr_outer }
method cr_olex(*@value) { @value ?? (@!cr_olex := @value[0]) !! @!cr_olex }
method cr_ilex(*@value) { @value ?? (@!cr_ilex := @value[0]) !! @!cr_ilex }
method cr_nlex(*@value) { @value ?? (@!cr_nlex := @value[0]) !! @!cr_nlex }
method cr_slex(*@value) { @value ?? (@!cr_slex := @value[0]) !! @!cr_slex }
method cr_handlers(*@value) { @value ?? (@!cr_handlers := @value[0]) !! @!cr_handlers }

method dump() {
my @dumped;
nqp::push(@dumped, "+ method");
Expand All @@ -164,6 +186,14 @@ class JAST::Method is JAST::Node {
for @!locals {
nqp::push(@dumped, "++ local " ~ $_[0] ~ " " ~ $_[1]);
}
nqp::push(@dumped, "++ crname $!cr_name");
nqp::push(@dumped, "++ crcuid $!cr_cuid");
nqp::push(@dumped, "++ crouter $!cr_outer");
for @!cr_olex { nqp::push(@dumped, "++ olex $_"); }
for @!cr_ilex { nqp::push(@dumped, "++ ilex $_"); }
for @!cr_nlex { nqp::push(@dumped, "++ nlex $_"); }
for @!cr_slex { nqp::push(@dumped, "++ slex $_"); }
nqp::push(@dumped, "++ handlers " ~ join(' ', @!cr_handlers));
for @!instructions {
nqp::push(@dumped, $_.dump());
}
Expand Down
32 changes: 32 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/jast2bc/JASTToJVMBytecode.java
Expand Up @@ -141,6 +141,7 @@ else if (curLine.equals("+ method")) {

private static boolean processMethod(BufferedReader in, ClassWriter c, String className) throws Exception {
String curLine, methodName = null, returnType = null;
String crName = null, crCuid = null, crOuter = null;
boolean isStatic = false;
List<String> argNames = new ArrayList<String>();
List<Type> argTypes = new ArrayList<Type>();
Expand All @@ -149,6 +150,11 @@ private static boolean processMethod(BufferedReader in, ClassWriter c, String cl
Map<String, Label> labelMap = new HashMap<String, Label>();
Stack<Label> tryStartStack = new Stack<Label>();
Stack<Label> tryEndStack = new Stack<Label>();
List<String> croLex = new ArrayList<String>();
List<String> criLex = new ArrayList<String>();
List<String> crnLex = new ArrayList<String>();
List<String> crsLex = new ArrayList<String>();
long[] crHandlers = null;
int curArgIndex = 1;

MethodVisitor m = null;
Expand Down Expand Up @@ -191,6 +197,32 @@ else if (curLine.startsWith("++ local ")) {
localVariables.put(bits[2], new VariableDef(curArgIndex, t.getDescriptor()));
curArgIndex += (t == Type.LONG_TYPE || t == Type.DOUBLE_TYPE ? 2 : 1);
}
else if (curLine.startsWith("++ crname "))
crName = curLine.substring("++ crname ".length());
else if (curLine.startsWith("++ crcuid "))
crCuid = curLine.substring("++ crcuid ".length());
else if (curLine.startsWith("++ crouter "))
crOuter = curLine.substring("++ crouter ".length());
else if (curLine.startsWith("++ olex "))
croLex.add(curLine.substring("++ olex ".length()));
else if (curLine.startsWith("++ ilex "))
criLex.add(curLine.substring("++ ilex ".length()));
else if (curLine.startsWith("++ nlex "))
crnLex.add(curLine.substring("++ nlex ".length()));
else if (curLine.startsWith("++ slex "))
crsLex.add(curLine.substring("++ slex ".length()));
else if (curLine.startsWith("++ handlers ")) {
String suffix = curLine.substring("++ handlers ".length());
if (!suffix.equals("")) {
String[] longStrs = suffix.split("\\s");
crHandlers = new long[longStrs.length];
for (int i = 0; i < longStrs.length; i++)
crHandlers[i] = Long.parseLong(longStrs[i]);
}
else {
crHandlers = new long[0];
}
}
else
throw new Exception("Cannot understand '" + curLine + "'");
continue;
Expand Down

0 comments on commit 99dbf54

Please sign in to comment.