Merge changes I40e7f7c1,I6542c6eb * changes: Return to jtry1..jtry10 to save space Statically import fail/0 instead of defining new fields
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 04a39b4..2121f86 100644 --- a/src/compiler/am2j.pl +++ b/src/compiler/am2j.pl
@@ -130,6 +130,12 @@ write(Out, 'import '), write_package(P, Out), write(Out, '.*;'), nl(Out). +write_java0(import_static(P,F), _, Out) :- !, + write(Out, 'import static '), + write_package(P, Out), + write(Out, '.'), + write(Out, F), + write(Out, ';'), nl(Out). write_java0(import_package(P,FA), _, Out) :- !, write(Out, 'import '), write_package(P, Out), @@ -143,12 +149,7 @@ write_java0((Label: Instruction), In, Out) :- !, write_label(Label, Out), write_java0(Instruction, In, Out). -write_java0(label(fail/0), _, Out) :- !, - tab(Out, 4), - write(Out, 'static final Operation '), - write_index(fail/0, Out), - write(Out, ' = com.googlecode.prolog_cafe.lang.Failure.FAIL_0'), - write(Out, ';'), nl(Out). +write_java0(label(fail/0), _, _) :- !. write_java0(label(L), _, Out) :- !, tab(Out, 4), write(Out, 'static final Operation '), @@ -468,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), @@ -1170,6 +1165,7 @@ + end_predicate(p, f/n) + import_package(p) ++ import_static(p, f/n) + import_package(p, f/n) + main(f/n, public): [Instructions]
diff --git a/src/compiler/pl2am.pl b/src/compiler/pl2am.pl index dca9608..2cbe84c 100644 --- a/src/compiler/pl2am.pl +++ b/src/compiler/pl2am.pl
@@ -102,6 +102,7 @@ end_predicate(p, f/n) import_package(p) + import_static(p, f/n) import_package(p, f/n) main(f/n, public): [Instructions] @@ -162,6 +163,7 @@ :- dynamic package_name/1. :- dynamic public_predicates/2. :- dynamic import_package/2. +:- dynamic import_static/2. :- dynamic internal_declarations/1. :- dynamic file_name/1. :- dynamic dummy_clause_counter/1. @@ -205,6 +207,7 @@ retractall(package_name(_)), retractall(public_predicates(_,_)), retractall(import_package(_,_)), + retractall(import_static(_,_)), retractall(internal_declarations(_)), retractall(file_name(_)), retractall(dummy_clause_counter(_)), @@ -250,7 +253,7 @@ 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. @@ -815,16 +818,23 @@ %%% Import Declarations generate_import --> + {findall((P,C), import_static(P, C), S)}, + gen_importstatic(S), {findall((P,C), import_package(P, C), X)}, - gen_import(X). + gen_importpkg(X). -gen_import([]) --> !. -gen_import([(P,'*')|Xs]) --> !, +gen_importstatic([]) --> !. +gen_importstatic([(P,C)|Xs]) --> + [import_static(P, C)], + gen_importstatic(Xs). + +gen_importpkg([]) --> !. +gen_importpkg([(P,'*')|Xs]) --> !, [import_package(P)], - gen_import(Xs). -gen_import([(P,C)|Xs]) --> + gen_importpkg(Xs). +gen_importpkg([(P,C)|Xs]) --> [import_package(P, C)], - gen_import(Xs). + gen_importpkg(Xs). %%% Information generate_info(Functor, Arity) -->
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/Failure.java b/src/lang/Failure.java index 15c3c04..7b109a0 100644 --- a/src/lang/Failure.java +++ b/src/lang/Failure.java
@@ -22,7 +22,7 @@ /** Returns a string representation of this <code>Failure</code>. */ public String toString(){ return "Failure"; } - public static final Operation FAIL_0 = new PRED_fail_0(); + public static final Operation fail_0 = new PRED_fail_0(); private static final class PRED_fail_0 extends Operation { @Override public Operation exec(Prolog engine) throws PrologException {
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;