Annotation of gforth/doc/gforth.ds, revision 1.4
1.1 anton 1: \input texinfo @c -*-texinfo-*-
2: @comment The source is gforth.ds, from which gforth.texi is generated
3: @comment %**start of header (This is for running Texinfo on a region.)
4: @setfilename gforth.info
5: @settitle Gforth Manual
6: @dircategory GNU programming tools
7: @direntry
8: * Gforth: (gforth). A fast interpreter for the Forth language.
9: @end direntry
10: @comment @setchapternewpage odd
1.3 anton 11: @macro progstyle {TEXT}
12: @quotation
13: {Programming style note:} \TEXT\
14: @end quotation
15: @end macro
1.1 anton 16: @comment %**end of header (This is for running Texinfo on a region.)
17:
18: @ifinfo
19: This file documents Gforth 0.3
20:
21: Copyright @copyright{} 1995-1997 Free Software Foundation, Inc.
22:
23: Permission is granted to make and distribute verbatim copies of
24: this manual provided the copyright notice and this permission notice
25: are preserved on all copies.
26:
27: @ignore
28: Permission is granted to process this file through TeX and print the
29: results, provided the printed document carries a copying permission
30: notice identical to this one except for the removal of this paragraph
31: (this paragraph not being relevant to the printed manual).
32:
33: @end ignore
34: Permission is granted to copy and distribute modified versions of this
35: manual under the conditions for verbatim copying, provided also that the
36: sections entitled "Distribution" and "General Public License" are
37: included exactly as in the original, and provided that the entire
38: resulting derived work is distributed under the terms of a permission
39: notice identical to this one.
40:
41: Permission is granted to copy and distribute translations of this manual
42: into another language, under the above conditions for modified versions,
43: except that the sections entitled "Distribution" and "General Public
44: License" may be included in a translation approved by the author instead
45: of in the original English.
46: @end ifinfo
47:
48: @finalout
49: @titlepage
50: @sp 10
51: @center @titlefont{Gforth Manual}
52: @sp 2
53: @center for version 0.3
54: @sp 2
55: @center Anton Ertl
56: @center Bernd Paysan
1.2 jwilke 57: @center Jens Wilke
1.1 anton 58: @sp 3
59: @center This manual is under construction
60:
61: @comment The following two commands start the copyright page.
62: @page
63: @vskip 0pt plus 1filll
64: Copyright @copyright{} 1995--1997 Free Software Foundation, Inc.
65:
66: @comment !! Published by ... or You can get a copy of this manual ...
67:
68: Permission is granted to make and distribute verbatim copies of
69: this manual provided the copyright notice and this permission notice
70: are preserved on all copies.
71:
72: Permission is granted to copy and distribute modified versions of this
73: manual under the conditions for verbatim copying, provided also that the
74: sections entitled "Distribution" and "General Public License" are
75: included exactly as in the original, and provided that the entire
76: resulting derived work is distributed under the terms of a permission
77: notice identical to this one.
78:
79: Permission is granted to copy and distribute translations of this manual
80: into another language, under the above conditions for modified versions,
81: except that the sections entitled "Distribution" and "General Public
82: License" may be included in a translation approved by the author instead
83: of in the original English.
84: @end titlepage
85:
86:
87: @node Top, License, (dir), (dir)
88: @ifinfo
89: Gforth is a free implementation of ANS Forth available on many
90: personal machines. This manual corresponds to version 0.3.
91: @end ifinfo
92:
93: @menu
94: * License::
95: * Goals:: About the Gforth Project
96: * Other Books:: Things you might want to read
97: * Invoking Gforth:: Starting Gforth
98: * Words:: Forth words available in Gforth
99: * Tools:: Programming tools
100: * ANS conformance:: Implementation-defined options etc.
101: * Model:: The abstract machine of Gforth
102: * Integrating Gforth:: Forth as scripting language for applications
103: * Emacs and Gforth:: The Gforth Mode
104: * Image Files:: @code{.fi} files contain compiled code
105: * Engine:: The inner interpreter and the primitives
106: * Bugs:: How to report them
107: * Origin:: Authors and ancestors of Gforth
108: * Word Index:: An item for each Forth word
109: * Concept Index:: A menu covering many topics
110: @end menu
111:
112: @node License, Goals, Top, Top
113: @unnumbered GNU GENERAL PUBLIC LICENSE
114: @center Version 2, June 1991
115:
116: @display
117: Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
118: 675 Mass Ave, Cambridge, MA 02139, USA
119:
120: Everyone is permitted to copy and distribute verbatim copies
121: of this license document, but changing it is not allowed.
122: @end display
123:
124: @unnumberedsec Preamble
125:
126: The licenses for most software are designed to take away your
127: freedom to share and change it. By contrast, the GNU General Public
128: License is intended to guarantee your freedom to share and change free
129: software---to make sure the software is free for all its users. This
130: General Public License applies to most of the Free Software
131: Foundation's software and to any other program whose authors commit to
132: using it. (Some other Free Software Foundation software is covered by
133: the GNU Library General Public License instead.) You can apply it to
134: your programs, too.
135:
136: When we speak of free software, we are referring to freedom, not
137: price. Our General Public Licenses are designed to make sure that you
138: have the freedom to distribute copies of free software (and charge for
139: this service if you wish), that you receive source code or can get it
140: if you want it, that you can change the software or use pieces of it
141: in new free programs; and that you know you can do these things.
142:
143: To protect your rights, we need to make restrictions that forbid
144: anyone to deny you these rights or to ask you to surrender the rights.
145: These restrictions translate to certain responsibilities for you if you
146: distribute copies of the software, or if you modify it.
147:
148: For example, if you distribute copies of such a program, whether
149: gratis or for a fee, you must give the recipients all the rights that
150: you have. You must make sure that they, too, receive or can get the
151: source code. And you must show them these terms so they know their
152: rights.
153:
154: We protect your rights with two steps: (1) copyright the software, and
155: (2) offer you this license which gives you legal permission to copy,
156: distribute and/or modify the software.
157:
158: Also, for each author's protection and ours, we want to make certain
159: that everyone understands that there is no warranty for this free
160: software. If the software is modified by someone else and passed on, we
161: want its recipients to know that what they have is not the original, so
162: that any problems introduced by others will not reflect on the original
163: authors' reputations.
164:
165: Finally, any free program is threatened constantly by software
166: patents. We wish to avoid the danger that redistributors of a free
167: program will individually obtain patent licenses, in effect making the
168: program proprietary. To prevent this, we have made it clear that any
169: patent must be licensed for everyone's free use or not licensed at all.
170:
171: The precise terms and conditions for copying, distribution and
172: modification follow.
173:
174: @iftex
175: @unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
176: @end iftex
177: @ifinfo
178: @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
179: @end ifinfo
180:
181: @enumerate 0
182: @item
183: This License applies to any program or other work which contains
184: a notice placed by the copyright holder saying it may be distributed
185: under the terms of this General Public License. The ``Program'', below,
186: refers to any such program or work, and a ``work based on the Program''
187: means either the Program or any derivative work under copyright law:
188: that is to say, a work containing the Program or a portion of it,
189: either verbatim or with modifications and/or translated into another
190: language. (Hereinafter, translation is included without limitation in
191: the term ``modification''.) Each licensee is addressed as ``you''.
192:
193: Activities other than copying, distribution and modification are not
194: covered by this License; they are outside its scope. The act of
195: running the Program is not restricted, and the output from the Program
196: is covered only if its contents constitute a work based on the
197: Program (independent of having been made by running the Program).
198: Whether that is true depends on what the Program does.
199:
200: @item
201: You may copy and distribute verbatim copies of the Program's
202: source code as you receive it, in any medium, provided that you
203: conspicuously and appropriately publish on each copy an appropriate
204: copyright notice and disclaimer of warranty; keep intact all the
205: notices that refer to this License and to the absence of any warranty;
206: and give any other recipients of the Program a copy of this License
207: along with the Program.
208:
209: You may charge a fee for the physical act of transferring a copy, and
210: you may at your option offer warranty protection in exchange for a fee.
211:
212: @item
213: You may modify your copy or copies of the Program or any portion
214: of it, thus forming a work based on the Program, and copy and
215: distribute such modifications or work under the terms of Section 1
216: above, provided that you also meet all of these conditions:
217:
218: @enumerate a
219: @item
220: You must cause the modified files to carry prominent notices
221: stating that you changed the files and the date of any change.
222:
223: @item
224: You must cause any work that you distribute or publish, that in
225: whole or in part contains or is derived from the Program or any
226: part thereof, to be licensed as a whole at no charge to all third
227: parties under the terms of this License.
228:
229: @item
230: If the modified program normally reads commands interactively
231: when run, you must cause it, when started running for such
232: interactive use in the most ordinary way, to print or display an
233: announcement including an appropriate copyright notice and a
234: notice that there is no warranty (or else, saying that you provide
235: a warranty) and that users may redistribute the program under
236: these conditions, and telling the user how to view a copy of this
237: License. (Exception: if the Program itself is interactive but
238: does not normally print such an announcement, your work based on
239: the Program is not required to print an announcement.)
240: @end enumerate
241:
242: These requirements apply to the modified work as a whole. If
243: identifiable sections of that work are not derived from the Program,
244: and can be reasonably considered independent and separate works in
245: themselves, then this License, and its terms, do not apply to those
246: sections when you distribute them as separate works. But when you
247: distribute the same sections as part of a whole which is a work based
248: on the Program, the distribution of the whole must be on the terms of
249: this License, whose permissions for other licensees extend to the
250: entire whole, and thus to each and every part regardless of who wrote it.
251:
252: Thus, it is not the intent of this section to claim rights or contest
253: your rights to work written entirely by you; rather, the intent is to
254: exercise the right to control the distribution of derivative or
255: collective works based on the Program.
256:
257: In addition, mere aggregation of another work not based on the Program
258: with the Program (or with a work based on the Program) on a volume of
259: a storage or distribution medium does not bring the other work under
260: the scope of this License.
261:
262: @item
263: You may copy and distribute the Program (or a work based on it,
264: under Section 2) in object code or executable form under the terms of
265: Sections 1 and 2 above provided that you also do one of the following:
266:
267: @enumerate a
268: @item
269: Accompany it with the complete corresponding machine-readable
270: source code, which must be distributed under the terms of Sections
271: 1 and 2 above on a medium customarily used for software interchange; or,
272:
273: @item
274: Accompany it with a written offer, valid for at least three
275: years, to give any third party, for a charge no more than your
276: cost of physically performing source distribution, a complete
277: machine-readable copy of the corresponding source code, to be
278: distributed under the terms of Sections 1 and 2 above on a medium
279: customarily used for software interchange; or,
280:
281: @item
282: Accompany it with the information you received as to the offer
283: to distribute corresponding source code. (This alternative is
284: allowed only for noncommercial distribution and only if you
285: received the program in object code or executable form with such
286: an offer, in accord with Subsection b above.)
287: @end enumerate
288:
289: The source code for a work means the preferred form of the work for
290: making modifications to it. For an executable work, complete source
291: code means all the source code for all modules it contains, plus any
292: associated interface definition files, plus the scripts used to
293: control compilation and installation of the executable. However, as a
294: special exception, the source code distributed need not include
295: anything that is normally distributed (in either source or binary
296: form) with the major components (compiler, kernel, and so on) of the
297: operating system on which the executable runs, unless that component
298: itself accompanies the executable.
299:
300: If distribution of executable or object code is made by offering
301: access to copy from a designated place, then offering equivalent
302: access to copy the source code from the same place counts as
303: distribution of the source code, even though third parties are not
304: compelled to copy the source along with the object code.
305:
306: @item
307: You may not copy, modify, sublicense, or distribute the Program
308: except as expressly provided under this License. Any attempt
309: otherwise to copy, modify, sublicense or distribute the Program is
310: void, and will automatically terminate your rights under this License.
311: However, parties who have received copies, or rights, from you under
312: this License will not have their licenses terminated so long as such
313: parties remain in full compliance.
314:
315: @item
316: You are not required to accept this License, since you have not
317: signed it. However, nothing else grants you permission to modify or
318: distribute the Program or its derivative works. These actions are
319: prohibited by law if you do not accept this License. Therefore, by
320: modifying or distributing the Program (or any work based on the
321: Program), you indicate your acceptance of this License to do so, and
322: all its terms and conditions for copying, distributing or modifying
323: the Program or works based on it.
324:
325: @item
326: Each time you redistribute the Program (or any work based on the
327: Program), the recipient automatically receives a license from the
328: original licensor to copy, distribute or modify the Program subject to
329: these terms and conditions. You may not impose any further
330: restrictions on the recipients' exercise of the rights granted herein.
331: You are not responsible for enforcing compliance by third parties to
332: this License.
333:
334: @item
335: If, as a consequence of a court judgment or allegation of patent
336: infringement or for any other reason (not limited to patent issues),
337: conditions are imposed on you (whether by court order, agreement or
338: otherwise) that contradict the conditions of this License, they do not
339: excuse you from the conditions of this License. If you cannot
340: distribute so as to satisfy simultaneously your obligations under this
341: License and any other pertinent obligations, then as a consequence you
342: may not distribute the Program at all. For example, if a patent
343: license would not permit royalty-free redistribution of the Program by
344: all those who receive copies directly or indirectly through you, then
345: the only way you could satisfy both it and this License would be to
346: refrain entirely from distribution of the Program.
347:
348: If any portion of this section is held invalid or unenforceable under
349: any particular circumstance, the balance of the section is intended to
350: apply and the section as a whole is intended to apply in other
351: circumstances.
352:
353: It is not the purpose of this section to induce you to infringe any
354: patents or other property right claims or to contest validity of any
355: such claims; this section has the sole purpose of protecting the
356: integrity of the free software distribution system, which is
357: implemented by public license practices. Many people have made
358: generous contributions to the wide range of software distributed
359: through that system in reliance on consistent application of that
360: system; it is up to the author/donor to decide if he or she is willing
361: to distribute software through any other system and a licensee cannot
362: impose that choice.
363:
364: This section is intended to make thoroughly clear what is believed to
365: be a consequence of the rest of this License.
366:
367: @item
368: If the distribution and/or use of the Program is restricted in
369: certain countries either by patents or by copyrighted interfaces, the
370: original copyright holder who places the Program under this License
371: may add an explicit geographical distribution limitation excluding
372: those countries, so that distribution is permitted only in or among
373: countries not thus excluded. In such case, this License incorporates
374: the limitation as if written in the body of this License.
375:
376: @item
377: The Free Software Foundation may publish revised and/or new versions
378: of the General Public License from time to time. Such new versions will
379: be similar in spirit to the present version, but may differ in detail to
380: address new problems or concerns.
381:
382: Each version is given a distinguishing version number. If the Program
383: specifies a version number of this License which applies to it and ``any
384: later version'', you have the option of following the terms and conditions
385: either of that version or of any later version published by the Free
386: Software Foundation. If the Program does not specify a version number of
387: this License, you may choose any version ever published by the Free Software
388: Foundation.
389:
390: @item
391: If you wish to incorporate parts of the Program into other free
392: programs whose distribution conditions are different, write to the author
393: to ask for permission. For software which is copyrighted by the Free
394: Software Foundation, write to the Free Software Foundation; we sometimes
395: make exceptions for this. Our decision will be guided by the two goals
396: of preserving the free status of all derivatives of our free software and
397: of promoting the sharing and reuse of software generally.
398:
399: @iftex
400: @heading NO WARRANTY
401: @end iftex
402: @ifinfo
403: @center NO WARRANTY
404: @end ifinfo
405:
406: @item
407: BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
408: FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
409: OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
410: PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
411: OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
412: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
413: TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
414: PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
415: REPAIR OR CORRECTION.
416:
417: @item
418: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
419: WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
420: REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
421: INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
422: OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
423: TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
424: YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
425: PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
426: POSSIBILITY OF SUCH DAMAGES.
427: @end enumerate
428:
429: @iftex
430: @heading END OF TERMS AND CONDITIONS
431: @end iftex
432: @ifinfo
433: @center END OF TERMS AND CONDITIONS
434: @end ifinfo
435:
436: @page
437: @unnumberedsec How to Apply These Terms to Your New Programs
438:
439: If you develop a new program, and you want it to be of the greatest
440: possible use to the public, the best way to achieve this is to make it
441: free software which everyone can redistribute and change under these terms.
442:
443: To do so, attach the following notices to the program. It is safest
444: to attach them to the start of each source file to most effectively
445: convey the exclusion of warranty; and each file should have at least
446: the ``copyright'' line and a pointer to where the full notice is found.
447:
448: @smallexample
449: @var{one line to give the program's name and a brief idea of what it does.}
450: Copyright (C) 19@var{yy} @var{name of author}
451:
452: This program is free software; you can redistribute it and/or modify
453: it under the terms of the GNU General Public License as published by
454: the Free Software Foundation; either version 2 of the License, or
455: (at your option) any later version.
456:
457: This program is distributed in the hope that it will be useful,
458: but WITHOUT ANY WARRANTY; without even the implied warranty of
459: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
460: GNU General Public License for more details.
461:
462: You should have received a copy of the GNU General Public License
463: along with this program; if not, write to the Free Software
464: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
465: @end smallexample
466:
467: Also add information on how to contact you by electronic and paper mail.
468:
469: If the program is interactive, make it output a short notice like this
470: when it starts in an interactive mode:
471:
472: @smallexample
473: Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
474: Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
475: type `show w'.
476: This is free software, and you are welcome to redistribute it
477: under certain conditions; type `show c' for details.
478: @end smallexample
479:
480: The hypothetical commands @samp{show w} and @samp{show c} should show
481: the appropriate parts of the General Public License. Of course, the
482: commands you use may be called something other than @samp{show w} and
483: @samp{show c}; they could even be mouse-clicks or menu items---whatever
484: suits your program.
485:
486: You should also get your employer (if you work as a programmer) or your
487: school, if any, to sign a ``copyright disclaimer'' for the program, if
488: necessary. Here is a sample; alter the names:
489:
490: @smallexample
491: Yoyodyne, Inc., hereby disclaims all copyright interest in the program
492: `Gnomovision' (which makes passes at compilers) written by James Hacker.
493:
494: @var{signature of Ty Coon}, 1 April 1989
495: Ty Coon, President of Vice
496: @end smallexample
497:
498: This General Public License does not permit incorporating your program into
499: proprietary programs. If your program is a subroutine library, you may
500: consider it more useful to permit linking proprietary applications with the
501: library. If this is what you want to do, use the GNU Library General
502: Public License instead of this License.
503:
504: @iftex
505: @unnumbered Preface
506: @cindex Preface
507: This manual documents Gforth. The reader is expected to know
508: Forth. This manual is primarily a reference manual. @xref{Other Books}
509: for introductory material.
510: @end iftex
511:
512: @node Goals, Other Books, License, Top
513: @comment node-name, next, previous, up
514: @chapter Goals of Gforth
515: @cindex Goals
516: The goal of the Gforth Project is to develop a standard model for
517: ANS Forth. This can be split into several subgoals:
518:
519: @itemize @bullet
520: @item
521: Gforth should conform to the Forth standard (ANS Forth).
522: @item
523: It should be a model, i.e. it should define all the
524: implementation-dependent things.
525: @item
526: It should become standard, i.e. widely accepted and used. This goal
527: is the most difficult one.
528: @end itemize
529:
530: To achieve these goals Gforth should be
531: @itemize @bullet
532: @item
533: Similar to previous models (fig-Forth, F83)
534: @item
535: Powerful. It should provide for all the things that are considered
536: necessary today and even some that are not yet considered necessary.
537: @item
538: Efficient. It should not get the reputation of being exceptionally
539: slow.
540: @item
541: Free.
542: @item
543: Available on many machines/easy to port.
544: @end itemize
545:
546: Have we achieved these goals? Gforth conforms to the ANS Forth
547: standard. It may be considered a model, but we have not yet documented
548: which parts of the model are stable and which parts we are likely to
549: change. It certainly has not yet become a de facto standard. It has some
550: similarities and some differences to previous models. It has some
551: powerful features, but not yet everything that we envisioned. We
552: certainly have achieved our execution speed goals (@pxref{Performance}).
553: It is free and available on many machines.
554:
555: @node Other Books, Invoking Gforth, Goals, Top
556: @chapter Other books on ANS Forth
557: @cindex books on Forth
558:
559: As the standard is relatively new, there are not many books out yet. It
560: is not recommended to learn Forth by using Gforth and a book that is
561: not written for ANS Forth, as you will not know your mistakes from the
562: deviations of the book.
563:
564: @cindex standard document for ANS Forth
565: @cindex ANS Forth document
566: There is, of course, the standard, the definite reference if you want to
567: write ANS Forth programs. It is available in printed form from the
568: National Standards Institute Sales Department (Tel.: USA (212) 642-4900;
569: Fax.: USA (212) 302-1286) as document @cite{X3.215-1994} for about $200. You
570: can also get it from Global Engineering Documents (Tel.: USA (800)
571: 854-7179; Fax.: (303) 843-9880) for about $300.
572:
573: @cite{dpANS6}, the last draft of the standard, which was then submitted to ANSI
574: for publication is available electronically and for free in some MS Word
575: format, and it has been converted to HTML. Some pointers to these
576: versions can be found through
577: @*@url{http://www.complang.tuwien.ac.at/projects/forth.html}.
578:
579: @cindex introductory book
580: @cindex book, introductory
581: @cindex Woehr, Jack: @cite{Forth: The New Model}
582: @cindex @cite{Forth: The new model} (book)
583: @cite{Forth: The New Model} by Jack Woehr (Prentice-Hall, 1993) is an
584: introductory book based on a draft version of the standard. It does not
585: cover the whole standard. It also contains interesting background
586: information (Jack Woehr was in the ANS Forth Technical Committee). It is
587: not appropriate for complete newbies, but programmers experienced in
588: other languages should find it ok.
589:
590: @node Invoking Gforth, Words, Other Books, Top
591: @chapter Invoking Gforth
592: @cindex invoking Gforth
593: @cindex running Gforth
594: @cindex command-line options
595: @cindex options on the command line
596: @cindex flags on the command line
597:
598: You will usually just say @code{gforth}. In many other cases the default
599: Gforth image will be invoked like this:
600:
601: @example
602: gforth [files] [-e forth-code]
603: @end example
604:
605: executing the contents of the files and the Forth code in the order they
606: are given.
607:
608: In general, the command line looks like this:
609:
610: @example
611: gforth [initialization options] [image-specific options]
612: @end example
613:
614: The initialization options must come before the rest of the command
615: line. They are:
616:
617: @table @code
618: @cindex -i, command-line option
619: @cindex --image-file, command-line option
620: @item --image-file @var{file}
621: @itemx -i @var{file}
622: Loads the Forth image @var{file} instead of the default
623: @file{gforth.fi} (@pxref{Image Files}).
624:
625: @cindex --path, command-line option
626: @cindex -p, command-line option
627: @item --path @var{path}
628: @itemx -p @var{path}
629: Uses @var{path} for searching the image file and Forth source code files
630: instead of the default in the environment variable @code{GFORTHPATH} or
631: the path specified at installation time (e.g.,
632: @file{/usr/local/share/gforth/0.2.0:.}). A path is given as a list of
633: directories, separated by @samp{:} (on Unix) or @samp{;} (on other OSs).
634:
635: @cindex --dictionary-size, command-line option
636: @cindex -m, command-line option
637: @cindex @var{size} parameters for command-line options
638: @cindex size of the dictionary and the stacks
639: @item --dictionary-size @var{size}
640: @itemx -m @var{size}
641: Allocate @var{size} space for the Forth dictionary space instead of
642: using the default specified in the image (typically 256K). The
643: @var{size} specification consists of an integer and a unit (e.g.,
644: @code{4M}). The unit can be one of @code{b} (bytes), @code{e} (element
645: size, in this case Cells), @code{k} (kilobytes), and @code{M}
646: (Megabytes). If no unit is specified, @code{e} is used.
647:
648: @cindex --data-stack-size, command-line option
649: @cindex -d, command-line option
650: @item --data-stack-size @var{size}
651: @itemx -d @var{size}
652: Allocate @var{size} space for the data stack instead of using the
653: default specified in the image (typically 16K).
654:
655: @cindex --return-stack-size, command-line option
656: @cindex -r, command-line option
657: @item --return-stack-size @var{size}
658: @itemx -r @var{size}
659: Allocate @var{size} space for the return stack instead of using the
660: default specified in the image (typically 15K).
661:
662: @cindex --fp-stack-size, command-line option
663: @cindex -f, command-line option
664: @item --fp-stack-size @var{size}
665: @itemx -f @var{size}
666: Allocate @var{size} space for the floating point stack instead of
667: using the default specified in the image (typically 15.5K). In this case
668: the unit specifier @code{e} refers to floating point numbers.
669:
670: @cindex --locals-stack-size, command-line option
671: @cindex -l, command-line option
672: @item --locals-stack-size @var{size}
673: @itemx -l @var{size}
674: Allocate @var{size} space for the locals stack instead of using the
675: default specified in the image (typically 14.5K).
676:
677: @cindex -h, command-line option
678: @cindex --help, command-line option
679: @item --help
680: @itemx -h
681: Print a message about the command-line options
682:
683: @cindex -v, command-line option
684: @cindex --version, command-line option
685: @item --version
686: @itemx -v
687: Print version and exit
688:
689: @cindex --debug, command-line option
690: @item --debug
691: Print some information useful for debugging on startup.
692:
693: @cindex --offset-image, command-line option
694: @item --offset-image
695: Start the dictionary at a slightly different position than would be used
696: otherwise (useful for creating data-relocatable images,
697: @pxref{Data-Relocatable Image Files}).
698:
699: @cindex --clear-dictionary, command-line option
700: @item --clear-dictionary
701: Initialize all bytes in the dictionary to 0 before loading the image
702: (@pxref{Data-Relocatable Image Files}).
703: @end table
704:
705: @cindex loading files at startup
706: @cindex executing code on startup
707: @cindex batch processing with Gforth
708: As explained above, the image-specific command-line arguments for the
709: default image @file{gforth.fi} consist of a sequence of filenames and
710: @code{-e @var{forth-code}} options that are interpreted in the sequence
711: in which they are given. The @code{-e @var{forth-code}} or
712: @code{--evaluate @var{forth-code}} option evaluates the forth
713: code. This option takes only one argument; if you want to evaluate more
714: Forth words, you have to quote them or use several @code{-e}s. To exit
715: after processing the command line (instead of entering interactive mode)
716: append @code{-e bye} to the command line.
717:
718: @cindex versions, invoking other versions of Gforth
719: If you have several versions of Gforth installed, @code{gforth} will
720: invoke the version that was installed last. @code{gforth-@var{version}}
721: invokes a specific version. You may want to use the option
722: @code{--path}, if your environment contains the variable
723: @code{GFORTHPATH}.
724:
725: Not yet implemented:
726: On startup the system first executes the system initialization file
727: (unless the option @code{--no-init-file} is given; note that the system
728: resulting from using this option may not be ANS Forth conformant). Then
729: the user initialization file @file{.gforth.fs} is executed, unless the
730: option @code{--no-rc} is given; this file is first searched in @file{.},
731: then in @file{~}, then in the normal path (see above).
732:
733: @node Words, Tools, Invoking Gforth, Top
734: @chapter Forth Words
735: @cindex Words
736:
737: @menu
738: * Notation::
739: * Arithmetic::
740: * Stack Manipulation::
741: * Memory::
742: * Control Structures::
743: * Locals::
744: * Defining Words::
745: * Tokens for Words::
746: * Wordlists::
747: * Files::
748: * Blocks::
749: * Other I/O::
750: * Programming Tools::
751: * Assembler and Code words::
752: * Threading Words::
753: @end menu
754:
755: @node Notation, Arithmetic, Words, Words
756: @section Notation
757: @cindex notation of glossary entries
758: @cindex format of glossary entries
759: @cindex glossary notation format
760: @cindex word glossary entry format
761:
762: The Forth words are described in this section in the glossary notation
763: that has become a de-facto standard for Forth texts, i.e.,
764:
765: @format
766: @var{word} @var{Stack effect} @var{wordset} @var{pronunciation}
767: @end format
768: @var{Description}
769:
770: @table @var
771: @item word
772: @cindex case insensitivity
773: The name of the word. BTW, Gforth is case insensitive, so you can
774: type the words in in lower case (However, @pxref{core-idef}).
775:
776: @item Stack effect
777: @cindex stack effect
778: The stack effect is written in the notation @code{@var{before} --
779: @var{after}}, where @var{before} and @var{after} describe the top of
780: stack entries before and after the execution of the word. The rest of
781: the stack is not touched by the word. The top of stack is rightmost,
782: i.e., a stack sequence is written as it is typed in. Note that Gforth
783: uses a separate floating point stack, but a unified stack
784: notation. Also, return stack effects are not shown in @var{stack
785: effect}, but in @var{Description}. The name of a stack item describes
786: the type and/or the function of the item. See below for a discussion of
787: the types.
788:
789: All words have two stack effects: A compile-time stack effect and a
790: run-time stack effect. The compile-time stack-effect of most words is
791: @var{ -- }. If the compile-time stack-effect of a word deviates from
792: this standard behaviour, or the word does other unusual things at
793: compile time, both stack effects are shown; otherwise only the run-time
794: stack effect is shown.
795:
796: @cindex pronounciation of words
797: @item pronunciation
798: How the word is pronounced.
799:
800: @cindex wordset
801: @item wordset
802: The ANS Forth standard is divided into several wordsets. A standard
803: system need not support all of them. So, the fewer wordsets your program
804: uses the more portable it will be in theory. However, we suspect that
805: most ANS Forth systems on personal machines will feature all
806: wordsets. Words that are not defined in the ANS standard have
807: @code{gforth} or @code{gforth-internal} as wordset. @code{gforth}
808: describes words that will work in future releases of Gforth;
809: @code{gforth-internal} words are more volatile. Environmental query
810: strings are also displayed like words; you can recognize them by the
811: @code{environment} in the wordset field.
812:
813: @item Description
814: A description of the behaviour of the word.
815: @end table
816:
817: @cindex types of stack items
818: @cindex stack item types
819: The type of a stack item is specified by the character(s) the name
820: starts with:
821:
822: @table @code
823: @item f
824: @cindex @code{f}, stack item type
825: Boolean flags, i.e. @code{false} or @code{true}.
826: @item c
827: @cindex @code{c}, stack item type
828: Char
829: @item w
830: @cindex @code{w}, stack item type
831: Cell, can contain an integer or an address
832: @item n
833: @cindex @code{n}, stack item type
834: signed integer
835: @item u
836: @cindex @code{u}, stack item type
837: unsigned integer
838: @item d
839: @cindex @code{d}, stack item type
840: double sized signed integer
841: @item ud
842: @cindex @code{ud}, stack item type
843: double sized unsigned integer
844: @item r
845: @cindex @code{r}, stack item type
846: Float (on the FP stack)
847: @item a_
848: @cindex @code{a_}, stack item type
849: Cell-aligned address
850: @item c_
851: @cindex @code{c_}, stack item type
852: Char-aligned address (note that a Char may have two bytes in Windows NT)
853: @item f_
854: @cindex @code{f_}, stack item type
855: Float-aligned address
856: @item df_
857: @cindex @code{df_}, stack item type
858: Address aligned for IEEE double precision float
859: @item sf_
860: @cindex @code{sf_}, stack item type
861: Address aligned for IEEE single precision float
862: @item xt
863: @cindex @code{xt}, stack item type
864: Execution token, same size as Cell
865: @item wid
866: @cindex @code{wid}, stack item type
867: Wordlist ID, same size as Cell
868: @item f83name
869: @cindex @code{f83name}, stack item type
870: Pointer to a name structure
871: @item "
872: @cindex @code{"}, stack item type
873: string in the input stream (not the stack). The terminating character is
874: a blank by default. If it is not a blank, it is shown in @code{<>}
875: quotes.
876: @end table
877:
878: @node Arithmetic, Stack Manipulation, Notation, Words
879: @section Arithmetic
880: @cindex arithmetic words
881:
882: @cindex division with potentially negative operands
883: Forth arithmetic is not checked, i.e., you will not hear about integer
884: overflow on addition or multiplication, you may hear about division by
885: zero if you are lucky. The operator is written after the operands, but
886: the operands are still in the original order. I.e., the infix @code{2-1}
887: corresponds to @code{2 1 -}. Forth offers a variety of division
888: operators. If you perform division with potentially negative operands,
889: you do not want to use @code{/} or @code{/mod} with its undefined
890: behaviour, but rather @code{fm/mod} or @code{sm/mod} (probably the
891: former, @pxref{Mixed precision}).
892:
893: @menu
894: * Single precision::
895: * Bitwise operations::
896: * Mixed precision:: operations with single and double-cell integers
897: * Double precision:: Double-cell integer arithmetic
898: * Floating Point::
899: @end menu
900:
901: @node Single precision, Bitwise operations, Arithmetic, Arithmetic
902: @subsection Single precision
903: @cindex single precision arithmetic words
904:
905: doc-+
906: doc--
907: doc-*
908: doc-/
909: doc-mod
910: doc-/mod
911: doc-negate
912: doc-abs
913: doc-min
914: doc-max
915:
916: @node Bitwise operations, Mixed precision, Single precision, Arithmetic
917: @subsection Bitwise operations
918: @cindex bitwise operation words
919:
920: doc-and
921: doc-or
922: doc-xor
923: doc-invert
924: doc-2*
925: doc-2/
926:
927: @node Mixed precision, Double precision, Bitwise operations, Arithmetic
928: @subsection Mixed precision
929: @cindex mixed precision arithmetic words
930:
931: doc-m+
932: doc-*/
933: doc-*/mod
934: doc-m*
935: doc-um*
936: doc-m*/
937: doc-um/mod
938: doc-fm/mod
939: doc-sm/rem
940:
941: @node Double precision, Floating Point, Mixed precision, Arithmetic
942: @subsection Double precision
943: @cindex double precision arithmetic words
944:
945: @cindex double-cell numbers, input format
946: @cindex input format for double-cell numbers
947: The outer (aka text) interpreter converts numbers containing a dot into
948: a double precision number. Note that only numbers with the dot as last
949: character are standard-conforming.
950:
951: doc-d+
952: doc-d-
953: doc-dnegate
954: doc-dabs
955: doc-dmin
956: doc-dmax
957:
958: @node Floating Point, , Double precision, Arithmetic
959: @subsection Floating Point
960: @cindex floating point arithmetic words
961:
962: @cindex floating-point numbers, input format
963: @cindex input format for floating-point numbers
964: The format of floating point numbers recognized by the outer (aka text)
965: interpreter is: a signed decimal number, possibly containing a decimal
966: point (@code{.}), followed by @code{E} or @code{e}, optionally followed
967: by a signed integer (the exponent). E.g., @code{1e} is the same as
968: @code{+1.0e+0}. Note that a number without @code{e}
969: is not interpreted as floating-point number, but as double (if the
970: number contains a @code{.}) or single precision integer. Also,
971: conversions between string and floating point numbers always use base
972: 10, irrespective of the value of @code{BASE}. If @code{BASE} contains a
973: value greater then 14, the @code{E} may be interpreted as digit and the
974: number will be interpreted as integer, unless it has a signed exponent
975: (both @code{+} and @code{-} are allowed as signs).
976:
977: @cindex angles in trigonometric operations
978: @cindex trigonometric operations
979: Angles in floating point operations are given in radians (a full circle
980: has 2 pi radians). Note, that Gforth has a separate floating point
981: stack, but we use the unified notation.
982:
983: @cindex floating-point arithmetic, pitfalls
984: Floating point numbers have a number of unpleasant surprises for the
985: unwary (e.g., floating point addition is not associative) and even a few
986: for the wary. You should not use them unless you know what you are doing
987: or you don't care that the results you get are totally bogus. If you
988: want to learn about the problems of floating point numbers (and how to
989: avoid them), you might start with @cite{David Goldberg, What Every
990: Computer Scientist Should Know About Floating-Point Arithmetic, ACM
991: Computing Surveys 23(1):5@minus{}48, March 1991}.
992:
993: doc-f+
994: doc-f-
995: doc-f*
996: doc-f/
997: doc-fnegate
998: doc-fabs
999: doc-fmax
1000: doc-fmin
1001: doc-floor
1002: doc-fround
1003: doc-f**
1004: doc-fsqrt
1005: doc-fexp
1006: doc-fexpm1
1007: doc-fln
1008: doc-flnp1
1009: doc-flog
1010: doc-falog
1011: doc-fsin
1012: doc-fcos
1013: doc-fsincos
1014: doc-ftan
1015: doc-fasin
1016: doc-facos
1017: doc-fatan
1018: doc-fatan2
1019: doc-fsinh
1020: doc-fcosh
1021: doc-ftanh
1022: doc-fasinh
1023: doc-facosh
1024: doc-fatanh
1025:
1026: @node Stack Manipulation, Memory, Arithmetic, Words
1027: @section Stack Manipulation
1028: @cindex stack manipulation words
1029:
1030: @cindex floating-point stack in the standard
1031: Gforth has a data stack (aka parameter stack) for characters, cells,
1032: addresses, and double cells, a floating point stack for floating point
1033: numbers, a return stack for storing the return addresses of colon
1034: definitions and other data, and a locals stack for storing local
1035: variables. Note that while every sane Forth has a separate floating
1036: point stack, this is not strictly required; an ANS Forth system could
1037: theoretically keep floating point numbers on the data stack. As an
1038: additional difficulty, you don't know how many cells a floating point
1039: number takes. It is reportedly possible to write words in a way that
1040: they work also for a unified stack model, but we do not recommend trying
1041: it. Instead, just say that your program has an environmental dependency
1042: on a separate FP stack.
1043:
1044: @cindex return stack and locals
1045: @cindex locals and return stack
1046: Also, a Forth system is allowed to keep the local variables on the
1047: return stack. This is reasonable, as local variables usually eliminate
1048: the need to use the return stack explicitly. So, if you want to produce
1049: a standard complying program and if you are using local variables in a
1050: word, forget about return stack manipulations in that word (see the
1051: standard document for the exact rules).
1052:
1053: @menu
1054: * Data stack::
1055: * Floating point stack::
1056: * Return stack::
1057: * Locals stack::
1058: * Stack pointer manipulation::
1059: @end menu
1060:
1061: @node Data stack, Floating point stack, Stack Manipulation, Stack Manipulation
1062: @subsection Data stack
1063: @cindex data stack manipulation words
1064: @cindex stack manipulations words, data stack
1065:
1066: doc-drop
1067: doc-nip
1068: doc-dup
1069: doc-over
1070: doc-tuck
1071: doc-swap
1072: doc-rot
1073: doc--rot
1074: doc-?dup
1075: doc-pick
1076: doc-roll
1077: doc-2drop
1078: doc-2nip
1079: doc-2dup
1080: doc-2over
1081: doc-2tuck
1082: doc-2swap
1083: doc-2rot
1084:
1085: @node Floating point stack, Return stack, Data stack, Stack Manipulation
1086: @subsection Floating point stack
1087: @cindex floating-point stack manipulation words
1088: @cindex stack manipulation words, floating-point stack
1089:
1090: doc-fdrop
1091: doc-fnip
1092: doc-fdup
1093: doc-fover
1094: doc-ftuck
1095: doc-fswap
1096: doc-frot
1097:
1098: @node Return stack, Locals stack, Floating point stack, Stack Manipulation
1099: @subsection Return stack
1100: @cindex return stack manipulation words
1101: @cindex stack manipulation words, return stack
1102:
1103: doc->r
1104: doc-r>
1105: doc-r@
1106: doc-rdrop
1107: doc-2>r
1108: doc-2r>
1109: doc-2r@
1110: doc-2rdrop
1111:
1112: @node Locals stack, Stack pointer manipulation, Return stack, Stack Manipulation
1113: @subsection Locals stack
1114:
1115: @node Stack pointer manipulation, , Locals stack, Stack Manipulation
1116: @subsection Stack pointer manipulation
1117: @cindex stack pointer manipulation words
1118:
1119: doc-sp@
1120: doc-sp!
1121: doc-fp@
1122: doc-fp!
1123: doc-rp@
1124: doc-rp!
1125: doc-lp@
1126: doc-lp!
1127:
1128: @node Memory, Control Structures, Stack Manipulation, Words
1129: @section Memory
1130: @cindex Memory words
1131:
1132: @menu
1133: * Memory Access::
1134: * Address arithmetic::
1135: * Memory Blocks::
1136: @end menu
1137:
1138: @node Memory Access, Address arithmetic, Memory, Memory
1139: @subsection Memory Access
1140: @cindex memory access words
1141:
1142: doc-@
1143: doc-!
1144: doc-+!
1145: doc-c@
1146: doc-c!
1147: doc-2@
1148: doc-2!
1149: doc-f@
1150: doc-f!
1151: doc-sf@
1152: doc-sf!
1153: doc-df@
1154: doc-df!
1155:
1156: @node Address arithmetic, Memory Blocks, Memory Access, Memory
1157: @subsection Address arithmetic
1158: @cindex address arithmetic words
1159:
1160: ANS Forth does not specify the sizes of the data types. Instead, it
1161: offers a number of words for computing sizes and doing address
1162: arithmetic. Basically, address arithmetic is performed in terms of
1163: address units (aus); on most systems the address unit is one byte. Note
1164: that a character may have more than one au, so @code{chars} is no noop
1165: (on systems where it is a noop, it compiles to nothing).
1166:
1167: @cindex alignment of addresses for types
1168: ANS Forth also defines words for aligning addresses for specific
1169: types. Many computers require that accesses to specific data types
1170: must only occur at specific addresses; e.g., that cells may only be
1171: accessed at addresses divisible by 4. Even if a machine allows unaligned
1172: accesses, it can usually perform aligned accesses faster.
1173:
1174: For the performance-conscious: alignment operations are usually only
1175: necessary during the definition of a data structure, not during the
1176: (more frequent) accesses to it.
1177:
1178: ANS Forth defines no words for character-aligning addresses. This is not
1179: an oversight, but reflects the fact that addresses that are not
1180: char-aligned have no use in the standard and therefore will not be
1181: created.
1182:
1183: @cindex @code{CREATE} and alignment
1184: The standard guarantees that addresses returned by @code{CREATE}d words
1185: are cell-aligned; in addition, Gforth guarantees that these addresses
1186: are aligned for all purposes.
1187:
1188: Note that the standard defines a word @code{char}, which has nothing to
1189: do with address arithmetic.
1190:
1191: doc-chars
1192: doc-char+
1193: doc-cells
1194: doc-cell+
1195: doc-cell
1196: doc-align
1197: doc-aligned
1198: doc-floats
1199: doc-float+
1200: doc-float
1201: doc-falign
1202: doc-faligned
1203: doc-sfloats
1204: doc-sfloat+
1205: doc-sfalign
1206: doc-sfaligned
1207: doc-dfloats
1208: doc-dfloat+
1209: doc-dfalign
1210: doc-dfaligned
1211: doc-maxalign
1212: doc-maxaligned
1213: doc-cfalign
1214: doc-cfaligned
1215: doc-address-unit-bits
1216:
1217: @node Memory Blocks, , Address arithmetic, Memory
1218: @subsection Memory Blocks
1219: @cindex memory block words
1220:
1221: doc-move
1222: doc-erase
1223:
1224: While the previous words work on address units, the rest works on
1225: characters.
1226:
1227: doc-cmove
1228: doc-cmove>
1229: doc-fill
1230: doc-blank
1231:
1232: @node Control Structures, Locals, Memory, Words
1233: @section Control Structures
1234: @cindex control structures
1235:
1236: Control structures in Forth cannot be used in interpret state, only in
1237: compile state@footnote{More precisely, they have no interpretation
1238: semantics (@pxref{Interpretation and Compilation Semantics})}, i.e., in
1239: a colon definition. We do not like this limitation, but have not seen a
1240: satisfying way around it yet, although many schemes have been proposed.
1241:
1242: @menu
1243: * Selection::
1244: * Simple Loops::
1245: * Counted Loops::
1246: * Arbitrary control structures::
1247: * Calls and returns::
1248: * Exception Handling::
1249: @end menu
1250:
1251: @node Selection, Simple Loops, Control Structures, Control Structures
1252: @subsection Selection
1253: @cindex selection control structures
1254: @cindex control structures for selection
1255:
1256: @cindex @code{IF} control structure
1257: @example
1258: @var{flag}
1259: IF
1260: @var{code}
1261: ENDIF
1262: @end example
1263: or
1264: @example
1265: @var{flag}
1266: IF
1267: @var{code1}
1268: ELSE
1269: @var{code2}
1270: ENDIF
1271: @end example
1272:
1273: You can use @code{THEN} instead of @code{ENDIF}. Indeed, @code{THEN} is
1274: standard, and @code{ENDIF} is not, although it is quite popular. We
1275: recommend using @code{ENDIF}, because it is less confusing for people
1276: who also know other languages (and is not prone to reinforcing negative
1277: prejudices against Forth in these people). Adding @code{ENDIF} to a
1278: system that only supplies @code{THEN} is simple:
1279: @example
1280: : endif POSTPONE then ; immediate
1281: @end example
1282:
1283: [According to @cite{Webster's New Encyclopedic Dictionary}, @dfn{then
1284: (adv.)} has the following meanings:
1285: @quotation
1286: ... 2b: following next after in order ... 3d: as a necessary consequence
1287: (if you were there, then you saw them).
1288: @end quotation
1289: Forth's @code{THEN} has the meaning 2b, whereas @code{THEN} in Pascal
1290: and many other programming languages has the meaning 3d.]
1291:
1292: Gforth also provides the words @code{?dup-if} and @code{?dup-0=-if}, so
1293: you can avoid using @code{?dup}. Using these alternatives is also more
1294: efficient than using @code{?dup}. Definitions in plain standard Forth
1295: for @code{ENDIF}, @code{?DUP-IF} and @code{?DUP-0=-IF} are provided in
1296: @file{compat/control.fs}.
1297:
1298: @cindex @code{CASE} control structure
1299: @example
1300: @var{n}
1301: CASE
1302: @var{n1} OF @var{code1} ENDOF
1303: @var{n2} OF @var{code2} ENDOF
1304: @dots{}
1305: ENDCASE
1306: @end example
1307:
1308: Executes the first @var{codei}, where the @var{ni} is equal to
1309: @var{n}. A default case can be added by simply writing the code after
1310: the last @code{ENDOF}. It may use @var{n}, which is on top of the stack,
1311: but must not consume it.
1312:
1313: @node Simple Loops, Counted Loops, Selection, Control Structures
1314: @subsection Simple Loops
1315: @cindex simple loops
1316: @cindex loops without count
1317:
1318: @cindex @code{WHILE} loop
1319: @example
1320: BEGIN
1321: @var{code1}
1322: @var{flag}
1323: WHILE
1324: @var{code2}
1325: REPEAT
1326: @end example
1327:
1328: @var{code1} is executed and @var{flag} is computed. If it is true,
1329: @var{code2} is executed and the loop is restarted; If @var{flag} is
1330: false, execution continues after the @code{REPEAT}.
1331:
1332: @cindex @code{UNTIL} loop
1333: @example
1334: BEGIN
1335: @var{code}
1336: @var{flag}
1337: UNTIL
1338: @end example
1339:
1340: @var{code} is executed. The loop is restarted if @code{flag} is false.
1341:
1342: @cindex endless loop
1343: @cindex loops, endless
1344: @example
1345: BEGIN
1346: @var{code}
1347: AGAIN
1348: @end example
1349:
1350: This is an endless loop.
1351:
1352: @node Counted Loops, Arbitrary control structures, Simple Loops, Control Structures
1353: @subsection Counted Loops
1354: @cindex counted loops
1355: @cindex loops, counted
1356: @cindex @code{DO} loops
1357:
1358: The basic counted loop is:
1359: @example
1360: @var{limit} @var{start}
1361: ?DO
1362: @var{body}
1363: LOOP
1364: @end example
1365:
1366: This performs one iteration for every integer, starting from @var{start}
1367: and up to, but excluding @var{limit}. The counter, aka index, can be
1368: accessed with @code{i}. E.g., the loop
1369: @example
1370: 10 0 ?DO
1371: i .
1372: LOOP
1373: @end example
1374: prints
1375: @example
1376: 0 1 2 3 4 5 6 7 8 9
1377: @end example
1378: The index of the innermost loop can be accessed with @code{i}, the index
1379: of the next loop with @code{j}, and the index of the third loop with
1380: @code{k}.
1381:
1382: doc-i
1383: doc-j
1384: doc-k
1385:
1386: The loop control data are kept on the return stack, so there are some
1387: restrictions on mixing return stack accesses and counted loop
1388: words. E.g., if you put values on the return stack outside the loop, you
1389: cannot read them inside the loop. If you put values on the return stack
1390: within a loop, you have to remove them before the end of the loop and
1391: before accessing the index of the loop.
1392:
1393: There are several variations on the counted loop:
1394:
1395: @code{LEAVE} leaves the innermost counted loop immediately.
1396:
1397: If @var{start} is greater than @var{limit}, a @code{?DO} loop is entered
1398: (and @code{LOOP} iterates until they become equal by wrap-around
1399: arithmetic). This behaviour is usually not what you want. Therefore,
1400: Gforth offers @code{+DO} and @code{U+DO} (as replacements for
1401: @code{?DO}), which do not enter the loop if @var{start} is greater than
1402: @var{limit}; @code{+DO} is for signed loop parameters, @code{U+DO} for
1403: unsigned loop parameters.
1404:
1405: @code{LOOP} can be replaced with @code{@var{n} +LOOP}; this updates the
1406: index by @var{n} instead of by 1. The loop is terminated when the border
1407: between @var{limit-1} and @var{limit} is crossed. E.g.:
1408:
1409: @code{4 0 +DO i . 2 +LOOP} prints @code{0 2}
1410:
1411: @code{4 1 +DO i . 2 +LOOP} prints @code{1 3}
1412:
1413: @cindex negative increment for counted loops
1414: @cindex counted loops with negative increment
1415: The behaviour of @code{@var{n} +LOOP} is peculiar when @var{n} is negative:
1416:
1417: @code{-1 0 ?DO i . -1 +LOOP} prints @code{0 -1}
1418:
1419: @code{ 0 0 ?DO i . -1 +LOOP} prints nothing
1420:
1421: Therefore we recommend avoiding @code{@var{n} +LOOP} with negative
1422: @var{n}. One alternative is @code{@var{u} -LOOP}, which reduces the
1423: index by @var{u} each iteration. The loop is terminated when the border
1424: between @var{limit+1} and @var{limit} is crossed. Gforth also provides
1425: @code{-DO} and @code{U-DO} for down-counting loops. E.g.:
1426:
1427: @code{-2 0 -DO i . 1 -LOOP} prints @code{0 -1}
1428:
1429: @code{-1 0 -DO i . 1 -LOOP} prints @code{0}
1430:
1431: @code{ 0 0 -DO i . 1 -LOOP} prints nothing
1432:
1433: Unfortunately, @code{+DO}, @code{U+DO}, @code{-DO}, @code{U-DO} and
1434: @code{-LOOP} are not in the ANS Forth standard. However, an
1435: implementation for these words that uses only standard words is provided
1436: in @file{compat/loops.fs}.
1437:
1438: @code{?DO} can also be replaced by @code{DO}. @code{DO} always enters
1439: the loop, independent of the loop parameters. Do not use @code{DO}, even
1440: if you know that the loop is entered in any case. Such knowledge tends
1441: to become invalid during maintenance of a program, and then the
1442: @code{DO} will make trouble.
1443:
1444: @code{UNLOOP} is used to prepare for an abnormal loop exit, e.g., via
1445: @code{EXIT}. @code{UNLOOP} removes the loop control parameters from the
1446: return stack so @code{EXIT} can get to its return address.
1447:
1448: @cindex @code{FOR} loops
1449: Another counted loop is
1450: @example
1451: @var{n}
1452: FOR
1453: @var{body}
1454: NEXT
1455: @end example
1456: This is the preferred loop of native code compiler writers who are too
1457: lazy to optimize @code{?DO} loops properly. In Gforth, this loop
1458: iterates @var{n+1} times; @code{i} produces values starting with @var{n}
1459: and ending with 0. Other Forth systems may behave differently, even if
1460: they support @code{FOR} loops. To avoid problems, don't use @code{FOR}
1461: loops.
1462:
1463: @node Arbitrary control structures, Calls and returns, Counted Loops, Control Structures
1464: @subsection Arbitrary control structures
1465: @cindex control structures, user-defined
1466:
1467: @cindex control-flow stack
1468: ANS Forth permits and supports using control structures in a non-nested
1469: way. Information about incomplete control structures is stored on the
1470: control-flow stack. This stack may be implemented on the Forth data
1471: stack, and this is what we have done in Gforth.
1472:
1473: @cindex @code{orig}, control-flow stack item
1474: @cindex @code{dest}, control-flow stack item
1475: An @i{orig} entry represents an unresolved forward branch, a @i{dest}
1476: entry represents a backward branch target. A few words are the basis for
1477: building any control structure possible (except control structures that
1478: need storage, like calls, coroutines, and backtracking).
1479:
1480: doc-if
1481: doc-ahead
1482: doc-then
1483: doc-begin
1484: doc-until
1485: doc-again
1486: doc-cs-pick
1487: doc-cs-roll
1488:
1489: On many systems control-flow stack items take one word, in Gforth they
1490: currently take three (this may change in the future). Therefore it is a
1491: really good idea to manipulate the control flow stack with
1492: @code{cs-pick} and @code{cs-roll}, not with data stack manipulation
1493: words.
1494:
1495: Some standard control structure words are built from these words:
1496:
1497: doc-else
1498: doc-while
1499: doc-repeat
1500:
1501: Gforth adds some more control-structure words:
1502:
1503: doc-endif
1504: doc-?dup-if
1505: doc-?dup-0=-if
1506:
1507: Counted loop words constitute a separate group of words:
1508:
1509: doc-?do
1510: doc-+do
1511: doc-u+do
1512: doc--do
1513: doc-u-do
1514: doc-do
1515: doc-for
1516: doc-loop
1517: doc-+loop
1518: doc--loop
1519: doc-next
1520: doc-leave
1521: doc-?leave
1522: doc-unloop
1523: doc-done
1524:
1525: The standard does not allow using @code{cs-pick} and @code{cs-roll} on
1526: @i{do-sys}. Our system allows it, but it's your job to ensure that for
1527: every @code{?DO} etc. there is exactly one @code{UNLOOP} on any path
1528: through the definition (@code{LOOP} etc. compile an @code{UNLOOP} on the
1529: fall-through path). Also, you have to ensure that all @code{LEAVE}s are
1530: resolved (by using one of the loop-ending words or @code{DONE}).
1531:
1532: Another group of control structure words are
1533:
1534: doc-case
1535: doc-endcase
1536: doc-of
1537: doc-endof
1538:
1539: @i{case-sys} and @i{of-sys} cannot be processed using @code{cs-pick} and
1540: @code{cs-roll}.
1541:
1542: @subsubsection Programming Style
1543:
1544: In order to ensure readability we recommend that you do not create
1545: arbitrary control structures directly, but define new control structure
1546: words for the control structure you want and use these words in your
1547: program.
1548:
1549: E.g., instead of writing
1550:
1551: @example
1552: begin
1553: ...
1554: if [ 1 cs-roll ]
1555: ...
1556: again then
1557: @end example
1558:
1559: we recommend defining control structure words, e.g.,
1560:
1561: @example
1562: : while ( dest -- orig dest )
1563: POSTPONE if
1564: 1 cs-roll ; immediate
1565:
1566: : repeat ( orig dest -- )
1567: POSTPONE again
1568: POSTPONE then ; immediate
1569: @end example
1570:
1571: and then using these to create the control structure:
1572:
1573: @example
1574: begin
1575: ...
1576: while
1577: ...
1578: repeat
1579: @end example
1580:
1581: That's much easier to read, isn't it? Of course, @code{REPEAT} and
1582: @code{WHILE} are predefined, so in this example it would not be
1583: necessary to define them.
1584:
1585: @node Calls and returns, Exception Handling, Arbitrary control structures, Control Structures
1586: @subsection Calls and returns
1587: @cindex calling a definition
1588: @cindex returning from a definition
1589:
1.3 anton 1590: @cindex recursive definitions
1591: A definition can be called simply be writing the name of the definition
1592: to be called. Note that normally a definition is invisible during its
1593: definition. If you want to write a directly recursive definition, you
1594: can use @code{recursive} to make the current definition visible.
1595:
1596: doc-recursive
1597:
1598: Another way to perform a recursive call is
1599:
1600: doc-recurse
1601:
1602: @c @progstyle{
1603: I prefer using @code{recursive} to @code{recurse}, because
1604: calling the definition by name is more descriptive (if the name is
1605: well-chosen) than the somewhat cryptic @code{recurse}. E.g., in a
1606: quicksort implementation, it is much better to read (and think) ``now
1607: sort the partitions'' than to read ``now do a recursive call''.
1608:
1609: For mutual recursion, use @code{defer}red words, like this:
1610:
1611: @example
1612: defer foo
1613:
1614: : bar ( ... -- ... )
1615: ... foo ... ;
1616:
1617: :noname ( ... -- ... )
1618: ... bar ... ;
1619: IS foo
1620: @end example
1621:
1622: When the end of the definition is reached, it returns. An earlier return
1623: can be forced using
1.1 anton 1624:
1625: doc-exit
1626:
1627: Don't forget to clean up the return stack and @code{UNLOOP} any
1628: outstanding @code{?DO}...@code{LOOP}s before @code{EXIT}ing. The
1629: primitive compiled by @code{EXIT} is
1630:
1631: doc-;s
1632:
1633: @node Exception Handling, , Calls and returns, Control Structures
1634: @subsection Exception Handling
1635: @cindex Exceptions
1636:
1637: doc-catch
1638: doc-throw
1639:
1640: @node Locals, Defining Words, Control Structures, Words
1641: @section Locals
1642: @cindex locals
1643:
1644: Local variables can make Forth programming more enjoyable and Forth
1645: programs easier to read. Unfortunately, the locals of ANS Forth are
1646: laden with restrictions. Therefore, we provide not only the ANS Forth
1647: locals wordset, but also our own, more powerful locals wordset (we
1648: implemented the ANS Forth locals wordset through our locals wordset).
1649:
1650: The ideas in this section have also been published in the paper
1651: @cite{Automatic Scoping of Local Variables} by M. Anton Ertl, presented
1652: at EuroForth '94; it is available at
1653: @*@url{http://www.complang.tuwien.ac.at/papers/ertl94l.ps.gz}.
1654:
1655: @menu
1656: * Gforth locals::
1657: * ANS Forth locals::
1658: @end menu
1659:
1660: @node Gforth locals, ANS Forth locals, Locals, Locals
1661: @subsection Gforth locals
1662: @cindex Gforth locals
1663: @cindex locals, Gforth style
1664:
1665: Locals can be defined with
1666:
1667: @example
1668: @{ local1 local2 ... -- comment @}
1669: @end example
1670: or
1671: @example
1672: @{ local1 local2 ... @}
1673: @end example
1674:
1675: E.g.,
1676: @example
1677: : max @{ n1 n2 -- n3 @}
1678: n1 n2 > if
1679: n1
1680: else
1681: n2
1682: endif ;
1683: @end example
1684:
1685: The similarity of locals definitions with stack comments is intended. A
1686: locals definition often replaces the stack comment of a word. The order
1687: of the locals corresponds to the order in a stack comment and everything
1688: after the @code{--} is really a comment.
1689:
1690: This similarity has one disadvantage: It is too easy to confuse locals
1691: declarations with stack comments, causing bugs and making them hard to
1692: find. However, this problem can be avoided by appropriate coding
1693: conventions: Do not use both notations in the same program. If you do,
1694: they should be distinguished using additional means, e.g. by position.
1695:
1696: @cindex types of locals
1697: @cindex locals types
1698: The name of the local may be preceded by a type specifier, e.g.,
1699: @code{F:} for a floating point value:
1700:
1701: @example
1702: : CX* @{ F: Ar F: Ai F: Br F: Bi -- Cr Ci @}
1703: \ complex multiplication
1704: Ar Br f* Ai Bi f* f-
1705: Ar Bi f* Ai Br f* f+ ;
1706: @end example
1707:
1708: @cindex flavours of locals
1709: @cindex locals flavours
1710: @cindex value-flavoured locals
1711: @cindex variable-flavoured locals
1712: Gforth currently supports cells (@code{W:}, @code{W^}), doubles
1713: (@code{D:}, @code{D^}), floats (@code{F:}, @code{F^}) and characters
1714: (@code{C:}, @code{C^}) in two flavours: a value-flavoured local (defined
1715: with @code{W:}, @code{D:} etc.) produces its value and can be changed
1716: with @code{TO}. A variable-flavoured local (defined with @code{W^} etc.)
1717: produces its address (which becomes invalid when the variable's scope is
1718: left). E.g., the standard word @code{emit} can be defined in terms of
1719: @code{type} like this:
1720:
1721: @example
1722: : emit @{ C^ char* -- @}
1723: char* 1 type ;
1724: @end example
1725:
1726: @cindex default type of locals
1727: @cindex locals, default type
1728: A local without type specifier is a @code{W:} local. Both flavours of
1729: locals are initialized with values from the data or FP stack.
1730:
1731: Currently there is no way to define locals with user-defined data
1732: structures, but we are working on it.
1733:
1734: Gforth allows defining locals everywhere in a colon definition. This
1735: poses the following questions:
1736:
1737: @menu
1738: * Where are locals visible by name?::
1739: * How long do locals live?::
1740: * Programming Style::
1741: * Implementation::
1742: @end menu
1743:
1744: @node Where are locals visible by name?, How long do locals live?, Gforth locals, Gforth locals
1745: @subsubsection Where are locals visible by name?
1746: @cindex locals visibility
1747: @cindex visibility of locals
1748: @cindex scope of locals
1749:
1750: Basically, the answer is that locals are visible where you would expect
1751: it in block-structured languages, and sometimes a little longer. If you
1752: want to restrict the scope of a local, enclose its definition in
1753: @code{SCOPE}...@code{ENDSCOPE}.
1754:
1755: doc-scope
1756: doc-endscope
1757:
1758: These words behave like control structure words, so you can use them
1759: with @code{CS-PICK} and @code{CS-ROLL} to restrict the scope in
1760: arbitrary ways.
1761:
1762: If you want a more exact answer to the visibility question, here's the
1763: basic principle: A local is visible in all places that can only be
1764: reached through the definition of the local@footnote{In compiler
1765: construction terminology, all places dominated by the definition of the
1766: local.}. In other words, it is not visible in places that can be reached
1767: without going through the definition of the local. E.g., locals defined
1768: in @code{IF}...@code{ENDIF} are visible until the @code{ENDIF}, locals
1769: defined in @code{BEGIN}...@code{UNTIL} are visible after the
1770: @code{UNTIL} (until, e.g., a subsequent @code{ENDSCOPE}).
1771:
1772: The reasoning behind this solution is: We want to have the locals
1773: visible as long as it is meaningful. The user can always make the
1774: visibility shorter by using explicit scoping. In a place that can
1775: only be reached through the definition of a local, the meaning of a
1776: local name is clear. In other places it is not: How is the local
1777: initialized at the control flow path that does not contain the
1778: definition? Which local is meant, if the same name is defined twice in
1779: two independent control flow paths?
1780:
1781: This should be enough detail for nearly all users, so you can skip the
1782: rest of this section. If you really must know all the gory details and
1783: options, read on.
1784:
1785: In order to implement this rule, the compiler has to know which places
1786: are unreachable. It knows this automatically after @code{AHEAD},
1787: @code{AGAIN}, @code{EXIT} and @code{LEAVE}; in other cases (e.g., after
1788: most @code{THROW}s), you can use the word @code{UNREACHABLE} to tell the
1789: compiler that the control flow never reaches that place. If
1790: @code{UNREACHABLE} is not used where it could, the only consequence is
1791: that the visibility of some locals is more limited than the rule above
1792: says. If @code{UNREACHABLE} is used where it should not (i.e., if you
1793: lie to the compiler), buggy code will be produced.
1794:
1795: doc-unreachable
1796:
1797: Another problem with this rule is that at @code{BEGIN}, the compiler
1798: does not know which locals will be visible on the incoming
1799: back-edge. All problems discussed in the following are due to this
1800: ignorance of the compiler (we discuss the problems using @code{BEGIN}
1801: loops as examples; the discussion also applies to @code{?DO} and other
1802: loops). Perhaps the most insidious example is:
1803: @example
1804: AHEAD
1805: BEGIN
1806: x
1807: [ 1 CS-ROLL ] THEN
1808: @{ x @}
1809: ...
1810: UNTIL
1811: @end example
1812:
1813: This should be legal according to the visibility rule. The use of
1814: @code{x} can only be reached through the definition; but that appears
1815: textually below the use.
1816:
1817: From this example it is clear that the visibility rules cannot be fully
1818: implemented without major headaches. Our implementation treats common
1819: cases as advertised and the exceptions are treated in a safe way: The
1820: compiler makes a reasonable guess about the locals visible after a
1821: @code{BEGIN}; if it is too pessimistic, the
1822: user will get a spurious error about the local not being defined; if the
1823: compiler is too optimistic, it will notice this later and issue a
1824: warning. In the case above the compiler would complain about @code{x}
1825: being undefined at its use. You can see from the obscure examples in
1826: this section that it takes quite unusual control structures to get the
1827: compiler into trouble, and even then it will often do fine.
1828:
1829: If the @code{BEGIN} is reachable from above, the most optimistic guess
1830: is that all locals visible before the @code{BEGIN} will also be
1831: visible after the @code{BEGIN}. This guess is valid for all loops that
1832: are entered only through the @code{BEGIN}, in particular, for normal
1833: @code{BEGIN}...@code{WHILE}...@code{REPEAT} and
1834: @code{BEGIN}...@code{UNTIL} loops and it is implemented in our
1835: compiler. When the branch to the @code{BEGIN} is finally generated by
1836: @code{AGAIN} or @code{UNTIL}, the compiler checks the guess and
1837: warns the user if it was too optimistic:
1838: @example
1839: IF
1840: @{ x @}
1841: BEGIN
1842: \ x ?
1843: [ 1 cs-roll ] THEN
1844: ...
1845: UNTIL
1846: @end example
1847:
1848: Here, @code{x} lives only until the @code{BEGIN}, but the compiler
1849: optimistically assumes that it lives until the @code{THEN}. It notices
1850: this difference when it compiles the @code{UNTIL} and issues a
1851: warning. The user can avoid the warning, and make sure that @code{x}
1852: is not used in the wrong area by using explicit scoping:
1853: @example
1854: IF
1855: SCOPE
1856: @{ x @}
1857: ENDSCOPE
1858: BEGIN
1859: [ 1 cs-roll ] THEN
1860: ...
1861: UNTIL
1862: @end example
1863:
1864: Since the guess is optimistic, there will be no spurious error messages
1865: about undefined locals.
1866:
1867: If the @code{BEGIN} is not reachable from above (e.g., after
1868: @code{AHEAD} or @code{EXIT}), the compiler cannot even make an
1869: optimistic guess, as the locals visible after the @code{BEGIN} may be
1870: defined later. Therefore, the compiler assumes that no locals are
1871: visible after the @code{BEGIN}. However, the user can use
1872: @code{ASSUME-LIVE} to make the compiler assume that the same locals are
1873: visible at the BEGIN as at the point where the top control-flow stack
1874: item was created.
1875:
1876: doc-assume-live
1877:
1878: E.g.,
1879: @example
1880: @{ x @}
1881: AHEAD
1882: ASSUME-LIVE
1883: BEGIN
1884: x
1885: [ 1 CS-ROLL ] THEN
1886: ...
1887: UNTIL
1888: @end example
1889:
1890: Other cases where the locals are defined before the @code{BEGIN} can be
1891: handled by inserting an appropriate @code{CS-ROLL} before the
1892: @code{ASSUME-LIVE} (and changing the control-flow stack manipulation
1893: behind the @code{ASSUME-LIVE}).
1894:
1895: Cases where locals are defined after the @code{BEGIN} (but should be
1896: visible immediately after the @code{BEGIN}) can only be handled by
1897: rearranging the loop. E.g., the ``most insidious'' example above can be
1898: arranged into:
1899: @example
1900: BEGIN
1901: @{ x @}
1902: ... 0=
1903: WHILE
1904: x
1905: REPEAT
1906: @end example
1907:
1908: @node How long do locals live?, Programming Style, Where are locals visible by name?, Gforth locals
1909: @subsubsection How long do locals live?
1910: @cindex locals lifetime
1911: @cindex lifetime of locals
1912:
1913: The right answer for the lifetime question would be: A local lives at
1914: least as long as it can be accessed. For a value-flavoured local this
1915: means: until the end of its visibility. However, a variable-flavoured
1916: local could be accessed through its address far beyond its visibility
1917: scope. Ultimately, this would mean that such locals would have to be
1918: garbage collected. Since this entails un-Forth-like implementation
1919: complexities, I adopted the same cowardly solution as some other
1920: languages (e.g., C): The local lives only as long as it is visible;
1921: afterwards its address is invalid (and programs that access it
1922: afterwards are erroneous).
1923:
1924: @node Programming Style, Implementation, How long do locals live?, Gforth locals
1925: @subsubsection Programming Style
1926: @cindex locals programming style
1927: @cindex programming style, locals
1928:
1929: The freedom to define locals anywhere has the potential to change
1930: programming styles dramatically. In particular, the need to use the
1931: return stack for intermediate storage vanishes. Moreover, all stack
1932: manipulations (except @code{PICK}s and @code{ROLL}s with run-time
1933: determined arguments) can be eliminated: If the stack items are in the
1934: wrong order, just write a locals definition for all of them; then
1935: write the items in the order you want.
1936:
1937: This seems a little far-fetched and eliminating stack manipulations is
1938: unlikely to become a conscious programming objective. Still, the number
1939: of stack manipulations will be reduced dramatically if local variables
1940: are used liberally (e.g., compare @code{max} in @ref{Gforth locals} with
1941: a traditional implementation of @code{max}).
1942:
1943: This shows one potential benefit of locals: making Forth programs more
1944: readable. Of course, this benefit will only be realized if the
1945: programmers continue to honour the principle of factoring instead of
1946: using the added latitude to make the words longer.
1947:
1948: @cindex single-assignment style for locals
1949: Using @code{TO} can and should be avoided. Without @code{TO},
1950: every value-flavoured local has only a single assignment and many
1951: advantages of functional languages apply to Forth. I.e., programs are
1952: easier to analyse, to optimize and to read: It is clear from the
1953: definition what the local stands for, it does not turn into something
1954: different later.
1955:
1956: E.g., a definition using @code{TO} might look like this:
1957: @example
1958: : strcmp @{ addr1 u1 addr2 u2 -- n @}
1959: u1 u2 min 0
1960: ?do
1961: addr1 c@@ addr2 c@@ -
1962: ?dup-if
1963: unloop exit
1964: then
1965: addr1 char+ TO addr1
1966: addr2 char+ TO addr2
1967: loop
1968: u1 u2 - ;
1969: @end example
1970: Here, @code{TO} is used to update @code{addr1} and @code{addr2} at
1971: every loop iteration. @code{strcmp} is a typical example of the
1972: readability problems of using @code{TO}. When you start reading
1973: @code{strcmp}, you think that @code{addr1} refers to the start of the
1974: string. Only near the end of the loop you realize that it is something
1975: else.
1976:
1977: This can be avoided by defining two locals at the start of the loop that
1978: are initialized with the right value for the current iteration.
1979: @example
1980: : strcmp @{ addr1 u1 addr2 u2 -- n @}
1981: addr1 addr2
1982: u1 u2 min 0
1983: ?do @{ s1 s2 @}
1984: s1 c@@ s2 c@@ -
1985: ?dup-if
1986: unloop exit
1987: then
1988: s1 char+ s2 char+
1989: loop
1990: 2drop
1991: u1 u2 - ;
1992: @end example
1993: Here it is clear from the start that @code{s1} has a different value
1994: in every loop iteration.
1995:
1996: @node Implementation, , Programming Style, Gforth locals
1997: @subsubsection Implementation
1998: @cindex locals implementation
1999: @cindex implementation of locals
2000:
2001: @cindex locals stack
2002: Gforth uses an extra locals stack. The most compelling reason for
2003: this is that the return stack is not float-aligned; using an extra stack
2004: also eliminates the problems and restrictions of using the return stack
2005: as locals stack. Like the other stacks, the locals stack grows toward
2006: lower addresses. A few primitives allow an efficient implementation:
2007:
2008: doc-@local#
2009: doc-f@local#
2010: doc-laddr#
2011: doc-lp+!#
2012: doc-lp!
2013: doc->l
2014: doc-f>l
2015:
2016: In addition to these primitives, some specializations of these
2017: primitives for commonly occurring inline arguments are provided for
2018: efficiency reasons, e.g., @code{@@local0} as specialization of
2019: @code{@@local#} for the inline argument 0. The following compiling words
2020: compile the right specialized version, or the general version, as
2021: appropriate:
2022:
2023: doc-compile-@local
2024: doc-compile-f@local
2025: doc-compile-lp+!
2026:
2027: Combinations of conditional branches and @code{lp+!#} like
2028: @code{?branch-lp+!#} (the locals pointer is only changed if the branch
2029: is taken) are provided for efficiency and correctness in loops.
2030:
2031: A special area in the dictionary space is reserved for keeping the
2032: local variable names. @code{@{} switches the dictionary pointer to this
2033: area and @code{@}} switches it back and generates the locals
2034: initializing code. @code{W:} etc.@ are normal defining words. This
2035: special area is cleared at the start of every colon definition.
2036:
2037: @cindex wordlist for defining locals
2038: A special feature of Gforth's dictionary is used to implement the
2039: definition of locals without type specifiers: every wordlist (aka
2040: vocabulary) has its own methods for searching
2041: etc. (@pxref{Wordlists}). For the present purpose we defined a wordlist
2042: with a special search method: When it is searched for a word, it
2043: actually creates that word using @code{W:}. @code{@{} changes the search
2044: order to first search the wordlist containing @code{@}}, @code{W:} etc.,
2045: and then the wordlist for defining locals without type specifiers.
2046:
2047: The lifetime rules support a stack discipline within a colon
2048: definition: The lifetime of a local is either nested with other locals
2049: lifetimes or it does not overlap them.
2050:
2051: At @code{BEGIN}, @code{IF}, and @code{AHEAD} no code for locals stack
2052: pointer manipulation is generated. Between control structure words
2053: locals definitions can push locals onto the locals stack. @code{AGAIN}
2054: is the simplest of the other three control flow words. It has to
2055: restore the locals stack depth of the corresponding @code{BEGIN}
2056: before branching. The code looks like this:
2057: @format
2058: @code{lp+!#} current-locals-size @minus{} dest-locals-size
2059: @code{branch} <begin>
2060: @end format
2061:
2062: @code{UNTIL} is a little more complicated: If it branches back, it
2063: must adjust the stack just like @code{AGAIN}. But if it falls through,
2064: the locals stack must not be changed. The compiler generates the
2065: following code:
2066: @format
2067: @code{?branch-lp+!#} <begin> current-locals-size @minus{} dest-locals-size
2068: @end format
2069: The locals stack pointer is only adjusted if the branch is taken.
2070:
2071: @code{THEN} can produce somewhat inefficient code:
2072: @format
2073: @code{lp+!#} current-locals-size @minus{} orig-locals-size
2074: <orig target>:
2075: @code{lp+!#} orig-locals-size @minus{} new-locals-size
2076: @end format
2077: The second @code{lp+!#} adjusts the locals stack pointer from the
2078: level at the @var{orig} point to the level after the @code{THEN}. The
2079: first @code{lp+!#} adjusts the locals stack pointer from the current
2080: level to the level at the orig point, so the complete effect is an
2081: adjustment from the current level to the right level after the
2082: @code{THEN}.
2083:
2084: @cindex locals information on the control-flow stack
2085: @cindex control-flow stack items, locals information
2086: In a conventional Forth implementation a dest control-flow stack entry
2087: is just the target address and an orig entry is just the address to be
2088: patched. Our locals implementation adds a wordlist to every orig or dest
2089: item. It is the list of locals visible (or assumed visible) at the point
2090: described by the entry. Our implementation also adds a tag to identify
2091: the kind of entry, in particular to differentiate between live and dead
2092: (reachable and unreachable) orig entries.
2093:
2094: A few unusual operations have to be performed on locals wordlists:
2095:
2096: doc-common-list
2097: doc-sub-list?
2098: doc-list-size
2099:
2100: Several features of our locals wordlist implementation make these
2101: operations easy to implement: The locals wordlists are organised as
2102: linked lists; the tails of these lists are shared, if the lists
2103: contain some of the same locals; and the address of a name is greater
2104: than the address of the names behind it in the list.
2105:
2106: Another important implementation detail is the variable
2107: @code{dead-code}. It is used by @code{BEGIN} and @code{THEN} to
2108: determine if they can be reached directly or only through the branch
2109: that they resolve. @code{dead-code} is set by @code{UNREACHABLE},
2110: @code{AHEAD}, @code{EXIT} etc., and cleared at the start of a colon
2111: definition, by @code{BEGIN} and usually by @code{THEN}.
2112:
2113: Counted loops are similar to other loops in most respects, but
2114: @code{LEAVE} requires special attention: It performs basically the same
2115: service as @code{AHEAD}, but it does not create a control-flow stack
2116: entry. Therefore the information has to be stored elsewhere;
2117: traditionally, the information was stored in the target fields of the
2118: branches created by the @code{LEAVE}s, by organizing these fields into a
2119: linked list. Unfortunately, this clever trick does not provide enough
2120: space for storing our extended control flow information. Therefore, we
2121: introduce another stack, the leave stack. It contains the control-flow
2122: stack entries for all unresolved @code{LEAVE}s.
2123:
2124: Local names are kept until the end of the colon definition, even if
2125: they are no longer visible in any control-flow path. In a few cases
2126: this may lead to increased space needs for the locals name area, but
2127: usually less than reclaiming this space would cost in code size.
2128:
2129:
2130: @node ANS Forth locals, , Gforth locals, Locals
2131: @subsection ANS Forth locals
2132: @cindex locals, ANS Forth style
2133:
2134: The ANS Forth locals wordset does not define a syntax for locals, but
2135: words that make it possible to define various syntaxes. One of the
2136: possible syntaxes is a subset of the syntax we used in the Gforth locals
2137: wordset, i.e.:
2138:
2139: @example
2140: @{ local1 local2 ... -- comment @}
2141: @end example
2142: or
2143: @example
2144: @{ local1 local2 ... @}
2145: @end example
2146:
2147: The order of the locals corresponds to the order in a stack comment. The
2148: restrictions are:
2149:
2150: @itemize @bullet
2151: @item
2152: Locals can only be cell-sized values (no type specifiers are allowed).
2153: @item
2154: Locals can be defined only outside control structures.
2155: @item
2156: Locals can interfere with explicit usage of the return stack. For the
2157: exact (and long) rules, see the standard. If you don't use return stack
2158: accessing words in a definition using locals, you will be all right. The
2159: purpose of this rule is to make locals implementation on the return
2160: stack easier.
2161: @item
2162: The whole definition must be in one line.
2163: @end itemize
2164:
2165: Locals defined in this way behave like @code{VALUE}s (@xref{Simple
2166: Defining Words}). I.e., they are initialized from the stack. Using their
2167: name produces their value. Their value can be changed using @code{TO}.
2168:
2169: Since this syntax is supported by Gforth directly, you need not do
2170: anything to use it. If you want to port a program using this syntax to
2171: another ANS Forth system, use @file{compat/anslocal.fs} to implement the
2172: syntax on the other system.
2173:
2174: Note that a syntax shown in the standard, section A.13 looks
2175: similar, but is quite different in having the order of locals
2176: reversed. Beware!
2177:
2178: The ANS Forth locals wordset itself consists of the following word
2179:
2180: doc-(local)
2181:
2182: The ANS Forth locals extension wordset defines a syntax, but it is so
2183: awful that we strongly recommend not to use it. We have implemented this
2184: syntax to make porting to Gforth easy, but do not document it here. The
2185: problem with this syntax is that the locals are defined in an order
2186: reversed with respect to the standard stack comment notation, making
2187: programs harder to read, and easier to misread and miswrite. The only
2188: merit of this syntax is that it is easy to implement using the ANS Forth
2189: locals wordset.
2190:
2191: @node Defining Words, Tokens for Words, Locals, Words
2192: @section Defining Words
2193: @cindex defining words
2194:
2195: @menu
2196: * Simple Defining Words::
2197: * Colon Definitions::
2198: * User-defined Defining Words::
2199: * Supplying names::
2200: * Interpretation and Compilation Semantics::
2201: @end menu
2202:
2203: @node Simple Defining Words, Colon Definitions, Defining Words, Defining Words
2204: @subsection Simple Defining Words
2205: @cindex simple defining words
2206: @cindex defining words, simple
2207:
2208: doc-constant
2209: doc-2constant
2210: doc-fconstant
2211: doc-variable
2212: doc-2variable
2213: doc-fvariable
2214: doc-create
2215: doc-user
2216: doc-value
2217: doc-to
2218: doc-defer
2219: doc-is
2220:
2221: @node Colon Definitions, User-defined Defining Words, Simple Defining Words, Defining Words
2222: @subsection Colon Definitions
2223: @cindex colon definitions
2224:
2225: @example
2226: : name ( ... -- ... )
2227: word1 word2 word3 ;
2228: @end example
2229:
2230: creates a word called @code{name}, that, upon execution, executes
2231: @code{word1 word2 word3}. @code{name} is a @dfn{(colon) definition}.
2232:
2233: The explanation above is somewhat superficial. @xref{Interpretation and
2234: Compilation Semantics} for an in-depth discussion of some of the issues
2235: involved.
2236:
2237: doc-:
2238: doc-;
2239:
2240: @node User-defined Defining Words, Supplying names, Colon Definitions, Defining Words
2241: @subsection User-defined Defining Words
2242: @cindex user-defined defining words
2243: @cindex defining words, user-defined
2244:
2245: You can create new defining words simply by wrapping defining-time code
2246: around existing defining words and putting the sequence in a colon
2247: definition.
2248:
2249: @cindex @code{CREATE} ... @code{DOES>}
2250: If you want the words defined with your defining words to behave
2251: differently from words defined with standard defining words, you can
2252: write your defining word like this:
2253:
2254: @example
2255: : def-word ( "name" -- )
2256: Create @var{code1}
2257: DOES> ( ... -- ... )
2258: @var{code2} ;
2259:
2260: def-word name
2261: @end example
2262:
2263: Technically, this fragment defines a defining word @code{def-word}, and
2264: a word @code{name}; when you execute @code{name}, the address of the
2265: body of @code{name} is put on the data stack and @var{code2} is executed
2266: (the address of the body of @code{name} is the address @code{HERE}
2267: returns immediately after the @code{CREATE}).
2268:
2269: In other words, if you make the following definitions:
2270:
2271: @example
2272: : def-word1 ( "name" -- )
2273: Create @var{code1} ;
2274:
2275: : action1 ( ... -- ... )
2276: @var{code2} ;
2277:
2278: def-word name1
2279: @end example
2280:
2281: Using @code{name1 action1} is equivalent to using @code{name}.
2282:
2283: E.g., you can implement @code{Constant} in this way:
2284:
2285: @example
2286: : constant ( w "name" -- )
2287: create ,
2288: DOES> ( -- w )
2289: @@ ;
2290: @end example
2291:
2292: When you create a constant with @code{5 constant five}, first a new word
2293: @code{five} is created, then the value 5 is laid down in the body of
2294: @code{five} with @code{,}. When @code{five} is invoked, the address of
2295: the body is put on the stack, and @code{@@} retrieves the value 5.
2296:
2297: @cindex stack effect of @code{DOES>}-parts
2298: @cindex @code{DOES>}-parts, stack effect
2299: In the example above the stack comment after the @code{DOES>} specifies
2300: the stack effect of the defined words, not the stack effect of the
2301: following code (the following code expects the address of the body on
2302: the top of stack, which is not reflected in the stack comment). This is
2303: the convention that I use and recommend (it clashes a bit with using
2304: locals declarations for stack effect specification, though).
2305:
2306: @subsubsection Applications of @code{CREATE..DOES>}
2307: @cindex @code{CREATE} ... @code{DOES>}, applications
2308:
2309: You may wonder how to use this feature. Here are some usage patterns:
2310:
2311: @cindex factoring similar colon definitions
2312: When you see a sequence of code occurring several times, and you can
2313: identify a meaning, you will factor it out as a colon definition. When
2314: you see similar colon definitions, you can factor them using
2315: @code{CREATE..DOES>}. E.g., an assembler usually defines several words
2316: that look very similar:
2317: @example
2318: : ori, ( reg-target reg-source n -- )
2319: 0 asm-reg-reg-imm ;
2320: : andi, ( reg-target reg-source n -- )
2321: 1 asm-reg-reg-imm ;
2322: @end example
2323:
2324: This could be factored with:
2325: @example
2326: : reg-reg-imm ( op-code -- )
2327: create ,
2328: DOES> ( reg-target reg-source n -- )
2329: @@ asm-reg-reg-imm ;
2330:
2331: 0 reg-reg-imm ori,
2332: 1 reg-reg-imm andi,
2333: @end example
2334:
2335: @cindex currying
2336: Another view of @code{CREATE..DOES>} is to consider it as a crude way to
2337: supply a part of the parameters for a word (known as @dfn{currying} in
2338: the functional language community). E.g., @code{+} needs two
2339: parameters. Creating versions of @code{+} with one parameter fixed can
2340: be done like this:
2341: @example
2342: : curry+ ( n1 -- )
2343: create ,
2344: DOES> ( n2 -- n1+n2 )
2345: @@ + ;
2346:
2347: 3 curry+ 3+
2348: -2 curry+ 2-
2349: @end example
2350:
2351: @subsubsection The gory details of @code{CREATE..DOES>}
2352: @cindex @code{CREATE} ... @code{DOES>}, details
2353:
2354: doc-does>
2355:
2356: @cindex @code{DOES>} in a separate definition
2357: This means that you need not use @code{CREATE} and @code{DOES>} in the
2358: same definition; E.g., you can put the @code{DOES>}-part in a separate
2359: definition. This allows us to, e.g., select among different DOES>-parts:
2360: @example
2361: : does1
2362: DOES> ( ... -- ... )
2363: ... ;
2364:
2365: : does2
2366: DOES> ( ... -- ... )
2367: ... ;
2368:
2369: : def-word ( ... -- ... )
2370: create ...
2371: IF
2372: does1
2373: ELSE
2374: does2
2375: ENDIF ;
2376: @end example
2377:
2378: @cindex @code{DOES>} in interpretation state
2379: In a standard program you can apply a @code{DOES>}-part only if the last
2380: word was defined with @code{CREATE}. In Gforth, the @code{DOES>}-part
2381: will override the behaviour of the last word defined in any case. In a
2382: standard program, you can use @code{DOES>} only in a colon
2383: definition. In Gforth, you can also use it in interpretation state, in a
2384: kind of one-shot mode:
2385: @example
2386: CREATE name ( ... -- ... )
2387: @var{initialization}
2388: DOES>
2389: @var{code} ;
2390: @end example
2391: This is equivalent to the standard
2392: @example
2393: :noname
2394: DOES>
2395: @var{code} ;
2396: CREATE name EXECUTE ( ... -- ... )
2397: @var{initialization}
2398: @end example
2399:
2400: You can get the address of the body of a word with
2401:
2402: doc->body
2403:
2404: @node Supplying names, Interpretation and Compilation Semantics, User-defined Defining Words, Defining Words
2405: @subsection Supplying names for the defined words
2406: @cindex names for defined words
2407: @cindex defining words, name parameter
2408:
2409: @cindex defining words, name given in a string
2410: By default, defining words take the names for the defined words from the
2411: input stream. Sometimes you want to supply the name from a string. You
2412: can do this with
2413:
2414: doc-nextname
2415:
2416: E.g.,
2417:
2418: @example
2419: s" foo" nextname create
2420: @end example
2421: is equivalent to
2422: @example
2423: create foo
2424: @end example
2425:
2426: @cindex defining words without name
2427: Sometimes you want to define a word without a name. You can do this with
2428:
2429: doc-noname
2430:
2431: @cindex execution token of last defined word
2432: To make any use of the newly defined word, you need its execution
2433: token. You can get it with
2434:
2435: doc-lastxt
2436:
2437: E.g., you can initialize a deferred word with an anonymous colon
2438: definition:
2439: @example
2440: Defer deferred
2441: noname : ( ... -- ... )
2442: ... ;
2443: lastxt IS deferred
2444: @end example
2445:
2446: @code{lastxt} also works when the last word was not defined as
2447: @code{noname}.
2448:
2449: The standard has also recognized the need for anonymous words and
2450: provides
2451:
2452: doc-:noname
2453:
2454: This leaves the execution token for the word on the stack after the
2455: closing @code{;}. You can rewrite the last example with @code{:noname}:
2456: @example
2457: Defer deferred
2458: :noname ( ... -- ... )
2459: ... ;
2460: IS deferred
2461: @end example
2462:
2463: @node Interpretation and Compilation Semantics, , Supplying names, Defining Words
2464: @subsection Interpretation and Compilation Semantics
2465: @cindex semantics, interpretation and compilation
2466:
2467: @cindex interpretation semantics
2468: The @dfn{interpretation semantics} of a word are what the text
2469: interpreter does when it encounters the word in interpret state. It also
2470: appears in some other contexts, e.g., the execution token returned by
2471: @code{' @var{word}} identifies the interpretation semantics of
2472: @var{word} (in other words, @code{' @var{word} execute} is equivalent to
2473: interpret-state text interpretation of @code{@var{word}}).
2474:
2475: @cindex compilation semantics
2476: The @dfn{compilation semantics} of a word are what the text interpreter
2477: does when it encounters the word in compile state. It also appears in
2478: other contexts, e.g, @code{POSTPONE @var{word}} compiles@footnote{In
2479: standard terminology, ``appends to the current definition''.} the
2480: compilation semantics of @var{word}.
2481:
2482: @cindex execution semantics
2483: The standard also talks about @dfn{execution semantics}. They are used
2484: only for defining the interpretation and compilation semantics of many
2485: words. By default, the interpretation semantics of a word are to
2486: @code{execute} its execution semantics, and the compilation semantics of
2487: a word are to @code{compile,} its execution semantics.@footnote{In
2488: standard terminology: The default interpretation semantics are its
2489: execution semantics; the default compilation semantics are to append its
2490: execution semantics to the execution semantics of the current
2491: definition.}
2492:
2493: @cindex immediate words
2494: You can change the compilation semantics into @code{execute}ing the
2495: execution semantics with
2496:
2497: doc-immediate
2498:
2499: @cindex compile-only words
2500: You can remove the interpretation semantics of a word with
2501:
2502: doc-compile-only
2503: doc-restrict
2504:
2505: Note that ticking (@code{'}) compile-only words gives an error
2506: (``Interpreting a compile-only word'').
2507:
2508: Gforth also allows you to define words with arbitrary combinations of
2509: interpretation and compilation semantics.
2510:
2511: doc-interpret/compile:
2512:
2513: This feature was introduced for implementing @code{TO} and @code{S"}. I
2514: recommend that you do not define such words, as cute as they may be:
2515: they make it hard to get at both parts of the word in some contexts.
2516: E.g., assume you want to get an execution token for the compilation
2517: part. Instead, define two words, one that embodies the interpretation
2518: part, and one that embodies the compilation part.
2519:
2520: There is, however, a potentially useful application of this feature:
2521: Providing differing implementations for the default semantics. While
2522: this introduces redundancy and is therefore usually a bad idea, a
2523: performance improvement may be worth the trouble. E.g., consider the
2524: word @code{foobar}:
2525:
2526: @example
2527: : foobar
2528: foo bar ;
2529: @end example
2530:
2531: Let us assume that @code{foobar} is called so frequently that the
2532: calling overhead would take a significant amount of the run-time. We can
2533: optimize it with @code{interpret/compile:}:
2534:
2535: @example
2536: :noname
2537: foo bar ;
2538: :noname
2539: POSTPONE foo POSTPONE bar ;
2540: interpret/compile: foobar
2541: @end example
2542:
2543: This definition has the same interpretation semantics and essentially
2544: the same compilation semantics as the simple definition of
2545: @code{foobar}, but the implementation of the compilation semantics is
2546: more efficient with respect to run-time.
2547:
2548: @cindex state-smart words are a bad idea
2549: Some people try to use state-smart words to emulate the feature provided
2550: by @code{interpret/compile:} (words are state-smart if they check
2551: @code{STATE} during execution). E.g., they would try to code
2552: @code{foobar} like this:
2553:
2554: @example
2555: : foobar
2556: STATE @@
2557: IF ( compilation state )
2558: POSTPONE foo POSTPONE bar
2559: ELSE
2560: foo bar
2561: ENDIF ; immediate
2562: @end example
2563:
2564: While this works if @code{foobar} is processed only by the text
2565: interpreter, it does not work in other contexts (like @code{'} or
2566: @code{POSTPONE}). E.g., @code{' foobar} will produce an execution token
2567: for a state-smart word, not for the interpretation semantics of the
2568: original @code{foobar}; when you execute this execution token (directly
2569: with @code{EXECUTE} or indirectly through @code{COMPILE,}) in compile
2570: state, the result will not be what you expected (i.e., it will not
2571: perform @code{foo bar}). State-smart words are a bad idea. Simply don't
2572: write them!
2573:
2574: @cindex defining words with arbitrary semantics combinations
2575: It is also possible to write defining words that define words with
2576: arbitrary combinations of interpretation and compilation semantics (or,
2577: preferably, arbitrary combinations of implementations of the default
2578: semantics). In general, this looks like:
2579:
2580: @example
2581: : def-word
2582: create-interpret/compile
2583: @var{code1}
2584: interpretation>
2585: @var{code2}
2586: <interpretation
2587: compilation>
2588: @var{code3}
2589: <compilation ;
2590: @end example
2591:
2592: For a @var{word} defined with @code{def-word}, the interpretation
2593: semantics are to push the address of the body of @var{word} and perform
2594: @var{code2}, and the compilation semantics are to push the address of
2595: the body of @var{word} and perform @var{code3}. E.g., @code{constant}
2596: can also be defined like this:
2597:
2598: @example
2599: : constant ( n "name" -- )
2600: create-interpret/compile
2601: ,
2602: interpretation> ( -- n )
2603: @@
2604: <interpretation
2605: compilation> ( compilation. -- ; run-time. -- n )
2606: @@ postpone literal
2607: <compilation ;
2608: @end example
2609:
2610: doc-create-interpret/compile
2611: doc-interpretation>
2612: doc-<interpretation
2613: doc-compilation>
2614: doc-<compilation
2615:
2616: Note that words defined with @code{interpret/compile:} and
2617: @code{create-interpret/compile} have an extended header structure that
2618: differs from other words; however, unless you try to access them with
2619: plain address arithmetic, you should not notice this. Words for
2620: accessing the header structure usually know how to deal with this; e.g.,
2621: @code{' word >body} also gives you the body of a word created with
2622: @code{create-interpret/compile}.
2623:
2624: @node Tokens for Words, Wordlists, Defining Words, Words
2625: @section Tokens for Words
2626: @cindex tokens for words
2627:
2628: This chapter describes the creation and use of tokens that represent
2629: words on the stack (and in data space).
2630:
2631: Named words have interpretation and compilation semantics. Unnamed words
2632: just have execution semantics.
2633:
2634: @cindex execution token
2635: An @dfn{execution token} represents the execution semantics of an
2636: unnamed word. An execution token occupies one cell. As explained in
2637: section @ref{Supplying names}, the execution token of the last words
2638: defined can be produced with
2639:
2640: short-lastxt
2641:
2642: You can perform the semantics represented by an execution token with
2643: doc-execute
2644: You can compile the word with
2645: doc-compile,
2646:
2647: @cindex code field address
2648: @cindex CFA
2649: In Gforth, the abstract data type @emph{execution token} is implemented
2650: as CFA (code field address).
2651:
2652: The interpretation semantics of a named word are also represented by an
2653: execution token. You can get it with
2654:
2655: doc-[']
2656: doc-'
2657:
2658: For literals, you use @code{'} in interpreted code and @code{[']} in
2659: compiled code. Gforth's @code{'} and @code{[']} behave somewhat unusual
2660: by complaining about compile-only words. To get an execution token for a
2661: compiling word @var{X}, use @code{COMP' @var{X} drop} or @code{[COMP']
2662: @var{X} drop}.
2663:
2664: @cindex compilation token
2665: The compilation semantics are represented by a @dfn{compilation token}
2666: consisting of two cells: @var{w xt}. The top cell @var{xt} is an
2667: execution token. The compilation semantics represented by the
2668: compilation token can be performed with @code{execute}, which consumes
2669: the whole compilation token, with an additional stack effect determined
2670: by the represented compilation semantics.
2671:
2672: doc-[comp']
2673: doc-comp'
2674:
2675: You can compile the compilation semantics with @code{postpone,}. I.e.,
2676: @code{COMP' @var{word} POSTPONE,} is equivalent to @code{POSTPONE
2677: @var{word}}.
2678:
2679: doc-postpone,
2680:
2681: At present, the @var{w} part of a compilation token is an execution
2682: token, and the @var{xt} part represents either @code{execute} or
2683: @code{compile,}. However, don't rely on that knowledge, unless necessary;
2684: we may introduce unusual compilation tokens in the future (e.g.,
2685: compilation tokens representing the compilation semantics of literals).
2686:
2687: @cindex name token
2688: @cindex name field address
2689: @cindex NFA
2690: Named words are also represented by the @dfn{name token}. The abstract
2691: data type @emph{name token} is implemented as NFA (name field address).
2692:
2693: doc-find-name
2694: doc-name>int
2695: doc-name?int
2696: doc-name>comp
2697: doc-name>string
2698:
2699: @node Wordlists, Files, Tokens for Words, Words
2700: @section Wordlists
2701:
2702: @node Files, Blocks, Wordlists, Words
2703: @section Files
2704:
2705: @node Blocks, Other I/O, Files, Words
2706: @section Blocks
2707:
2708: @node Other I/O, Programming Tools, Blocks, Words
2709: @section Other I/O
2710:
2711: @node Programming Tools, Assembler and Code words, Other I/O, Words
2712: @section Programming Tools
2713: @cindex programming tools
2714:
2715: @menu
2716: * Debugging:: Simple and quick.
2717: * Assertions:: Making your programs self-checking.
1.2 jwilke 2718: * Singlestep debugger:: Executing your program word by word.
1.1 anton 2719: @end menu
2720:
2721: @node Debugging, Assertions, Programming Tools, Programming Tools
2722: @subsection Debugging
2723: @cindex debugging
2724:
1.2 jwilke 2725: The simple debugging aids provided in @file{debugs.fs}
1.1 anton 2726: are meant to support a different style of debugging than the
2727: tracing/stepping debuggers used in languages with long turn-around
2728: times.
2729:
2730: A much better (faster) way in fast-compiling languages is to add
2731: printing code at well-selected places, let the program run, look at
2732: the output, see where things went wrong, add more printing code, etc.,
2733: until the bug is found.
2734:
2735: The word @code{~~} is easy to insert. It just prints debugging
2736: information (by default the source location and the stack contents). It
2737: is also easy to remove (@kbd{C-x ~} in the Emacs Forth mode to
2738: query-replace them with nothing). The deferred words
2739: @code{printdebugdata} and @code{printdebugline} control the output of
2740: @code{~~}. The default source location output format works well with
2741: Emacs' compilation mode, so you can step through the program at the
2742: source level using @kbd{C-x `} (the advantage over a stepping debugger
2743: is that you can step in any direction and you know where the crash has
2744: happened or where the strange data has occurred).
2745:
2746: Note that the default actions clobber the contents of the pictured
2747: numeric output string, so you should not use @code{~~}, e.g., between
2748: @code{<#} and @code{#>}.
2749:
2750: doc-~~
2751: doc-printdebugdata
2752: doc-printdebugline
2753:
1.2 jwilke 2754: @node Assertions, Singlestep Debugger, Debugging, Programming Tools
1.1 anton 2755: @subsection Assertions
2756: @cindex assertions
2757:
2758: It is a good idea to make your programs self-checking, in particular, if
2759: you use an assumption (e.g., that a certain field of a data structure is
2760: never zero) that may become wrong during maintenance. Gforth supports
2761: assertions for this purpose. They are used like this:
2762:
2763: @example
2764: assert( @var{flag} )
2765: @end example
2766:
2767: The code between @code{assert(} and @code{)} should compute a flag, that
2768: should be true if everything is alright and false otherwise. It should
2769: not change anything else on the stack. The overall stack effect of the
2770: assertion is @code{( -- )}. E.g.
2771:
2772: @example
2773: assert( 1 1 + 2 = ) \ what we learn in school
2774: assert( dup 0<> ) \ assert that the top of stack is not zero
2775: assert( false ) \ this code should not be reached
2776: @end example
2777:
2778: The need for assertions is different at different times. During
2779: debugging, we want more checking, in production we sometimes care more
2780: for speed. Therefore, assertions can be turned off, i.e., the assertion
2781: becomes a comment. Depending on the importance of an assertion and the
2782: time it takes to check it, you may want to turn off some assertions and
2783: keep others turned on. Gforth provides several levels of assertions for
2784: this purpose:
2785:
2786: doc-assert0(
2787: doc-assert1(
2788: doc-assert2(
2789: doc-assert3(
2790: doc-assert(
2791: doc-)
2792:
2793: @code{Assert(} is the same as @code{assert1(}. The variable
2794: @code{assert-level} specifies the highest assertions that are turned
2795: on. I.e., at the default @code{assert-level} of one, @code{assert0(} and
2796: @code{assert1(} assertions perform checking, while @code{assert2(} and
2797: @code{assert3(} assertions are treated as comments.
2798:
2799: Note that the @code{assert-level} is evaluated at compile-time, not at
2800: run-time. I.e., you cannot turn assertions on or off at run-time, you
2801: have to set the @code{assert-level} appropriately before compiling a
2802: piece of code. You can compile several pieces of code at several
2803: @code{assert-level}s (e.g., a trusted library at level 1 and newly
2804: written code at level 3).
2805:
2806: doc-assert-level
2807:
2808: If an assertion fails, a message compatible with Emacs' compilation mode
2809: is produced and the execution is aborted (currently with @code{ABORT"}.
2810: If there is interest, we will introduce a special throw code. But if you
2811: intend to @code{catch} a specific condition, using @code{throw} is
2812: probably more appropriate than an assertion).
2813:
1.2 jwilke 2814: @node Singlestep Debugger, , Assertions, Programming Tools
2815: @subsection Singlestep Debugger
2816: @cindex singlestep Debugger
2817: @cindex debugging Singlestep
2818: @cindex @code{dbg}
2819: @cindex @code{BREAK:}
2820: @cindex @code{BREAK"}
2821:
2822: When a new word is created there's often the need to check whether it behaves
2823: alright or not. You can do this by typing @code{dbg badword}. This might
2824: look like:
2825: @example
2826: : badword 0 DO i . LOOP ; ok
2827: 2 dbg badword
2828: : badword
2829: Scanning code...
2830:
2831: Nesting debugger ready!
2832:
2833: 400D4738 8049BC4 0 -> [ 2 ] 00002 00000
2834: 400D4740 8049F68 DO -> [ 0 ]
2835: 400D4744 804A0C8 i -> [ 1 ] 00000
2836: 400D4748 400C5E60 . -> 0 [ 0 ]
2837: 400D474C 8049D0C LOOP -> [ 0 ]
2838: 400D4744 804A0C8 i -> [ 1 ] 00001
2839: 400D4748 400C5E60 . -> 1 [ 0 ]
2840: 400D474C 8049D0C LOOP -> [ 0 ]
2841: 400D4758 804B384 ; -> ok
2842: @end example
2843:
2844: Each line displayed is one step. You always have to hit return to execute the next
2845: word that is displayed. If you don't want to execute the next word in a
2846: whole, you have to type 'n' for @code{nest}. Here is an overview what keys
2847: are available:
2848:
2849: @table @i
2850:
1.4 ! anton 2851: @item <return>
1.2 jwilke 2852: Next; Execute the next word
2853:
2854: @item n
2855: Nest; Single step through next word
2856:
2857: @item u
2858: Unnest; Stop debugging and execute rest of word. When we got to this word
2859: with nest, continue debugging with the upper word
2860:
2861: @item d
2862: Done; Stop debugging and execute rest
2863:
2864: @item s
2865: Stopp; Abort immediately
2866:
2867: @end table
2868:
2869: Debugging large application with this mechanism is very difficult, because
2870: you have to nest very deep into the program before the interesting part
2871: begins. This takes a lot of time.
2872:
2873: To do it more directly put a @code{BREAK:} command into your source code.
2874: When program execution reaches @code{BREAK:} the single step debugger is
2875: invoked and you have all the features described above.
2876:
2877: If you have more than one part to debug it is useful to know where the
2878: program has stopped at the moment. You can do this by the
2879: @code{BREAK" string"} command. This behaves like @code{BREAK:} except that
2880: string is typed out when the ``breakpoint'' is reached.
2881:
1.1 anton 2882: @node Assembler and Code words, Threading Words, Programming Tools, Words
2883: @section Assembler and Code words
2884: @cindex assembler
2885: @cindex code words
2886:
2887: Gforth provides some words for defining primitives (words written in
2888: machine code), and for defining the the machine-code equivalent of
2889: @code{DOES>}-based defining words. However, the machine-independent
2890: nature of Gforth poses a few problems: First of all, Gforth runs on
2891: several architectures, so it can provide no standard assembler. What's
2892: worse is that the register allocation not only depends on the processor,
2893: but also on the @code{gcc} version and options used.
2894:
2895: The words that Gforth offers encapsulate some system dependences (e.g., the
2896: header structure), so a system-independent assembler may be used in
2897: Gforth. If you do not have an assembler, you can compile machine code
2898: directly with @code{,} and @code{c,}.
2899:
2900: doc-assembler
2901: doc-code
2902: doc-end-code
2903: doc-;code
2904: doc-flush-icache
2905:
2906: If @code{flush-icache} does not work correctly, @code{code} words
2907: etc. will not work (reliably), either.
2908:
2909: These words are rarely used. Therefore they reside in @code{code.fs},
2910: which is usually not loaded (except @code{flush-icache}, which is always
2911: present). You can load them with @code{require code.fs}.
2912:
2913: @cindex registers of the inner interpreter
2914: In the assembly code you will want to refer to the inner interpreter's
2915: registers (e.g., the data stack pointer) and you may want to use other
2916: registers for temporary storage. Unfortunately, the register allocation
2917: is installation-dependent.
2918:
2919: The easiest solution is to use explicit register declarations
2920: (@pxref{Explicit Reg Vars, , Variables in Specified Registers, gcc.info,
2921: GNU C Manual}) for all of the inner interpreter's registers: You have to
2922: compile Gforth with @code{-DFORCE_REG} (configure option
2923: @code{--enable-force-reg}) and the appropriate declarations must be
2924: present in the @code{machine.h} file (see @code{mips.h} for an example;
2925: you can find a full list of all declarable register symbols with
2926: @code{grep register engine.c}). If you give explicit registers to all
2927: variables that are declared at the beginning of @code{engine()}, you
2928: should be able to use the other caller-saved registers for temporary
2929: storage. Alternatively, you can use the @code{gcc} option
2930: @code{-ffixed-REG} (@pxref{Code Gen Options, , Options for Code
2931: Generation Conventions, gcc.info, GNU C Manual}) to reserve a register
2932: (however, this restriction on register allocation may slow Gforth
2933: significantly).
2934:
2935: If this solution is not viable (e.g., because @code{gcc} does not allow
2936: you to explicitly declare all the registers you need), you have to find
2937: out by looking at the code where the inner interpreter's registers
2938: reside and which registers can be used for temporary storage. You can
2939: get an assembly listing of the engine's code with @code{make engine.s}.
2940:
2941: In any case, it is good practice to abstract your assembly code from the
2942: actual register allocation. E.g., if the data stack pointer resides in
2943: register @code{$17}, create an alias for this register called @code{sp},
2944: and use that in your assembly code.
2945:
2946: @cindex code words, portable
2947: Another option for implementing normal and defining words efficiently
2948: is: adding the wanted functionality to the source of Gforth. For normal
2949: words you just have to edit @file{primitives} (@pxref{Automatic
2950: Generation}), defining words (equivalent to @code{;CODE} words, for fast
2951: defined words) may require changes in @file{engine.c}, @file{kernal.fs},
2952: @file{prims2x.fs}, and possibly @file{cross.fs}.
2953:
2954:
1.2 jwilke 2955: @node Threading Words, Including Files, Assembler and Code Words, Words
1.1 anton 2956: @section Threading Words
2957: @cindex threading words
2958:
2959: @cindex code address
2960: These words provide access to code addresses and other threading stuff
2961: in Gforth (and, possibly, other interpretive Forths). It more or less
2962: abstracts away the differences between direct and indirect threading
2963: (and, for direct threading, the machine dependences). However, at
2964: present this wordset is still incomplete. It is also pretty low-level;
2965: some day it will hopefully be made unnecessary by an internals wordset
2966: that abstracts implementation details away completely.
2967:
2968: doc->code-address
2969: doc->does-code
2970: doc-code-address!
2971: doc-does-code!
2972: doc-does-handler!
2973: doc-/does-handler
2974:
2975: The code addresses produced by various defining words are produced by
2976: the following words:
2977:
2978: doc-docol:
2979: doc-docon:
2980: doc-dovar:
2981: doc-douser:
2982: doc-dodefer:
2983: doc-dofield:
2984:
2985: You can recognize words defined by a @code{CREATE}...@code{DOES>} word
2986: with @code{>DOES-CODE}. If the word was defined in that way, the value
2987: returned is different from 0 and identifies the @code{DOES>} used by the
2988: defining word.
1.2 jwilke 2989:
2990: @node Including Files, , Threading Words, Words
2991: @section Threading Words
2992: @cindex including files
2993:
2994: @node Include and Require, Path handling, Including Files, Words
2995: @subsection Include and Requrie
2996:
2997: There a two words to include the source files more intelligently.
2998:
2999: doc-include
3000: doc-require
3001:
3002: @node Path handling, ,Require, Words
3003: @subsection Path handling
3004: @cindex path handling
3005:
3006: In larger program projects it is often neccassary to build up a structured
3007: directory tree. Standard forth programs are somewhere more central because
3008: they must be accessed from some more other programs. To achieve this it is
3009: possible to manipulate the search path in which gforth trys to find the
3010: source file.
3011:
3012: doc-fpath+
3013: doc-fpath=
3014: doc-.fpath
3015:
3016: Using fpath and require would look like:
3017:
3018: @example
3019:
3020: fpath= /usr/lib/forth/|./
3021:
3022: require timer.fs
3023:
3024: ...
3025:
3026: @end example
3027:
3028: @cindex ~+
3029: There is another nice feature which is similar to C's @code{include <...>}
3030: and @code{include "..."}. For example: You have a program seperated into
3031: several files in an subdirectory and you want to include some other files
3032: in this subdirectory from within the program. You have to tell gforth that
3033: you are now looking relative from the directory the current file comes from.
3034: You can tell this gforth by using the prefix @code{~+/} in front of the
3035: filename. It is also possible to add it to the search path.
3036:
3037: If you have the need to look for a file in the forth search path, you could
3038: use this gforth feature in your application.
3039:
3040: doc-open-fpath-file
3041:
3042: It is even possible to use your own search paths. Create a search path like
3043: this:
3044:
3045: @example
3046:
3047: Make a buffer for the path:
3048: create mypath 100 chars , \ maximum length (is checked)
3049: 0 , \ real len
3050: 100 chars allot \ space for path
3051:
3052: @end example
3053:
3054: You have the same functions for the forth search path in an generic version
3055: for different pathes.
3056:
3057: doc-path+
3058: doc-path=
3059: doc-.path
3060: doc-open-path-file
1.1 anton 3061:
3062: @node Tools, ANS conformance, Words, Top
3063: @chapter Tools
3064:
3065: @menu
3066: * ANS Report:: Report the words used, sorted by wordset.
3067: @end menu
3068:
3069: See also @ref{Emacs and Gforth}.
3070:
3071: @node ANS Report, , Tools, Tools
3072: @section @file{ans-report.fs}: Report the words used, sorted by wordset
3073: @cindex @file{ans-report.fs}
3074: @cindex report the words used in your program
3075: @cindex words used in your program
3076:
3077: If you want to label a Forth program as ANS Forth Program, you must
3078: document which wordsets the program uses; for extension wordsets, it is
3079: helpful to list the words the program requires from these wordsets
3080: (because Forth systems are allowed to provide only some words of them).
3081:
3082: The @file{ans-report.fs} tool makes it easy for you to determine which
3083: words from which wordset and which non-ANS words your application
3084: uses. You simply have to include @file{ans-report.fs} before loading the
3085: program you want to check. After loading your program, you can get the
3086: report with @code{print-ans-report}. A typical use is to run this as
3087: batch job like this:
3088: @example
3089: gforth ans-report.fs myprog.fs -e "print-ans-report bye"
3090: @end example
3091:
3092: The output looks like this (for @file{compat/control.fs}):
3093: @example
3094: The program uses the following words
3095: from CORE :
3096: : POSTPONE THEN ; immediate ?dup IF 0=
3097: from BLOCK-EXT :
3098: \
3099: from FILE :
3100: (
3101: @end example
3102:
3103: @subsection Caveats
3104:
3105: Note that @file{ans-report.fs} just checks which words are used, not whether
3106: they are used in an ANS Forth conforming way!
3107:
3108: Some words are defined in several wordsets in the
3109: standard. @file{ans-report.fs} reports them for only one of the
3110: wordsets, and not necessarily the one you expect. It depends on usage
3111: which wordset is the right one to specify. E.g., if you only use the
3112: compilation semantics of @code{S"}, it is a Core word; if you also use
3113: its interpretation semantics, it is a File word.
3114:
3115: @c ******************************************************************
3116: @node ANS conformance, Model, Tools, Top
3117: @chapter ANS conformance
3118: @cindex ANS conformance of Gforth
3119:
3120: To the best of our knowledge, Gforth is an
3121:
3122: ANS Forth System
3123: @itemize @bullet
3124: @item providing the Core Extensions word set
3125: @item providing the Block word set
3126: @item providing the Block Extensions word set
3127: @item providing the Double-Number word set
3128: @item providing the Double-Number Extensions word set
3129: @item providing the Exception word set
3130: @item providing the Exception Extensions word set
3131: @item providing the Facility word set
3132: @item providing @code{MS} and @code{TIME&DATE} from the Facility Extensions word set
3133: @item providing the File Access word set
3134: @item providing the File Access Extensions word set
3135: @item providing the Floating-Point word set
3136: @item providing the Floating-Point Extensions word set
3137: @item providing the Locals word set
3138: @item providing the Locals Extensions word set
3139: @item providing the Memory-Allocation word set
3140: @item providing the Memory-Allocation Extensions word set (that one's easy)
3141: @item providing the Programming-Tools word set
3142: @item providing @code{;CODE}, @code{AHEAD}, @code{ASSEMBLER}, @code{BYE}, @code{CODE}, @code{CS-PICK}, @code{CS-ROLL}, @code{STATE}, @code{[ELSE]}, @code{[IF]}, @code{[THEN]} from the Programming-Tools Extensions word set
3143: @item providing the Search-Order word set
3144: @item providing the Search-Order Extensions word set
3145: @item providing the String word set
3146: @item providing the String Extensions word set (another easy one)
3147: @end itemize
3148:
3149: @cindex system documentation
3150: In addition, ANS Forth systems are required to document certain
3151: implementation choices. This chapter tries to meet these
3152: requirements. In many cases it gives a way to ask the system for the
3153: information instead of providing the information directly, in
3154: particular, if the information depends on the processor, the operating
3155: system or the installation options chosen, or if they are likely to
3156: change during the maintenance of Gforth.
3157:
3158: @comment The framework for the rest has been taken from pfe.
3159:
3160: @menu
3161: * The Core Words::
3162: * The optional Block word set::
3163: * The optional Double Number word set::
3164: * The optional Exception word set::
3165: * The optional Facility word set::
3166: * The optional File-Access word set::
3167: * The optional Floating-Point word set::
3168: * The optional Locals word set::
3169: * The optional Memory-Allocation word set::
3170: * The optional Programming-Tools word set::
3171: * The optional Search-Order word set::
3172: @end menu
3173:
3174:
3175: @c =====================================================================
3176: @node The Core Words, The optional Block word set, ANS conformance, ANS conformance
3177: @comment node-name, next, previous, up
3178: @section The Core Words
3179: @c =====================================================================
3180: @cindex core words, system documentation
3181: @cindex system documentation, core words
3182:
3183: @menu
3184: * core-idef:: Implementation Defined Options
3185: * core-ambcond:: Ambiguous Conditions
3186: * core-other:: Other System Documentation
3187: @end menu
3188:
3189: @c ---------------------------------------------------------------------
3190: @node core-idef, core-ambcond, The Core Words, The Core Words
3191: @subsection Implementation Defined Options
3192: @c ---------------------------------------------------------------------
3193: @cindex core words, implementation-defined options
3194: @cindex implementation-defined options, core words
3195:
3196:
3197: @table @i
3198: @item (Cell) aligned addresses:
3199: @cindex cell-aligned addresses
3200: @cindex aligned addresses
3201: processor-dependent. Gforth's alignment words perform natural alignment
3202: (e.g., an address aligned for a datum of size 8 is divisible by
3203: 8). Unaligned accesses usually result in a @code{-23 THROW}.
3204:
3205: @item @code{EMIT} and non-graphic characters:
3206: @cindex @code{EMIT} and non-graphic characters
3207: @cindex non-graphic characters and @code{EMIT}
3208: The character is output using the C library function (actually, macro)
3209: @code{putc}.
3210:
3211: @item character editing of @code{ACCEPT} and @code{EXPECT}:
3212: @cindex character editing of @code{ACCEPT} and @code{EXPECT}
3213: @cindex editing in @code{ACCEPT} and @code{EXPECT}
3214: @cindex @code{ACCEPT}, editing
3215: @cindex @code{EXPECT}, editing
3216: This is modeled on the GNU readline library (@pxref{Readline
3217: Interaction, , Command Line Editing, readline, The GNU Readline
3218: Library}) with Emacs-like key bindings. @kbd{Tab} deviates a little by
3219: producing a full word completion every time you type it (instead of
3220: producing the common prefix of all completions).
3221:
3222: @item character set:
3223: @cindex character set
3224: The character set of your computer and display device. Gforth is
3225: 8-bit-clean (but some other component in your system may make trouble).
3226:
3227: @item Character-aligned address requirements:
3228: @cindex character-aligned address requirements
3229: installation-dependent. Currently a character is represented by a C
3230: @code{unsigned char}; in the future we might switch to @code{wchar_t}
3231: (Comments on that requested).
3232:
3233: @item character-set extensions and matching of names:
3234: @cindex character-set extensions and matching of names
3235: @cindex case sensitivity for name lookup
3236: @cindex name lookup, case sensitivity
3237: @cindex locale and case sensitivity
3238: Any character except the ASCII NUL charcter can be used in a
3239: name. Matching is case-insensitive (except in @code{TABLE}s). The
3240: matching is performed using the C function @code{strncasecmp}, whose
3241: function is probably influenced by the locale. E.g., the @code{C} locale
3242: does not know about accents and umlauts, so they are matched
3243: case-sensitively in that locale. For portability reasons it is best to
3244: write programs such that they work in the @code{C} locale. Then one can
3245: use libraries written by a Polish programmer (who might use words
3246: containing ISO Latin-2 encoded characters) and by a French programmer
3247: (ISO Latin-1) in the same program (of course, @code{WORDS} will produce
3248: funny results for some of the words (which ones, depends on the font you
3249: are using)). Also, the locale you prefer may not be available in other
3250: operating systems. Hopefully, Unicode will solve these problems one day.
3251:
3252: @item conditions under which control characters match a space delimiter:
3253: @cindex space delimiters
3254: @cindex control characters as delimiters
3255: If @code{WORD} is called with the space character as a delimiter, all
3256: white-space characters (as identified by the C macro @code{isspace()})
3257: are delimiters. @code{PARSE}, on the other hand, treats space like other
3258: delimiters. @code{PARSE-WORD} treats space like @code{WORD}, but behaves
3259: like @code{PARSE} otherwise. @code{(NAME)}, which is used by the outer
3260: interpreter (aka text interpreter) by default, treats all white-space
3261: characters as delimiters.
3262:
3263: @item format of the control flow stack:
3264: @cindex control flow stack, format
3265: The data stack is used as control flow stack. The size of a control flow
3266: stack item in cells is given by the constant @code{cs-item-size}. At the
3267: time of this writing, an item consists of a (pointer to a) locals list
3268: (third), an address in the code (second), and a tag for identifying the
3269: item (TOS). The following tags are used: @code{defstart},
3270: @code{live-orig}, @code{dead-orig}, @code{dest}, @code{do-dest},
3271: @code{scopestart}.
3272:
3273: @item conversion of digits > 35
3274: @cindex digits > 35
3275: The characters @code{[\]^_'} are the digits with the decimal value
3276: 36@minus{}41. There is no way to input many of the larger digits.
3277:
3278: @item display after input terminates in @code{ACCEPT} and @code{EXPECT}:
3279: @cindex @code{EXPECT}, display after end of input
3280: @cindex @code{ACCEPT}, display after end of input
3281: The cursor is moved to the end of the entered string. If the input is
3282: terminated using the @kbd{Return} key, a space is typed.
3283:
3284: @item exception abort sequence of @code{ABORT"}:
3285: @cindex exception abort sequence of @code{ABORT"}
3286: @cindex @code{ABORT"}, exception abort sequence
3287: The error string is stored into the variable @code{"error} and a
3288: @code{-2 throw} is performed.
3289:
3290: @item input line terminator:
3291: @cindex input line terminator
3292: @cindex line terminator on input
3293: @cindex newline charcter on input
3294: For interactive input, @kbd{C-m} (CR) and @kbd{C-j} (LF) terminate
3295: lines. One of these characters is typically produced when you type the
3296: @kbd{Enter} or @kbd{Return} key.
3297:
3298: @item maximum size of a counted string:
3299: @cindex maximum size of a counted string
3300: @cindex counted string, maximum size
3301: @code{s" /counted-string" environment? drop .}. Currently 255 characters
3302: on all ports, but this may change.
3303:
3304: @item maximum size of a parsed string:
3305: @cindex maximum size of a parsed string
3306: @cindex parsed string, maximum size
3307: Given by the constant @code{/line}. Currently 255 characters.
3308:
3309: @item maximum size of a definition name, in characters:
3310: @cindex maximum size of a definition name, in characters
3311: @cindex name, maximum length
3312: 31
3313:
3314: @item maximum string length for @code{ENVIRONMENT?}, in characters:
3315: @cindex maximum string length for @code{ENVIRONMENT?}, in characters
3316: @cindex @code{ENVIRONMENT?} string length, maximum
3317: 31
3318:
3319: @item method of selecting the user input device:
3320: @cindex user input device, method of selecting
3321: The user input device is the standard input. There is currently no way to
3322: change it from within Gforth. However, the input can typically be
3323: redirected in the command line that starts Gforth.
3324:
3325: @item method of selecting the user output device:
3326: @cindex user output device, method of selecting
3327: @code{EMIT} and @code{TYPE} output to the file-id stored in the value
3328: @code{outfile-id} (@code{stdout} by default). Gforth uses buffered
3329: output, so output on a terminal does not become visible before the next
3330: newline or buffer overflow. Output on non-terminals is invisible until
3331: the buffer overflows.
3332:
3333: @item methods of dictionary compilation:
3334: What are we expected to document here?
3335:
3336: @item number of bits in one address unit:
3337: @cindex number of bits in one address unit
3338: @cindex address unit, size in bits
3339: @code{s" address-units-bits" environment? drop .}. 8 in all current
3340: ports.
3341:
3342: @item number representation and arithmetic:
3343: @cindex number representation and arithmetic
3344: Processor-dependent. Binary two's complement on all current ports.
3345:
3346: @item ranges for integer types:
3347: @cindex ranges for integer types
3348: @cindex integer types, ranges
3349: Installation-dependent. Make environmental queries for @code{MAX-N},
3350: @code{MAX-U}, @code{MAX-D} and @code{MAX-UD}. The lower bounds for
3351: unsigned (and positive) types is 0. The lower bound for signed types on
3352: two's complement and one's complement machines machines can be computed
3353: by adding 1 to the upper bound.
3354:
3355: @item read-only data space regions:
3356: @cindex read-only data space regions
3357: @cindex data-space, read-only regions
3358: The whole Forth data space is writable.
3359:
3360: @item size of buffer at @code{WORD}:
3361: @cindex size of buffer at @code{WORD}
3362: @cindex @code{WORD} buffer size
3363: @code{PAD HERE - .}. 104 characters on 32-bit machines. The buffer is
3364: shared with the pictured numeric output string. If overwriting
3365: @code{PAD} is acceptable, it is as large as the remaining dictionary
3366: space, although only as much can be sensibly used as fits in a counted
3367: string.
3368:
3369: @item size of one cell in address units:
3370: @cindex cell size
3371: @code{1 cells .}.
3372:
3373: @item size of one character in address units:
3374: @cindex char size
3375: @code{1 chars .}. 1 on all current ports.
3376:
3377: @item size of the keyboard terminal buffer:
3378: @cindex size of the keyboard terminal buffer
3379: @cindex terminal buffer, size
3380: Varies. You can determine the size at a specific time using @code{lp@@
3381: tib - .}. It is shared with the locals stack and TIBs of files that
3382: include the current file. You can change the amount of space for TIBs
3383: and locals stack at Gforth startup with the command line option
3384: @code{-l}.
3385:
3386: @item size of the pictured numeric output buffer:
3387: @cindex size of the pictured numeric output buffer
3388: @cindex pictured numeric output buffer, size
3389: @code{PAD HERE - .}. 104 characters on 32-bit machines. The buffer is
3390: shared with @code{WORD}.
3391:
3392: @item size of the scratch area returned by @code{PAD}:
3393: @cindex size of the scratch area returned by @code{PAD}
3394: @cindex @code{PAD} size
3395: The remainder of dictionary space. @code{unused pad here - - .}.
3396:
3397: @item system case-sensitivity characteristics:
3398: @cindex case-sensitivity characteristics
3399: Dictionary searches are case insensitive (except in
3400: @code{TABLE}s). However, as explained above under @i{character-set
3401: extensions}, the matching for non-ASCII characters is determined by the
3402: locale you are using. In the default @code{C} locale all non-ASCII
3403: characters are matched case-sensitively.
3404:
3405: @item system prompt:
3406: @cindex system prompt
3407: @cindex prompt
3408: @code{ ok} in interpret state, @code{ compiled} in compile state.
3409:
3410: @item division rounding:
3411: @cindex division rounding
3412: installation dependent. @code{s" floored" environment? drop .}. We leave
3413: the choice to @code{gcc} (what to use for @code{/}) and to you (whether
3414: to use @code{fm/mod}, @code{sm/rem} or simply @code{/}).
3415:
3416: @item values of @code{STATE} when true:
3417: @cindex @code{STATE} values
3418: -1.
3419:
3420: @item values returned after arithmetic overflow:
3421: On two's complement machines, arithmetic is performed modulo
3422: 2**bits-per-cell for single arithmetic and 4**bits-per-cell for double
3423: arithmetic (with appropriate mapping for signed types). Division by zero
3424: typically results in a @code{-55 throw} (Floating-point unidentified
3425: fault), although a @code{-10 throw} (divide by zero) would be more
3426: appropriate.
3427:
3428: @item whether the current definition can be found after @t{DOES>}:
3429: @cindex @t{DOES>}, visibility of current definition
3430: No.
3431:
3432: @end table
3433:
3434: @c ---------------------------------------------------------------------
3435: @node core-ambcond, core-other, core-idef, The Core Words
3436: @subsection Ambiguous conditions
3437: @c ---------------------------------------------------------------------
3438: @cindex core words, ambiguous conditions
3439: @cindex ambiguous conditions, core words
3440:
3441: @table @i
3442:
3443: @item a name is neither a word nor a number:
3444: @cindex name not found
3445: @cindex Undefined word
3446: @code{-13 throw} (Undefined word). Actually, @code{-13 bounce}, which
3447: preserves the data and FP stack, so you don't lose more work than
3448: necessary.
3449:
3450: @item a definition name exceeds the maximum length allowed:
3451: @cindex Word name too long
3452: @code{-19 throw} (Word name too long)
3453:
3454: @item addressing a region not inside the various data spaces of the forth system:
3455: @cindex Invalid memory address
3456: The stacks, code space and name space are accessible. Machine code space is
3457: typically readable. Accessing other addresses gives results dependent on
3458: the operating system. On decent systems: @code{-9 throw} (Invalid memory
3459: address).
3460:
3461: @item argument type incompatible with parameter:
3462: @cindex Argument type mismatch
3463: This is usually not caught. Some words perform checks, e.g., the control
3464: flow words, and issue a @code{ABORT"} or @code{-12 THROW} (Argument type
3465: mismatch).
3466:
3467: @item attempting to obtain the execution token of a word with undefined execution semantics:
3468: @cindex Interpreting a compile-only word, for @code{'} etc.
3469: @cindex execution token of words with undefined execution semantics
3470: @code{-14 throw} (Interpreting a compile-only word). In some cases, you
3471: get an execution token for @code{compile-only-error} (which performs a
3472: @code{-14 throw} when executed).
3473:
3474: @item dividing by zero:
3475: @cindex dividing by zero
3476: @cindex floating point unidentified fault, integer division
3477: @cindex divide by zero
3478: typically results in a @code{-55 throw} (floating point unidentified
3479: fault), although a @code{-10 throw} (divide by zero) would be more
3480: appropriate.
3481:
3482: @item insufficient data stack or return stack space:
3483: @cindex insufficient data stack or return stack space
3484: @cindex stack overflow
3485: @cindex Address alignment exception, stack overflow
3486: @cindex Invalid memory address, stack overflow
3487: Depending on the operating system, the installation, and the invocation
3488: of Gforth, this is either checked by the memory management hardware, or
3489: it is not checked. If it is checked, you typically get a @code{-9 throw}
3490: (Invalid memory address) as soon as the overflow happens. If it is not
3491: check, overflows typically result in mysterious illegal memory accesses,
3492: producing @code{-9 throw} (Invalid memory address) or @code{-23 throw}
3493: (Address alignment exception); they might also destroy the internal data
3494: structure of @code{ALLOCATE} and friends, resulting in various errors in
3495: these words.
3496:
3497: @item insufficient space for loop control parameters:
3498: @cindex insufficient space for loop control parameters
3499: like other return stack overflows.
3500:
3501: @item insufficient space in the dictionary:
3502: @cindex insufficient space in the dictionary
3503: @cindex dictionary overflow
3504: Depending on the operating system, the installation, and the invocation
3505: of Gforth, this is either checked by the memory management hardware, or
3506: it is not checked. Similar results as stack overflows. However,
3507: typically the error appears at a different place when one inserts or
3508: removes code. Also, the @code{THROW} does not relieve the situation (it
3509: does for stack overflows).
3510:
3511: @item interpreting a word with undefined interpretation semantics:
3512: @cindex interpreting a word with undefined interpretation semantics
3513: @cindex Interpreting a compile-only word
3514: For some words, we have defined interpretation semantics. For the
3515: others: @code{-14 throw} (Interpreting a compile-only word).
3516:
3517: @item modifying the contents of the input buffer or a string literal:
3518: @cindex modifying the contents of the input buffer or a string literal
3519: These are located in writable memory and can be modified.
3520:
3521: @item overflow of the pictured numeric output string:
3522: @cindex overflow of the pictured numeric output string
3523: @cindex pictured numeric output string, overflow
3524: Not checked. Runs into the dictionary and destroys it (at least,
3525: partially).
3526:
3527: @item parsed string overflow:
3528: @cindex parsed string overflow
3529: @code{PARSE} cannot overflow. @code{WORD} does not check for overflow.
3530:
3531: @item producing a result out of range:
3532: @cindex result out of range
3533: On two's complement machines, arithmetic is performed modulo
3534: 2**bits-per-cell for single arithmetic and 4**bits-per-cell for double
3535: arithmetic (with appropriate mapping for signed types). Division by zero
3536: typically results in a @code{-55 throw} (floatingpoint unidentified
3537: fault), although a @code{-10 throw} (divide by zero) would be more
3538: appropriate. @code{convert} and @code{>number} currently overflow
3539: silently.
3540:
3541: @item reading from an empty data or return stack:
3542: @cindex stack empty
3543: @cindex stack underflow
3544: The data stack is checked by the outer (aka text) interpreter after
3545: every word executed. If it has underflowed, a @code{-4 throw} (Stack
3546: underflow) is performed. Apart from that, stacks may be checked or not,
3547: depending on operating system, installation, and invocation. The
3548: consequences of stack underflows are similar to the consequences of
3549: stack overflows. Note that even if the system uses checking (through the
3550: MMU), your program may have to underflow by a significant number of
3551: stack items to trigger the reaction (the reason for this is that the
3552: MMU, and therefore the checking, works with a page-size granularity).
3553:
3554: @item unexpected end of the input buffer, resulting in an attempt to use a zero-length string as a name:
3555: @cindex unexpected end of the input buffer
3556: @cindex zero-length string as a name
3557: @cindex Attempt to use zero-length string as a name
3558: @code{Create} and its descendants perform a @code{-16 throw} (Attempt to
3559: use zero-length string as a name). Words like @code{'} probably will not
3560: find what they search. Note that it is possible to create zero-length
3561: names with @code{nextname} (should it not?).
3562:
3563: @item @code{>IN} greater than input buffer:
3564: @cindex @code{>IN} greater than input buffer
3565: The next invocation of a parsing word returns a string with length 0.
3566:
3567: @item @code{RECURSE} appears after @code{DOES>}:
3568: @cindex @code{RECURSE} appears after @code{DOES>}
3569: Compiles a recursive call to the defining word, not to the defined word.
3570:
3571: @item argument input source different than current input source for @code{RESTORE-INPUT}:
3572: @cindex argument input source different than current input source for @code{RESTORE-INPUT}
3573: @cindex Argument type mismatch, @code{RESTORE-INPUT}
3574: @cindex @code{RESTORE-INPUT}, Argument type mismatch
3575: @code{-12 THROW}. Note that, once an input file is closed (e.g., because
3576: the end of the file was reached), its source-id may be
3577: reused. Therefore, restoring an input source specification referencing a
3578: closed file may lead to unpredictable results instead of a @code{-12
3579: THROW}.
3580:
3581: In the future, Gforth may be able to restore input source specifications
3582: from other than the current input source.
3583:
3584: @item data space containing definitions gets de-allocated:
3585: @cindex data space containing definitions gets de-allocated
3586: Deallocation with @code{allot} is not checked. This typically results in
3587: memory access faults or execution of illegal instructions.
3588:
3589: @item data space read/write with incorrect alignment:
3590: @cindex data space read/write with incorrect alignment
3591: @cindex alignment faults
3592: @cindex Address alignment exception
3593: Processor-dependent. Typically results in a @code{-23 throw} (Address
3594: alignment exception). Under Linux on a 486 or later processor with
3595: alignment turned on, incorrect alignment results in a @code{-9 throw}
3596: (Invalid memory address). There are reportedly some processors with
3597: alignment restrictions that do not report them.
3598:
3599: @item data space pointer not properly aligned, @code{,}, @code{C,}:
3600: @cindex data space pointer not properly aligned, @code{,}, @code{C,}
3601: Like other alignment errors.
3602:
3603: @item less than u+2 stack items (@code{PICK} and @code{ROLL}):
3604: Like other stack underflows.
3605:
3606: @item loop control parameters not available:
3607: @cindex loop control parameters not available
3608: Not checked. The counted loop words simply assume that the top of return
3609: stack items are loop control parameters and behave accordingly.
3610:
3611: @item most recent definition does not have a name (@code{IMMEDIATE}):
3612: @cindex most recent definition does not have a name (@code{IMMEDIATE})
3613: @cindex last word was headerless
3614: @code{abort" last word was headerless"}.
3615:
3616: @item name not defined by @code{VALUE} used by @code{TO}:
3617: @cindex name not defined by @code{VALUE} used by @code{TO}
3618: @cindex @code{TO} on non-@code{VALUE}s
3619: @cindex Invalid name argument, @code{TO}
3620: @code{-32 throw} (Invalid name argument) (unless name is a local or was
3621: defined by @code{CONSTANT}; in the latter case it just changes the constant).
3622:
3623: @item name not found (@code{'}, @code{POSTPONE}, @code{[']}, @code{[COMPILE]}):
3624: @cindex name not found (@code{'}, @code{POSTPONE}, @code{[']}, @code{[COMPILE]})
3625: @cindex Undefined word, @code{'}, @code{POSTPONE}, @code{[']}, @code{[COMPILE]}
3626: @code{-13 throw} (Undefined word)
3627:
3628: @item parameters are not of the same type (@code{DO}, @code{?DO}, @code{WITHIN}):
3629: @cindex parameters are not of the same type (@code{DO}, @code{?DO}, @code{WITHIN})
3630: Gforth behaves as if they were of the same type. I.e., you can predict
3631: the behaviour by interpreting all parameters as, e.g., signed.
3632:
3633: @item @code{POSTPONE} or @code{[COMPILE]} applied to @code{TO}:
3634: @cindex @code{POSTPONE} or @code{[COMPILE]} applied to @code{TO}
3635: Assume @code{: X POSTPONE TO ; IMMEDIATE}. @code{X} performs the
3636: compilation semantics of @code{TO}.
3637:
3638: @item String longer than a counted string returned by @code{WORD}:
3639: @cindex String longer than a counted string returned by @code{WORD}
3640: @cindex @code{WORD}, string overflow
3641: Not checked. The string will be ok, but the count will, of course,
3642: contain only the least significant bits of the length.
3643:
3644: @item u greater than or equal to the number of bits in a cell (@code{LSHIFT}, @code{RSHIFT}):
3645: @cindex @code{LSHIFT}, large shift counts
3646: @cindex @code{RSHIFT}, large shift counts
3647: Processor-dependent. Typical behaviours are returning 0 and using only
3648: the low bits of the shift count.
3649:
3650: @item word not defined via @code{CREATE}:
3651: @cindex @code{>BODY} of non-@code{CREATE}d words
3652: @code{>BODY} produces the PFA of the word no matter how it was defined.
3653:
3654: @cindex @code{DOES>} of non-@code{CREATE}d words
3655: @code{DOES>} changes the execution semantics of the last defined word no
3656: matter how it was defined. E.g., @code{CONSTANT DOES>} is equivalent to
3657: @code{CREATE , DOES>}.
3658:
3659: @item words improperly used outside @code{<#} and @code{#>}:
3660: Not checked. As usual, you can expect memory faults.
3661:
3662: @end table
3663:
3664:
3665: @c ---------------------------------------------------------------------
3666: @node core-other, , core-ambcond, The Core Words
3667: @subsection Other system documentation
3668: @c ---------------------------------------------------------------------
3669: @cindex other system documentation, core words
3670: @cindex core words, other system documentation
3671:
3672: @table @i
3673: @item nonstandard words using @code{PAD}:
3674: @cindex @code{PAD} use by nonstandard words
3675: None.
3676:
3677: @item operator's terminal facilities available:
3678: @cindex operator's terminal facilities available
3679: After processing the command line, Gforth goes into interactive mode,
3680: and you can give commands to Gforth interactively. The actual facilities
3681: available depend on how you invoke Gforth.
3682:
3683: @item program data space available:
3684: @cindex program data space available
3685: @cindex data space available
3686: @code{UNUSED .} gives the remaining dictionary space. The total
3687: dictionary space can be specified with the @code{-m} switch
3688: (@pxref{Invoking Gforth}) when Gforth starts up.
3689:
3690: @item return stack space available:
3691: @cindex return stack space available
3692: You can compute the total return stack space in cells with
3693: @code{s" RETURN-STACK-CELLS" environment? drop .}. You can specify it at
3694: startup time with the @code{-r} switch (@pxref{Invoking Gforth}).
3695:
3696: @item stack space available:
3697: @cindex stack space available
3698: You can compute the total data stack space in cells with
3699: @code{s" STACK-CELLS" environment? drop .}. You can specify it at
3700: startup time with the @code{-d} switch (@pxref{Invoking Gforth}).
3701:
3702: @item system dictionary space required, in address units:
3703: @cindex system dictionary space required, in address units
3704: Type @code{here forthstart - .} after startup. At the time of this
3705: writing, this gives 80080 (bytes) on a 32-bit system.
3706: @end table
3707:
3708:
3709: @c =====================================================================
3710: @node The optional Block word set, The optional Double Number word set, The Core Words, ANS conformance
3711: @section The optional Block word set
3712: @c =====================================================================
3713: @cindex system documentation, block words
3714: @cindex block words, system documentation
3715:
3716: @menu
3717: * block-idef:: Implementation Defined Options
3718: * block-ambcond:: Ambiguous Conditions
3719: * block-other:: Other System Documentation
3720: @end menu
3721:
3722:
3723: @c ---------------------------------------------------------------------
3724: @node block-idef, block-ambcond, The optional Block word set, The optional Block word set
3725: @subsection Implementation Defined Options
3726: @c ---------------------------------------------------------------------
3727: @cindex implementation-defined options, block words
3728: @cindex block words, implementation-defined options
3729:
3730: @table @i
3731: @item the format for display by @code{LIST}:
3732: @cindex @code{LIST} display format
3733: First the screen number is displayed, then 16 lines of 64 characters,
3734: each line preceded by the line number.
3735:
3736: @item the length of a line affected by @code{\}:
3737: @cindex length of a line affected by @code{\}
3738: @cindex @code{\}, line length in blocks
3739: 64 characters.
3740: @end table
3741:
3742:
3743: @c ---------------------------------------------------------------------
3744: @node block-ambcond, block-other, block-idef, The optional Block word set
3745: @subsection Ambiguous conditions
3746: @c ---------------------------------------------------------------------
3747: @cindex block words, ambiguous conditions
3748: @cindex ambiguous conditions, block words
3749:
3750: @table @i
3751: @item correct block read was not possible:
3752: @cindex block read not possible
3753: Typically results in a @code{throw} of some OS-derived value (between
3754: -512 and -2048). If the blocks file was just not long enough, blanks are
3755: supplied for the missing portion.
3756:
3757: @item I/O exception in block transfer:
3758: @cindex I/O exception in block transfer
3759: @cindex block transfer, I/O exception
3760: Typically results in a @code{throw} of some OS-derived value (between
3761: -512 and -2048).
3762:
3763: @item invalid block number:
3764: @cindex invalid block number
3765: @cindex block number invalid
3766: @code{-35 throw} (Invalid block number)
3767:
3768: @item a program directly alters the contents of @code{BLK}:
3769: @cindex @code{BLK}, altering @code{BLK}
3770: The input stream is switched to that other block, at the same
3771: position. If the storing to @code{BLK} happens when interpreting
3772: non-block input, the system will get quite confused when the block ends.
3773:
3774: @item no current block buffer for @code{UPDATE}:
3775: @cindex @code{UPDATE}, no current block buffer
3776: @code{UPDATE} has no effect.
3777:
3778: @end table
3779:
3780: @c ---------------------------------------------------------------------
3781: @node block-other, , block-ambcond, The optional Block word set
3782: @subsection Other system documentation
3783: @c ---------------------------------------------------------------------
3784: @cindex other system documentation, block words
3785: @cindex block words, other system documentation
3786:
3787: @table @i
3788: @item any restrictions a multiprogramming system places on the use of buffer addresses:
3789: No restrictions (yet).
3790:
3791: @item the number of blocks available for source and data:
3792: depends on your disk space.
3793:
3794: @end table
3795:
3796:
3797: @c =====================================================================
3798: @node The optional Double Number word set, The optional Exception word set, The optional Block word set, ANS conformance
3799: @section The optional Double Number word set
3800: @c =====================================================================
3801: @cindex system documentation, double words
3802: @cindex double words, system documentation
3803:
3804: @menu
3805: * double-ambcond:: Ambiguous Conditions
3806: @end menu
3807:
3808:
3809: @c ---------------------------------------------------------------------
3810: @node double-ambcond, , The optional Double Number word set, The optional Double Number word set
3811: @subsection Ambiguous conditions
3812: @c ---------------------------------------------------------------------
3813: @cindex double words, ambiguous conditions
3814: @cindex ambiguous conditions, double words
3815:
3816: @table @i
3817: @item @var{d} outside of range of @var{n} in @code{D>S}:
3818: @cindex @code{D>S}, @var{d} out of range of @var{n}
3819: The least significant cell of @var{d} is produced.
3820:
3821: @end table
3822:
3823:
3824: @c =====================================================================
3825: @node The optional Exception word set, The optional Facility word set, The optional Double Number word set, ANS conformance
3826: @section The optional Exception word set
3827: @c =====================================================================
3828: @cindex system documentation, exception words
3829: @cindex exception words, system documentation
3830:
3831: @menu
3832: * exception-idef:: Implementation Defined Options
3833: @end menu
3834:
3835:
3836: @c ---------------------------------------------------------------------
3837: @node exception-idef, , The optional Exception word set, The optional Exception word set
3838: @subsection Implementation Defined Options
3839: @c ---------------------------------------------------------------------
3840: @cindex implementation-defined options, exception words
3841: @cindex exception words, implementation-defined options
3842:
3843: @table @i
3844: @item @code{THROW}-codes used in the system:
3845: @cindex @code{THROW}-codes used in the system
3846: The codes -256@minus{}-511 are used for reporting signals. The mapping
3847: from OS signal numbers to throw codes is -256@minus{}@var{signal}. The
3848: codes -512@minus{}-2047 are used for OS errors (for file and memory
3849: allocation operations). The mapping from OS error numbers to throw codes
3850: is -512@minus{}@code{errno}. One side effect of this mapping is that
3851: undefined OS errors produce a message with a strange number; e.g.,
3852: @code{-1000 THROW} results in @code{Unknown error 488} on my system.
3853: @end table
3854:
3855: @c =====================================================================
3856: @node The optional Facility word set, The optional File-Access word set, The optional Exception word set, ANS conformance
3857: @section The optional Facility word set
3858: @c =====================================================================
3859: @cindex system documentation, facility words
3860: @cindex facility words, system documentation
3861:
3862: @menu
3863: * facility-idef:: Implementation Defined Options
3864: * facility-ambcond:: Ambiguous Conditions
3865: @end menu
3866:
3867:
3868: @c ---------------------------------------------------------------------
3869: @node facility-idef, facility-ambcond, The optional Facility word set, The optional Facility word set
3870: @subsection Implementation Defined Options
3871: @c ---------------------------------------------------------------------
3872: @cindex implementation-defined options, facility words
3873: @cindex facility words, implementation-defined options
3874:
3875: @table @i
3876: @item encoding of keyboard events (@code{EKEY}):
3877: @cindex keyboard events, encoding in @code{EKEY}
3878: @cindex @code{EKEY}, encoding of keyboard events
3879: Not yet implemented.
3880:
3881: @item duration of a system clock tick:
3882: @cindex duration of a system clock tick
3883: @cindex clock tick duration
3884: System dependent. With respect to @code{MS}, the time is specified in
3885: microseconds. How well the OS and the hardware implement this, is
3886: another question.
3887:
3888: @item repeatability to be expected from the execution of @code{MS}:
3889: @cindex repeatability to be expected from the execution of @code{MS}
3890: @cindex @code{MS}, repeatability to be expected
3891: System dependent. On Unix, a lot depends on load. If the system is
3892: lightly loaded, and the delay is short enough that Gforth does not get
3893: swapped out, the performance should be acceptable. Under MS-DOS and
3894: other single-tasking systems, it should be good.
3895:
3896: @end table
3897:
3898:
3899: @c ---------------------------------------------------------------------
3900: @node facility-ambcond, , facility-idef, The optional Facility word set
3901: @subsection Ambiguous conditions
3902: @c ---------------------------------------------------------------------
3903: @cindex facility words, ambiguous conditions
3904: @cindex ambiguous conditions, facility words
3905:
3906: @table @i
3907: @item @code{AT-XY} can't be performed on user output device:
3908: @cindex @code{AT-XY} can't be performed on user output device
3909: Largely terminal dependent. No range checks are done on the arguments.
3910: No errors are reported. You may see some garbage appearing, you may see
3911: simply nothing happen.
3912:
3913: @end table
3914:
3915:
3916: @c =====================================================================
3917: @node The optional File-Access word set, The optional Floating-Point word set, The optional Facility word set, ANS conformance
3918: @section The optional File-Access word set
3919: @c =====================================================================
3920: @cindex system documentation, file words
3921: @cindex file words, system documentation
3922:
3923: @menu
3924: * file-idef:: Implementation Defined Options
3925: * file-ambcond:: Ambiguous Conditions
3926: @end menu
3927:
3928: @c ---------------------------------------------------------------------
3929: @node file-idef, file-ambcond, The optional File-Access word set, The optional File-Access word set
3930: @subsection Implementation Defined Options
3931: @c ---------------------------------------------------------------------
3932: @cindex implementation-defined options, file words
3933: @cindex file words, implementation-defined options
3934:
3935: @table @i
3936: @item file access methods used:
3937: @cindex file access methods used
3938: @code{R/O}, @code{R/W} and @code{BIN} work as you would
3939: expect. @code{W/O} translates into the C file opening mode @code{w} (or
3940: @code{wb}): The file is cleared, if it exists, and created, if it does
3941: not (with both @code{open-file} and @code{create-file}). Under Unix
3942: @code{create-file} creates a file with 666 permissions modified by your
3943: umask.
3944:
3945: @item file exceptions:
3946: @cindex file exceptions
3947: The file words do not raise exceptions (except, perhaps, memory access
3948: faults when you pass illegal addresses or file-ids).
3949:
3950: @item file line terminator:
3951: @cindex file line terminator
3952: System-dependent. Gforth uses C's newline character as line
3953: terminator. What the actual character code(s) of this are is
3954: system-dependent.
3955:
3956: @item file name format:
3957: @cindex file name format
3958: System dependent. Gforth just uses the file name format of your OS.
3959:
3960: @item information returned by @code{FILE-STATUS}:
3961: @cindex @code{FILE-STATUS}, returned information
3962: @code{FILE-STATUS} returns the most powerful file access mode allowed
3963: for the file: Either @code{R/O}, @code{W/O} or @code{R/W}. If the file
3964: cannot be accessed, @code{R/O BIN} is returned. @code{BIN} is applicable
3965: along with the returned mode.
3966:
3967: @item input file state after an exception when including source:
3968: @cindex exception when including source
3969: All files that are left via the exception are closed.
3970:
3971: @item @var{ior} values and meaning:
3972: @cindex @var{ior} values and meaning
3973: The @var{ior}s returned by the file and memory allocation words are
3974: intended as throw codes. They typically are in the range
3975: -512@minus{}-2047 of OS errors. The mapping from OS error numbers to
3976: @var{ior}s is -512@minus{}@var{errno}.
3977:
3978: @item maximum depth of file input nesting:
3979: @cindex maximum depth of file input nesting
3980: @cindex file input nesting, maximum depth
3981: limited by the amount of return stack, locals/TIB stack, and the number
3982: of open files available. This should not give you troubles.
3983:
3984: @item maximum size of input line:
3985: @cindex maximum size of input line
3986: @cindex input line size, maximum
3987: @code{/line}. Currently 255.
3988:
3989: @item methods of mapping block ranges to files:
3990: @cindex mapping block ranges to files
3991: @cindex files containing blocks
3992: @cindex blocks in files
3993: By default, blocks are accessed in the file @file{blocks.fb} in the
3994: current working directory. The file can be switched with @code{USE}.
3995:
3996: @item number of string buffers provided by @code{S"}:
3997: @cindex @code{S"}, number of string buffers
3998: 1
3999:
4000: @item size of string buffer used by @code{S"}:
4001: @cindex @code{S"}, size of string buffer
4002: @code{/line}. currently 255.
4003:
4004: @end table
4005:
4006: @c ---------------------------------------------------------------------
4007: @node file-ambcond, , file-idef, The optional File-Access word set
4008: @subsection Ambiguous conditions
4009: @c ---------------------------------------------------------------------
4010: @cindex file words, ambiguous conditions
4011: @cindex ambiguous conditions, file words
4012:
4013: @table @i
4014: @item attempting to position a file outside its boundaries:
4015: @cindex @code{REPOSITION-FILE}, outside the file's boundaries
4016: @code{REPOSITION-FILE} is performed as usual: Afterwards,
4017: @code{FILE-POSITION} returns the value given to @code{REPOSITION-FILE}.
4018:
4019: @item attempting to read from file positions not yet written:
4020: @cindex reading from file positions not yet written
4021: End-of-file, i.e., zero characters are read and no error is reported.
4022:
4023: @item @var{file-id} is invalid (@code{INCLUDE-FILE}):
4024: @cindex @code{INCLUDE-FILE}, @var{file-id} is invalid
4025: An appropriate exception may be thrown, but a memory fault or other
4026: problem is more probable.
4027:
4028: @item I/O exception reading or closing @var{file-id} (@code{INCLUDE-FILE}, @code{INCLUDED}):
4029: @cindex @code{INCLUDE-FILE}, I/O exception reading or closing @var{file-id}
4030: @cindex @code{INCLUDED}, I/O exception reading or closing @var{file-id}
4031: The @var{ior} produced by the operation, that discovered the problem, is
4032: thrown.
4033:
4034: @item named file cannot be opened (@code{INCLUDED}):
4035: @cindex @code{INCLUDED}, named file cannot be opened
4036: The @var{ior} produced by @code{open-file} is thrown.
4037:
4038: @item requesting an unmapped block number:
4039: @cindex unmapped block numbers
4040: There are no unmapped legal block numbers. On some operating systems,
4041: writing a block with a large number may overflow the file system and
4042: have an error message as consequence.
4043:
4044: @item using @code{source-id} when @code{blk} is non-zero:
4045: @cindex @code{SOURCE-ID}, behaviour when @code{BLK} is non-zero
4046: @code{source-id} performs its function. Typically it will give the id of
4047: the source which loaded the block. (Better ideas?)
4048:
4049: @end table
4050:
4051:
4052: @c =====================================================================
4053: @node The optional Floating-Point word set, The optional Locals word set, The optional File-Access word set, ANS conformance
4054: @section The optional Floating-Point word set
4055: @c =====================================================================
4056: @cindex system documentation, floating-point words
4057: @cindex floating-point words, system documentation
4058:
4059: @menu
4060: * floating-idef:: Implementation Defined Options
4061: * floating-ambcond:: Ambiguous Conditions
4062: @end menu
4063:
4064:
4065: @c ---------------------------------------------------------------------
4066: @node floating-idef, floating-ambcond, The optional Floating-Point word set, The optional Floating-Point word set
4067: @subsection Implementation Defined Options
4068: @c ---------------------------------------------------------------------
4069: @cindex implementation-defined options, floating-point words
4070: @cindex floating-point words, implementation-defined options
4071:
4072: @table @i
4073: @item format and range of floating point numbers:
4074: @cindex format and range of floating point numbers
4075: @cindex floating point numbers, format and range
4076: System-dependent; the @code{double} type of C.
4077:
4078: @item results of @code{REPRESENT} when @var{float} is out of range:
4079: @cindex @code{REPRESENT}, results when @var{float} is out of range
4080: System dependent; @code{REPRESENT} is implemented using the C library
4081: function @code{ecvt()} and inherits its behaviour in this respect.
4082:
4083: @item rounding or truncation of floating-point numbers:
4084: @cindex rounding of floating-point numbers
4085: @cindex truncation of floating-point numbers
4086: @cindex floating-point numbers, rounding or truncation
4087: System dependent; the rounding behaviour is inherited from the hosting C
4088: compiler. IEEE-FP-based (i.e., most) systems by default round to
4089: nearest, and break ties by rounding to even (i.e., such that the last
4090: bit of the mantissa is 0).
4091:
4092: @item size of floating-point stack:
4093: @cindex floating-point stack size
4094: @code{s" FLOATING-STACK" environment? drop .} gives the total size of
4095: the floating-point stack (in floats). You can specify this on startup
4096: with the command-line option @code{-f} (@pxref{Invoking Gforth}).
4097:
4098: @item width of floating-point stack:
4099: @cindex floating-point stack width
4100: @code{1 floats}.
4101:
4102: @end table
4103:
4104:
4105: @c ---------------------------------------------------------------------
4106: @node floating-ambcond, , floating-idef, The optional Floating-Point word set
4107: @subsection Ambiguous conditions
4108: @c ---------------------------------------------------------------------
4109: @cindex floating-point words, ambiguous conditions
4110: @cindex ambiguous conditions, floating-point words
4111:
4112: @table @i
4113: @item @code{df@@} or @code{df!} used with an address that is not double-float aligned:
4114: @cindex @code{df@@} or @code{df!} used with an address that is not double-float aligned
4115: System-dependent. Typically results in a @code{-23 THROW} like other
4116: alignment violations.
4117:
4118: @item @code{f@@} or @code{f!} used with an address that is not float aligned:
4119: @cindex @code{f@@} used with an address that is not float aligned
4120: @cindex @code{f!} used with an address that is not float aligned
4121: System-dependent. Typically results in a @code{-23 THROW} like other
4122: alignment violations.
4123:
4124: @item floating-point result out of range:
4125: @cindex floating-point result out of range
4126: System-dependent. Can result in a @code{-55 THROW} (Floating-point
4127: unidentified fault), or can produce a special value representing, e.g.,
4128: Infinity.
4129:
4130: @item @code{sf@@} or @code{sf!} used with an address that is not single-float aligned:
4131: @cindex @code{sf@@} or @code{sf!} used with an address that is not single-float aligned
4132: System-dependent. Typically results in an alignment fault like other
4133: alignment violations.
4134:
4135: @item @code{BASE} is not decimal (@code{REPRESENT}, @code{F.}, @code{FE.}, @code{FS.}):
4136: @cindex @code{BASE} is not decimal (@code{REPRESENT}, @code{F.}, @code{FE.}, @code{FS.})
4137: The floating-point number is converted into decimal nonetheless.
4138:
4139: @item Both arguments are equal to zero (@code{FATAN2}):
4140: @cindex @code{FATAN2}, both arguments are equal to zero
4141: System-dependent. @code{FATAN2} is implemented using the C library
4142: function @code{atan2()}.
4143:
4144: @item Using @code{FTAN} on an argument @var{r1} where cos(@var{r1}) is zero:
4145: @cindex @code{FTAN} on an argument @var{r1} where cos(@var{r1}) is zero
4146: System-dependent. Anyway, typically the cos of @var{r1} will not be zero
4147: because of small errors and the tan will be a very large (or very small)
4148: but finite number.
4149:
4150: @item @var{d} cannot be presented precisely as a float in @code{D>F}:
4151: @cindex @code{D>F}, @var{d} cannot be presented precisely as a float
4152: The result is rounded to the nearest float.
4153:
4154: @item dividing by zero:
4155: @cindex dividing by zero, floating-point
4156: @cindex floating-point dividing by zero
4157: @cindex floating-point unidentified fault, FP divide-by-zero
4158: @code{-55 throw} (Floating-point unidentified fault)
4159:
4160: @item exponent too big for conversion (@code{DF!}, @code{DF@@}, @code{SF!}, @code{SF@@}):
4161: @cindex exponent too big for conversion (@code{DF!}, @code{DF@@}, @code{SF!}, @code{SF@@})
4162: System dependent. On IEEE-FP based systems the number is converted into
4163: an infinity.
4164:
4165: @item @var{float}<1 (@code{FACOSH}):
4166: @cindex @code{FACOSH}, @var{float}<1
4167: @cindex floating-point unidentified fault, @code{FACOSH}
4168: @code{-55 throw} (Floating-point unidentified fault)
4169:
4170: @item @var{float}=<-1 (@code{FLNP1}):
4171: @cindex @code{FLNP1}, @var{float}=<-1
4172: @cindex floating-point unidentified fault, @code{FLNP1}
4173: @code{-55 throw} (Floating-point unidentified fault). On IEEE-FP systems
4174: negative infinity is typically produced for @var{float}=-1.
4175:
4176: @item @var{float}=<0 (@code{FLN}, @code{FLOG}):
4177: @cindex @code{FLN}, @var{float}=<0
4178: @cindex @code{FLOG}, @var{float}=<0
4179: @cindex floating-point unidentified fault, @code{FLN} or @code{FLOG}
4180: @code{-55 throw} (Floating-point unidentified fault). On IEEE-FP systems
4181: negative infinity is typically produced for @var{float}=0.
4182:
4183: @item @var{float}<0 (@code{FASINH}, @code{FSQRT}):
4184: @cindex @code{FASINH}, @var{float}<0
4185: @cindex @code{FSQRT}, @var{float}<0
4186: @cindex floating-point unidentified fault, @code{FASINH} or @code{FSQRT}
4187: @code{-55 throw} (Floating-point unidentified fault). @code{fasinh}
4188: produces values for these inputs on my Linux box (Bug in the C library?)
4189:
4190: @item |@var{float}|>1 (@code{FACOS}, @code{FASIN}, @code{FATANH}):
4191: @cindex @code{FACOS}, |@var{float}|>1
4192: @cindex @code{FASIN}, |@var{float}|>1
4193: @cindex @code{FATANH}, |@var{float}|>1
4194: @cindex floating-point unidentified fault, @code{FACOS}, @code{FASIN} or @code{FATANH}
4195: @code{-55 throw} (Floating-point unidentified fault).
4196:
4197: @item integer part of float cannot be represented by @var{d} in @code{F>D}:
4198: @cindex @code{F>D}, integer part of float cannot be represented by @var{d}
4199: @cindex floating-point unidentified fault, @code{F>D}
4200: @code{-55 throw} (Floating-point unidentified fault).
4201:
4202: @item string larger than pictured numeric output area (@code{f.}, @code{fe.}, @code{fs.}):
4203: @cindex string larger than pictured numeric output area (@code{f.}, @code{fe.}, @code{fs.})
4204: This does not happen.
4205: @end table
4206:
4207: @c =====================================================================
4208: @node The optional Locals word set, The optional Memory-Allocation word set, The optional Floating-Point word set, ANS conformance
4209: @section The optional Locals word set
4210: @c =====================================================================
4211: @cindex system documentation, locals words
4212: @cindex locals words, system documentation
4213:
4214: @menu
4215: * locals-idef:: Implementation Defined Options
4216: * locals-ambcond:: Ambiguous Conditions
4217: @end menu
4218:
4219:
4220: @c ---------------------------------------------------------------------
4221: @node locals-idef, locals-ambcond, The optional Locals word set, The optional Locals word set
4222: @subsection Implementation Defined Options
4223: @c ---------------------------------------------------------------------
4224: @cindex implementation-defined options, locals words
4225: @cindex locals words, implementation-defined options
4226:
4227: @table @i
4228: @item maximum number of locals in a definition:
4229: @cindex maximum number of locals in a definition
4230: @cindex locals, maximum number in a definition
4231: @code{s" #locals" environment? drop .}. Currently 15. This is a lower
4232: bound, e.g., on a 32-bit machine there can be 41 locals of up to 8
4233: characters. The number of locals in a definition is bounded by the size
4234: of locals-buffer, which contains the names of the locals.
4235:
4236: @end table
4237:
4238:
4239: @c ---------------------------------------------------------------------
4240: @node locals-ambcond, , locals-idef, The optional Locals word set
4241: @subsection Ambiguous conditions
4242: @c ---------------------------------------------------------------------
4243: @cindex locals words, ambiguous conditions
4244: @cindex ambiguous conditions, locals words
4245:
4246: @table @i
4247: @item executing a named local in interpretation state:
4248: @cindex local in interpretation state
4249: @cindex Interpreting a compile-only word, for a local
4250: Locals have no interpretation semantics. If you try to perform the
4251: interpretation semantics, you will get a @code{-14 throw} somewhere
4252: (Interpreting a compile-only word). If you perform the compilation
4253: semantics, the locals access will be compiled (irrespective of state).
4254:
4255: @item @var{name} not defined by @code{VALUE} or @code{(LOCAL)} (@code{TO}):
4256: @cindex name not defined by @code{VALUE} or @code{(LOCAL)} used by @code{TO}
4257: @cindex @code{TO} on non-@code{VALUE}s and non-locals
4258: @cindex Invalid name argument, @code{TO}
4259: @code{-32 throw} (Invalid name argument)
4260:
4261: @end table
4262:
4263:
4264: @c =====================================================================
4265: @node The optional Memory-Allocation word set, The optional Programming-Tools word set, The optional Locals word set, ANS conformance
4266: @section The optional Memory-Allocation word set
4267: @c =====================================================================
4268: @cindex system documentation, memory-allocation words
4269: @cindex memory-allocation words, system documentation
4270:
4271: @menu
4272: * memory-idef:: Implementation Defined Options
4273: @end menu
4274:
4275:
4276: @c ---------------------------------------------------------------------
4277: @node memory-idef, , The optional Memory-Allocation word set, The optional Memory-Allocation word set
4278: @subsection Implementation Defined Options
4279: @c ---------------------------------------------------------------------
4280: @cindex implementation-defined options, memory-allocation words
4281: @cindex memory-allocation words, implementation-defined options
4282:
4283: @table @i
4284: @item values and meaning of @var{ior}:
4285: @cindex @var{ior} values and meaning
4286: The @var{ior}s returned by the file and memory allocation words are
4287: intended as throw codes. They typically are in the range
4288: -512@minus{}-2047 of OS errors. The mapping from OS error numbers to
4289: @var{ior}s is -512@minus{}@var{errno}.
4290:
4291: @end table
4292:
4293: @c =====================================================================
4294: @node The optional Programming-Tools word set, The optional Search-Order word set, The optional Memory-Allocation word set, ANS conformance
4295: @section The optional Programming-Tools word set
4296: @c =====================================================================
4297: @cindex system documentation, programming-tools words
4298: @cindex programming-tools words, system documentation
4299:
4300: @menu
4301: * programming-idef:: Implementation Defined Options
4302: * programming-ambcond:: Ambiguous Conditions
4303: @end menu
4304:
4305:
4306: @c ---------------------------------------------------------------------
4307: @node programming-idef, programming-ambcond, The optional Programming-Tools word set, The optional Programming-Tools word set
4308: @subsection Implementation Defined Options
4309: @c ---------------------------------------------------------------------
4310: @cindex implementation-defined options, programming-tools words
4311: @cindex programming-tools words, implementation-defined options
4312:
4313: @table @i
4314: @item ending sequence for input following @code{;CODE} and @code{CODE}:
4315: @cindex @code{;CODE} ending sequence
4316: @cindex @code{CODE} ending sequence
4317: @code{END-CODE}
4318:
4319: @item manner of processing input following @code{;CODE} and @code{CODE}:
4320: @cindex @code{;CODE}, processing input
4321: @cindex @code{CODE}, processing input
4322: The @code{ASSEMBLER} vocabulary is pushed on the search order stack, and
4323: the input is processed by the text interpreter, (starting) in interpret
4324: state.
4325:
4326: @item search order capability for @code{EDITOR} and @code{ASSEMBLER}:
4327: @cindex @code{ASSEMBLER}, search order capability
4328: The ANS Forth search order word set.
4329:
4330: @item source and format of display by @code{SEE}:
4331: @cindex @code{SEE}, source and format of output
4332: The source for @code{see} is the intermediate code used by the inner
4333: interpreter. The current @code{see} tries to output Forth source code
4334: as well as possible.
4335:
4336: @end table
4337:
4338: @c ---------------------------------------------------------------------
4339: @node programming-ambcond, , programming-idef, The optional Programming-Tools word set
4340: @subsection Ambiguous conditions
4341: @c ---------------------------------------------------------------------
4342: @cindex programming-tools words, ambiguous conditions
4343: @cindex ambiguous conditions, programming-tools words
4344:
4345: @table @i
4346:
4347: @item deleting the compilation wordlist (@code{FORGET}):
4348: @cindex @code{FORGET}, deleting the compilation wordlist
4349: Not implemented (yet).
4350:
4351: @item fewer than @var{u}+1 items on the control flow stack (@code{CS-PICK}, @code{CS-ROLL}):
4352: @cindex @code{CS-PICK}, fewer than @var{u}+1 items on the control flow stack
4353: @cindex @code{CS-ROLL}, fewer than @var{u}+1 items on the control flow stack
4354: @cindex control-flow stack underflow
4355: This typically results in an @code{abort"} with a descriptive error
4356: message (may change into a @code{-22 throw} (Control structure mismatch)
4357: in the future). You may also get a memory access error. If you are
4358: unlucky, this ambiguous condition is not caught.
4359:
4360: @item @var{name} can't be found (@code{FORGET}):
4361: @cindex @code{FORGET}, @var{name} can't be found
4362: Not implemented (yet).
4363:
4364: @item @var{name} not defined via @code{CREATE}:
4365: @cindex @code{;CODE}, @var{name} not defined via @code{CREATE}
4366: @code{;CODE} behaves like @code{DOES>} in this respect, i.e., it changes
4367: the execution semantics of the last defined word no matter how it was
4368: defined.
4369:
4370: @item @code{POSTPONE} applied to @code{[IF]}:
4371: @cindex @code{POSTPONE} applied to @code{[IF]}
4372: @cindex @code{[IF]} and @code{POSTPONE}
4373: After defining @code{: X POSTPONE [IF] ; IMMEDIATE}. @code{X} is
4374: equivalent to @code{[IF]}.
4375:
4376: @item reaching the end of the input source before matching @code{[ELSE]} or @code{[THEN]}:
4377: @cindex @code{[IF]}, end of the input source before matching @code{[ELSE]} or @code{[THEN]}
4378: Continue in the same state of conditional compilation in the next outer
4379: input source. Currently there is no warning to the user about this.
4380:
4381: @item removing a needed definition (@code{FORGET}):
4382: @cindex @code{FORGET}, removing a needed definition
4383: Not implemented (yet).
4384:
4385: @end table
4386:
4387:
4388: @c =====================================================================
4389: @node The optional Search-Order word set, , The optional Programming-Tools word set, ANS conformance
4390: @section The optional Search-Order word set
4391: @c =====================================================================
4392: @cindex system documentation, search-order words
4393: @cindex search-order words, system documentation
4394:
4395: @menu
4396: * search-idef:: Implementation Defined Options
4397: * search-ambcond:: Ambiguous Conditions
4398: @end menu
4399:
4400:
4401: @c ---------------------------------------------------------------------
4402: @node search-idef, search-ambcond, The optional Search-Order word set, The optional Search-Order word set
4403: @subsection Implementation Defined Options
4404: @c ---------------------------------------------------------------------
4405: @cindex implementation-defined options, search-order words
4406: @cindex search-order words, implementation-defined options
4407:
4408: @table @i
4409: @item maximum number of word lists in search order:
4410: @cindex maximum number of word lists in search order
4411: @cindex search order, maximum depth
4412: @code{s" wordlists" environment? drop .}. Currently 16.
4413:
4414: @item minimum search order:
4415: @cindex minimum search order
4416: @cindex search order, minimum
4417: @code{root root}.
4418:
4419: @end table
4420:
4421: @c ---------------------------------------------------------------------
4422: @node search-ambcond, , search-idef, The optional Search-Order word set
4423: @subsection Ambiguous conditions
4424: @c ---------------------------------------------------------------------
4425: @cindex search-order words, ambiguous conditions
4426: @cindex ambiguous conditions, search-order words
4427:
4428: @table @i
4429: @item changing the compilation wordlist (during compilation):
4430: @cindex changing the compilation wordlist (during compilation)
4431: @cindex compilation wordlist, change before definition ends
4432: The word is entered into the wordlist that was the compilation wordlist
4433: at the start of the definition. Any changes to the name field (e.g.,
4434: @code{immediate}) or the code field (e.g., when executing @code{DOES>})
4435: are applied to the latest defined word (as reported by @code{last} or
4436: @code{lastxt}), if possible, irrespective of the compilation wordlist.
4437:
4438: @item search order empty (@code{previous}):
4439: @cindex @code{previous}, search order empty
4440: @cindex Vocstack empty, @code{previous}
4441: @code{abort" Vocstack empty"}.
4442:
4443: @item too many word lists in search order (@code{also}):
4444: @cindex @code{also}, too many word lists in search order
4445: @cindex Vocstack full, @code{also}
4446: @code{abort" Vocstack full"}.
4447:
4448: @end table
4449:
4450: @c ***************************************************************
4451: @node Model, Integrating Gforth, ANS conformance, Top
4452: @chapter Model
4453:
4454: This chapter has yet to be written. It will contain information, on
4455: which internal structures you can rely.
4456:
4457: @c ***************************************************************
4458: @node Integrating Gforth, Emacs and Gforth, Model, Top
4459: @chapter Integrating Gforth into C programs
4460:
4461: This is not yet implemented.
4462:
4463: Several people like to use Forth as scripting language for applications
4464: that are otherwise written in C, C++, or some other language.
4465:
4466: The Forth system ATLAST provides facilities for embedding it into
4467: applications; unfortunately it has several disadvantages: most
4468: importantly, it is not based on ANS Forth, and it is apparently dead
4469: (i.e., not developed further and not supported). The facilities
4470: provided by Gforth in this area are inspired by ATLASTs facilities, so
4471: making the switch should not be hard.
4472:
4473: We also tried to design the interface such that it can easily be
4474: implemented by other Forth systems, so that we may one day arrive at a
4475: standardized interface. Such a standard interface would allow you to
4476: replace the Forth system without having to rewrite C code.
4477:
4478: You embed the Gforth interpreter by linking with the library
4479: @code{libgforth.a} (give the compiler the option @code{-lgforth}). All
4480: global symbols in this library that belong to the interface, have the
4481: prefix @code{forth_}. (Global symbols that are used internally have the
4482: prefix @code{gforth_}).
4483:
4484: You can include the declarations of Forth types and the functions and
4485: variables of the interface with @code{#include <forth.h>}.
4486:
4487: Types.
4488:
4489: Variables.
4490:
4491: Data and FP Stack pointer. Area sizes.
4492:
4493: functions.
4494:
4495: forth_init(imagefile)
4496: forth_evaluate(string) exceptions?
4497: forth_goto(address) (or forth_execute(xt)?)
4498: forth_continue() (a corountining mechanism)
4499:
4500: Adding primitives.
4501:
4502: No checking.
4503:
4504: Signals?
4505:
4506: Accessing the Stacks
4507:
4508: @node Emacs and Gforth, Image Files, Integrating Gforth, Top
4509: @chapter Emacs and Gforth
4510: @cindex Emacs and Gforth
4511:
4512: @cindex @file{gforth.el}
4513: @cindex @file{forth.el}
4514: @cindex Rydqvist, Goran
4515: @cindex comment editing commands
4516: @cindex @code{\}, editing with Emacs
4517: @cindex debug tracer editing commands
4518: @cindex @code{~~}, removal with Emacs
4519: @cindex Forth mode in Emacs
4520: Gforth comes with @file{gforth.el}, an improved version of
4521: @file{forth.el} by Goran Rydqvist (included in the TILE package). The
4522: improvements are a better (but still not perfect) handling of
4523: indentation. I have also added comment paragraph filling (@kbd{M-q}),
4524: commenting (@kbd{C-x \}) and uncommenting (@kbd{C-u C-x \}) regions and
4525: removing debugging tracers (@kbd{C-x ~}, @pxref{Debugging}). I left the
4526: stuff I do not use alone, even though some of it only makes sense for
4527: TILE. To get a description of these features, enter Forth mode and type
4528: @kbd{C-h m}.
4529:
4530: @cindex source location of error or debugging output in Emacs
4531: @cindex error output, finding the source location in Emacs
4532: @cindex debugging output, finding the source location in Emacs
4533: In addition, Gforth supports Emacs quite well: The source code locations
4534: given in error messages, debugging output (from @code{~~}) and failed
4535: assertion messages are in the right format for Emacs' compilation mode
4536: (@pxref{Compilation, , Running Compilations under Emacs, emacs, Emacs
4537: Manual}) so the source location corresponding to an error or other
4538: message is only a few keystrokes away (@kbd{C-x `} for the next error,
4539: @kbd{C-c C-c} for the error under the cursor).
4540:
4541: @cindex @file{TAGS} file
4542: @cindex @file{etags.fs}
4543: @cindex viewing the source of a word in Emacs
4544: Also, if you @code{include} @file{etags.fs}, a new @file{TAGS} file
4545: (@pxref{Tags, , Tags Tables, emacs, Emacs Manual}) will be produced that
4546: contains the definitions of all words defined afterwards. You can then
4547: find the source for a word using @kbd{M-.}. Note that emacs can use
4548: several tags files at the same time (e.g., one for the Gforth sources
4549: and one for your program, @pxref{Select Tags Table,,Selecting a Tags
4550: Table,emacs, Emacs Manual}). The TAGS file for the preloaded words is
4551: @file{$(datadir)/gforth/$(VERSION)/TAGS} (e.g.,
4552: @file{/usr/local/share/gforth/0.2.0/TAGS}).
4553:
4554: @cindex @file{.emacs}
4555: To get all these benefits, add the following lines to your @file{.emacs}
4556: file:
4557:
4558: @example
4559: (autoload 'forth-mode "gforth.el")
4560: (setq auto-mode-alist (cons '("\\.fs\\'" . forth-mode) auto-mode-alist))
4561: @end example
4562:
4563: @node Image Files, Engine, Emacs and Gforth, Top
4564: @chapter Image Files
4565: @cindex image files
4566: @cindex @code{.fi} files
4567: @cindex precompiled Forth code
4568: @cindex dictionary in persistent form
4569: @cindex persistent form of dictionary
4570:
4571: An image file is a file containing an image of the Forth dictionary,
4572: i.e., compiled Forth code and data residing in the dictionary. By
4573: convention, we use the extension @code{.fi} for image files.
4574:
4575: @menu
4576: * Image File Background:: Why have image files?
4577: * Non-Relocatable Image Files:: don't always work.
4578: * Data-Relocatable Image Files:: are better.
4579: * Fully Relocatable Image Files:: better yet.
4580: * Stack and Dictionary Sizes:: Setting the default sizes for an image.
4581: * Running Image Files:: @code{gforth -i @var{file}} or @var{file}.
4582: * Modifying the Startup Sequence:: and turnkey applications.
4583: @end menu
4584:
4585: @node Image File Background, Non-Relocatable Image Files, Image Files, Image Files
4586: @section Image File Background
4587: @cindex image file background
4588:
4589: Our Forth system consists not only of primitives, but also of
4590: definitions written in Forth. Since the Forth compiler itself belongs to
4591: those definitions, it is not possible to start the system with the
4592: primitives and the Forth source alone. Therefore we provide the Forth
4593: code as an image file in nearly executable form. At the start of the
4594: system a C routine loads the image file into memory, optionally
4595: relocates the addresses, then sets up the memory (stacks etc.) according
4596: to information in the image file, and starts executing Forth code.
4597:
4598: The image file variants represent different compromises between the
4599: goals of making it easy to generate image files and making them
4600: portable.
4601:
4602: @cindex relocation at run-time
4603: Win32Forth 3.4 and Mitch Bradleys @code{cforth} use relocation at
4604: run-time. This avoids many of the complications discussed below (image
4605: files are data relocatable without further ado), but costs performance
4606: (one addition per memory access).
4607:
4608: @cindex relocation at load-time
4609: By contrast, our loader performs relocation at image load time. The
4610: loader also has to replace tokens standing for primitive calls with the
4611: appropriate code-field addresses (or code addresses in the case of
4612: direct threading).
4613:
4614: There are three kinds of image files, with different degrees of
4615: relocatability: non-relocatable, data-relocatable, and fully relocatable
4616: image files.
4617:
4618: @cindex image file loader
4619: @cindex relocating loader
4620: @cindex loader for image files
4621: These image file variants have several restrictions in common; they are
4622: caused by the design of the image file loader:
4623:
4624: @itemize @bullet
4625: @item
4626: There is only one segment; in particular, this means, that an image file
4627: cannot represent @code{ALLOCATE}d memory chunks (and pointers to
4628: them). And the contents of the stacks are not represented, either.
4629:
4630: @item
4631: The only kinds of relocation supported are: adding the same offset to
4632: all cells that represent data addresses; and replacing special tokens
4633: with code addresses or with pieces of machine code.
4634:
4635: If any complex computations involving addresses are performed, the
4636: results cannot be represented in the image file. Several applications that
4637: use such computations come to mind:
4638: @itemize @minus
4639: @item
4640: Hashing addresses (or data structures which contain addresses) for table
4641: lookup. If you use Gforth's @code{table}s or @code{wordlist}s for this
4642: purpose, you will have no problem, because the hash tables are
4643: recomputed automatically when the system is started. If you use your own
4644: hash tables, you will have to do something similar.
4645:
4646: @item
4647: There's a cute implementation of doubly-linked lists that uses
4648: @code{XOR}ed addresses. You could represent such lists as singly-linked
4649: in the image file, and restore the doubly-linked representation on
4650: startup.@footnote{In my opinion, though, you should think thrice before
4651: using a doubly-linked list (whatever implementation).}
4652:
4653: @item
4654: The code addresses of run-time routines like @code{docol:} cannot be
4655: represented in the image file (because their tokens would be replaced by
4656: machine code in direct threaded implementations). As a workaround,
4657: compute these addresses at run-time with @code{>code-address} from the
4658: executions tokens of appropriate words (see the definitions of
4659: @code{docol:} and friends in @file{kernel.fs}).
4660:
4661: @item
4662: On many architectures addresses are represented in machine code in some
4663: shifted or mangled form. You cannot put @code{CODE} words that contain
4664: absolute addresses in this form in a relocatable image file. Workarounds
4665: are representing the address in some relative form (e.g., relative to
4666: the CFA, which is present in some register), or loading the address from
4667: a place where it is stored in a non-mangled form.
4668: @end itemize
4669: @end itemize
4670:
4671: @node Non-Relocatable Image Files, Data-Relocatable Image Files, Image File Background, Image Files
4672: @section Non-Relocatable Image Files
4673: @cindex non-relocatable image files
4674: @cindex image files, non-relocatable
4675:
4676: These files are simple memory dumps of the dictionary. They are specific
4677: to the executable (i.e., @file{gforth} file) they were created
4678: with. What's worse, they are specific to the place on which the
4679: dictionary resided when the image was created. Now, there is no
4680: guarantee that the dictionary will reside at the same place the next
4681: time you start Gforth, so there's no guarantee that a non-relocatable
4682: image will work the next time (Gforth will complain instead of crashing,
4683: though).
4684:
4685: You can create a non-relocatable image file with
4686:
4687: doc-savesystem
4688:
4689: @node Data-Relocatable Image Files, Fully Relocatable Image Files, Non-Relocatable Image Files, Image Files
4690: @section Data-Relocatable Image Files
4691: @cindex data-relocatable image files
4692: @cindex image files, data-relocatable
4693:
4694: These files contain relocatable data addresses, but fixed code addresses
4695: (instead of tokens). They are specific to the executable (i.e.,
4696: @file{gforth} file) they were created with. For direct threading on some
4697: architectures (e.g., the i386), data-relocatable images do not work. You
4698: get a data-relocatable image, if you use @file{gforthmi} with a
4699: Gforth binary that is not doubly indirect threaded (@pxref{Fully
4700: Relocatable Image Files}).
4701:
4702: @node Fully Relocatable Image Files, Stack and Dictionary Sizes, Data-Relocatable Image Files, Image Files
4703: @section Fully Relocatable Image Files
4704: @cindex fully relocatable image files
4705: @cindex image files, fully relocatable
4706:
4707: @cindex @file{kern*.fi}, relocatability
4708: @cindex @file{gforth.fi}, relocatability
4709: These image files have relocatable data addresses, and tokens for code
4710: addresses. They can be used with different binaries (e.g., with and
4711: without debugging) on the same machine, and even across machines with
4712: the same data formats (byte order, cell size, floating point
4713: format). However, they are usually specific to the version of Gforth
4714: they were created with. The files @file{gforth.fi} and @file{kernl*.fi}
4715: are fully relocatable.
4716:
4717: There are two ways to create a fully relocatable image file:
4718:
4719: @menu
4720: * gforthmi:: The normal way
4721: * cross.fs:: The hard way
4722: @end menu
4723:
4724: @node gforthmi, cross.fs, Fully Relocatable Image Files, Fully Relocatable Image Files
4725: @subsection @file{gforthmi}
4726: @cindex @file{comp-i.fs}
4727: @cindex @file{gforthmi}
4728:
4729: You will usually use @file{gforthmi}. If you want to create an
4730: image @var{file} that contains everything you would load by invoking
4731: Gforth with @code{gforth @var{options}}, you simply say
4732: @example
4733: gforthmi @var{file} @var{options}
4734: @end example
4735:
4736: E.g., if you want to create an image @file{asm.fi} that has the file
4737: @file{asm.fs} loaded in addition to the usual stuff, you could do it
4738: like this:
4739:
4740: @example
4741: gforthmi asm.fi asm.fs
4742: @end example
4743:
4744: @file{gforthmi} works like this: It produces two non-relocatable
4745: images for different addresses and then compares them. Its output
4746: reflects this: first you see the output (if any) of the two Gforth
4747: invocations that produce the nonrelocatable image files, then you see
4748: the output of the comparing program: It displays the offset used for
4749: data addresses and the offset used for code addresses;
4750: moreover, for each cell that cannot be represented correctly in the
4751: image files, it displays a line like the following one:
4752:
4753: @example
4754: 78DC BFFFFA50 BFFFFA40
4755: @end example
4756:
4757: This means that at offset $78dc from @code{forthstart}, one input image
4758: contains $bffffa50, and the other contains $bffffa40. Since these cells
4759: cannot be represented correctly in the output image, you should examine
4760: these places in the dictionary and verify that these cells are dead
4761: (i.e., not read before they are written).
4762:
4763: @cindex @code{savesystem} during @file{gforthmi}
4764: @cindex @code{bye} during @file{gforthmi}
4765: @cindex doubly indirect threaded code
4766: @cindex environment variable @code{GFORTHD}
4767: @cindex @code{GFORTHD} environment variable
4768: @cindex @code{gforth-ditc}
4769: There are a few wrinkles: After processing the passed @var{options}, the
4770: words @code{savesystem} and @code{bye} must be visible. A special doubly
4771: indirect threaded version of the @file{gforth} executable is used for
4772: creating the nonrelocatable images; you can pass the exact filename of
4773: this executable through the environment variable @code{GFORTHD}
4774: (default: @file{gforth-ditc}); if you pass a version that is not doubly
4775: indirect threaded, you will not get a fully relocatable image, but a
4776: data-relocatable image (because there is no code address offset).
4777:
4778: @node cross.fs, , gforthmi, Fully Relocatable Image Files
4779: @subsection @file{cross.fs}
4780: @cindex @file{cross.fs}
4781: @cindex cross-compiler
4782: @cindex metacompiler
4783:
4784: You can also use @code{cross}, a batch compiler that accepts a Forth-like
4785: programming language. This @code{cross} language has to be documented
4786: yet.
4787:
4788: @cindex target compiler
4789: @code{cross} also allows you to create image files for machines with
4790: different data sizes and data formats than the one used for generating
4791: the image file. You can also use it to create an application image that
4792: does not contain a Forth compiler. These features are bought with
4793: restrictions and inconveniences in programming. E.g., addresses have to
4794: be stored in memory with special words (@code{A!}, @code{A,}, etc.) in
4795: order to make the code relocatable.
4796:
4797:
4798: @node Stack and Dictionary Sizes, Running Image Files, Fully Relocatable Image Files, Image Files
4799: @section Stack and Dictionary Sizes
4800: @cindex image file, stack and dictionary sizes
4801: @cindex dictionary size default
4802: @cindex stack size default
4803:
4804: If you invoke Gforth with a command line flag for the size
4805: (@pxref{Invoking Gforth}), the size you specify is stored in the
4806: dictionary. If you save the dictionary with @code{savesystem} or create
4807: an image with @file{gforthmi}, this size will become the default
4808: for the resulting image file. E.g., the following will create a
4809: fully relocatable version of gforth.fi with a 1MB dictionary:
4810:
4811: @example
4812: gforthmi gforth.fi -m 1M
4813: @end example
4814:
4815: In other words, if you want to set the default size for the dictionary
4816: and the stacks of an image, just invoke @file{gforthmi} with the
4817: appropriate options when creating the image.
4818:
4819: @cindex stack size, cache-friendly
4820: Note: For cache-friendly behaviour (i.e., good performance), you should
4821: make the sizes of the stacks modulo, say, 2K, somewhat different. E.g.,
4822: the default stack sizes are: data: 16k (mod 2k=0); fp: 15.5k (mod
4823: 2k=1.5k); return: 15k(mod 2k=1k); locals: 14.5k (mod 2k=0.5k).
4824:
4825: @node Running Image Files, Modifying the Startup Sequence, Stack and Dictionary Sizes, Image Files
4826: @section Running Image Files
4827: @cindex running image files
4828: @cindex invoking image files
4829: @cindex image file invocation
4830:
4831: @cindex -i, invoke image file
4832: @cindex --image file, invoke image file
4833: You can invoke Gforth with an image file @var{image} instead of the
4834: default @file{gforth.fi} with the @code{-i} flag (@pxref{Invoking Gforth}):
4835: @example
4836: gforth -i @var{image}
4837: @end example
4838:
4839: @cindex executable image file
4840: @cindex image files, executable
4841: If your operating system supports starting scripts with a line of the
4842: form @code{#! ...}, you just have to type the image file name to start
4843: Gforth with this image file (note that the file extension @code{.fi} is
4844: just a convention). I.e., to run Gforth with the image file @var{image},
4845: you can just type @var{image} instead of @code{gforth -i @var{image}}.
4846:
4847: doc-#!
4848:
4849: @node Modifying the Startup Sequence, , Running Image Files, Image Files
4850: @section Modifying the Startup Sequence
4851: @cindex startup sequence for image file
4852: @cindex image file initialization sequence
4853: @cindex initialization sequence of image file
4854:
4855: You can add your own initialization to the startup sequence through the
4856: deferred word
4857:
4858: doc-'cold
4859:
4860: @code{'cold} is invoked just before the image-specific command line
4861: processing (by default, loading files and evaluating (@code{-e}) strings)
4862: starts.
4863:
4864: A sequence for adding your initialization usually looks like this:
4865:
4866: @example
4867: :noname
4868: Defers 'cold \ do other initialization stuff (e.g., rehashing wordlists)
4869: ... \ your stuff
4870: ; IS 'cold
4871: @end example
4872:
4873: @cindex turnkey image files
4874: @cindex image files, turnkey applications
4875: You can make a turnkey image by letting @code{'cold} execute a word
4876: (your turnkey application) that never returns; instead, it exits Gforth
4877: via @code{bye} or @code{throw}.
4878:
4879: @cindex command-line arguments, access
4880: @cindex arguments on the command line, access
4881: You can access the (image-specific) command-line arguments through the
4882: variables @code{argc} and @code{argv}. @code{arg} provides conventient
4883: access to @code{argv}.
4884:
4885: doc-argc
4886: doc-argv
4887: doc-arg
4888:
4889: If @code{'cold} exits normally, Gforth processes the command-line
4890: arguments as files to be loaded and strings to be evaluated. Therefore,
4891: @code{'cold} should remove the arguments it has used in this case.
4892:
4893: @c ******************************************************************
4894: @node Engine, Bugs, Image Files, Top
4895: @chapter Engine
4896: @cindex engine
4897: @cindex virtual machine
4898:
4899: Reading this section is not necessary for programming with Gforth. It
4900: may be helpful for finding your way in the Gforth sources.
4901:
4902: The ideas in this section have also been published in the papers
4903: @cite{ANS fig/GNU/??? Forth} (in German) by Bernd Paysan, presented at
4904: the Forth-Tagung '93 and @cite{A Portable Forth Engine} by M. Anton
4905: Ertl, presented at EuroForth '93; the latter is available at
4906: @*@url{http://www.complang.tuwien.ac.at/papers/ertl93.ps.Z}.
4907:
4908: @menu
4909: * Portability::
4910: * Threading::
4911: * Primitives::
4912: * Performance::
4913: @end menu
4914:
4915: @node Portability, Threading, Engine, Engine
4916: @section Portability
4917: @cindex engine portability
4918:
4919: One of the main goals of the effort is availability across a wide range
4920: of personal machines. fig-Forth, and, to a lesser extent, F83, achieved
4921: this goal by manually coding the engine in assembly language for several
4922: then-popular processors. This approach is very labor-intensive and the
4923: results are short-lived due to progress in computer architecture.
4924:
4925: @cindex C, using C for the engine
4926: Others have avoided this problem by coding in C, e.g., Mitch Bradley
4927: (cforth), Mikael Patel (TILE) and Dirk Zoller (pfe). This approach is
4928: particularly popular for UNIX-based Forths due to the large variety of
4929: architectures of UNIX machines. Unfortunately an implementation in C
4930: does not mix well with the goals of efficiency and with using
4931: traditional techniques: Indirect or direct threading cannot be expressed
4932: in C, and switch threading, the fastest technique available in C, is
4933: significantly slower. Another problem with C is that it is very
4934: cumbersome to express double integer arithmetic.
4935:
4936: @cindex GNU C for the engine
4937: @cindex long long
4938: Fortunately, there is a portable language that does not have these
4939: limitations: GNU C, the version of C processed by the GNU C compiler
4940: (@pxref{C Extensions, , Extensions to the C Language Family, gcc.info,
4941: GNU C Manual}). Its labels as values feature (@pxref{Labels as Values, ,
4942: Labels as Values, gcc.info, GNU C Manual}) makes direct and indirect
4943: threading possible, its @code{long long} type (@pxref{Long Long, ,
4944: Double-Word Integers, gcc.info, GNU C Manual}) corresponds to Forth's
4945: double numbers@footnote{Unfortunately, long longs are not implemented
4946: properly on all machines (e.g., on alpha-osf1, long longs are only 64
4947: bits, the same size as longs (and pointers), but they should be twice as
1.4 ! anton 4948: long according to @pxref{Long Long, , Double-Word Integers, gcc.info, GNU
1.1 anton 4949: C Manual}). So, we had to implement doubles in C after all. Still, on
4950: most machines we can use long longs and achieve better performance than
4951: with the emulation package.}. GNU C is available for free on all
4952: important (and many unimportant) UNIX machines, VMS, 80386s running
4953: MS-DOS, the Amiga, and the Atari ST, so a Forth written in GNU C can run
4954: on all these machines.
4955:
4956: Writing in a portable language has the reputation of producing code that
4957: is slower than assembly. For our Forth engine we repeatedly looked at
4958: the code produced by the compiler and eliminated most compiler-induced
4959: inefficiencies by appropriate changes in the source code.
4960:
4961: @cindex explicit register declarations
4962: @cindex --enable-force-reg, configuration flag
4963: @cindex -DFORCE_REG
4964: However, register allocation cannot be portably influenced by the
4965: programmer, leading to some inefficiencies on register-starved
4966: machines. We use explicit register declarations (@pxref{Explicit Reg
4967: Vars, , Variables in Specified Registers, gcc.info, GNU C Manual}) to
4968: improve the speed on some machines. They are turned on by using the
4969: configuration flag @code{--enable-force-reg} (@code{gcc} switch
4970: @code{-DFORCE_REG}). Unfortunately, this feature not only depends on the
4971: machine, but also on the compiler version: On some machines some
4972: compiler versions produce incorrect code when certain explicit register
4973: declarations are used. So by default @code{-DFORCE_REG} is not used.
4974:
4975: @node Threading, Primitives, Portability, Engine
4976: @section Threading
4977: @cindex inner interpreter implementation
4978: @cindex threaded code implementation
4979:
4980: @cindex labels as values
4981: GNU C's labels as values extension (available since @code{gcc-2.0},
4982: @pxref{Labels as Values, , Labels as Values, gcc.info, GNU C Manual})
4983: makes it possible to take the address of @var{label} by writing
4984: @code{&&@var{label}}. This address can then be used in a statement like
4985: @code{goto *@var{address}}. I.e., @code{goto *&&x} is the same as
4986: @code{goto x}.
4987:
4988: @cindex NEXT, indirect threaded
4989: @cindex indirect threaded inner interpreter
4990: @cindex inner interpreter, indirect threaded
4991: With this feature an indirect threaded NEXT looks like:
4992: @example
4993: cfa = *ip++;
4994: ca = *cfa;
4995: goto *ca;
4996: @end example
4997: @cindex instruction pointer
4998: For those unfamiliar with the names: @code{ip} is the Forth instruction
4999: pointer; the @code{cfa} (code-field address) corresponds to ANS Forths
5000: execution token and points to the code field of the next word to be
5001: executed; The @code{ca} (code address) fetched from there points to some
5002: executable code, e.g., a primitive or the colon definition handler
5003: @code{docol}.
5004:
5005: @cindex NEXT, direct threaded
5006: @cindex direct threaded inner interpreter
5007: @cindex inner interpreter, direct threaded
5008: Direct threading is even simpler:
5009: @example
5010: ca = *ip++;
5011: goto *ca;
5012: @end example
5013:
5014: Of course we have packaged the whole thing neatly in macros called
5015: @code{NEXT} and @code{NEXT1} (the part of NEXT after fetching the cfa).
5016:
5017: @menu
5018: * Scheduling::
5019: * Direct or Indirect Threaded?::
5020: * DOES>::
5021: @end menu
5022:
5023: @node Scheduling, Direct or Indirect Threaded?, Threading, Threading
5024: @subsection Scheduling
5025: @cindex inner interpreter optimization
5026:
5027: There is a little complication: Pipelined and superscalar processors,
5028: i.e., RISC and some modern CISC machines can process independent
5029: instructions while waiting for the results of an instruction. The
5030: compiler usually reorders (schedules) the instructions in a way that
5031: achieves good usage of these delay slots. However, on our first tries
5032: the compiler did not do well on scheduling primitives. E.g., for
5033: @code{+} implemented as
5034: @example
5035: n=sp[0]+sp[1];
5036: sp++;
5037: sp[0]=n;
5038: NEXT;
5039: @end example
5040: the NEXT comes strictly after the other code, i.e., there is nearly no
5041: scheduling. After a little thought the problem becomes clear: The
5042: compiler cannot know that sp and ip point to different addresses (and
5043: the version of @code{gcc} we used would not know it even if it was
5044: possible), so it could not move the load of the cfa above the store to
5045: the TOS. Indeed the pointers could be the same, if code on or very near
5046: the top of stack were executed. In the interest of speed we chose to
5047: forbid this probably unused ``feature'' and helped the compiler in
5048: scheduling: NEXT is divided into the loading part (@code{NEXT_P1}) and
5049: the goto part (@code{NEXT_P2}). @code{+} now looks like:
5050: @example
5051: n=sp[0]+sp[1];
5052: sp++;
5053: NEXT_P1;
5054: sp[0]=n;
5055: NEXT_P2;
5056: @end example
5057: This can be scheduled optimally by the compiler.
5058:
5059: This division can be turned off with the switch @code{-DCISC_NEXT}. This
5060: switch is on by default on machines that do not profit from scheduling
5061: (e.g., the 80386), in order to preserve registers.
5062:
5063: @node Direct or Indirect Threaded?, DOES>, Scheduling, Threading
5064: @subsection Direct or Indirect Threaded?
5065: @cindex threading, direct or indirect?
5066:
5067: @cindex -DDIRECT_THREADED
5068: Both! After packaging the nasty details in macro definitions we
5069: realized that we could switch between direct and indirect threading by
5070: simply setting a compilation flag (@code{-DDIRECT_THREADED}) and
5071: defining a few machine-specific macros for the direct-threading case.
5072: On the Forth level we also offer access words that hide the
5073: differences between the threading methods (@pxref{Threading Words}).
5074:
5075: Indirect threading is implemented completely machine-independently.
5076: Direct threading needs routines for creating jumps to the executable
5077: code (e.g. to docol or dodoes). These routines are inherently
5078: machine-dependent, but they do not amount to many source lines. I.e.,
5079: even porting direct threading to a new machine is a small effort.
5080:
5081: @cindex --enable-indirect-threaded, configuration flag
5082: @cindex --enable-direct-threaded, configuration flag
5083: The default threading method is machine-dependent. You can enforce a
5084: specific threading method when building Gforth with the configuration
5085: flag @code{--enable-direct-threaded} or
5086: @code{--enable-indirect-threaded}. Note that direct threading is not
5087: supported on all machines.
5088:
5089: @node DOES>, , Direct or Indirect Threaded?, Threading
5090: @subsection DOES>
5091: @cindex @code{DOES>} implementation
5092:
5093: @cindex dodoes routine
5094: @cindex DOES-code
5095: One of the most complex parts of a Forth engine is @code{dodoes}, i.e.,
5096: the chunk of code executed by every word defined by a
5097: @code{CREATE}...@code{DOES>} pair. The main problem here is: How to find
5098: the Forth code to be executed, i.e. the code after the
5099: @code{DOES>} (the DOES-code)? There are two solutions:
5100:
5101: In fig-Forth the code field points directly to the dodoes and the
5102: DOES-code address is stored in the cell after the code address (i.e. at
5103: @code{@var{cfa} cell+}). It may seem that this solution is illegal in
5104: the Forth-79 and all later standards, because in fig-Forth this address
5105: lies in the body (which is illegal in these standards). However, by
5106: making the code field larger for all words this solution becomes legal
5107: again. We use this approach for the indirect threaded version and for
5108: direct threading on some machines. Leaving a cell unused in most words
5109: is a bit wasteful, but on the machines we are targeting this is hardly a
5110: problem. The other reason for having a code field size of two cells is
5111: to avoid having different image files for direct and indirect threaded
5112: systems (direct threaded systems require two-cell code fields on many
5113: machines).
5114:
5115: @cindex DOES-handler
5116: The other approach is that the code field points or jumps to the cell
5117: after @code{DOES}. In this variant there is a jump to @code{dodoes} at
5118: this address (the DOES-handler). @code{dodoes} can then get the
5119: DOES-code address by computing the code address, i.e., the address of
5120: the jump to dodoes, and add the length of that jump field. A variant of
5121: this is to have a call to @code{dodoes} after the @code{DOES>}; then the
5122: return address (which can be found in the return register on RISCs) is
5123: the DOES-code address. Since the two cells available in the code field
5124: are used up by the jump to the code address in direct threading on many
5125: architectures, we use this approach for direct threading on these
5126: architectures. We did not want to add another cell to the code field.
5127:
5128: @node Primitives, Performance, Threading, Engine
5129: @section Primitives
5130: @cindex primitives, implementation
5131: @cindex virtual machine instructions, implementation
5132:
5133: @menu
5134: * Automatic Generation::
5135: * TOS Optimization::
5136: * Produced code::
5137: @end menu
5138:
5139: @node Automatic Generation, TOS Optimization, Primitives, Primitives
5140: @subsection Automatic Generation
5141: @cindex primitives, automatic generation
5142:
5143: @cindex @file{prims2x.fs}
5144: Since the primitives are implemented in a portable language, there is no
5145: longer any need to minimize the number of primitives. On the contrary,
5146: having many primitives has an advantage: speed. In order to reduce the
5147: number of errors in primitives and to make programming them easier, we
5148: provide a tool, the primitive generator (@file{prims2x.fs}), that
5149: automatically generates most (and sometimes all) of the C code for a
5150: primitive from the stack effect notation. The source for a primitive
5151: has the following form:
5152:
5153: @cindex primitive source format
5154: @format
5155: @var{Forth-name} @var{stack-effect} @var{category} [@var{pronounc.}]
5156: [@code{""}@var{glossary entry}@code{""}]
5157: @var{C code}
5158: [@code{:}
5159: @var{Forth code}]
5160: @end format
5161:
5162: The items in brackets are optional. The category and glossary fields
5163: are there for generating the documentation, the Forth code is there
5164: for manual implementations on machines without GNU C. E.g., the source
5165: for the primitive @code{+} is:
5166: @example
5167: + n1 n2 -- n core plus
5168: n = n1+n2;
5169: @end example
5170:
5171: This looks like a specification, but in fact @code{n = n1+n2} is C
5172: code. Our primitive generation tool extracts a lot of information from
5173: the stack effect notations@footnote{We use a one-stack notation, even
5174: though we have separate data and floating-point stacks; The separate
5175: notation can be generated easily from the unified notation.}: The number
5176: of items popped from and pushed on the stack, their type, and by what
5177: name they are referred to in the C code. It then generates a C code
5178: prelude and postlude for each primitive. The final C code for @code{+}
5179: looks like this:
5180:
5181: @example
5182: I_plus: /* + ( n1 n2 -- n ) */ /* label, stack effect */
5183: /* */ /* documentation */
5184: @{
5185: DEF_CA /* definition of variable ca (indirect threading) */
5186: Cell n1; /* definitions of variables */
5187: Cell n2;
5188: Cell n;
5189: n1 = (Cell) sp[1]; /* input */
5190: n2 = (Cell) TOS;
5191: sp += 1; /* stack adjustment */
5192: NAME("+") /* debugging output (with -DDEBUG) */
5193: @{
5194: n = n1+n2; /* C code taken from the source */
5195: @}
5196: NEXT_P1; /* NEXT part 1 */
5197: TOS = (Cell)n; /* output */
5198: NEXT_P2; /* NEXT part 2 */
5199: @}
5200: @end example
5201:
5202: This looks long and inefficient, but the GNU C compiler optimizes quite
5203: well and produces optimal code for @code{+} on, e.g., the R3000 and the
5204: HP RISC machines: Defining the @code{n}s does not produce any code, and
5205: using them as intermediate storage also adds no cost.
5206:
5207: There are also other optimizations, that are not illustrated by this
5208: example: Assignments between simple variables are usually for free (copy
5209: propagation). If one of the stack items is not used by the primitive
5210: (e.g. in @code{drop}), the compiler eliminates the load from the stack
5211: (dead code elimination). On the other hand, there are some things that
5212: the compiler does not do, therefore they are performed by
5213: @file{prims2x.fs}: The compiler does not optimize code away that stores
5214: a stack item to the place where it just came from (e.g., @code{over}).
5215:
5216: While programming a primitive is usually easy, there are a few cases
5217: where the programmer has to take the actions of the generator into
5218: account, most notably @code{?dup}, but also words that do not (always)
5219: fall through to NEXT.
5220:
5221: @node TOS Optimization, Produced code, Automatic Generation, Primitives
5222: @subsection TOS Optimization
5223: @cindex TOS optimization for primitives
5224: @cindex primitives, keeping the TOS in a register
5225:
5226: An important optimization for stack machine emulators, e.g., Forth
5227: engines, is keeping one or more of the top stack items in
5228: registers. If a word has the stack effect @var{in1}...@var{inx} @code{--}
5229: @var{out1}...@var{outy}, keeping the top @var{n} items in registers
5230: @itemize @bullet
5231: @item
5232: is better than keeping @var{n-1} items, if @var{x>=n} and @var{y>=n},
5233: due to fewer loads from and stores to the stack.
5234: @item is slower than keeping @var{n-1} items, if @var{x<>y} and @var{x<n} and
5235: @var{y<n}, due to additional moves between registers.
5236: @end itemize
5237:
5238: @cindex -DUSE_TOS
5239: @cindex -DUSE_NO_TOS
5240: In particular, keeping one item in a register is never a disadvantage,
5241: if there are enough registers. Keeping two items in registers is a
5242: disadvantage for frequent words like @code{?branch}, constants,
5243: variables, literals and @code{i}. Therefore our generator only produces
5244: code that keeps zero or one items in registers. The generated C code
5245: covers both cases; the selection between these alternatives is made at
5246: C-compile time using the switch @code{-DUSE_TOS}. @code{TOS} in the C
5247: code for @code{+} is just a simple variable name in the one-item case,
5248: otherwise it is a macro that expands into @code{sp[0]}. Note that the
5249: GNU C compiler tries to keep simple variables like @code{TOS} in
5250: registers, and it usually succeeds, if there are enough registers.
5251:
5252: @cindex -DUSE_FTOS
5253: @cindex -DUSE_NO_FTOS
5254: The primitive generator performs the TOS optimization for the
5255: floating-point stack, too (@code{-DUSE_FTOS}). For floating-point
5256: operations the benefit of this optimization is even larger:
5257: floating-point operations take quite long on most processors, but can be
5258: performed in parallel with other operations as long as their results are
5259: not used. If the FP-TOS is kept in a register, this works. If
5260: it is kept on the stack, i.e., in memory, the store into memory has to
5261: wait for the result of the floating-point operation, lengthening the
5262: execution time of the primitive considerably.
5263:
5264: The TOS optimization makes the automatic generation of primitives a
5265: bit more complicated. Just replacing all occurrences of @code{sp[0]} by
5266: @code{TOS} is not sufficient. There are some special cases to
5267: consider:
5268: @itemize @bullet
5269: @item In the case of @code{dup ( w -- w w )} the generator must not
5270: eliminate the store to the original location of the item on the stack,
5271: if the TOS optimization is turned on.
5272: @item Primitives with stack effects of the form @code{--}
5273: @var{out1}...@var{outy} must store the TOS to the stack at the start.
5274: Likewise, primitives with the stack effect @var{in1}...@var{inx} @code{--}
5275: must load the TOS from the stack at the end. But for the null stack
5276: effect @code{--} no stores or loads should be generated.
5277: @end itemize
5278:
5279: @node Produced code, , TOS Optimization, Primitives
5280: @subsection Produced code
5281: @cindex primitives, assembly code listing
5282:
5283: @cindex @file{engine.s}
5284: To see what assembly code is produced for the primitives on your machine
5285: with your compiler and your flag settings, type @code{make engine.s} and
5286: look at the resulting file @file{engine.s}.
5287:
5288: @node Performance, , Primitives, Engine
5289: @section Performance
5290: @cindex performance of some Forth interpreters
5291: @cindex engine performance
5292: @cindex benchmarking Forth systems
5293: @cindex Gforth performance
5294:
5295: On RISCs the Gforth engine is very close to optimal; i.e., it is usually
5296: impossible to write a significantly faster engine.
5297:
5298: On register-starved machines like the 386 architecture processors
5299: improvements are possible, because @code{gcc} does not utilize the
5300: registers as well as a human, even with explicit register declarations;
5301: e.g., Bernd Beuster wrote a Forth system fragment in assembly language
5302: and hand-tuned it for the 486; this system is 1.19 times faster on the
5303: Sieve benchmark on a 486DX2/66 than Gforth compiled with
5304: @code{gcc-2.6.3} with @code{-DFORCE_REG}.
5305:
5306: @cindex Win32Forth performance
5307: @cindex NT Forth performance
5308: @cindex eforth performance
5309: @cindex ThisForth performance
5310: @cindex PFE performance
5311: @cindex TILE performance
5312: However, this potential advantage of assembly language implementations
5313: is not necessarily realized in complete Forth systems: We compared
5314: Gforth (direct threaded, compiled with @code{gcc-2.6.3} and
5315: @code{-DFORCE_REG}) with Win32Forth 1.2093, LMI's NT Forth (Beta, May
5316: 1994) and Eforth (with and without peephole (aka pinhole) optimization
5317: of the threaded code); all these systems were written in assembly
5318: language. We also compared Gforth with three systems written in C:
5319: PFE-0.9.14 (compiled with @code{gcc-2.6.3} with the default
5320: configuration for Linux: @code{-O2 -fomit-frame-pointer -DUSE_REGS
5321: -DUNROLL_NEXT}), ThisForth Beta (compiled with gcc-2.6.3 -O3
5322: -fomit-frame-pointer; ThisForth employs peephole optimization of the
5323: threaded code) and TILE (compiled with @code{make opt}). We benchmarked
5324: Gforth, PFE, ThisForth and TILE on a 486DX2/66 under Linux. Kenneth
5325: O'Heskin kindly provided the results for Win32Forth and NT Forth on a
5326: 486DX2/66 with similar memory performance under Windows NT. Marcel
5327: Hendrix ported Eforth to Linux, then extended it to run the benchmarks,
5328: added the peephole optimizer, ran the benchmarks and reported the
5329: results.
5330:
5331: We used four small benchmarks: the ubiquitous Sieve; bubble-sorting and
5332: matrix multiplication come from the Stanford integer benchmarks and have
5333: been translated into Forth by Martin Fraeman; we used the versions
5334: included in the TILE Forth package, but with bigger data set sizes; and
5335: a recursive Fibonacci number computation for benchmarking calling
5336: performance. The following table shows the time taken for the benchmarks
5337: scaled by the time taken by Gforth (in other words, it shows the speedup
5338: factor that Gforth achieved over the other systems).
5339:
5340: @example
5341: relative Win32- NT eforth This-
5342: time Gforth Forth Forth eforth +opt PFE Forth TILE
5343: sieve 1.00 1.39 1.14 1.39 0.85 1.58 3.18 8.58
5344: bubble 1.00 1.31 1.41 1.48 0.88 1.50 3.88
5345: matmul 1.00 1.47 1.35 1.46 0.74 1.58 4.09
5346: fib 1.00 1.52 1.34 1.22 0.86 1.74 2.99 4.30
5347: @end example
5348:
5349: You may find the good performance of Gforth compared with the systems
5350: written in assembly language quite surprising. One important reason for
5351: the disappointing performance of these systems is probably that they are
5352: not written optimally for the 486 (e.g., they use the @code{lods}
5353: instruction). In addition, Win32Forth uses a comfortable, but costly
5354: method for relocating the Forth image: like @code{cforth}, it computes
5355: the actual addresses at run time, resulting in two address computations
5356: per NEXT (@pxref{Image File Background}).
5357:
5358: Only Eforth with the peephole optimizer performs comparable to
5359: Gforth. The speedups achieved with peephole optimization of threaded
5360: code are quite remarkable. Adding a peephole optimizer to Gforth should
5361: cause similar speedups.
5362:
5363: The speedup of Gforth over PFE, ThisForth and TILE can be easily
5364: explained with the self-imposed restriction of the latter systems to
5365: standard C, which makes efficient threading impossible (however, the
1.4 ! anton 5366: measured implementation of PFE uses a GNU C extension: @pxref{Global Reg
1.1 anton 5367: Vars, , Defining Global Register Variables, gcc.info, GNU C Manual}).
5368: Moreover, current C compilers have a hard time optimizing other aspects
5369: of the ThisForth and the TILE source.
5370:
5371: Note that the performance of Gforth on 386 architecture processors
5372: varies widely with the version of @code{gcc} used. E.g., @code{gcc-2.5.8}
5373: failed to allocate any of the virtual machine registers into real
5374: machine registers by itself and would not work correctly with explicit
5375: register declarations, giving a 1.3 times slower engine (on a 486DX2/66
5376: running the Sieve) than the one measured above.
5377:
5378: Note also that there have been several releases of Win32Forth since the
5379: release presented here, so the results presented here may have little
5380: predictive value for the performance of Win32Forth today.
5381:
5382: @cindex @file{Benchres}
5383: In @cite{Translating Forth to Efficient C} by M. Anton Ertl and Martin
5384: Maierhofer (presented at EuroForth '95), an indirect threaded version of
5385: Gforth is compared with Win32Forth, NT Forth, PFE, and ThisForth; that
5386: version of Gforth is 2%@minus{}8% slower on a 486 than the direct
5387: threaded version used here. The paper available at
5388: @*@url{http://www.complang.tuwien.ac.at/papers/ertl&maierhofer95.ps.gz};
5389: it also contains numbers for some native code systems. You can find a
5390: newer version of these measurements at
5391: @url{http://www.complang.tuwien.ac.at/forth/performance.html}. You can
5392: find numbers for Gforth on various machines in @file{Benchres}.
5393:
5394: @node Bugs, Origin, Engine, Top
5395: @chapter Bugs
5396: @cindex bug reporting
5397:
5398: Known bugs are described in the file BUGS in the Gforth distribution.
5399:
5400: If you find a bug, please send a bug report to
5401: @email{bug-gforth@@gnu.ai.mit.edu}. A bug report should
5402: describe the Gforth version used (it is announced at the start of an
5403: interactive Gforth session), the machine and operating system (on Unix
5404: systems you can use @code{uname -a} to produce this information), the
5405: installation options (send the @file{config.status} file), and a
5406: complete list of changes you (or your installer) have made to the Gforth
5407: sources (if any); it should contain a program (or a sequence of keyboard
5408: commands) that reproduces the bug and a description of what you think
5409: constitutes the buggy behaviour.
5410:
5411: For a thorough guide on reporting bugs read @ref{Bug Reporting, , How
5412: to Report Bugs, gcc.info, GNU C Manual}.
5413:
5414:
5415: @node Origin, Word Index, Bugs, Top
5416: @chapter Authors and Ancestors of Gforth
5417:
5418: @section Authors and Contributors
5419: @cindex authors of Gforth
5420: @cindex contributors to Gforth
5421:
5422: The Gforth project was started in mid-1992 by Bernd Paysan and Anton
5423: Ertl. The third major author was Jens Wilke. Lennart Benschop (who was
5424: one of Gforth's first users, in mid-1993) and Stuart Ramsden inspired us
5425: with their continuous feedback. Lennart Benshop contributed
5426: @file{glosgen.fs}, while Stuart Ramsden has been working on automatic
5427: support for calling C libraries. Helpful comments also came from Paul
5428: Kleinrubatscher, Christian Pirker, Dirk Zoller, Marcel Hendrix, John
5429: Wavrik, Barrie Stott and Marc de Groot.
5430:
5431: Gforth also owes a lot to the authors of the tools we used (GCC, CVS,
5432: and autoconf, among others), and to the creators of the Internet: Gforth
5433: was developed across the Internet, and its authors have not met
5434: physically yet.
5435:
5436: @section Pedigree
5437: @cindex Pedigree of Gforth
5438:
5439: Gforth descends from BigForth (1993) and fig-Forth. Gforth and PFE (by
5440: Dirk Zoller) will cross-fertilize each other. Of course, a significant
5441: part of the design of Gforth was prescribed by ANS Forth.
5442:
5443: Bernd Paysan wrote BigForth, a descendent from TurboForth, an unreleased
5444: 32 bit native code version of VolksForth for the Atari ST, written
5445: mostly by Dietrich Weineck.
5446:
5447: VolksForth descends from F83. It was written by Klaus Schleisiek, Bernd
5448: Pennemann, Georg Rehfeld and Dietrich Weineck for the C64 (called
5449: UltraForth there) in the mid-80s and ported to the Atari ST in 1986.
5450:
5451: Henry Laxen and Mike Perry wrote F83 as a model implementation of the
5452: Forth-83 standard. !! Pedigree? When?
5453:
5454: A team led by Bill Ragsdale implemented fig-Forth on many processors in
5455: 1979. Robert Selzer and Bill Ragsdale developed the original
5456: implementation of fig-Forth for the 6502 based on microForth.
5457:
5458: The principal architect of microForth was Dean Sanderson. microForth was
5459: FORTH, Inc.'s first off-the-shelf product. It was developed in 1976 for
5460: the 1802, and subsequently implemented on the 8080, the 6800 and the
5461: Z80.
5462:
5463: All earlier Forth systems were custom-made, usually by Charles Moore,
5464: who discovered (as he puts it) Forth during the late 60s. The first full
5465: Forth existed in 1971.
5466:
5467: A part of the information in this section comes from @cite{The Evolution
5468: of Forth} by Elizabeth D. Rather, Donald R. Colburn and Charles
5469: H. Moore, presented at the HOPL-II conference and preprinted in SIGPLAN
5470: Notices 28(3), 1993. You can find more historical and genealogical
5471: information about Forth there.
5472:
5473: @node Word Index, Concept Index, Origin, Top
5474: @unnumbered Word Index
5475:
5476: This index is as incomplete as the manual. Each word is listed with
5477: stack effect and wordset.
5478:
5479: @printindex fn
5480:
5481: @node Concept Index, , Word Index, Top
5482: @unnumbered Concept and Word Index
5483:
5484: This index is as incomplete as the manual. Not all entries listed are
5485: present verbatim in the text. Only the names are listed for the words
5486: here.
5487:
5488: @printindex cp
5489:
5490: @contents
5491: @bye
5492:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>