diff --git a/source/eaxhla.c b/source/eaxhla.c index 6ae90d1..6969daf 100644 --- a/source/eaxhla.c +++ b/source/eaxhla.c @@ -35,10 +35,8 @@ 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; @@ -58,6 +56,14 @@ void add_logic_equals(cpuregister_t * c1, cpuregister_t * c2) { } */ +void add_repeat(void) { + control_block_stack[control_block_stack_top++] = symbol_id++; + append_instructions(ASMDIRMEM, control_block_stack[control_block_stack_top]); +} +void fin_repeat(void) { + append_instructions(JMP, D32, REL, control_block_stack[control_block_stack_top--]); +} + static char * scope = NULL; void empty_out_scope(void) { free(scope); diff --git a/source/eaxhla.h b/source/eaxhla.h index d6a0ad1..d9d25be 100644 --- a/source/eaxhla.h +++ b/source/eaxhla.h @@ -81,6 +81,8 @@ extern void fin_if(void); extern void add_logic_equals(); extern void add_logic_equals(cpuregister_t * c1, cpuregister_t * c2); */ +extern void add_repeat(void); +extern void fin_repeat(void); /* 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 4f24647..a76d816 100644 --- a/source/eaxhla.y +++ b/source/eaxhla.y @@ -197,6 +197,12 @@ immediate: LITERAL { $$.value = variable->_id; free($1); } + /* + | stored_literal { + $$.type = REL; + $$.value = $1 + } + */ ; memory: artimetric_block @@ -233,7 +239,7 @@ stored_literal: ARRAY_LITERAL { code: %empty | error code { /*yyerrok;*/ } - /*| repeat code */ + | repeat code /*| if code */ | call code | label code @@ -249,11 +255,21 @@ label: LABEL { } ; - /* -repeat: REPEAT code END_REPEAT - | UNTIL logic REPEAT code END_REPEAT +repeat_start: REPEAT { + add_repeat(); + } ; +repeat_end: END_REPEAT { + fin_repeat(); + } + ; + +repeat: repeat_start code repeat_end + /*| UNTIL logic REPEAT code END_REPEAT*/ + ; + + /* if_start: IF { add_if(); } ; diff --git a/test/repeat.eax b/test/repeat.eax new file mode 100644 index 0000000..c954a5a --- /dev/null +++ b/test/repeat.eax @@ -0,0 +1,11 @@ +program my_repeat + u8 <> message = "Heyo\n" +begin + repeat + mov eax 1 + mov edi 1 + mov esi message + mov edx 5 + syscall + end repeat +end program