Package weasel.interpreter.bytecode

Examples of weasel.interpreter.bytecode.WeaselInstructionCast


      return new WeaselInstructionList();
    }
    int primitiveID = WeaselPrimitive.getUnwrapped(weaselGenericClass.getBaseClass());
    if(primitiveID==WeaselPrimitive.getPrimitiveID(returnType.getBaseClass())){
      if(WeaselPrimitive.getPrimitiveID(weaselGenericClass.getBaseClass())==0){
        instructionList.addWithoutLine(new WeaselInstructionCast(weaselGenericClass.getBaseClass().getByteName()));
      }
      returnType = weaselGenericClass;
      return instructionList;
    }
    WeaselInstructionList instructionList = new WeaselInstructionList();
    int line = this.instructionList.getLine();
    try{
      switch(primitiveID){
      case WeaselPrimitive.BOOLEAN:
        instructionList.add(line, new WeaselInstructionLoadConstBoolean(WeaselPrimitive.getBoolean(constant)));
        break;
      case WeaselPrimitive.CHAR:
        instructionList.add(line, new WeaselInstructionLoadConstChar(WeaselPrimitive.getChar(constant)));
        break;
      case WeaselPrimitive.BYTE:
        instructionList.add(line, new WeaselInstructionLoadConstByte(WeaselPrimitive.getByte(constant)));
        break;
      case WeaselPrimitive.SHORT:
        instructionList.add(line, new WeaselInstructionLoadConstShort(WeaselPrimitive.getShort(constant)));
        break;
      case WeaselPrimitive.INT:
        instructionList.add(line, new WeaselInstructionLoadConstInteger(WeaselPrimitive.getInteger(constant)));
        break;
      case WeaselPrimitive.LONG:
        instructionList.add(line, new WeaselInstructionLoadConstLong(WeaselPrimitive.getLong(constant)));
        break;
      case WeaselPrimitive.FLOAT:
        instructionList.add(line, new WeaselInstructionLoadConstFloat(WeaselPrimitive.getFloat(constant)));
        break;
      case WeaselPrimitive.DOUBLE:
        instructionList.add(line, new WeaselInstructionLoadConstDouble(WeaselPrimitive.getDouble(constant)));
        break;
      }
    }catch(WeaselNativeException e){
      throw new WeaselCompilerException(this.instructionList.getLine(), e.getMessage());
    }
    if(WeaselPrimitive.getPrimitiveID(weaselGenericClass.getBaseClass())==0){
      instructionList.addWithoutLine(new WeaselInstructionCast(weaselGenericClass.getBaseClass().getByteName()));
    }
    returnType = weaselGenericClass;
    this.instructionList = instructionList;
    return instructionList;
  }
View Full Code Here


    }else{
      expectWrapper = weaselGenericClass;
    }
   
    if(returnType.getBaseClass().isPrimitive()){
      instructions.addWithoutLine(new WeaselInstructionCast(returnWrapper.getBaseClass().getByteName()));
    }
   
    if(!returnWrapper.getBaseClass().isInterface() && !expectWrapper.getBaseClass().isInterface()){
      if(returnWrapper.canCastTo(expectWrapper) && !expectWrapper.canCastTo(returnWrapper)){
        throw new WeaselCompilerException(instructions.getLine(), "Types %s and %s are not compatible", returnType, weaselGenericClass);
      }
    }
   
    instructions.addWithoutLine(new WeaselInstructionCast(expectWrapper.getBaseClass().getRealName()));
   
    if(weaselGenericClass.getBaseClass().isPrimitive()){
      instructions.addWithoutLine(new WeaselInstructionCastPrimitive(WeaselPrimitive.getPrimitiveID(weaselGenericClass.getBaseClass())));
    }
    returnType = weaselGenericClass;
View Full Code Here

      wcr = compileOperator(compiler, compilerHelper, write, ret, elementParent, isVariable, i+1);
      instructions = wcr.getInstructions();
      if(wc.isPrimitive()){
        instructions.add(operator.line, new WeaselInstructionCastPrimitive(WeaselPrimitive.getPrimitiveID(wc)));
      }else{
        instructions.add(operator.line, new WeaselInstructionCast(wc.getByteName()));
      }
    }else if(oper==WeaselOperator.MINUS_PREFIX || oper==WeaselOperator.PLUS_PREFIX){
      wcr = compileOperator(compiler, compilerHelper, null, null, null, false, i+1);
      instructions = wcr.getInstructions();
      ret = wcr.getReturnType();
View Full Code Here

  }

  public static WeaselGenericClass autoCast(WeaselCompiler compiler, WeaselGenericClass wc1, WeaselGenericClass wc2, int line, WeaselInstructionList instructions, boolean b) throws WeaselCompilerException{
    if(!wc1.getBaseClass().isPrimitive() && wc2.getBaseClass().isPrimitive()){
      wc2 = new WeaselGenericClass(compiler.getWeaselClass(WeaselPrimitive.getWrapper(wc2.getBaseClass())));
      instructions.add(line, new WeaselInstructionCast(wc2.getBaseClass().getByteName()));
    }else if(wc1.getBaseClass().isPrimitive() && wc2.getBaseClass().isPrimitive()){
      if(wc1.getBaseClass()!=wc2.getBaseClass()){
        boolean canCast = WeaselPrimitive.canCastAutoTo(wc1.getBaseClass(), wc2.getBaseClass());
        if(canCast){
          instructions.add(line, new WeaselInstructionCastPrimitive(WeaselPrimitive.getPrimitiveID(wc2.getBaseClass())));
View Full Code Here

    }else{
      expectWrapper = weaselGenericClass;
    }
   
    if(returnType.getBaseClass().isPrimitive()){
      instructionList.addWithoutLine(new WeaselInstructionCast(returnWrapper.getBaseClass().getByteName()));
    }
   
    if(!returnWrapper.getBaseClass().isInterface() && !expectWrapper.getBaseClass().isInterface()){
      if(returnWrapper.canCastTo(expectWrapper) && !expectWrapper.canCastTo(returnWrapper)){
        throw new WeaselCompilerException(instructionList.getLine(), "Types %s and %s are not compatible", returnType, weaselGenericClass);
      }
    }
   
    instructionList.addWithoutLine(new WeaselInstructionCast(expectWrapper.getBaseClass().getRealName()));
   
    if(weaselGenericClass.getBaseClass().isPrimitive()){
      instructionList.addWithoutLine(new WeaselInstructionCastPrimitive(WeaselPrimitive.getPrimitiveID(weaselGenericClass.getBaseClass())));
    }
    returnType = weaselGenericClass;
View Full Code Here

TOP

Related Classes of weasel.interpreter.bytecode.WeaselInstructionCast

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.