minor improvements

This commit is contained in:
andromeda
2026-03-25 21:37:40 +01:00
parent 2960c1b795
commit 9becdea2b9

View File

@@ -667,18 +667,17 @@ tokenise:
push rdi push rdi
push rax push rax
push rdx push rdx
; TODO probably should not ignore null bytes mov rsi, whitespace_2 ; rsi -> list of whitespace bytes
mov rsi, whitespace_2 ; rsi -> list of whitespace (ignored) bytes mov rdi, 2 ; rdi = size of the list in bytes
mov rdi, 2 ; rdi = size of list in bytes
; dl = current byte ; dl = current byte
call elemb call elemb
; al = 0 if not whitespace, 1 if whitespace ; al = 0 if not whitespace, 1 if whitespace
cmp al, 1 ; check if current byte is whitespace test eax, 1 ; check if current byte is whitespace
pop rdx pop rdx ; dl = current byte
pop rax pop rax ; rax = number of tokens processed
pop rdi pop rdi ; rdi -> current byte of program
pop rsi pop rsi ; rsi -> last byte of program
je .skip_byte_whitespace jnz .skip_byte_whitespace
test byte [.expecting], E_OPERATOR ; check if an operator is expected test byte [.expecting], E_OPERATOR ; check if an operator is expected
jnz .operator ; if so, handle it jnz .operator ; if so, handle it
@@ -690,17 +689,19 @@ tokenise:
call print.debug call print.debug
mov rsi, .msg_comment mov rsi, .msg_comment
call print call print
pop rsi pop rsi ; rsi -> last byte of program
test byte [.expecting], E_COMMENT ; make sure a comment is expected test byte [.expecting], E_COMMENT ; make sure a comment is expected
jz .unexpected_comment ; if not, error jz .unexpected_comment ; if not, error
.comment_loop: .comment_loop:
; TODO range check rdi
mov dl, [rdi] ; dl = current byte mov dl, [rdi] ; dl = current byte
cmp dl, 0x0A ; if current byte is a newline cmp dl, 0x0A ; if current byte is a newline
je .comment_break ; then break je .comment_break ; then break
inc rdi ; point to next unread byte inc rdi ; point to next unread byte
cmp rdi, rsi
jge .break
jmp .comment_loop jmp .comment_loop
.comment_break: .comment_break:
jmp .loop jmp .loop
@@ -729,7 +730,7 @@ tokenise:
test byte [.expecting], E_COMMA ; make sure a comma was expected test byte [.expecting], E_COMMA ; make sure a comma was expected
jz .unexpected_comma ; if not, error jz .unexpected_comma ; if not, error
inc rdi inc rdi
mov [.expecting], E_WHITESPACE | E_OPERAND ; else, make operand expected mov byte [.expecting], E_WHITESPACE | E_OPERAND ; else, make operand expected
jmp .loop ; and loop jmp .loop ; and loop
.newline_mk_flags: .newline_mk_flags:
@@ -757,15 +758,12 @@ tokenise:
call print call print
pop rsi pop rsi
push rax mov rcx, rax ; rcx = number of tokens processed
xor eax, eax ; eax = number of bytes in operator xor eax, eax ; eax = number of bytes in operator
mov [.pending_operator], eax ; zero pending operator mov [.pending_operator], eax ; zero pending operator
.operator_loop: .operator_loop:
; TODO give this its own error ; TODO give this its own error
; TODO make this pop rax
cmp eax, 4 ; check that operator is short enough
jg .unexpected_operator ; if not, error
mov dl, [rdi] ; next byte mov dl, [rdi] ; next byte
@@ -781,8 +779,12 @@ tokenise:
mov [.pending_operator + eax], dl mov [.pending_operator + eax], dl
inc rax ; inc byte counter inc eax ; inc byte counter
inc rdi ; inc byte pointer inc rdi ; inc byte pointer
cmp eax, 4 ; check that operator is short enough
jg .unexpected_operator ; if not, error
cmp rdi, rsi
jge .break
jmp .operator_loop ; and loop jmp .operator_loop ; and loop
.operator_break: .operator_break:
@@ -792,10 +794,10 @@ tokenise:
mov edi, [.pending_operator] ; edi = operator to be searched mov edi, [.pending_operator] ; edi = operator to be searched
call identify_operator call identify_operator
; ax = operator's token ID ; ax = operator's token ID
mov cx, ax ; cx = operator's token ID for safe keeping push rcx
mov ecx, eax ; cx = operator's token ID
pop rdi ; rdi = byte counter
pop rax ; rax = tokens processed pop rax ; rax = tokens processed
pop rdi ; rdi = byte counter
mov [TOKEN_TABLE_ADDR + rax * 2], cx mov [TOKEN_TABLE_ADDR + rax * 2], cx
inc rax ; plus 1 token processed inc rax ; plus 1 token processed