コード例 #1
0
abstract class AbstractCommitUserIdentityPredicate extends Predicate.P3 {
  private static final long serialVersionUID = 1L;
  private static final SymbolTerm user = SymbolTerm.intern("user", 1);
  private static final SymbolTerm anonymous = SymbolTerm.intern("anonymous");

  AbstractCommitUserIdentityPredicate(Term a1, Term a2, Term a3, Operation n) {
    arg1 = a1;
    arg2 = a2;
    arg3 = a3;
    cont = n;
  }

  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;
  }
}
コード例 #2
0
ファイル: GerritCommonTest.java プロジェクト: web1992/gerrit
  @Test
  public void testReductionLimit() throws CompileException {
    PrologEnvironment env = envFactory.create(machine);
    setUpEnvironment(env);

    String script = "loopy :- b(5).\n" + "b(N) :- N > 0, !, S = N - 1, b(S).\n" + "b(_) :- 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")));
  }
コード例 #3
0
  @Override
  public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();

    PatchSetInfo psInfo = StoredValues.PATCH_SET_INFO.get(engine);

    SymbolTerm msg = SymbolTerm.create(psInfo.getMessage());
    if (!a1.unify(msg, engine.trail)) {
      return engine.fail();
    }
    return cont;
  }
コード例 #4
0
  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;
  }
コード例 #5
0
 /** Registers {@code user_input}, {@code user_output}, and {@code user_error} streams. */
 public void configureUserIO(InputStream in, OutputStream out, OutputStream err) {
   if (engine.streamManager == null) {
     engine.streamManager = new HashtableOfTerm(7);
   }
   if (in != null) {
     engine.streamManager.put(
         SymbolTerm.intern("user_input"),
         new JavaObjectTerm(
             new PushbackReader(
                 new BufferedReader(new InputStreamReader(in)), Prolog.PUSHBACK_SIZE)));
   }
   if (out != null) {
     engine.streamManager.put(
         SymbolTerm.intern("user_output"),
         new JavaObjectTerm(
             new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)), true)));
   }
   if (err != null) {
     engine.streamManager.put(
         SymbolTerm.intern("user_error"),
         new JavaObjectTerm(
             new PrintWriter(new BufferedWriter(new OutputStreamWriter(err)), true)));
   }
 }
コード例 #6
0
  /**
   * Execute the predicate on the current thread.
   *
   * <p>This method does not return until {@link #isEngineStopped()} returns true. Implementors of
   * the class are expected to invoke this method to perform evaluation, and terminate out of the
   * loop at the proper time based on an invocation to {@link #success()} or {@link #fail()}.
   *
   * @throws PrologException
   */
  protected void executePredicate() throws PrologException {
    Prolog engine = this.engine;
    Operation code = this.code;
    long reductionsRemaining = reductionLimit;
    try {
      engine.init();

      do {
        if (isEngineStopped()) return;
        if (--reductionsRemaining <= 0) throw new ReductionLimitException(reductionLimit);
        code = code.exec(engine);
      } while (engine.halt == 0);

      if (engine.halt != 1) {
        throw new HaltException(engine.halt - 1);
      }
    } finally {
      this.reductionsUsed = reductionLimit - reductionsRemaining;
      this.code = code;
      SymbolTerm.gc();
    }
  }