factor/library/words.facts

261 lines
12 KiB
Plaintext
Raw Normal View History

2006-08-02 15:17:13 -04:00
IN: words
USING: definitions help inspector kernel kernel-internals parser ;
2006-01-06 02:04:42 -05:00
2006-08-15 21:23:05 -04:00
HELP: execute ( word -- )
{ $values { "word" "a word" } }
{ $description "Executes a word." }
{ $examples
{ $example ": twice dup execute execute ;\n: hello \"Hello\" print ;\n\\ hello twice" "Hello\nHello" }
} ;
2006-08-15 21:23:05 -04:00
HELP: word-props ( word -- props )
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "props" "a hashtable" } }
{ $description "Outputs a word's property hashtable." } ;
2006-08-15 21:23:05 -04:00
HELP: set-word-props ( props word -- )
2006-01-06 02:04:42 -05:00
{ $values { "props" "a hashtable" } { "word" "a word" } }
{ $description "Sets a word's property hashtable." }
{ $notes "The given hashtable must not be a literal, since it will get mutated by future calls to " { $link set-word-prop } "." } ;
2006-08-15 21:23:05 -04:00
HELP: word-primitive ( word -- n )
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "n" "a non-negative integer" } }
{ $description "Outputs a word's primitive number." } ;
2006-08-15 21:23:05 -04:00
HELP: set-word-primitive ( n word -- )
2006-01-06 02:04:42 -05:00
{ $values { "n" "a non-negative integer" } { "word" "a word" } }
{ $description "Sets a word's primitive number." }
{ $notes "Changing the primitive number does not update the execution token, and the word will still call its old definition until a subsequent call to " { $link update-xt } "." } ;
2006-08-15 21:23:05 -04:00
HELP: word-def ( word -- obj )
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "obj" "an object" } }
{ $description "Outputs a word's primitive parameter. This parameter is only used if the primitive number is 1 (compound definitions) or 2 (symbols)." } ;
2006-08-15 21:23:05 -04:00
HELP: set-word-def ( obj word -- )
2006-01-06 02:04:42 -05:00
{ $values { "obj" "an object" } { "word" "a word" } }
{ $description "Sets a word's primitive parameter." }
2006-01-08 20:41:31 -05:00
$low-level-note ;
2006-08-15 21:23:05 -04:00
HELP: undefined
{ $class-description "The class of undefined words created by " { $link POSTPONE: DEFER: } "." }
2006-01-08 20:41:31 -05:00
{ $see-also POSTPONE: DEFER: } ;
2006-08-15 21:23:05 -04:00
HELP: compound
{ $description "The class of compound words created by " { $link POSTPONE: : } "." }
2006-01-08 20:41:31 -05:00
{ $see-also POSTPONE: : define-compound } ;
2006-08-15 21:23:05 -04:00
HELP: primitive
2006-01-08 20:41:31 -05:00
{ $description "The class of primitive words." } ;
2006-08-15 21:23:05 -04:00
HELP: symbol
{ $description "The class of symbols created by " { $link POSTPONE: SYMBOL: } "." }
2006-01-08 20:41:31 -05:00
{ $see-also POSTPONE: SYMBOL: define-symbol intern-symbol } ;
2006-01-06 02:04:42 -05:00
2006-08-15 21:23:05 -04:00
HELP: init-word
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } }
{ $description "Initializes a word output from the " { $link <word> } " primitive." } ;
2006-08-15 21:23:05 -04:00
HELP: word-prop
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "name" "a property name" } { "value" "a property value" } }
{ $description "Retrieves a word property. Word property names are conventionally strings." } ;
2006-08-15 21:23:05 -04:00
HELP: set-word-prop
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "value" "a property value" } { "name" "a property name" } }
{ $description "Stores a word property. Word property names are conventionally strings." } ;
2006-08-15 21:23:05 -04:00
HELP: remove-word-prop
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "name" "a property name" } }
{ $description "Removes a word property, so future lookups will output " { $link f } " until it is set again. Word property names are conventionally strings." } ;
2006-08-15 21:23:05 -04:00
HELP: word-xt
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "xt" "an execution token integer" } }
{ $description "Outputs the machine code address of the word's definition." } ;
2006-08-15 21:23:05 -04:00
HELP: set-word-xt
2006-01-06 02:04:42 -05:00
{ $values { "xt" "an execution token integer" } { "word" "a word" } }
{ $description "Sets the machine code address of the word's definition." }
2006-01-08 20:41:31 -05:00
{ $warning "This word is unsafe. Specifying an invalid address can corrupt memory and crash the runtime." }
2006-01-06 02:04:42 -05:00
{ $notes "This word is used by the compiler." } ;
2006-08-15 21:23:05 -04:00
HELP: uses
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "seq" "a sequence of words" } }
{ $description "Outputs a sequence of words directory called by the given word." }
{ $notes "The sequence will include the word itself if it is recursive." }
{ $see-also uses } ;
2006-08-15 21:23:05 -04:00
HELP: crossref
2006-08-16 21:55:53 -04:00
{ $var-description "A graph whose vertices are words and edges are usages. See " { $link "graphs" } "." }
2006-07-25 02:08:06 -04:00
{ $see-also usage xref-words } ;
2006-01-06 02:04:42 -05:00
2006-08-15 21:23:05 -04:00
HELP: xref-word
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } }
2006-06-16 23:12:40 -04:00
{ $description "Adds a vertex representing this word, along with edges representing dependencies to the " { $link crossref } " graph." }
2006-01-08 20:41:31 -05:00
$low-level-note ;
2006-01-06 02:04:42 -05:00
2006-08-15 21:23:05 -04:00
HELP: usage
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "seq" "a sequence of words" } }
{ $description "Outputs a sequence of words that directly call the given word." }
{ $notes "The sequence will include the word itself if it is recursive." }
{ $see-also usage } ;
2006-08-15 21:23:05 -04:00
HELP: unxref-word*
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } }
{ $contract "Updates the word to cope with a callee being redefined." }
2006-01-08 20:41:31 -05:00
$low-level-note ;
2006-01-06 02:04:42 -05:00
2006-08-15 21:23:05 -04:00
HELP: unxref-word
2006-06-16 23:12:40 -04:00
{ $values { "word" "a word" } }
{ $description "Remove the vertex representing the word from the " { $link crossref } " graph." }
2006-01-08 20:41:31 -05:00
$low-level-note ;
2006-01-06 02:04:42 -05:00
2006-08-15 21:23:05 -04:00
HELP: define
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "def" "an object" } { "primitive" "a non-negative integer" } }
{ $description "Defines a word and updates cross-referencing." }
2006-01-08 20:41:31 -05:00
$low-level-note
2006-01-06 02:04:42 -05:00
{ $see-also define-symbol define-compound } ;
2006-08-15 21:23:05 -04:00
HELP: define-symbol
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } }
{ $description "Defines the word to push itself on the stack when executed." } ;
2006-08-15 21:23:05 -04:00
HELP: intern-symbol
2006-06-04 15:35:00 -04:00
{ $values { "word" "a word" } }
{ $description "If the word is undefined, makes it into a symbol which pushes itself on the stack when executed. If the word already has a definition, does nothing." } ;
2006-08-15 21:23:05 -04:00
HELP: define-compound
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "def" "a quotation" } }
{ $description "Defines the word to call a quotation when executed." } ;
2006-08-15 21:23:05 -04:00
HELP: reset-word
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } }
{ $description "Reset word declarations." }
2006-01-08 20:41:31 -05:00
$low-level-note ;
2006-01-06 02:04:42 -05:00
2006-08-15 21:23:05 -04:00
HELP: reset-generic
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } }
{ $description "Reset word declarations and generic word properties." }
2006-01-08 20:41:31 -05:00
$low-level-note ;
2006-01-06 02:04:42 -05:00
2006-08-15 21:23:05 -04:00
HELP: (word) ( name vocab -- word )
{ $values { "name" "a string" } { "vocab" "a string" } { "word" "a word" } }
{ $description "Allocates an uninterned word with the specified name and vocabulary. User code should call " { $link gensym } " to create uninterned words and " { $link create } " to create interned words." }
{ $see-also <word> } ;
2006-08-15 21:23:05 -04:00
HELP: <word>
2006-06-04 15:35:00 -04:00
{ $values { "name" "a string" } { "vocab" "a string" } { "word" "a word" } }
{ $description "Allocates an uninterned word with the specified name and vocabulary, and a blank word properties hashtable. User code should call " { $link gensym } " to create uninterned words and " { $link create } " to create interned words." } ;
2006-06-04 15:35:00 -04:00
2006-08-15 21:23:05 -04:00
HELP: gensym
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } }
{ $description "Creates an uninterned word that is not equal to any other word in the system. Gensyms have an automatically-generated name based on a prefix and an incrementing counter." }
{ $examples { $example "gensym ." "G:260561" } }
{ $notes "Gensyms are often used as placeholder values that have no meaning of their own but must be unique. For example, the compiler uses gensyms to label sections of assembly code." } ;
2006-08-15 21:23:05 -04:00
HELP: define-temp
2006-06-04 15:35:00 -04:00
{ $values { "quot" "a quotation" } { "word" "a word" } }
{ $description "Creates an uninterned word that will call " { $snippet "quot" } " when executed." }
{ $notes
"The following phrases are equivalent:"
{ $code "[ 2 2 + . ] call" }
{ $code "[ 2 2 + . ] define-temp execute" }
} ;
2006-08-15 21:23:05 -04:00
HELP: definer
2006-01-06 02:04:42 -05:00
{ $values { "word" "a word" } { "definer" "a word" } }
{ $description "Outputs the parsing word that defines the given word." }
{ $examples
2006-01-13 20:13:14 -05:00
{ $example ": foo ; \\ foo definer ." "POSTPONE: :" }
{ $example "SYMBOL: foo \\ foo definer ." "POSTPONE: SYMBOL:" }
2006-01-06 02:04:42 -05:00
} ;
2006-08-15 21:23:05 -04:00
HELP: bootstrapping?
2006-08-16 21:55:53 -04:00
{ $var-description "Set by the library while bootstrap is in progress. Some parsing words need to behave differently during bootstrap." } ;
2006-08-15 21:23:05 -04:00
HELP: vocabularies
2006-08-16 21:55:53 -04:00
{ $var-description "Holds a hashtable mapping vocabulary names to vocabularies." } ;
2006-08-15 21:23:05 -04:00
HELP: word
{ $values { "word" "a word" } }
{ $description "Outputs the most recently defined word." }
{ $see-also save-location } ;
2006-08-15 21:23:05 -04:00
HELP: set-word
{ $values { "word" "a word" } }
{ $description "Sets the recently defined word. Usually you would call " { $link save-location } " on a newly-defined word instead, which will in turn call this word." }
{ $see-also word } ;
2006-08-15 21:23:05 -04:00
HELP: vocabs
{ $values { "word" "a sequence of strings" } }
{ $description "Outputs a sequence of all defined vocabulary names." } ;
2006-08-15 21:23:05 -04:00
HELP: vocab
{ $values { "name" "a string" } { "vocab" "a hashtable" } }
{ $description "Outputs a named vocabulary, or " { $link f } " if no vocabulary with this name exists." } ;
2006-08-15 21:23:05 -04:00
HELP: ensure-vocab
{ $values { "name" "a string" } }
{ $description "Creates a vocabulary if it does not already exist." } ;
2006-08-15 21:23:05 -04:00
HELP: words
{ $values { "vocab" "a string" } { "seq" "a sequence of words" } }
{ $description "Outputs a sequence of words defined in the vocabulary, or " { $link f } " if no vocabulary with this name exists." } ;
2006-08-15 21:23:05 -04:00
HELP: all-words
{ $values { "seq" "a sequence of words" } }
{ $description "Outputs a sequence of all words in the dictionary." } ;
2006-08-15 21:23:05 -04:00
HELP: word-subset
{ $values { "quot" "a quotation with stack effect " { $snippet "( word -- ? )" } } { "seq" "a sequence of words" } }
{ $description "Outputs a sequence of words satisfying the predicate." } ;
2006-08-15 21:23:05 -04:00
HELP: xref-words
2006-06-16 23:12:40 -04:00
{ $description "Update the " { $link crossref } " graph of word dependencies. Usually this is done automatically." } ;
2006-08-15 21:23:05 -04:00
HELP: lookup
{ $values { "name" "a string" } { "vocab" "a string" } { "word" "a word or " { $link f } } }
{ $description "Looks up a word in the dictionary. If the vocabulary or the word is not defined, outputs " { $link f } "." } ;
2006-08-15 21:23:05 -04:00
HELP: reveal
{ $values { "word" "a word" } }
{ $description "Adds a newly-created word to the dictionary. Usually this word does not need to be called directly." }
{ $see-also create } ;
2006-08-15 21:23:05 -04:00
HELP: check-create
2006-08-01 17:35:00 -04:00
{ $values { "name" "a string" } { "vocab" "a string" } }
{ $description "Throws a " { $link check-create } " error if " { $snippet "name" } " or " { $snippet "vocab" } " is not a string." }
{ $error-description "Thrown if " { $link create } " is called with invalid parameters." } ;
2006-08-15 21:23:05 -04:00
HELP: create
{ $values { "name" "a string" } { "vocab" "a string" } { "word" "a word" } }
{ $description "Creates a new word. Creates the vocabulary first if it does not already exist. If the vocabulary exists and already contains a word with the requested name, outputs the existing word." } ;
2006-08-15 21:23:05 -04:00
HELP: constructor-word
{ $values { "name" "a string" } { "vocab" "a string" } { "word" "a word" } }
{ $description "Creates a new word, surrounding " { $snippet "name" } " in angle brackets." }
{ $examples { $example "\"salmon\" \"scratchpad\" constructor-word ." "<salmon>" } } ;
2006-08-15 21:23:05 -04:00
HELP: forget-word
{ $values { "word" "a word" } }
2006-08-15 21:23:05 -04:00
{ $description "Removes a word from its vocabulary. User code should call " { $link forget } " instead, since it also does the right thing when forgetting class words." }
2006-08-02 15:17:13 -04:00
{ $see-also POSTPONE: FORGET: forget-vocab forget } ;
2006-06-04 15:35:00 -04:00
2006-08-15 21:23:05 -04:00
HELP: forget-vocab
2006-06-04 15:35:00 -04:00
{ $values { "vocab" "a string" } }
{ $description "Removes a vocabulary. All words in the vocabulary become uninterned." }
{ $see-also forget } ;
2006-08-17 23:08:04 -04:00
HELP: target-word
{ $values { "word" "a word" } { "target" "a word" } }
{ $description "Looks up a word with the same name and vocabulary as the given word. Used during bootstrap to transfer host words to the target dictionary." } ;
2006-08-15 21:23:05 -04:00
HELP: interned?
{ $values { "word" "a word" } { "?" "a boolean" } }
{ $description "Test if the word is an interned word." } ;
2006-08-15 21:23:05 -04:00
HELP: bootstrap-word
{ $values { "word" "a word" } { "target" "a word" } }
{ $description "Looks up a word with the same name and vocabulary as the given word, performing a transformation to handle parsing words in the target dictionary. Used during bootstrap to transfer host words to the target dictionary." } ;
2006-08-15 21:23:05 -04:00
HELP: update-xt ( word -- )
{ $values { "word" "a word" } }
{ $description "Updates a word's execution token based on the value of the " { $link word-primitive } " slot. If the word was compiled, this will lose the compiled definition and make it run in the interpreter." } ;