From a68c5e0dede762819328c000b234f8f2c0ed91b3 Mon Sep 17 00:00:00 2001 From: jbirddog <100367399+jbirddog@users.noreply.github.com> Date: Sat, 6 Jul 2024 23:53:01 -0400 Subject: [PATCH] First pass at parsing input stack effects (#77) --- blue_test.asm | 2 ++ code_buffer_test.inc | 1 - dictionary.inc | 39 +++++++++++++++++++++++++++++++++++---- flow.inc | 10 +++++----- kernel_test.inc | 16 ++++++++++++++++ 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/blue_test.asm b/blue_test.asm index fd5b242..a4ff037 100644 --- a/blue_test.asm +++ b/blue_test.asm @@ -84,6 +84,8 @@ failure: mov esi, newline call print_char + + call dump_code_buffer mov dil, [test_num] mov eax, 60 diff --git a/code_buffer_test.inc b/code_buffer_test.inc index b935d64..2acfdf9 100644 --- a/code_buffer_test.inc +++ b/code_buffer_test.inc @@ -43,6 +43,5 @@ check_code_buffer: .failure_length: .failure_byte: - call dump_code_buffer jmp failure diff --git a/dictionary.inc b/dictionary.inc index 0fb2c91..0db2179 100644 --- a/dictionary.inc +++ b/dictionary.inc @@ -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 @@ -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 @@ -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 diff --git a/flow.inc b/flow.inc index dd317f2..ca736ed 100644 --- a/flow.inc +++ b/flow.inc @@ -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 diff --git a/kernel_test.inc b/kernel_test.inc index 88a8573..e57962c 100644 --- a/kernel_test.inc +++ b/kernel_test.inc @@ -129,6 +129,7 @@ kernel_test: tc1 user_one_byte tc1 user_empty_words tc1 seX_empty + tc1 ise_1 tc2 bogus @@ -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 '