change %ALLOT to return the aligned address of the data structure

This commit is contained in:
Jesse D. McDonald 2020-10-23 23:33:14 -05:00
parent 21eb4fafc4
commit 688fe7369e
1 changed files with 10 additions and 3 deletions

View File

@ -1451,9 +1451,16 @@ VARIABLE TOTAL
: ENDSTRUCT ( align offset "<spaces?>name" -- ) : ENDSTRUCT ( align offset "<spaces?>name" -- )
OVER ALIGNED-TO 2CONSTANT ; 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 \ Reserve data or heap space for a data structure given alignment and size
: %ALLOT ( align bytes -- a-addr ) SWAP ALIGN-TO ALLOT ; \ It is assumed that ALLOCATE (but not ALLOT) returns an address suitably
: %ALLOCATE ( align bytes -- a-addr ) NIP ALLOCATE ; \ 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 >>SYSTEM
@ -1821,7 +1828,7 @@ ENDSTRUCT termios%
>>SYSTEM >>SYSTEM
CREATE SCRATCH-TERMIOS termios% %ALLOT termios% %ALLOT CONSTANT SCRATCH-TERMIOS
>>FORTH >>FORTH