Search in sources :

Example 6 with StructureTerm

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();
}
Also used : StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm)

Example 7 with StructureTerm

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;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm)

Example 8 with StructureTerm

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;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm)

Example 9 with StructureTerm

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")));
}
Also used : StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) StringReader(java.io.StringReader) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) CompileException(com.googlecode.prolog_cafe.exceptions.CompileException) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) PushbackReader(java.io.PushbackReader) Test(org.junit.Test)

Example 10 with StructureTerm

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);
}
Also used : StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) ArrayList(java.util.ArrayList) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) Term(com.googlecode.prolog_cafe.lang.Term) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) Module(com.google.inject.Module)

Aggregations

StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)14 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)12 Term (com.googlecode.prolog_cafe.lang.Term)11 IntegerTerm (com.googlecode.prolog_cafe.lang.IntegerTerm)8 JavaObjectTerm (com.googlecode.prolog_cafe.lang.JavaObjectTerm)6 Account (com.google.gerrit.reviewdb.client.Account)5 ListTerm (com.googlecode.prolog_cafe.lang.ListTerm)4 VariableTerm (com.googlecode.prolog_cafe.lang.VariableTerm)4 CurrentUser (com.google.gerrit.server.CurrentUser)2 CompileException (com.googlecode.prolog_cafe.exceptions.CompileException)2 PushbackReader (java.io.PushbackReader)2 ArrayList (java.util.ArrayList)2 LabelType (com.google.gerrit.common.data.LabelType)1 LabelTypes (com.google.gerrit.common.data.LabelTypes)1 LabelValue (com.google.gerrit.common.data.LabelValue)1 SubmitRecord (com.google.gerrit.common.data.SubmitRecord)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 AnonymousUser (com.google.gerrit.server.AnonymousUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1