Package weasel.interpreter

Examples of weasel.interpreter.WeaselGenericClass


  public WeaselCompilerReturn compile(WeaselToken token, WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelpher, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
    expect(iterator.next(), WeaselTokenType.OPENBRACKET);
    WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
    if(tree==null)
      throw new WeaselCompilerException(token.line, "Condition need to be a boolean value");
    WeaselCompilerReturn wcr = tree.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.booleanClass), null, false);
    WeaselInstructionList instructions = wcr.getInstructions();
    WeaselTree.autoCast(compiler, wcr.getReturnType(), new WeaselGenericClass(compiler.baseTypes.booleanClass), token.line, instructions, true);
    WeaselInstructionJump j1;
    instructions.add(token.line, j1 = new WeaselInstructionIf());
    instructions.addAll(compileBlock(compiler, compilerHelpher, iterator));
    WeaselToken t = iterator.next();
    if(t.tokenType==WeaselTokenType.KEYWORD && t.param == WeaselKeyWord.ELSE){
      WeaselInstructionJump j2;
      instructions.add(t.line, j2 = new WeaselInstructionJump());
      j1.setTarget(j2);
      instructions.addAll(compileBlock(compiler, compilerHelpher, iterator));
      j2.setTarget(instructions.getLast());
    }else{
      iterator.previous();
      j1.setTarget(instructions.getLast());
    }
    return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(compiler.baseTypes.voidClass));
  }
View Full Code Here


      return level.get(0).compile(compiler, compilerHelper, null, expect, elementParent, isVariable);
    WeaselToken operator = operators.get(i);
    Properties oper = (Properties)operator.param;
    WeaselInstructionList instructions;
    WeaselCompilerReturn wcr;
    WeaselGenericClass ret;
    if(oper==WeaselOperator.INSTANCEOF){
      WeaselInstanceofToken wit = (WeaselInstanceofToken) operator;
      WeaselClass wc = compiler.getWeaselClass("O"+wit.className+";");
      WeaselGenericClass wgc = new WeaselGenericClass(wc);
      wcr = compileOperator(compiler, compilerHelper, write, wgc, elementParent, isVariable, i-1);
      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{
View Full Code Here

      return level.get(operators.size()).compile(compiler, compilerHelper, write, expect, elementParent, isVariable);
    WeaselToken operator = operators.get(i);
    Properties oper = (Properties)operator.param;
    WeaselInstructionList instructions = new WeaselInstructionList();
    WeaselCompilerReturn wcr;
    WeaselGenericClass ret;
    WeaselGenericClass wgc;
    if(oper==WeaselOperator.COMMA){
      wcr = level.get(i).compile(compiler, compilerHelper, null, expect, null, false);
      instructions.addAll(wcr.getInstructions());
      ret = wcr.getReturnType();
      wcr = compileInfixOperator(compiler, compilerHelper, null, new WeaselGenericClass(compiler.baseTypes.voidClass), null, false, i+1);
      instructions.addAll(wcr.getInstructions());
      if(wcr.getReturnType().getBaseClass()!=compiler.baseTypes.voidClass){
        instructions.add(operator.line, new WeaselInstructionPop());
      }
    }else if(oper==WeaselOperator.ASSIGN){
      WeaselCompilerReturn wcr2 = compileInfixOperator(compiler, compilerHelper, null, expect, null, false, i+1);
      wcr = level.get(i).compile(compiler, compilerHelper, wcr2.getReturnType(), expect, null, false);
      instructions.addAll(wcr.getInstructions());
      instructions.replacePlaceHolderWith(wcr2.getInstructions());
      ret = wcr.getReturnType();
    }else if(oper==WeaselOperator.LOGICAL_OR || oper==WeaselOperator.LOGICAL_AND || oper==WeaselOperator.BITWISE_OR || oper==WeaselOperator.BITWISE_AND
         || oper==WeaselOperator.BITWISE_XOR || oper==WeaselOperator.LESS || oper==WeaselOperator.GREATER
         || oper==WeaselOperator.LESS_EQUAL || oper==WeaselOperator.GREATER_EQUAL
         || oper==WeaselOperator.PLUS || oper==WeaselOperator.MINUS || oper==WeaselOperator.TIMES || oper==WeaselOperator.DIVIDE
         || oper==WeaselOperator.REMAINDER){
      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();
      wgc = WeaselTree.autoCast(compiler, wgc, ret, operator.line, instructions, false);
      instructions.addAll(wcr.getInstructions());
      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());
View Full Code Here

    }
    iterator.previous();
 
    WeaselTree tree = parse(iterator, WeaselTokenType.SEMICOLON);
    if(tree!=null){
      WeaselCompilerReturn wcr = tree.compile(compiler, compilerHelper, null, new WeaselGenericClass(compiler.baseTypes.voidClass), null, false);
      return wcr.getInstructions(compiler, compiler.baseTypes.voidClass);
    }
    return null;
  }
View Full Code Here

    }
    iterator.previous();
 
    WeaselTree tree = parse(iterator, WeaselTokenType.SEMICOLON);
    if(tree!=null){
      WeaselCompilerReturn wcr = tree.compile(compiler, compilerHelper, null, new WeaselGenericClass(compiler.baseTypes.voidClass), null, false);
      return wcr.getInstructions(compiler, compiler.baseTypes.voidClass);
    }
    return null;
  }
View Full Code Here

      modifiers.add(token);
    }
    int modifier = getModifier(modifiers, WeaselModifier.FINAL);
    WeaselClassCompiler wcc = compilerHelper.getClassCompiler();
    WeaselGenericClassInfo wgci = wcc.readGenericClass(token, iterator);
    WeaselGenericClass wgc = wgci.getGenericClass(wcc.getGenericClass());
    iterator.previous();
    WeaselInstructionList instructions = new WeaselInstructionList();
    do{
      iterator.next();
      instructions.addAll(compileVar(modifier, wgc, compiler, compilerHelper, iterator));
View Full Code Here

      className = "["+className;
      token = iterator.next();
      WeaselCompiler.expect(token, WeaselTokenType.CLOSEINDEX);
      token = iterator.next();
    }
    wgc = new WeaselGenericClass(compiler.getWeaselClass(className), wgc.getGenerics());
    WeaselVariableInfo wvi = compilerHelper.newVar(modifier, varName, wgc);
    if(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.ASSIGN){
      WeaselCompilerReturn wcr = parse(iterator, WeaselTokenType.SEMICOLON, WeaselTokenType.COMMA).compile(compiler, compilerHelper, null, wgc, null, false);
      WeaselInstructionList instructions = wcr.getInstructions(compiler, wgc);
      instructions.add(token.line, new WeaselInstructionSaveVariable(wvi.pos));
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){
View Full Code Here

        Iterator<WeaselGenericMethod2> iterator = methods.iterator();
        while(iterator.hasNext()){
          if(iterator.next().getGenericParams().length!=param)
            iterator.remove();
        }
        WeaselGenericClass expect = null;
        if(methods.isEmpty())
          throw new WeaselCompilerException(line, "No method %s found with %s params", param);
        List<WeaselGenericClass> params = new ArrayList<WeaselGenericClass>();
        for(int i=0; i<param; i++){
          if(methods.size()==1)
            expect = methods.get(0).getGenericParams()[i];
          wcr = treeLevel.level.get(i).compile(compiler, compilerHelper, null, expect, null, false);
          instructions.addAll(wcr.getInstructions());
          params.add(wcr.getReturnType());
        }
        iterator = methods.iterator();
        while(iterator.hasNext()){
          WeaselGenericMethod2 m=iterator.next();
          for(int i=0; i<param; i++){
            if(params.get(i)!=null && !params.get(i).canCastTo(m.getGenericParams()[i]))
              iterator.remove();
          }
        }
        if(methods.isEmpty()){
          throw new WeaselCompilerException(line, "No method %s found with for params %s", methodName, params);
        }
        if(methods.size()==1){
          method = methods.get(0);
        }else{
          throw new WeaselCompilerException(line, "Not supported now");
        }
        return new WeaselParameterCompileReturn(instructions, method);
      }
    }
    if(func==null){
      method = null;
      for(WeaselGenericMethod2 m:methods){
        if(m.getGenericParams().length==0){
          method = m;
          break;
        }
      }
      if(method==null){
        throw new WeaselCompilerException(line, "No method %s found with no params", methodName);
      }
    }else{
      Iterator<WeaselGenericMethod2> iterator = methods.iterator();
      while(iterator.hasNext()){
        if(iterator.next().getGenericParams().length!=1)
          iterator.remove();
      }
      WeaselGenericClass expect = null;
      if(methods.isEmpty())
        throw new WeaselCompilerException(line, "No method %s found with one param", methodName);
      if(methods.size()==1)
        expect = methods.get(0).getGenericParams()[0];
      wcr = func.compile(compiler, compilerHelper, null, expect, null, false);
View Full Code Here

  public WeaselCompilerReturn compile(WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, WeaselGenericClass write, WeaselGenericClass expect, WeaselGenericClass elementParent, boolean isVariable) throws WeaselCompilerException {
    if(write!=null){
      throw new WeaselCompilerException(token.line, "Can't write any value to Condition");
    }
    WeaselInstructionList instructions;
    WeaselCompilerReturn wcr = condition.compile(compiler, compilerHelper, null, new WeaselGenericClass(compiler.baseTypes.booleanClass), null, false);
    instructions = wcr.getInstructions(compiler, compiler.baseTypes.booleanClass);
    WeaselInstructionJump j1;
    WeaselInstructionJump j2;
    instructions.add(token.line, j1 = new WeaselInstructionIf());
    wcr = tree1.compile(compiler, compilerHelper, null, expect, elementParent, isVariable);
    WeaselGenericClass wc = wcr.getReturnType();
    instructions.addAll(wcr.getInstructions());
    wcr = tree2.compile(compiler, compilerHelper, null, expect, elementParent, isVariable);
    if(wc.getBaseClass()==compiler.baseTypes.voidClass || wcr.getReturnType().getBaseClass()==compiler.baseTypes.voidClass){
      throw new WeaselCompilerException(token.line, "Can't return void");
    }
    WeaselGenericClass wc2 = wcr.getReturnType();
    wc = WeaselTree.autoCast(compiler, wc, wc2, token.line, instructions, false);
    instructions.add(token.line, j2 = new WeaselInstructionJump());
    j1.setTarget(j2);
    instructions.addAll(wcr.getInstructions());
    wc2 = WeaselTree.autoCast(compiler, wc2, wc, token.line, instructions, true);
View Full Code Here

TOP

Related Classes of weasel.interpreter.WeaselGenericClass

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.