Pin maximum functor arity to 10

The compiler needs an arity of 10 to compile itself into Java.
Gerrit Code Review pins the arity to 8 to ensure an optimized
code path is always used.

Simplify the virtual machine code by pinning the arity to 10 and
extending the choice point saving optimization for all ranges.
This eliminates some weird code paths using an array for extra
registers beyond the optimized 8.

Simplify register naming by using r1...r10 instead of areg1...areg10.

Change-Id: I6ffdc8c8ab1cb94886f9a303021d210c263892b0
diff --git a/src/builtin/PRED_$get_prolog_impl_flag_2.java b/src/builtin/PRED_$get_prolog_impl_flag_2.java
index 1004c7f..d53e7d9 100644
--- a/src/builtin/PRED_$get_prolog_impl_flag_2.java
+++ b/src/builtin/PRED_$get_prolog_impl_flag_2.java
@@ -28,7 +28,7 @@
 	    if (! a2.unify(SymbolTerm.intern(engine.getDebug()), engine.trail))
 		return engine.fail();
 	} else if (a1.equals(MAX_ARITY)) {
-	    if (! a2.unify(new IntegerTerm(engine.getMaxArity()), engine.trail))
+	    if (! a2.unify(new IntegerTerm(Prolog.MAX_ARITY), engine.trail))
 		return engine.fail();
 	} else {
 	    return engine.fail();
diff --git a/src/builtin/PRED_regex_match_3.java b/src/builtin/PRED_regex_match_3.java
index 0da77c9..5d796f5 100644
--- a/src/builtin/PRED_regex_match_3.java
+++ b/src/builtin/PRED_regex_match_3.java
@@ -1,6 +1,7 @@
 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;
@@ -56,16 +57,16 @@
         return engine.fail();
       }
 
-      engine.areg1 = new JavaObjectTerm(matcher);
-      engine.areg2 = arg3;
-      return engine.jtry2(regex_check, regex_next);
+      engine.r1 = new JavaObjectTerm(matcher);
+      engine.r2 = arg3;
+      return engine.jtry(regex_check, regex_next, new ChoicePointFrame.S2(engine));
   }
 
   private static final class PRED_regex_check extends Operation {
     @Override
     public Operation exec(Prolog engine) {
-      Term a1 = engine.areg1;
-      Term result = engine.areg2;
+      Term a1 = engine.r1;
+      Term result = engine.r2;
       Matcher matcher = (Matcher)((JavaObjectTerm)a1).object();
 
       Term matches = getMatches(matcher);
@@ -87,13 +88,13 @@
   private static final class PRED_regex_empty extends Operation {
     @Override
     public Operation exec(Prolog engine) {
-      Term a1 = engine.areg1;
+      Term a1 = engine.r1;
       Matcher matcher = (Matcher)((JavaObjectTerm)a1).object();
       if (!matcher.find()) {
         return engine.fail();
       }
 
-      return engine.jtry2(regex_check, regex_next);
+      return engine.jtry(regex_check, regex_next, new ChoicePointFrame.S2(engine));
     }
   }
 
diff --git a/src/compiler/am2j.pl b/src/compiler/am2j.pl
index 8da39a3..04a39b4 100644
--- a/src/compiler/am2j.pl
+++ b/src/compiler/am2j.pl
@@ -468,15 +468,16 @@
 write_java0(try(Li,Lj), _, Out) :- !, 
 	clause(current_arity(A), _),
 	tab(Out, 8),
-	write(Out, 'return engine.jtry'),
-	( A =< 8 ->
-		write(Out, A), write(Out, '(')
-		;
-		write(Out, '('), write(Out, A), write(Out, ', ')
-	),
+	write(Out, 'return engine.jtry('),
 	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),
@@ -1089,15 +1090,7 @@
 	am2j_error([register,expression,must,not,be,unbound,variable]),
 	fail.
 write_reg(void,   Out) :- !, write(Out, 'new VariableTerm(engine)').
-write_reg(ea(1),  Out) :- !, write(Out, 'engine.areg1').
-write_reg(ea(2),  Out) :- !, write(Out, 'engine.areg2').
-write_reg(ea(3),  Out) :- !, write(Out, 'engine.areg3').
-write_reg(ea(4),  Out) :- !, write(Out, 'engine.areg4').
-write_reg(ea(5),  Out) :- !, write(Out, 'engine.areg5').
-write_reg(ea(6),  Out) :- !, write(Out, 'engine.areg6').
-write_reg(ea(7),  Out) :- !, write(Out, 'engine.areg7').
-write_reg(ea(8),  Out) :- !, write(Out, 'engine.areg8').
-write_reg(ea(X),  Out) :- !, write(Out, 'engine.aregs['), Y is X - 9, write(Out, Y), write(Out, ']').
+write_reg(ea(R),  Out) :- 1 =< R, R =< 10, !, write(Out, 'engine.r'), write(Out, R).
 write_reg(econt,  Out) :- !, write(Out, 'engine.cont').
 write_reg(arg(X), Out) :- !, write(Out, arg), write(Out, X).
 write_reg(a(X),   Out) :- !, write(Out, a), write(Out, X).
@@ -1111,7 +1104,7 @@
 % am2j only
 write_reg(args(X),Out) :- !, write(Out, 'args['), write(Out, X), write(Out, ']').
 write_reg(X, _) :-
-	am2j_error([X,is,an,invalid,register,expression]),
+	am2j_error([invalid_register,X]),
 	fail.
 
 write_reg_args([], _) :- !.
diff --git a/src/compiler/pl2am.pl b/src/compiler/pl2am.pl
index 118d5d1..dca9608 100644
--- a/src/compiler/pl2am.pl
+++ b/src/compiler/pl2am.pl
@@ -250,6 +250,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_dummy_package,
 	assert_dummy_public.
 
@@ -548,7 +549,7 @@
 	%
 	[FA: []],
 	{FA = Functor/Arity},
-	set_arguments(1, Arity, arg, ea, set), % set arg(N) to engine.areg(N)
+	set_arguments(1, Arity, arg, ea, set), % set arg(N) to engine.r(N)
 	[set(cont, econt)], % set cont to engine.cont
 	[OPT2],
 	[OPT3],
@@ -576,7 +577,7 @@
 	[DeclLocalVars],    % generates the declarations of local variables
 	[decl_pred_vars([cont])],
 	{FA = _/Arity},
-	set_arguments(1, Arity, ea, a, set), % set engine.areg(N) to a(N).
+	set_arguments(1, Arity, ea, a, set), % set engine.r(N) to a(N).
 	[set(econt, cont)], % set engine.cont to cont
 	compile_clause(Clause, GTI0, GTI1, LTI),
 	{N1 is N + 1},
diff --git a/src/lang/ChoicePointFrame.java b/src/lang/ChoicePointFrame.java
index e921072..908586a 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
  */
-class ChoicePointFrame {
+public abstract class ChoicePointFrame {
     ChoicePointFrame prior;
 
     long timeStamp;
@@ -18,12 +18,6 @@
     int tr;          // trail pointer
     int b0;          // cut point
 
-    static ChoicePointFrame S0(Operation cont) {
-      ChoicePointFrame r = new ChoicePointFrame();
-      r.cont = cont;
-      return r;
-    }
-
     void restore(Prolog engine) {
       engine.cont = this.cont;
     }
@@ -37,186 +31,225 @@
       return t;
     }
 
-    static final class S1 extends ChoicePointFrame {
-      private Term areg1;
+    public static final class S0 extends ChoicePointFrame {
+    }
 
-      S1(Prolog engine) {
-        this.cont = engine.cont;
-        this.areg1 = engine.areg1;
+    public static final class S1 extends ChoicePointFrame {
+      private final Term r1;
+
+      public S1(Prolog engine) {
+        this.r1 = engine.r1;
       }
 
       void restore(Prolog engine) {
         engine.cont = this.cont;
-        engine.areg1 = this.areg1;
+        engine.r1 = this.r1;
       }
     }
 
-    static final class S2 extends ChoicePointFrame {
-      private Term areg1, areg2;
+    public static final class S2 extends ChoicePointFrame {
+      private final Term r1, r2;
 
-      S2(Prolog engine) {
-        this.cont = engine.cont;
-        this.areg1 = engine.areg1;
-        this.areg2 = engine.areg2;
+      public S2(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+      }
+
+      void restore(Prolog engine) {
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+      }
+    }
+
+    public static final class S3 extends ChoicePointFrame {
+      private final Term r1, r2, r3;
+
+      public S3(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+        this.r3 = engine.r3;
       }
 
       void restore(Prolog engine) {
         engine.cont = this.cont;
-        engine.areg1 = this.areg1;
-        engine.areg2 = this.areg2;
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+        engine.r3 = this.r3;
       }
     }
 
-    static final class S3 extends ChoicePointFrame {
-      private Term areg1, areg2, areg3;
+    public static final class S4 extends ChoicePointFrame {
+      private final Term r1, r2, r3, r4;
 
-      S3(Prolog engine) {
-        this.cont = engine.cont;
-        this.areg1 = engine.areg1;
-        this.areg2 = engine.areg2;
-        this.areg3 = engine.areg3;
+      public S4(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+        this.r3 = engine.r3;
+        this.r4 = engine.r4;
       }
 
       void restore(Prolog engine) {
         engine.cont = this.cont;
-        engine.areg1 = this.areg1;
-        engine.areg2 = this.areg2;
-        engine.areg3 = this.areg3;
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+        engine.r3 = this.r3;
+        engine.r4 = this.r4;
       }
     }
 
-    static final class S4 extends ChoicePointFrame {
-      private Term areg1, areg2, areg3, areg4;
+    public static final class S5 extends ChoicePointFrame {
+      private final Term r1, r2, r3, r4, r5;
 
-      S4(Prolog engine) {
-        this.cont = engine.cont;
-        this.areg1 = engine.areg1;
-        this.areg2 = engine.areg2;
-        this.areg3 = engine.areg3;
-        this.areg4 = engine.areg4;
+      public S5(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+        this.r3 = engine.r3;
+        this.r4 = engine.r4;
+        this.r5 = engine.r5;
       }
 
       void restore(Prolog engine) {
         engine.cont = this.cont;
-        engine.areg1 = this.areg1;
-        engine.areg2 = this.areg2;
-        engine.areg3 = this.areg3;
-        engine.areg4 = this.areg4;
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+        engine.r3 = this.r3;
+        engine.r4 = this.r4;
+        engine.r5 = this.r5;
       }
     }
 
-    static final class S5 extends ChoicePointFrame {
-      private Term areg1, areg2, areg3, areg4, areg5;
+    public static final class S6 extends ChoicePointFrame {
+      private final Term r1, r2, r3, r4, r5, r6;
 
-      S5(Prolog engine) {
-        this.cont = engine.cont;
-        this.areg1 = engine.areg1;
-        this.areg2 = engine.areg2;
-        this.areg3 = engine.areg3;
-        this.areg4 = engine.areg4;
-        this.areg5 = engine.areg5;
+      public S6(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+        this.r3 = engine.r3;
+        this.r4 = engine.r4;
+        this.r5 = engine.r5;
+        this.r6 = engine.r6;
       }
 
       void restore(Prolog engine) {
         engine.cont = this.cont;
-        engine.areg1 = this.areg1;
-        engine.areg2 = this.areg2;
-        engine.areg3 = this.areg3;
-        engine.areg4 = this.areg4;
-        engine.areg5 = this.areg5;
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+        engine.r3 = this.r3;
+        engine.r4 = this.r4;
+        engine.r5 = this.r5;
+        engine.r6 = this.r6;
       }
     }
 
-    static final class S6 extends ChoicePointFrame {
-      private Term areg1, areg2, areg3, areg4, areg5, areg6;
+    public static final class S7 extends ChoicePointFrame {
+      private final Term r1, r2, r3, r4, r5, r6, r7;
 
-      S6(Prolog engine) {
-        this.cont = engine.cont;
-        this.areg1 = engine.areg1;
-        this.areg2 = engine.areg2;
-        this.areg3 = engine.areg3;
-        this.areg4 = engine.areg4;
-        this.areg5 = engine.areg5;
-        this.areg6 = engine.areg6;
+      public S7(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+        this.r3 = engine.r3;
+        this.r4 = engine.r4;
+        this.r5 = engine.r5;
+        this.r6 = engine.r6;
+        this.r7 = engine.r7;
       }
 
       void restore(Prolog engine) {
         engine.cont = this.cont;
-        engine.areg1 = this.areg1;
-        engine.areg2 = this.areg2;
-        engine.areg3 = this.areg3;
-        engine.areg4 = this.areg4;
-        engine.areg5 = this.areg5;
-        engine.areg6 = this.areg6;
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+        engine.r3 = this.r3;
+        engine.r4 = this.r4;
+        engine.r5 = this.r5;
+        engine.r6 = this.r6;
+        engine.r7 = this.r7;
       }
     }
 
-    static final class S7 extends ChoicePointFrame {
-      private Term areg1, areg2, areg3, areg4, areg5, areg6, areg7;
+    public static class S8 extends ChoicePointFrame {
+      private final Term r1, r2, r3, r4, r5, r6, r7, r8;
 
-      S7(Prolog engine) {
-        this.cont = engine.cont;
-        this.areg1 = engine.areg1;
-        this.areg2 = engine.areg2;
-        this.areg3 = engine.areg3;
-        this.areg4 = engine.areg4;
-        this.areg5 = engine.areg5;
-        this.areg6 = engine.areg6;
-        this.areg7 = engine.areg7;
+      public S8(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+        this.r3 = engine.r3;
+        this.r4 = engine.r4;
+        this.r5 = engine.r5;
+        this.r6 = engine.r6;
+        this.r7 = engine.r7;
+        this.r8 = engine.r8;
       }
 
       void restore(Prolog engine) {
         engine.cont = this.cont;
-        engine.areg1 = this.areg1;
-        engine.areg2 = this.areg2;
-        engine.areg3 = this.areg3;
-        engine.areg4 = this.areg4;
-        engine.areg5 = this.areg5;
-        engine.areg6 = this.areg6;
-        engine.areg7 = this.areg7;
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+        engine.r3 = this.r3;
+        engine.r4 = this.r4;
+        engine.r5 = this.r5;
+        engine.r6 = this.r6;
+        engine.r7 = this.r7;
+        engine.r8 = this.r8;
       }
     }
 
-    static class S8 extends ChoicePointFrame {
-      private Term areg1, areg2, areg3, areg4, areg5, areg6, areg7, areg8;
+    public static class S9 extends ChoicePointFrame {
+      private final Term r1, r2, r3, r4, r5, r6, r7, r8, r9;
 
-      S8(Prolog engine) {
-        this.cont = engine.cont;
-        this.areg1 = engine.areg1;
-        this.areg2 = engine.areg2;
-        this.areg3 = engine.areg3;
-        this.areg4 = engine.areg4;
-        this.areg5 = engine.areg5;
-        this.areg6 = engine.areg6;
-        this.areg7 = engine.areg7;
-        this.areg8 = engine.areg8;
+      S9(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+        this.r3 = engine.r3;
+        this.r4 = engine.r4;
+        this.r5 = engine.r5;
+        this.r6 = engine.r6;
+        this.r7 = engine.r7;
+        this.r8 = engine.r8;
+        this.r9 = engine.r9;
       }
 
       void restore(Prolog engine) {
         engine.cont = this.cont;
-        engine.areg1 = this.areg1;
-        engine.areg2 = this.areg2;
-        engine.areg3 = this.areg3;
-        engine.areg4 = this.areg4;
-        engine.areg5 = this.areg5;
-        engine.areg6 = this.areg6;
-        engine.areg7 = this.areg7;
-        engine.areg8 = this.areg8;
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+        engine.r3 = this.r3;
+        engine.r4 = this.r4;
+        engine.r5 = this.r5;
+        engine.r6 = this.r6;
+        engine.r7 = this.r7;
+        engine.r8 = this.r8;
+        engine.r9 = this.r9;
       }
     }
 
-    static final class S9 extends S8 {
-      private Term[] aregs;
+    public static class S10 extends ChoicePointFrame {
+      private final Term r1, r2, r3, r4, r5, r6, r7, r8, r9, r10;
 
-      S9(int arity, Prolog engine) {
-        super(engine);
-        aregs = new Term[arity - 8];
-        System.arraycopy(engine.aregs, 0, aregs, 0, aregs.length);
+      public S10(Prolog engine) {
+        this.r1 = engine.r1;
+        this.r2 = engine.r2;
+        this.r3 = engine.r3;
+        this.r4 = engine.r4;
+        this.r5 = engine.r5;
+        this.r6 = engine.r6;
+        this.r7 = engine.r7;
+        this.r8 = engine.r8;
+        this.r9 = engine.r9;
+        this.r10 = engine.r10;
       }
 
       void restore(Prolog engine) {
-        System.arraycopy(aregs, 0, engine.aregs, 0, aregs.length);
-        super.restore(engine);
+        engine.cont = this.cont;
+        engine.r1 = this.r1;
+        engine.r2 = this.r2;
+        engine.r3 = this.r3;
+        engine.r4 = this.r4;
+        engine.r5 = this.r5;
+        engine.r6 = this.r6;
+        engine.r7 = this.r7;
+        engine.r8 = this.r8;
+        engine.r9 = this.r9;
+        engine.r10 = this.r10;
       }
     }
 }
diff --git a/src/lang/Prolog.java b/src/lang/Prolog.java
index 25ced4e..231ab2c 100644
--- a/src/lang/Prolog.java
+++ b/src/lang/Prolog.java
@@ -20,18 +20,16 @@
  *
  * @author Mutsunori Banbara (banbara@kobe-u.ac.jp)
  * @author Naoyuki Tamura (tamura@kobe-u.ac.jp)
- * @version 1.2
-*/
+ */
 public final class Prolog {
+    public static final int MAX_ARITY = 10;
     private static final SymbolTerm NONE = SymbolTerm.intern("$none");
 
     /** Prolog thread */
     public PrologControl control;
 
     /** Argument registers */
-    public Term areg1, areg2, areg3, areg4, areg5, areg6, areg7, areg8;
-    public Term[] aregs;
-    private static final Term[] NO_REGISTERS = {};
+    public Term r1, r2, r3, r4, r5, r6, r7, r8, r9, r10;
 
     /** Continuation goal register */
     public Operation cont;
@@ -60,8 +58,6 @@
 
     /** Prolog implementation flag: <code>debug</code>. */
     protected String debug;
-    /** Prolog implementation flag: <code>max_arity</code>. */
-    protected int maxArity = 255;
 
     /** Holds an exception term for <code>catch/3</code> and <code>throw/1</code>. */
     protected Term exception;
@@ -129,28 +125,21 @@
      * </ul>
      */
   private void initOnce() {
-    if (8 < maxArity)
-      aregs = new Term[maxArity - 8];
-    else
-      aregs = NO_REGISTERS;
-
     if (pcl == null) pcl = new PrologClassLoader();
     if (internalDB == null) internalDB = new InternalDatabase();
-
-    streamManager = new HashtableOfTerm();
+    if (streamManager == null) streamManager = new HashtableOfTerm();
   }
 
     /** Initializes this Prolog engine. */
     public void init() { 
-	if (aregs == null)
-	  initOnce();
+	initOnce();
 	stack.init();
 	trail.init();
 	B0 = stack.top();
 	CPFTimeStamp = Long.MIN_VALUE;
 
 	// Creates an initial choice point frame.
-	ChoicePointFrame initialFrame = ChoicePointFrame.S0(null);
+	ChoicePointFrame initialFrame = new ChoicePointFrame.S0();
 	initialFrame.b0 = B0;
 	initialFrame.bp = Failure.FAILURE;
 	initialFrame.tr = trail.top();
@@ -207,7 +196,7 @@
      * <code>var</code>, <code>Int</code>, <code>flo</code>, 
      * <code>con</code>, <code>str</code>, or <code>lis</code>, 
      * depending on whether the dereferenced value of argument 
-     * register <code>areg[1]</code> is a
+     * register <code>r1</code> is a
      * variable, integer, float,
      * atom, compound term, or non-empty list, respectively.
      */
@@ -217,7 +206,7 @@
 				    Operation con, 
 				    Operation str, 
 				    Operation lis) {
-	Term arg1 = areg1.dereference();
+	Term arg1 = r1.dereference();
 	if (arg1.isVariable())
 	    return var;
 	if (arg1.isInteger())
@@ -234,7 +223,7 @@
     }
 
     /**
-     * If the dereferenced value of arugment register <code>areg[1]</code>
+     * If the dereferenced value of argument register <code>r[1]</code>
      * is an integer, float, atom, or compound term (except for non-empty list),
      * this returns the <code>Predicate</code> object to which its key is mapped
      * in hashtable <code>hash</code>.
@@ -247,11 +236,11 @@
      *   <li>compound term - functor/arity
      * </ul>
      *
-     * If there is no mapping for the key of <code>areg[1]</code>, 
+     * If there is no mapping for the key of <code>r[1]</code>,
      * this returns <code>otherwise</code>.
      */
     public Operation switch_on_hash(HashMap<Term,Operation> hash, Operation otherwise) {
-	Term arg1 = areg1.dereference();
+	Term arg1 = r1.dereference();
 	Term key;
 	if (arg1.isInteger() || arg1.isDouble() || arg1.isSymbol()) {
 	    key = arg1;
@@ -273,20 +262,8 @@
     }
 
     /** Creates a new choice point frame. */
-    public Operation jtry0(Operation p, Operation next) { return finishjtry(p, next, ChoicePointFrame.S0(cont)); }
-    public Operation jtry1(Operation p, Operation next) { return finishjtry(p, next, new ChoicePointFrame.S1(this)); }
-    public Operation jtry2(Operation p, Operation next) { return finishjtry(p, next, new ChoicePointFrame.S2(this)); }
-    public Operation jtry3(Operation p, Operation next) { return finishjtry(p, next, new ChoicePointFrame.S3(this)); }
-    public Operation jtry4(Operation p, Operation next) { return finishjtry(p, next, new ChoicePointFrame.S4(this)); }
-    public Operation jtry5(Operation p, Operation next) { return finishjtry(p, next, new ChoicePointFrame.S5(this)); }
-    public Operation jtry6(Operation p, Operation next) { return finishjtry(p, next, new ChoicePointFrame.S6(this)); }
-    public Operation jtry7(Operation p, Operation next) { return finishjtry(p, next, new ChoicePointFrame.S7(this)); }
-    public Operation jtry8(Operation p, Operation next) { return finishjtry(p, next, new ChoicePointFrame.S8(this)); }
-    public Operation jtry(int arity, Operation p, Operation next) {
-	return finishjtry(p, next, new ChoicePointFrame.S9(arity, this));
-    }
-
-    private Operation finishjtry(Operation p, Operation next, ChoicePointFrame entry) {
+    public Operation jtry(Operation p, Operation next, ChoicePointFrame entry) {
+      entry.cont = cont;
       entry.b0 = B0;
       entry.bp = next;
       entry.tr = trail.top();
@@ -327,9 +304,6 @@
     /** Sets the value of Prolog implementation flag: <code>debug</code>. */
     public void setDebug(String mode) { debug = mode;}
 
-    /** Returns the value of Prolog implementation flag: <code>max_arity</code>. */
-    public int getMaxArity() { return maxArity; }
-
     /** Returns the value of <code>exception</code>. This is used in <code>catch/3</code>. */
     public Term getException() { return exception; }
     /** Sets the value of <code>exception</code>. This is used in <code>throw/1</code>. */
diff --git a/src/lang/PrologControl.java b/src/lang/PrologControl.java
index fe36ef2..b10a178 100644
--- a/src/lang/PrologControl.java
+++ b/src/lang/PrologControl.java
@@ -58,8 +58,6 @@
       return InternalDatabase.DEFAULT_SIZE;
     }
     public void setMaxDatabaseSize(int size) {
-      if (engine.aregs != null)
-        throw new IllegalStateException("Prolog already initialized");
       if (engine.internalDB != null)
         engine.internalDB.maxContents = size;
       else
@@ -72,20 +70,9 @@
       return engine.pcl;
     }
     public void setPrologClassLoader(PrologClassLoader cl) {
-      if (engine.aregs != null)
-        throw new IllegalStateException("Prolog already initialized");
       engine.pcl = cl;
     }
 
-    public int getMaxArity() { return engine.getMaxArity(); }
-    public void setMaxArity(int max) {
-      if (max < 8)
-        throw new IllegalStateException("invalid arity " + max);
-      if (engine.aregs != null)
-        throw new IllegalStateException("Prolog already initialized");
-      engine.maxArity = max;
-    }
-
     /** Sets a goal and its arguments to this Prolog thread. 
      * An initial continuation goal (a <code>Success</code> object)
      * is set to the <code>cont</code> field of goal <code>p</code> as continuation.