| @subtitle for version @value{VERSION}, @value{UPDATED} |
@subtitle for version @value{VERSION}, @value{UPDATED} |
| @author Neal Crook |
@author Neal Crook |
| @author Anton Ertl |
@author Anton Ertl |
| |
@author David Kuehling |
| @author Bernd Paysan |
@author Bernd Paysan |
| @author Jens Wilke |
@author Jens Wilke |
| @page |
@page |
| |
|
| doc-noname |
doc-noname |
| @cindex execution token of last defined word |
@cindex execution token of last defined word |
| doc-lastxt |
doc-latestxt |
| |
|
| @noindent |
@noindent |
| The previous example can be rewritten using @code{noname} and |
The previous example can be rewritten using @code{noname} and |
| @code{lastxt}: |
@code{latestxt}: |
| |
|
| @example |
@example |
| Defer deferred |
Defer deferred |
| noname : ( ... -- ... ) |
noname : ( ... -- ... ) |
| ... ; |
... ; |
| lastxt IS deferred |
latestxt IS deferred |
| @end example |
@end example |
| |
|
| @noindent |
@noindent |
| @code{noname} works with any defining word, not just @code{:}. |
@code{noname} works with any defining word, not just @code{:}. |
| |
|
| @code{lastxt} also works when the last word was not defined as |
@code{latestxt} also works when the last word was not defined as |
| @code{noname}. It does not work for combined words, though. It also has |
@code{noname}. It does not work for combined words, though. It also has |
| the useful property that is is valid as soon as the header for a |
the useful property that is is valid as soon as the header for a |
| definition has been built. Thus: |
definition has been built. Thus: |
| |
|
| @example |
@example |
| lastxt . : foo [ lastxt . ] ; ' foo . |
latestxt . : foo [ latestxt . ] ; ' foo . |
| @end example |
@end example |
| |
|
| @noindent |
@noindent |
| : stats ( xt -- ) DUP ." (Gathering statistics for " . ." )" |
: stats ( xt -- ) DUP ." (Gathering statistics for " . ." )" |
| ... ; \ other code |
... ; \ other code |
| |
|
| : my: : lastxt postpone literal ['] stats compile, ; |
: my: : latestxt postpone literal ['] stats compile, ; |
| |
|
| my: foo + - ; |
my: foo + - ; |
| @end example |
@end example |
| @code{my:} is executed. |
@code{my:} is executed. |
| @item |
@item |
| The @code{:} within the definition (the one between @code{my:} and |
The @code{:} within the definition (the one between @code{my:} and |
| @code{lastxt}) is executed, and does just what it always does; it parses |
@code{latestxt}) is executed, and does just what it always does; it parses |
| the input stream for a name, builds a dictionary header for the name |
the input stream for a name, builds a dictionary header for the name |
| @code{foo} and switches @code{state} from interpret to compile. |
@code{foo} and switches @code{state} from interpret to compile. |
| @item |
@item |
| The word @code{lastxt} is executed. It puts the @i{xt} for the word that is |
The word @code{latestxt} is executed. It puts the @i{xt} for the word that is |
| being defined -- @code{foo} -- onto the stack. |
being defined -- @code{foo} -- onto the stack. |
| @item |
@item |
| The code that was produced by @code{postpone literal} is executed; this |
The code that was produced by @code{postpone literal} is executed; this |
| : @var{inst-format} ( entry-num "name" -- ) |
: @var{inst-format} ( entry-num "name" -- ) |
| here name string, ( entry-num c-addr ) \ parse and save "name" |
here name string, ( entry-num c-addr ) \ parse and save "name" |
| noname create , ( entry-num ) |
noname create , ( entry-num ) |
| lastxt swap cells @var{table} + ! |
latestxt swap cells @var{table} + ! |
| does> ( addr w -- ) |
does> ( addr w -- ) |
| \ disassemble instruction w at addr |
\ disassemble instruction w at addr |
| @@ >r |
@@ >r |
| \ and enters it as u-th entry into table-xt |
\ and enters it as u-th entry into table-xt |
| 2@@ swap here name string, ( u table-xt disasm-xt c-addr ) \ remember string |
2@@ swap here name string, ( u table-xt disasm-xt c-addr ) \ remember string |
| noname create 2, \ define anonymous word |
noname create 2, \ define anonymous word |
| execute lastxt swap ! \ enter xt of defined word into table-xt |
execute latestxt swap ! \ enter xt of defined word into table-xt |
| does> ( addr w -- ) |
does> ( addr w -- ) |
| \ disassemble instruction w at addr |
\ disassemble instruction w at addr |
| 2@@ >r ( addr w disasm-xt R: c-addr ) |
2@@ >r ( addr w disasm-xt R: c-addr ) |
| DROP} or @code{[COMP'] @i{word} DROP} (for details @pxref{Compilation |
DROP} or @code{[COMP'] @i{word} DROP} (for details @pxref{Compilation |
| token}). |
token}). |
| |
|
| Another way to get an XT is @code{:noname} or @code{lastxt} |
Another way to get an XT is @code{:noname} or @code{latestxt} |
| (@pxref{Anonymous Definitions}). For anonymous words this gives an xt |
(@pxref{Anonymous Definitions}). For anonymous words this gives an xt |
| for the only behaviour the word has (the execution semantics). For |
for the only behaviour the word has (the execution semantics). For |
| named words, @code{lastxt} produces an XT for the same behaviour it |
named words, @code{latestxt} produces an XT for the same behaviour it |
| would produce if the word was defined anonymously. |
would produce if the word was defined anonymously. |
| |
|
| @example |
@example |
| @subsection Name token |
@subsection Name token |
| |
|
| @cindex name token |
@cindex name token |
| |
Gforth represents named words by the @dfn{name token}, (@i{nt}). Name |
| |
token is an abstract data type that occurs as argument or result of the |
| |
words below. |
| |
|
| |
@c !! put this elswhere? |
| @cindex name field address |
@cindex name field address |
| @cindex NFA |
@cindex NFA |
| Gforth represents named words by the @dfn{name token}, (@i{nt}). In |
The closest thing to the nt in older Forth systems is the name field |
| Gforth, the abstract data type @emph{name token} is implemented as a |
address (NFA), but there are significant differences: in older Forth |
| name field address (NFA). |
systems each word had a unique NFA, LFA, CFA and PFA (in this order, or |
| |
LFA, NFA, CFA, PFA) and there were words for getting from one to the |
| |
next. In contrast, in Gforth 0@dots{}n nts correspond to one xt; there |
| |
is a link field in the structure identified by the name token, but |
| |
searching usually uses a hash table external to these structures; the |
| |
name in Gforth has a cell-wide count-and-flags field, and the nt is not |
| |
implemented as the address of that count field. |
| |
|
| doc-find-name |
doc-find-name |
| |
doc-latest |
| |
doc->name |
| doc-name>int |
doc-name>int |
| doc-name?int |
doc-name?int |
| doc-name>comp |
doc-name>comp |
| because the recognition of the end of the code is unreliable. You can |
because the recognition of the end of the code is unreliable. You can |
| use @code{disasm} if it did not display enough. It may display more, if |
use @code{disasm} if it did not display enough. It may display more, if |
| the code word is not immediately followed by a named word. If you have |
the code word is not immediately followed by a named word. If you have |
| something else there, you can follow the word with @code{align last @ ,} |
something else there, you can follow the word with @code{align latest ,} |
| to ensure that the end is recognized. |
to ensure that the end is recognized. |
| |
|
| @node 386 Assembler, Alpha Assembler, Common Disassembler, Assembler and Code Words |
@node 386 Assembler, Alpha Assembler, Common Disassembler, Assembler and Code Words |
| The word is entered into the word list that was the compilation word list |
The word is entered into the word list that was the compilation word list |
| at the start of the definition. Any changes to the name field (e.g., |
at the start of the definition. Any changes to the name field (e.g., |
| @code{immediate}) or the code field (e.g., when executing @code{DOES>}) |
@code{immediate}) or the code field (e.g., when executing @code{DOES>}) |
| are applied to the latest defined word (as reported by @code{last} or |
are applied to the latest defined word (as reported by @code{latest} or |
| @code{lastxt}), if possible, irrespective of the compilation word list. |
@code{latestxt}), if possible, irrespective of the compilation word list. |
| |
|
| @item search order empty (@code{previous}): |
@item search order empty (@code{previous}): |
| @cindex @code{previous}, search order empty |
@cindex @code{previous}, search order empty |
| @code{compile,}. |
@code{compile,}. |
| |
|
| @cindex gforth-itc engine |
@cindex gforth-itc engine |
| If you want to compile xts with @code{,}, use @command{gforth-itc}. This |
If you want to compile xts with @code{,}, use @command{gforth-itc}. |
| engine uses plain old indirect threaded code. It still compiles in a |
This engine uses plain old indirect threaded code. It still compiles in |
| primitive-centric style, so you cannot use @code{compile,} instead of |
a primitive-centric style, so you cannot use @code{compile,} instead of |
| @code{,} (e.g., for producing tables of xts with @code{] word1 word2 |
@code{,} (e.g., for producing tables of xts with @code{] word1 word2 |
| ... [}. If you want to do that, you have to use @command{gforth-itc} |
... [}). If you want to do that, you have to use @command{gforth-itc} |
| and execute @code{' , is compile,}. Your program can check if it is |
and execute @code{' , is compile,}. Your program can check if it is |
| running on a hybrid direct/indirect threaded engine or a pure indirect |
running on a hybrid direct/indirect threaded engine or a pure indirect |
| threaded engine with @code{threading-method} (@pxref{Threading Words}). |
threaded engine with @code{threading-method} (@pxref{Threading Words}). |