(C) 2000 - 2001 Guido Draheim
lisence: GNU LGPL, non-substantial parts may promote to any opensource.org approved license.
description: "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
STRUCT
( "name" -- here zero-offset )( | ) ; |
; |
begin definition of a new structure (mpe.000)
: STRUCT CREATE !CSP HERE 0 DUP , DOES> @ ;
EXTENSIONS
END-STRUCT
( here some-offset -- )( | ) ; |
; |
terminate definition of a new structure (mpe.000)
: END-STRUCT SWAP ! ?CSP ;
EXTENSIONS
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
SUBRECORD
( outer-offset "name" -- outer-offset here zero-offset )( | ) ; |
; |
begin definition of a subrecord (mpe.000)
: STRUCT CREATE HERE 0 DUP , DOES> @ ;
EXTENSIONS
END-SUBRECORD
( outer-offset here some-offset -- outer-offset+some )( | ) ; |
; |
end definition of a subrecord (mpe.000)
: END-SUBRECORD TUCK SWAP ! + ;
EXTENSIONS
ARRAY-OF
( some-offset n len "name" -- some-offset )( | ) ; |
; |
a FIELD-array
: ARRAY-OF * FIELD ;
EXTENSIONS
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
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
INSTANCE
( len "name" -- )(
)
;
p4:"instance";
Create a named instance of a named structure.
: INSTANCE CREATE ALLOT ;
EXTENSIONS
INSTANCE-ADDR
( len -- addr )( | ) ; |
; |
Create nameless instance of a structure and return base address.
: INSTANCE-ADDR HERE SWAP ALLOT ;
EXTENSIONS
STRUCTURE
( "name" -- here zero-offset )exec( | ) ; |
; |
start a structure definition
: STRUCTURE: CREATE !CSP HERE 0 DUP , DOES> CREATE @ ALLOT ;FCode_RT (p4_structure_RT)
EXTENSIONS
ENDSTRUCTURE
( here some-offset -- )( | ) ; |
; |
finalize a previously started STRUCTURE definition
: ENDSTRUCTURE SWAP ! ?CSP ;
EXTENSIONS
SIZEOF
( "name" -- size )(
)
;
as:"sizeof";
get the size-value from a previous structure definition
: SIZEOF ' >BODY @ STATE @ IF [COMPILE] LITERAL THEN ; IMMEDIATEFCode_XE (p4_sizeof_XT)
EXTENSIONS
CHAR%
( .. )(
)
;
as:"char-percent";
ordinary primitive CHAR%
an executable word (no special usage info)
or wrapper call around p4_char_mod
EXTENSIONS
CELL%
( .. )(
)
;
as:"cell-percent";
ordinary primitive CELL%
an executable word (no special usage info)
or wrapper call around p4_cell_mod
EXTENSIONS
WCHAR%
( .. )(
)
;
as:"wchar-percent";
ordinary primitive WCHAR%
an executable word (no special usage info)
or wrapper call around p4_wchar_mod
EXTENSIONS
DOUBLE%
( .. )(
)
;
as:"double-percent";
ordinary primitive DOUBLE%
an executable word (no special usage info)
or wrapper call around p4_double_mod
EXTENSIONS
FLOAT%
( .. )(
)
;
as:"float-percent";
ordinary primitive FLOAT%
an executable word (no special usage info)
or wrapper call around p4_float_mod
EXTENSIONS
SFLOAT%
( .. )(
)
;
as:"sfloat-percent";
ordinary primitive SFLOAT%
an executable word (no special usage info)
or wrapper call around p4_sfloat_mod
EXTENSIONS
DFLOAT%
( .. )(
)
;
as:"dfloat-percent";
ordinary primitive DFLOAT%
an executable word (no special usage info)
or wrapper call around p4_dfloat_mod