Not logged in

Artifact 9d8b9f0bdde8914236c45f8033e0e842db986b49

File user/crc/comp.lang.forth/plainstruct.retro part of check-in [be937afc34] - Start adding ported code snippits from comp.lang.forth newsgroup. by crc on 2010-06-14 20:40:24. [annotate]


(    Title:  Plain Structures
      File:  plainstruct.fs
   Version:  1.0.1
   Adaptor:  David N. Williams
   License:  Public Domain
 Test file:  plainstruct-test.fs
  Log file:  plainstruct.log
   Revised:  June 14, 2010
)

decimal
: struct   ( -- 0 )  0 ;
: /struct: ( <"sizename"> u -- )  aligned constant ;
: +field   ( offset size <"name"> -- offset+size )
  ` : over .data + ` .data ` + ` ; ;
: cfield:  ( offset <"name"> -- offset+1char )
  1 +field ;
: field:  ( offset <"name">  -- offset+1cell )
  1 +field ;
: 2field:  ( offset <"name">  -- offset+2cells )
  2 +field ;
: sfield:  ( offset <"name">  -- offset+2cells )
  2 +field ;



struct ( point) 
   1 +field >x 
   1 +field >y 
   1 +field >plotchar 
         /struct: /point 

create mypoint /point allot
     15 mypoint >x !
     22 mypoint >y !
     'o mypoint >plotchar !

: mypoint@  ( -- x y plotchar /point ) 
   mypoint push 
   r >x @ 
   r >y @ 
   pop >plotchar @ 
   /point ;