( Library of Forth code. ) ( Push a 42, and check it after all is done, just to make sure none of this code leaves anything on the stack. ) 42 ( TODO: - Make sure that dp is aligned before definitions are started. Do this by redefining colon to take care of the alignment and then call the old colon. ) ( Used mainly in debugging tests. ) : dup4 dup dup dup dup ; ( Stack and dp display. ) : show dup . cr ; : showr r@ . cr ; : ps 10 print_stack ; : pr 10 print_rstack ; : prs r> 10 print_rstack >r ; : dp ( Just an alias. ) here ; : ph ( Show where we are. ) here . cr ; ( Storing things in the dictionary by hand. ) : size_t ( The length of one entry. ) 4 ; : dp+ ( Increment dp by exactly one entry. ) size_t allot ; : dp!+ ( [ n -- ] Store a value in dp and advance. ) here ! dp+ ; ( Ahhhh. ) : recurse last dp!+ ; immediate : sq dup * ; ( Push a space. ) : bl 32 ; ( Conditionals. ) : push_bze ( Push &bze onto the stack. ) literal bze ; : push_branch ( Push &branch onto the stack. ) literal branch ; ( Note how IF and THEN save and restore the rstack. They must do this because the very act of entering them pushes a value on the rstack -- a value which will be popped when IF or THEN is finished executing -- so we need to work "underneath" that value. [See doc/design for discussion of conditionals.] ) : if r> push_bze dp!+ here >r dp+ >r ; immediate ( THEN means ENDIF in this bizarre language. ) : then r> here r> ! dp+ >r ; immediate ( ELSE ) : else r> push_branch dp!+ here r> ! here >r dp+ >r ; immediate ( STRING: take the delimiter, compile the string into the dictionary. This definition stolen from page 252 of Brodie.) ( c -- ) ( : string word c@ 1 + allot ; )