public void ExecutionCanStepOut(bool useTailCalls) { var host = new LispHost(useTailCalls: useTailCalls); var hasHalted = false; host.RootFrame.EvaluatingExpression += (s, e) => { if (!hasHalted && e.Expression.ToString() == "(+ 1 1)") { e.HaltExecution = true; hasHalted = true; } }; var evalResult = host.Eval(@" (defun test-method () (+ 1 1) ; initial halt here (+ 2 2)) (test-method) (+ 3 3) (+ 4 4) "); Assert.False(evalResult.ExecutionState.IsExecutionComplete); Assert.Equal("s: (+ 1 1)", evalResult.ExecutionState.PeekOperation().ToString()); host.StepOut(evalResult.ExecutionState); Assert.False(evalResult.ExecutionState.IsExecutionComplete); Assert.Equal("s: (+ 3 3)", evalResult.ExecutionState.PeekOperation().ToString()); host.StepOut(evalResult.ExecutionState); // can't step out at the root level; this was really a run to end Assert.True(evalResult.ExecutionState.IsExecutionComplete); Assert.Equal(8, ((LispInteger)evalResult.LastResult).Value); }
public void ExecutionStepOutWhenNextOperationIsNotAnExpression() { var host = new LispHost(); host.RootFrame.FunctionReturned += (s, e) => { if (e.Frame.FunctionSymbol.Value == "COMMON-LISP-USER:TEST-METHOD") { e.HaltExecution = true; } }; var evalResult = host.Eval(@" (defun test-method () (+ 1 2)) (test-method) (+ 4 5) "); Assert.False(evalResult.ExecutionState.IsExecutionComplete); Assert.Equal(3, ((LispInteger)evalResult.LastResult).Value); Assert.Null(evalResult.ExecutionState.PeekCurrentExpression()); host.StepOut(evalResult.ExecutionState); // stepping out here steps out of everything Assert.True(evalResult.ExecutionState.IsExecutionComplete); Assert.Equal(9, ((LispInteger)evalResult.LastResult).Value);; }