Package weasel.interpreter

Examples of weasel.interpreter.WeaselClass$WeaselID


  private void resolve(WeaselInterpreter interpreter){
    if(field==null || type==null){
      int d = fieldDesk.lastIndexOf(":");
      int p = fieldDesk.lastIndexOf(".", d);
      WeaselClass weaselClass = getWeaselClass(interpreter, fieldDesk.substring(0, p));
      field = weaselClass.getField(fieldDesk.substring(p+1, d));
      type = interpreter.getWeaselClass(fieldDesk.substring(d+1));
    }
  }
View Full Code Here


          params[i] = se.value;
        }
      }
      thread.popObject();
      Object ret = nativeMethod.invoke(interpreter, thread, method, methodBody.getNameAndDesk(), object, params);
      WeaselClass rc = this.method.getReturnClasses();
      switch(WeaselPrimitive.getPrimitiveID(rc)){
      case WeaselPrimitive.BOOLEAN:
        thread.pushValue((Boolean)ret);
        break;
      case WeaselPrimitive.CHAR:
View Full Code Here

    }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);
    }
    return new WeaselGenericClass(wc, wgc.getGenerics());
  }
View Full Code Here

  public String toString() {
    return className+(generic==null?"":generic.toString());
  }

  public WeaselGenericClassInfo getGenericClassInfo(WeaselClass parentClass) {
    WeaselClass wc = null;
    int genericID = -1;
    try{
      wc = parentClass.getInterpreter().getWeaselClass(classByteName);
    }catch(WeaselNativeException e){}
    if(wc==null){
View Full Code Here

  @Override
  public WeaselCompilerReturn compile(WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, WeaselGenericClass write, WeaselGenericClass expect, WeaselGenericClass elementParent, boolean isVariable) throws WeaselCompilerException {
    WeaselInstructionList instructions = new WeaselInstructionList();
    if(newClass!=null){
     
      WeaselClass weaselClass = compiler.getWeaselClass(WeaselClass.mapClassNames(newClass));
      //TODO
      WeaselGenericClass genericClass = new WeaselGenericClass(weaselClass);
     
      if(arraySize==null){
       
        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()));
        }
      }
     
      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);
            }
View Full Code Here

  private void resolve(WeaselInterpreter interpreter){
    if(field==null || type==null){
      int d = fieldDesk.lastIndexOf(":");
      int p = fieldDesk.lastIndexOf(".", d);
      WeaselClass weaselClass = getWeaselClass(interpreter, fieldDesk.substring(0, p));
      field = weaselClass.getField(fieldDesk.substring(p+1, d));
      type = interpreter.getWeaselClass(fieldDesk.substring(d+1));
    }
  }
View Full Code Here

        }else{
          params[i] = se.value;
        }
      }
      Object ret = nativeMethod.invoke(interpreter, thread, method, methodBody.getNameAndDesk(), null, params);
      WeaselClass rc = this.method.getReturnClasses();
      switch(WeaselPrimitive.getPrimitiveID(rc)){
      case WeaselPrimitive.BOOLEAN:
        thread.pushValue((Boolean)ret);
        break;
      case WeaselPrimitive.CHAR:
View Full Code Here

      do{
        token = getNextToken();
        WeaselCompiler.expect(token, WeaselTokenType.IDENT);
        String generic = (String)token.param;
        token = getNextToken();
        WeaselClass genericClass;
        if(token.tokenType == WeaselTokenType.KEYWORD && token.param == WeaselKeyWord.EXTENDS){
          ListIterator<WeaselToken> li;
          genericListClass.add(lwtge = new WeaselTreeGenericElement(li = tokenParser.listIterator()));
          if(lwtge.close){
            genericList.add(new WeaselGenericInformation(generic, lwtge.getWeaselClass(interpreter), -1));
View Full Code Here

  @Override
  public WeaselGenericClassInfo readGenericClass(WeaselToken token, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
    WeaselCompiler.expect(token, WeaselTokenType.IDENT);
    String className = WeaselClass.mapClassNames((String)token.param);
    int genericID = -1;
    WeaselClass weaselClass = null;
    for(int i=0; i<genericInformation.length; i++){
      if(className.equals("O"+genericInformation[i].genericName+";")){
        genericID = i;
        weaselClass = genericInformation[i].genericInfo.genericClass;
        break;
      }
    }
    if(genericID==-1){
      try{
        interpreter.getWeaselClass(className);
      }catch(WeaselNativeException e){
        throw new WeaselCompilerException(token.line, e.getMessage());
      }
    }
    token = iterator.next();
    List<WeaselGenericClassInfo> genericObjects = new ArrayList<WeaselGenericClassInfo>();
    if(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.LESS){
      do{
        token = iterator.next();
        WeaselCompiler.expect(token, WeaselTokenType.IDENT);
        genericObjects.add(readGenericClass(token, iterator));
        token = iterator.next();
      }while(token.tokenType == WeaselTokenType.COMMA);
      if(!(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.GREATER)){
        if(!(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.RSHIFT)){
          onException(token.line, "WeaselCompiler.expect > at end of generic");
        }else{
          token = new WeaselToken(WeaselTokenType.OPERATOR, token.line, WeaselOperator.GREATER);
        }
      }else{
        token = iterator.next();
      }
    }
    while(token.tokenType==WeaselTokenType.OPENINDEX){
      token = iterator.next();
      WeaselCompiler.expect(token, WeaselTokenType.CLOSEINDEX);
      token = iterator.next();
      className = "["+className;
    }
    iterator.previous();
    if(genericID==-1){
      try{
        weaselClass = interpreter.getWeaselClass(className);
      }catch(WeaselNativeException e){
        throw new WeaselCompilerException(token.line, e.getMessage());
      }
      return new WeaselGenericClassInfo(weaselClass, -1, genericObjects.toArray(new WeaselGenericClassInfo[0]));
    }else{
      while(className.charAt(0)=='['){
        weaselClass = new WeaselClass(interpreter, weaselClass, className, null);
        className = className.substring(1);
      }
      return new WeaselGenericClassInfo(weaselClass, genericID, genericObjects.toArray(new WeaselGenericClassInfo[0]));
    }
  }
View Full Code Here

    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{
        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

TOP

Related Classes of weasel.interpreter.WeaselClass$WeaselID

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.