use of com.googlecode.prolog_cafe.lang.StructureTerm in project gerrit by GerritCodeReview.
the class PrologTestCase method call.
private void call(BufferingPrologControl env, String name) {
StructureTerm head = SymbolTerm.create(pkg, name, 0);
assert_().withFailureMessage("Cannot invoke " + pkg + ":" + name).that(env.execute(Prolog.BUILTIN, "call", head)).isTrue();
}
use of com.googlecode.prolog_cafe.lang.StructureTerm in project gerrit by GerritCodeReview.
the class AbstractCommitUserIdentityPredicate method exec.
protected Operation exec(Prolog engine, UserIdentity userId) throws PrologException {
engine.setB0();
Term a1 = arg1.dereference();
Term a2 = arg2.dereference();
Term a3 = arg3.dereference();
Term idTerm;
Term nameTerm = Prolog.Nil;
Term emailTerm = Prolog.Nil;
Account.Id id = userId.getAccount();
if (id == null) {
idTerm = anonymous;
} else {
idTerm = new IntegerTerm(id.get());
}
String name = userId.getName();
if (name != null && !name.equals("")) {
nameTerm = SymbolTerm.create(name);
}
String email = userId.getEmail();
if (email != null && !email.equals("")) {
emailTerm = SymbolTerm.create(email);
}
if (!a1.unify(new StructureTerm(user, idTerm), engine.trail)) {
return engine.fail();
}
if (!a2.unify(nameTerm, engine.trail)) {
return engine.fail();
}
if (!a3.unify(emailTerm, engine.trail)) {
return engine.fail();
}
return cont;
}
use of com.googlecode.prolog_cafe.lang.StructureTerm in project gerrit by GerritCodeReview.
the class PRED_change_owner_1 method exec.
@Override
public Operation exec(Prolog engine) throws PrologException {
engine.setB0();
Term a1 = arg1.dereference();
Account.Id ownerId = StoredValues.getChange(engine).getOwner();
if (!a1.unify(new StructureTerm(user, new IntegerTerm(ownerId.get())), engine.trail)) {
return engine.fail();
}
return cont;
}
use of com.googlecode.prolog_cafe.lang.StructureTerm in project gerrit by GerritCodeReview.
the class GerritCommonTest method reductionLimit.
@Test
public void reductionLimit() throws Exception {
PrologEnvironment env = envFactory.create(machine);
setUpEnvironment(env);
String script = "loopy :- b(5).\nb(N) :- N > 0, !, S = N - 1, b(S).\nb(_) :- true.\n";
SymbolTerm nameTerm = SymbolTerm.create("testReductionLimit");
JavaObjectTerm inTerm = new JavaObjectTerm(new PushbackReader(new StringReader(script), Prolog.PUSHBACK_SIZE));
if (!env.execute(Prolog.BUILTIN, "consult_stream", nameTerm, inTerm)) {
throw new CompileException("Cannot consult " + nameTerm);
}
exception.expect(ReductionLimitException.class);
exception.expectMessage("exceeded reduction limit of 1300");
env.once(Prolog.BUILTIN, "call", new StructureTerm(":", SymbolTerm.create("user"), SymbolTerm.create("loopy")));
}
use of com.googlecode.prolog_cafe.lang.StructureTerm in project gerrit by GerritCodeReview.
the class PrologTestCase method load.
protected void load(String pkg, String prologResource, Module... modules) throws CompileException, IOException {
ArrayList<Module> moduleList = new ArrayList<>();
moduleList.add(new PrologModule.EnvironmentModule());
moduleList.addAll(Arrays.asList(modules));
envFactory = Guice.createInjector(moduleList).getInstance(PrologEnvironment.Factory.class);
PrologEnvironment env = envFactory.create(newMachine());
consult(env, getClass(), prologResource);
this.pkg = pkg;
hasSetup = has(env, "setup");
hasTeardown = has(env, "teardown");
StructureTerm head = new StructureTerm(":", SymbolTerm.intern(pkg), new StructureTerm(test_1, new VariableTerm()));
tests = new ArrayList<>();
for (Term[] pair : env.all(Prolog.BUILTIN, "clause", head, new VariableTerm())) {
tests.add(pair[0]);
}
assertThat(tests).isNotEmpty();
machine = PrologMachineCopy.save(env);
}
Aggregations