Search in sources :

Example 6 with VariableTerm

use of com.googlecode.prolog_cafe.lang.VariableTerm 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)

Example 7 with VariableTerm

use of com.googlecode.prolog_cafe.lang.VariableTerm in project gerrit by GerritCodeReview.

the class PRED_current_user_2 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    Term a2 = arg2.dereference();
    if (a1 instanceof VariableTerm) {
        throw new PInstantiationException(this, 1);
    }
    if (!a2.unify(createUser(engine, a1), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) PInstantiationException(com.googlecode.prolog_cafe.exceptions.PInstantiationException)

Aggregations

SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)7 Term (com.googlecode.prolog_cafe.lang.Term)7 VariableTerm (com.googlecode.prolog_cafe.lang.VariableTerm)7 IntegerTerm (com.googlecode.prolog_cafe.lang.IntegerTerm)5 JavaObjectTerm (com.googlecode.prolog_cafe.lang.JavaObjectTerm)5 PInstantiationException (com.googlecode.prolog_cafe.exceptions.PInstantiationException)4 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)4 IllegalTypeException (com.googlecode.prolog_cafe.exceptions.IllegalTypeException)3 LabelType (com.google.gerrit.common.data.LabelType)2 PrologEnvironment (com.google.gerrit.rules.PrologEnvironment)2 CurrentUser (com.google.gerrit.server.CurrentUser)2 LabelPermission (com.google.gerrit.server.permissions.LabelPermission)2 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 OrmException (com.google.gwtorm.server.OrmException)2 JavaException (com.googlecode.prolog_cafe.exceptions.JavaException)2 ReductionLimitException (com.googlecode.prolog_cafe.exceptions.ReductionLimitException)2 SystemException (com.googlecode.prolog_cafe.exceptions.SystemException)2 ListTerm (com.googlecode.prolog_cafe.lang.ListTerm)2 ArrayList (java.util.ArrayList)2