Annotation of gforth/kernel/toolsext.fs, revision 1.9

1.6       anton       1: \ Copyright (C) 1995,1998 Free Software Foundation, Inc.
1.1       anton       2: 
                      3: \ This file is part of Gforth.
                      4: 
                      5: \ Gforth is free software; you can redistribute it and/or
                      6: \ modify it under the terms of the GNU General Public License
                      7: \ as published by the Free Software Foundation; either version 2
                      8: \ of the License, or (at your option) any later version.
                      9: 
                     10: \ This program is distributed in the hope that it will be useful,
                     11: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     12: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     13: \ GNU General Public License for more details.
                     14: 
                     15: \ You should have received a copy of the GNU General Public License
                     16: \ along with this program; if not, write to the Free Software
                     17: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     18: 
1.3       jwilke     19: Warnings off
1.1       anton      20: 
                     21: Variable countif
                     22: 
                     23: : dummy ;  immediate
                     24: : >exec  >r ; restrict ( :-)
1.7       anton      25: : scanIF   f83find  dup 0=  IF  drop ['] dummy >head  THEN  ;
1.1       anton      26: 
1.2       jwilke     27: Create [struct]-search    ' scanIF A,  ' (reveal) A,  ' drop A, ' drop A,
1.5       pazsan     28: Create [struct]-voc       [struct]-search A,
                     29:                           NIL A,       NIL A,       NIL A,
1.1       anton      30: 
                     31: : ?if  countif @ 0<
                     32:   IF  [ [struct]-voc 3 cells + ] ALiteral @ lookup !  THEN ;
                     33: 
                     34: UNLOCK  Tlast @ TNIL Tlast !  LOCK
                     35: \ last @  0 last !
                     36: 
1.8       crook      37: : [IF]
                     38:   1 countif +! ?if ;       immediate
                     39: : [THEN]
                     40:   -1 countif +! ?if ;       immediate
                     41: : [ELSE]
                     42:   postpone [THEN] postpone [IF] ;
1.1       anton      43:                                      immediate
                     44: ' [IF]   Alias [IFDEF]               immediate
                     45: ' [IF]   Alias [IFUNDEF]             immediate
1.8       crook      46: ' [THEN] Alias [ENDIF]               immediate
1.1       anton      47: ' [IF]   Alias [BEGIN]               immediate
                     48: ' [IF]   Alias [WHILE]               immediate
                     49: ' [THEN] Alias [UNTIL]               immediate
                     50: ' [THEN] Alias [AGAIN]               immediate
                     51: ' [IF]   Alias [DO]                  immediate
                     52: ' [IF]   Alias [?DO]                 immediate
                     53: ' [THEN] Alias [LOOP]                immediate
                     54: ' [THEN] Alias [+LOOP]               immediate
                     55: : [REPEAT]  postpone [AGAIN] postpone [THEN] ;
                     56:                                      immediate
                     57: ' ( Alias (                          immediate
                     58: ' \ Alias \                          immediate
                     59: 
                     60: UNLOCK Tlast @ swap Tlast ! LOCK
                     61: \ last @ swap last !
1.5       pazsan     62: 1 cells - [struct]-voc cell+ !
1.1       anton      63: 
                     64: \ Interpretative Structuren                            30apr92py
                     65: 
                     66: : defined   bl word find nip 0<> ; immediate
1.8       crook      67: 
                     68: : [IF] ( flag | flag "<spaces>name ..." -- ) \ tools-ext bracket-if
                     69:   \G If flag is @code{TRUE} do nothing (and therefore
                     70:   \G execute subsequent words as normal). If flag is @code{FALSE},
                     71:   \G parse and discard words from the parse
                     72:   \G area (refilling it if necessary using
                     73:   \G @code{REFILL}) including nested instances of @code{[IF]}..
                     74:   \G @code{[ELSE]}.. @code{[THEN]} and @code{[IF]}.. @code{[THEN]}
                     75:   \G until the balancing @code{[ELSE]} or @code{[THEN]} has been
                     76:   \G parsed and discarded. Immediate word.
                     77:        0= IF  countif off
1.1       anton      78:               lookup @ [ [struct]-voc 3 cells + ] ALiteral !
                     79:              [struct]-voc lookup !
                     80:           THEN ;                                      immediate
1.8       crook      81: 
                     82: : [IFDEF] ( "<spaces>name" -- ) \ gforth bracket-if-def
                     83:   \G If name is found in the current search-order, behave like
1.9     ! crook      84:   \G @code{[IF]} with a @code{TRUE} flag, otherwise behave like
1.8       crook      85:   \G @code{[IF]} with a @code{FALSE} flag. Immediate word.
                     86:   postpone defined    postpone [IF] ;                 immediate
                     87: 
                     88: : [IFUNDEF] ( "<spaces>name" -- ) \ gforth bracket-if-un-def
                     89:   \G If name is not found in the current search-order, behave like
1.9     ! crook      90:   \G @code{[IF]} with a @code{TRUE} flag, otherwise behave like
1.8       crook      91:   \G @code{[IF]} with a @code{FALSE} flag. Immediate word.
                     92:   postpone defined 0= postpone [IF] ;                 immediate
                     93: 
                     94: : [ELSE]  ( "<spaces>name ..." -- ) \ tools-ext bracket-else
                     95:   \G Parse and discard words from the parse
                     96:   \G area (refilling it if necessary using
                     97:   \G @code{REFILL}) including nested instances of @code{[IF]}..
                     98:   \G @code{[ELSE]}.. @code{[THEN]} and @code{[IF]}.. @code{[THEN]}
                     99:   \G until the balancing @code{[THEN]} has been parsed and discarded.
                    100:   \G @code{[ELSE]} only gets executed if the balancing @code{[IF]}
                    101:   \G was @code{TRUE}; if it was @code{FALSE}, @code{[IF]} would
                    102:   \G have parsed and discarded the @code{[ELSE]}, leaving the
                    103:   \G subsequent words to be executed as normal.
                    104:   \G Immediate word.
                    105:   0 postpone [IF] ;                                   immediate
                    106: 
                    107: : [THEN] ( -- ) \ tools-ext bracket-then
                    108:   \G Do nothing; used as a marker for other words to parse
1.9     ! crook     109:   \G and discard up to. Immediate word.
1.8       crook     110:   ;                                                   immediate
                    111: 
                    112: : [ENDIF] ( -- ) \ gforth bracket-end-if
1.9     ! crook     113:   \G Do nothing; synonym for @code{[THEN]}
1.8       crook     114:   ;                                                   immediate
1.1       anton     115: 
                    116: \ Structs for interpreter                              28nov92py
                    117: 
                    118: User (i)
                    119: 
1.8       crook     120: : [DO]  ( n-limit n-index -- ) \ gforth bracket-do
                    121:   >in @ -rot
1.1       anton     122:   DO   I (i) ! dup >r >in ! interpret r> swap +LOOP  drop ;
                    123:                                                       immediate
1.8       crook     124: 
                    125: : [?DO] ( n-limit n-index -- ) \ gforth bracket-question-do
                    126:   2dup = IF 2drop postpone [ELSE] ELSE postpone [DO] THEN ;
1.1       anton     127:                                                       immediate
1.8       crook     128: 
                    129: : [+LOOP] ( n -- ) \ gforth bracket-question-plus-loop
                    130:   rdrop rdrop ;                                       immediate
                    131: 
                    132: : [LOOP] ( -- ) \ gforth bracket-loop
                    133:   1 rdrop rdrop ;                                     immediate
                    134: 
                    135: : [FOR] ( n -- ) \ gforth bracket-for
                    136:   0 swap postpone [DO] ;                              immediate
                    137: 
                    138: : [NEXT] ( n -- ) \ gforth bracket-next
                    139:   -1 rdrop rdrop ;                                    immediate
                    140: 
1.4       pazsan    141: :noname (i) @ ;
                    142: :noname (i) @ postpone Literal ;
1.8       crook     143: interpret/compile: [I] ( -- n ) \ gforth bracket-i
                    144: 
                    145: : [BEGIN] ( -- ) \ gforth bracket-begin
                    146:   >in @ >r BEGIN r@ >in ! interpret UNTIL rdrop ;     immediate
                    147: 
                    148: ' [+LOOP]  Alias [UNTIL] ( flag -- ) \ gforth bracket-until
1.1       anton     149:                                                       immediate
1.8       crook     150: 
                    151: : [REPEAT]  ( -- ) \ gforth bracket-repeat
                    152:   false rdrop rdrop ;                                 immediate
                    153: 
                    154: ' [REPEAT] Alias [AGAIN] ( -- ) \ gforth bracket-again
                    155:                                                       immediate
                    156: 
                    157: : [WHILE]   ( flag -- ) \ gforth bracket-while
1.1       anton     158:   0= IF   postpone [ELSE] true rdrop rdrop 1 countif +!  THEN ;
                    159:                                                       immediate
                    160: 
1.3       jwilke    161: Warnings on

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>