-;; 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
- dq PAIRDUP
- ;; Stack is (word length word length).
- dq FIND ; Try to find word
- dq DUP_
- dq ZBRANCH, 8 * 20 ; Check if word is found
-
- ;; - Word is found -
-
- dq STATE, GET, ZBRANCH, 8 * 9 ; Check whether we are in compilation or immediate mode
-
- ;; (Word found, compilation mode)
- dq DUP_, IS_IMMEDIATE, NOT_, ZBRANCH, 8 * 4 ; If the word is immediate, continue as we would in immediate mode
-
- ;; Otherwise, we want to compile this word
- dq TCFA
- dq COMMA
- dq EXIT
-
- ;; (Word found, immediate mode)
- ;; Execute word
- dq TCFA
- ;; Stack is (word length addr)
- dq SWAP, DROP
- dq SWAP, DROP
- ;; Stack is (addr)
- dq EXEC
- dq EXIT
-
- ;; - No word is found, assume it is an integer literal -
- ;; Stack is (word length addr)
- dq DROP
- dq PARSE_NUMBER
-
- dq STATE, GET, ZBRANCH, 8 * 5 ; Check whether we are in compilation or immediate mode
-
- ;; (Number, compilation mode)
- dq LIT, LIT, COMMA
- dq COMMA
- dq EXIT
-
- ;; (Number, immediate mode)
- dq EXIT
-