1 ;;; Managing a memory area for temporary "objects".
3 ;;; Object space is allocated cyclically, starting subsequent to prior
4 ;;; allocation and cycling back when requested object size exceeds
5 ;;; the space edge. The "inital" part, which starts as empty, is
6 ;;; considered "held" space that is not reused when cycling back, and
7 ;;; apart from allowing for this, the space management is left open.
10 WORD p_objectspace,'TEMPSPACE',dovariable
11 ;; Holds size and address of the object space.
12 dq 1073741824 ; [0] Total object space size (request size)
13 dq 0 ; [8] Object space base address.
15 WORD p_tempused,'TEMPUSED',dovariable
16 dq 0 ; [16] Currently used.
18 WORD p_tempheld,'TEMPHELD',dovariable
20 ;; Marks the barrier for "held space"
21 dq 0 ; [24] Currently held.
23 WORD p_temp,'TEMP',fasm
25 ;; Allocate an object of given size
27 cmp qword [p_objectspace_DFA+8],0
28 jg p_objecthole_initialized
29 ;; initialize object space
30 push qword [p_objectspace_DFA]
32 pop qword [p_objectspace_DFA+8]
33 p_objecthole_initialized:
34 mov rax,qword [p_tempheld_DFA]
35 cmp rax,qword [p_tempused_DFA]
36 jl p_objecthole_recycle
38 add rax,qword [p_tempused_DFA]
39 cmp rax,qword [p_objectspace_DFA]
40 jl p_objecthole_from_tail
41 mov rax,qword [p_tempheld_DFA] ; cycling back to here
43 mov qword [p_tempused_DFA],rax
45 p_objecthole_from_tail:
46 ;; rax = new usage count
47 mov rbx,qword [p_tempused_DFA]
48 add rbx,qword [p_objectspace_DFA+8]
50 mov qword [p_tempused_DFA],rax
54 WORD p_str2temp,'STR>TEMP',fasm
55 ;; ( char* n -- char* n )
56 ;; Capture a given [n:char*] string as a new temp object with
62 DOFORTH p_temp ; ( -- char* n addr )
72 push rbx ; ( -- addr n char* addr n )