// Path: src/main/java/com/madisp/stupid/Block.java
// public class Block {
// 	private final StatementListExpression body;
// 	private final String[] varNames;
// 
// 	/**
// 	 * Create a new block with named arguments
// 	 * @param varNames list of argument names
// 	 * @param body expression that is to be evaluated
// 	 */
// 	public Block(String[] varNames, StatementListExpression body) {
// 		this.varNames = Arrays.copyOf(varNames, varNames.length);
// 		this.body = body;
// 	}
// 
// 	/**
// 	 * Evaluate the body of a block with given arguments. The length
// 	 * of arguments must match the length of given names in the constructor.
// 	 * @param ctx The context wherein to evaluate the block
// 	 * @param args argument values (must match the same length and order as given
// 	 *             in the constructor)
// 	 * @return The evaluated value of the block
// 	 */
// 	public Object yield(ExecContext ctx, Object... args) {
// 		if (varNames.length != args.length) {
// 			throw new IllegalArgumentException();
// 		}
// 		Map<String, Object> argMap = new HashMap<String, Object>();
// 		for (int i = 0; i < varNames.length; i++) {
// 			argMap.put(varNames[i], args[i]);
// 		}
// 		// wrap our block arguments over the underlying context
// 		StackContext withArgs = new StackContext();
// 		withArgs.pushExecContext(ctx); // the underlying context
// 		withArgs.pushExecContext(new VarContext(Collections.unmodifiableMap(argMap))); // args
// 		return body.value(withArgs);
// 	};
// }
// 
// Path: src/main/java/com/madisp/stupid/ExecContext.java
// public interface ExecContext {
// 	/**
// 	 * Get a field value from the environment.
// 	 * @param root The object whose field value is being queried. May be null which semantically
// 	 *             means getting a value from the "scope" or ExecContext itself.
// 	 * @param identifier field identifier
// 	 * @return the Java value of the given field
// 	 * @throws NoSuchFieldException if field was not found / getting value is not supported
// 	 */
// 	Object getFieldValue(Object root, String identifier) throws NoSuchFieldException;
// 
// 	/**
// 	 * Assigns a value to a field in the environment.
// 	 * @param root The object whose field value is being set. May be null which semantically
// 	 *             means getting a value from the "scope" or ExecContext itself.
// 	 * @param identifier field identifier
// 	 * @param value the new value for the field
// 	 * @return if successful, the value itself
// 	 * @throws NoSuchFieldException if the field was not found / setting values is not supported
// 	 */
// 	Object setFieldValue(Object root, String identifier, Object value) throws NoSuchFieldException;
// 
// 	/**
// 	 * Calls a method in the environment.
// 	 * @param root The object whose method is being called. May be null.
// 	 * @param identifier The method name
// 	 * @param args List of arguments, the types of these will be matched against the methods
// 	 * @return The result of calling {root}.{identifier}({args})
// 	 * @throws NoSuchMethodException if no method with matching signature was found or calling is not supported
// 	 */
// 	Object callMethod(Object root, String identifier, Object... args) throws NoSuchMethodException;
// 
// 	/**
// 	 * Yield a value with some arguments.
// 	 * Typically used for evaluating {@link Block} instances, but in some implementations
// 	 * may also be used to execute SAM (single-access-method) interface. For an example
// 	 * implementation see {@link com.madisp.stupid.context.ReflectionContext}
// 	 * @param base The object/value to yield
// 	 * @param args The arguments, if any, to apply
// 	 * @return The result of yielding the base object
// 	 * @throws NoSuchMethodException
// 	 */
// 	Object apply(Object base, Object[] args) throws NoSuchMethodException;
// 
// 	/**
// 	 * Obtain a descriptor for a given resource.
// 	 * The only Android-specific part in stupid. This method was intended to be used
// 	 * for resolving android integer ID's from package-type-name tuplets. It may be
// 	 * reused for other purposes if it makes sense. All implementations in stupid itself
// 	 * currently throw NoSuchFieldException.
// 	 * @param pckg The package name of the resource
// 	 * @param type The type of the resource
// 	 * @param name The identifier for the resource
// 	 * @return An object describing the resource
// 	 * @throws NoSuchFieldException if the resource wasn't found
// 	 */
// 	Object getResource(String pckg, String type, String name) throws NoSuchFieldException;
// 
// 	/**
// 	 * Dereference an object.
// 	 * Usually this means applying .value(this) onto a value until
// 	 * we have a POJO instance. See {@link com.madisp.stupid.context.BaseContext} for an
// 	 * implementation.
// 	 * @param object The object to dereference. May be null.
// 	 * @return The dereferenced object. May return the same object if it already was dereferenced.
// 	 */
// 	Object dereference(Object object);
// 
// 	/**
// 	 * Obtain the type coercion rules.
// 	 * @return the Converter defining the type coercion rules for the environment
// 	 */
// 	Converter getConverter();
// }


import com.madisp.stupid.Block;
import com.madisp.stupid.ExecContext;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
	@Override
	public Object getFieldValue(Object root, String identifier) {
		Iterator<ExecContext> iter = stack.iterator();
		while (iter.hasNext()) {
			try {
				return iter.next().getFieldValue(root, identifier);
			} catch (NoSuchFieldException e) {
				// ignore, jump to next scope
				if (false) { e.printStackTrace(); }
			}
		}
		return null;
	}

	@Override
	public Object setFieldValue(Object root, String identifier, Object value) {
		Iterator<ExecContext> iter = stack.descendingIterator();
		while (iter.hasNext()) {
			try {
				return iter.next().setFieldValue(root, identifier, value);
			} catch (NoSuchFieldException e) {
				// ignore, jump to next scope
				if (false) { e.printStackTrace(); }
			}
		}
		return null;
	}

	@Override
	public Object callMethod(Object root, String identifier, Object... args) {
// Path: src/main/java/com/madisp/stupid/Block.java
// public class Block {
// 	private final StatementListExpression body;
// 	private final String[] varNames;
// 
// 	/**
// 	 * Create a new block with named arguments
// 	 * @param varNames list of argument names
// 	 * @param body expression that is to be evaluated
// 	 */
// 	public Block(String[] varNames, StatementListExpression body) {
// 		this.varNames = Arrays.copyOf(varNames, varNames.length);
// 		this.body = body;
// 	}
// 
// 	/**
// 	 * Evaluate the body of a block with given arguments. The length
// 	 * of arguments must match the length of given names in the constructor.
// 	 * @param ctx The context wherein to evaluate the block
// 	 * @param args argument values (must match the same length and order as given
// 	 *             in the constructor)
// 	 * @return The evaluated value of the block
// 	 */
// 	public Object yield(ExecContext ctx, Object... args) {
// 		if (varNames.length != args.length) {
// 			throw new IllegalArgumentException();
// 		}
// 		Map<String, Object> argMap = new HashMap<String, Object>();
// 		for (int i = 0; i < varNames.length; i++) {
// 			argMap.put(varNames[i], args[i]);
// 		}
// 		// wrap our block arguments over the underlying context
// 		StackContext withArgs = new StackContext();
// 		withArgs.pushExecContext(ctx); // the underlying context
// 		withArgs.pushExecContext(new VarContext(Collections.unmodifiableMap(argMap))); // args
// 		return body.value(withArgs);
// 	};
// }
// 
// Path: src/main/java/com/madisp/stupid/ExecContext.java
// public interface ExecContext {
// 	/**
// 	 * Get a field value from the environment.
// 	 * @param root The object whose field value is being queried. May be null which semantically
// 	 *             means getting a value from the "scope" or ExecContext itself.
// 	 * @param identifier field identifier
// 	 * @return the Java value of the given field
// 	 * @throws NoSuchFieldException if field was not found / getting value is not supported
// 	 */
// 	Object getFieldValue(Object root, String identifier) throws NoSuchFieldException;
// 
// 	/**
// 	 * Assigns a value to a field in the environment.
// 	 * @param root The object whose field value is being set. May be null which semantically
// 	 *             means getting a value from the "scope" or ExecContext itself.
// 	 * @param identifier field identifier
// 	 * @param value the new value for the field
// 	 * @return if successful, the value itself
// 	 * @throws NoSuchFieldException if the field was not found / setting values is not supported
// 	 */
// 	Object setFieldValue(Object root, String identifier, Object value) throws NoSuchFieldException;
// 
// 	/**
// 	 * Calls a method in the environment.
// 	 * @param root The object whose method is being called. May be null.
// 	 * @param identifier The method name
// 	 * @param args List of arguments, the types of these will be matched against the methods
// 	 * @return The result of calling {root}.{identifier}({args})
// 	 * @throws NoSuchMethodException if no method with matching signature was found or calling is not supported
// 	 */
// 	Object callMethod(Object root, String identifier, Object... args) throws NoSuchMethodException;
// 
// 	/**
// 	 * Yield a value with some arguments.
// 	 * Typically used for evaluating {@link Block} instances, but in some implementations
// 	 * may also be used to execute SAM (single-access-method) interface. For an example
// 	 * implementation see {@link com.madisp.stupid.context.ReflectionContext}
// 	 * @param base The object/value to yield
// 	 * @param args The arguments, if any, to apply
// 	 * @return The result of yielding the base object
// 	 * @throws NoSuchMethodException
// 	 */
// 	Object apply(Object base, Object[] args) throws NoSuchMethodException;
// 
// 	/**
// 	 * Obtain a descriptor for a given resource.
// 	 * The only Android-specific part in stupid. This method was intended to be used
// 	 * for resolving android integer ID's from package-type-name tuplets. It may be
// 	 * reused for other purposes if it makes sense. All implementations in stupid itself
// 	 * currently throw NoSuchFieldException.
// 	 * @param pckg The package name of the resource
// 	 * @param type The type of the resource
// 	 * @param name The identifier for the resource
// 	 * @return An object describing the resource
// 	 * @throws NoSuchFieldException if the resource wasn't found
// 	 */
// 	Object getResource(String pckg, String type, String name) throws NoSuchFieldException;
// 
// 	/**
// 	 * Dereference an object.
// 	 * Usually this means applying .value(this) onto a value until
// 	 * we have a POJO instance. See {@link com.madisp.stupid.context.BaseContext} for an
// 	 * implementation.
// 	 * @param object The object to dereference. May be null.
// 	 * @return The dereferenced object. May return the same object if it already was dereferenced.
// 	 */
// 	Object dereference(Object object);
// 
// 	/**
// 	 * Obtain the type coercion rules.
// 	 * @return the Converter defining the type coercion rules for the environment
// 	 */
// 	Converter getConverter();
// }


// Path: src/main/java/com/madisp/stupid/context/StackContext.java
import com.madisp.stupid.Block;
import com.madisp.stupid.ExecContext;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;

	@Override
	public Object getFieldValue(Object root, String identifier) {
		Iterator<ExecContext> iter = stack.iterator();
		while (iter.hasNext()) {
			try {
				return iter.next().getFieldValue(root, identifier);
			} catch (NoSuchFieldException e) {
				// ignore, jump to next scope
				if (false) { e.printStackTrace(); }
			}
		}
		return null;
	}

	@Override
	public Object setFieldValue(Object root, String identifier, Object value) {
		Iterator<ExecContext> iter = stack.descendingIterator();
		while (iter.hasNext()) {
			try {
				return iter.next().setFieldValue(root, identifier, value);
			} catch (NoSuchFieldException e) {
				// ignore, jump to next scope
				if (false) { e.printStackTrace(); }
			}
		}
		return null;
	}

	@Override
	public Object callMethod(Object root, String identifier, Object... args) {
		Iterator<ExecContext> iter = stack.descendingIterator();