Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use small-integers to find mainlineQbid, entryQbid, deserializeQbid, …
…loadQbid
  • Loading branch information
sorear committed Jun 21, 2013
1 parent c51de3f commit 8c2ec14
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
29 changes: 15 additions & 14 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -30,6 +30,7 @@ my $LCMP := JAST::Instruction.new( :op('lcmp') );
my $DCMPL := JAST::Instruction.new( :op('dcmpl') );
my $RETURN := JAST::Instruction.new( :op('return') );
my $ARETURN := JAST::Instruction.new( :op('areturn') );
my $IRETURN := JAST::Instruction.new( :op('ireturn') );
my $ATHROW := JAST::Instruction.new( :op('athrow') );

# Common constant loads.
Expand Down Expand Up @@ -2877,9 +2878,9 @@ class QAST::CompilerJAST {
# Compile to JAST and register this block as the deserialization
# handler.
self.as_jast($block);
my $des_meth := JAST::Method.new( :name('deserializeCuid'), :returns($TYPE_STR), :static(0) );
$des_meth.append(JAST::PushSVal.new( :value($block.cuid) ));
$des_meth.append(JAST::Instruction.new( :op('areturn') ));
my $des_meth := JAST::Method.new( :name('deserializeQbid'), :returns('I'), :static(0) );
$des_meth.append(JAST::PushIndex.new( :value(self.cuid_to_qbid($block.cuid)) ));
$des_meth.append($IRETURN);
$*JCLASS.add_method($des_meth);
}

Expand All @@ -2891,9 +2892,9 @@ class QAST::CompilerJAST {
QAST::Op.new( :op('null') )
);
self.as_jast($load_block);
my $load_meth := JAST::Method.new( :name('loadCuid'), :returns($TYPE_STR), :static(0) );
$load_meth.append(JAST::PushSVal.new( :value($load_block.cuid) ));
$load_meth.append(JAST::Instruction.new( :op('areturn') ));
my $load_meth := JAST::Method.new( :name('loadQbid'), :returns('I'), :static(0) );
$load_meth.append(JAST::PushIndex.new( :value(self.cuid_to_qbid($load_block.cuid)) ));
$load_meth.append($IRETURN);
$*JCLASS.add_method($load_meth);
}

Expand All @@ -2909,16 +2910,16 @@ class QAST::CompilerJAST {
my $main_meth := JAST::Method.new( :name('main'), :returns('Void') );
$main_meth.add_argument('argv', "[$TYPE_STR");
$main_meth.append(JAST::PushCVal.new( :value('L' ~ $*JCLASS.name ~ ';') ));
$main_meth.append(JAST::PushSVal.new( :value($main_block.cuid) ));
$main_meth.append(JAST::PushIndex.new( :value(self.cuid_to_qbid($main_block.cuid)) ));
$main_meth.append($ALOAD_0);
$main_meth.append(JAST::Instruction.new( :op('invokestatic'),
$TYPE_CU, 'enterFromMain',
'Void', 'Ljava/lang/Class;', $TYPE_STR, "[$TYPE_STR"));
'Void', 'Ljava/lang/Class;', 'I', "[$TYPE_STR"));
$main_meth.append($RETURN);
$*JCLASS.add_method($main_meth);
my $entry_cuid_meth := JAST::Method.new( :name('entryCuid'), :returns($TYPE_STR), :static(0) );
$entry_cuid_meth.append(JAST::PushSVal.new( :value($main_block.cuid) ));
$entry_cuid_meth.append($ARETURN);
my $entry_cuid_meth := JAST::Method.new( :name('entryQbid'), :returns('I'), :static(0) );
$entry_cuid_meth.append(JAST::PushIndex.new( :value(self.cuid_to_qbid($main_block.cuid)) ));
$entry_cuid_meth.append($IRETURN);
$*JCLASS.add_method($entry_cuid_meth);
}

Expand All @@ -2929,9 +2930,9 @@ class QAST::CompilerJAST {
$*JCLASS.add_method($hll_meth);

# Add method that returns the mainline block.
my $mainline_meth := JAST::Method.new( :name('mainlineCuid'), :returns($TYPE_STR), :static(0) );
$mainline_meth.append(JAST::PushSVal.new( :value($cu[0].cuid) ));
$mainline_meth.append(JAST::Instruction.new( :op('areturn') ));
my $mainline_meth := JAST::Method.new( :name('mainlineQbid'), :returns('I'), :static(0) );
$mainline_meth.append(JAST::PushIndex.new( :value(self.cuid_to_qbid($cu[0].cuid)) ));
$mainline_meth.append($IRETURN);
$*JCLASS.add_method($mainline_meth);

return $*JCLASS;
Expand Down
38 changes: 26 additions & 12 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java
Expand Up @@ -57,10 +57,10 @@ public static void enterFromMain(Class<?> cuType, int entryCodeRefIdx, String[]
throws Exception {
ThreadContext tc = (new GlobalContext()).mainThread;
CompilationUnit cu = setupCompilationUnit(tc, cuType, false);
Ops.invokeMain(tc, cu.codeRefs[entryCodeRefIdx], cuType.getName(), argv);
Ops.invokeMain(tc, cu.qbidToCodeRef[entryCodeRefIdx], cuType.getName(), argv);
}
public static void enterFromMain(Class<?> cuType, String cuid, String[] argv)
throws Exception {
throws Exception { /*FOR_STAGE0*/
ThreadContext tc = (new GlobalContext()).mainThread;
CompilationUnit cu = setupCompilationUnit(tc, cuType, false);
Ops.invokeMain(tc, cu.lookupCodeRef(cuid), cuType.getName(), argv);
Expand Down Expand Up @@ -166,9 +166,10 @@ public void initializeCompilationUnit(ThreadContext tc) {

/* Run any deserialization code. */
CodeRef desCodeRef = null;
String desCuid = deserializeCuid();
if (desCuid != null)
desCodeRef = lookupCodeRef(desCuid);
if (deserializeCuid() != null)
desCodeRef = lookupCodeRef(deserializeCuid());
if (deserializeQbid() >= 0)
desCodeRef = lookupCodeRef(deserializeQbid());
if (desCodeRef != null)
try {
Ops.invokeArgless(tc, desCodeRef);
Expand All @@ -186,9 +187,10 @@ public void initializeCompilationUnit(ThreadContext tc) {
*/
public void runLoadIfAvailable(ThreadContext tc) {
CodeRef loadCodeRef = null;
String loadCuid = loadCuid();
if (loadCuid != null)
loadCodeRef = lookupCodeRef(loadCuid);
if (loadCuid() != null)
loadCodeRef = lookupCodeRef(loadCuid());
if (loadQbid() >= 0)
loadCodeRef = lookupCodeRef(loadQbid());
if (loadCodeRef != null)
try {
Ops.invokeArgless(tc, loadCodeRef);
Expand Down Expand Up @@ -261,28 +263,40 @@ private void setLexValues(ThreadContext tc, CodeRef cr, String toParse) {
/**
* Code generation overrides this if there's an SC to deserialize.
*/
public String deserializeCuid() {
public String deserializeCuid() { /*FOR_STAGE0*/
return null;
}
public int deserializeQbid() {
return -1;
}

/**
* Code generation overrides this if there's an SC to deserialize.
*/
public String loadCuid() {
public String loadCuid() { /*FOR_STAGE0*/
return null;
}
public int loadQbid() {
return -1;
}

/**
* Code generation overrides this with the mainline blcok.
*/
public String mainlineCuid() {
public String mainlineCuid() { /*FOR_STAGE0*/
return null;
}
public int mainlineQbid() {
return -1;
}

/**
* Code generation overrides this with the entry-point block, if any.
*/
public String entryCuid() {
public String entryCuid() { /*FOR_STAGE0*/
return null;
}
public int entryQbid() {
return -1;
}
}
7 changes: 5 additions & 2 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/EvalServer.java
Expand Up @@ -106,9 +106,12 @@ else if (cmdStrings[1].equals("run")) {
gc.sharingHint = true;

CompilationUnit cu = CompilationUnit.setupCompilationUnit(gc.mainThread, cuType, true);
if (cu.entryCuid() == null)
CodeRef entryRef = null;
if (cu.entryCuid() != null) entryRef = cu.lookupCodeRef(cu.entryCuid());
if (cu.entryQbid() >= 0) entryRef = cu.lookupCodeRef(cu.entryQbid());
if (entryRef == null)
throw new RuntimeException("This class is not an entry point");
Ops.invokeMain(gc.mainThread, cu.lookupCodeRef(cu.entryCuid()), cuType.getName(), argv);
Ops.invokeMain(gc.mainThread, entryRef, cuType.getName(), argv);
}
else {
throw new RuntimeException("Unknown command "+cmdStrings[1]);
Expand Down
4 changes: 3 additions & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -4387,7 +4387,9 @@ public static long iscompunit(SixModelObject obj, ThreadContext tc) {
}
public static SixModelObject compunitmainline(SixModelObject obj, ThreadContext tc) {
EvalResult res = (EvalResult)obj;
return res.cu.lookupCodeRef(res.cu.mainlineCuid());
return res.cu.mainlineCuid() == null ?
res.cu.lookupCodeRef(res.cu.mainlineQbid()) :
res.cu.lookupCodeRef(res.cu.mainlineCuid());
}
public static SixModelObject compunitcodes(SixModelObject obj, ThreadContext tc) {
EvalResult res = (EvalResult)obj;
Expand Down

0 comments on commit 8c2ec14

Please sign in to comment.