version 1.94, 2001/12/09 19:12:45
|
version 1.95, 2001/12/24 14:09:06
|
Line 3859 look for a 6 and place that on the table
|
Line 3859 look for a 6 and place that on the table
|
the stack. What happens if you try to do a third addition? Pick up the |
the stack. What happens if you try to do a third addition? Pick up the |
first card, pick up the second card -- ah! There is no second card. This |
first card, pick up the second card -- ah! There is no second card. This |
is called a @dfn{stack underflow} and consitutes an error. If you try to |
is called a @dfn{stack underflow} and consitutes an error. If you try to |
do the same thing with Forth it will report an error (probably a Stack |
do the same thing with Forth it often reports an error (probably a Stack |
Underflow or an Invalid Memory Address error). |
Underflow or an Invalid Memory Address error). |
|
|
The opposite situation to a stack underflow is a @dfn{stack overflow}, |
The opposite situation to a stack underflow is a @dfn{stack overflow}, |
Line 7947 Directives}).
|
Line 7947 Directives}).
|
@c that, we can also show what's not. In any case, I have written a |
@c that, we can also show what's not. In any case, I have written a |
@c section Compiling Words which also deals with [ ]. |
@c section Compiling Words which also deals with [ ]. |
|
|
@code{[} and @code{]} also give you the ability to switch into compile |
@c !! The following example does not work in Gforth 0.5.9 or later. |
state and back, but we cannot think of any useful Standard application |
|
for this ability. Pre-ANS Forth textbooks have examples like this: |
|
|
|
@example |
@c @code{[} and @code{]} also give you the ability to switch into compile |
: AA ." this is A" ; |
@c state and back, but we cannot think of any useful Standard application |
: BB ." this is B" ; |
@c for this ability. Pre-ANS Forth textbooks have examples like this: |
: CC ." this is C" ; |
|
|
@c @example |
create table ] aa bb cc [ |
@c : AA ." this is A" ; |
|
@c : BB ." this is B" ; |
: go ( n -- ) \ n is offset into table.. 0 for 1st entry |
@c : CC ." this is C" ; |
cells table + @ execute ; |
|
@end example |
@c create table ] aa bb cc [ |
|
|
This example builds a jump table; @code{0 go} will display ``@code{this |
@c : go ( n -- ) \ n is offset into table.. 0 for 1st entry |
is A}''. Using @code{[} and @code{]} in this example is equivalent to |
@c cells table + @@ execute ; |
defining @code{table} like this: |
@c @end example |
|
|
@example |
@c This example builds a jump table; @code{0 go} will display ``@code{this |
create table ' aa COMPILE, ' bb COMPILE, ' cc COMPILE, |
@c is A}''. Using @code{[} and @code{]} in this example is equivalent to |
@end example |
@c defining @code{table} like this: |
|
|
The problem with this code is that the definition of @code{table} is not |
@c @example |
portable -- it @i{compile}s execution tokens into code space. Whilst it |
@c create table ' aa COMPILE, ' bb COMPILE, ' cc COMPILE, |
@i{may} work on systems where code space and data space co-incide, the |
@c @end example |
Standard only allows data space to be assigned for a @code{CREATE}d |
|
word. In addition, the Standard only allows @code{@@} to access data |
@c The problem with this code is that the definition of @code{table} is not |
space, whilst this example is using it to access code space. The only |
@c portable -- it @i{compile}s execution tokens into code space. Whilst it |
portable, Standard way to build this table is to build it in data space, |
@c @i{may} work on systems where code space and data space co-incide, the |
like this: |
@c Standard only allows data space to be assigned for a @code{CREATE}d |
|
@c word. In addition, the Standard only allows @code{@@} to access data |
@example |
@c space, whilst this example is using it to access code space. The only |
create table ' aa , ' bb , ' cc , |
@c portable, Standard way to build this table is to build it in data space, |
@end example |
@c like this: |
|
|
|
@c @example |
|
@c create table ' aa , ' bb , ' cc , |
|
@c @end example |
|
|
doc-state |
@c doc-state |
|
|
|
|
@node Interpreter Directives, , Interpret/Compile states, The Text Interpreter |
@node Interpreter Directives, , Interpret/Compile states, The Text Interpreter |