--- gforth/Attic/toolsext.fs 1994/02/11 16:30:47 1.1 +++ gforth/Attic/toolsext.fs 1996/07/16 20:57:14 1.8 @@ -1,78 +1,95 @@ -\ TOOLSEXT.FS [IF] [ELSE] [THEN] and more 20may93jaw +\ Interpretative Structuren 16feb92py -\ This here is fully ans compatible -\ May be cross-compiled +\ Copyright (C) 1995 Free Software Foundation, Inc. -\ ( \ added 09jun93jaw +\ This file is part of Gforth. -\ very close to dpANS5 - -decimal - -CREATE Opennest 7 chars allot -CREATE Closenest 7 chars allot - -: SKIPNEST - 1 BEGIN - BEGIN name count dup WHILE - 2dup Opennest count compare 0= - IF 2drop 1+ - ELSE Closenest count compare 0= IF 1- THEN - THEN - ?dup 0= ?EXIT - REPEAT - 2drop refill 0= - UNTIL drop ; - -\ : ( s" (" Opennest place -\ s" )" Closenest place -\ SKIPNEST ; immediate - -: comment? ( c-addr u -- c-addr u ) - 2dup s" (" compare 0= - IF postpone ( - ELSE 2dup s" \" compare 0= IF postpone \ THEN - THEN ; - -: [ELSE] - 1 BEGIN - BEGIN name count dup WHILE - comment? - 2dup s" [IF]" compare 0= - IF 2drop 1+ - ELSE 2dup s" [ELSE]" compare 0= - IF 2drop 1- dup IF 1+ THEN - ELSE s" [THEN]" compare 0= IF 1- THEN - THEN - THEN - ?dup 0= ?EXIT - REPEAT - 2drop refill 0= - UNTIL drop ; immediate - -: [THEN] ( -- ) ; immediate - -: [IF] ( flag -- ) - 0= IF postpone [ELSE] THEN ; immediate - -\ [IFUNDEF] [IFDEF] 9may93jaw - -: [IFUNDEF] - name find nip 0= postpone [IF] ; immediate -: [IFDEF] - name find nip 0<> postpone [IF] ; immediate - - -\ [IF]? 9jun93jaw - -\ same as comment? but skips [IF] .... [THEN] - -: [if]? ( c-addr u -- c-addr u ) - 2dup s" [IF]" compare 0= >r - 2dup s" [ELSE]" compare 0= >r - 2dup s" [IFUNDEF]" compare 0= >r - 2dup s" [IFDEF]" compare 0= r> or r> or r> or - IF s" [IF]" Opennest place - s" [THEN]" Closenest place - SKIPNEST THEN ; +\ Gforth is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation; either version 2 +\ of the License, or (at your option) any later version. + +\ This program is distributed in the hope that it will be useful, +\ but WITHOUT ANY WARRANTY; without even the implied warranty of +\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +\ GNU General Public License for more details. + +\ You should have received a copy of the GNU General Public License +\ along with this program; if not, write to the Free Software +\ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +Variable countif + +: dummy ; immediate +: >exec >r ; restrict ( :-) +: scanIF f83find dup 0= IF drop ['] dummy >name THEN ; + +Create [struct]-search ' scanIF A, ' (reveal) A, ' drop A, +Create [struct]-voc NIL A, [struct]-search A, + NIL A, NIL A, + +: ?if countif @ 0< + IF [ [struct]-voc 3 cells + ] ALiteral @ lookup ! THEN ; + +UNLOCK Tlast @ NIL Tlast ! LOCK + +: [IF] 1 countif +! ?if ; immediate +: [THEN] -1 countif +! ?if ; immediate +: [ELSE] postpone [THEN] r> >exec postpone [IF] ; + immediate +' [IF] Alias [IFDEF] immediate +' [IF] Alias [IFUNDEF] immediate +' [THEN] Alias [ENDIF] immediate +' [IF] Alias [BEGIN] immediate +' [IF] Alias [WHILE] immediate +' [THEN] Alias [UNTIL] immediate +' [THEN] Alias [AGAIN] immediate +' [IF] Alias [DO] immediate +' [IF] Alias [?DO] immediate +' [THEN] Alias [LOOP] immediate +' [THEN] Alias [+LOOP] immediate +: [REPEAT] postpone [AGAIN] postpone [THEN] ; + immediate +' ( Alias ( immediate +' \ Alias \ immediate + +UNLOCK Tlast @ swap Tlast ! LOCK +1 cells - [struct]-voc ! + +\ Interpretative Structuren 30apr92py + +: defined bl word find nip 0<> ; immediate +: [IF] 0= IF countif off + lookup @ [ [struct]-voc 3 cells + ] ALiteral ! + [struct]-voc lookup ! + THEN ; immediate +: [IFDEF] postpone defined postpone [IF] ; immediate +: [IFUNDEF] postpone defined 0= postpone [IF] ; immediate +: [ELSE] 0 postpone [IF] ; immediate +: [THEN] ; immediate +: [ENDIF] ; immediate + +\ Structs for interpreter 28nov92py + +User (i) + +: [DO] ( start end -- ) >in @ -rot + DO I (i) ! dup >r >in ! interpret r> swap +LOOP drop ; + immediate +: [?DO] 2dup = IF 2drop postpone [ELSE] ELSE postpone [DO] THEN ; + immediate +: [+LOOP] ( n -- ) rdrop rdrop ; immediate +: [LOOP] ( -- ) 1 rdrop rdrop ; immediate +: [FOR] ( n -- ) 0 swap postpone [DO] ; immediate +: [NEXT] ( n -- ) -1 rdrop rdrop ; immediate +: [I] ( -- index ) (I) @ postpone Literal ; immediate +: [BEGIN] >in @ >r BEGIN r@ >in ! interpret UNTIL rdrop ; + immediate +' [+LOOP] Alias [UNTIL] immediate +: [REPEAT] ( -- ) false rdrop rdrop ; immediate +' [REPEAT] Alias [AGAIN] immediate +: [WHILE] ( flag -- ) + 0= IF postpone [ELSE] true rdrop rdrop 1 countif +! THEN ; + immediate