"STRUCT - simple struct implementation"

struct EXTENSIONS /* NEON-MOPS-MPE variant */
* STRUCT ( "name" -- here zero-offset )

begin definition of a new structure (mpe.000)
 : STRUCT CREATE  !CSP
   HERE
   0 DUP ,
 DOES>
   @
 ;

EXTENSIONS struct ordinary primitive

* END-STRUCT ( here some-offset -- )

terminate definition of a new structure (mpe.000)
 : END-STRUCT  SWAP !  ?CSP ;

EXTENSIONS struct ordinary primitive

* FIELD ( offset size "name" -- offset+size )

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>
    @ +
 ;

EXTENSIONS struct defining primitive

* SUBRECORD ( outer-offset "name" -- outer-offset here zero-offset )

begin definition of a subrecord (mpe.000)
 : STRUCT CREATE  
   HERE
   0 DUP ,
 DOES>
   @
 ;

EXTENSIONS struct ordinary primitive

* END-SUBRECORD ( outer-offset here some-offset -- outer-offset+some )

end definition of a subrecord (mpe.000)
 : END-SUBRECORD  TUCK SWAP !  + ;

EXTENSIONS struct ordinary primitive

* ARRAY-OF ( some-offset n len "name" -- some-offset )

a FIELD-array
 : ARRAY-OF * FIELD ;

EXTENSIONS struct ordinary primitive

* VARIANT ( outer-offset "name" -- outer-offset here zero-offset )

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 ;

EXTENSIONS struct ordinary primitive

* END-VARIANT ( outer-offset here some-offset -- outer-offset )

terminate definition of a new variant (mpe.000)
 : END-STRUCT  TUCK SWAP !  2DUP < IF NIP ELSE DROP THEN ;

EXTENSIONS struct ordinary primitive

* INSTANCE ( len "name" -- )

Create a named instance of a named structure.
 : INSTANCE  CREATE ALLOT ;

EXTENSIONS struct ordinary primitive

* INSTANCE-ADDR ( len -- addr )

Create nameless instance of a structure and return base address.
 : INSTANCE-ADDR  HERE SWAP ALLOT ;

EXTENSIONS struct ordinary primitive

/* traditional wording */
STRUCTURE

[] no special info, see general notes

EXTENSIONS struct defining primitive

* ENDSTRUCTURE ( here some-offset -- )

finalize a previously started STRUCTURE definition
 : ENDSTRUCTURE  SWAP !  ?CSP ;

EXTENSIONS struct ordinary primitive

SIZEOF

[] no special info, see general notes

EXTENSIONS struct compiling primitive

/* gforth compatibility */ CHAR%

[] no special info, see general notes

EXTENSIONS struct ordinary primitive

CELL%

[] no special info, see general notes

EXTENSIONS struct ordinary primitive

WCHAR%

[] no special info, see general notes

EXTENSIONS struct ordinary primitive

DOUBLE%

[] no special info, see general notes

EXTENSIONS struct ordinary primitive

FLOAT%

[] no special info, see general notes

EXTENSIONS struct ordinary primitive

SFLOAT%

[] no special info, see general notes

EXTENSIONS struct ordinary primitive

DFLOAT%

[] no special info, see general notes

EXTENSIONS struct ordinary primitive