"STRUCT - simple struct implementation"
struct
"struct" implements neon/mops/mpe-like structures.
"structs" implements fsl/mforth-like structures.
the two wordsets are designed to let the sub-words
to be used interchangably both inside STRUCT and
STRUCTURE definitions. They will also work inside
pfe's class-definitions btw.
The provided words try to be compatible
with the simple implementation guidelines as
provided in the survey at the comp.lang.forth.repository
(http://forth.sourceforge.net/word/structure)
and the documentation on MPE' forth's implementation
(/vol/c/Programme/PfwVfx/Doc/VfxMan.Htm/struct.html)
and the structs-source of the Forth Scientific Library
(lib/fsl/structs.fth)
plus some compatibility sugar for the gforth' struct
(gforth/struct.fs)
field-layout
PFA[0] has the offset (elsewhere for the method-table)
PFA[1] has the sizeof (may serve as minimalistic type-id)
struct-layout
PFA[0] unused (elswehere method-table or type-id)
PFA[1] has the sizeof (that is instantiated)
therefore SIZEOF is designed to give a nice result in
both places.
EXTENSIONS
begin definition of a new structure (mpe.000)
: STRUCT CREATE !CSP
HERE
0 DUP ,
DOES>
@
;
|
struct ordinary primitive
terminate definition of a new structure (mpe.000)
: END-STRUCT SWAP ! ?CSP ;
|
struct ordinary primitive
create a field - the workhorse for both STRUCT and STRUCTURE
implementations. The created fieldname is an OFFSET: -word
that memorizes the current offset in its PFA and will add
that offset on runtime. This forth-word does *not* align.
: FIELD CREATE
OVER ,
+
DOES>
@ +
;
|
struct defining primitive
begin definition of a subrecord (mpe.000)
: STRUCT CREATE
HERE
0 DUP ,
DOES>
@
;
|
struct ordinary primitive
end definition of a subrecord (mpe.000)
: END-SUBRECORD TUCK SWAP ! + ;
|
struct ordinary primitive
a FIELD -array
: ARRAY-OF * FIELD ;
|
struct ordinary primitive
Variant records describe an alternative view of the
current record or subrecord from the start to the current point.
The variant need not be of the same length, but the larger is taken
: VARIANT SUBRECORD ;
|
struct ordinary primitive
terminate definition of a new variant (mpe.000)
: END-STRUCT TUCK SWAP ! 2DUP < IF NIP ELSE DROP THEN ;
|
struct ordinary primitive
Create a named instance of a named structure.
: INSTANCE CREATE ALLOT ;
|
struct ordinary primitive
Create nameless instance of a structure and return base address.
: INSTANCE-ADDR HERE SWAP ALLOT ;
|
struct ordinary primitive
start a structure definition
: STRUCTURE: CREATE !CSP
HERE
0 DUP ,
DOES>
CREATE @ ALLOT
;
|
struct defining primitive
finalize a previously started STRUCTURE definition
: ENDSTRUCTURE SWAP ! ?CSP ;
|
struct ordinary primitive
get the size-value from a previous structure definition
: SIZEOF ' >BODY @ STATE @ IF [COMPILE] LITERAL THEN ; IMMEDIATE
|
struct compiling primitive
EXTENSIONS CHAR%
no special info, see general notes
struct ordinary primitive
EXTENSIONS CELL%
no special info, see general notes
struct ordinary primitive