} ;
HELP: breakpoint-if
-{ $values { "word" word } { "quot" { $quotation ( -- ? ) } } }
+{ $values { "word" word } { "quot" { $quotation ( ... -- ... ? ) } } }
{ $description "Annotates a word definition to enter the single stepper if the quotation yields true. The quotation has access to the datastack as it exists just before " { $snippet "word" } " is called. Use " { $link reset } " to clear." }
{ $examples
"Break if the input to sq is 3:"
- { $unchecked-example
+ { $code
"USE: tools.walker \\ sq [ dup 3 = ] breakpoint-if"
- ""
+ }
+} ;
+
+HELP: breakpoint-after
+{ $values { "word" word } { "n" number } }
+{ $description "Annotates a word definition to enter the single stepper after the word has been called " { $snippet "n" } " times. Use " { $link reset } " to clear." }
+{ $examples
+ "Break after calling sq 3 times:"
+ { $code
+ "USE: tools.walker \\ sq 3 breakpoint-after"
}
} ;
{ $subsections
breakpoint
breakpoint-if
+ breakpoint-after
}
"Breakpoints can be inserted directly into code:"
{ $subsections
: breakpoint ( word -- )
[ add-breakpoint ] annotate ;
-: breakpoint-if ( word quot -- )
+: breakpoint-if ( word quot: ( ... -- ... ? ) -- )
'[ [ _ [ [ break ] when ] ] dip 3append ] annotate ;
+: breakpoint-after ( word n -- )
+ 0 1array swap '[
+ [
+ 0 _ [ 1 + dup ] change-nth-unsafe
+ _ >= [ break ] when
+ ] prepend
+ ] annotate ;
+
! For convenience
IN: syntax