Package weasel.compiler

Examples of weasel.compiler.WeaselCompilerException


      iterator.previous();
      while(true){
        token = iterator.next();
        if(token.tokenType==WeaselTokenType.OPENBLOCK){
          if(canComeArray)
            throw new WeaselCompilerException(token.line, "Too many {");
          indexes.add(new WeaselArrayInit(iterator, arrays-1));
          token = iterator.next();
          if(token.tokenType==WeaselTokenType.CLOSEBLOCK)
            break;
          if(token.tokenType!=WeaselTokenType.COMMA)
            throw new WeaselCompilerException(token.line, "Expect } but gto %s", token);
        }else{
          iterator.previous();
          indexes.add(WeaselTree.parse(iterator, WeaselTokenType.COMMA, WeaselTokenType.CLOSEBLOCK));
          iterator.previous();
          token = iterator.next();
View Full Code Here


      if(o instanceof WeaselArrayInit){
        instructions.addAll(((WeaselArrayInit)o).compile(compiler, compilerHelper, arrayClass));
      }else{
        WeaselCompilerReturn wcr = ((WeaselTree)o).compile(compiler, compilerHelper, null, arrayClass, null, false);
        if(!wcr.getReturnType().canCastTo(arrayClass))
          throw new WeaselCompilerException(token.line, "Can't cast %s to %s", wcr.getReturnType(), arrayClass);
        instructions.addAll(wcr.getInstructions());
      }
      instructions.add(token.line, new WeaselInstructionPush(2));
      instructions.add(token.line, new WeaselInstructionLoadConstInteger(i));
      instructions.add(token.line, new WeaselInstructionWriteIndex(WeaselPrimitive.getPrimitiveID(arrayClass.getBaseClass())));
View Full Code Here

  public boolean close;
 
  public WeaselTreeGenericElement(ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
    WeaselToken token = iterator.next();
    if(token.tokenType!=WeaselTokenType.IDENT){
      throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
    }
    this.token = token;
    realClassName = (String) token.param;
    token = iterator.next();
    while(token.tokenType==WeaselTokenType.OPERATOR && token.param==WeaselOperator.ELEMENT){
      token = iterator.next();
      if(token.tokenType!=WeaselTokenType.IDENT){
        throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
      }
      realClassName = "."+(String) token.param;
      token = iterator.next();
    }
    className = realClassName;
View Full Code Here

    try{
      return new WeaselGenericClass(parentClass.getBaseClass().getInterpreter().getWeaselClass(classByteName), generic.getGenericClasses(parentClass));
    }catch(WeaselNativeException e){}
    WeaselGenericClass wgc = parentClass.getGenericClass(realClassName);
    if(wgc==null){
      throw new WeaselCompilerException(token.line, "Class %s not found", className);
    }
    WeaselClass wc = wgc.getBaseClass();
    int i=0;
    while(classByteName.charAt(i++)=='['){
      wc = new WeaselClass(wc.getInterpreter(), wc, "["+wc.getByteName(), null);
View Full Code Here

    this.generic = generic;
    if(token.tokenType==WeaselTokenType.KEYWORD && token.param == WeaselKeyWord.NEW){
      do{
        token = iterator.next();
        if(token.tokenType!=WeaselTokenType.IDENT)
          throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
        if(newClass==null){
          newClass = (String)token.param;
        }else{
          newClass += "."+(String)token.param;
        }
        token = iterator.next();
      }while(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.ELEMENT);
      if(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.LESS){
        this.generic = new WeaselTreeGeneric(iterator);
        if(this.generic.close){
          throw new WeaselCompilerException(token.line, "Expect Ident but got >");
        }
        token = iterator.next();
      }
      if(token.tokenType==WeaselTokenType.OPENBRACKET){
        func = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
      }else if(token.tokenType==WeaselTokenType.OPENINDEX){
        arraySize = new ArrayList<WeaselTree>();
        boolean size = true;
        boolean anySizeDesk=false;
        while(true){
          token = iterator.next();
          if(token.tokenType!=WeaselTokenType.CLOSEINDEX && size){
            iterator.previous();
            arraySize.add(WeaselTree.parse(iterator, WeaselTokenType.CLOSEINDEX));
            iterator.previous();
            token = iterator.next();
            anySizeDesk = true;
          }else{
            arraySize.add(null);
            size = false;
          }
          if(token.tokenType!=WeaselTokenType.CLOSEINDEX){
            throw new WeaselCompilerException(token.line, "Expect ] but got %s", token);
          }
          if(iterator.hasNext()){
            token = iterator.next();
            if(token.tokenType!=WeaselTokenType.OPENINDEX){
              iterator.previous();
              break;
            }
          }else{
            break;
          }
        }
        if(iterator.hasNext()){
          token = iterator.next();
          if(token.tokenType==WeaselTokenType.OPENBLOCK){
            if(anySizeDesk){
              throw new WeaselCompilerException(token.line, "Can't make array initializer while array have static size");
            }
            arrayInit = new WeaselArrayInit(iterator, arraySize.size());
          }else{
            iterator.previous();
          }
        }
      }else{
        throw new WeaselCompilerException(token.line, "Expect ( or [ but got %s", token);
      }
    }else{
      if(iterator.hasNext()){
        token = iterator.next();
        if(token.tokenType==WeaselTokenType.OPENBRACKET){
View Full Code Here

      }else{
        compiler.compileEasy(elementParent.getBaseClass());
        methods = elementParent.getGenericMethods((String)token.param, isVariable);
      }
      if(methods.isEmpty()){
        throw new WeaselCompilerException(token.line, "Method not found %s", token);
      }
     
      WeaselParameterCompileReturn wcr = WeaselTree.compileParamList(token.line, (String)token.param, compiler, compilerHelper, func, methods);
     
      if(elementParent==null){
        if(!WeaselModifier.isStatic(wcr.method.getMethod().getMethod().getModifier())){
          instructions.add(token.line, new WeaselInstructionLoadVariable(compilerHelper.getVariable("this").pos));
        }
      }
     
      instructions.addAll(wcr.instructions);
     
      if(elementParent==null){
        if(WeaselModifier.isStatic(wcr.method.getMethod().getMethod().getModifier())){
          instructions.add(token.line, new WeaselInstructionInvokeStatic(wcr.method.getMethod().getMethod().getNameAndDesk()));
        }else{
          instructions.add(token.line, new WeaselInstructionInvoke(wcr.method.getMethod().getMethod().getClassNameAndDesk()));
        }
      }else{
        if(isVariable){
          instructions.add(token.line, new WeaselInstructionInvoke(wcr.method.getMethod().getMethod().getClassNameAndDesk()));
        }else{
          instructions.add(token.line, new WeaselInstructionInvokeStatic(wcr.method.getMethod().getMethod().getNameAndDesk()));
        }
      }
     
      return new WeaselCompilerReturnInstructionList(instructions, wcr.method.getGenericReturn());
    }else if(isIndex){
      WeaselGenericClass arrayClass;
      String variable = (String)token.param;
      if(elementParent==null){
        WeaselVariableInfo wvi = compilerHelper.getVariable(variable);
        if(wvi==null){
          WeaselGenericField wf = compilerHelper.getGenericField(variable);
          if(wf==null){
            WeaselClass weaselClass;
            try{
              weaselClass = compiler.getWeaselClass(WeaselClass.mapClassNames(variable));
            }catch(WeaselNativeException e){
              throw new WeaselCompilerException(token.line, "Variable not declared bevore %s", variable);
            }
            return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(weaselClass), true);
          }
          if(WeaselModifier.isStatic(compilerHelper.getCompilingMethod().getMethod().getMethod().getModifier())){
            if(!WeaselModifier.isStatic(wf.getField().getModifier())){
              throw new WeaselCompilerException(token.line, "Variable %s is not static", variable);
            }
          }
          if(WeaselModifier.isStatic(wf.getField().getModifier())){
            instructions.add(token.line, new WeaselInstructionReadStaticField(wf.getField().getDesk()));
          }else{
            wvi = compilerHelper.getVariable("this");
            instructions.add(token.line, new WeaselInstructionReadFieldOf(wvi.pos, wf.getField().getDesk()));
          }
          arrayClass = wf.getGenericType();
        }else{
          arrayClass = wvi.type;
          instructions.add(token.line, new WeaselInstructionLoadVariable(wvi.pos));
        }
      }else{
        WeaselGenericField field = elementParent.getGenericField((String)token.param);
        if(field==null)
          throw new WeaselCompilerException(token.line, "Variable %s not declared in %s", token, elementParent);
        arrayClass = field.getGenericType();
        instructions.add(token.line, new WeaselInstructionReadField(field.getField().getDesk()));
      }
      if(!arrayClass.getBaseClass().isArray()){
        throw new WeaselCompilerException(token.line, "%s is not an array", arrayClass);
      }
      WeaselCompilerReturn wcr = func.compile(compiler, compilerHelper, null, new WeaselGenericClass(compiler.baseTypes.intClass), null, false);
      instructions.addAll(wcr.getInstructions(compiler, compiler.baseTypes.intClass));
      if(write==null){
        instructions.add(token.line, new WeaselInstructionReadIndex(WeaselPrimitive.getPrimitiveID(arrayClass.getBaseClass().getArrayClass())));
      }else{
        instructions.add(token.line, new WeaselInstructionPlaceHolder());
        WeaselTree.autoCast(compiler, write, new WeaselGenericClass(arrayClass.getBaseClass().getArrayClass(), arrayClass.getGenerics()), token.line, instructions, true);
        instructions.add(token.line, new WeaselInstructionWriteIndex(WeaselPrimitive.getPrimitiveID(arrayClass.getBaseClass().getArrayClass())));
      }
      return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(arrayClass.getBaseClass().getArrayClass(), arrayClass.getGenerics()));
    }else if(token==null){
      return tree.compile(compiler, compilerHelper, write, expect, elementParent, isVariable);
    }else{
      switch(token.tokenType){
      case BOOL:
      case DOUBLE:
      case INTEGER:
      case NULL:
      case STRING:
        if(write!=null){
          throw new WeaselCompilerException(token.line, "Can't write %s to constant %s", write, token);
        }
        return new WeaselCompilerReturnConstant(compiler, token.line, token.param);
      case KEYWORD:
        if(token.param!=WeaselKeyWord.THIS)
          throw new WeaselCompilerException(token.line, "Expect ident but got %s", token);
      case IDENT:
        String variable = token.toString();
        if(elementParent==null){
          WeaselVariableInfo wvi = compilerHelper.getVariable(variable);
          if(wvi==null){
            WeaselGenericField wf = compilerHelper.getGenericField(variable);
            if(wf==null){
              WeaselClass weaselClass;
              try{
                weaselClass = compiler.getWeaselClass(WeaselClass.mapClassNames(variable));
              }catch(WeaselNativeException e){
                throw new WeaselCompilerException(token.line, "Variable not declared bevore %s", variable);
              }
              return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(weaselClass), true);
            }
            if(WeaselModifier.isStatic(compilerHelper.getCompilingMethod().getMethod().getMethod().getModifier())){
              if(!WeaselModifier.isStatic(wf.getField().getModifier())){
                throw new WeaselCompilerException(token.line, "Variable %s is not static", variable);
              }
            }
            if(WeaselModifier.isStatic(wf.getField().getModifier())){
              if(write==null){
                instructions.add(token.line, new WeaselInstructionReadStaticField(wf.getField().getDesk()));
              }else{
                instructions.add(token.line, new WeaselInstructionPlaceHolder());
                WeaselTree.autoCast(compiler, write, wf.getGenericType(), token.line, instructions, true);
                instructions.add(token.line, new WeaselInstructionWriteStaticField(wf.getField().getDesk()));
              }
            }else{
              wvi = compilerHelper.getVariable("this");
              if(write==null){
                instructions.add(token.line, new WeaselInstructionReadFieldOf(wvi.pos, wf.getField().getDesk()));
              }else{
                instructions.add(token.line, new WeaselInstructionPlaceHolder());
                WeaselTree.autoCast(compiler, write, wf.getGenericType(), token.line, instructions, true);
                instructions.add(token.line, new WeaselInstructionWriteFieldOf(wvi.pos, wf.getField().getDesk()));
              }
            }
            return new WeaselCompilerReturnInstructionList(instructions, wf.getGenericType());
          }else{
            if(write==null){
              instructions.add(token.line, new WeaselInstructionLoadVariable(wvi.pos));
            }else{
              instructions.add(token.line, new WeaselInstructionPlaceHolder());
              WeaselTree.autoCast(compiler, write, wvi.type, token.line, instructions, true);
              instructions.add(token.line, new WeaselInstructionSaveVariable(wvi.pos));
            }
            return new WeaselCompilerReturnInstructionList(instructions, wvi.type);
          }
        }else{
          WeaselGenericField wf = elementParent.getGenericField(variable);
          if(wf==null){
            WeaselClass weaselClass;
            try{
              weaselClass = compiler.getWeaselClass(WeaselClass.mapClassNames(variable));
            }catch(WeaselNativeException e){
              throw new WeaselCompilerException(token.line, "Variable not declared bevore %s", variable);
            }
            if(isVariable){
              throw new WeaselCompilerException(token.line, "Can't get class form variable", variable);
            }
            return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(weaselClass), true);
          }
          if(isVariable){
            if(write==null){
              instructions.add(token.line, new WeaselInstructionReadField(wf.getField().getDesk()));
            }else{
              instructions.add(token.line, new WeaselInstructionPlaceHolder());
              WeaselTree.autoCast(compiler, write, wf.getGenericType(), token.line, instructions, true);
              instructions.add(token.line, new WeaselInstructionWriteField(wf.getField().getDesk()));
            }
          }else{
            if(!WeaselModifier.isStatic(wf.getField().getModifier()))
              throw new WeaselCompilerException(token.line, "Filed %s isn't static", wf);
            if(write==null){
              instructions.add(token.line, new WeaselInstructionReadStaticField(wf.getField().getDesk()));
            }else{
              instructions.add(token.line, new WeaselInstructionPlaceHolder());
              WeaselTree.autoCast(compiler, write, wf.getGenericType(), token.line, instructions, true);
              instructions.add(token.line, new WeaselInstructionWriteStaticField(wf.getField().getDesk()));
            }
          }
          return new WeaselCompilerReturnInstructionList(instructions, wf.getGenericType());
        }
      case CHAR:
        if(write!=null){
          throw new WeaselCompilerException(token.line, "Can't write %s to constant %s", write, token);
        }
        String s = (String) token.param;
        if(s.length()!=1)
          throw new WeaselCompilerException(token.line, "Only one char expected");
        return new WeaselCompilerReturnConstant(compiler, token.line, s.charAt(0));
      default:
        throw new WeaselCompilerException(token.line, "Expect ident but got %s", token);
      }
    }
  }
View Full Code Here

      if(wcr.getReturnType().canCastTo(wgc)){
        instructions = new WeaselInstructionList();
        instructions.add(operator.line, new WeaselInstructionLoadConstBoolean(true));
      }else{
        if(wcr.getReturnType().getBaseClass().isPrimitive())
          throw new WeaselCompilerException(operator.line, "can't use implements for primitives");
        instructions = wcr.getInstructions();
        instructions.add(operator.line, new WeaselInstructionInstanceof(wc.getByteName()));
      }
      ret = new WeaselGenericClass(compiler.baseTypes.booleanClass);
    }else if(oper==WeaselOperator.CAST){
      WeaselCastToken wct = (WeaselCastToken) operator;
      WeaselClass wc = compiler.getWeaselClass(WeaselClass.mapClassNames(wct.className));
      ret = new WeaselGenericClass(wc);
      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();
      int primitiveID = WeaselPrimitive.getPrimitiveID(ret.getBaseClass());
      if(oper==WeaselOperator.MINUS_PREFIX || oper==WeaselOperator.PLUS_PREFIX){
        if(primitiveID!=WeaselPrimitive.CHAR && primitiveID!=WeaselPrimitive.BYTE && primitiveID!=WeaselPrimitive.SHORT
            && primitiveID!=WeaselPrimitive.INT && primitiveID!=WeaselPrimitive.LONG
             && primitiveID!=WeaselPrimitive.FLOAT && primitiveID!=WeaselPrimitive.DOUBLE){
          throw new WeaselCompilerException(operator.line, "Operator %s is only usable with char, byte, short, int, long, float, double, not with %s", oper, ret);
        }
      }
      if(oper==WeaselOperator.MINUS_PREFIX){
        instructions.add(operator.line, new WeaselInstructionNeg(primitiveID));
      }
    }else{
      throw new WeaselCompilerException(operator.line, "Unknown operator %s", operator);
    }
    return new WeaselCompilerReturnInstructionList(instructions, ret);
  }
View Full Code Here

      ret = WeaselTree.autoCast(compiler, ret, wgc, operator.line, instructions, true);
      ret = WeaselGenericClass.getSmallestSame(wgc, ret);
      int primitiveID = WeaselPrimitive.getPrimitiveID(ret.getBaseClass());
      if(oper==WeaselOperator.LOGICAL_OR||oper==WeaselOperator.LOGICAL_AND){
        if(primitiveID!=WeaselPrimitive.BOOLEAN){
          throw new WeaselCompilerException(operator.line, "Operator %s is only usable with boolean, not with %s %s", oper, wgc, ret);
        }
      }else if(oper==WeaselOperator.BITWISE_OR || oper==WeaselOperator.BITWISE_AND || oper==WeaselOperator.BITWISE_XOR){
        if(primitiveID!=WeaselPrimitive.BOOLEAN && primitiveID!=WeaselPrimitive.CHAR && primitiveID!=WeaselPrimitive.BYTE &&
            primitiveID!=WeaselPrimitive.SHORT && primitiveID!=WeaselPrimitive.INT && primitiveID!=WeaselPrimitive.LONG){
          throw new WeaselCompilerException(operator.line, "Operator %s is only usable with boolean, char, byte, short, int, long, not with %s %s", oper, wgc, ret);
        }
      }else if(oper==WeaselOperator.LESS || oper==WeaselOperator.GREATER || oper==WeaselOperator.LESS_EQUAL
           || oper==WeaselOperator.GREATER_EQUAL){
        if(primitiveID!=WeaselPrimitive.CHAR && primitiveID!=WeaselPrimitive.BYTE && primitiveID!=WeaselPrimitive.SHORT
            && primitiveID!=WeaselPrimitive.INT && primitiveID!=WeaselPrimitive.LONG
             && primitiveID!=WeaselPrimitive.FLOAT && primitiveID!=WeaselPrimitive.DOUBLE){
          throw new WeaselCompilerException(operator.line, "Operator %s is only usable with char, byte, short, int, long, float, double, not with %s %s", oper, wgc, ret);
        }
        ret = new WeaselGenericClass(compiler.baseTypes.booleanClass);
      }else if(oper==WeaselOperator.PLUS || oper==WeaselOperator.MINUS || oper==WeaselOperator.TIMES || oper==WeaselOperator.DIVIDE
           || oper==WeaselOperator.REMAINDER){
        if(primitiveID!=WeaselPrimitive.CHAR && primitiveID!=WeaselPrimitive.BYTE && primitiveID!=WeaselPrimitive.SHORT
            && primitiveID!=WeaselPrimitive.INT && primitiveID!=WeaselPrimitive.LONG
             && primitiveID!=WeaselPrimitive.FLOAT && primitiveID!=WeaselPrimitive.DOUBLE){
          throw new WeaselCompilerException(operator.line, "Operator %s is only usable with char, byte, short, int, long, float, double, not with %s %s", oper, wgc, ret);
        }
      }
      if(oper==WeaselOperator.LOGICAL_OR){
        instructions.add(operator.line, new WeaselInstructionLogicalOr(primitiveID));
      }else if(oper==WeaselOperator.LOGICAL_AND){
        instructions.add(operator.line, new WeaselInstructionLogicalAnd(primitiveID));
      }else if(oper==WeaselOperator.BITWISE_OR){
        instructions.add(operator.line, new WeaselInstructionBitwiseOr(primitiveID));
      }else if(oper==WeaselOperator.BITWISE_AND){
        instructions.add(operator.line, new WeaselInstructionBitwiseAnd(primitiveID));
      }else if(oper==WeaselOperator.BITWISE_XOR){
        instructions.add(operator.line, new WeaselInstructionBitwiseXor(primitiveID));
      }else if(oper==WeaselOperator.LESS){
        instructions.add(operator.line, new WeaselInstructionLess(primitiveID));
      }else if(oper==WeaselOperator.GREATER){
        instructions.add(operator.line, new WeaselInstructionGreater(primitiveID));
      }else if(oper==WeaselOperator.LESS_EQUAL){
        instructions.add(operator.line, new WeaselInstructionLessEqual(primitiveID));
      }else if(oper==WeaselOperator.GREATER_EQUAL){
        instructions.add(operator.line, new WeaselInstructionGreaterEqual(primitiveID));
      }else if(oper==WeaselOperator.PLUS){
        instructions.add(operator.line, new WeaselInstructionAdd(primitiveID));
      }else if(oper==WeaselOperator.MINUS){
        instructions.add(operator.line, new WeaselInstructionSub(primitiveID));
      }else if(oper==WeaselOperator.TIMES){
        instructions.add(operator.line, new WeaselInstructionMul(primitiveID));
      }else if(oper==WeaselOperator.DIVIDE){
        instructions.add(operator.line, new WeaselInstructionDiv(primitiveID));
      }else if(oper==WeaselOperator.REMAINDER){
        instructions.add(operator.line, new WeaselInstructionMod(primitiveID));
      }
    }else if(oper==WeaselOperator.RSHIFT || oper==WeaselOperator.LSHIFT){
      wcr = compileInfixOperator(compiler, compilerHelper, null, expect, null, false, i-1);
      instructions.addAll(wcr.getInstructions());
      ret = wcr.getReturnType();
      wcr = level.get(i+1).compile(compiler, compilerHelper, null, expect, null, false);
      wgc = wcr.getReturnType();
      instructions.addAll(wcr.getInstructions());
      WeaselTree.autoCast(compiler, wgc, new WeaselGenericClass(compiler.baseTypes.intClass), operator.line, instructions, true);
      int primitiveID = WeaselPrimitive.getPrimitiveID(ret.getBaseClass());
      if(oper==WeaselOperator.RSHIFT||oper==WeaselOperator.LSHIFT){
        if(primitiveID!=WeaselPrimitive.CHAR && primitiveID!=WeaselPrimitive.BYTE && primitiveID!=WeaselPrimitive.SHORT
            && primitiveID!=WeaselPrimitive.INT && primitiveID!=WeaselPrimitive.LONG){
          throw new WeaselCompilerException(operator.line, "Operator %s is only usable with char, byte, short, int, long, not with %s", oper, ret);
        }
      }
      if(oper==WeaselOperator.RSHIFT){
        instructions.add(operator.line, new WeaselInstructionRShift(primitiveID));
      }else if(oper==WeaselOperator.LSHIFT){
        instructions.add(operator.line, new WeaselInstructionLShift(primitiveID));
      }
    }else if(oper==WeaselOperator.VERY_SAME || oper==WeaselOperator.NOT_VERY_SAME
           || oper==WeaselOperator.EQUAL || oper==WeaselOperator.NOT_EQUAL){
      wcr = compileInfixOperator(compiler, compilerHelper, null, expect, null, false, i-1);
      instructions.addAll(wcr.getInstructions());
      wgc = wcr.getReturnType();
      wcr = level.get(i+1).compile(compiler, compilerHelper, null, expect, null, false);
      ret = wcr.getReturnType();
      if(wgc.getBaseClass().isPrimitive()||ret.getBaseClass().isPrimitive())
        wgc = WeaselTree.autoCast(compiler, wgc, ret, operator.line, instructions, false);
      instructions.addAll(wcr.getInstructions());
      if(wgc.getBaseClass().isPrimitive()||ret.getBaseClass().isPrimitive())
        ret = WeaselTree.autoCast(compiler, ret, wgc, operator.line, instructions, true);
      int primitiveID = WeaselPrimitive.getPrimitiveID(ret.getBaseClass());
      if(oper==WeaselOperator.VERY_SAME){
        instructions.add(operator.line, new WeaselInstructionVerySame(primitiveID));
      }else if(oper==WeaselOperator.NOT_VERY_SAME){
        instructions.add(operator.line, new WeaselInstructionNotVerySame(primitiveID));
      }else if(oper==WeaselOperator.EQUAL){
        instructions.add(operator.line, new WeaselInstructionEqual(primitiveID));
      }else if(oper==WeaselOperator.NOT_EQUAL){
        instructions.add(operator.line, new WeaselInstructionNotEqual(primitiveID));
      }
      ret = new WeaselGenericClass(compiler.baseTypes.booleanClass);
    }else if(oper==WeaselOperator.ELEMENT){
      wcr = compileInfixOperator(compiler, compilerHelper, null, null, null, false, i-1);
      instructions.addAll(wcr.getInstructions());
      wgc = wcr.getReturnType();
      wcr = level.get(i+1).compile(compiler, compilerHelper, write, expect, wgc, !wcr.isClassAccess());
      ret = wcr.getReturnType();
      instructions.addAll(wcr.getInstructions());
    }else{
      throw new WeaselCompilerException(operator.line, "Unknown operator %s", operator);
    }
    return new WeaselCompilerReturnInstructionList(instructions, ret);
  }
View Full Code Here

    expect(iterator.next(), WeaselTokenType.OPENBRACKET);
    compilerHelpher.openBlock(true);
    WeaselInstructionList instructions = WeaselTree.parseAndCompileWhithVarDec(compiler, compilerHelpher, iterator);
    WeaselTree tree2 = WeaselTree.parse(iterator, WeaselTokenType.SEMICOLON);
    if(tree2==null){
      throw new WeaselCompilerException(token.line, "Expect boolean value in secound part of for");
    }
    WeaselTree tree3 = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
   
    WeaselToken t = iterator.next();
    WeaselCompilerReturn wcr;
View Full Code Here

    WeaselToken t = iterator.next();
    int s = 1;
    if(t.tokenType==WeaselTokenType.INTEGER){
      s = (Integer)t.param;
      if(s<=0)
        throw new WeaselCompilerException(t.line, "Negatives and 0 are not permitted");
      t = iterator.next();
    }
    WeaselInstructionList instructionList = new WeaselInstructionList();
    compilerHelpher.addClosingsAndFrees(s, instructionList, true);
    WeaselInstructionJump breakJump;
View Full Code Here

TOP

Related Classes of weasel.compiler.WeaselCompilerException

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.