package Models.Statements;

import Exceptions.BaseException;
import Models.Program.GenericStack;
import Models.Program.IDictionary;
import Models.Program.ProgramState;
import Models.Types.IType;

public class ForkStatement implements IStatement {
    private IStatement statement;

    public ForkStatement(IStatement statement) {
        this.statement = statement;
    }

    public ProgramState execute(ProgramState state) throws BaseException {
        ProgramState forkedProgramState = new ProgramState(new GenericStack<IStatement>(), state.getSymbolTable().copy(), state.getOutput(), state.getFileTable(), state.getHeap(), this.statement);
        return forkedProgramState;
    }

    public IStatement copy() {
        return new ForkStatement(this.statement.copy());
    }

    public String toString() {
        return "fork(" + this.statement.toString() + ")";
    }

    public IDictionary<String, IType> typeCheck(IDictionary<String, IType> typeTable) throws BaseException {
        this.statement.typeCheck(typeTable.copy());
        return typeTable;
    }
}
