Skip to content

Commit

Permalink
First pass at parsing input stack effects (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbirddog authored Jul 7, 2024
1 parent a219e17 commit a68c5e0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
2 changes: 2 additions & 0 deletions blue_test.asm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ failure:

mov esi, newline
call print_char

call dump_code_buffer
mov dil, [test_num]
mov eax, 60
Expand Down
1 change: 0 additions & 1 deletion code_buffer_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ check_code_buffer:
.failure_length:
.failure_byte:

call dump_code_buffer
jmp failure

39 changes: 35 additions & 4 deletions dictionary.inc
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ macro _ose e {
_core_words:
.prev_word = 0

_wi 'eax', 3, se_reg_eax, 0, 0

.se_reg_latest = .prev_word
.prev_word = 0

_wi '--', 2, seX_o_parse, 0, 0
_wi '))', 2, seX_parse_end, 0, 0

.se_latest = .prev_word
.se_parse_latest = .prev_word
.prev_word = 0
_w 'b,', 2, b_comma, 1, 0
Expand Down Expand Up @@ -364,20 +369,33 @@ seX_i_parse:
cmp [_blue.word_len], 0
je se_bad

mov rdi, _core_words.se_latest
mov rdi, _core_words.se_parse_latest
call _find_from

cmp rax, _core_words.seX_o_parse
je seX_o_parse

jmp se_bad
call parser_next_word
cmp [_blue.word_len], 0
je se_bad

mov rdi, _core_words.se_reg_latest
call _find_from

test rax, rax
jz se_bad

add rax, _dictionary.code_offset
call qword [rax]
jmp seX_i_parse
seX_o_parse:
call parser_next_word
cmp [_blue.word_len], 0
je se_bad

mov rdi, _core_words.se_latest
mov rdi, _core_words.se_parse_latest
call _find_from

cmp rax, _core_words.seX_parse_end
Expand All @@ -392,3 +410,16 @@ seX_parse_end:
stosb

ret

se_reg_eax:
mov rax, _EAX
mov rdi, [_dictionary.here]
stosq

mov rdi, [_dictionary.latest]
add rdi, 2
mov al, byte [rdi]
inc al
stosb
ret
10 changes: 5 additions & 5 deletions flow.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
;
flow_in:
call word_input_stack_effects
mov edi, esi
mov rdi, rsi

.loop:
dec ecx
js .done

lea ebx, [edi + (ecx * 8)]
mov ebx, [ebx]
and ebx, REG_MASK
shr ebx, REG_OFFSET
lea rbx, [rdi + (rcx * 8)]
mov rbx, [rbx]
and rbx, REG_MASK
shr rbx, REG_OFFSET

call data_stack_pop
cmp eax, _IMMEDIATE
Expand Down
16 changes: 16 additions & 0 deletions kernel_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ kernel_test:
tc1 user_one_byte
tc1 user_empty_words
tc1 seX_empty
tc1 ise_1
tc2 bogus

Expand Down Expand Up @@ -204,6 +205,21 @@ seX_empty:
db 0x01
.expected_length = $ - .expected

ise_1:
.blue:
db ': syscall (( num eax -- )) ; '
db ': _ 60 syscall ; entry '
.blue_length = $ - .blue

.expected:
db 0xc3
db 0xb8
dd 0x3c
db 0xe8
db 0xf5, 0xff, 0xff, 0xff
db 0xc3
.expected_length = $ - .expected

entry_0:
.blue:
db ': 1b 1 b, ; entry '
Expand Down

0 comments on commit a68c5e0

Please sign in to comment.