public int load(int offset) {
    int temp = runStack.get(framePointers.peek() + offset);

    runStack.add(temp);

    return offset;
  }
Example #2
0
    private void processWrites(Context cx) {
      writeReady = true;
      removeInterest(SelectionKey.OP_WRITE);
      QueuedWrite qw = writeQueue.peek();
      while (qw != null) {
        try {
          if (qw.shutdown) {
            if (log.isDebugEnabled()) {
              log.debug("Sending shutdown for {}", clientChannel);
            }
            clientChannel.socket().shutdownOutput();
            sendWriteCallback(cx, qw, Context.getUndefinedValue());
          } else {
            int written = clientChannel.write(qw.buf);
            if (log.isDebugEnabled()) {
              log.debug("Wrote {} to {} from {}", written, clientChannel, qw.buf);
            }
            if (qw.buf.hasRemaining()) {
              // We didn't write the whole thing.
              writeReady = false;
              addInterest(SelectionKey.OP_WRITE);
              break;
            } else {
              sendWriteCallback(cx, qw, Context.getUndefinedValue());
            }
          }

        } catch (ClosedChannelException cce) {
          if (log.isDebugEnabled()) {
            log.debug("Channel is closed");
          }
          setErrno(Constants.EOF);
          sendWriteCallback(cx, qw, Constants.EOF);
        } catch (IOException ioe) {
          if (log.isDebugEnabled()) {
            log.debug("Error on write: {}", ioe);
          }
          setErrno(Constants.EIO);
          sendWriteCallback(cx, qw, Constants.EIO);
        }
        qw = writeQueue.peek();
      }
    }
Example #3
0
 @Override
 public void endUnionExpr(boolean create) {
   ArrayDeque stack = popFrame();
   if (create) {
     LocationPath result = new LocationPath(Scope.LOCAL, 0);
     result.addToContext((LocationPath) stack.pollFirst());
     result.addToContext((LocationPath) stack.pollFirst());
     push(result);
   } else push(stack.peek());
 }
Example #4
0
 public boolean isValid(String s) {
   ArrayDeque<Character> stack = new ArrayDeque<Character>();
   for (int i = 0; i < s.length(); i++) {
     if (!stack.isEmpty()) {
       Character top = stack.peek();
       if (top == '(' && s.charAt(i) == ')'
           || top == '[' && s.charAt(i) == ']'
           || top == '{' && s.charAt(i) == '}') {
         stack.pop();
       } else {
         stack.push(s.charAt(i));
       }
     } else {
       stack.push(s.charAt(i));
     }
   }
   return stack.isEmpty();
 }
  @Override
  public void render(float delta) {
    super.render(delta);

    int nextNodeIndex = -1;

    // prepare text

    kApplication.spriteBatch().begin();
    {
      this.background.draw(kApplication.spriteBatch());
    }
    kApplication.spriteBatch().end();

    this.chessboard_renderer_.begin();
    {
      nextNodeIndex = game_path_.peek().render(region_of_interest_);
    }
    this.chessboard_renderer_.end();

    kApplication.spriteBatch().begin();
    {
      hud.render(kApplication.spriteBatch(), delta);
    }
    kApplication.spriteBatch().end();

    if (nextNodeIndex > -1) {
      if (game_path_.size() > 1) {

        // Cull grandchildren to deallocate memory
        GraphSquare cur_top = game_path_.pop();
        game_path_.peek().CullGrandChildrenExcept(cur_top);
        game_path_.push(cur_top);
      }
      this.region_of_interest_.Reconstrain(
          game_path_.peek().getChildVirtualPosition(nextNodeIndex));
      game_path_.push(game_path_.peek().getChildNode(nextNodeIndex));

      this.hud.pushMove(this.game_path_.peek().toString());

    } else if (game_path_.size() > 1 && this.region_of_interest_.ZoomOutRequired()) {
      GraphSquare previous = game_path_.pop();
      region_of_interest_.Deconstrain(
          game_path_.peek().getChildVirtualPosition(game_path_.peek().getChildIndex(previous)));
      this.hud.popMove();
    }
  }
 /**
  * Return the root hash of a binary tree with leaves at the given depths and with the given hash
  * val in each leaf.
  */
 byte[] hashed(byte[] val, Integer... depths) {
   ArrayDeque<Integer> dstack = new ArrayDeque<Integer>();
   ArrayDeque<byte[]> hstack = new ArrayDeque<byte[]>();
   Iterator<Integer> depthiter = Arrays.asList(depths).iterator();
   if (depthiter.hasNext()) {
     dstack.push(depthiter.next());
     hstack.push(val);
   }
   while (depthiter.hasNext()) {
     Integer depth = depthiter.next();
     byte[] hash = val;
     while (depth.equals(dstack.peek())) {
       // consume the stack
       hash = Hashable.binaryHash(hstack.pop(), hash);
       depth = dstack.pop() - 1;
     }
     dstack.push(depth);
     hstack.push(hash);
   }
   assert hstack.size() == 1;
   return hstack.pop();
 }
 @SuppressWarnings("unchecked")
 public <T extends YAMLDescriptor> T peek() {
   return (T) stackedContext.peek();
 }
 public int peekFramePointers() {
   return framePointers.peek();
 }