File:  [gforth] / gforth / Attic / toolsext.fs
Revision 1.9: download - view: text, annotated - select for diffs
Thu Feb 6 21:23:06 1997 UTC (25 years, 4 months ago) by pazsan
Branches: MAIN
CVS tags: v0-3-0, HEAD
Started to merge in changes made for gforth-EC project.

    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: \ last @  0 last !
   37: 
   38: : [IF]      1 countif +! ?if ;       immediate
   39: : [THEN]   -1 countif +! ?if ;       immediate
   40: : [ELSE]   postpone [THEN] postpone [IF] ;
   41:                                      immediate
   42: ' [IF]   Alias [IFDEF]               immediate
   43: ' [IF]   Alias [IFUNDEF]             immediate
   44: ' [THEN] Alias [ENDIF]                immediate
   45: ' [IF]   Alias [BEGIN]               immediate
   46: ' [IF]   Alias [WHILE]               immediate
   47: ' [THEN] Alias [UNTIL]               immediate
   48: ' [THEN] Alias [AGAIN]               immediate
   49: ' [IF]   Alias [DO]                  immediate
   50: ' [IF]   Alias [?DO]                 immediate
   51: ' [THEN] Alias [LOOP]                immediate
   52: ' [THEN] Alias [+LOOP]               immediate
   53: : [REPEAT]  postpone [AGAIN] postpone [THEN] ;
   54:                                      immediate
   55: ' ( Alias (                          immediate
   56: ' \ Alias \                          immediate
   57: 
   58: UNLOCK Tlast @ swap Tlast ! LOCK
   59: \ last @ swap last !
   60: 1 cells - [struct]-voc !
   61: 
   62: \ Interpretative Structuren                            30apr92py
   63: 
   64: : defined   bl word find nip 0<> ; immediate
   65: : [IF] 0= IF  countif off
   66:               lookup @ [ [struct]-voc 3 cells + ] ALiteral !
   67: 	      [struct]-voc lookup !
   68:           THEN ;                                      immediate
   69: : [IFDEF]   postpone defined    postpone [IF] ;       immediate
   70: : [IFUNDEF] postpone defined 0= postpone [IF] ;       immediate
   71: : [ELSE] 0 postpone [IF] ;                            immediate
   72: : [THEN] ;                                            immediate
   73: : [ENDIF] ;                                           immediate
   74: 
   75: \ Structs for interpreter                              28nov92py
   76: 
   77: User (i)
   78: 
   79: : [DO]  ( start end -- )  >in @ -rot
   80:   DO   I (i) ! dup >r >in ! interpret r> swap +LOOP  drop ;
   81:                                                       immediate
   82: : [?DO] 2dup = IF 2drop postpone [ELSE] ELSE postpone [DO] THEN ;
   83:                                                       immediate
   84: : [+LOOP] ( n -- ) rdrop rdrop ;                      immediate
   85: : [LOOP] ( -- ) 1 rdrop rdrop ;                       immediate
   86: : [FOR] ( n -- )  0 swap postpone [DO] ;              immediate
   87: : [NEXT] ( n -- ) -1 rdrop rdrop ;                    immediate
   88: : [I] ( -- index ) (I) @ postpone Literal ;           immediate
   89: : [BEGIN] >in @ >r BEGIN r@ >in ! interpret UNTIL rdrop ;
   90:                                                       immediate
   91: ' [+LOOP]  Alias [UNTIL] immediate
   92: : [REPEAT]  ( -- )  false rdrop rdrop ;               immediate
   93: ' [REPEAT] Alias [AGAIN] immediate
   94: : [WHILE]   ( flag -- )
   95:   0= IF   postpone [ELSE] true rdrop rdrop 1 countif +!  THEN ;
   96:                                                       immediate
   97: 

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