Package info.s5d.assembly

Source Code of info.s5d.assembly.AssemblyScript

package info.s5d.assembly;

import info.s5d.assembly.instruction.Instruction;
import info.s5d.assembly.instruction.handler.BasicInstructionHandler;
import info.s5d.assembly.instruction.handler.InstructionHandler;

import java.util.Stack;

public class AssemblyScript
{
  private Stack<Instruction> instructions;
  private InstructionHandler insnHandler;

  public AssemblyScript()
  {
    instructions = new Stack<Instruction>();
    insnHandler = new BasicInstructionHandler(this);
  }

  /**
   * Pushes an instruction onto the "bottom" of the script.
   *
   * @param instruction the instruction to be pushed
   */
  public void push(Instruction instruction)
  {
    instructions.push(instruction);
  }

  public int size()
  {
    return instructions.size();
  }

  public boolean empty()
  {
    return instructions.empty();
  }

  /**
   * Returns the instruction at the specified index
   */
  public Instruction instructionAt(int index)
  {
    return instructions.elementAt(index);
  }

  public void run()
  {
    run(0);
  }

  /**
   *
   * @param start which line to start running the script
   */
  public void run(int start)
  {
    /*for (Instruction instruction : instructions) {
      instruction.handleInstruction(insnHandler);
    }*/
    for (int i = start; i < size(); i++) {
      Instruction instruction = instructionAt(i);
      if (instruction == null)
        return; //we're done
      try {
        instruction.handleInstruction(insnHandler);
      } catch (Exception e) {
       
      }
    }
  }
}
TOP

Related Classes of info.s5d.assembly.AssemblyScript

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.