diff --git a/startup.4th b/startup.4th index eb40c71..86fe31a 100644 --- a/startup.4th +++ b/startup.4th @@ -1451,9 +1451,16 @@ VARIABLE TOTAL : ENDSTRUCT ( align offset "name" -- ) OVER ALIGNED-TO 2CONSTANT ; +\ Accessors for type descriptors +: %SIZEOF ( align size -- size ) NIP ; +: %ALIGNOF ( align size -- align ) DROP ; + \ Reserve data or heap space for a data structure given alignment and size -: %ALLOT ( align bytes -- a-addr ) SWAP ALIGN-TO ALLOT ; -: %ALLOCATE ( align bytes -- a-addr ) NIP ALLOCATE ; +\ It is assumed that ALLOCATE (but not ALLOT) returns an address suitably +\ aligned for any primitive data type; %ALLOCATE is not suitable for data +\ structures with unusually high alignment requirements +: %ALLOT ( align bytes -- a-addr ) SWAP ALIGN-TO HERE SWAP ALLOT ; +: %ALLOCATE ( align bytes -- a-addr ) %SIZEOF ALLOCATE ; >>SYSTEM @@ -1821,7 +1828,7 @@ ENDSTRUCT termios% >>SYSTEM -CREATE SCRATCH-TERMIOS termios% %ALLOT +termios% %ALLOT CONSTANT SCRATCH-TERMIOS >>FORTH