From: Ralph Ronnquist Date: Fri, 4 Jun 2021 01:47:54 +0000 (+1000) Subject: Changed to use "cyclic' temporary block allocation for strings X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=42844a6fe395162a374bd7bb6e8ed9a04b8d580c;p=rrq%2Frrqforth.git Changed to use "cyclic' temporary block allocation for strings --- diff --git a/rrqforth b/rrqforth index df86d14..7d58efd 100755 Binary files a/rrqforth and b/rrqforth differ diff --git a/rrqforth.asm b/rrqforth.asm index f0ef63a..b06fed1 100644 --- a/rrqforth.asm +++ b/rrqforth.asm @@ -161,6 +161,7 @@ include 'stack.asm' include 'math.asm' include 'logic.asm' include 'stdio.asm' +include 'temp.asm' include 'compile.asm' WORD p_program_version,'PROGRAM_VERSION',dostring diff --git a/stdio.asm b/stdio.asm index eeac438..12c0ed4 100644 --- a/stdio.asm +++ b/stdio.asm @@ -214,7 +214,9 @@ p_read_word_nomore: WORD p_double_quote,'"',fasm ;; " (fool emacs) ;; ( -- char* n ) - ;; Scan to double quote in stream buffer, putting the string on PAD + ;; Scan to double quote in stream buffer, putting the string + ;; on PAD, plus an extra NUL, then copy that into a new temp + ;; object, but exclude the NUL from the returned count, n. pushr rsi push p_pad_DFA push 0 @@ -232,6 +234,14 @@ p_double_quote_loop: jmp p_double_quote_loop p_double_quote_endquote: p_double_quote_endstream: + lea rdi,[p_pad_DFA] + add rdi,qword [rsp] + stosb + ;; copy PAD string into new temp object + inc qword [rsp] + DOFORTH p_str2temp + dec qword [rsp] + add qword [rsp+8],8 ; adjust pointer popr rsi next diff --git a/temp.asm b/temp.asm new file mode 100644 index 0000000..9759f54 --- /dev/null +++ b/temp.asm @@ -0,0 +1,50 @@ +;;; 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. +;;; + + 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. + + WORD p_temp,'TEMP',fasm + ;; ( size -- addr ) + ;; Allocate an object of given size + pushr rsi + cmp qword [p_objectspace_DFA+8],0 + jg p_objecthole_initialized + ;; initialize object space + push qword [p_objectspace_DFA] + DOFORTH p_malloc + pop qword [p_objectspace_DFA+8] +p_objecthole_initialized: + mov rax,qword [rsp] + 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] +p_objecthole_from_tail: + 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 + popr rsi + next + + WORD p_str2temp,'STR>TEMP' + ;; ( 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