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

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


    String methodName = null;

    // 3rd. argument (unbound variable)
    a3 = a3.dereference();
    if (!a3.isVariable()) {
      throw new IllegalTypeException(this, 3, "variable", a3);
    }
    try {
      // 1st. argument (atom or java term)
      a1 = a1.dereference();
      if (a1.isVariable()) {
        throw new PInstantiationException(this, 1);
      } else if (a1.isSymbol()) { // class
        clazz = Class.forName(((SymbolTerm) a1).name());
      } else if (a1.isJavaObject()) { // instance
        instance = ((JavaObjectTerm) a1).object();
        clazz = ((JavaObjectTerm) a1).getClazz();
      } else {
        throw new IllegalTypeException(this, 1, "atom_or_java", a1);
      }
      // 2nd. argument (atom or callable term)
      a2 = a2.dereference();
      if (a2.isVariable()) {
        throw new PInstantiationException(this, 2);
      } else if (a2.isSymbol()) { // No argument method
        m = clazz.getMethod(((SymbolTerm) a2).name());
        // m.setAccessible(true);
        value = m.invoke(instance);
      } else if (a2.isStructure()) { // Parameterized method
        methodName = ((StructureTerm) a2).name();
        arity = ((StructureTerm) a2).arity();
        methods = clazz.getMethods();
        if (methods.length == 0) {
          throw new ExistenceException(this, 2, "method", a2, "");
        }
        pArgs = ((StructureTerm) a2).args();
        jArgs = new Object[arity];
        for (int i = 0; i < arity; i++) {
          pArgs[i] = pArgs[i].dereference();
          if (!pArgs[i].isJavaObject()) {
            pArgs[i] = new JavaObjectTerm(pArgs[i]);
          }
          jArgs[i] = pArgs[i].toJava();
        }
        for (Method method : methods) {
          if (method.getName().equals(methodName)
              && checkParameterTypes(method.getParameterTypes(),
                  pArgs)) {
            try {
              m = method;
              // m.setAccessible(true);
              value = m.invoke(instance, jArgs);
              break; // Succeeds to invoke the method
            } catch (Exception e) {
              m = null; // Back to loop
            }
          }
        }
        if (m == null) {
          throw new ExistenceException(this, 2, "method", a2, "");
        }
      } else {
        throw new IllegalTypeException(this, 2, "callable", a2);
      }
      if (value == null) {
        return cont;
      }
      if (!a3.unify(toPrologTerm(value), engine.trail)) {
View Full Code Here


    Constructor c = null;

    // 2nd. argument (unbound variable)
    a2 = a2.dereference();
    if (!a2.isVariable()) {
      throw new IllegalTypeException(this, 2, "variable", a2);
    }
    // 1st. argument (atom or callable term)
    try {
      a1 = a1.dereference();
      if (a1.isVariable()) {
        throw new PInstantiationException(this, 1);
      }
      if (!a1.isSymbol() && !a1.isStructure()) {
        throw new IllegalTypeException(this, 1, "callable", a1);
      }
      if (a1.isSymbol()) { // No argument constructor
        clazz = Class.forName(((SymbolTerm) a1).name());
        c = clazz.getDeclaredConstructor();
        if (c == null) {
View Full Code Here

    Term a1;
    a1 = arg1;

    a1 = a1.dereference();
    if (!a1.isJavaObject()) {
      throw new IllegalTypeException(this, 1, "java", a1);
    }
    Object obj = ((JavaObjectTerm) a1).object();
    if (!(obj instanceof PRED_$begin_exception_1)) {
      throw new SystemException(
          "a1 must be an object of PRED_$begin_exception_1: "
View Full Code Here

        }
        //END inline expansion
        //START inline expansion of $cut(a(4))
        a4 = a4.dereference();
        if (! a4.isInteger()) {
            throw new IllegalTypeException("integer", a4);
        } else {
            engine.cut(((IntegerTerm) a4).intValue());
        }
        //END inline expansion
        return new PRED_hash_keys_2(a2, a3, cont);
View Full Code Here

        }
        //END inline expansion
        //START inline expansion of $cut(a(4))
        a4 = a4.dereference();
        if (! a4.isInteger()) {
            throw new IllegalTypeException("integer", a4);
        } else {
            engine.cut(((IntegerTerm) a4).intValue());
        }
        //END inline expansion
        return cont;
View Full Code Here

    a1 = arg1;
    a2 = arg2;

    a1 = a1.dereference();
    if (!a1.isVariable()) {
      throw new IllegalTypeException(this, 1, "variable", a1);
    }
    Term newHash = new JavaObjectTerm(new HashMapOfTerm());
    a2 = a2.dereference();
    if (a2.isNil()) {
      if (!a1.unify(newHash, engine.trail)) {
        return engine.fail();
      }
      return cont;
    } else if (!a2.isList()) {
      throw new IllegalTypeException(this, 2, "list", a2);
    }
    // a2 is list
    Term tmp = a2;
    while (!tmp.isNil()) {
      if (tmp.isVariable()) {
        throw new PInstantiationException(this, 2);
      }
      if (!tmp.isList()) {
        throw new IllegalTypeException(this, 2, "list", a2);
      }
      Term car = ((ListTerm) tmp).car().dereference();
      if (car.isVariable()) {
        throw new PInstantiationException(this, 2);
      }
View Full Code Here

        }
        //END inline expansion
        //START inline expansion of $cut(a(6))
        a6 = a6.dereference();
        if (! a6.isInteger()) {
            throw new IllegalTypeException("integer", a6);
        } else {
            engine.cut(((IntegerTerm) a6).intValue());
        }
        //END inline expansion
        p1 = new PRED_$dummy_12_builtins$002Epl_3(a5, new VariableTerm(engine), a2, cont);
View Full Code Here

      if (!a2.unify(Nil, engine.trail)) {
        return engine.fail();
      }
      return cont;
    } else if (!a1.isList()) {
      throw new IllegalTypeException(this, 1, "list", a1);
    }
    len = ((ListTerm) a1).length();
    list = new Term[len];
    tmp = a1;
    for (int i = 0; i < len; i++) {
      if (!tmp.isList()) {
        throw new IllegalTypeException(this, 1, "list", a1);
      }
      list[i] = ((ListTerm) tmp).car().dereference();
      tmp = ((ListTerm) tmp).cdr().dereference();
    }
    if (!tmp.equals(Nil)) {
View Full Code Here

    // InByte
    a2 = a2.dereference();
    if (!a2.isVariable()) {
      if (!a2.isInteger()) {
        throw new IllegalTypeException(this, 2, "in_byte", a2);
      }
      int n = ((IntegerTerm) a2).intValue();
      if (n != -1 && (n < 0 || n > 255)) {
        throw new RepresentationException(this, 2, "in_byte");
      }
View Full Code Here

    a1 = a1.dereference();
    if (a1.isNil()) {
      return engine.fail();
    }
    if (!a1.isList()) {
      throw new IllegalTypeException(this, 1, "list", a1);
    }
    Term x = Prolog.Nil;
    Term tmp = a1;
    while (!tmp.isNil()) {
      if (!tmp.isList()) {
        throw new IllegalTypeException(this, 1, "list", a1);
      }
      Term car = ((ListTerm) tmp).car().dereference();
      if (car.isVariable()) {
        throw new PInstantiationException(this, 1);
      }
View Full Code Here

TOP

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

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.