I have been using the EDO system by GT Hawkins, circa 1987, which
uses the second of the two creation conventions you show, namely:
STRUCT{
1 CELLS FIELD: P.X
1 CELLS FIELD: P.Y
}STRUCT POINT \ -- len
Instead of STRUCT{, EDO uses S{
Instead of }STRUCT, EDO uses }S
Instead of FIELD: or OFFSET, EDO uses :: which, as Stephen Pelc
notes, has exactly the same definition of FIELD:
It has a number of additional 'features' that lend it to use in a
variety of programming utilizations.
One of those additional features is a barebones vector array
creation that takes a basic structure and extends it for use in a
much larger environment.
My including this isn't meant to obscure the thread, but rather to
give another example of what's been done. Since there isn't a
standard at the moment, and since most all structure packages do
pretty much the same things, I haven't worried about changing the
names of the definitions in this package to conform to any other
system.
\ ---[ EDO - Extended Data Objects ]---------------------------------
\ Note that this listing is different from the basic EDO file that is
\ present on the Taygeta archive site, as I have included definitions
\ that I use in my day-to-day programming tasks
\ -------------------------------------------------------------------
: [EDO] ;
1 CONSTANT 1BYTE
cell CONSTANT 1WORD ( -- n )
8 CONSTANT 1FLOAT
: BYTE* ;
: WORD+ ( n -- n+WORD ) 1WORD + ;
: WORD* ( n -- n*WORD ) 1WORD * ;
: FLOAT* ( n -- n*FLOAT ) FLOATS ;
: DEF ( size -- ) CONSTANT ;
: S{ ( -- 0 ) 0 ;
: :: ( offset object-definition -- offset )
CREATE OVER , + DOES> @[EMAIL PROTECTED]
+ ;
: }S ( size -- ) CONSTANT ;
\ ---[ Define Vector/Operator ]--------------------------------------
: [] ( object-definition #objects -- )
OVER * CONSTANT \ define the vector
CREATE , \ define the vector operator
DOES> @[EMAIL PROTECTED]
* + ;
\ ---[ Extended Definitions ]----------------------------------------
1BYTE DEF {1BYTE}-DEF
2 BYTE* DEF {2BYTE}-DEF
4 BYTE* DEF {4BYTE}-DEF
1WORD DEF {1WORD}-DEF
2 WORD* DEF {2WORD}-DEF
8 BYTE* DEF {1FLOAT}-DEF
\ ---[ Usage Example ]-----------------------------------------------
\ Define the structure
S{
{1BYTE}-DEF :: p.red
{1BYTE}-DEF :: p.green
{1BYTE}-DEF :: p.blue
}S palette-obj
\ Define a vector array of this structure
palette-obj 256 [] palette[]-obj palette-ndx
\ Create the array in the dictionary
create Palette[] here palette[]-obj dup allot 0 fill
\ Access the vector array
: GetPalette \ loads palette data from the VGA
256 0 do
i $03C7 P!
$03C9 P@[EMAIL PROTECTED]
Palette[] i palette-ndx p.red C!
$03C9 P@[EMAIL PROTECTED]
Palette[] i palette-ndx p.green C!
$03C9 P@[EMAIL PROTECTED]
Palette[] i palette-ndx p.blue C!
loop
;
: SetPalette \ sets VGA palette to data in Palette[]
256 0 do
i $03C8 P!
Palette[] i palette-ndx
dup p.red C@[EMAIL PROTECTED]
$03C9 P!
dup p.green C@[EMAIL PROTECTED]
$03C9 P!
p.blue C@[EMAIL PROTECTED]
$03C9 P!
loop
;


|