disable all breakpoints initially
[rrq/rrqforth.git] / temp.asm
1 ;;; Managing a memory area for temporary "objects".
2 ;;;
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.
8
9
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.
14         dq 0 ; [16] Currently used.
15
16         WORD p_tempheld,'TEMPHELD',dovariable
17         ;; ( -- a )
18         ;; Marks the barrier for "held space"
19         dq 0 ; [24] Currently held.
20
21         WORD p_temp,'TEMP',fasm
22         ;; ( size -- addr )
23         ;; Allocate an object of given size
24         pushr rsi
25         cmp qword [p_objectspace_DFA+8],0
26         jg p_objecthole_initialized
27         ;; initialize object space
28         push qword [p_objectspace_DFA]
29         DOFORTH p_malloc
30         pop qword [p_objectspace_DFA+8]
31 p_objecthole_initialized:
32         mov rax,qword [rsp]
33         add rax,qword [p_objectspace_DFA+16]
34         cmp rax,qword [p_objectspace_DFA]
35         jl p_objecthole_from_tail
36         mov rax,qword [p_tempheld_DFA] ; cycling back to here
37         mov qword [p_objectspace_DFA+16],rax
38         add rax,qword [rsp]
39 p_objecthole_from_tail:
40         ;; rax = new usage count
41         mov rbx,qword [p_objectspace_DFA+16]
42         add rbx,qword [p_objectspace_DFA+8]
43         mov qword [rsp],rbx
44         mov qword [p_objectspace_DFA+16],rax
45         popr rsi
46         next
47
48         WORD p_str2temp,'STR>TEMP',fasm
49         ;; ( char* n -- char* n )
50         ;; Capture a given [n:char*] string as a new temp object with
51         ;; leading size cell.
52         pushr rsi
53         mov rax,qword [rsp]
54         add rax,8
55         push rax
56         DOFORTH p_temp          ; ( -- char* n  addr )
57         pop rax
58         pop rbx
59         mov qword[rax],rbx
60         add rax,8
61         pop rcx
62         push rax
63         push rbx
64         push rcx
65         push rax
66         push rbx                ; ( -- addr n char* addr n )
67         DOFORTH p_strncpy
68         popr rsi
69         next