Package weasel.compiler

Examples of weasel.compiler.WeaselCompilerReturn


    }
    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


      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));
      instructions.add(token.line, new WeaselInstructionPop());
      compilerHelper.writeVar(wvi);
      return instructions;
    }else{
View Full Code Here

    }
    return wc1;
  }
 
  public static WeaselParameterCompileReturn compileParamList(int line, String methodName, WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, WeaselTree func, List<WeaselGenericMethod2> methods) throws WeaselCompilerException {
    WeaselCompilerReturn wcr;
    WeaselInstructionList instructions = new WeaselInstructionList();
    WeaselGenericMethod2 method;
    if(func instanceof WeaselTreeLevel){
      WeaselTreeLevel treeLevel = (WeaselTreeLevel) func;
      if(treeLevel.levelPriority == 0){
        int param=treeLevel.level.size();
        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);
      instructions.addAll(wcr.getInstructions());
      iterator = methods.iterator();
      while(iterator.hasNext()){
        WeaselGenericMethod2 m=iterator.next();
        if(!wcr.getReturnType().canCastTo(m.getGenericParams()[0]))
          iterator.remove();
      }
      if(methods.isEmpty()){
        throw new WeaselCompilerException(line, "No method %s found with for param %s", methodName, wcr.getReturnType());
      }
      if(methods.size()==1){
        method = methods.get(0);
      }else{
        throw new WeaselCompilerException(line, "Not supported now");
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);
    j2.setTarget(instructions.getLast());
    return new WeaselCompilerReturnInstructionList(instructions, WeaselGenericClass.getSmallestSame(wc, wc2));
  }
View Full Code Here

TOP

Related Classes of weasel.compiler.WeaselCompilerReturn

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.