From: Ralph Ronnquist Date: Tue, 18 May 2021 12:19:48 +0000 (+1000) Subject: Change word layout to more wasteful use of full cells. X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=3025dcd6895d494d9f5e700887033f2c315e06d2;p=rrq%2Frrqforth.git Change word layout to more wasteful use of full cells. Also added cross-pointers to simplify moving between tfa and cfa. --- diff --git a/machine.asm b/machine.asm index a8bfbd8..74b1060 100644 --- a/machine.asm +++ b/machine.asm @@ -103,30 +103,49 @@ macro DOFORTH label { ENDFORTH } -;;; ======================================== -;;; Macro WORD starts a FORTH word definition in this code -;;; previous_word = 0 ; Used for chaining the words IMMEDIATE = 1 ; optional flag (symbol) -macro WORD label, name, doer, flags { +;;; ======================================== +;;; Macro WORD starts a FORTH word definition in this code. +;;; The layout of a word is as follows: +;;; TFA: [8 bytes] pointer to previous word in the word list +;;; [8 bytes] pointer to the word's CFA +;;; [8 bytes] a flags field +;;; [8 bytes] the length of the word's pname +;;; [varying] the word's pname +;;; [1 byte] NUL -- making an asciiz of the pname +;;; ;;[? bytes] 0-7 bytes for address alignment to [disabled] +;;; [8 bytes] pointer to the word's TFA +;;; OFF: [8 bytes] the DOES offset for the word +;;; CFA: [8 bytes] pointer to the word's "doer" code +;;; DFA: [? bytes] the word's data field + +macro WORD label, name, doer, flags, previous, offset { + local pname ;; align 8 label#_TFA: ;; TFA - dq previous_word + if previous eq + dq previous_word + else + dq previous + end if previous_word = label#_TFA ;; PFA + dq label#_CFA ; link to CFA of word + dq flags + 0 label#_PFA: - db flags + 0 - db label - $ - 2 + dq pname - $ - 8 db name - db 0 +pname: db 0 ; extra NUL byte ;; align 8 - + dq label#_TFA ; link to TFA of word label#_OFF: - dq 0 ; The DOES offset. Defaults to 0. + dq offset + 0 ; The DOES offset. Defaults to 0. ;; also CFA = pointer to "doer" +label#_CFA: label: if doer eq dq doforth @@ -141,6 +160,39 @@ label: label#_DFA: } +macro tfa2cfa reg { + mov reg,qword [reg+8] +} +macro tfa2dfa reg { + tfa2cfa reg + add reg,8 +} +macro tfa2pfa reg { + add reg,24 +} +macro tfa2pname reg { + add reg,32 +} +macro cfa2tfa reg { + sub reg,16 + mov reg,qword [reg] +} +macro cfa2dfa reg { + add reg,8 +} +macro dfa2cfa reg { + sub reg,8 +} +macro dfa2tfa reg { + sub reg,24 + mov reg,qword [reg] +} +macro pushpname rg { ; ( reg -- chars* length ) + add rg,8 + push rg + sub rg,8 + push qword [rg] +} ;;; ======================================== ;;; The BLOCK macro lays out the length for a subsequent block to the ;;; given label. @@ -151,11 +203,12 @@ datastart: } ;;; ======================================== -;;; The STRING macro lays out length byte and data for s short string +;;; The STRING macro lays out length cell and data for several string +;;; components. macro STRING [data] { common local datastart, dataend - db dataend - datastart + dq dataend - datastart datastart: forward db data