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.getDeclaredMethod(((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.getDeclaredMethods();
        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


      while (!x.isNil()) {
        if (x.isVariable()) {
          throw new PInstantiationException(this, 2);
        }
        if (!x.isList()) {
          throw new IllegalTypeException(this, 2, "list", a2);
        }
        Term car = ((ListTerm) x).car().dereference();
        if (car.isVariable()) {
          throw new PInstantiationException(this, 2);
        }
        if (!car.isInteger()) {
          throw new RepresentationException(this, 2, "character_code");
        }
        // car is an integer
        int i = ((IntegerTerm) car).intValue();
        if (!Character.isDefined((char) i)) {
          throw new RepresentationException(this, 2, "character_code");
        }
        sb.append((char) i);
        x = ((ListTerm) x).cdr().dereference();
      }
      if (!a1.unify(SymbolTerm.makeSymbol(sb.toString()), engine.trail)) {
        return engine.fail();
      }
      return cont;
    } else { // atom_codes(+Atom, ?CharCodeList)
      if (!a1.isSymbol()) {
        throw new IllegalTypeException(this, 1, "atom", a1);
      }
      char[] chars = ((SymbolTerm) a1).name().toCharArray();
      Term x = Nil;
      for (int i = chars.length; i > 0; i--) {
        x = new ListTerm(new IntegerTerm(chars[i - 1]), x);
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

    // Char
    a2 = a2.dereference();
    if (!a2.isVariable()) {
      if (!a2.isInteger()) {
        throw new IllegalTypeException(this, 2, "integer", a2);
      }
      int n = ((IntegerTerm) a2).intValue();
      if (n != -1 && !Character.isDefined(n)) {
        throw new RepresentationException(this, 2, "in_character_code");
      }
View Full Code Here

    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    }
    if (!a1.isSymbol()) {
      throw new IllegalTypeException(this, 1, "atom", a1);
    }
    length = ((SymbolTerm) a1).name().length();
    if (a2.isVariable()) {
      if (!a2.unify(new IntegerTerm(length), engine.trail)) {
        return engine.fail();
      }
    } else if (a2.isInteger()) {
      int n = ((IntegerTerm) a2).intValue();
      if (n < 0) {
        throw new IllegalDomainException(this, 2, "not_less_than_zero",
            a2);
      }
      if (length != n) {
        return engine.fail();
      }
    } else {
      throw new IllegalTypeException(this, 1, "integer", a2);
    }
    return cont;
  }
View Full Code Here

    Term a1 = arg1;
    int idx;

    a1 = a1.dereference();
    if (!a1.isInteger()) {
      throw new IllegalTypeException(this, 1, "integer", a1);
    }
    idx = ((IntegerTerm) a1).intValue();
    engine.internalDB.erase(idx);
    return cont;
  }
View Full Code Here

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

    if (!(stream instanceof PrintWriter)) {
      throw new PermissionException(this, "output", "stream", a1, "");
    }
    a2 = a2.dereference();
    if (!a2.isJavaObject()) {
      throw new IllegalTypeException(this, 2, "java", a2);
    }
    // print java
    ((PrintWriter) stream).print(((JavaObjectTerm) a2).object().toString());
    return cont;
  }
View Full Code Here

        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)
      a2 = a2.dereference();
      if (a2.isVariable()) {
        throw new PInstantiationException(this, 2);
      } else if (!a2.isSymbol()) {
        throw new IllegalTypeException(this, 2, "atom", a2);
      }
      field = clazz.getField(((SymbolTerm) a2).name());
      // 3rd. argument (term)
      a3 = a3.dereference();
      if (a3.isJavaObject()) {
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
        engine.aregs[1] = a5;
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.