Diff for /gforth/kernel/cond.fs between versions 1.5 and 1.27

version 1.5, 1999/03/23 20:24:24 version 1.27, 2012/08/21 19:36:55
Line 1 Line 1
 \ Structural Conditionals                              12dec92py  \ Structural Conditionals                              12dec92py
   
 \ Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.  \ Copyright (C) 1995,1996,1997,2000,2003,2004,2007,2010,2011 Free Software Foundation, Inc.
   
 \ This file is part of Gforth.  \ This file is part of Gforth.
   
 \ Gforth is free software; you can redistribute it and/or  \ Gforth is free software; you can redistribute it and/or
 \ modify it under the terms of the GNU General Public License  \ modify it under the terms of the GNU General Public License
 \ as published by the Free Software Foundation; either version 2  \ as published by the Free Software Foundation, either version 3
 \ of the License, or (at your option) any later version.  \ of the License, or (at your option) any later version.
   
 \ This program is distributed in the hope that it will be useful,  \ This program is distributed in the hope that it will be useful,
Line 15 Line 15
 \ GNU General Public License for more details.  \ GNU General Public License for more details.
   
 \ You should have received a copy of the GNU General Public License  \ You should have received a copy of the GNU General Public License
 \ along with this program; if not, write to the Free Software  \ along with this program. If not, see http://www.gnu.org/licenses/.
 \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
   
 here 0 , \ just a dummy, the real value of locals-list is patched into it in glocals.fs  here 0 , \ just a dummy, the real value of locals-list is patched into it in glocals.fs
 AConstant locals-list \ acts like a variable that contains  AConstant locals-list \ acts like a variable that contains
Line 48  variable backedge-locals Line 47  variable backedge-locals
 \ locals-list (valid at address) (third)  \ locals-list (valid at address) (third)
   
 \ types  \ types
 0 constant defstart  [IFUNDEF] defstart 
   0 constant defstart     \ usally defined in comp.fs
   [THEN]
 1 constant live-orig  1 constant live-orig
 2 constant dead-orig  2 constant dead-orig
 3 constant dest \ the loopback branch is always assumed live  3 constant dest \ the loopback branch is always assumed live
Line 78  variable backedge-locals Line 79  variable backedge-locals
   
 3 constant cs-item-size  3 constant cs-item-size
   
 : CS-PICK ( ... u -- ... destu ) \ tools-ext  : CS-PICK ( ... u -- ... destu ) \ tools-ext c-s-pick
  1+ cs-item-size * 1- >r   1+ cs-item-size * 1- >r
  r@ pick  r@ pick  r@ pick   r@ pick  r@ pick  r@ pick
  rdrop   rdrop
  dup non-orig? ;   dup non-orig? ;
   
 : CS-ROLL ( destu/origu .. dest0/orig0 u -- .. dest0/orig0 destu/origu ) \ tools-ext  : CS-ROLL ( destu/origu .. dest0/orig0 u -- .. dest0/orig0 destu/origu ) \ tools-ext c-s-roll
  1+ cs-item-size * 1- >r   1+ cs-item-size * 1- >r
  r@ roll r@ roll r@ roll   r@ roll r@ roll r@ roll
  rdrop   rdrop
  dup cs-item? ;    dup cs-item? ; 
   
   : CS-DROP ( dest -- ) \ gforth
       dest? 2drop ;
   
 : cs-push-part ( -- list addr )  : cs-push-part ( -- list addr )
  locals-list @ here ;   locals-list @ here ;
   
Line 103  variable backedge-locals Line 107  variable backedge-locals
   
 \ Structural Conditionals                              12dec92py  \ Structural Conditionals                              12dec92py
   
   defer other-control-flow ( -- )
   \ hook for control-flow stuff that's not handled by begin-like etc.
   
 : ?struc      ( flag -- )       abort" unstructured " ;  : ?struc      ( flag -- )       abort" unstructured " ;
 : sys?        ( sys -- )        dup 0= ?struc ;  : sys?        ( sys -- )        dup 0= ?struc ;
 : >mark ( -- orig )  : >mark ( -- orig )
  cs-push-orig 0 , ;   cs-push-orig 0 , other-control-flow ;
 : >resolve    ( addr -- )        here over - swap ! ;  : >resolve    ( addr -- )
 : <resolve    ( addr -- )        here - , ;      here swap !
       basic-block-end ;
   : <resolve    ( addr -- )        , ;
   
 : BUT  : BUT
     1 cs-roll ;                      immediate restrict      1 cs-roll ;                      immediate restrict
Line 144  immediate restrict Line 153  immediate restrict
 \ people who have not been brought up with Forth (or who have been  \ people who have not been brought up with Forth (or who have been
 \ brought up with fig-Forth).  \ brought up with fig-Forth).
   
 : ELSE ( compilation orig1 -- orig2 ; run-time f -- ) \ core  : ELSE ( compilation orig1 -- orig2 ; run-time -- ) \ core
     POSTPONE ahead      POSTPONE ahead
     1 cs-roll      1 cs-roll
     POSTPONE then ; immediate restrict      POSTPONE then ; immediate restrict
Line 153  Defer begin-like ( -- ) Line 162  Defer begin-like ( -- )
 ' noop IS begin-like  ' noop IS begin-like
   
 : BEGIN ( compilation -- dest ; run-time -- ) \ core  : BEGIN ( compilation -- dest ; run-time -- ) \ core
     begin-like cs-push-part dest ; immediate restrict      begin-like cs-push-part dest
       basic-block-end ; immediate restrict
   
 Defer again-like ( dest -- addr )  Defer again-like ( dest -- addr )
 ' nip IS again-like  ' nip IS again-like
Line 161  Defer again-like ( dest -- addr ) Line 171  Defer again-like ( dest -- addr )
 : AGAIN ( compilation dest -- ; run-time -- ) \ core-ext  : AGAIN ( compilation dest -- ; run-time -- ) \ core-ext
     dest? again-like  POSTPONE branch  <resolve ; immediate restrict      dest? again-like  POSTPONE branch  <resolve ; immediate restrict
   
 Defer until-like  Defer until-like ( list addr xt1 xt2 -- )
 : until, ( list addr xt1 xt2 -- )  drop compile, <resolve drop ;  :noname ( list addr xt1 xt2 -- )
 ' until, IS until-like      drop compile, <resolve drop ;
   IS until-like
   
 : UNTIL ( compilation dest -- ; run-time f -- ) \ core  : UNTIL ( compilation dest -- ; run-time f -- ) \ core
     dest? ['] ?branch ['] ?branch-lp+!# until-like ; immediate restrict      dest? ['] ?branch ['] ?branch-lp+!# until-like ; immediate restrict
Line 176  Defer until-like Line 187  Defer until-like
     POSTPONE again      POSTPONE again
     POSTPONE then ; immediate restrict      POSTPONE then ; immediate restrict
   
   \ not clear if this should really go into Gforth's kernel...
   
   : CONTINUE ( dest-sys j*sys -- dest-sys j*sys ) \ gforth
       \g jump to the next outer BEGIN
       depth 0 ?DO  I pick dest = IF
               I cs-item-size / cs-pick postpone AGAIN
               LEAVE  THEN
       cs-item-size +LOOP
       true abort" no BEGIN found" ; immediate compile-only
   
 \ counted loops  \ counted loops
   
 \ leave poses a little problem here  \ leave poses a little problem here
Line 216  Avariable leave-sp  leave-stack 3 cells Line 237  Avariable leave-sp  leave-stack 3 cells
     leave-sp ! ;      leave-sp ! ;
   
 : DONE ( compilation orig -- ; run-time -- ) \ gforth  : DONE ( compilation orig -- ; run-time -- ) \ gforth
     \ !! the original done had ( addr -- )      \g resolves all LEAVEs up to the compilaton orig (from a BEGIN)
     drop >r drop      drop >r drop
     begin      begin
         leave>          leave>
Line 296  Defer exit-like ( -- ) Line 317  Defer exit-like ( -- )
 ' noop IS exit-like  ' noop IS exit-like
   
 : EXIT ( compilation -- ; run-time nest-sys -- ) \ core  : EXIT ( compilation -- ; run-time nest-sys -- ) \ core
     \G Return to the calling definition; usually used as a way of  \G Return to the calling definition; usually used as a way of
     \G forcing an early return from a definition. Before  \G forcing an early return from a definition. Before
     \G @code{EXIT}ing you must clean up the return stack and  \G @code{EXIT}ing you must clean up the return stack and
     \G @code{UNLOOP} any outstanding @code{?DO}...@code{LOOP}s.  \G @code{UNLOOP} any outstanding @code{?DO}...@code{LOOP}s.
     exit-like      exit-like
     POSTPONE ;s      POSTPONE ;s
       basic-block-end
     POSTPONE unreachable ; immediate restrict      POSTPONE unreachable ; immediate restrict
   
 : ?EXIT ( -- ) ( compilation -- ; run-time nest-sys f -- | nest-sys ) \ gforth  : ?EXIT ( -- ) ( compilation -- ; run-time nest-sys f -- | nest-sys ) \ gforth

Removed from v.1.5  
changed lines
  Added in v.1.27


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