Skip to content

Commit

Permalink
Fix dictionary look up bug (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbirddog authored Jul 13, 2024
1 parent 8540540 commit 8e90abc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ _AL = REG_RAX or _BYTE
_EAX = REG_RAX or _DWORD
_RAX = REG_RAX or _QWORD

_ECX = REG_RCX or _DWORD

_blue:
.tib dq 0
.tib_len dd 0
Expand Down
20 changes: 17 additions & 3 deletions dictionary.inc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ macro _ose e {
_core_words:
.prev_word = 0

_wi 'ecx', 3, se_reg_ecx, 0, 0
_wi 'eax', 3, se_reg_eax, 0, 0

.se_reg_latest = .prev_word
Expand Down Expand Up @@ -146,9 +147,9 @@ _find_from:
jne .next

inc rdi
dec ecx
js .check_word
dec cl
jnz .check_word

pop rax
jmp .done

Expand Down Expand Up @@ -426,3 +427,16 @@ se_reg_eax:
stosb
ret

se_reg_ecx:
mov rax, _ECX
mov rdi, [_dictionary.here]
stosq

mov rdi, [_dictionary.latest]
add rdi, 2
mov al, byte [rdi]
inc al
stosb
ret
24 changes: 24 additions & 0 deletions dictionary_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ macro tc2 word, in_len, word_len {
ok
}

macro tc3 word, from {
mov [_blue.tib], _core_words.##word + _dictionary.word_offset
mov [_blue.tib_len], _core_words.##word + 1
mov [_blue.tib_in], 0

t 'finds the expected word'

call parser_next_word

mov rdi, from
call _find_from
cmp rax, _core_words.##word
jne failure

ok
}

dictionary_test:
call dictionary_init

Expand Down Expand Up @@ -141,6 +159,12 @@ dictionary_test:
tc1 word_d_comma, 2, _core_words.d_comma
tc1 word_q_comma, 2, _core_words.q_comma
tc1 word_base, 4, _core_words.base

tc3 seX_o_parse, _core_words.se_parse_latest
tc3 seX_parse_end, _core_words.se_parse_latest

tc3 se_reg_eax, _core_words.se_reg_latest
tc3 se_reg_ecx, _core_words.se_reg_latest
call dictionary_deinit
Expand Down

0 comments on commit 8e90abc

Please sign in to comment.