package code.instr;

import code.space.Computation;
import code.space.Space;
import code.stuff.Logger;
import code.stuff.Tracer;
import code.term.Term;
import code.term.TermImplRef;

/**
 * Construct a term that wraps a variable.  Such a term is used
 * only for the right-hand side of a collapsing rule, such as:
 *
 *    append [] x = x
 *
 * The wrapper ensures a single entry to the variable and
 * supports replacement in place.
 *
 * @author Sergio Antoy
 * @since Oct 13, 2006
 */

public class MakeRef implements Instruction {

    private MakeRef() {}
    public final static MakeRef singleton = new MakeRef();

    public void execute(Computation computation) {
	Term variable = (Term) Space.instance.preTerm.pop();
        Term term = new Term(new TermImplRef(variable));
	Space.instance.preTerm.push(term);
        if (Tracer.instruction) {
	    Logger.logln(computation.getIdString() + ": MakeRef: " + variable);
        }
    }

    public String printAsTxtLoadable() { return "MakeRef"; }

}
