Package weasel.interpreter.bytecode

Examples of weasel.interpreter.bytecode.WeaselInstructionInvoke


       
        instructions.add(token.line, new WeaselInstructionNew(weaselClass.getByteName()));
       
        instructions.add(token.line, new WeaselInstructionPush(1));
       
        instructions.add(token.line, new WeaselInstructionInvoke(weaselClass.getRealName()+".<preInit>()"));
       
        List<WeaselGenericMethod2> methods = genericClass.getGenericMethods("<init>", true);
       
        instructions.add(token.line, new WeaselInstructionPush(1));
       
        WeaselParameterCompileReturn wcr = WeaselTree.compileParamList(token.line, newClass, compiler, compilerHelper, func, methods);
       
        instructions.addAll(wcr.instructions);
       
        instructions.add(token.line, new WeaselInstructionInvoke(wcr.method.getMethod().getMethod().getClassNameAndDesk()));
       
      }else{
       
        String className = weaselClass.getByteName();
        for(int i=0; i<arraySize.size(); i++){
          className = "["+className;
        }
       
        genericClass = new WeaselGenericClass(compiler.getWeaselClass(className), genericClass.getGenerics());
       
        if(arrayInit==null){
         
          className = weaselClass.getByteName();
         
          int sizes = 0;
          for(WeaselTree tree:arraySize){
            if(tree==null){
              className = "["+className;
            }else{
              WeaselCompilerReturn wcr = tree.compile(compiler, compilerHelper, null, new WeaselGenericClass(compiler.baseTypes.intClass), null, false);
              instructions.addAll(wcr.getInstructions(compiler, compiler.baseTypes.intClass));
              sizes++;
            }
          }
         
          instructions.add(token.line, new WeaselInstructionNewArray(className, sizes));
         
        }else{
          instructions.addAll(arrayInit.compile(compiler, compilerHelper, genericClass));
        }
       
      }
     
      return new WeaselCompilerReturnInstructionList(instructions, genericClass);
    }else if(isFunc){
      List<WeaselGenericMethod2> methods;
      if(elementParent==null){
        methods = compilerHelper.getGenericMethods((String)token.param);
      }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()));
        }
      }
     
View Full Code Here


    WeaselInstructionList instructions = new WeaselInstructionList();
    ListIterator<WeaselToken> iterator = methodTokens.listIterator();
    if(method.getName().equals("<preInit>")){
      if(method.getParentClass().getSuperClass()!=null){
        instructions.add(0, new WeaselInstructionLoadVariable(getVariable("this").pos));
        instructions.add(0, new WeaselInstructionInvoke(method.getParentClass().getSuperClass().getRealName()+".<preInit>()"));
      }
    }else if(method.getName().equals("<init>")){
      boolean auto = true;
      if(iterator.hasNext()){
        WeaselToken token = iterator.next();
        if(token!=null && token.tokenType==WeaselTokenType.KEYWORD){
          if(iterator.next().tokenType==WeaselTokenType.OPENBRACKET){
            try{
              if(token.param==WeaselKeyWord.THIS){
                superCaller = false;
                auto = false;
                WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
                List<WeaselGenericMethod2> methods = classCompiler.genericClass.getGenericMethodsOfThis("<init>", true);
                WeaselParameterCompileReturn wpcr = WeaselTree.compileParamList(token.line, "<init>", compiler, this, tree, methods);
                instructions.addAll(wpcr.instructions);
                instructions.add(token.line, new WeaselInstructionInvoke(wpcr.method.getMethod().getMethod().getClassNameAndDesk()));
                token = iterator.next();
                if(token.tokenType!=WeaselTokenType.SEMICOLON)
                  throw new WeaselCompilerException(token.line, "Expect ; but got %s", token);
              }else if(token.param==WeaselKeyWord.SUPER){
                superCaller = true;
                auto = false;
                WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
                List<WeaselGenericMethod2> methods = classCompiler.genericClass.getGenericSuperClass().getGenericMethodsOfThis("<init>", true);
                WeaselParameterCompileReturn wpcr = WeaselTree.compileParamList(token.line, "<init>", compiler, this, tree, methods);
                instructions.addAll(wpcr.instructions);
                instructions.add(token.line, new WeaselInstructionInvoke(wpcr.method.getMethod().getMethod().getClassNameAndDesk()));
                token = iterator.next();
                if(token.tokenType!=WeaselTokenType.SEMICOLON)
                  throw new WeaselCompilerException(token.line, "Expect ; but got %s", token);
              }else{
                iterator.previous();
                iterator.previous();
              }
            }catch(WeaselCompilerException e){
              compiler.addWeaselCompilerMessage(new WeaselCompilerMessage(MessageType.ERROR, e.getLine(), parentClass.getFileName(), e.getMessage()));
              iterator.previous();
              token = iterator.next();
              while(token.tokenType!=WeaselTokenType.SEMICOLON && iterator.hasNext()){
                token = iterator.next();
              }
            }
          }else{
            iterator.previous();
            iterator.previous();
          }
        }else{
          iterator.previous();
        }
      }
      if(auto){
        superCaller = true;
        if(classCompiler.genericClass.getGenericSuperClass()!=null){
          WeaselGenericMethod2 method = classCompiler.genericClass.getGenericSuperClass().getGenericMethodOfThis("<init>()", new WeaselGenericClass[0]);
          if(method==null){
            compiler.addWeaselCompilerMessage(
                new WeaselCompilerMessage(MessageType.ERROR, 0, parentClass.getFileName(),
                    String.format("No default constructor in %s found", classCompiler.genericClass.getGenericSuperClass())));
          }else{
            instructions.add(0, new WeaselInstructionInvoke(method.getMethod().getMethod().getClassNameAndDesk()));
          }
        }
      }
    }
    while(iterator.hasNext()){
View Full Code Here

TOP

Related Classes of weasel.interpreter.bytecode.WeaselInstructionInvoke

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.