Skip to content

Commit 8c2ec14

Browse files
committed
Use small-integers to find mainlineQbid, entryQbid, deserializeQbid, loadQbid
1 parent c51de3f commit 8c2ec14

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ my $LCMP := JAST::Instruction.new( :op('lcmp') );
3030
my $DCMPL := JAST::Instruction.new( :op('dcmpl') );
3131
my $RETURN := JAST::Instruction.new( :op('return') );
3232
my $ARETURN := JAST::Instruction.new( :op('areturn') );
33+
my $IRETURN := JAST::Instruction.new( :op('ireturn') );
3334
my $ATHROW := JAST::Instruction.new( :op('athrow') );
3435

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

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

@@ -2909,16 +2910,16 @@ class QAST::CompilerJAST {
29092910
my $main_meth := JAST::Method.new( :name('main'), :returns('Void') );
29102911
$main_meth.add_argument('argv', "[$TYPE_STR");
29112912
$main_meth.append(JAST::PushCVal.new( :value('L' ~ $*JCLASS.name ~ ';') ));
2912-
$main_meth.append(JAST::PushSVal.new( :value($main_block.cuid) ));
2913+
$main_meth.append(JAST::PushIndex.new( :value(self.cuid_to_qbid($main_block.cuid)) ));
29132914
$main_meth.append($ALOAD_0);
29142915
$main_meth.append(JAST::Instruction.new( :op('invokestatic'),
29152916
$TYPE_CU, 'enterFromMain',
2916-
'Void', 'Ljava/lang/Class;', $TYPE_STR, "[$TYPE_STR"));
2917+
'Void', 'Ljava/lang/Class;', 'I', "[$TYPE_STR"));
29172918
$main_meth.append($RETURN);
29182919
$*JCLASS.add_method($main_meth);
2919-
my $entry_cuid_meth := JAST::Method.new( :name('entryCuid'), :returns($TYPE_STR), :static(0) );
2920-
$entry_cuid_meth.append(JAST::PushSVal.new( :value($main_block.cuid) ));
2921-
$entry_cuid_meth.append($ARETURN);
2920+
my $entry_cuid_meth := JAST::Method.new( :name('entryQbid'), :returns('I'), :static(0) );
2921+
$entry_cuid_meth.append(JAST::PushIndex.new( :value(self.cuid_to_qbid($main_block.cuid)) ));
2922+
$entry_cuid_meth.append($IRETURN);
29222923
$*JCLASS.add_method($entry_cuid_meth);
29232924
}
29242925

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

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

29372938
return $*JCLASS;

src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public static void enterFromMain(Class<?> cuType, int entryCodeRefIdx, String[]
5757
throws Exception {
5858
ThreadContext tc = (new GlobalContext()).mainThread;
5959
CompilationUnit cu = setupCompilationUnit(tc, cuType, false);
60-
Ops.invokeMain(tc, cu.codeRefs[entryCodeRefIdx], cuType.getName(), argv);
60+
Ops.invokeMain(tc, cu.qbidToCodeRef[entryCodeRefIdx], cuType.getName(), argv);
6161
}
6262
public static void enterFromMain(Class<?> cuType, String cuid, String[] argv)
63-
throws Exception {
63+
throws Exception { /*FOR_STAGE0*/
6464
ThreadContext tc = (new GlobalContext()).mainThread;
6565
CompilationUnit cu = setupCompilationUnit(tc, cuType, false);
6666
Ops.invokeMain(tc, cu.lookupCodeRef(cuid), cuType.getName(), argv);
@@ -166,9 +166,10 @@ public void initializeCompilationUnit(ThreadContext tc) {
166166

167167
/* Run any deserialization code. */
168168
CodeRef desCodeRef = null;
169-
String desCuid = deserializeCuid();
170-
if (desCuid != null)
171-
desCodeRef = lookupCodeRef(desCuid);
169+
if (deserializeCuid() != null)
170+
desCodeRef = lookupCodeRef(deserializeCuid());
171+
if (deserializeQbid() >= 0)
172+
desCodeRef = lookupCodeRef(deserializeQbid());
172173
if (desCodeRef != null)
173174
try {
174175
Ops.invokeArgless(tc, desCodeRef);
@@ -186,9 +187,10 @@ public void initializeCompilationUnit(ThreadContext tc) {
186187
*/
187188
public void runLoadIfAvailable(ThreadContext tc) {
188189
CodeRef loadCodeRef = null;
189-
String loadCuid = loadCuid();
190-
if (loadCuid != null)
191-
loadCodeRef = lookupCodeRef(loadCuid);
190+
if (loadCuid() != null)
191+
loadCodeRef = lookupCodeRef(loadCuid());
192+
if (loadQbid() >= 0)
193+
loadCodeRef = lookupCodeRef(loadQbid());
192194
if (loadCodeRef != null)
193195
try {
194196
Ops.invokeArgless(tc, loadCodeRef);
@@ -261,28 +263,40 @@ private void setLexValues(ThreadContext tc, CodeRef cr, String toParse) {
261263
/**
262264
* Code generation overrides this if there's an SC to deserialize.
263265
*/
264-
public String deserializeCuid() {
266+
public String deserializeCuid() { /*FOR_STAGE0*/
265267
return null;
266268
}
269+
public int deserializeQbid() {
270+
return -1;
271+
}
267272

268273
/**
269274
* Code generation overrides this if there's an SC to deserialize.
270275
*/
271-
public String loadCuid() {
276+
public String loadCuid() { /*FOR_STAGE0*/
272277
return null;
273278
}
279+
public int loadQbid() {
280+
return -1;
281+
}
274282

275283
/**
276284
* Code generation overrides this with the mainline blcok.
277285
*/
278-
public String mainlineCuid() {
286+
public String mainlineCuid() { /*FOR_STAGE0*/
279287
return null;
280288
}
289+
public int mainlineQbid() {
290+
return -1;
291+
}
281292

282293
/**
283294
* Code generation overrides this with the entry-point block, if any.
284295
*/
285-
public String entryCuid() {
296+
public String entryCuid() { /*FOR_STAGE0*/
286297
return null;
287298
}
299+
public int entryQbid() {
300+
return -1;
301+
}
288302
}

src/vm/jvm/runtime/org/perl6/nqp/runtime/EvalServer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ else if (cmdStrings[1].equals("run")) {
106106
gc.sharingHint = true;
107107

108108
CompilationUnit cu = CompilationUnit.setupCompilationUnit(gc.mainThread, cuType, true);
109-
if (cu.entryCuid() == null)
109+
CodeRef entryRef = null;
110+
if (cu.entryCuid() != null) entryRef = cu.lookupCodeRef(cu.entryCuid());
111+
if (cu.entryQbid() >= 0) entryRef = cu.lookupCodeRef(cu.entryQbid());
112+
if (entryRef == null)
110113
throw new RuntimeException("This class is not an entry point");
111-
Ops.invokeMain(gc.mainThread, cu.lookupCodeRef(cu.entryCuid()), cuType.getName(), argv);
114+
Ops.invokeMain(gc.mainThread, entryRef, cuType.getName(), argv);
112115
}
113116
else {
114117
throw new RuntimeException("Unknown command "+cmdStrings[1]);

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4387,7 +4387,9 @@ public static long iscompunit(SixModelObject obj, ThreadContext tc) {
43874387
}
43884388
public static SixModelObject compunitmainline(SixModelObject obj, ThreadContext tc) {
43894389
EvalResult res = (EvalResult)obj;
4390-
return res.cu.lookupCodeRef(res.cu.mainlineCuid());
4390+
return res.cu.mainlineCuid() == null ?
4391+
res.cu.lookupCodeRef(res.cu.mainlineQbid()) :
4392+
res.cu.lookupCodeRef(res.cu.mainlineCuid());
43914393
}
43924394
public static SixModelObject compunitcodes(SixModelObject obj, ThreadContext tc) {
43934395
EvalResult res = (EvalResult)obj;

0 commit comments

Comments
 (0)