]> gitweb.factorcode.org Git - factor.git/commitdiff
tools.walker: adding breakpoint-after
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 8 Sep 2023 16:48:14 +0000 (09:48 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 8 Sep 2023 16:48:14 +0000 (09:48 -0700)
basis/tools/walker/walker-docs.factor
basis/tools/walker/walker.factor

index bcf287f820b05f9caef5699491db165a239a08e4..630ba460786ba14cecb71685d71c48ef59b0def1 100644 (file)
@@ -11,13 +11,22 @@ HELP: breakpoint
 } ;
 
 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"
     }
 } ;
 
@@ -37,6 +46,7 @@ $nl
 { $subsections
     breakpoint
     breakpoint-if
+    breakpoint-after
 }
 "Breakpoints can be inserted directly into code:"
 { $subsections
index 6b1c1f0a0b572909b728132f321a64de5acbf863..c00daaef8eab5b80493adb7db1cbcdd0a1714f4e 100644 (file)
@@ -161,9 +161,17 @@ SYMBOL: +stopped+
 : 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