commit cf4288984b845e4aea1d728c9131494ad2f8bc8d
parent 747fbd1eb7978fd3ac9bd701813184ed10462d19
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Mon, 18 Jul 2022 08:11:45 -0400
Make dusk.asm slightly tighter
And move "allot" to bootlo.
Diffstat:
2 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/dusk.asm b/dusk.asm
@@ -102,6 +102,7 @@ firstword 'bye', 3, word_bye
int 0x80
defword 'noop', 4, word_noop
+_ret: ; label for whenever you need to conditionally return
ret
defword 'main', 4, word_main
@@ -184,7 +185,7 @@ defword '(does)', 6, word_doesroutine
defword '(s)', 3, word_strlit
pop esi ; addr of str
pspush esi
- mov eax, 0
+ xor eax, eax
lodsb ; len
add esi, eax ; ret to PC right after str
jmp esi
@@ -417,6 +418,7 @@ defword 'c!', 2, word_cstore
defword 'c,', 2, word_cwrite
pspop eax
+_cwrite: ; al=c
mov esi, [here]
mov [esi], al
inc dword [here]
@@ -455,6 +457,7 @@ defword '+!', 2, word_addstore
defword ',', 1, word_write
pspop eax
+_write: ; eax=n
mov esi, [here]
mov [esi], eax
add dword [here], CELLSZ
@@ -543,23 +546,22 @@ litncode:
pspush 0
litncode_end:
defword 'litn', 4, word_litn
- pspush litncode ; src
- pspush litncode_end-litncode-CELLSZ ; len_of_code-len-of-imm
- call word_movewrite
+ mov esi, litncode ; src
+ mov ecx, litncode_end-litncode-CELLSZ ; len_of_code-len-of-imm
+ call _movewrite
jmp word_write
defword 'execute,', 8, word_executewrite
- pspush 0xe8 ; call opcode
- call word_cwrite
- mov eax, [ebp] ; absolute addr
+ mov al, 0xe8 ; call opcode
+ call _cwrite
+ pspop eax ; absolute addr
sub eax, [here] ; displacement
sub eax, 4 ; ... from *after* call/jmp op
- mov [ebp], eax
- jmp word_write
+ jmp _write
defword 'exit,', 5, word_exitwrite
- pspush 0xc3 ; ret opcode
- jmp word_cwrite
+ mov al, 0xc3 ; ret opcode
+ jmp _cwrite
defword 'current', 7, word_current
sysval current
@@ -582,13 +584,7 @@ defword 'compiling', 9, word_compiling
defword 'in<', 3, word_inrd
sysalias inrd
-defword 'allot', 5, word_allot
- pspop eax
- add dword [here], eax
- ret
-
-; : move ( src dst u -- ) ?dup if
-; A>r >r >A begin ( src ) c@+ Ac!+ next drop r>A then ;
+; ( src dst u -- )
defword 'move', 4, word_move
pspop ecx
pspop edi
@@ -596,7 +592,6 @@ defword 'move', 4, word_move
test ecx, ecx
jz _ret
rep movsb
-_ret:
ret
; ( a u -- )
@@ -605,6 +600,7 @@ defword 'move,', 5, word_movewrite
pspop esi
test ecx, ecx
jz _ret
+_movewrite: ; esi=a ecx=u
mov edi, [here]
add dword [here], ecx
rep movsb
@@ -654,7 +650,7 @@ defword 'curword', 7, word_curword
; ( -- str-or-0 )
defword 'maybeword', 9, word_maybeword
- ; save toptr so that it doesn't mess [inrd], which would be calling a word
+ ; save toptr so that it doesn't mess [inrd], which could be calling a word
; with to semantics
push dword [toptr]
mov dword [toptr], 0
@@ -692,7 +688,7 @@ _word_eof:
defword 'word', 4, word_word
call word_maybeword
test dword [ebp], -1
- jnz word_noop
+ jnz _ret
mov ecx, 13
mov esi, wordexpstr
jmp _errmsg
@@ -842,16 +838,16 @@ defword "'", 1, word_apos
; : entry ( str -- )
; c@+ tuck move, ( len ) current , c, here to current ;
defword 'entry', 5, word_entry
- mov esi, [ebp]
+ pspop esi
xor ecx, ecx
mov cl, [esi]
- inc dword [ebp]
- pspush ecx
- call word_tuck
- call word_movewrite
- call word_current
- call word_write
- call word_cwrite
+ inc esi
+ mov edx, ecx ; save len
+ call _movewrite
+ mov eax, [current]
+ call _write
+ mov eax, edx
+ call _cwrite
mov eax, [here]
mov [current], eax
ret
@@ -906,7 +902,7 @@ defword 'runword', 7, word_runword
call word_parse
pspop eax
test eax, eax
- jnz word_noop ; is a literal
+ jnz _ret ; is a literal
; not a literal
pspush curword
call word_find
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -4,6 +4,7 @@
: to+ ['] +! [to] ;
: to' ['] noop [to] ;
: to@ ['] @ [to] ;
+: allot to+ here ;
: compile ' litn ['] execute, execute, ; immediate
: if compile (?br) here 4 allot ; immediate
: ahead compile (br) here 4 allot ; immediate