package de.unitrier.st.uap.w25.tram;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class LoggedMachine extends AbstractMachine {
    private static final Logger logger = LogManager.getLogger(LoggedMachine.class);
    private int stepCounter = 0;

    public LoggedMachine(Instruction[] prog) { super(prog); }
    public LoggedMachine(Instruction[] prog, Integer[] stack) { super(prog, stack); }

    @Override
    public void execute() {
        logger.info("Executing...");
        logger.debug("0: {}", confStr());
        while (!isHalted()) executeStep();
        logger.info("Finished with STACK: {}", stackStr());
    }

    @Override
    public void executeStep() {
        int step = stepCounter++;
        super.executeStep();
        logger.debug("{}: {}", step, confStr());
    }
}
