Package maelstrom.funge.interpreter.stack

Examples of maelstrom.funge.interpreter.stack.Stack


public abstract class LogicalOperator implements Operator {

  public static class Not implements Operator {

    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();

      stack.push(stack.pop() == 0 ? 1 : 0);
    }
View Full Code Here


    /**
     * Pops one entry from the stack. Pushes a 1 if the entry is greater than 0, pushes a 0 otherwise
     */
    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();

      Long b = stack.pop();
      Long a = stack.pop();

      stack.push(a > b ? 1 : 0);
    }
View Full Code Here

  // Adds the two top most numbers on the stack
  public static class Add implements Operator {

    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();
      stack.push((stack.pop() + stack.pop()));
    }
View Full Code Here

  // Subtracts the two top most numbers on the stack
  public static class Subtract implements Operator {

    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();
      stack.push(0 - (stack.pop() - stack.pop()));
    }
View Full Code Here

  // Adds the two top most numbers on the stack
  public static class Multiply implements Operator {

    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();
      stack.push((stack.pop() * stack.pop()));
    }
 
View Full Code Here

  // Divides the two top most numbers on the stack
  public static class Divide implements Operator {

    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();

      long b = stack.pop();
      long a = stack.pop();

      if (b == 0) {
        stack.push(0);
      } else {
        stack.push(a / b);
      }
    }
View Full Code Here

  // Divides the two top most numbers on the stack
  public static class Modulus implements Operator {

    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();

      long b = stack.pop();
      long a = stack.pop();

      if (b == 0) {
        stack.push(0);
      } else {
        stack.push(a % b);
      }
    }
View Full Code Here

  // Clones the first element on the stack
  public static class OutputChar implements Operator {

    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();
      System.out.print((char)stack.pop());
    }
View Full Code Here

  // Swaps the first two values on the stack
  public static class OutputNum implements Operator {

    public void perform(Funge funge) {
      Stack stack = funge.getStackStack().getStack();
      System.out.print(stack.pop());
    }
View Full Code Here

    public void perform(Funge funge) {


      try {
        Stack stack = funge.getStackStack().getStack();
              stack.push(System.in.read());
            } catch (IOException err) {
              //TODO: Handle this exception as per spec
              err.printStackTrace();
            }
View Full Code Here

TOP

Related Classes of maelstrom.funge.interpreter.stack.Stack

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.