// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   MacroFunction.java

package lt.monarch.function;

import lt.monarch.function.node.ConstantNode;

// Referenced classes of package lt.monarch.function:
//			AbstractIdentifier, MacroIdentifier, MacroParameter, Node, 
//			FunctionError, Identifier, NodeCompiler

public class MacroFunction extends AbstractIdentifier
	implements MacroIdentifier
{

	protected Node body;
	protected MacroParameter params[];

	public int parameterCount()
	{
		return params.length;
	}

	public MacroParameter[] parameters()
	{
		return params;
	}

	public synchronized double evaluate(double ad[])
	{
		for(int i = 0; i < params.length; i++)
			params[i].setNode(new ConstantNode(ad[i]));

		return body.evaluate();
	}

	public synchronized Node expand(Node anode[])
	{
		for(int i = 0; i < params.length; i++)
			params[i].setNode(anode[i]);

		return body.cloneNode().simplify();
	}

	public Identifier derivative(int i)
	{
		throw new FunctionError("Derivative not supported");
	}

	public synchronized void compileRef(NodeCompiler nodecompiler, Node anode[])
	{
		for(int i = 0; i < params.length; i++)
			params[i].setNode(anode[i]);

		body.compile(nodecompiler);
	}

	public MacroFunction(String s, MacroParameter amacroparameter[], Node node)
	{
		super(s);
		body = node;
		params = amacroparameter;
	}
}
