Skip to content

Commit

Permalink
document tail call elimination
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotlinski committed Aug 12, 2015
1 parent 7969d7b commit 51993b8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/anatomy.tex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ \section{Header}

The first two bytes contain a back-pointer to the previous word, starting at \$4bed. The next byte, "02", is the length of "bg" name string. After that, the string "bg" follows. (42 = 'b', 47 = 'g')

The name length byte is also used to store special attributes of the word. Bit 7 is "immediate" flag, which means that the word should execute immediately instead of being compiled into word definitions. ("(" is such an example of an immediate word that does not get compiled.) Bit 6 is "hidden" flag, which makes a word unfindable. Since bg is neither immediate nor hidden, bits 7-6 are both clear.
The name length byte is also used to store special attributes of the word. Bit 7 is "immediate" flag, which means that the word should execute immediately instead of being compiled into word definitions. ("(" is such an example of an immediate word that does not get compiled.) Bit 6 is "hidden" flag, which makes a word unfindable. Bit 5 is the "no-tail-call-elimination" flag, which makes sure that tail call elimination (the practice of replacing jsr/rts with jmp) is not performed if this word is the jsr target. Since bg does not have these flags set, bits 7-5 are all clear.

\section{Code}

Expand Down
1 change: 1 addition & 0 deletions docs/forth.tex
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ \section{Compiling}
\item[[ ( -- )] Leave compile mode. Execute the following words immediately instead of compiling them.
\item[{]} ( -- )] Return to compile mode.
\item[immediate] Mark the word being compiled as immediate (i.e. inside colon definitions, it will be executed immediately instead of compiled).
\item[no-tce] Do not perform tail call elimination (the practice of substituting jsr/rts with jmp) if this word is the jsr target.
\item[{[']} name ( -- xt )] Place name's execution token xt on the stack. The execution token returned by the compiled phrase \texttt{['] x} is the same value returned by \texttt{' x} outside of compilation state. Typical use: \texttt{: x ... {[}'{]} name ... ;}
\item[compile, ( xt -- )] Append \texttt{jsr xt} to the word being compiled. Typical use: \texttt{: recurse immed latest @ >cfa compile, ;}
\item[postpone xxx] Compile the compilation semantics (instead of interpretation semantics) of xxx. Typical use:
Expand Down

0 comments on commit 51993b8

Please sign in to comment.