Package jp.ac.kobe_u.cs.prolog.lang

Examples of jp.ac.kobe_u.cs.prolog.lang.JavaObjectTerm


  private Term toPrologTerm(Object obj) {
    if (Term.instanceOfTerm(obj)) {
      return (Term) obj;
    } else {
      return new JavaObjectTerm(obj);
    }
  }
View Full Code Here


      if (!a2.unify(new IntegerTerm(c), engine.trail)) {
        return engine.fail();
      }
      return cont;
    } catch (IOException e) {
      throw new TermException(new JavaObjectTerm(e));
    }
  }
View Full Code Here

      if (!a2.unify(new IntegerTerm(c), engine.trail)) {
        return engine.fail();
      }
      return cont;
    } catch (IOException e) {
      throw new TermException(new JavaObjectTerm(e));
    }
  }
View Full Code Here

    engine.setB0();
    Term a1;
    a1 = arg1;
    a1 = a1.dereference();
    if (a1.isVariable()) {
      ((VariableTerm) a1).bind(new JavaObjectTerm(engine
          .getCurrentInput()), engine.trail);
    } else if (a1.isJavaObject()) {
      if (!a1.unify(new JavaObjectTerm(engine.getCurrentInput()),
          engine.trail)) {
        return engine.fail();
      }
    } else {
      throw new IllegalDomainException(this, 1, "stream", a1);
View Full Code Here

      if (!a2.unify(new IntegerTerm(c), engine.trail)) {
        return engine.fail();
      }
      return cont;
    } catch (IOException e) {
      throw new TermException(new JavaObjectTerm(e));
    }
  }
View Full Code Here

    } else { // a1 = nonvar /\ a2 = var
      // (a1 = java \/ a1 = str \/ a1 = clo) /\ a2 = var
      if (a1.isJavaObject() || a1.isStructure() || a1.isClosure()) {
        ((VariableTerm) a2).bind(a1, engine.trail);
      } else { // a1 != java /\ a1 != str /\ a1 != clo /\ a2 = var
        ((VariableTerm) a2).bind(new JavaObjectTerm(a1.toJava()),
            engine.trail);
      }
    }
    return cont;
  }
View Full Code Here

      for (int i = v.size(); i > 0; i--) {
        t = new ListTerm(inverseConversion(v.elementAt(i - 1)), t);
      }
      return t;
    }
    return new JavaObjectTerm(o);
  }
View Full Code Here

    a1 = a1.dereference();
    if (!a1.isVariable()) {
      throw new IllegalTypeException(this, 1, "variable", a1);
    }
    if (!a1
        .unify(new JavaObjectTerm(engine.getHashManager()),
            engine.trail)) {
      return engine.fail();
    }
    return cont;
  }
View Full Code Here

  public Predicate exec(Prolog engine) {
    engine.setB0();
    File file;
    Term alias = null;
    Term opts = SYM_NIL;
    JavaObjectTerm streamObject;
    Term a1, a2, a3, a4;
    a1 = arg1;
    a2 = arg2;
    a3 = arg3;
    a4 = arg4;

    // stream
    a3 = a3.dereference();
    if (!a3.isVariable()) {
      throw new IllegalTypeException(this, 3, "variable", a3);
    }
    // source_sink
    a1 = a1.dereference();
    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    }
    if (!a1.isSymbol()) {
      throw new IllegalDomainException(this, 1, "source_sink", a1);
    }
    file = new File(((SymbolTerm) a1).name());
    // io_mode
    a2 = a2.dereference();
    if (a2.isVariable()) {
      throw new PInstantiationException(this, 2);
    }
    if (!a2.isSymbol()) {
      throw new IllegalTypeException(this, 2, "atom", a2);
    }
    try {
      if (a2.equals(SYM_READ)) {
        if (!file.exists()) {
          throw new ExistenceException(this, 1, "source_sink", a1, "");
        }
        PushbackReader in = new PushbackReader(new BufferedReader(
            new FileReader(file)), Prolog.PUSHBACK_SIZE);
        streamObject = new JavaObjectTerm(in);
        opts = new ListTerm(SYM_INPUT, opts);
      } else if (a2.equals(SYM_WRITE)) {
        PrintWriter out = new PrintWriter(new BufferedWriter(
            new FileWriter(file, false)));
        streamObject = new JavaObjectTerm(out);
        opts = new ListTerm(SYM_OUTPUT, opts);
      } else if (a2.equals(SYM_APPEND)) {
        PrintWriter out = new PrintWriter(new BufferedWriter(
            new FileWriter(file, true)));
        streamObject = new JavaObjectTerm(out);
        opts = new ListTerm(SYM_OUTPUT, opts);
      } else {
        throw new IllegalDomainException(this, 2, "io_mode", a2);
      }
    } catch (IOException e) {
View Full Code Here

    a1 = a1.dereference();
    if (!a1.isVariable()) {
      throw new IllegalTypeException(this, 1, "variable", a1);
    }
    if (!a1.unify(new JavaObjectTerm(engine.getStreamManager()),
        engine.trail)) {
      return engine.fail();
    }
    return cont;
  }
View Full Code Here

TOP

Related Classes of jp.ac.kobe_u.cs.prolog.lang.JavaObjectTerm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.