Examples of WeaselInstruction


Examples of weasel.interpreter.bytecode.WeaselInstruction

    WeaselCompilerReturn wcr;
    if(instructions == null){
      instructions = new WeaselInstructionList();
      instructions.add(token.line, new WeaselInstructionJumperDummy());
    }
    WeaselInstruction startJump = instructions.getLast();
    wcr = tree2.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.voidClass), null, false);
    instructions.addAll(wcr.getInstructions());
    WeaselTree.autoCast(compiler, wcr.getReturnType(), new WeaselGenericClass(compiler.baseTypes.booleanClass), token.line, instructions, true);
    WeaselInstructionIf ifI;
    instructions.add(token.line, ifI = new WeaselInstructionIf());
    if(t.tokenType==WeaselTokenType.OPENBLOCK){
      t = iterator.next();
      while(t.tokenType!=WeaselTokenType.CLOSEBLOCK){
        iterator.previous();
        instructions.addAll(WeaselTree.parseAndCompile(compiler, compilerHelpher, iterator));
        t = iterator.next();
      }
    }else{
      iterator.previous();
      instructions.addAll(WeaselTree.parseAndCompile(compiler, compilerHelpher, iterator));
    }
    WeaselInstruction continueJump = instructions.getLast();
    if(tree3!=null){
      wcr = tree3.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.voidClass), null, false);
      instructions = wcr.getInstructions();
      if(wcr.getReturnType().getBaseClass()!=compiler.baseTypes.voidClass)
        instructions.add(t.line, new WeaselInstructionPop());
    }
    WeaselInstruction ifJump = new WeaselInstructionJump(startJump);
    instructions.add(token.line, ifJump);
    ifI.setTarget(ifJump);
    WeaselBlockInfo wbi = compilerHelpher.closeBlock();
    int pops = wbi.varsToPop();
    if(pops==1){
      instructions.add(t.line, new WeaselInstructionPop());
    }else if(pops>1){
      instructions.add(t.line, new WeaselInstructionPops(pops));
    }
    if(pops>=1){
      instructions.add(token.line, new WeaselInstructionReservate(pops));
    }
    WeaselInstruction breakJump = instructions.getLast();
    for(WeaselInstructionJump breakI:wbi.breaks){
      breakI.setTarget(breakJump);
    }
    for(WeaselInstructionJump continueI:wbi.continues){
      continueI.setTarget(continueJump);
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

    this.line = line;
  }

  public boolean gotoCatchForClass(WeaselClass weaselClass) {
    int newOpened = 0;
    WeaselInstruction instruction;
    while(true){
      instruction = method.getInstruction(programPointer++);
      if(instruction==null)
        return false;
      if(instruction instanceof WeaselInstructionTry){
        newOpened++;
      }else if(instruction instanceof WeaselInstructionTryEnd){
        if(newOpened>0){
          newOpened--;
        }else{
          endTry();
        }
      }else if(instruction instanceof WeaselInstructionLine){
        instruction.run(interpreter, thread, this);
      }else if(instruction instanceof WeaselInstructionCatch){
        if(newOpened==0){
          if(weaselClass.canBeCastTo(((WeaselInstructionCatch)instruction).getAceptedExceptionClass(interpreter))){
            programPointer--;
            return true;
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

      throw new WeaselCompilerException(token.line, "Expect boolean value in while");
    }
    WeaselToken t = iterator.next();
    WeaselCompilerReturn wcr;
    WeaselInstructionList instructions = new WeaselInstructionList();
    WeaselInstruction continueJump = new WeaselInstructionJumperDummy();
    instructions.add(token.line, continueJump);
    wcr = tree1.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.booleanClass), null, false);
    instructions.addAll(wcr.getInstructions());
    WeaselTree.autoCast(compiler, wcr.getReturnType(), new WeaselGenericClass(compiler.baseTypes.booleanClass), token.line, instructions, true);
    WeaselInstructionIf ifI;
    instructions.add(token.line, ifI = new WeaselInstructionIf());
    if(t.tokenType==WeaselTokenType.OPENBLOCK){
      t = iterator.next();
      while(t.tokenType!=WeaselTokenType.CLOSEBLOCK){
        iterator.previous();
        instructions.addAll(WeaselTree.parseAndCompile(compiler, compilerHelpher, iterator));
        t = iterator.next();
      }
    }else{
      iterator.previous();
      instructions.addAll(WeaselTree.parseAndCompile(compiler, compilerHelpher, iterator));
    }
    WeaselInstruction ifJump = new WeaselInstructionJump(continueJump);
    instructions.add(token.line, ifJump);
    ifI.setTarget(ifJump);
    WeaselBlockInfo wbi = compilerHelpher.closeBlock();
    int pops = wbi.varsToPop();
    if(pops==1){
      instructions.add(token.line, new WeaselInstructionPop());
    }else if(pops>1){
      instructions.add(token.line, new WeaselInstructionPops(pops));
    }
    if(pops>=1){
      instructions.add(t.line, new WeaselInstructionReservate(pops));
    }
    WeaselInstruction breakJump = instructions.getLast();
    for(WeaselInstructionJump breakI:wbi.breaks){
      breakI.setTarget(breakJump);
    }
    for(WeaselInstructionJump continueI:wbi.continues){
      continueI.setTarget(continueJump);
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

    }
    t = iterator.next();
    if(t.tokenType!=WeaselTokenType.KEYWORD || t.param!=WeaselKeyWord.WHILE){
      throw new WeaselCompilerException(t.line, "expect while but got %s", t);
    }
    WeaselInstruction continueJump = instructions.getLast();
    expect(t = iterator.next(), WeaselTokenType.OPENBRACKET);
    WeaselTree tree1 = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
    if(tree1==null){
      throw new WeaselCompilerException(t.line, "Expect boolean value in while");
    }
    WeaselCompilerReturn wcr;
    wcr = tree1.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.booleanClass), null, false);
    instructions.addAll(wcr.getInstructions());
    WeaselTree.autoCast(compiler, wcr.getReturnType(), new WeaselGenericClass(compiler.baseTypes.booleanClass), t.line, instructions, true);
    WeaselInstruction ifJump = new WeaselInstructionJump(startJump);
    instructions.add(t.line, new WeaselInstructionIf(ifJump));
    instructions.add(t.line, ifJump);
    WeaselBlockInfo wbi = compilerHelpher.closeBlock();
    int pops = wbi.varsToPop();
    if(pops==1){
      instructions.add(t.line, new WeaselInstructionPop());
    }else if(pops>1){
      instructions.add(t.line, new WeaselInstructionPops(pops));
    }
    if(pops>=1){
      instructions.addFirst(token.line, new WeaselInstructionReservate(pops));
    }
    WeaselInstruction breakJump = instructions.getLast();
    for(WeaselInstructionJump breakI:wbi.breaks){
      breakI.setTarget(breakJump);
    }
    for(WeaselInstructionJump continueI:wbi.continues){
      continueI.setTarget(continueJump);
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

    if(sleepTime<=0)
      sleepTime = 0;
  }
 
  public void runNextInstruction() {
    WeaselInstruction instrucion;
    do{
      while(true){
        instrucion = methodExecutor.getNextInstruction();
        if(instrucion!=null)
          break;
        callReturn();
        if(methodExecutor==null)
          return;
      }
      try{
        instrucion.run(interpreter, this, methodExecutor);
      }catch(Throwable e){
        WeaselRuntimeException wre;
        if(e instanceof WeaselRuntimeException){
          wre = (WeaselRuntimeException)e;
        }else{
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

  }

  public boolean gotoCatchForClass(WeaselClass weaselClass) {
    int newOpened = 0;
    int syncStarted = 0;
    WeaselInstruction instruction;
    while(true){
      instruction = method.getInstruction(programPointer++);
      if(instruction==null)
        return false;
      if(instruction instanceof WeaselInstructionTry){
        newOpened++;
      }else if(instruction instanceof WeaselInstructionTryEnd){
        if(newOpened>0){
          newOpened--;
        }else{
          endTry();
        }
      }else if(instruction instanceof WeaselInstructionLine){
        instruction.run(thread.interpreter, thread, this);
      }else if(instruction instanceof WeaselInstructionCatch){
        if(newOpened==0){
          if(weaselClass.canCastTo(((WeaselInstructionCatch)instruction).getAceptedExceptionClass(thread.interpreter))){
            programPointer--;
            return true;
          }
        }
      }else if(instruction instanceof WeaselInstructionSync){
        syncStarted++;
      }else if(instruction instanceof WeaselInstructionSyncEnd){
        if(syncStarted<=0){
          syncStarted = 0;
          instruction.run(thread.interpreter, thread, this);
        }else{
          syncStarted--;
        }
      }
    }
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

    }
    instructions.add(instruction);
  }
 
  public void addFirst(int line, WeaselInstructionReservate instruction) {
    WeaselInstruction inst = instructions.get(0);
    if(inst instanceof WeaselInstructionLine){
      int rline = ((WeaselInstructionLine) inst).getLine();
      if(rline==line){
        instructions.add(1, instruction);
        return;
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

  }

  public WeaselInstruction[] getInstructions() {
    for(WeaselInstruction instruction:instructions){
      if(instruction instanceof WeaselInstructionJump){
        WeaselInstruction target = ((WeaselInstructionJump) instruction).getTarget();
        int i=0;
        for(WeaselInstruction targetInstruction:instructions){
          if(targetInstruction==target)
            break;
          i++;
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

    return instructions.get(instructions.size()-1);
  }

  public void replacePlaceHolderWith(WeaselInstructionList instructions2) {
    List<WeaselInstruction> after = new ArrayList<WeaselInstruction>();
    WeaselInstruction wi;
    while(!((wi = instructions.remove(instructions.size()-1)) instanceof WeaselInstructionPlaceHolder)){
      after.add(0, wi);
    }
    instructions.addAll(instructions2.instructions);
    instructions.addAll(after);
View Full Code Here

Examples of weasel.interpreter.bytecode.WeaselInstruction

    if(sleepTime<=0)
      sleepTime = 0;
  }
 
  public void runNextInstruction() {
    WeaselInstruction instrucion;
    do{
      while(true){
        instrucion = methodInfo.getNextInstruction();
        if(instrucion!=null)
          break;
        methodInfo = methodInfo.getCaller();
        if(methodInfo==null)
          return;
      }
      try{
        instrucion.run(interpreter, this, methodInfo);
      }catch(Throwable e){
        WeaselRuntimeException wre;
        if(e instanceof WeaselRuntimeException){
          wre = (WeaselRuntimeException)e;
        }else{
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.