package function.builtin;

import static sexpression.Nil.NIL;

import environment.RuntimeEnvironment;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;

@FunctionNames({ "EXIT" })
public class EXIT extends LispFunction {

    private ArgumentValidator argumentValidator;
    private RuntimeEnvironment environment;

    public EXIT(String name) {
        this.argumentValidator = new ArgumentValidator(name);
        this.argumentValidator.setMaximumNumberOfArguments(0);
        this.environment = RuntimeEnvironment.getInstance();
    }

    @Override
    public SExpression call(Cons argumentList) {
        argumentValidator.validate(argumentList);
        environment.terminateSuccessfully();

        return NIL;
    }

}
