From 688fe7369e468184283521e395abb0626d197475 Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Fri, 23 Oct 2020 23:33:14 -0500 Subject: [PATCH] change %ALLOT to return the aligned address of the data structure --- startup.4th | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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