Breakpoints
A breakpoint is an an intentional pausing place in a program for debugging purpose. It is a means of getting information about a program during its execution. During the interruption, you can check whether the program is functioning as expected. In Smojo, we use the wordBPto place a breakpoint in the code.
: addition bp + bp cr "The sum is " . . cr bp ; 5 2 addition --breakpoint: ADDITION[1] -- <2> 5 2 --breakpoint: ADDITION[2] -- <1> 7 The sum is 7 --breakpoint: ADDITION[3] -- <0> ok
Quiz
Question 1
Run theADDITIONprogram. Can you explain what happens at the three different breakpoints?
When
bpis run, the state of the stack at that time is shown. At the first brakpoint,
5and
2are on the stack. At the second breakpoint, i.e., after
+, the two numbers are consumed and their sum
7is pushed onto the stack. At the third breakpoint, the number
7is popped and printed so there is nothing on the stack.