package dspl.intermediate.instructions;


/**
 * Wrapper class for a series of instructions.  Its used by the tree walker
 * to keep track of the end of the instruction list.
 * 
 * @author Jeffrey
 */
public class InstructionSet 
{
	/**
	 * First insturction in the series
	 */
	private Instruction head;
	
	/**
	 * Final instruction in the series
	 */
	private Instruction tail;
	
	/**
	 * Primary contructor builds an empty list
	 */
	public InstructionSet()
	{
		head = null;
		tail = null;
	}
	
	/**
	 * Takes the next instruction and appends it to the list
	 * if there is currently no list, it starts the list
	 * @param next
	 */
	public void append(Instruction next)
	{
		if(head == null)
		{
			head = next;
			tail = next;
		}
		else
		{
			tail.setNextInstruction(next);
			tail = next;
		}
	}
	
	public void append(InstructionSet nextSet)
	{
		if(head == null)
		{
			this.head = nextSet.head;
			this.tail = nextSet.tail;
		}
		else
		{
			this.tail.setNextInstruction(nextSet.head);
			this.tail = nextSet.tail;
		}
		
	}
	
	/**
	 * Returns the head of the list
	 * @return
	 */
	public Instruction first()
	{
		return head;
	}
	
	public Instruction last()
	{
		return tail;
	}
	
}
