version 1.59, 2000/07/16 20:09:37
|
version 1.60, 2000/07/17 15:26:32
|
Line 1901 In this case the stack comment is pretty
|
Line 1901 In this case the stack comment is pretty
|
is simple enough. If you think it would be a good idea to add such a |
is simple enough. If you think it would be a good idea to add such a |
comment to increase readability, you should also consider factoring the |
comment to increase readability, you should also consider factoring the |
word into several simpler words (@pxref{Factoring Tutorial,, |
word into several simpler words (@pxref{Factoring Tutorial,, |
Factoring}), which typically eliminates the need for the stack effect; |
Factoring}), which typically eliminates the need for the stack comment; |
however, if you decide not to refactor it, then having such a comment is |
however, if you decide not to refactor it, then having such a comment is |
better than not having it. |
better than not having it. |
|
|
Line 2200 Comparison words produce canonical flags
|
Line 2200 Comparison words produce canonical flags
|
|
|
Gforth supports all combinations of the prefixes @code{0 u d d0 du} (or |
Gforth supports all combinations of the prefixes @code{0 u d d0 du} (or |
none) and the comparisons @code{= <> < > <= >=}. Only a part of these |
none) and the comparisons @code{= <> < > <= >=}. Only a part of these |
combinations are standard (see the standard or !! the glossary for |
combinations are standard (for details see the standard or @ref{Word |
details). |
Glossary}). |
|
|
You can use @code{and or xor invert} can be used as operations on |
You can use @code{and or xor invert} can be used as operations on |
canonical flags. Actually they are bitwise operations: |
canonical flags. Actually they are bitwise operations: |
Line 2553 one at @code{addr cell+} etc.
|
Line 2553 one at @code{addr cell+} etc.
|
You can also reserve memory without creating a new word: |
You can also reserve memory without creating a new word: |
|
|
@example |
@example |
here 10 cells allot |
here 10 cells allot . |
.s |
here . |
@end example |
@end example |
|
|
@code{Here} pushes the start address of the memory area. You should |
@code{Here} pushes the start address of the memory area. You should |
Line 2568 you have just @code{allot}ed with
|
Line 2568 you have just @code{allot}ed with
|
|
|
@example |
@example |
-10 cells allot |
-10 cells allot |
|
here . |
@end example |
@end example |
|
|
Note that you cannot do this if you have created a new word in the |
Note that you cannot do this if you have created a new word in the |
Line 2587 free throw
|
Line 2588 free throw
|
|
|
The @code{throw}s deal with errors (e.g., out of memory). |
The @code{throw}s deal with errors (e.g., out of memory). |
|
|
And there is also a garbage collector @url{!!}, which eliminates the |
And there is also a garbage collector |
need to @code{free} memory explicitly. |
@url{http://www.complang.tuwien.ac.at/forth/garbage-collection.zip}, |
|
which eliminates the need to @code{free} memory explicitly. |
|
|
|
|
@node Characters and Strings Tutorial, Alignment Tutorial, Memory Tutorial, Tutorial |
@node Characters and Strings Tutorial, Alignment Tutorial, Memory Tutorial, Tutorial |
Line 2831 see foo
|
Line 2833 see foo
|
: bar ( ... "word" -- ... ) |
: bar ( ... "word" -- ... ) |
' execute ; |
' execute ; |
see bar |
see bar |
1 2 bar + |
1 2 bar + . |
@end example |
@end example |
|
|
You often want to parse a word during compilation and compile its XT so |
You often want to parse a word during compilation and compile its XT so |
Line 2892 this:
|
Line 2894 this:
|
: foo 100 throw ; |
: foo 100 throw ; |
: foo1 foo ." after foo" ; |
: foo1 foo ." after foo" ; |
: bar ['] foo1 catch ; |
: bar ['] foo1 catch ; |
bar |
bar . |
@end example |
@end example |
|
|
It is often important to restore a value upon leaving a definition, even |
It is often important to restore a value upon leaving a definition, even |
Line 3015 Definition and use of field offsets now
|
Line 3017 Definition and use of field offsets now
|
|
|
@example |
@example |
2 cells simple-field field1 |
2 cells simple-field field1 |
( addr ) field1 |
create mystruct 4 cells allot |
|
mystruct .s field1 .s drop |
@end example |
@end example |
|
|
If you want to do something with the word without performing the code |
If you want to do something with the word without performing the code |
Line 3149 Instead, you can use @code{LITERAL (comp
|
Line 3152 Instead, you can use @code{LITERAL (comp
|
: [FOO] ( compilation: --; run-time: -- n ) |
: [FOO] ( compilation: --; run-time: -- n ) |
500 POSTPONE literal ; immediate |
500 POSTPONE literal ; immediate |
|
|
: flip foo ; |
: flip [FOO] ; |
flip . |
flip . |
see flip |
see flip |
@end example |
@end example |
Line 3266 interpretation semantics:
|
Line 3269 interpretation semantics:
|
|
|
@example |
@example |
' if |
' if |
comp' if .s |
comp' if .s 2drop |
@end example |
@end example |
|
|
|
|