From: Jonas Hvid Date: Sun, 8 Dec 2019 17:32:21 +0000 (+0100) Subject: Add space for immediate flag X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=89a6a52d6128a4f9ac3c7aa26fc0df111e4160db;p=rrq%2Fjonasforth.git Add space for immediate flag We don't actually use this for anything yet. --- diff --git a/impl.asm b/impl.asm index f8093d0..5736469 100644 --- a/impl.asm +++ b/impl.asm @@ -15,12 +15,12 @@ segment readable executable find: ;; RSI contains the entry we are currently looking at .loop: - movzx rcx, byte [rsi + 8] ; Length of word being looked at + movzx rcx, byte [rsi + 16] ; Length of word being looked at cmp rcx, [.search_length] jne .next ; If the words don't have the same length, we have the wrong word ;; Otherwise, we need to compare strings - lea rdx, [rsi + 8 + 1] ; Location of character being compared in entry + lea rdx, [rsi + 16 + 1] ; Location of character being compared in entry mov rdi, [.search_buffer] ; Location of character being compared in search buffer .compare_char: mov al, [rdx] diff --git a/main.asm b/main.asm index d0c4391..8133cdc 100644 --- a/main.asm +++ b/main.asm @@ -32,11 +32,12 @@ macro popr x { ;; ;; This macro also defines a label LABEL_entry. initial_latest_entry = 0 -macro header label, name { +macro header label, name, immediate { local .string_end label#_entry: dq initial_latest_entry + dq 0 db .string_end - ($ + 1) db name .string_end: @@ -46,16 +47,16 @@ initial_latest_entry = label#_entry } ;; Define a Forth word that is implemented in assembly. See 'header' for details. -macro forth_asm label, name { - header label, name +macro forth_asm label, name, immediate { + header label, name, immediate dq .start .start: } ;; Define a Forth word that is implemented in Forth. (The body will be a list of ;; 'dq' statements.) -macro forth label, name { - header label, name +macro forth label, name, immediate { + header label, name, immediate dq DOCOL } @@ -117,7 +118,7 @@ forth_asm FIND, 'FIND' ;; entry. forth_asm TCFA, '>CFA' pop rax - add rax, 8 ; [rax] = length of name + add rax, 16 ; [rax] = length of name movzx rbx, byte [rax] inc rax add rax, rbx ; [rax] = codeword @@ -453,6 +454,10 @@ forth_asm CREATE, 'CREATE' mov [rdi], rax ; Insert link to previous entry mov [latest_entry], rdi ; Update LATEST to point to this word + add rdi, 8 + mov rax, 0 + mov [rdi], rax ; Set immediate flag + add rdi, 8 mov [rdi], rcx ; Insert length @@ -469,6 +474,21 @@ forth_asm CREATE, 'CREATE' next +;; Mark the last added word as immediate. +forth IMMEDIATE, 'IMMEDIATE', 1 + dq LIT, 1 + dq LATEST, GET + dq LIT, 8, PLUS + dq PUT + dq EXIT + +;; Return 0 if the given word is not immediate. +forth IS_IMMEDIATE, 'IMMEDIATE?' + dq FIND + dq LIT, 8, PLUS + dq GET + dq EXIT + forth MAIN, 'MAIN' dq HELLO dq INTERPRET