Return to jtry1..jtry10 to save space Encoding ChoicePointFrame.Sn into the bytecode of each compiled predicate resulted in a larger runtime JAR in commit d53fd3122110ad5440de6b8a4edfe65a17d6f457. Return to the previous jtry1...jtryN helper methods that allocate the new frame and continue. Change-Id: I40e7f7c181c7064071141ac6d40b28a4516abd50
diff --git a/src/builtin/PRED_regex_match_3.java b/src/builtin/PRED_regex_match_3.java index 5d796f5..a96779a 100644 --- a/src/builtin/PRED_regex_match_3.java +++ b/src/builtin/PRED_regex_match_3.java
@@ -1,7 +1,6 @@ package com.googlecode.prolog_cafe.builtin; import com.googlecode.prolog_cafe.exceptions.IllegalTypeException; import com.googlecode.prolog_cafe.exceptions.PInstantiationException; -import com.googlecode.prolog_cafe.lang.ChoicePointFrame; import com.googlecode.prolog_cafe.lang.JavaObjectTerm; import com.googlecode.prolog_cafe.lang.ListTerm; import com.googlecode.prolog_cafe.lang.Operation; @@ -10,7 +9,6 @@ import com.googlecode.prolog_cafe.lang.SymbolTerm; import com.googlecode.prolog_cafe.lang.Term; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -59,7 +57,7 @@ engine.r1 = new JavaObjectTerm(matcher); engine.r2 = arg3; - return engine.jtry(regex_check, regex_next, new ChoicePointFrame.S2(engine)); + return engine.jtry2(regex_check, regex_next); } private static final class PRED_regex_check extends Operation { @@ -94,7 +92,7 @@ return engine.fail(); } - return engine.jtry(regex_check, regex_next, new ChoicePointFrame.S2(engine)); + return engine.jtry2(regex_check, regex_next); } }
diff --git a/src/compiler/am2j.pl b/src/compiler/am2j.pl index 846ea83..2121f86 100644 --- a/src/compiler/am2j.pl +++ b/src/compiler/am2j.pl
@@ -469,16 +469,10 @@ write_java0(try(Li,Lj), _, Out) :- !, clause(current_arity(A), _), tab(Out, 8), - write(Out, 'return engine.jtry('), + write(Out, 'return engine.jtry'), write(Out, A), write(Out, '('), write_index(Li, Out), write(Out, ', '), write_index(Lj, Out), - write(Out, ', '), - ( A == 0 -> - write(Out, 'new S0()') - ; - write(Out, 'new S'), write(Out, A), write(Out, '(engine)') - ), write(Out, ');'), nl(Out). write_java0(retry(Li,Lj), _, Out) :- !, tab(Out, 8),
diff --git a/src/compiler/pl2am.pl b/src/compiler/pl2am.pl index 8700a80..2cbe84c 100644 --- a/src/compiler/pl2am.pl +++ b/src/compiler/pl2am.pl
@@ -253,7 +253,6 @@ assert_import('com.googlecode.prolog_cafe.builtin'), assert_import('com.googlecode.prolog_cafe.exceptions'), assert_import('com.googlecode.prolog_cafe.lang'), - assert_import('com.googlecode.prolog_cafe.lang.ChoicePointFrame'), assert(import_static('com.googlecode.prolog_cafe.lang.Failure', fail_0)), assert_dummy_package, assert_dummy_public.
diff --git a/src/lang/ChoicePointFrame.java b/src/lang/ChoicePointFrame.java index 908586a..f94dd90 100644 --- a/src/lang/ChoicePointFrame.java +++ b/src/lang/ChoicePointFrame.java
@@ -9,7 +9,7 @@ * @author Naoyuki Tamura (tamura@kobe-u.ac.jp) * @version 1.0 */ -public abstract class ChoicePointFrame { +class ChoicePointFrame { ChoicePointFrame prior; long timeStamp; @@ -31,13 +31,10 @@ return t; } - public static final class S0 extends ChoicePointFrame { - } - - public static final class S1 extends ChoicePointFrame { + static final class S1 extends ChoicePointFrame { private final Term r1; - public S1(Prolog engine) { + S1(Prolog engine) { this.r1 = engine.r1; } @@ -47,10 +44,10 @@ } } - public static final class S2 extends ChoicePointFrame { + static final class S2 extends ChoicePointFrame { private final Term r1, r2; - public S2(Prolog engine) { + S2(Prolog engine) { this.r1 = engine.r1; this.r2 = engine.r2; } @@ -61,10 +58,10 @@ } } - public static final class S3 extends ChoicePointFrame { + static final class S3 extends ChoicePointFrame { private final Term r1, r2, r3; - public S3(Prolog engine) { + S3(Prolog engine) { this.r1 = engine.r1; this.r2 = engine.r2; this.r3 = engine.r3; @@ -78,10 +75,10 @@ } } - public static final class S4 extends ChoicePointFrame { + static final class S4 extends ChoicePointFrame { private final Term r1, r2, r3, r4; - public S4(Prolog engine) { + S4(Prolog engine) { this.r1 = engine.r1; this.r2 = engine.r2; this.r3 = engine.r3; @@ -97,10 +94,10 @@ } } - public static final class S5 extends ChoicePointFrame { + static final class S5 extends ChoicePointFrame { private final Term r1, r2, r3, r4, r5; - public S5(Prolog engine) { + S5(Prolog engine) { this.r1 = engine.r1; this.r2 = engine.r2; this.r3 = engine.r3; @@ -118,10 +115,10 @@ } } - public static final class S6 extends ChoicePointFrame { + static final class S6 extends ChoicePointFrame { private final Term r1, r2, r3, r4, r5, r6; - public S6(Prolog engine) { + S6(Prolog engine) { this.r1 = engine.r1; this.r2 = engine.r2; this.r3 = engine.r3; @@ -141,10 +138,10 @@ } } - public static final class S7 extends ChoicePointFrame { + static final class S7 extends ChoicePointFrame { private final Term r1, r2, r3, r4, r5, r6, r7; - public S7(Prolog engine) { + S7(Prolog engine) { this.r1 = engine.r1; this.r2 = engine.r2; this.r3 = engine.r3; @@ -166,10 +163,10 @@ } } - public static class S8 extends ChoicePointFrame { + static class S8 extends ChoicePointFrame { private final Term r1, r2, r3, r4, r5, r6, r7, r8; - public S8(Prolog engine) { + S8(Prolog engine) { this.r1 = engine.r1; this.r2 = engine.r2; this.r3 = engine.r3; @@ -193,7 +190,7 @@ } } - public static class S9 extends ChoicePointFrame { + static class S9 extends ChoicePointFrame { private final Term r1, r2, r3, r4, r5, r6, r7, r8, r9; S9(Prolog engine) { @@ -222,10 +219,10 @@ } } - public static class S10 extends ChoicePointFrame { + static class S10 extends ChoicePointFrame { private final Term r1, r2, r3, r4, r5, r6, r7, r8, r9, r10; - public S10(Prolog engine) { + S10(Prolog engine) { this.r1 = engine.r1; this.r2 = engine.r2; this.r3 = engine.r3;
diff --git a/src/lang/Prolog.java b/src/lang/Prolog.java index 231ab2c..4279f99 100644 --- a/src/lang/Prolog.java +++ b/src/lang/Prolog.java
@@ -139,7 +139,7 @@ CPFTimeStamp = Long.MIN_VALUE; // Creates an initial choice point frame. - ChoicePointFrame initialFrame = new ChoicePointFrame.S0(); + ChoicePointFrame initialFrame = new ChoicePointFrame(); initialFrame.b0 = B0; initialFrame.bp = Failure.FAILURE; initialFrame.tr = trail.top(); @@ -261,8 +261,20 @@ stack.top.restore(this); } + public Operation jtry0(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame()); } + public Operation jtry1(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S1(this)); } + public Operation jtry2(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S2(this)); } + public Operation jtry3(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S3(this)); } + public Operation jtry4(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S4(this)); } + public Operation jtry5(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S5(this)); } + public Operation jtry6(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S6(this)); } + public Operation jtry7(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S7(this)); } + public Operation jtry8(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S8(this)); } + public Operation jtry9(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S8(this)); } + public Operation jtry10(Operation p, Operation next) { return jtry(p, next, new ChoicePointFrame.S8(this)); } + /** Creates a new choice point frame. */ - public Operation jtry(Operation p, Operation next, ChoicePointFrame entry) { + private Operation jtry(Operation p, Operation next, ChoicePointFrame entry) { entry.cont = cont; entry.b0 = B0; entry.bp = next;