mirror of
https://github.com/samsonjs/sectorforth.git
synced 2026-03-25 09:35:47 +00:00
Calculate defword entry length with %strlen
This commit is contained in:
parent
d55d6bc190
commit
e5b0b97643
1 changed files with 23 additions and 22 deletions
|
|
@ -59,13 +59,14 @@ LENMASK equ 0x1f
|
||||||
%define link 0
|
%define link 0
|
||||||
|
|
||||||
; 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 2-3 0 ; name, label, flags
|
||||||
word_%3:
|
word_%2:
|
||||||
dw link ; link to previous word
|
dw link ; link to previous word
|
||||||
%define link word_%3
|
%define link word_%2
|
||||||
db %4+%2 ; flags+length
|
%strlen %%len %1
|
||||||
|
db %3+%%len ; flags+length
|
||||||
db %1 ; name
|
db %1 ; name
|
||||||
%3: ; code starts here
|
%2: ; code starts here
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
; NEXT advances execution to the next word. The actual code is
|
; NEXT advances execution to the next word. The actual code is
|
||||||
|
|
@ -85,25 +86,25 @@ word_%3:
|
||||||
; nand ( x1 x2 -- n ) NAND the two values at the top of the stack
|
; nand ( x1 x2 -- n ) NAND the two values at the top of the stack
|
||||||
; exit ( r:addr -- ) Resume execution at address at the top of
|
; exit ( r:addr -- ) Resume execution at address at the top of
|
||||||
; the return stack
|
; the return stack
|
||||||
defword "@",1,FETCH
|
defword "@",FETCH
|
||||||
pop bx
|
pop bx
|
||||||
push word [bx]
|
push word [bx]
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword "!",1,STORE
|
defword "!",STORE
|
||||||
pop bx
|
pop bx
|
||||||
pop word [bx]
|
pop word [bx]
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword "sp@",3,SPFETCH
|
defword "sp@",SPFETCH
|
||||||
push sp
|
push sp
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword "rp@",3,RPFETCH
|
defword "rp@",RPFETCH
|
||||||
push bp
|
push bp
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword "0=",2,ZEROEQUALS
|
defword "0=",ZEROEQUALS
|
||||||
pop ax
|
pop ax
|
||||||
test ax,ax
|
test ax,ax
|
||||||
setnz al ; AL=0 if ZF=1, else AL=1
|
setnz al ; AL=0 if ZF=1, else AL=1
|
||||||
|
|
@ -112,14 +113,14 @@ word_%3:
|
||||||
push ax
|
push ax
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword "+",1,PLUS
|
defword "+",PLUS
|
||||||
pop bx
|
pop bx
|
||||||
pop ax
|
pop ax
|
||||||
add ax,bx
|
add ax,bx
|
||||||
push ax
|
push ax
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword "nand",4,NAND
|
defword "nand",NAND
|
||||||
pop bx
|
pop bx
|
||||||
pop ax
|
pop ax
|
||||||
and ax,bx
|
and ax,bx
|
||||||
|
|
@ -127,7 +128,7 @@ word_%3:
|
||||||
push ax
|
push ax
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword "exit",4,EXIT
|
defword "exit",EXIT
|
||||||
xchg sp,bp ; swap SP and BP, SP controls return stack
|
xchg sp,bp ; swap SP and BP, SP controls return stack
|
||||||
pop si ; pop address to next word
|
pop si ; pop address to next word
|
||||||
xchg sp,bp ; restore SP and BP
|
xchg sp,bp ; restore SP and BP
|
||||||
|
|
@ -139,15 +140,15 @@ word_%3:
|
||||||
; TIB could be left out. But it is exposed so that sectorforth
|
; TIB could be left out. But it is exposed so that sectorforth
|
||||||
; code that accesses the parse area can be written in an idiomatic
|
; code that accesses the parse area can be written in an idiomatic
|
||||||
; fashion (e.g. TIB >IN @ +).
|
; fashion (e.g. TIB >IN @ +).
|
||||||
defword "tib",3,TIBVAR
|
defword "tib",TIBVAR
|
||||||
push word TIB
|
push word TIB
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword "state",5,STATEVAR
|
defword "state",STATEVAR
|
||||||
push word STATE
|
push word STATE
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
defword ">in",3,TOINVAR
|
defword ">in",TOINVAR
|
||||||
push word TOIN
|
push word TOIN
|
||||||
NEXT
|
NEXT
|
||||||
|
|
||||||
|
|
@ -158,12 +159,12 @@ next:
|
||||||
jmp ax ; jump directly to it
|
jmp ax ; jump directly to it
|
||||||
|
|
||||||
; Words and data space for the HERE and LATEST variables.
|
; Words and data space for the HERE and LATEST variables.
|
||||||
defword "here",4,HEREVAR
|
defword "here",HEREVAR
|
||||||
push word HERE
|
push word HERE
|
||||||
NEXT
|
NEXT
|
||||||
HERE: dw start_HERE
|
HERE: dw start_HERE
|
||||||
|
|
||||||
defword "latest",6,LATESTVAR
|
defword "latest",LATESTVAR
|
||||||
push word LATEST
|
push word LATEST
|
||||||
NEXT
|
NEXT
|
||||||
LATEST: dw word_SEMICOLON ; initialized to last word in dictionary
|
LATEST: dw word_SEMICOLON ; initialized to last word in dictionary
|
||||||
|
|
@ -173,7 +174,7 @@ LATEST: dw word_SEMICOLON ; initialized to last word in dictionary
|
||||||
;
|
;
|
||||||
; KEY waits for a key press and pushes its scan code (AH) and
|
; KEY waits for a key press and pushes its scan code (AH) and
|
||||||
; ASCII character (AL) to the stack, both in a single cell.
|
; ASCII character (AL) to the stack, both in a single cell.
|
||||||
defword "key",3,KEY
|
defword "key",KEY
|
||||||
mov ah,0
|
mov ah,0
|
||||||
int 0x16
|
int 0x16
|
||||||
push ax
|
push ax
|
||||||
|
|
@ -181,7 +182,7 @@ LATEST: dw word_SEMICOLON ; initialized to last word in dictionary
|
||||||
|
|
||||||
; EMIT writes to the screen the ASCII character corresponding to
|
; EMIT writes to the screen the ASCII character corresponding to
|
||||||
; the lowest 8 bits of the value at the top of the stack.
|
; the lowest 8 bits of the value at the top of the stack.
|
||||||
defword "emit",4,EMIT
|
defword "emit",EMIT
|
||||||
pop ax
|
pop ax
|
||||||
call writechar
|
call writechar
|
||||||
NEXT
|
NEXT
|
||||||
|
|
@ -190,7 +191,7 @@ LATEST: dw word_SEMICOLON ; initialized to last word in dictionary
|
||||||
; creates a dictionary entry for it, writes machine code to jump
|
; creates a dictionary entry for it, writes machine code to jump
|
||||||
; to DOCOL, updates LATEST and HERE, and switches to compilation
|
; to DOCOL, updates LATEST and HERE, and switches to compilation
|
||||||
; state.
|
; state.
|
||||||
defword ":",1,COLON
|
defword ":",COLON
|
||||||
call token ; parse word from input
|
call token ; parse word from input
|
||||||
push si
|
push si
|
||||||
mov si,di ; set parsed word as string copy source
|
mov si,di ; set parsed word as string copy source
|
||||||
|
|
@ -240,7 +241,7 @@ DOCOL:
|
||||||
; of EXIT to the end of a new word definition, makes the word
|
; of EXIT to the end of a new word definition, makes the word
|
||||||
; visible in the dictionary, and switches back to interpretation
|
; visible in the dictionary, and switches back to interpretation
|
||||||
; state.
|
; state.
|
||||||
defword ";",1,SEMICOLON,F_IMMEDIATE
|
defword ";",SEMICOLON,F_IMMEDIATE
|
||||||
mov bx,[LATEST]
|
mov bx,[LATEST]
|
||||||
and byte [bx+2],~F_HIDDEN ; reveal new word
|
and byte [bx+2],~F_HIDDEN ; reveal new word
|
||||||
mov byte [STATE],0 ; switch to interpretation state
|
mov byte [STATE],0 ; switch to interpretation state
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue