mirror of
https://github.com/kanaka/mal.git
synced 2024-09-21 10:37:58 +03:00
Fixes for long strings
Extra code in string_append_char, string_append_string, and print_string to handle long strings. Printing *env* no longer produces segfault.
This commit is contained in:
parent
17d45192b9
commit
b43cd5b639
@ -431,14 +431,39 @@ raw_to_symbol:
|
||||
|
||||
;; Appends a character to a string
|
||||
;; Input: Address of string in RSI, character in CL
|
||||
;;
|
||||
;; Modifies
|
||||
;; RAX
|
||||
string_append_char:
|
||||
push rsi
|
||||
; Get the end of the string
|
||||
.get_end:
|
||||
mov rax, [rsi + Array.next]
|
||||
cmp rax, 0
|
||||
jz .got_dest_end
|
||||
mov rsi, rax
|
||||
jmp .get_end
|
||||
.got_dest_end:
|
||||
|
||||
; Check if this chunk is full
|
||||
mov eax, DWORD [rsi + Array.length]
|
||||
cmp eax, (array_chunk_len*8)
|
||||
jne .append
|
||||
|
||||
; full, need to allocate another
|
||||
call alloc_array
|
||||
mov [rsi + Array.next], rax
|
||||
mov rsi, rax
|
||||
xor eax, eax ; Set length to zero
|
||||
.append:
|
||||
inc eax
|
||||
mov DWORD [rsi + Array.length], eax
|
||||
dec eax
|
||||
add rax, rsi
|
||||
add rax, Array.data ; End of data
|
||||
mov [rax], BYTE cl
|
||||
|
||||
pop rsi ; Restore original value
|
||||
ret
|
||||
|
||||
;; Appends a string to the end of a string
|
||||
@ -469,6 +494,9 @@ string_append_string:
|
||||
mov r8d, DWORD [rbx + Array.length]
|
||||
add r11, r8
|
||||
|
||||
cmp r8d, 0
|
||||
je .return ; Appending zero-size array
|
||||
|
||||
; Find the end of the string in RSI
|
||||
; and put the address of the Array object into rax
|
||||
mov rax, rsi
|
||||
@ -523,6 +551,7 @@ string_append_string:
|
||||
cmp r8, r9
|
||||
jne .copy_loop ; Next byte
|
||||
|
||||
.alloc_dest:
|
||||
; Reached the end of the destination
|
||||
; Need to allocate another Array
|
||||
push rax
|
||||
@ -541,6 +570,7 @@ string_append_string:
|
||||
|
||||
mov r9, rax
|
||||
add r9, Array.size
|
||||
jmp .copy_loop
|
||||
|
||||
.finished:
|
||||
; Compare r8 (destination) with data start
|
||||
@ -550,7 +580,7 @@ string_append_string:
|
||||
inc r8
|
||||
; r8 now contains length
|
||||
mov DWORD [rax + Array.length], r8d
|
||||
|
||||
.return:
|
||||
ret
|
||||
|
||||
;; ------------------------------------------
|
||||
@ -568,10 +598,18 @@ print_string:
|
||||
cmp al, maltype_string
|
||||
jne .error
|
||||
|
||||
.print_chunk:
|
||||
; write(1, string, length)
|
||||
push rsi
|
||||
mov edx, [rsi + Array.length] ; number of bytes
|
||||
add rsi, Array.data ; address of raw string to output
|
||||
call print_rawstring
|
||||
pop rsi
|
||||
|
||||
; Check if this is the end
|
||||
mov rsi, QWORD [rsi + Array.next]
|
||||
cmp rsi, 0
|
||||
jne .print_chunk ; next chunk
|
||||
|
||||
; Restore registers
|
||||
pop rsi
|
||||
|
Loading…
Reference in New Issue
Block a user