plus-field:useful — ordinary primitive
EXTENSIONS
+FIELD
( offset "name" -- offset )( | ) ; |
; |
created a new name with an OFFSET-RT runtime using the given offset. Leave the offset-value untouched, so it can be modified with words like CHAR+ and CELL+ and SFLOAT+ ; This word is the simplest way to declared structure access words in forth - the two STRUCT modules contain a more elaborate series of words. Use this one like:
0 ( a fresh definition is started ) +FIELD zapp.a+ CHAR+ ( zero offset from the base of the struct ) +FIELD zapp.b+ CELL+ ( no alignment, starts off at 1 from base ) +FIELD zapp+ DROP ( store size of complete zap structure ) 0 zapp+ ( extend the zap structure ) +FIELD zappx.c+ CELL+ ( a new field ) +FIELD zappx+ DROP ( and save it again ) CREATE zapp1 0 zapp+ ALLOT ( a way to allocate a strucutre ) zapp2 zapp.b+ @ ( read a value from the field ) 16 zapp2 zapp.b+ ! ( store a value in there )
this form is not the traditional form used in forth, it is however quite simple. Use the simplefield declaration with /FIELD to be compatible with traditional styles that build on top of sizeof constants in forth (which are not part of the ANS Forth standard).