File:  [gforth] / gforth / Attic / toolsext.fs
Revision 1.8: download - view: text, annotated - select for diffs
Tue Jul 16 20:57:14 1996 UTC (27 years, 8 months ago) by pazsan
Branches: MAIN
CVS tags: v0-2-1, v0-2-0, HEAD
SPECIAL: to create special "state-smart" words

    1: \ Interpretative Structuren                            16feb92py
    2: 
    3: \ Copyright (C) 1995 Free Software Foundation, Inc.
    4: 
    5: \ This file is part of Gforth.
    6: 
    7: \ Gforth is free software; you can redistribute it and/or
    8: \ modify it under the terms of the GNU General Public License
    9: \ as published by the Free Software Foundation; either version 2
   10: \ of the License, or (at your option) any later version.
   11: 
   12: \ This program is distributed in the hope that it will be useful,
   13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
   14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15: \ GNU General Public License for more details.
   16: 
   17: \ You should have received a copy of the GNU General Public License
   18: \ along with this program; if not, write to the Free Software
   19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   20: 
   21: 
   22: Variable countif
   23: 
   24: : dummy ;  immediate
   25: : >exec  >r ; restrict ( :-)
   26: : scanIF   f83find  dup 0=  IF  drop ['] dummy >name  THEN  ;
   27: 
   28: Create [struct]-search    ' scanIF A,  ' (reveal) A,  ' drop A,
   29: Create [struct]-voc       NIL A,       [struct]-search A,
   30:                           NIL A,       NIL A,
   31: 
   32: : ?if  countif @ 0<
   33:   IF  [ [struct]-voc 3 cells + ] ALiteral @ lookup !  THEN ;
   34: 
   35: UNLOCK  Tlast @ NIL Tlast !  LOCK
   36: 
   37: : [IF]      1 countif +! ?if ;       immediate
   38: : [THEN]   -1 countif +! ?if ;       immediate
   39: : [ELSE]   postpone [THEN] r> >exec postpone [IF] ;
   40:                                      immediate
   41: ' [IF]   Alias [IFDEF]               immediate
   42: ' [IF]   Alias [IFUNDEF]             immediate
   43: ' [THEN] Alias [ENDIF]                immediate
   44: ' [IF]   Alias [BEGIN]               immediate
   45: ' [IF]   Alias [WHILE]               immediate
   46: ' [THEN] Alias [UNTIL]               immediate
   47: ' [THEN] Alias [AGAIN]               immediate
   48: ' [IF]   Alias [DO]                  immediate
   49: ' [IF]   Alias [?DO]                 immediate
   50: ' [THEN] Alias [LOOP]                immediate
   51: ' [THEN] Alias [+LOOP]               immediate
   52: : [REPEAT]  postpone [AGAIN] postpone [THEN] ;
   53:                                      immediate
   54: ' ( Alias (                          immediate
   55: ' \ Alias \                          immediate
   56: 
   57: UNLOCK Tlast @ swap Tlast ! LOCK
   58: 1 cells - [struct]-voc !
   59: 
   60: \ Interpretative Structuren                            30apr92py
   61: 
   62: : defined   bl word find nip 0<> ; immediate
   63: : [IF] 0= IF  countif off
   64:               lookup @ [ [struct]-voc 3 cells + ] ALiteral !
   65: 	      [struct]-voc lookup !
   66:           THEN ;                                      immediate
   67: : [IFDEF]   postpone defined    postpone [IF] ;       immediate
   68: : [IFUNDEF] postpone defined 0= postpone [IF] ;       immediate
   69: : [ELSE] 0 postpone [IF] ;                            immediate
   70: : [THEN] ;                                            immediate
   71: : [ENDIF] ;                                           immediate
   72: 
   73: \ Structs for interpreter                              28nov92py
   74: 
   75: User (i)
   76: 
   77: : [DO]  ( start end -- )  >in @ -rot
   78:   DO   I (i) ! dup >r >in ! interpret r> swap +LOOP  drop ;
   79:                                                       immediate
   80: : [?DO] 2dup = IF 2drop postpone [ELSE] ELSE postpone [DO] THEN ;
   81:                                                       immediate
   82: : [+LOOP] ( n -- ) rdrop rdrop ;                      immediate
   83: : [LOOP] ( -- ) 1 rdrop rdrop ;                       immediate
   84: : [FOR] ( n -- )  0 swap postpone [DO] ;              immediate
   85: : [NEXT] ( n -- ) -1 rdrop rdrop ;                    immediate
   86: : [I] ( -- index ) (I) @ postpone Literal ;           immediate
   87: : [BEGIN] >in @ >r BEGIN r@ >in ! interpret UNTIL rdrop ;
   88:                                                       immediate
   89: ' [+LOOP]  Alias [UNTIL] immediate
   90: : [REPEAT]  ( -- )  false rdrop rdrop ;               immediate
   91: ' [REPEAT] Alias [AGAIN] immediate
   92: : [WHILE]   ( flag -- )
   93:   0= IF   postpone [ELSE] true rdrop rdrop 1 countif +!  THEN ;
   94:                                                       immediate
   95: 

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