dq NEWLINE
dq EXIT
+;; The INTERPRET word reads and interprets user input. It's behavior depends on
+;; the current STATE. It provides special handling for integers. (TODO)
+forth INTERPRET, 'INTERPRET'
+ dq READ_WORD
+ dq FIND
+ dq TCFA
+ dq EXEC
+ dq EXIT
+
;; .U prints the value on the stack as an unsigned integer in hexadecimal.
forth_asm DOTU, '.U'
mov [.length], 0
pop rsi
next
+;; Takes a value and an address, and stores the value at the given address.
+forth_asm PUT, '!'
+ pop rbx ; Address
+ pop rax ; Value
+ mov [rbx], rax
+ next
+
+;; Takes an address and returns the value at the given address.
+forth_asm GET, '@'
+ pop rax
+ mov rax, [rax]
+ push rax
+ next
+
+;; Get the location of the STATE variable. It can be set with '!' and read with
+;; '@'.
+forth STATE, 'STATE'
+ dq LIT, var_STATE
+ dq EXIT
+
forth MAIN, 'MAIN'
dq HELLO
- dq READ_WORD, FIND, TCFA, EXEC
- dq BRANCH, -8 * 5
+ dq INTERPRET
+ dq BRANCH, -8 * 2
dq TERMINATE
segment readable writable
latest_entry dq initial_latest_entry
+;; The STATE variable is 0 when the interpreter is executing, and non-zero when
+;; it is compiling.
+var_STATE dq 0
+
FIND.rsi dq ?
READ_WORD.rsi dq ?