2 \ A sometimes minimal FORTH compiler and tutorial for Linux / i386 systems. -*- asm -*-
3 \ By Richard W.M. Jones <rich@annexia.org> http://annexia.org/forth
4 \ This is PUBLIC DOMAIN (see public domain release statement below).
5 \ $Id: jonesforth.f,v 1.5 2007-09-26 22:20:52 rich Exp $
7 \ The first part of this tutorial is in jonesforth.S. Get if from http://annexia.org/forth
9 \ PUBLIC DOMAIN ----------------------------------------------------------------------
11 \ I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
13 \ In case this is not legally possible, I grant any entity the right to use this work for any purpose,
14 \ without any conditions, unless such conditions are required by law.
16 \ SETTING UP ----------------------------------------------------------------------
18 \ Let's get a few housekeeping things out of the way. Firstly because I need to draw lots of
19 \ ASCII-art diagrams to explain concepts, the best way to look at this is using a window which
20 \ uses a fixed width font and is at least this wide:
22 \<------------------------------------------------------------------------------------------------------------------------>
24 \ Secondly make sure TABS are set to 8 characters. The following should be a vertical
25 \ line. If not, sort out your tabs.
31 \ Thirdly I assume that your screen is at least 50 characters high.
33 \ START OF FORTH CODE ----------------------------------------------------------------------
35 \ We've now reached the stage where the FORTH system is running and self-hosting. All further
36 \ words can be written as FORTH itself, including words like IF, THEN, .", etc which in most
37 \ languages would be considered rather fundamental.
39 \ Some notes about the code:
41 \ I use indenting to show structure. The amount of whitespace has no meaning to FORTH however
42 \ except that you must use at least one whitespace character between words, and words themselves
43 \ cannot contain whitespace.
45 \ FORTH is case-sensitive. Use capslock!
47 \ The primitive word /MOD (DIVMOD) leaves both the quotient and the remainder on the stack. (On
48 \ i386, the idivl instruction gives both anyway). Now we can define the / and MOD in terms of /MOD
49 \ and a few other primitives.
53 \ Define some character constants
57 \ CR prints a carriage return
60 \ SPACE prints a space
61 : SPACE 'SPACE' EMIT ;
63 \ DUP, DROP are defined in assembly for speed, but this is how you might define them
64 \ in FORTH. Notice use of the scratch variables _X and _Y.
65 \ : DUP _X ! _X @ _X @ ;
68 \ The 2... versions of the standard operators work on pairs of stack entries. They're not used
69 \ very commonly so not really worth writing in assembler. Here is how they are defined in FORTH.
73 \ More standard FORTH words.
77 \ NEGATE leaves the negative of a number on the stack.
80 \ Standard words for booleans.
85 \ LITERAL takes whatever is on the stack and compiles LIT <foo>
88 , \ compile the literal itself (from the stack)
91 \ Now we can use [ and ] to insert literals which are calculated at compile time. (Recall that
92 \ [ and ] are the FORTH words which switch into and out of immediate mode.)
93 \ Within definitions, use [ ... ] LITERAL anywhere that '...' is a constant expression which you
94 \ would rather only compute once (at compile time, rather than calculating it each time your word runs).
96 [ \ go into immediate mode (temporarily)
97 CHAR : \ push the number 58 (ASCII code of colon) on the parameter stack
98 ] \ go back to compile mode
99 LITERAL \ compile LIT 58 as the definition of ':' word
102 \ A few more character constants defined the same way as above.
103 : '(' [ CHAR ( ] LITERAL ;
104 : ')' [ CHAR ) ] LITERAL ;
105 : '"' [ CHAR " ] LITERAL ;
106 : 'A' [ CHAR A ] LITERAL ;
107 : '0' [ CHAR 0 ] LITERAL ;
108 : '-' [ CHAR - ] LITERAL ;
109 : '.' [ CHAR . ] LITERAL ;
111 \ While compiling, '[COMPILE] word' compiles 'word' if it would otherwise be IMMEDIATE.
112 : [COMPILE] IMMEDIATE
113 WORD \ get the next word
114 FIND \ find it in the dictionary
115 >CFA \ get its codeword
119 \ RECURSE makes a recursive call to the current word that is being compiled.
121 \ Normally while a word is being compiled, it is marked HIDDEN so that references to the
122 \ same word within are calls to the previous definition of the word. However we still have
123 \ access to the word which we are currently compiling through the LATEST pointer so we
124 \ can use that to compile a recursive call.
126 LATEST @ \ LATEST points to the word being compiled at the moment
127 >CFA \ get the codeword
131 \ So far we have defined only very simple definitions. Before we can go further, we really need to
132 \ make some control structures, like IF ... THEN and loops. Luckily we can define arbitrary control
133 \ structures directly in FORTH.
135 \ Please note that the control structures as I have defined them here will only work inside compiled
136 \ words. If you try to type in expressions using IF, etc. in immediate mode, then they won't work.
137 \ Making these work in immediate mode is left as an exercise for the reader.
139 \ condition IF true-part THEN rest
140 \ -- compiles to: --> condition 0BRANCH OFFSET true-part rest
141 \ where OFFSET is the offset of 'rest'
142 \ condition IF true-part ELSE false-part THEN
143 \ -- compiles to: --> condition 0BRANCH OFFSET true-part BRANCH OFFSET2 false-part rest
144 \ where OFFSET if the offset of false-part and OFFSET2 is the offset of rest
146 \ IF is an IMMEDIATE word which compiles 0BRANCH followed by a dummy offset, and places
147 \ the address of the 0BRANCH on the stack. Later when we see THEN, we pop that address
148 \ off the stack, calculate the offset, and back-fill the offset.
150 ' 0BRANCH , \ compile 0BRANCH
151 HERE @ \ save location of the offset on the stack
152 0 , \ compile a dummy offset
157 HERE @ SWAP - \ calculate the offset from the address saved on the stack
158 SWAP ! \ store the offset in the back-filled location
162 ' BRANCH , \ definite branch to just over the false-part
163 HERE @ \ save location of the offset on the stack
164 0 , \ compile a dummy offset
165 SWAP \ now back-fill the original (IF) offset
166 DUP \ same as for THEN word above
171 \ BEGIN loop-part condition UNTIL
172 \ -- compiles to: --> loop-part condition 0BRANCH OFFSET
173 \ where OFFSET points back to the loop-part
174 \ This is like do { loop-part } while (condition) in the C language
176 HERE @ \ save location on the stack
180 ' 0BRANCH , \ compile 0BRANCH
181 HERE @ - \ calculate the offset from the address saved on the stack
182 , \ compile the offset here
185 \ BEGIN loop-part AGAIN
186 \ -- compiles to: --> loop-part BRANCH OFFSET
187 \ where OFFSET points back to the loop-part
188 \ In other words, an infinite loop which can only be returned from with EXIT
190 ' BRANCH , \ compile BRANCH
191 HERE @ - \ calculate the offset back
192 , \ compile the offset here
195 \ BEGIN condition WHILE loop-part REPEAT
196 \ -- compiles to: --> condition 0BRANCH OFFSET2 loop-part BRANCH OFFSET
197 \ where OFFSET points back to condition (the beginning) and OFFSET2 points to after the whole piece of code
198 \ So this is like a while (condition) { loop-part } loop in the C language
200 ' 0BRANCH , \ compile 0BRANCH
201 HERE @ \ save location of the offset2 on the stack
202 0 , \ compile a dummy offset2
206 ' BRANCH , \ compile BRANCH
207 SWAP \ get the original offset (from BEGIN)
208 HERE @ - , \ and compile it after BRANCH
210 HERE @ SWAP - \ calculate the offset2
211 SWAP ! \ and back-fill it in the original location
214 \ FORTH allows ( ... ) as comments within function definitions. This works by having an IMMEDIATE
215 \ word called ( which just drops input characters until it hits the corresponding ).
217 1 \ allowed nested parens by keeping track of depth
219 KEY \ read next character
220 DUP '(' = IF \ open paren?
221 DROP \ drop the open paren
224 ')' = IF \ close paren?
228 DUP 0= UNTIL \ continue until we reach matching close paren, depth 0
229 DROP \ drop the depth counter
233 From now on we can use ( ... ) for comments.
235 In FORTH style we can also use ( ... -- ... ) to show the effects that a word has on the
236 parameter stack. For example:
238 ( n -- ) means that the word consumes an integer (n) from the parameter stack.
239 ( b a -- c ) means that the word uses two integers (a and b, where a is at the top of stack)
240 and returns a single integer (c).
241 ( -- ) means the word has no effect on the stack
244 ( With the looping constructs, we can now write SPACES, which writes n spaces to stdout. )
247 DUP 0> ( while n > 0 )
249 SPACE ( print a space )
250 1- ( until we count down to 0 )
255 ( Standard words for manipulating BASE. )
256 : DECIMAL ( -- ) 10 BASE ! ;
257 : HEX ( -- ) 16 BASE ! ;
260 The standard FORTH word . (DOT) is very important. It takes the number at the top
261 of the stack and prints it out. However first I'm going to implement some lower-level
264 U.R ( u width -- ) which prints an unsigned number, padded to a certain width
265 U. ( u -- ) which prints an unsigned number
266 .R ( n width -- ) which prints a signed number, padded to a certain width.
270 will print out these characters:
271 <space> <space> - 1 2 3
273 In other words, the number padded left to a certain number of characters.
275 The full number is printed even if it is wider than width, and this is what allows us to
276 define the ordinary functions U. and . (we just set width to zero knowing that the full
277 number will be printed anyway).
279 Another wrinkle of . and friends is that they obey the current base in the variable BASE.
280 BASE can be anything in the range 2 to 36.
282 While we're defining . &c we can also define .S which is a useful debugging tool. This
283 word prints the current stack (non-destructively) from top to bottom.
286 ( This is the underlying recursive definition of U. )
288 BASE @ /MOD ( width rem quot )
289 DUP 0<> IF ( if quotient <> 0 then )
290 RECURSE ( print the quotient )
292 DROP ( drop the zero quotient )
295 ( print the remainder )
297 '0' ( decimal digits 0..9 )
299 10 - ( hex and beyond digits A..Z )
307 FORTH word .S prints the contents of the stack. It doesn't alter the stack.
308 Very useful for debugging.
311 DSP@ ( get current stack pointer )
315 DUP @ U. ( print the stack element )
322 ( This word returns the width (in characters) of an unsigned number in the current base )
323 : UWIDTH ( u -- width )
324 BASE @ / ( rem quot )
325 DUP 0<> IF ( if quotient <> 0 then )
326 RECURSE 1+ ( return 1+recursive call )
328 DROP ( drop the zero quotient )
336 UWIDTH ( width u uwidth )
337 -ROT ( u uwidth width )
338 SWAP - ( u width-uwidth )
339 ( At this point if the requested width is narrower, we'll have a negative number on the stack.
340 Otherwise the number on the stack is the number of spaces to print. But SPACES won't print
341 a negative number of spaces anyway, so it's now safe to call SPACES ... )
343 ( ... and then call the underlying implementation of U. )
348 .R prints a signed number, padded to a certain width. We can't just print the sign
349 and call U.R because we want the sign to be next to the number ('-123' instead of '- 123').
355 1 ( save a flag to remember that it was negative | width n 1 )
364 SWAP ( flag width u )
365 DUP ( flag width u u )
366 UWIDTH ( flag width u uwidth )
367 -ROT ( flag u uwidth width )
368 SWAP - ( flag u width-uwidth )
373 IF ( was it negative? print the - character )
380 ( Finally we can define word . in terms of .R, with a trailing space. )
383 ( The real U., note the trailing space. )
386 ( ? fetches the integer at an address and prints it. )
389 ( c a b WITHIN returns true if a <= c and c < b )
405 ( DEPTH returns the depth of the stack. )
408 4- ( adjust because S0 was on the stack when we pushed DSP )
412 ALIGNED takes an address and rounds it up (aligns it) to the next 4 byte boundary.
414 : ALIGNED ( addr -- addr )
415 3 + 3 INVERT AND ( (addr+3) & ~3 )
419 ALIGN aligns the HERE pointer, so the next word appended will be aligned properly.
421 : ALIGN HERE @ ALIGNED HERE ! ;
424 S" string" is used in FORTH to define strings. It leaves the address of the string and
425 its length on the stack, with the address at the top. The space following S" is the normal
426 space between FORTH words and is not a part of the string.
428 This is tricky to define because it has to do different things depending on whether
429 we are compiling or in immediate mode. (Thus the word is marked IMMEDIATE so it can
430 detect this and do different things).
432 In compile mode we append
433 LITSTRING <string length> <string rounded up 4 bytes>
434 to the current word. The primitive LITSTRING does the right thing when the current
437 In immediate mode there isn't a particularly good place to put the string, but in this
438 case we put the string at HERE (but we _don't_ change HERE). This is meant as a temporary
439 location, likely to be overwritten soon after.
441 : S" IMMEDIATE ( -- len addr )
442 STATE @ IF ( compiling? )
443 ' LITSTRING , ( compile LITSTRING )
444 HERE @ ( save the address of the length word on the stack )
445 0 , ( dummy length - we don't know what it is yet )
447 KEY ( get next character of the string )
450 HERE @ C! ( store the character in the compiled image )
451 1 HERE +! ( increment HERE pointer by 1 byte )
453 DROP ( drop the double quote character at the end )
454 DUP ( get the saved address of the length word )
455 HERE @ SWAP - ( calculate the length )
456 4- ( subtract 4 (because we measured from the start of the length word) )
457 SWAP ! ( and back-fill the length location )
458 ALIGN ( round up to next multiple of 4 bytes for the remaining code )
459 ELSE ( immediate mode )
460 HERE @ ( get the start address of the temporary space )
465 OVER C! ( save next character )
466 1+ ( increment address )
468 DROP ( drop the final " character )
469 HERE @ - ( calculate the length )
470 HERE @ ( push the start address )
475 ." is the print string operator in FORTH. Example: ." Something to print"
476 The space after the operator is the ordinary space required between words and is not
477 a part of what is printed.
479 In immediate mode we just keep reading characters and printing them until we get to
480 the next double quote.
482 In compile mode we use S" to store the string, then add EMITSTRING afterwards:
483 LITSTRING <string length> <string rounded up to 4 bytes> EMITSTRING
485 It may be interesting to note the use of [COMPILE] to turn the call to the immediate
486 word S" into compilation of that word. It compiles it into the definition of .",
487 not into the definition of the word being compiled when this is running (complicated
490 : ." IMMEDIATE ( -- )
491 STATE @ IF ( compiling? )
492 [COMPILE] S" ( read the string, and compile LITSTRING, etc. )
493 ' EMITSTRING , ( compile the final EMITSTRING )
495 ( In immediate mode, just read characters and print them until we get
496 to the ending double quote. )
500 DROP ( drop the double quote character )
501 EXIT ( return from this function )
509 In FORTH, global constants and variables are defined like this:
511 10 CONSTANT TEN when TEN is executed, it leaves the integer 10 on the stack
512 VARIABLE VAR when VAR is executed, it leaves the address of VAR on the stack
514 Constants can be read but not written, eg:
518 You can read a variable (in this example called VAR) by doing:
520 VAR @ leaves the value of VAR on the stack
521 VAR @ . CR prints the value of VAR
522 VAR ? CR same as above, since ? is the same as @ .
524 and update the variable by doing:
526 20 VAR ! sets VAR to 20
528 Note that variables are uninitialised (but see VALUE later on which provides initialised
529 variables with a slightly simpler syntax).
531 How can we define the words CONSTANT and VARIABLE?
533 The trick is to define a new word for the variable itself (eg. if the variable was called
534 'VAR' then we would define a new word called VAR). This is easy to do because we exposed
535 dictionary entry creation through the CREATE word (part of the definition of : above).
536 A call to CREATE TEN leaves the dictionary entry:
541 +---------+---+---+---+---+
542 | LINK | 3 | T | E | N |
543 +---------+---+---+---+---+
546 For CONSTANT we can continue by appending DOCOL (the codeword), then LIT followed by
547 the constant itself and then EXIT, forming a little word definition that returns the
550 +---------+---+---+---+---+------------+------------+------------+------------+
551 | LINK | 3 | T | E | N | DOCOL | LIT | 10 | EXIT |
552 +---------+---+---+---+---+------------+------------+------------+------------+
555 Notice that this word definition is exactly the same as you would have got if you had
558 Note for people reading the code below: DOCOL is a constant word which we defined in the
559 assembler part which returns the value of the assembler symbol of the same name.
562 CREATE ( make the dictionary entry (the name follows CONSTANT) )
563 DOCOL , ( append DOCOL (the codeword field of this word) )
564 ' LIT , ( append the codeword LIT )
565 , ( append the value on the top of the stack )
566 ' EXIT , ( append the codeword EXIT )
570 VARIABLE is a little bit harder because we need somewhere to put the variable. There is
571 nothing particularly special about the 'user definitions area' (the area of memory pointed
572 to by HERE where we have previously just stored new word definitions). We can slice off
573 bits of this memory area to store anything we want, so one possible definition of
574 VARIABLE might create this:
576 +--------------------------------------------------------------+
579 +---------+---------+---+---+---+---+------------+------------+---|--------+------------+
580 | <var> | LINK | 3 | V | A | R | DOCOL | LIT | <addr var> | EXIT |
581 +---------+---------+---+---+---+---+------------+------------+------------+------------+
584 where <var> is the place to store the variable, and <addr var> points back to it.
586 To make this more general let's define a couple of words which we can use to allocate
587 arbitrary memory from the user definitions area.
589 First ALLOT, where n ALLOT allocates n bytes of memory. (Note when calling this that
590 it's a very good idea to make sure that n is a multiple of 4, or at least that next time
591 a word is compiled that HERE has been left as a multiple of 4).
593 : ALLOT ( n -- addr )
594 HERE @ SWAP ( here n )
595 HERE +! ( adds n to HERE, after this the old value of HERE is still on the stack )
599 Second, CELLS. In FORTH the phrase 'n CELLS ALLOT' means allocate n integers of whatever size
600 is the natural size for integers on this machine architecture. On this 32 bit machine therefore
601 CELLS just multiplies the top of stack by 4.
603 : CELLS ( n -- n ) 4 * ;
606 So now we can define VARIABLE easily in much the same way as CONSTANT above. Refer to the
607 diagram above to see what the word that this creates will look like.
610 1 CELLS ALLOT ( allocate 1 cell of memory, push the pointer to this memory )
611 CREATE ( make the dictionary entry (the name follows VARIABLE) )
612 DOCOL , ( append DOCOL (the codeword field of this word) )
613 ' LIT , ( append the codeword LIT )
614 , ( append the pointer to the new memory )
615 ' EXIT , ( append the codeword EXIT )
619 VALUEs are like VARIABLEs but with a simpler syntax. You would generally use them when you
620 want a variable which is read often, and written infrequently.
622 20 VALUE VAL creates VAL with initial value 20
623 VAL pushes the value directly on the stack
624 30 TO VAL updates VAL, setting it to 30
626 Notice that 'VAL' on its own doesn't return the address of the value, but the value itself,
627 making values simpler and more obvious to use than variables (no indirection through '@').
628 The price is a more complicated implementation, although despite the complexity there is no
629 performance penalty at runtime.
631 A naive implementation of 'TO' would be quite slow, involving a dictionary search each time.
632 But because this is FORTH we have complete control of the compiler so we can compile TO more
633 efficiently, turning:
637 and calculating <addr> (the address of the value) at compile time.
639 Now this is the clever bit. We'll compile our value like this:
641 +---------+---+---+---+---+------------+------------+------------+------------+
642 | LINK | 3 | V | A | L | DOCOL | LIT | <value> | EXIT |
643 +---------+---+---+---+---+------------+------------+------------+------------+
646 where <value> is the actual value itself. Note that when VAL executes, it will push the
647 value on the stack, which is what we want.
649 But what will TO use for the address <addr>? Why of course a pointer to that <value>:
651 code compiled - - - - --+------------+------------+------------+-- - - - -
652 by TO VAL | LIT | <addr> | ! |
653 - - - - --+------------+-----|------+------------+-- - - - -
656 +---------+---+---+---+---+------------+------------+------------+------------+
657 | LINK | 3 | V | A | L | DOCOL | LIT | <value> | EXIT |
658 +---------+---+---+---+---+------------+------------+------------+------------+
661 In other words, this is a kind of self-modifying code.
663 (Note to the people who want to modify this FORTH to add inlining: values defined this
664 way cannot be inlined).
667 CREATE ( make the dictionary entry (the name follows VALUE) )
668 DOCOL , ( append DOCOL )
669 ' LIT , ( append the codeword LIT )
670 , ( append the initial value )
671 ' EXIT , ( append the codeword EXIT )
674 : TO IMMEDIATE ( n -- )
675 WORD ( get the name of the value )
676 FIND ( look it up in the dictionary )
677 >DFA ( get a pointer to the first data field (the 'LIT') )
678 4+ ( increment to point at the value )
679 STATE @ IF ( compiling? )
680 ' LIT , ( compile LIT )
681 , ( compile the address of the value )
683 ELSE ( immediate mode )
684 ! ( update it straightaway )
688 ( x +TO VAL adds x to VAL )
690 WORD ( get the name of the value )
691 FIND ( look it up in the dictionary )
692 >DFA ( get a pointer to the first data field (the 'LIT') )
693 4+ ( increment to point at the value )
694 STATE @ IF ( compiling? )
695 ' LIT , ( compile LIT )
696 , ( compile the address of the value )
697 ' +! , ( compile +! )
698 ELSE ( immediate mode )
699 +! ( update it straightaway )
704 ID. takes an address of a dictionary entry and prints the word's name.
706 For example: LATEST @ ID. would print the name of the last word that was defined.
709 4+ ( skip over the link pointer )
710 DUP C@ ( get the flags/length byte )
711 F_LENMASK AND ( mask out the flags - just want the length )
714 DUP 0> ( length > 0? )
716 SWAP 1+ ( addr len -- len addr+1 )
717 DUP C@ ( len addr -- len addr char | get the next character)
718 EMIT ( len addr char -- len addr | and print it)
719 SWAP 1- ( len addr -- addr len-1 | subtract one from length )
721 2DROP ( len addr -- )
725 'WORD word FIND ?HIDDEN' returns true if 'word' is flagged as hidden.
727 'WORD word FIND ?IMMEDIATE' returns true if 'word' is flagged as immediate.
730 4+ ( skip over the link pointer )
731 C@ ( get the flags/length byte )
732 F_HIDDEN AND ( mask the F_HIDDEN flag and return it (as a truth value) )
735 4+ ( skip over the link pointer )
736 C@ ( get the flags/length byte )
737 F_IMMED AND ( mask the F_IMMED flag and return it (as a truth value) )
741 WORDS prints all the words defined in the dictionary, starting with the word defined most recently.
742 However it doesn't print hidden words.
744 The implementation simply iterates backwards from LATEST using the link pointers.
747 LATEST @ ( start at LATEST dictionary entry )
749 DUP 0<> ( while link pointer is not null )
751 DUP ?HIDDEN NOT IF ( ignore hidden words )
752 DUP ID. ( but if not hidden, print the word )
755 @ ( dereference the link pointer - go to previous word )
762 So far we have only allocated words and memory. FORTH provides a rather primitive method
765 'FORGET word' deletes the definition of 'word' from the dictionary and everything defined
766 after it, including any variables and other memory allocated after.
768 The implementation is very simple - we look up the word (which returns the dictionary entry
769 address). Then we set HERE to point to that address, so in effect all future allocations
770 and definitions will overwrite memory starting at the word. We also need to set LATEST to
771 point to the previous word.
773 Note that you cannot FORGET built-in words (well, you can try but it will probably cause
776 XXX: Because we wrote VARIABLE to store the variable in memory allocated before the word,
777 in the current implementation VARIABLE FOO FORGET FOO will leak 1 cell of memory.
780 WORD FIND ( find the word, gets the dictionary entry address )
781 DUP @ LATEST ! ( set LATEST to point to the previous word )
782 HERE ! ( and store HERE with the dictionary address )
786 DUMP is used to dump out the contents of memory, in the 'traditional' hexdump format.
788 : DUMP ( addr len -- )
789 BASE @ ROT ( save the current BASE at the bottom of the stack )
790 HEX ( and switch the hexadecimal mode )
793 DUP 0> ( while len > 0 )
795 OVER 8 .R ( print the address )
798 ( print up to 16 words on this line )
799 2DUP ( addr len addr len )
800 1- 15 AND 1+ ( addr len addr linelen )
802 DUP 0> ( while linelen > 0 )
804 SWAP ( addr len linelen addr )
805 DUP C@ ( addr len linelen addr byte )
806 2 .R SPACE ( print the byte )
807 1+ SWAP 1- ( addr len linelen addr -- addr len addr+1 linelen-1 )
811 ( print the ASCII equivalents )
812 2DUP 1- 15 AND 1+ ( addr len addr linelen )
814 DUP 0> ( while linelen > 0)
816 SWAP ( addr len linelen addr )
817 DUP C@ ( addr len linelen addr byte )
818 DUP 32 128 WITHIN IF ( 32 <= c < 128? )
823 1+ SWAP 1- ( addr len linelen addr -- addr len addr+1 linelen-1 )
828 DUP 1- 15 AND 1+ ( addr len linelen )
829 DUP ( addr len linelen linelen )
830 ROT ( addr linelen len linelen )
831 - ( addr linelen len-linelen )
832 ROT ( len-linelen addr linelen )
833 + ( len-linelen addr+linelen )
834 SWAP ( addr-linelen len-linelen )
837 2DROP ( restore stack )
838 BASE ! ( restore saved BASE )
841 ( Finally print the welcome prompt. )
842 ." JONESFORTH VERSION " VERSION . CR