package aya.entities;

import java.util.ArrayList;
import java.util.EmptyStackException;

import aya.obj.Obj;
import aya.obj.block.Block;

public class Tuple {	
	Block[] elements;
	
	/** 
	 * Tuples will not need to be resized during runtime
	 * @param blocks
	 */
	public Tuple(Block[] blocks) {
		elements = blocks;
	}
	
	/**
	 * evals each of the blocks and returns an array containing each
	 * of the results
	 * @return
	 */
	public ArrayList<Obj> evalToResults() {
		ArrayList<Obj> out = new ArrayList<Obj>(elements.length);
		for (int i = 0; i < elements.length; i++) {
			Block b = elements[i].duplicate();
			try {
				b.eval();
			} catch (EmptyStackException e) {
				throw new RuntimeException("Empty Stack in tuple");
			}
			out.add(b.pop());
		}
		return out;
	}
	
	public String toString() {
		String s = "(";
		for(int i = 0; i < elements.length; i++) {
			if(i!=0) {
				s += ", ";
			}
			s += elements[i].toString(false);
		}
		return s + ")";
	}
	
}

@@ -84,24 +84,68 @@
 ception;%0D%0A%0D%0A
+import aya.exceptions.AyaRuntimeException;%0D%0A
 import aya.o
@@ -757,16 +757,19 @@
 row new 
+Aya
 RuntimeE

Fix runtime exception in tuple execution