-
Notifications
You must be signed in to change notification settings - Fork 33
/
Forth-83.txt
6248 lines (3114 loc) · 196 KB
/
Forth-83.txt
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
FORTH-83 STANDARD
A PUBLICATION OF THE FORTH STANDARDS TEAM
AUGUST 1983
FORTH-83 STANDARD
COPYRIGHT c. 1983 FORTH STANDARDS TEAM
Permission is hereby granted to reproduce this document in whole
or in part provided that such reproductions refer to the fact
that the copied material is subject to copyright by the FORTH
Standards Team. No changes or modifications may be made to the
copied material unless it is clearly indicated that such changes
were not incorporated in the original copyrighted work.
The existence of a FORTH Standard does not in any respect
preclude anyone, whether the individual has approved this
Standard or not, from implementing, marketing, purchasing or
using products, processes, or procedures not conforming to the
Standard. FORTH Standards are subject to periodic review and
users are cautioned to obtain the latest editions.
ISBN 0-914699-03-2
FORTH STANDARDS TEAM
P.O. BOX 4545
MOUNTAIN VIEW, CA 94040
USA
ii
FORTH-83 STANDARD
TABLE OF CONTENTS
1. FOREWORD ............................................... 1
2. PURPOSE ................................................ 2
3. SCOPE .................................................. 2
4. TRADEOFFS .............................................. 3
5. DEFINITIONS OF TERMS ................................... 4
6. REFERENCES ............................................. 12
7. REQUIREMENTS ........................................... 13
8. COMPLIANCE AND LABELING ................................ 15
9. USAGE .................................................. 17
10. ERROR CONDITIONS ....................................... 20
11. GLOSSARY NOTATION ...................................... 22
12. REQUIRED WORD SET ...................................... 25
13. DOUBLE NUMBER EXTENSION WORD SET ....................... 41
14. ASSEMBLER EXTENSION WORD SET ........................... 44
15. SYSTEM EXTENSION WORD SET .............................. 46
16. CONTROLLED REFERENCE WORDS ............................. 48
APPENDICES
A. FORTH STANDARDS TEAM MEMBERSHIP ................... 51
B. UNCONTROLLED REFERENCE WORDS ...................... 54
C. EXPERIMENTAL PROPOSALS ............................ 60
C.1 SEARCH ORDER SPECIFICATION AND CONTROL ....... 61
C.2 DEFINITION FIELD ADDRESS CONVERSION OPERATORS . 66
D. STANDARDS TEAM CHARTER ............................ 69
E. PROPOSAL/COMMENT FORM AND INSTRUCTIONS ............ 78
iii
FORTH-83 STANDARD
iv
1. FOREWORD
1. FOREWORD
FORTH is an integrated programming approach and computer
language. FORTH was invented by Mr. Charles Moore specifically
to increase programmer productivity in the development of
computer related applications without sacrificing machine
efficiency. FORTH is a layered environment containing the
elements of a computer language as well as those of an operating
system and a machine monitor. This extensible, layered
environment provides for highly interactive program development
and testing.
In the interests of transportability of application software
written in FORTH, standardization efforts began in the mid-1970s
by the European FORTH User's Group (EFUG). This effort resulted
in the FORTH-77 Standard. As the language continued to evolve,
an interim FORTH-78 Standard was published by the FORTH Standards
Team. Following FORTH Standards Team meetings in 1979 the FORTH-
79 Standard was published in 1980.
The FORTH Standards Team is comprised of individuals who have a
great variety of experience and technical expertise with FORTH.
The FORTH Standards Team consists of both users and implementers.
Comments, proposals, and correspondence should be mailed to:
FORTH Standards Team, P.O. Box 4545, Mountain View, CA 94040 USA.
FORTH's extensibility allows the language to be expanded and
adapted to special needs and different hardware systems. A
programmer or vendor may choose to strictly adhere with the
standard, but the choice to deviate is acknowledged as beneficial
and sometimes necessary. If the standard does not explicitly
specify a requirement or restriction, a system or application may
utilize any choice without sacrificing compliance to the standard
provided that the system or application remains transportable and
obeys the other requirements of the standard.
1
2. PURPOSE
2. PURPOSE
The purpose of this standard is to allow transportability of
FORTH-83 Standard Programs in source form among FORTH-83 Standard
Systems. A standard program shall execute equivalently on all
standard systems.
3. SCOPE
This standard shall apply to any FORTH-83 Standard Program
executing on any FORTH-83 Standard System, provided sufficient
computer resources (memory, mass storage) are available.
2
4. TRADEOFFS
4. TRADEOFFS
When conflicting choices are made, the following order guides the
Standards Team:
1) Functional correctness - known bounds, non-ambiguous;
2) Portability - repeatable results when programs are
transported among Standard Systems;
3) Simplicity;
4) Naming clarity - uniformity of expression using descriptive
rather than procedure names, i.e., [COMPILE] rather than 'C,
and ALLOT rather than DP+! ;
5) Generality;
6) Execution speed;
7) Memory compactness;
8) Compilation speed;
9) Historical continuity;
10) Pronounceability;
11) Teachability.
3
5. DEFINITIONS OF TERMS
5. DEFINITIONS OF TERMS
These are the definitions of the terms used within this Standard.
address, byte
An unsigned 16-bit number that locates an 8-bit byte in a
standard FORTH address space over the range {0..65,535}. It
may be a native machine address or a representation on a
virtual machine, locating the addr-th byte within the
virtual byte address space. Addresses are treated as
unsigned numbers. See: "arithmetic, two's complement"
address, compilation
The numerical value compiled for a FORTH word definition
which identifies that definition. The address interpreter
uses this value to locate the machine code corresponding to
each definition.
address, native machine
The natural address representation of the host computer.
address, parameter field
The address of the first byte of memory associated with a
word definition for the storage of compilation addresses (in
a colon definition), numeric data, text characters, etc.
arithmetic, two's complement
Arithmetic is performed using two's complement integers
within a field of either 16 or 32 bits as indicated by the
operation. Addition and subtraction of two's complement
integers ignore any overflow condition. This allows numbers
treated as unsigned to produce the same results as if the
numbers had been treated as signed.
block
The 1024 bytes of data from mass storage which are
referenced by block numbers in the range {0..the number of
blocks available -1}. The actual amount of data transferred
and the translation from block number to device and physical
record is a function of the implementation. See: "block
buffer" "mass storage"
block buffer
A 1024-byte memory area where a block is made temporarily
available for use. Block buffers are uniquely assigned to
blocks. See: "9.7 Multiprogramming Impact"
byte
An assembly of 8 bits. In reference to memory, it is the
storage capacity for 8 bits.
4
5. DEFINITIONS OF TERMS
character
A 7-bit number the significance of which is given by the
ASCII standard. When contained in a larger field, the
higher order bits are zero. See: "6. REFERENCES"
compilation
The action of converting text words from the input stream
into an internal form suitable for later execution. When in
the compile state, the compilation addresses of FORTH words
are compiled into the dictionary for later execution by the
address interpreter. Numbers are compiled to be placed on
the data stack when later executed. Numbers are accepted
from the input stream unsigned or negatively signed and
converted using the value of BASE . See: "number" "number
conversion" "interpreter, text"
defining word
A word that, when executed, creates a new dictionary entry
in the compilation vocabulary. The new word name is taken
from the input stream. If the input stream is exhausted
before the new name is available, an error condition exists.
Example of defining words are: : CONSTANT CREATE
definition
See: "word definition"
dictionary
A structure of word definitions in computer memory which is
extensible and grows toward higher memory addresses.
Entries are organized in vocabularies to aid location by
name. See: "search order"
display
The process of sending one or more characters to the current
output device. These characters are typically displayed or
printed on a terminal. The selection of the current output
device is system dependent.
division, floored
Integer division in which the remainder carries the sign of
the divisor or is zero, and the quotient is rounded to its
arithmetic floor. Note that, except for error conditions,
n1 n2 SWAP OVER /MOD ROT * + is identical to n1. See:
"floor, arithmetic"
Examples:
dividend divisor remainder quotient
10 7 3 1
-10 7 4 -2
10 -7 -4 -2
-10 -7 -3 1
equivalent execution
5
5. DEFINITIONS OF TERMS
A standard program will produce the same results, exclusive
of timing dependencies, when given the same inputs on any
Standard System which has sufficient resources to execute
the program. Only standard source programs are
transportable.
error condition
An exceptional condition which requires action by the system
which may be other than the expected function. Refer to the
section "10. Error Conditions".
false
A zero number represents the false state of a flag.
flag
A number that may have one of two logical states, false or
true. See: "false" "true"
floor, arithmetic
If z is any real number, then the floor of z is the greatest
integer less than or equal to z.
The floor of +.6 is 0
The floor of -.4 is -1
free field format
Numbers are converted using the value of BASE and then
displayed with no leading zeros. A trailing space is
displayed. The number of characters displayed is the
minimum number of characters, at least one, to uniquely
represent the number. See: "number conversion"
glossary
A set of explanations in natural language to describe the
corresponding computer execution of word definitions.
immediate word
A word which executes when encountered during compilation or
interpretation. Immediate words handle special cases during
compilation. See, for example, IF LITERAL ." etc.
input stream
A sequence of characters available to the system, for
processing by the text interpreter. The input stream
conventionally may be taken from the current input device
(via the text input buffer) and mass storage (via a block
buffer). BLK , >IN , TIB and #TIB specify the input stream.
Words using or altering BLK , >IN , TIB and #TIB are
responsible for maintaining and restoring control of the
input stream.
6
5. DEFINITIONS OF TERMS
The input stream extends from the offset value of >IN to the
size of the input stream. If BLK is zero the input stream
is contained within the area addressed by TIB and is #TIB
bytes long. If BLK is non-zero the input stream is
contained within the block buffer specified by BLK and is
1024 bytes long. See: "11.8 Input Text"
interpreter, address
The machine code instructions, routine or other facilities
that execute compiled word definitions containing
compilation addresses.
interpreter, text
The word definitions(s) that repeatedly accepts a word name
from the input stream, locates the corresponding compilation
address and starts the address interpreter to execute it.
Text from the input stream interpreted as a number leaves
the corresponding value on the data stack. Numbers are
accepted from the input stream unsigned or negatively signed
and converted using the value of BASE . See: "number"
"number conversion"
layers
The grouping of word names of each Standard word set to show
like characteristics. No implementation requirements are
implied by this grouping.
layer, compiler
Word definitions which add new procedures to the dictionary
or which aid compilation by adding compilation addresses or
data structures to the dictionary.
layer, devices
Word definitions which allow access to mass storage and
computer peripheral devices.
layer, interpreter
Word definitions which support vocabularies, terminal
output, and the interpretation of text from the text input
buffer or a mass storage device by executing the
corresponding word definitions.
layer, nucleus
Word definitions generally defined in machine code that
control the execution of the fundamental operations of a
virtual FORTH machine. This includes the address
interpreter.
load
Redirection of the text interpreter's input stream to be
from mass storage. This is the general method for
compilation of new definitions into the dictionary.
mass storage
7
5. DEFINITIONS OF TERMS
Storage which might reside outside FORTH's address space.
Mass storage data is made available in the form of 1024-byte
blocks. A block is accessible within the FORTH address
space in a block buffer. When a block has been indicated as
UPDATEed (modified) the block will ultimately be transferred
to mass storage.
number
When values exist within a larger field, the most-
significant bits are zero. 16-bit numbers are represented
in memory by addressing the first of two bytes at
consecutive addresses. The byte order is unspecified by
this Standard. Double numbers are represented on the stack
with the most-significant 16 bits (with sign) most
accessible. Double numbers are represented in memory by two
consecutive 16-bit numbers. The address of the least
significant 16 bits is two greater than the address of the
most significant 16 bits. The byte order within each 16-bit
field is unspecified. See: "arithmetic, two's complement"
"number types" "9.8 Numbers" "11.7 Stack Parameters"
number conversion
Numbers are maintained internally in binary and represented
externally by using graphic characters within the ASCII
character set. Conversion between the internal and external
forms is performed using the current value of BASE to
determine the digits of a number. A digit has a value
ranging from zero to the value of BASE-1. The digit with
the value zero is represented by the ASCII character "0"
(position 3/0 with the decimal equivalent of 48). This
representation of digits proceeds through the ASCII
character set to the character "(" corresponding to the
decimal value 9. For digits with a value exceeding 9, the
ASCII graphic characters beginning with the character "A"
(position 4/1 with the decimal equivalent 65) corresponding
to the decimal value 10 are used. This sequence then
continues up to and including the digit with the decimal
value 71 which is represented by the ASCII character "~"
(position 7/14 with a decimal equivalent 126). A negative
number may be represented by preceding the digits with a
single leading minus sign, the character "-".
number types
All number types consist of some number of bits. These bits
are either arbitrary or are weighted.
8
5. DEFINITIONS OF TERMS
Signed and unsigned numbers use weighted bits. Weighted
bits within a number have a value of a power of two
beginning with the rightmost (least-significant) bit having
the value of two to the zero power. This weighting
continues to the leftmost bit increasing the power by one
for each bit. For an unsigned number this weighting pattern
includes the leftmost bit; thus, for an unsigned 16-bit
number the weight of the leftmost bit is 32,768. For a
signed number this weighting pattern includes the leftmost
bit but the weight of the leftmost bit is negated; thus, for
a signed 16-bit number the weight of the leftmost bit is
-32,768. This weighting pattern for signed numbers is
called two's complement notation.
Unspecified weighted numbers are either unsigned numbers or
signed numbers; program context determines whether the
number is signed or unsigned. See: "11.7 Stack Parameters"
pictured numeric output
The use of numeric output definitions which convert
numerical values into text strings. These definitions are
used in a sequence which resembles a symbolic 'picture' of
the desired text format. Conversion proceeds from least-
significant digit to most-significant digit, and converted
characters are stored from higher memory addresses to lower.
program
A complete specification of execution to achieve a specific
function (application task) expressed in FORTH source code
form.
receive
The process of obtaining one character from the current
input device. The selection of the current input device is
system dependent.
recursion
The process of self-reference, either directly or
indirectly.
return
The means of indicating the end of text by striking a key on
an input device. The key used is system dependent. This
key is typically called "RETURN", "CARRIAGE RETURN", or
"ENTER".
screen
Textual data arranged for editing. By convention, a screen
consists of 16 lines (numbered 0 through 15) of 64
characters each. Screens usually contain program source
text, but may be used to view mass storage data. The first
byte of a screen occupies the first byte of a mass storage
block, which is the beginning point for text interpretation
during a load.
9
5. DEFINITIONS OF TERMS
search order
A specification of the order in which selected vocabularies
in the dictionary are searched. Execution of a vocabulary
makes it the first vocabulary in the search order. The
dictionary is searched whenever a word is to be located by
its name. This order applies to all dictionary searches
unless otherwise noted. The search order begins with the
last vocabulary executed and ends with FORTH , unless
altered in a system dependent manner.
source definition
Text consisting of word names suitable for compilation or
execution by the text interpreter. Such text is usually
arranged in screens and maintained on a mass storage device.
stack, data
A last in, first out list consisting of 16-bit binary
values. This stack is primarily used to hold intermediate
values during execution of word definitions. Stack values
may represent numbers, characters, addresses, boolean
values, etc.
When the name 'stack' is used alone, it implies the data
stack.
stack, return
A last in, first out list which contains the addresses of
word definitions whose execution has not been completed by
the address interpreter. As a word definition passes
control to another definition, the return point is placed on
the return stack.
The return stack may cautiously be used for other values.
string, counted
A sequence of consecutive 8-bit bytes located in memory by
their low memory address. The byte at this address contains
a count {0..255} of the number of bytes following which are
part of the string. The count does not include the count
byte itself. Counted strings usually contain ASCII
characters.
string, text
A sequence of consecutive 8-bit bytes located in memory by
their low memory address and length in bytes. Strings
usually, but not exclusively, contain ASCII characters.
When the term 'string' is used alone or in conjunction with
other words it refers to text strings.
structure, control
10
5. DEFINITIONS OF TERMS
A group of FORTH words which when executed alter the
execution sequence. The group starts and terminates with
compiler words. Examples of control structures: DO ...
LOOP DO ... +LOOP BEGIN ... WHILE ... REPEAT BEGIN ...
UNTIL IF ... THEN IF ... ELSE ... THEN See: "9.9 Control
Structures"
transportability
This term indicates that equivalent execution results when a
program is executed on other than the system on which it was
created. See: "equivalent execution"
true
A non-zero value represents the true state of a flag. Any
non-zero value will be accepted by a standard word as
'true'; all standard words return a 16-bit value with all
bits set to one when returning a 'true' flag.
user area
An area in memory which contains the storage for user
variable.
variable, user
A variable whose data storage area is usually located in the
user area. Some system variables are maintained in the user
area so that the words may be re-entrant to different users.
vocabulary
An ordered list of word definitions. Vocabularies are an
advantage in separating different word definitions that may
have the same name. More than one definition with the same
name can exist in one vocabulary. The latter is called a
redefinition. The most recently created redefinition will
be found when the vocabulary is searched.
vocabulary, compilation
The vocabulary into which new word definitions are appended.
word
A sequence of characters terminated by one blank or the end
of the input stream. Leading blanks are ignored. Words are
usually obtained via the input stream.
word definition
A named FORTH execution procedure compiled into the
dictionary. Its execution may be defined in terms of
machine code, as a sequence of compilation address, or other
compiled words.
word name
11
5. DEFINITIONS OF TERMS
The name of a word definition. Word names are limited to 31
characters and may not contain an ASCII space. If two
definitions have different word names in the same vocabulary