diff --git a/Makefile b/Makefile index 7b7a041..35dee51 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ ${OBJECT.d}/%.pluglock: ${OBJECT.d}/%.pp touch $@ test: ${OUT} - -ORIGIN="$$(realpath .)" PATH="$$(realpath .):${PATH}" cmdtest + -ORIGIN="$$(realpath .)" PATH="$$(realpath .):${PATH}" cmdtest --fast -${WRAP} ./${OUT} test/nop.eax bootstrap: diff --git a/source/eaxhla.c b/source/eaxhla.c index a075d7a..6ae90d1 100644 --- a/source/eaxhla.c +++ b/source/eaxhla.c @@ -6,6 +6,8 @@ * the storage of variables. */ +// XXX: we dont *actually* have to store names, do we? + #include #include #include @@ -33,9 +35,29 @@ static size_t anon_variable_counter = 0; */ static size_t unresolved_label_counter = 0; +/* +static int control_block_stack[12]; +static size_t control_block_stack_top = 0; +*/ + static unsigned symbol_id = 1; tommy_hashtable symbol_table; +/* +void add_if(void) { + control_block_stack[control_block_stack_top++] = symbol_id++; +} + +void fin_if(void) { + append_instructions(ASMDIRMEM, control_block_stack[control_block_stack_top--]); +} + +void add_logic_equals(cpuregister_t * c1, cpuregister_t * c2) { + append_instructions(CMP, c1->size, REG, c1->number, REG, c2->number); + append_instructions(JNE, D32, REL, control_block_stack[control_block_stack_top]); +} +*/ + static char * scope = NULL; void empty_out_scope(void) { free(scope); @@ -60,7 +82,6 @@ symbol_t * new_symbol(char * name) { return r; } -static void free_symbol(void * data) { symbol_t * variable = (symbol_t*)data; @@ -332,6 +353,7 @@ void add_fastcall(const char * const destination) { append_instructions(CALL, REL, function->_id); } + int type2size(const int type) { switch (type) { case U8: diff --git a/source/eaxhla.h b/source/eaxhla.h index 8b6c979..d6a0ad1 100644 --- a/source/eaxhla.h +++ b/source/eaxhla.h @@ -75,6 +75,12 @@ extern void add_procedure(const char * const name); extern void add_fastcall(const char * const destination); extern void fin_procedure(void); extern void fin_hla(void); +/* +extern void add_if(void); +extern void fin_if(void); +extern void add_logic_equals(); +extern void add_logic_equals(cpuregister_t * c1, cpuregister_t * c2); +*/ /* Not implemented extern symbol_t * add_function(symbol_t function); extern symbol_t * get_function(const char * const name); diff --git a/source/eaxhla.y b/source/eaxhla.y index 29820fc..4f24647 100644 --- a/source/eaxhla.y +++ b/source/eaxhla.y @@ -106,7 +106,6 @@ document: hla { fin_hla(); } hla: %empty // | library hla - | declaration hla // tmp | program hla | function hla ; @@ -234,12 +233,12 @@ stored_literal: ARRAY_LITERAL { code: %empty | error code { /*yyerrok;*/ } - | repeat code - | if code + /*| repeat code */ + /*| if code */ | call code | label code | machine code - | BREAK code + /*| BREAK code*/ | exit code | instruction code ; @@ -250,15 +249,26 @@ label: LABEL { } ; + /* repeat: REPEAT code END_REPEAT | UNTIL logic REPEAT code END_REPEAT ; -if: IF logic THEN code END_IF +if_start: IF { add_if(); } + ; + +if_end: END_IF { fin_if(); } + ; + +if: if_start logic THEN code if_end | IF logic THEN code ELSE code END_IF ; -logic: logical_operand ITAND logical_operand +logic: register '=' register { + add_logic_equals(&$1, &$3); + } + ; + logical_operand ITAND logical_operand | logical_operand ITOR logical_operand | logical_operand ITXOR logical_operand | logical_operand '=' logical_operand @@ -277,6 +287,7 @@ logical_operand: sublogic sublogic: '(' logic ')' ; + */ machine: MACHINE machine_code END_MACHINE ; diff --git a/test/CMDTEST_eaxhla.rb b/test/CMDTEST_eaxhla.rb index 4db06c5..da4c872 100644 --- a/test/CMDTEST_eaxhla.rb +++ b/test/CMDTEST_eaxhla.rb @@ -1,127 +1,73 @@ -$default_output_file = "test_me_please" +$default_output_file = "a.out" class CMDTEST_error_batch < Cmdtest::Testcase def test_unknown_instruction - create_file "input.eax", <<-HEREDOC - procedure a - nop - end procedure + import_file "test/unknown_instruction.eax", "./" - unix - program main - wigglecall a - end program - HEREDOC - - cmd "eaxhla input.eax" do + cmd "eaxhla unknown_instruction.eax" do stderr_equal /.+/ exit_status 1 end end def test_unclosed_comment - create_file "input.eax", <<-HEREDOC - /* - reeeeeeee - reeeeeeeee - reeeeee - HEREDOC + import_file "test/unclosed_comment.eax", "./" - cmd "eaxhla input.eax" do + cmd "eaxhla unclosed_comment.eax" do stderr_equal /.+/ exit_status 1 end end def test_unclosed_artimetric - create_file "input.eax", <<-HEREDOC - program a - u8 var = [ - HEREDOC + import_file "test/unclosed_artimetric.eax", "./" - cmd "eaxhla input.eax" do + cmd "eaxhla unclosed_artimetric.eax" do stderr_equal /.+/ exit_status 1 end end def test_unclosed_program - create_file "input.eax", <<-HEREDOC - unix - program main - begin - exit 1 - end rpogram - HEREDOC + import_file "test/unclosed_program.eax", "./" - cmd "eaxhla input.eax" do + cmd "eaxhla unclosed_program.eax" do stderr_equal /.+/ exit_status 1 end end def test_double_declare - create_file "input.eax", <<-HEREDOC - program main - u8 a - u8 a - begin - end program - HEREDOC + import_file "test/double_declare.eax", "./" - cmd "eaxhla input.eax" do + cmd "eaxhla double_declare.eax" do stderr_equal /.+/ exit_status 1 end end def test_double_program - create_file "input.eax", <<-HEREDOC - program a - begin - end program + import_file "test/double_program.eax", "./" - program b - begin - end program - HEREDOC - - cmd "eaxhla input.eax" do + cmd "eaxhla double_program.eax" do stderr_equal /.+/ exit_status 1 end end def test_cut_string - create_file "input.eax", <<-HEREDOC - program main - u8 <> kek = "asd - begin - end program - HEREDOC + import_file "test/cut_string.eax", "./" - cmd "eaxhla input.eax" do + cmd "eaxhla cut_string.eax" do stderr_equal /.+\n(.|\n)+/m exit_status 1 end end def test_multi_error - create_file "input.eax", <<-HEREDOC - program main - k8 kek - begin - wigglecall func - xor $rsp rsp - xor rsp rsp - poke rsp - xor rsp rsp - xor rsp rsp - xor rsp rsp - end program - HEREDOC + import_file "test/multi_error.eax", "./" - cmd "eaxhla input.eax" do + cmd "eaxhla multi_error.eax" do stderr_equal /.+\n(.|\n)+/m exit_status 1 end @@ -130,31 +76,31 @@ end class CMDTEST_warning_batch < Cmdtest::Testcase def test_overflows - create_file "input.eax", <<-HEREDOC - program main - u8 a = 10 - u8 b = 10000 - u8 c = -200 - begin - end program - HEREDOC + import_file "test/overflows.eax", "./" ignore_file $default_output_file - cmd "eaxhla input.eax" do - created_files "a.out" + cmd "eaxhla overflows.eax" do + stderr_equal /.+/ + end + end + + def test_very_empty + import_file "test/very_empty.eax", "./" + + ignore_file $default_output_file + + cmd "eaxhla very_empty.eax" do stderr_equal /.+/ end end def test_empty - create_file "input.eax", <<-HEREDOC - HEREDOC + import_file "test/empty.eax", "./" ignore_file $default_output_file - cmd "eaxhla input.eax" do - created_files "a.out" + cmd "eaxhla empty.eax" do stderr_equal /.+/ end end diff --git a/test/basic_if.eax b/test/basic_if.eax new file mode 100644 index 0000000..2f37b92 --- /dev/null +++ b/test/basic_if.eax @@ -0,0 +1,9 @@ +program basic_if +begin + mov rax 2 + mov rbx 3 + if rax = rbx then + exit 1 + end if + exit 0 +end program diff --git a/test/cut_string.eax b/test/cut_string.eax new file mode 100644 index 0000000..a5881c5 --- /dev/null +++ b/test/cut_string.eax @@ -0,0 +1,4 @@ +program main + u8 <> kek = "asd +begin +end program diff --git a/test/double_declare.eax b/test/double_declare.eax new file mode 100644 index 0000000..7088d82 --- /dev/null +++ b/test/double_declare.eax @@ -0,0 +1,5 @@ +program main + u8 a + u8 a +begin +end program diff --git a/test/double_program.eax b/test/double_program.eax new file mode 100644 index 0000000..0a78697 --- /dev/null +++ b/test/double_program.eax @@ -0,0 +1,7 @@ +program a +begin +end program + +program b +begin +end program diff --git a/test/hello_world.c b/test/hello_world.c new file mode 100644 index 0000000..ea4d243 --- /dev/null +++ b/test/hello_world.c @@ -0,0 +1,5 @@ +// @BAKE gcc $@ -o $*.out -ggdb +signed main() { + puts("Hello World!"); + return 0; +} diff --git a/test/multi_error.eax b/test/multi_error.eax new file mode 100644 index 0000000..ed18aee --- /dev/null +++ b/test/multi_error.eax @@ -0,0 +1,11 @@ +program main + k8 kek +begin + wigglecall func + xor $rsp rsp + xor rsp rsp + poke rsp + xor rsp rsp + xor rsp rsp + xor rsp rsp +end program diff --git a/test/overflows.eax b/test/overflows.eax new file mode 100644 index 0000000..06fbd55 --- /dev/null +++ b/test/overflows.eax @@ -0,0 +1,6 @@ +program main + u8 a = 10 + u8 b = 10000 + u8 c = -200 +begin +end program diff --git a/test/sigint.eax b/test/sigint.eax new file mode 100644 index 0000000..40e1433 --- /dev/null +++ b/test/sigint.eax @@ -0,0 +1,5 @@ +program sigint +begin + my_loop: + jmp my_loop +end program diff --git a/test/unclosed_artimetric.eax b/test/unclosed_artimetric.eax new file mode 100644 index 0000000..fc2e15a --- /dev/null +++ b/test/unclosed_artimetric.eax @@ -0,0 +1,2 @@ +program a + u8 var = [ diff --git a/test/unclosed_comment.eax b/test/unclosed_comment.eax new file mode 100644 index 0000000..441923c --- /dev/null +++ b/test/unclosed_comment.eax @@ -0,0 +1,4 @@ +/* + reeeeeeee + reeeeeeeee + reeeeee diff --git a/test/unclosed_program.eax b/test/unclosed_program.eax new file mode 100644 index 0000000..df35de8 --- /dev/null +++ b/test/unclosed_program.eax @@ -0,0 +1,5 @@ +unix +program main +begin + exit 1 +end rpogram diff --git a/test/unknown_instruction.eax b/test/unknown_instruction.eax new file mode 100644 index 0000000..9ec4ee8 --- /dev/null +++ b/test/unknown_instruction.eax @@ -0,0 +1,8 @@ +procedure a + nop +end procedure + +unix +program main + wigglecall a +end program diff --git a/test/very_empty.eax b/test/very_empty.eax new file mode 100644 index 0000000..e69de29