X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=bootstrap.asm;h=1b8b65862947102c2c9117ae73eaf2890219d322;hb=850cb3e0bb2f5dc95bcce971d57f21fc5623c548;hp=1fc941a86e7eac80bb2615bccd64b33c16e0d960;hpb=a856c7d5b35de1b48bdd948186ec4a03f7c3685c;p=rrq%2Fjonasforth.git diff --git a/bootstrap.asm b/bootstrap.asm index 1fc941a..1b8b658 100644 --- a/bootstrap.asm +++ b/bootstrap.asm @@ -47,11 +47,10 @@ forth OUTOF_IMMEDIATE, ']' dq LIT, 1, STATE, PUT_BYTE dq EXIT -;; The INTERPRET word reads and interprets user input. It's behavior depends on -;; the current STATE. It provides special handling for integers. -forth INTERPRET, 'INTERPRET' - ;; Read word - dq READ_WORD +;; INTERPRET-WORD expects a word as a (buffer, length) pair on the stack. It +;; interprets and executes the word. It's behavior depends on the current STATE. +;; It provides special handling for integers. +forth INTERPRET_WORD, 'INTERPRET-WORD' dq PAIRDUP ;; Stack is (word length word length). dq FIND ; Try to find word @@ -95,3 +94,30 @@ forth INTERPRET, 'INTERPRET' ;; (Number, immediate mode) dq EXIT + +;; The INTERPRET word reads and interprets a single word from the user. +forth INTERPRET, 'INTERPRET' + dq READ_WORD + dq INTERPRET_WORD + dq EXIT + +;; INTERPRET_STRING is a variant of INTERPRET that reads from a string instead +;; of from the user. It takes a string as a (buffer, length) pair on the stack +;; and interprets the entire string, even if the string has more than one word. +forth INTERPRET_STRING, 'INTERPRET-STRING' + dq INPUT_LENGTH, PUT + dq INPUT_BUFFER, PUT + + ;; Check if the buffer is-non-empty + ;; [TODO] This probably won't work for strings with whitespace at the end. + dq INPUT_LENGTH, GET + dq ZBRANCH, 8 * 5 ; to EXIT + + dq READ_WORD + + dq INTERPRET_WORD + dq BRANCH, -8 * 7 ; to INPUT-LENGTH @ + + dq LIT, 0, INPUT_BUFFER, PUT + + dq EXIT