/// <summary> /// The method that represents the 'exit' function in the language. /// Exits from the current function, returning any value passed to the function. /// </summary> /// <param name="interpreter">The interpreter that the method is being called from.</param> /// <param name="args">The arguments being passed to the function as a TArgumentList.</param> /// <returns>The argument passed to the function. If no arguments were passed, it returns TNil.</returns> public static TType Exit(Interpreter interpreter, TArgumentList args) { // Get the argument passed (if any) to return TType returnValue = TNil.Instance; if (args.Count > 0) returnValue = args[0]; // Pops from the function stack or kill the interpreter if the stack level is already at it's lowest // When this method returns, the calling method should check the stack level and exit accordingly if (interpreter.Stack.Level <= 1) interpreter.Kill(); else interpreter.Stack.Pop(); return returnValue; }