version 1.15, 1999/03/23 20:24:20
|
version 1.25, 2007/12/31 18:40:24
|
Line 1
|
Line 1
|
\ data structures (like C structs) |
\ 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. |
\ 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. |
|
|
|
: naligned ( addr1 n -- addr2 ) \ gforth |
: naligned ( addr1 n -- addr2 ) \ gforth |
\g @var{addr2} is the aligned version of @var{addr1} with respect to the |
\g @var{addr2} is the aligned version of @var{addr1} with respect to the |
Line 29
|
Line 28
|
\ a field that makes no change |
\ a field that makes no change |
\ to enable accessing the offset with "['] <field> >body @" this |
\ to enable accessing the offset with "['] <field> >body @" this |
\ is not implemented with "['] noop alias" |
\ is not implemented with "['] noop alias" |
last @ |
latest |
if |
if |
immediate |
immediate |
then |
then |
Line 44 does> ( name execution: -- )
|
Line 43 does> ( name execution: -- )
|
create field, ; |
create field, ; |
|
|
: field ( align1 offset1 align size "name" -- align2 offset2 ) \ gforth |
: field ( align1 offset1 align size "name" -- align2 offset2 ) \ gforth |
\G @code{name} execution: @var{addr1} -- @var{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 |
2 pick |
if \ field offset <> 0 |
if \ field offset <> 0 |
[IFDEF] (Field) |
[IFDEF] (Field) |
Line 58 does> ( name execution: -- )
|
Line 61 does> ( name execution: -- )
|
field, ; |
field, ; |
|
|
: end-struct ( align size "name" -- ) \ gforth |
: end-struct ( align size "name" -- ) \ gforth |
\g @code{name} execution: @var{addr1} -- @var{addr1+offset1}@* |
\g Define a structure/type descriptor @var{name} with alignment |
\g Create a field @var{name} with offset @var{offset1}, and the type |
\g @var{align} and size @var{size1} (@var{size} rounded up to be a |
\g given by @var{size align}. @var{offset2} is the offset of the |
\g multiple of @var{align}).@* |
\g next field, and @var{align2} is the alignment of all fields. |
\g @code{name} execution: -- @var{align size1}@* |
over nalign \ pad size to full alignment |
over nalign \ pad size to full alignment |
2constant ; |
2constant ; |
|
|
Line 98 cell% 2* 2constant double%
|
Line 101 cell% 2* 2constant double%
|
\g similar to @code{allocate}. |
\g similar to @code{allocate}. |
nip allocate ; |
nip allocate ; |
|
|
: %alloc ( size align -- addr ) \ gforth |
: %alloc ( align size -- addr ) \ gforth |
\g Allocate @var{size} address units with alignment @var{align}, |
\g Allocate @var{size} address units with alignment @var{align}, |
\g giving a data block at @var{addr}; @code{throw} an ior code |
\g giving a data block at @var{addr}; @code{throw} an ior code |
\g if not successful. |
\g if not successful. |