-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple dictionary find routine (#50)
- Loading branch information
Showing
6 changed files
with
179 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
; | ||
; entry: | ||
; | ||
; 08 - 1 byte flags | ||
; - 1 byte word len | ||
; - 6 bytes reserved | ||
; 08 - prev addr | ||
; 08 - code addr | ||
; ?? - word chars (padded to dq) | ||
; ?? - stack effects | ||
; | ||
|
||
DE_HIDDEN = 1 | ||
DE_IMMEDIATE = 2 | ||
|
||
_core_words: | ||
.b_comma: | ||
db DE_IMMEDIATE | ||
db 2 | ||
dw 0 | ||
dd 0 | ||
dq 0 | ||
dq _core_code.b_comma | ||
dq 'b,' | ||
dq 0 ; TODO: stack effects (( b al -- | rdi )) | ||
.latest: | ||
.d_comma: | ||
db DE_IMMEDIATE | ||
db 2 | ||
dw 0 | ||
dd 0 | ||
dq .b_comma | ||
dq _core_code.d_comma | ||
dq 'd,' | ||
dq 0 ; TODO: stack effects (( d ax -- | rdi )) | ||
|
||
dictionary_init: | ||
mov esi, _dictionary.length | ||
mov edx, PROT_RW | ||
call mmap_buffer | ||
|
||
mov rdi, _dictionary.base | ||
stosq | ||
stosq | ||
mov [_dictionary.latest], _core_words.latest | ||
|
||
ret | ||
|
||
dictionary_deinit: | ||
mov esi, _dictionary.length | ||
mov rdi, [_dictionary.base] | ||
mov eax, SYS_MUNMAP | ||
syscall | ||
ret | ||
|
||
; | ||
; expects | ||
; - properly configured blue structure with non zero word len | ||
; | ||
dictionary_find: | ||
mov rdi, [_dictionary.latest] | ||
|
||
.find: | ||
push rdi | ||
|
||
test byte [edi], DE_HIDDEN | ||
jnz .next | ||
|
||
inc edi | ||
mov rsi, _blue.word_len | ||
mov ecx, [esi] | ||
lodsb | ||
cmp al, byte [edi] | ||
jne .next | ||
|
||
add edi, _dictionary.word_offset - 1 | ||
.check_word: | ||
lodsb | ||
cmp al, byte [edi] | ||
jne .next | ||
|
||
inc edi | ||
dec ecx | ||
js .check_word | ||
|
||
pop rax | ||
jmp .done | ||
.next: | ||
pop rdi | ||
add edi, _dictionary.prev_word_offset | ||
mov rdi, [rdi] | ||
|
||
test rdi, rdi | ||
jnz .find | ||
|
||
xor eax, eax | ||
.done: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
format elf64 executable 3 | ||
|
||
macro tc1 tib, tib_len, expected { | ||
mov [_blue.tib], tib | ||
mov [_blue.tib_len], tib_len | ||
mov [_blue.tib_in], 0 | ||
|
||
call parser_next_word | ||
call dictionary_find | ||
|
||
inc [test_num] | ||
cmp rax, expected | ||
jne failure | ||
} | ||
|
||
segment readable writeable | ||
|
||
include "defs.inc" | ||
|
||
test_num db 1 | ||
|
||
segment readable executable | ||
|
||
include "linux.inc" | ||
include "code_buffer.inc" | ||
include "dictionary.inc" | ||
include "parser.inc" | ||
|
||
entry $ | ||
mov [test_num], 0 | ||
|
||
call dictionary_init | ||
inc [test_num] | ||
mov rax, [_dictionary.base] | ||
cmp rax, [_dictionary.here] | ||
jne failure | ||
inc [test_num] | ||
mov rax, [_dictionary.latest] | ||
cmp rax, _core_words.latest | ||
jne failure | ||
|
||
tc1 unknown, 4, 0 | ||
tc1 d_comma, 2, _core_words.d_comma | ||
tc1 b_comma, 2, _core_words.b_comma | ||
call dictionary_deinit | ||
|
||
xor edi, edi | ||
exit: | ||
mov eax, 60 | ||
syscall | ||
|
||
failure: | ||
mov dil, [test_num] | ||
jmp exit | ||
|
||
segment readable | ||
|
||
unknown db '!@#$' | ||
b_comma db 'b,' | ||
d_comma db 'd,' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
TESTS := \ | ||
code_buffer_test \ | ||
parser_test \ | ||
dictionary_test \ | ||
elf_test \ | ||
elf_test_hello_world | ||
|
||
|