WIP and infinite loops

This commit is contained in:
anon
2024-07-27 14:19:04 +02:00
parent 0432dd87d4
commit 65d53007b9
4 changed files with 41 additions and 6 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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(); }
;

11
test/repeat.eax Normal file
View File

@ -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