mirror of
https://github.com/samsonjs/sectorforth.git
synced 2026-03-25 09:35:47 +00:00
Simplify macro that links dictionary entries
This commit is contained in:
parent
845744842d
commit
d55d6bc190
1 changed files with 7 additions and 23 deletions
|
|
@ -52,33 +52,17 @@ F_IMMEDIATE equ 0x80
|
||||||
F_HIDDEN equ 0x40
|
F_HIDDEN equ 0x40
|
||||||
LENMASK equ 0x1f
|
LENMASK equ 0x1f
|
||||||
|
|
||||||
; Each dictionary entry needs a link to the previous entry. The
|
; Each dictionary entry needs a link to the previous entry. The
|
||||||
; initlink macro uses the nasm context stack to push a context and
|
; last entry links to zero, marking the end of the dictionary.
|
||||||
; define a context-local macro called %$link that represents the
|
; As dictionary entries are defined, link will be redefined to
|
||||||
; end of the dictionary.
|
; point to the previous entry.
|
||||||
%macro initlink 0
|
%define link 0
|
||||||
%push
|
|
||||||
%define %$link 0
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
initlink ; expand initlink so %$link is initialized
|
|
||||||
|
|
||||||
; The link macro links dictionary entries by pushing a new context
|
|
||||||
; and redefining %$link as a context-local label at the current
|
|
||||||
; location (address) in the code. It then writes a 16-bit data
|
|
||||||
; word with the value of %$link in the previous context (i.e. the
|
|
||||||
; previous expansion of link), effectively writing a link field to
|
|
||||||
; the previous location.
|
|
||||||
%macro link 0
|
|
||||||
%push
|
|
||||||
%$link:
|
|
||||||
dw %$$link
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
; defword lays out a dictionary entry where it is expanded.
|
; defword lays out a dictionary entry where it is expanded.
|
||||||
%macro defword 3-4 0 ; name, length, label, flags
|
%macro defword 3-4 0 ; name, length, label, flags
|
||||||
word_%3:
|
word_%3:
|
||||||
link ; link to previous word
|
dw link ; link to previous word
|
||||||
|
%define link word_%3
|
||||||
db %4+%2 ; flags+length
|
db %4+%2 ; flags+length
|
||||||
db %1 ; name
|
db %1 ; name
|
||||||
%3: ; code starts here
|
%3: ; code starts here
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue