]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/annotations/annotations-docs.factor
6391c1175cfdebe8c7fe4c29af7efc2f70a24931
[factor.git] / basis / tools / annotations / annotations-docs.factor
1 USING: help.markup help.syntax words parser quotations strings
2 system sequences ;
3 IN: tools.annotations
4
5 ARTICLE: "tools.annotations" "Word annotations"
6 "The word annotation feature modifies word definitions to add debugging code. You can restore the old definition by calling " { $link reset } " on the word in question."
7 $nl
8 "Printing messages when a word is called or returns:"
9 { $subsections
10     watch
11     watch-vars
12 }
13 "Timing words:"
14 { $subsections
15     reset-word-timing
16     add-timing
17     word-timing.
18 }
19 "All of the above words are implemented using a single combinator which applies a quotation to a word definition to yield a new definition:"
20 { $subsections annotate }
21 { $warning
22     "Certain internal words, such as words in the " { $vocab-link "math" } ", " { $vocab-link "sequences" } " and UI vocabularies, cannot be annotated, since the annotated code may end up recursively invoking the word in question. This may crash or hang Factor. It is safest to only define annotations on your own words."
23 } ;
24
25 ABOUT: "tools.annotations"
26
27 HELP: annotate
28 { $values { "word" "a word" } { "quot" { $quotation ( old-def -- new-def ) } } }
29 { $description "Changes a word definition to the result of applying a quotation to the old definition." }
30 { $notes "This word is used to implement " { $link watch } "." } ;
31
32 HELP: watch
33 { $values { "word" word } }
34 { $description "Annotates a word definition to print the data stack on entry and exit." } ;
35
36 { watch watch-vars reset } related-words
37
38 HELP: reset
39 { $values
40      { "word" word } }
41 { $description "Resets any annotations on a word." }
42 { $notes "This word will remove a " { $link watch } "." } ;
43
44 HELP: watch-vars
45 { $values
46      { "word" word } { "vars" "a sequence of symbols" } }
47 { $description "Annotates a word definition to print the " { $snippet "vars" } " upon entering the word. This word is useful for debugging." } ;
48
49 HELP: add-timing
50 { $values { "word" word } }
51 { $description "Adds timing code to a word, which records its total running time, including that of words it calls, on every invocation." }
52 { $see-also "timing" "tools.profiler.sampling" } ;
53
54 HELP: reset-word-timing
55 { $description "Resets the word timing table." } ;
56
57 HELP: word-timing.
58 { $description "Prints the word timing table." } ;
59
60 HELP: cannot-annotate-twice
61 { $error-description "Thrown when attempting to annotate a word that's already been annotated. If a word already has an annotation such as a watch or a breakpoint, you must first " { $link reset } " the word before adding another annotation." } ;