| 1 : |
anton
|
1.1
|
\ implementation of Forth 200x structures |
| 2 : |
|
|
|
| 3 : |
|
|
\ Copyright (C) 2007 Free Software Foundation, Inc. |
| 4 : |
|
|
|
| 5 : |
|
|
\ This file is part of Gforth. |
| 6 : |
|
|
|
| 7 : |
|
|
\ Gforth is free software; you can redistribute it and/or |
| 8 : |
|
|
\ modify it under the terms of the GNU General Public License |
| 9 : |
anton
|
1.2
|
\ as published by the Free Software Foundation, either version 3 |
| 10 : |
anton
|
1.1
|
\ of the License, or (at your option) any later version. |
| 11 : |
|
|
|
| 12 : |
|
|
\ This program is distributed in the hope that it will be useful, |
| 13 : |
|
|
\ but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 : |
|
|
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 : |
|
|
\ GNU General Public License for more details. |
| 16 : |
|
|
|
| 17 : |
|
|
\ You should have received a copy of the GNU General Public License |
| 18 : |
anton
|
1.2
|
\ along with this program. If not, see http://www.gnu.org/licenses/. |
| 19 : |
anton
|
1.1
|
|
| 20 : |
pazsan
|
1.4
|
: standard+field ( n1 n2 "name" -- n3 ) \ X:structures plus-field |
| 21 : |
anton
|
1.1
|
over if |
| 22 : |
|
|
(field) over , |
| 23 : |
|
|
else |
| 24 : |
|
|
create dozerofield |
| 25 : |
|
|
then |
| 26 : |
|
|
+ ; |
| 27 : |
|
|
|
| 28 : |
pazsan
|
1.4
|
Defer +field |
| 29 : |
|
|
\ A number of things have field-like structure, but not |
| 30 : |
|
|
\ exactly field-like behavior. Objects, locals, etc. |
| 31 : |
|
|
\ Allow them to plug into +field. |
| 32 : |
|
|
|
| 33 : |
|
|
: standard:field ( -- ) |
| 34 : |
|
|
\g set +field to standard behavior |
| 35 : |
|
|
['] standard+field IS +field ; |
| 36 : |
|
|
|
| 37 : |
|
|
standard:field |
| 38 : |
|
|
|
| 39 : |
pazsan
|
1.3
|
: extend-structure ( n "name" -- struct-sys n ) \ Gforth |
| 40 : |
|
|
\g extend an existing structure |
| 41 : |
pazsan
|
1.4
|
standard:field >r 0 value lastxt >body r> ; |
| 42 : |
pazsan
|
1.3
|
|
| 43 : |
anton
|
1.1
|
: begin-structure ( "name" -- struct-sys 0 ) \ X:structures |
| 44 : |
pazsan
|
1.3
|
0 extend-structure ; |
| 45 : |
anton
|
1.1
|
|
| 46 : |
|
|
: end-structure ( struct-sys +n -- ) \ X:structures |
| 47 : |
|
|
swap ! ; |
| 48 : |
|
|
|
| 49 : |
|
|
: cfield: ( u1 "name" -- u2 ) \ X:structures |
| 50 : |
|
|
1 +field ; |
| 51 : |
|
|
|
| 52 : |
|
|
: field: ( u1 "name" -- u2 ) \ X:structures |
| 53 : |
|
|
aligned cell +field ; |
| 54 : |
|
|
|
| 55 : |
|
|
: 2field: ( u1 "name" -- u2 ) \ gforth |
| 56 : |
|
|
aligned 2 cells +field ; |
| 57 : |
|
|
|
| 58 : |
|
|
: ffield: ( u1 "name" -- u2 ) \ X:structures |
| 59 : |
|
|
faligned 1 floats +field ; |
| 60 : |
|
|
|
| 61 : |
|
|
: sffield: ( u1 "name" -- u2 ) \ X:structures |
| 62 : |
|
|
sfaligned 1 sfloats +field ; |
| 63 : |
|
|
|
| 64 : |
|
|
: dffield: ( u1 "name" -- u2 ) \ X:structures |
| 65 : |
|
|
dfaligned 1 dfloats +field ; |