--- gforth/struct.fs 1997/07/31 16:17:11 1.12 +++ gforth/struct.fs 2007/12/31 17:34:58 1.24 @@ -1,6 +1,6 @@ \ data structures (like C structs) -\ Copyright (C) 1995, 1997 Free Software Foundation, Inc. +\ Copyright (C) 1995,1997,2000,2003,2007 Free Software Foundation, Inc. \ This file is part of Gforth. @@ -16,18 +16,20 @@ \ 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. +\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. -: nalign ( addr1 n -- addr2 ) \ gforth -\g @code{addr2} is the aligned version of @code{addr1} wrt the -\g alignment @code{n}. +: naligned ( addr1 n -- addr2 ) \ gforth +\g @var{addr2} is the aligned version of @var{addr1} with respect to the +\g alignment @var{n}. 1- tuck + swap invert and ; +' naligned alias nalign \ old name, obsolete + : dozerofield ( -- ) \ a field that makes no change \ to enable accessing the offset with "['] >body @" this \ is not implemented with "['] noop alias" - last @ + latest if immediate then @@ -35,14 +37,18 @@ does> ( name execution: -- ) drop ; : field, ( align1 offset1 align size -- align2 offset2 ) - rot dup , ( align1 align size offset1 ) - + >r nalign r> ; + swap rot over nalign dup , ( align1 size align offset ) + rot + >r nalign r> ; : create-field ( align1 offset1 align size -- align2 offset2 ) create field, ; : field ( align1 offset1 align size "name" -- align2 offset2 ) \ gforth - \G name execution: ( addr1 -- addr2 ) + \g Create a field @var{name} with offset @var{offset1}, and the type + \g given by @var{align size}. @var{offset2} is the offset of the + \g next field, and @var{align2} is the alignment of all fields.@* + \g @code{name} execution: @var{addr1} -- @var{addr2}.@* + \g @var{addr2}=@var{addr1}+@var{offset1} 2 pick if \ field offset <> 0 [IFDEF] (Field) @@ -56,15 +62,15 @@ does> ( name execution: -- ) field, ; : end-struct ( align size "name" -- ) \ gforth -\g @code{name} execution: @code{addr1 -- addr1+offset1}@* -\g create a field @code{name} with offset @code{offset1}, and the type -\g given by @code{size align}. @code{offset2} is the offset of the -\g next field, and @code{align2} is the alignment of all fields. +\g Define a structure/type descriptor @var{name} with alignment +\g @var{align} and size @var{size1} (@var{size} rounded up to be a +\g multiple of @var{align}).@* +\g @code{name} execution: -- @var{align size1}@* over nalign \ pad size to full alignment 2constant ; 1 chars 0 end-struct struct ( -- align size ) \ gforth -\g an empty structure, used to start a structure definition. +\g An empty structure, used to start a structure definition. \ type descriptors 1 aligned 1 cells 2constant cell% ( -- align size ) \ gforth @@ -76,28 +82,28 @@ cell% 2* 2constant double% \ memory allocation words ' drop alias %alignment ( align size -- align ) \ gforth -\g the alignment of the structure +\g The alignment of the structure. ' nip alias %size ( align size -- size ) \ gforth -\g the size of the structure +\g The size of the structure. : %align ( align size -- ) \ gforth - \G align the data space pointer to the alignment @code{align}. + \G Align the data space pointer to the alignment @var{align}. drop here swap nalign here - allot ; : %allot ( align size -- addr ) \ gforth - \g allot @code{size} address units of data space with alignment - \g @code{align}; the resulting block of data is found at - \g @code{addr}. + \g Allot @var{size} address units of data space with alignment + \g @var{align}; the resulting block of data is found at + \g @var{addr}. tuck %align here swap allot ; : %allocate ( align size -- addr ior ) \ gforth - \g allocate @code{size} address units with alignment @code{align}, + \g Allocate @var{size} address units with alignment @var{align}, \g similar to @code{allocate}. nip allocate ; -: %alloc ( size align -- addr ) \ gforth - \g allocate @code{size} address units with alignment @code{align}, - \g giving a data block at @code{addr}; @code{throw}s an ior code +: %alloc ( align size -- addr ) \ gforth + \g Allocate @var{size} address units with alignment @var{align}, + \g giving a data block at @var{addr}; @code{throw} an ior code \g if not successful. %allocate throw ;