continue works

This commit is contained in:
anon
2024-07-27 14:29:42 +02:00
parent 65d53007b9
commit b09bbe6b89
5 changed files with 51 additions and 11 deletions

View File

@ -54,6 +54,9 @@ void add_logic_equals(cpuregister_t * c1, cpuregister_t * c2) {
append_instructions(CMP, c1->size, REG, c1->number, REG, c2->number); append_instructions(CMP, c1->size, REG, c1->number, REG, c2->number);
append_instructions(JNE, D32, REL, control_block_stack[control_block_stack_top]); append_instructions(JNE, D32, REL, control_block_stack[control_block_stack_top]);
} }
void add_break(void) {
append_instructions(JMP, D32)
}
*/ */
void add_repeat(void) { void add_repeat(void) {
@ -63,6 +66,9 @@ void add_repeat(void) {
void fin_repeat(void) { void fin_repeat(void) {
append_instructions(JMP, D32, REL, control_block_stack[control_block_stack_top--]); append_instructions(JMP, D32, REL, control_block_stack[control_block_stack_top--]);
} }
void add_continue(void) {
append_instructions(JMP, D32, REL, control_block_stack[control_block_stack_top]);
}
static char * scope = NULL; static char * scope = NULL;
void empty_out_scope(void) { void empty_out_scope(void) {

View File

@ -75,18 +75,21 @@ extern void add_procedure(const char * const name);
extern void add_fastcall(const char * const destination); extern void add_fastcall(const char * const destination);
extern void fin_procedure(void); extern void fin_procedure(void);
extern void fin_hla(void); extern void fin_hla(void);
/* // testing
extern void add_repeat(void);
extern void fin_repeat(void);
extern void add_continue(void);
/* Not implemented
extern void add_break(void);
extern symbol_t * add_function(symbol_t function);
extern symbol_t * get_function(const char * const name);
extern void add_if(void); extern void add_if(void);
extern void fin_if(void); extern void fin_if(void);
extern void add_logic_equals(); extern void add_logic_equals();
extern void add_logic_equals(cpuregister_t * c1, cpuregister_t * c2); 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);
*/
// Asm value constructs // Asm value constructs
/* These functions MUST return a valid symbol_t or /* These functions MUST return a valid symbol_t or

View File

@ -42,6 +42,7 @@ machine { return MACHINE; }
library { return LIBRARY; } library { return LIBRARY; }
break { return BREAK; } break { return BREAK; }
continue { return CONTINUE; }
until { return UNTIL; } until { return UNTIL; }
exit { return EXIT; } exit { return EXIT; }

View File

@ -98,7 +98,7 @@
// Instruction-likes // Instruction-likes
%token FASTCALL %token FASTCALL
%token EXIT BREAK %token EXIT BREAK CONTINUE
%% %%
document: hla { fin_hla(); } document: hla { fin_hla(); }
@ -244,9 +244,8 @@ code: %empty
| call code | call code
| label code | label code
| machine code | machine code
/*| BREAK code*/ | instruction code
| exit code | instruction_like code
| instruction code
; ;
label: LABEL { label: LABEL {
@ -436,6 +435,17 @@ artimetric_operand: LITERAL
} }
; ;
instruction_like: exit
| continue
| break
;
continue: CONTINUE { add_continue(); }
;
break: BREAK { ; }
;
exit: EXIT value { append_exit($2); } exit: EXIT value { append_exit($2); }
; ;

20
test/continue.eax Normal file
View File

@ -0,0 +1,20 @@
program my_continue
u8 <> yeah = "yeah"
u8 <> nope = "nope"
begin
repeat
mov eax 1
mov edi 1
mov esi yeah
mov edx 4
syscall
continue
mov eax 1
mov edi 1
mov esi nope
mov edx 4
syscall
end repeat
end program