Esempio n. 1
0
  @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")));
  }
  @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;
  }
  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;
  }