/
gforth.texi.in
17284 lines (14032 loc) · 588 KB
/
gforth.texi.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\input texinfo @c -*-texinfo-*-
@comment The source is gforth.ds, from which gforth.texi is generated
@c uncomment this if you want a smartphone PDF
@c iftex
@c internalpagesizes{150mm}{97mm}{-0.666in}{-0.95in}{0in}{0in}{160mm}{100mm}
@c contentsrightmargin=0pt
@c tableindent=0.1in
@c itemindent=0.2in
@c tolerance=700
@c defbodyindent=0.1in
@c lispnarrowing=0pt
@c end iftex
@comment TODO: nac29jan99 - a list of things to add in the next edit:
@comment 1. x-ref all ambiguous or implementation-defined features?
@comment 2. Describe the use of Auser Avariable AConstant A, etc.
@comment 3. words in miscellaneous section need a home.
@comment 4. search for TODO for other minor and major works required.
@comment 5. [rats] change all @var to @i in Forth source so that info
@comment file looks decent.
@c Not an improvement IMO - anton
@c and anyway, this should be taken up
@c with Karl Berry (the texinfo guy) - anton
@c
@c Karl Berry writes:
@c If they don't like the all-caps for @var Info output, all I can say is
@c that it's always been that way, and the usage of all-caps for
@c metavariables has a long tradition. I think it's best to just let it be
@c what it is, for the sake of consistency among manuals.
@c
@comment .. would be useful to have a word that identified all deferred words
@comment should semantics stuff in intro be moved to another section
@c POSTPONE, COMPILE, [COMPILE], LITERAL should have their own section
@comment %**start of header (This is for running Texinfo on a region.)
@setfilename gforth.info
@include version.texi
@settitle Gforth Manual
@c @syncodeindex pg cp
@macro progstyle {}
Programming style note:
@end macro
@macro assignment {}
@table @i
@item Assignment:
@end macro
@macro endassignment {}
@end table
@end macro
@comment macros for beautifying glossary entries
@macro GLOSS-START {}
@iftex
@ninerm
@end iftex
@end macro
@macro GLOSS-END {}
@iftex
@rm
@end iftex
@end macro
@comment %**end of header (This is for running Texinfo on a region.)
@copying
This manual is for Gforth (version @value{VERSION}, @value{UPDATED}),
a fast and portable implementation of the Standard Forth language. It
serves as reference manual, but it also contains an introduction to
Forth and a Forth tutorial.
Copyright @copyright{} 1995, 1996, 1997, 1998, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,2015,2016,2017 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below. A copy of the
license is included in the section entitled ``GNU Free Documentation
License.''
(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
this GNU Manual, like GNU software. Copies published by the Free
Software Foundation raise funds for GNU development.''
@end quotation
@end copying
@dircategory Software development
@direntry
* Gforth: (gforth). A fast interpreter for the Forth language.
@end direntry
@c The Texinfo manual also recommends doing this, but for Gforth it may
@c not make much sense
@c @dircategory Individual utilities
@c @direntry
@c * Gforth: (gforth)Invoking Gforth. gforth, gforth-fast, gforthmi
@c @end direntry
@titlepage
@title Gforth
@subtitle for version @value{VERSION}, @value{UPDATED}
@author Neal Crook
@author Anton Ertl
@author David Kuehling
@author Bernd Paysan
@author Jens Wilke
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@ifnottex
@node Top, Goals, (dir), (dir)
@top Gforth
@insertcopying
@menu
* Goals:: About the Gforth Project
* Gforth Environment:: Starting (and exiting) Gforth
* Tutorial:: Hands-on Forth Tutorial
* Introduction:: An introduction to Standard Forth
* Words:: Forth words available in Gforth
* Error messages:: How to interpret them
* Tools:: Programming tools
* Standard conformance:: Implementation-defined options etc.
* Standard vs Extensions:: Should I use extensions?
* Model:: The abstract machine of Gforth
* Integrating Gforth:: Forth as scripting language for applications
* Emacs and Gforth:: The Gforth Mode
* Image Files:: @code{.fi} files contain compiled code
* Engine:: The inner interpreter and the primitives
* Cross Compiler:: The Cross Compiler
* Bugs:: How to report them
* Origin:: Authors and ancestors of Gforth
* Forth-related information:: Books and places to look on the WWW
* Licenses::
* Word Index:: An item for each Forth word
* Concept Index:: A menu covering many topics
@detailmenu
--- The Detailed Node Listing ---
Gforth Environment
* Invoking Gforth:: Getting in
* Leaving Gforth:: Getting out
* Command-line editing::
* Environment variables:: that affect how Gforth starts up
* Gforth Files:: What gets installed and where
* Gforth in pipes::
* Startup speed:: When 14ms is not fast enough ...
Forth Tutorial
* Starting Gforth Tutorial::
* Syntax Tutorial::
* Crash Course Tutorial::
* Stack Tutorial::
* Arithmetics Tutorial::
* Stack Manipulation Tutorial::
* Using files for Forth code Tutorial::
* Comments Tutorial::
* Colon Definitions Tutorial::
* Decompilation Tutorial::
* Stack-Effect Comments Tutorial::
* Types Tutorial::
* Factoring Tutorial::
* Designing the stack effect Tutorial::
* Local Variables Tutorial::
* Conditional execution Tutorial::
* Flags and Comparisons Tutorial::
* General Loops Tutorial::
* Counted loops Tutorial::
* Recursion Tutorial::
* Leaving definitions or loops Tutorial::
* Return Stack Tutorial::
* Memory Tutorial::
* Characters and Strings Tutorial::
* Alignment Tutorial::
* Floating Point Tutorial::
* Files Tutorial::
* Interpretation and Compilation Semantics and Immediacy Tutorial::
* Execution Tokens Tutorial::
* Exceptions Tutorial::
* Defining Words Tutorial::
* Arrays and Records Tutorial::
* POSTPONE Tutorial::
* Literal Tutorial::
* Advanced macros Tutorial::
* Compilation Tokens Tutorial::
* Wordlists and Search Order Tutorial::
An Introduction to Standard Forth
* Introducing the Text Interpreter::
* Stacks and Postfix notation::
* Your first definition::
* How does that work?::
* Forth is written in Forth::
* Review - elements of a Forth system::
* Where to go next::
* Exercises::
Forth Words
* Notation::
* Case insensitivity::
* Comments::
* Boolean Flags::
* Arithmetic::
* Stack Manipulation::
* Memory::
* Control Structures::
* Defining Words::
* Interpretation and Compilation Semantics::
* Tokens for Words::
* Compiling words::
* The Text Interpreter::
* The Input Stream::
* Word Lists::
* Environmental Queries::
* Files::
* Blocks::
* Other I/O::
* OS command line arguments::
* Locals::
* Structures::
* Object-oriented Forth::
* Programming Tools::
* Multitasker::
* C Interface::
* Assembler and Code Words::
* Threading Words::
* Passing Commands to the OS::
* Keeping track of Time::
* Miscellaneous Words::
Arithmetic
* Single precision::
* Double precision:: Double-cell integer arithmetic
* Bitwise operations::
* Numeric comparison::
* Mixed precision:: Operations with single and double-cell integers
* Floating Point::
Stack Manipulation
* Data stack::
* Floating point stack::
* Return stack::
* Locals stack::
* Stack pointer manipulation::
Memory
* Memory model::
* Dictionary allocation::
* Heap Allocation::
* Memory Access::
* Address arithmetic::
* Memory Blocks::
Control Structures
* Selection:: IF ... ELSE ... ENDIF
* Simple Loops:: BEGIN ...
* Counted Loops:: DO
* BEGIN loops with multiple exits::
* General control structures with CASE::
* Arbitrary control structures::
* Calls and returns::
* Exception Handling::
Defining Words
* CREATE::
* Variables:: Variables and user variables
* Constants::
* Values:: Initialised variables
* Colon Definitions::
* Anonymous Definitions:: Definitions without names
* Quotations::
* Supplying names:: Passing definition names as strings
* User-defined Defining Words::
* Deferred Words:: Allow forward references
* Forward:: Auto-resolved forward references
* Aliases::
User-defined Defining Words
* CREATE..DOES> applications::
* CREATE..DOES> details::
* Advanced does> usage example::
* Const-does>::
Interpretation and Compilation Semantics
* Combined words::
Tokens for Words
* Execution token:: represents execution/interpretation semantics
* Compilation token:: represents compilation semantics
* Name token:: represents named words
Compiling words
* Literals:: Compiling data values
* Macros:: Compiling words
The Text Interpreter
* Input Sources::
* Number Conversion::
* Interpret/Compile states::
* Interpreter Directives::
* Recognizers::
Word Lists
* Vocabularies::
* Why use word lists?::
* Word list example::
Files
* Forth source files::
* General files::
* Redirection::
* Directories::
* Search Paths::
Search Paths
* Source Search Paths::
* General Search Paths::
Other I/O
* Simple numeric output:: Predefined formats
* Formatted numeric output:: Formatted (pictured) output
* String Formats:: How Forth stores strings in memory
* Displaying characters and strings:: Other stuff
* String words:: Gforth's little string library
* Terminal output:: Cursor positioning etc.
* Single-key input::
* Line input and conversion::
* Pipes:: How to create your own pipes
* Xchars and Unicode:: Non-ASCII characters
Locals
* Gforth locals::
* Standard Forth locals::
Gforth locals
* Where are locals visible by name?::
* How long do locals live?::
* Locals programming style::
* Locals implementation::
Structures
* Why explicit structure support?::
* Structure Usage::
* Structure Naming Convention::
* Structure Implementation::
* Structure Glossary::
* Forth200x Structures::
Object-oriented Forth
* Why object-oriented programming?::
* Object-Oriented Terminology::
* Objects::
* OOF::
* Mini-OOF::
* Comparison with other object models::
The @file{objects.fs} model
* Properties of the Objects model::
* Basic Objects Usage::
* The Objects base class::
* Creating objects::
* Object-Oriented Programming Style::
* Class Binding::
* Method conveniences::
* Classes and Scoping::
* Dividing classes::
* Object Interfaces::
* Objects Implementation::
* Objects Glossary::
The @file{oof.fs} model
* Properties of the OOF model::
* Basic OOF Usage::
* The OOF base class::
* Class Declaration::
* Class Implementation::
The @file{mini-oof.fs} model
* Basic Mini-OOF Usage::
* Mini-OOF Example::
* Mini-OOF Implementation::
Programming Tools
* Examining:: Data and Code.
* Forgetting words:: Usually before reloading.
* Debugging:: Simple and quick.
* Assertions:: Making your programs self-checking.
* Singlestep Debugger:: Executing your program word by word.
Multitasker
* Pthreads:: Native Unix multitasker
C Interface
* Calling C Functions::
* Declaring C Functions::
* Calling C function pointers::
* Defining library interfaces::
* Declaring OS-level libraries::
* Callbacks::
* C interface internals::
* Low-Level C Interface Words::
* Migrating the C interface from earlier Gforth::
Assembler and Code Words
* Assembler Definitions:: Definitions in assembly language
* Common Assembler:: Assembler Syntax
* Common Disassembler::
* 386 Assembler:: Deviations and special cases
* AMD64 Assembler::
* Alpha Assembler:: Deviations and special cases
* MIPS assembler:: Deviations and special cases
* PowerPC assembler:: Deviations and special cases
* ARM Assembler:: Deviations and special cases
* Other assemblers:: How to write them
Tools
* Standard Report:: Report the words used, sorted by wordset.
* Stack depth changes:: Where does this stack item come from?
Standard conformance
* The Core Words::
* The optional Block word set::
* The optional Double Number word set::
* The optional Exception word set::
* The optional Facility word set::
* The optional File-Access word set::
* The optional Floating-Point word set::
* The optional Locals word set::
* The optional Memory-Allocation word set::
* The optional Programming-Tools word set::
* The optional Search-Order word set::
The Core Words
* core-idef:: Implementation Defined Options
* core-ambcond:: Ambiguous Conditions
* core-other:: Other System Documentation
The optional Block word set
* block-idef:: Implementation Defined Options
* block-ambcond:: Ambiguous Conditions
* block-other:: Other System Documentation
The optional Double Number word set
* double-ambcond:: Ambiguous Conditions
The optional Exception word set
* exception-idef:: Implementation Defined Options
The optional Facility word set
* facility-idef:: Implementation Defined Options
* facility-ambcond:: Ambiguous Conditions
The optional File-Access word set
* file-idef:: Implementation Defined Options
* file-ambcond:: Ambiguous Conditions
The optional Floating-Point word set
* floating-idef:: Implementation Defined Options
* floating-ambcond:: Ambiguous Conditions
The optional Locals word set
* locals-idef:: Implementation Defined Options
* locals-ambcond:: Ambiguous Conditions
The optional Memory-Allocation word set
* memory-idef:: Implementation Defined Options
The optional Programming-Tools word set
* programming-idef:: Implementation Defined Options
* programming-ambcond:: Ambiguous Conditions
The optional Search-Order word set
* search-idef:: Implementation Defined Options
* search-ambcond:: Ambiguous Conditions
Emacs and Gforth
* Installing gforth.el:: Making Emacs aware of Forth.
* Emacs Tags:: Viewing the source of a word in Emacs.
* Hilighting:: Making Forth code look prettier.
* Auto-Indentation:: Customizing auto-indentation.
* Blocks Files:: Reading and writing blocks files.
Image Files
* Image Licensing Issues:: Distribution terms for images.
* Image File Background:: Why have image files?
* Non-Relocatable Image Files:: don't always work.
* Data-Relocatable Image Files:: are better.
* Fully Relocatable Image Files:: better yet.
* Stack and Dictionary Sizes:: Setting the default sizes for an image.
* Running Image Files:: @code{gforth -i @i{file}} or @i{file}.
* Modifying the Startup Sequence:: and turnkey applications.
Fully Relocatable Image Files
* gforthmi:: The normal way
* cross.fs:: The hard way
Engine
* Portability::
* Threading::
* Primitives::
* Performance::
Threading
* Scheduling::
* Direct or Indirect Threaded?::
* Dynamic Superinstructions::
* DOES>::
Primitives
* Automatic Generation::
* TOS Optimization::
* Produced code::
Cross Compiler
* Using the Cross Compiler::
* How the Cross Compiler Works::
Licenses
* GNU Free Documentation License:: License for copying this manual.
* Copying:: GPL (for copying this software).
@end detailmenu
@end menu
@end ifnottex
@c ----------------------------------------------------------
@iftex
@unnumbered Preface
@cindex Preface
This manual documents Gforth. Some introductory material is provided for
readers who are unfamiliar with Forth or who are migrating to Gforth
from other Forth compilers. However, this manual is primarily a
reference manual.
@end iftex
@comment TODO much more blurb here.
@c ******************************************************************
@node Goals, Gforth Environment, Top, Top
@comment node-name, next, previous, up
@chapter Goals of Gforth
@cindex goals of the Gforth project
The goal of the Gforth Project is to develop a standard model for
Standard Forth. This can be split into several subgoals:
@itemize @bullet
@item
Gforth should conform to the Forth Standard.
@item
It should be a model, i.e. it should define all the
implementation-dependent things.
@item
It should become standard, i.e. widely accepted and used. This goal
is the most difficult one.
@end itemize
To achieve these goals Gforth should be
@itemize @bullet
@item
Similar to previous models (fig-Forth, F83)
@item
Powerful. It should provide for all the things that are considered
necessary today and even some that are not yet considered necessary.
@item
Efficient. It should not get the reputation of being exceptionally
slow.
@item
Free.
@item
Available on many machines/easy to port.
@end itemize
Have we achieved these goals? Gforth conforms to the Forth-94 (ANS
Forth) and Forth-2012 standards. It may be considered a model, but we
have not yet documented which parts of the model are stable and which
parts we are likely to change. It certainly has not yet become a de
facto standard, but it appears to be quite popular. It has some
similarities to and some differences from previous models. It has some
powerful features, but not yet everything that we envisioned. We
certainly have achieved our execution speed goals
(@pxref{Performance})@footnote{However, in 1998 the bar was raised
when the major commercial Forth vendors switched to native code
compilers.}. It is free and available on many machines.
@c ******************************************************************
@node Gforth Environment, Tutorial, Goals, Top
@chapter Gforth Environment
@cindex Gforth environment
Note: ultimately, the Gforth man page will be auto-generated from the
material in this chapter.
@menu
* Invoking Gforth:: Getting in
* Leaving Gforth:: Getting out
* Command-line editing::
* Environment variables:: that affect how Gforth starts up
* Gforth Files:: What gets installed and where
* Gforth in pipes::
* Startup speed:: When 14ms is not fast enough ...
@end menu
For related information about the creation of images see @ref{Image Files}.
@comment ----------------------------------------------
@node Invoking Gforth, Leaving Gforth, Gforth Environment, Gforth Environment
@section Invoking Gforth
@cindex invoking Gforth
@cindex running Gforth
@cindex command-line options
@cindex options on the command line
@cindex flags on the command line
Gforth is made up of two parts; an executable ``engine'' (named
@command{gforth} or @command{gforth-fast}) and an image file. To start it, you
will usually just say @code{gforth} -- this automatically loads the
default image file @file{gforth.fi}. In many other cases the default
Gforth image will be invoked like this:
@example
gforth [file | -e forth-code] ...
@end example
@noindent
This interprets the contents of the files and the Forth code in the order they
are given.
In addition to the @command{gforth} engine, there is also an engine
called @command{gforth-fast}, which is faster, but gives less
informative error messages (@pxref{Error messages}) and may catch some
errors (in particular, stack underflows and integer division errors)
later or not at all. You should use it for debugged,
performance-critical programs.
Moreover, there is an engine called @command{gforth-itc}, which is
useful in some backwards-compatibility situations (@pxref{Direct or
Indirect Threaded?}).
In general, the command line looks like this:
@example
gforth[-fast] [engine options] [image options]
@end example
The engine options must come before the rest of the command
line. They are:
@table @code
@cindex -i, command-line option
@cindex --image-file, command-line option
@item --image-file @i{file}
@itemx -i @i{file}
Loads the Forth image @i{file} instead of the default
@file{gforth.fi} (@pxref{Image Files}).
@cindex --appl-image, command-line option
@item --appl-image @i{file}
Loads the image @i{file} and leaves all further command-line arguments
to the image (instead of processing them as engine options). This is
useful for building executable application images on Unix, built with
@code{gforthmi --application ...}.
@cindex --path, command-line option
@cindex -p, command-line option
@item --path @i{path}
@itemx -p @i{path}
Uses @i{path} for searching the image file and Forth source code files
instead of the default in the environment variable @code{GFORTHPATH} or
the path specified at installation time and the working directory
@code{.} (e.g., @file{/usr/local/share/gforth/0.2.0:.}). A path is given
as a list of directories, separated by @samp{:} (previous versions had
@samp{;} for other OSes, but since Cygwin now only accepts
@code{/cygdrive/<letter>}, and we dropped support for OS/2 and MS-DOS,
it is @samp{:} everywhere).
@cindex --dictionary-size, command-line option
@cindex -m, command-line option
@cindex @i{size} parameters for command-line options
@cindex size of the dictionary and the stacks
@item --dictionary-size @i{size}
@itemx -m @i{size}
Allocate @i{size} space for the Forth dictionary space instead of
using the default specified in the image (typically 256K). The
@i{size} specification for this and subsequent options consists of
an integer and a unit (e.g.,
@code{4M}). The unit can be one of @code{b} (bytes), @code{e} (element
size, in this case Cells), @code{k} (kilobytes), @code{M} (Megabytes),
@code{G} (Gigabytes), and @code{T} (Terabytes). If no unit is specified,
@code{e} is used.
@cindex --data-stack-size, command-line option
@cindex -d, command-line option
@item --data-stack-size @i{size}
@itemx -d @i{size}
Allocate @i{size} space for the data stack instead of using the
default specified in the image (typically 16K).
@cindex --return-stack-size, command-line option
@cindex -r, command-line option
@item --return-stack-size @i{size}
@itemx -r @i{size}
Allocate @i{size} space for the return stack instead of using the
default specified in the image (typically 15K).
@cindex --fp-stack-size, command-line option
@cindex -f, command-line option
@item --fp-stack-size @i{size}
@itemx -f @i{size}
Allocate @i{size} space for the floating point stack instead of
using the default specified in the image (typically 15.5K). In this case
the unit specifier @code{e} refers to floating point numbers.
@cindex --locals-stack-size, command-line option
@cindex -l, command-line option
@item --locals-stack-size @i{size}
@itemx -l @i{size}
Allocate @i{size} space for the locals stack instead of using the
default specified in the image (typically 14.5K).
@cindex --vm-commit, command-line option
@cindex overcommit memory for dictionary and stacks
@cindex memory overcommit for dictionary and stacks
@item --vm-commit
Normally, Gforth tries to start up even if there is not enough virtual
memory for the dictionary and the stacks (using @code{MAP_NORESERVE}
on OSs that support it); so you can ask for a really big dictionary
and/or stacks, and as long as you don't use more virtual memory than
is available, everything will be fine (but if you use more, processes
get killed). With this option you just use the default allocation
policy of the OS; for OSs that don't overcommit (e.g., Solaris), this
means that you cannot and should not ask for as big dictionary and
stacks, but once Gforth successfully starts up, out-of-memory won't
kill it.
@cindex -h, command-line option
@cindex --help, command-line option
@item --help
@itemx -h
Print a message about the command-line options
@cindex -v, command-line option
@cindex --version, command-line option
@item --version
@itemx -v
Print version and exit
@cindex --debug, command-line option
@item --debug
Print some information useful for debugging on startup.
@cindex --offset-image, command-line option
@item --offset-image
Start the dictionary at a slightly different position than would be used
otherwise (useful for creating data-relocatable images,
@pxref{Data-Relocatable Image Files}).
@cindex --no-offset-im, command-line option
@item --no-offset-im
Start the dictionary at the normal position.
@cindex --clear-dictionary, command-line option
@item --clear-dictionary
Initialize all bytes in the dictionary to 0 before loading the image
(@pxref{Data-Relocatable Image Files}).
@cindex --die-on-signal, command-line-option
@item --die-on-signal
Normally Gforth handles most signals (e.g., the user interrupt SIGINT,
or the segmentation violation SIGSEGV) by translating it into a Forth
@code{THROW}. With this option, Gforth exits if it receives such a
signal. This option is useful when the engine and/or the image might be
severely broken (such that it causes another signal before recovering
from the first); this option avoids endless loops in such cases.
@cindex --no-dynamic, command-line option
@cindex --dynamic, command-line option
@item --no-dynamic
@item --dynamic
Disable or enable dynamic superinstructions with replication
(@pxref{Dynamic Superinstructions}).
@cindex --no-super, command-line option
@item --no-super
Disable dynamic superinstructions, use just dynamic replication; this is
useful if you want to patch threaded code (@pxref{Dynamic
Superinstructions}).
@cindex --ss-number, command-line option
@item --ss-number=@var{N}
Use only the first @var{N} static superinstructions compiled into the
engine (default: use them all; note that only @code{gforth-fast} has
any). This option is useful for measuring the performance impact of
static superinstructions.
@cindex --ss-min-..., command-line options
@item --ss-min-codesize
@item --ss-min-ls
@item --ss-min-lsu
@item --ss-min-nexts
Use specified metric for determining the cost of a primitive or static
superinstruction for static superinstruction selection. @code{Codesize}
is the native code size of the primive or static superinstruction,
@code{ls} is the number of loads and stores, @code{lsu} is the number of
loads, stores, and updates, and @code{nexts} is the number of dispatches
(not taking dynamic superinstructions into account), i.e. every
primitive or static superinstruction has cost 1. Default:
@code{codesize} if you use dynamic code generation, otherwise
@code{nexts}.
@cindex --ss-greedy, command-line option
@item --ss-greedy
This option is useful for measuring the performance impact of static
superinstructions. By default, an optimal shortest-path algorithm is
used for selecting static superinstructions. With @option{--ss-greedy}
this algorithm is modified to assume that anything after the static
superinstruction currently under consideration is not combined into
static superinstructions. With @option{--ss-min-nexts} this produces
the same result as a greedy algorithm that always selects the longest
superinstruction available at the moment. E.g., if there are
superinstructions AB and BCD, then for the sequence A B C D the optimal
algorithm will select A BCD and the greedy algorithm will select AB C D.
@cindex --print-metrics, command-line option
@item --print-metrics
Prints some metrics used during static superinstruction selection:
@code{code size} is the actual size of the dynamically generated code.
@code{Metric codesize} is the sum of the codesize metrics as seen by
static superinstruction selection; there is a difference from @code{code
size}, because not all primitives and static superinstructions are
compiled into dynamically generated code, and because of markers. The
other metrics correspond to the @option{ss-min-...} options. This
option is useful for evaluating the effects of the @option{--ss-...}
options.
@end table
@cindex loading files at startup
@cindex executing code on startup
@cindex batch processing with Gforth
As explained above, the image-specific command-line arguments for the
default image @file{gforth.fi} consist of a sequence of filenames and
@code{-e @var{forth-code}} options that are interpreted in the sequence
in which they are given. The @code{-e @var{forth-code}} or
@code{--evaluate @var{forth-code}} option evaluates the Forth code. This
option takes only one argument; if you want to evaluate more Forth
words, you have to quote them or use @code{-e} several times. To exit
after processing the command line (instead of entering interactive mode)
append @code{-e bye} to the command line. You can also process the
command-line arguments with a Forth program (@pxref{OS command line
arguments}).
@cindex versions, invoking other versions of Gforth
If you have several versions of Gforth installed, @code{gforth} will
invoke the version that was installed last. @code{gforth-@i{version}}
invokes a specific version. If your environment contains the variable
@code{GFORTHPATH}, you may want to override it by using the
@code{--path} option.
On startup, before processing any of the image option, the user
initialization file either specified in the environment variable
@code{GFORTH_ENV} or, if not set, @file{~/.gforthrc0} is included, if
it exists. If @code{GFORTH_ENV} is ``@code{off},'' nothing is
included. After processing all the image options and just before
printing the boot message, the user initialization file
@file{~/.gforthrc} from your home directory is included, unless the
option @code{--no-rc} is given.
@comment ----------------------------------------------
@node Leaving Gforth, Command-line editing, Invoking Gforth, Gforth Environment
@section Leaving Gforth
@cindex Gforth - leaving
@cindex leaving Gforth
You can leave Gforth by typing @code{bye} or @kbd{Ctrl-d} (at the start
of a line) or (if you invoked Gforth with the @code{--die-on-signal}
option) @kbd{Ctrl-c}. When you leave Gforth, all of your definitions and
data are discarded. For ways of saving the state of the system before
leaving Gforth see @ref{Image Files}.
doc-bye
@comment ----------------------------------------------
@node Command-line editing, Environment variables, Leaving Gforth, Gforth Environment
@section Command-line editing
@cindex command-line editing
Gforth maintains a history file that records every line that you type to
the text interpreter. This file is preserved between sessions, and is
used to provide a command-line recall facility; if you type @kbd{Ctrl-P}
repeatedly you can recall successively older commands from this (or
previous) session(s). The full list of command-line editing facilities is:
@itemize @bullet
@item
@kbd{Ctrl-p} (``previous'') (or up-arrow) to recall successively older
commands from the history buffer.
@item
@kbd{Ctrl-n} (``next'') (or down-arrow) to recall successively newer commands
from the history buffer.
@item
@kbd{Ctrl-f} (or right-arrow) to move the cursor right, non-destructively.
@item
@kbd{Ctrl-b} (or left-arrow) to move the cursor left, non-destructively.
@item
@kbd{Ctrl-h} (backspace) to delete the character to the left of the cursor,
closing up the line.
@item
@kbd{Ctrl-k} to delete (``kill'') from the cursor to the end of the line.
@item
@kbd{Ctrl-a} to move the cursor to the start of the line.
@item
@kbd{Ctrl-e} to move the cursor to the end of the line.
@item
@key{RET} (@kbd{Ctrl-m}) or @key{LFD} (@kbd{Ctrl-j}) to submit the current
line.
@item
@key{TAB} to step through all possible full-word completions of the word
currently being typed.
@item
@kbd{Ctrl-d} on an empty line line to terminate Gforth (gracefully,
using @code{bye}).
@item
@kbd{Ctrl-x} (or @code{Ctrl-d} on a non-empty line) to delete the
character under the cursor.
@end itemize
When editing, displayable characters are inserted to the left of the
cursor position; the line is always in ``insert'' (as opposed to
``overstrike'') mode.
@cindex history file
@cindex @file{.gforth-history}
On Unix systems, the history file is @file{~/.gforth-history} by
default@footnote{i.e. it is stored in the user's home directory.}. You
can find out the name and location of your history file using:
@example
history-file type \ Unix-class systems
history-file type \ Other systems