introduced a hold area for temp space
[rrq/rrqforth.git] / temp.asm
index 8e0be257f11e4f7bbf022d82dba366f94528141c..7ece59078005ddfdcc740aba3d82c3afcbfa06f1 100644 (file)
--- a/temp.asm
+++ b/temp.asm
@@ -1,16 +1,23 @@
-;;; Managing a memory area for temporary objects
-;;;
-;;; A temporary object space is allocated from the current usage
-;;; level, or cycling back to be from the lowest space address when
-;;; the requested size exceeds the space edge.
+;;; Managing a memory area for temporary "objects".
 ;;;
+;;; Object space is allocated cyclically, starting subsequent to prior
+;;; allocation and cycling back when requested object size exceeds
+;;; the space edge. The "inital" part, which starts as empty, is
+;;; considered "held" space that is not reused when cycling back, and
+;;; apart from allowing for this, the space management is left open.
+
 
        WORD p_objectspace,'TEMPSPACE',dovariable
        ;; Holds size and address of the object space.
-       dq 104857600 ; [0] Total object space size (request size)
-       dq 0 ; [8] Object space base address
+       dq 1073741824 ; [0] Total object space size (request size)
+       dq 0 ; [8] Object space base address.
        dq 0 ; [16] Currently used.
 
+       WORD p_tempheld,'TEMPHELD',dovariable
+       ;; ( -- a )
+       ;; Marks the barrier for "held space"
+       dq 0 ; [24] Currently held.
+
        WORD p_temp,'TEMP',fasm
        ;; ( size -- addr )
        ;; Allocate an object of given size
@@ -26,14 +33,15 @@ p_objecthole_initialized:
        add rax,qword [p_objectspace_DFA+16]
        cmp rax,qword [p_objectspace_DFA]
        jl p_objecthole_from_tail
-       mov qword [p_objectspace_DFA+16],0
-       mov rax,qword [rsp]
+       mov rax,qword [p_tempheld_DFA] ; cycling back to here
+       mov qword [p_objectspace_DFA+16],rax
+       add rax,qword [rsp]
 p_objecthole_from_tail:
        ;; rax = new usage count
        mov rbx,qword [p_objectspace_DFA+16]
-       mov qword [p_objectspace_DFA+16],rax
        add rbx,qword [p_objectspace_DFA+8]
        mov qword [rsp],rbx
+       mov qword [p_objectspace_DFA+16],rax
        popr rsi
        next