Adapt to latest PrologCafe snapshot

I changed around some of the APIs in PrologCafe to make the use of
SymbolTerm safer in a shared environment.

Change-Id: I182c8c6fad78598749a75a1b45ad264c500ab5d5
This commit is contained in:
Shawn O. Pearce
2011-06-15 11:42:28 -07:00
parent 1418b1beb0
commit dd7a88b074
5 changed files with 19 additions and 15 deletions

View File

@@ -24,6 +24,8 @@ import com.googlecode.prolog_cafe.lang.PrologClassLoader;
import com.googlecode.prolog_cafe.lang.SystemException;
import com.googlecode.prolog_cafe.lang.Term;
import java.util.EnumSet;
/**
* Per-thread Prolog interpreter.
* <p>
@@ -56,7 +58,7 @@ public class PrologEnvironment extends BufferingPrologControl {
setPrologClassLoader(new PrologClassLoader(newCL));
setMaxArity(8);
setMaxDatabaseSize(64);
setEnableReflection(false);
setEnabled(EnumSet.allOf(Prolog.Feature.class), false);
}
/** Get the global Guice Injector that configured the environment. */

View File

@@ -139,7 +139,7 @@ public class ProjectState {
new PushbackReader(new StringReader(rules), Prolog.PUSHBACK_SIZE);
JavaObjectTerm streamObject = new JavaObjectTerm(in);
if (!env.execute(Prolog.BUILTIN, "consult_stream",
SymbolTerm.makeSymbol("rules.pl"), streamObject)) {
SymbolTerm.intern("rules.pl"), streamObject)) {
throw new CompileException("Cannot consult rules.pl " +
getProject().getName() + " " + getConfig().getRevision());
}

View File

@@ -24,9 +24,9 @@ import com.googlecode.prolog_cafe.lang.Term;
/** Exports list of {@code commit_label( label('Code-Review', 2), user(12345789) )}. */
class PRED_$load_commit_labels_1 extends Predicate.P1 {
private static final SymbolTerm sym_commit_label = SymbolTerm.makeSymbol("commit_label", 2);
private static final SymbolTerm sym_label = SymbolTerm.makeSymbol("label", 2);
private static final SymbolTerm sym_user = SymbolTerm.makeSymbol("user", 1);
private static final SymbolTerm sym_commit_label = SymbolTerm.intern("commit_label", 2);
private static final SymbolTerm sym_label = SymbolTerm.intern("label", 2);
private static final SymbolTerm sym_user = SymbolTerm.intern("user", 1);
PRED_$load_commit_labels_1(Term a1, Operation n) {
arg1 = a1;
@@ -57,7 +57,7 @@ class PRED_$load_commit_labels_1 extends Predicate.P1 {
StructureTerm labelTerm = new StructureTerm(
sym_label,
SymbolTerm.makeSymbol(t.getCategory().getLabelName()),
SymbolTerm.intern(t.getCategory().getLabelName()),
new IntegerTerm(a.getValue()));
StructureTerm userTerm = new StructureTerm(

View File

@@ -68,14 +68,14 @@ class PRED_get_legacy_approval_types_1 extends Predicate.P1 {
return cont;
}
static final SymbolTerm symApprovalType = SymbolTerm.makeSymbol(
static final SymbolTerm symApprovalType = SymbolTerm.intern(
"approval_type", 5);
static Term export(ApprovalType type) {
return new StructureTerm(symApprovalType,
SymbolTerm.makeSymbol(type.getCategory().getLabelName()),
SymbolTerm.makeSymbol(type.getCategory().getId().get()),
SymbolTerm.makeSymbol(type.getCategory().getFunctionName()),
SymbolTerm.intern(type.getCategory().getLabelName()),
SymbolTerm.intern(type.getCategory().getId().get()),
SymbolTerm.intern(type.getCategory().getFunctionName()),
new IntegerTerm(type.getMin().getValue()),
new IntegerTerm(type.getMax().getValue()));
}

View File

@@ -30,12 +30,13 @@ import java.io.FileNotFoundException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
/** Base class for any tests written in Prolog. */
public abstract class PrologTestCase extends TestCase {
private static final SymbolTerm test_1 = SymbolTerm.makeSymbol("test", 1);
private static final SymbolTerm test_1 = SymbolTerm.intern("test", 1);
private String pkg;
private boolean hasSetup;
@@ -54,6 +55,7 @@ public abstract class PrologTestCase extends TestCase {
PrologEnvironment.Factory.class);
env = factory.create(getClass().getClassLoader());
env.setMaxDatabaseSize(16 * 1024);
env.setEnabled(Prolog.Feature.IO, true);
consult(getClass(), prologResource);
@@ -62,7 +64,7 @@ public abstract class PrologTestCase extends TestCase {
hasTeardown = has("teardown");
StructureTerm head = new StructureTerm(":",
SymbolTerm.makeSymbol(pkg),
SymbolTerm.intern(pkg),
new StructureTerm(test_1, new VariableTerm()));
tests = new ArrayList<Term>();
@@ -79,7 +81,7 @@ public abstract class PrologTestCase extends TestCase {
}
String path = url.getPath();
if (!env.execute(Prolog.BUILTIN, "consult", SymbolTerm.makeSymbol(path))) {
if (!env.execute(Prolog.BUILTIN, "consult", SymbolTerm.intern(path))) {
throw new CompileException("Cannot consult" + path);
}
}
@@ -90,7 +92,7 @@ public abstract class PrologTestCase extends TestCase {
}
private boolean has(String name) {
StructureTerm head = SymbolTerm.makeSymbol(pkg, name, 0);
StructureTerm head = SymbolTerm.create(pkg, name, 0);
return env.execute(Prolog.BUILTIN, "clause", head, new VariableTerm());
}
@@ -145,7 +147,7 @@ public abstract class PrologTestCase extends TestCase {
}
private void call(String name) {
StructureTerm head = SymbolTerm.makeSymbol(pkg, name, 0);
StructureTerm head = SymbolTerm.create(pkg, name, 0);
if (!env.execute(Prolog.BUILTIN, "call", head)) {
fail("Cannot invoke " + pkg + ":" + name);
}