Changed to use "cyclic' temporary block allocation for strings
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 4 Jun 2021 01:47:54 +0000 (11:47 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 4 Jun 2021 01:47:54 +0000 (11:47 +1000)
rrqforth
rrqforth.asm
stdio.asm
temp.asm [new file with mode: 0644]

index df86d14c1efaee742189a9ef9d364880dec95af3..7d58efd65635dd025b48ff9b7bf625cc193db611 100755 (executable)
Binary files a/rrqforth and b/rrqforth differ
index f0ef63a248c087fb61bb38474fbe5faabbd0d879..b06fed1062ced657472f3362bc9071ed14d897e1 100644 (file)
@@ -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
index eeac43874b332fb92e81784c941da12be5169f4e..12c0ed45f46ee3a125704ee09ae52c3e29a9a299 100644 (file)
--- 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 (file)
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