From: Jonas Hvid Date: Sun, 8 Mar 2020 17:42:47 +0000 (+0100) Subject: Implement BUF" X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=f0df53c35124c9a5e2b045aba60b513faa344567;p=rrq%2Fjonasforth.git Implement BUF" This still doesn't actually work, because our definition of : doesn't make sense when we're reading input from the buffer. --- diff --git a/main.asm b/main.asm index 7443c48..a4db732 100644 --- a/main.asm +++ b/main.asm @@ -442,6 +442,47 @@ forth_asm READ_STRING, 'S"' next +;; BUF" works a bit like S, but it reads the string from the current input +;; buffer described in INPUT-BUFFER and INPUT-LENGTH. We use this fucntion in +;; sys.f to store strings. +forth_asm BUF_READ_STRING, 'BUF"' + push rsi + + ;; We borrow READ_STRING's buffer. They won't mind. + mov [READ_STRING.length], 0 + + ;; Skip space ([TODO]: Shouldn't we do this while parsing instead?) + inc [input_buffer] + dec [input_buffer_length] + +.read_char: + mov rbx, [input_buffer] + mov al, [rbx] + cmp al, '"' + je .done + + mov rdx, READ_STRING.buffer + add rdx, [READ_STRING.length] + mov [rdx], al + inc [READ_STRING.length] + + inc [input_buffer] + dec [input_buffer_length] + + jmp .read_char + +.done: + pop rsi + + ;; Skip closing " + inc [input_buffer] + dec [input_buffer_length] + + push READ_STRING.buffer + push [READ_STRING.length] + + next + ;; CREATE inserts a new header in the dictionary, and updates LATEST so that it ;; points to the header. To compile a word, the user can then call ',' to ;; continue to append data after the header. diff --git a/sys.f b/sys.f index 6b13ff9..27d540a 100644 --- a/sys.f +++ b/sys.f @@ -1,4 +1,4 @@ -S" :" CREATE ] DOCOL +BUF" :" CREATE ] DOCOL READ-WORD CREATE LIT DOCOL , ]