X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=temp.asm;h=932b1bb3e9e26bf4bf9d3fce01cbc231bbc171af;hb=cabd8413c10848728efcc2b869f631294f755d4d;hp=9759f546eee4e62dbbbb1e6079f15ecac59d3b28;hpb=42844a6fe395162a374bd7bb6e8ed9a04b8d580c;p=rrq%2Frrqforth.git diff --git a/temp.asm b/temp.asm index 9759f54..932b1bb 100644 --- a/temp.asm +++ b/temp.asm @@ -1,15 +1,24 @@ -;;; 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 ; Total object space size (request size) - dq 0 ; Object space base address - dq 0 ; Currently used. + dq 1073741824 ; [0] Total object space size (request size) + dq 0 ; [8] Object space base address. + + WORD p_tempused,'TEMPUSED',dovariable + 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 ) @@ -22,29 +31,45 @@ DOFORTH p_malloc pop qword [p_objectspace_DFA+8] p_objecthole_initialized: + mov rax,qword [p_tempheld_DFA] + cmp rax,qword [p_tempused_DFA] + jl p_objecthole_recycle mov rax,qword [rsp] - add rax,qword [p_objectspace_DFA+16] + add rax,qword [p_tempused_DFA] 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 +p_objecthole_recycle: + mov qword [p_tempused_DFA],rax + add rax,qword [rsp] p_objecthole_from_tail: - mov rbx,qword [p_objectspace_DFA+16] - mov qword [p_objectspace_DFA+16],rax + ;; rax = new usage count + mov rbx,qword [p_tempused_DFA] add rbx,qword [p_objectspace_DFA+8] mov qword [rsp],rbx + mov qword [p_tempused_DFA],rax popr rsi next - WORD p_str2temp,'STR>TEMP' + WORD p_str2temp,'STR>TEMP',fasm ;; ( char* n -- char* n ) ;; Capture a given [n:char*] string as a new temp object with ;; leading size cell. - dq p_dup, p_gtR ; size - dq p_dup, p_temp - dq p_dup, p_gtR ; address - dq p_2dup, p_put - dq p_literal, 8, p_plus - dq p_swap, p_strncpy - dq p_Rgt, p_Rgt, p_swap - dq p_exit + pushr rsi + mov rax,qword [rsp] + add rax,8 + push rax + DOFORTH p_temp ; ( -- char* n addr ) + pop rax + pop rbx + mov qword[rax],rbx + add rax,8 + pop rcx + push rax + push rbx + push rcx + push rax + push rbx ; ( -- addr n char* addr n ) + DOFORTH p_strncpy + popr rsi + next