Package weasel.interpreter

Examples of weasel.interpreter.WeaselNativeException


      case WeaselPrimitive.DOUBLE:
        thread.pushValue((Double)ret);
        break;
      case WeaselPrimitive.VOID:
        if(ret!=null){
          throw new WeaselNativeException("Got return parameter %s but expect a void value in %s", ret, methodDesk);
        }
        break;
      default:
        if(ret==null){
          thread.pushObject(0);
        }else{
          int objPtr = (Integer)ret;
          WeaselObject obj = interpreter.getObject(objPtr);
          if(!obj.getWeaselClass().canCastTo(rc))
            throw new WeaselNativeException("Got return parameter %s but expect a %s value in %s", ret, rc, methodDesk);
          thread.pushObject(objPtr);
        }
        break;
      }
    }else{
View Full Code Here


          gaveThis = true;
        }
      }else if(paramTypes[i].isPrimitive()){
        nameBuilder += WeaselClass.mapClassNames(paramTypes[i].getName());
      }else{
        throw new WeaselNativeException("Illegal parameter %s in method invokation %s", i, method);
      }
    }
    nameBuilder += ")";
    Class<?> returnType = method.getReturnType();
    if(returnType==WeaselObject.class){
      nameBuilder += "OObject;";
    }else if(returnType.isPrimitive()){
      nameBuilder += WeaselClass.mapClassNames(returnType.getName());
    }else{
      throw new WeaselNativeException("Illegal return parameter in method invokation %s", method);
    }
    name = nameBuilder;
  }
View Full Code Here

          gaveThis = true;
        }
      }else if(paramTypes[i].isPrimitive()){
        oParam[i] = param[j++];
      }else{
        throw new WeaselNativeException("Illegal parameter %s in method invokation %s", i, method);
      }
    }
    try {
      return method.invoke(null, oParam);
    } catch (Throwable e) {
      throw new WeaselNativeException(e, "Error on native method invokation %s", method);
    }
  }
View Full Code Here

    public static void registerMethodsInClass(Class<?> c){
      WeaselNamedMethod named;
      for(Method m:c.getMethods()){
        if((named=m.getAnnotation(WeaselNamedMethod.class))!=null){
          if(((m.getModifiers()&Modifier.STATIC)!=Modifier.STATIC))
            throw new WeaselNativeException("Only static Methods can be loaded");
          parseNamesAndRegister(named, m);
        }
      }
    }
View Full Code Here

      case WeaselPrimitive.DOUBLE:
        thread.pushValue((Double)ret);
        break;
      case WeaselPrimitive.VOID:
        if(ret!=null){
          throw new WeaselNativeException("Got return parameter %s but expect a void value in %s", ret, methodDesk);
        }
        break;
      default:
        if(ret==null){
          thread.pushObject(0);
        }else{
          int objPtr = (Integer)ret;
          WeaselObject obj = interpreter.getObject(objPtr);
          if(!obj.getWeaselClass().canCastTo(rc))
            throw new WeaselNativeException("Got return parameter %s but expect a %s value in %s", ret, rc, methodDesk);
          thread.pushObject(objPtr);
        }
        break;
      }
    }else{
View Full Code Here

  public void run(WeaselInterpreter interpreter, WeaselThread thread, WeaselMethodExecutor method) {
    StackElement se = thread.pop();
    if(se.value==null){
      WeaselObject object = interpreter.getObject(se.object);
      if(object==null)
        throw new WeaselNativeException("Null pointer");
      WeaselField field = object.getWeaselClass().getField("value");
      switch(primitiveID){
      case WeaselPrimitive.BOOLEAN:
        thread.pushValue(field.getBoolean(object));
        break;
      case WeaselPrimitive.CHAR:
        thread.pushValue(field.getChar(object));
        break;
      case WeaselPrimitive.BYTE:
        thread.pushValue(field.getBoolean(object));
        break;
      case WeaselPrimitive.SHORT:
        thread.pushValue(field.getShort(object));
        break;
      case WeaselPrimitive.INT:
        thread.pushValue(field.getInt(object));
        break;
      case WeaselPrimitive.LONG:
        thread.pushValue(field.getLong(object));
        break;
      case WeaselPrimitive.DOUBLE:
        thread.pushValue(field.getDouble(object));
        break;
      case WeaselPrimitive.FLOAT:
        thread.pushValue(field.getFloat(object));
        break;
      }
    }else{
      Object object = se.value;
      Class<?> c = object.getClass();
      switch(primitiveID){
      case WeaselPrimitive.BOOLEAN:
        thread.pushValue((Boolean)object);
        break;
      case WeaselPrimitive.CHAR:
        char cValue;
        if(c==Character.class){
          cValue = (Character)object;
        }else if(c==Byte.class){
          cValue = (char)(byte)(Byte)object;
        }else if(c==Short.class){
          cValue = (char)(short)(Short)object;
        }else if(c==Integer.class){
          cValue = (char)(int)(Integer)object;
        }else if(c==Long.class){
          cValue = (char)(long)(Long)object;
        }else if(c==Float.class){
          cValue = (char)(float)(Float)object;
        }else if(c==Double.class){
          cValue = (char)(double)(Double)object;
        }else{
          throw new WeaselNativeException("Can't cast %s to char", c);
        }
        thread.pushValue(cValue);
        break;
      case WeaselPrimitive.BYTE:
        byte bValue;
        if(c==Character.class){
          bValue = (byte)(char)(Character)object;
        }else if(c==Byte.class){
          bValue = (byte)(Byte)object;
        }else if(c==Short.class){
          bValue = (byte)(short)(Short)object;
        }else if(c==Integer.class){
          bValue = (byte)(int)(Integer)object;
        }else if(c==Long.class){
          bValue = (byte)(long)(Long)object;
        }else if(c==Float.class){
          bValue = (byte)(float)(Float)object;
        }else if(c==Double.class){
          bValue = (byte)(double)(Double)object;
        }else{
          throw new WeaselNativeException("Can't cast %s to byte", c);
        }
        thread.pushValue(bValue);
        break;
      case WeaselPrimitive.SHORT:
        short sValue;
        if(c==Character.class){
          sValue = (short)(char)(Character)object;
        }else if(c==Byte.class){
          sValue = (byte)(Byte)object;
        }else if(c==Short.class){
          sValue = (short)(Short)object;
        }else if(c==Integer.class){
          sValue = (short)(int)(Integer)object;
        }else if(c==Long.class){
          sValue = (short)(long)(Long)object;
        }else if(c==Float.class){
          sValue = (short)(float)(Float)object;
        }else if(c==Double.class){
          sValue = (short)(double)(Double)object;
        }else{
          throw new WeaselNativeException("Can't cast %s to short", c);
        }
        thread.pushValue(sValue);
        break;
      case WeaselPrimitive.INT:
        int iValue;
        if(c==Character.class){
          iValue = (char)(Character)object;
        }else if(c==Byte.class){
          iValue = (byte)(Byte)object;
        }else if(c==Short.class){
          iValue = (short)(Short)object;
        }else if(c==Integer.class){
          iValue = (int)(Integer)object;
        }else if(c==Long.class){
          iValue = (int)(long)(Long)object;
        }else if(c==Float.class){
          iValue = (int)(float)(Float)object;
        }else if(c==Double.class){
          iValue = (int)(double)(Double)object;
        }else{
          throw new WeaselNativeException("Can't cast %s to int", c);
        }
        thread.pushValue(iValue);
        break;
      case WeaselPrimitive.LONG:
        long lValue;
        if(c==Character.class){
          lValue = (char)(Character)object;
        }else if(c==Byte.class){
          lValue = (byte)(Byte)object;
        }else if(c==Short.class){
          lValue = (short)(Short)object;
        }else if(c==Integer.class){
          lValue = (int)(Integer)object;
        }else if(c==Long.class){
          lValue = (long)(Long)object;
        }else if(c==Float.class){
          lValue = (long)(float)(Float)object;
        }else if(c==Double.class){
          lValue = (long)(double)(Double)object;
        }else{
          throw new WeaselNativeException("Can't cast %s to long", c);
        }
        thread.pushValue(lValue);
        break;
      case WeaselPrimitive.DOUBLE:
        double dValue;
        if(c==Character.class){
          dValue = (char)(Character)object;
        }else if(c==Byte.class){
          dValue = (byte)(Byte)object;
        }else if(c==Short.class){
          dValue = (short)(Short)object;
        }else if(c==Integer.class){
          dValue = (int)(Integer)object;
        }else if(c==Long.class){
          dValue = (long)(Long)object;
        }else if(c==Float.class){
          dValue = (float)(Float)object;
        }else if(c==Double.class){
          dValue = (double)(Double)object;
        }else{
          throw new WeaselNativeException("Can't cast %s to double", c);
        }
        thread.pushValue(dValue);
        break;
      case WeaselPrimitive.FLOAT:
        float fValue;
        if(c==Character.class){
          fValue = (char)(Character)object;
        }else if(c==Byte.class){
          fValue = (byte)(Byte)object;
        }else if(c==Short.class){
          fValue = (short)(Short)object;
        }else if(c==Integer.class){
          fValue = (int)(Integer)object;
        }else if(c==Long.class){
          fValue = (long)(Long)object;
        }else if(c==Float.class){
          fValue = (float)(Float)object;
        }else if(c==Double.class){
          fValue = (float)(double)(Double)object;
        }else{
          throw new WeaselNativeException("Can't cast %s to float", c);
        }
        thread.pushValue(fValue);
        break;
      }
    }
View Full Code Here

  }


  public WeaselVariableInfo newVar(int modifier, String name, WeaselGenericClass type) {
    if(getVar(name)!=null)
      throw new WeaselNativeException("Duplicated definition of %s", name);
    WeaselVariableInfo wvi = new WeaselVariableInfo(modifier, name, type, varIndex++);
    variables.put(name, wvi);
    return wvi;
  }
View Full Code Here

      String name = weaselClass.getByteName();
      Object object = se.value;
      Class<?> c = object.getClass();
      if(name==WeaselBaseTypes.weaselBooleanClassName){
        if(c!=Boolean.class){
          throw new WeaselNativeException("Can't cast %s to %s", c, weaselClass);
        }
        thread.pushObject(interpreter.baseTypes.createBooleanObject((Boolean)object));
      }else if(name==WeaselBaseTypes.weaselCharClassName){
        if(c!=Character.class){
          throw new WeaselNativeException("Can't cast %s to %s", c, weaselClass);
        }
        thread.pushObject(interpreter.baseTypes.createCharObject((Character)object));
      }else if(name==WeaselBaseTypes.weaselByteClassName){
        if(c!=Byte.class){
          throw new WeaselNativeException("Can't cast %s to %s", c, weaselClass);
        }
        thread.pushObject(interpreter.baseTypes.createByteObject((Byte)object));
      }else if(name==WeaselBaseTypes.weaselShortClassName){
        if(c!=Short.class){
          throw new WeaselNativeException("Can't cast %s to %s", c, weaselClass);
        }
        thread.pushObject(interpreter.baseTypes.createShortObject((Short)object));
      }else if(name==WeaselBaseTypes.weaselIntClassName){
        if(c!=Integer.class){
          throw new WeaselNativeException("Can't cast %s to %s", c, weaselClass);
        }
        thread.pushObject(interpreter.baseTypes.createIntObject((Integer)object));
      }else if(name==WeaselBaseTypes.weaselLongClassName){
        if(c!=Long.class){
          throw new WeaselNativeException("Can't cast %s to %s", c, weaselClass);
        }
        thread.pushObject(interpreter.baseTypes.createLongObject((Long)object));
      }else if(name==WeaselBaseTypes.weaselFloatClassName){
        if(c!=Float.class){
          throw new WeaselNativeException("Can't cast %s to %s", c, weaselClass);
        }
        thread.pushObject(interpreter.baseTypes.createFloatObject((Float)object));
      }else if(name==WeaselBaseTypes.weaselDoubleClassName){
        if(c!=Double.class){
          throw new WeaselNativeException("Can't cast %s to %s", c, weaselClass);
        }
        thread.pushObject(interpreter.baseTypes.createDoubleObject((Double)object));
      }else{
        throw new WeaselNativeException("Can't cast %s to char", c);
      }
    }
  }
View Full Code Here

      while((line=lnr.readLine())!=null)
        source += line + "\n";
      lnr.close();
      return source;
    } catch (IOException e) {
      throw new WeaselNativeException(e, "Error while read class %s", file);
    }
  }
View Full Code Here

    try {
      Constructor<? extends WeaselClassCompiler> constructor = c.getDeclaredConstructor(WeaselCompiler.class, Object.class, String.class, String.class);
      constructor.setAccessible(true);
      return constructor.newInstance(this, null, name, fileName);
    } catch (Exception e) {
      throw new WeaselNativeException(e, "Error while create Weasel class compiler %s", version);
    }
  }
View Full Code Here

TOP

Related Classes of weasel.interpreter.WeaselNativeException

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.