home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 3
/
CDPDIII.bin
/
pd
/
programming
/
gnuforth
/
lib
/
stacks.f83
< prev
next >
Wrap
Text File
|
1992-05-19
|
3KB
|
109 lines
\
\ VECTOR REPRESENTED STACKS
\
\ Copyright (C) 1990 by Mikael R.K. Patel
\
\ Computer Aided Design Laboratory (CADLAB)
\ Department of Computer and Information Science
\ Linkoping University
\ S-581 83 LINKOPING
\ SWEDEN
\
\ Email: mip@ida.liu.se
\
\ Started on: 1 April 1990
\
\ Last updated on: 23 July 1990
\
\ Dependencies:
\ (forth) forth, structures, blocks
\
\ Description:
\ Management of vector represented stacks with cell stack width.
\
\ Copying:
\ This program 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 1, 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; see the file COPYING. If not, write to
\ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
.( Loading Stacks definitions...) cr
#include structures.f83
#include blocks.f83
vocabulary stacks ( -- )
structures blocks stacks definitions
struct.type STACK ( size -- )
ptr +top ( stack -- addr) private
long +bytes ( stack -- addr) private
ptr +bottom ( stack --- addr) private
struct.init ( size stack -- )
>r cells dup allot r@ +bytes !
here r@ +bottom !
here r> +top !
struct.end
: empty-stack ( stack -- )
dup +bottom @ swap +top !
;
: size-stack ( stack -- num)
+bytes @ cell /
;
: depth-stack ( stack -- num)
dup +bottom @ swap +top @ - cell /
;
: ?empty-stack ( stack -- bool)
dup +bottom @ swap +top @ =
;
: ?full-stack ( stack -- bool)
dup >r +bottom @ r@ +top @ - r> +bytes @ =
;
: push ( element stack -- )
+top dup cell negate swap +! @ !
;
: pop ( stack -- element)
+top dup @ @ cell rot +!
;
: map-stack ( stack block[element -- ] -- )
swap dup +bottom @ swap +top @ ?do
i @ swap dup >r call r>
cell +loop
drop
;
: ?map-stack ( stack block[element -- bool] -- )
swap dup +bottom @ swap +top @ ?do
i @ swap dup >r call r> swap
if leave then
cell +loop
drop
;
: .stack ( stack -- )
." stack#" dup . ." [" dup depth-stack 0 .r ." ] "
block[ ( element -- )
." /" 0 .r
]; map-stack
;
forth only