示例#1
0
        public void HaltExecutionOnMacroExpansion()
        {
            var host = new LispHost();

            host.AddMacro("FOURTY-TWO", (host, executionState, args) =>
            {
                return(new LispInteger(42));
            });
            host.RootFrame.MacroExpanded += (s, e) =>
            {
                if (e.Macro.NameSymbol.LocalName == "FOURTY-TWO")
                {
                    e.HaltExecution = true;
                }
            };
            var evalResult = host.Eval(@"
(fourty-two)
(+ 1 2)
");

            Assert.False(evalResult.ExecutionState.IsExecutionComplete);
            Assert.Equal("s: 42", evalResult.ExecutionState.PeekOperation().ToString());

            host.EvalContinue(evalResult.ExecutionState);
            Assert.True(evalResult.ExecutionState.IsExecutionComplete);
            Assert.Equal(3, ((LispInteger)evalResult.LastResult).Value);
        }
示例#2
0
        public void ExecutionCannotBeHaltedWhenEvaluatingFromWithinANativeMacro()
        {
            var host = new LispHost();

            host.AddMacro("NATIVE-FUNCTION", (host, executionState, args) =>
            {
                var result = host.EvalAtStackFrame(executionState.StackFrame, LispList.FromEnumerable(new LispObject[] { LispSymbol.CreateFromString("*"), new LispInteger(2), new LispInteger(2) }));
                return(result);
            });
            var hitBreakpoint = false;

            host.RootFrame.EvaluatingExpression += (s, e) =>
            {
                if (!hitBreakpoint &&
                    e.Expression is LispList list &&
                    list.ToString() == "(* 2 2)")
                {
                    hitBreakpoint   = true;
                    e.HaltExecution = true; // this should not be honored
                }
            };
            var evalResult = host.Eval("(native-function)");

            Assert.True(hitBreakpoint);
            Assert.True(evalResult.ExecutionState.IsExecutionComplete);
            Assert.Equal(4, ((LispInteger)evalResult.LastResult).Value);
        }