package codelines;

import animation.CodeLine;
import animation.ControlFlow;
import animation.Memory;
import animation.PseudoCodeNode;

public class FunctionCall extends CodeLine {

	private PseudoCodeNode target;
	private String[] params;
	
	public FunctionCall( PseudoCodeNode function, String[] params )
	{
		this.target = function;
		this.params = params;
	}
	
	@Override
	public ControlFlow runForward(Memory m) {
		int index = 1;
		for( String p : params )
		{
			m.declare( "param" + index, m.read( p, false ), true );
			index++;
		}
		actions.push( (Memory mem) -> {
			int ind = 1;
			for( @SuppressWarnings("unused") String p : params )
			{
				m.undeclare( "param" + ind, true );
				ind++;
			}
			return new ControlFlow( target );
		} );
		return new ControlFlow( target );
	}

}
