mirror of
https://github.com/sigmasternchen/macrofuck
synced 2025-03-15 15:18:56 +00:00
refactor: change program type to block
This commit is contained in:
parent
8c7f2c8603
commit
635f90e8e0
6 changed files with 20 additions and 20 deletions
18
src/ast.c
18
src/ast.c
|
@ -13,17 +13,17 @@
|
|||
#define last(stru, field) stru->field[stru->length - 1]
|
||||
|
||||
|
||||
struct program* program_new(void) {
|
||||
_new(program, program);
|
||||
program->length = 0;
|
||||
program->statements = NULL;
|
||||
return program;
|
||||
struct block* block_new(void) {
|
||||
_new(block, block);
|
||||
block->length = 0;
|
||||
block->statements = NULL;
|
||||
return block;
|
||||
}
|
||||
|
||||
void program_add_statement(struct program* program, struct statement* statement) {
|
||||
program->length++;
|
||||
adjust_array(program, statements, struct statement*);
|
||||
last(program, statements) = statement;
|
||||
void block_add_statement(struct block* block, struct statement* statement) {
|
||||
block->length++;
|
||||
adjust_array(block, statements, struct statement*);
|
||||
last(block, statements) = statement;
|
||||
}
|
||||
|
||||
struct statement* print_statement_new(struct expression* expr) {
|
||||
|
|
|
@ -94,13 +94,13 @@ struct statement {
|
|||
};
|
||||
};
|
||||
|
||||
struct program {
|
||||
struct block {
|
||||
size_t length;
|
||||
struct statement** statements;
|
||||
};
|
||||
|
||||
struct program* program_new(void);
|
||||
void program_add_statement(struct program*, struct statement*);
|
||||
struct block* block_new(void);
|
||||
void block_add_statement(struct block*, struct statement*);
|
||||
|
||||
struct statement* print_statement_new(struct expression*);
|
||||
struct statement* declaration_statement_new(char*, struct expression*);
|
||||
|
|
|
@ -467,7 +467,7 @@ void check_allocations(band_t* band) {
|
|||
}
|
||||
}
|
||||
|
||||
int codegen(FILE* out, struct program* program) {
|
||||
int codegen(FILE* out, struct block* program) {
|
||||
band_t* band = band_init();
|
||||
|
||||
for (size_t i = 0; i < program->length; i++) {
|
||||
|
|
|
@ -27,6 +27,6 @@ void _move_to(FILE*, band_t*, size_t);
|
|||
void _copy(FILE*, band_t*, region_t*, region_t*);
|
||||
region_t* _clone(FILE*, band_t*, region_t*);
|
||||
|
||||
int codegen(FILE*, struct program*);
|
||||
int codegen(FILE*, struct block*);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,7 +15,7 @@ extern int yydebug;
|
|||
|
||||
#define DEBUG_MODE (0)
|
||||
|
||||
struct program* program;
|
||||
struct block* program;
|
||||
|
||||
void help(void) {
|
||||
printf("// TODO\n");
|
||||
|
|
10
src/parser.y
10
src/parser.y
|
@ -14,14 +14,14 @@
|
|||
int yylex(void);
|
||||
void yyerror(const char*);
|
||||
|
||||
extern struct program* program;
|
||||
extern struct block* program;
|
||||
|
||||
%}
|
||||
|
||||
%verbose
|
||||
|
||||
%union {
|
||||
struct program* program;
|
||||
struct block* block;
|
||||
struct statement* statement;
|
||||
struct expression* expr;
|
||||
int op; // hack, but C doesn't let me use forward declarations of enums
|
||||
|
@ -31,7 +31,7 @@ extern struct program* program;
|
|||
char* id;
|
||||
}
|
||||
|
||||
%type <program> stats
|
||||
%type <block> stats
|
||||
%type <statement> stat print definition macrostat
|
||||
%type <expr> expr literal variable macroexpr calcexpr
|
||||
%type <op> op
|
||||
|
@ -72,12 +72,12 @@ file: stats
|
|||
|
||||
stats: /* empty */
|
||||
{
|
||||
$$ = program_new();
|
||||
$$ = block_new();
|
||||
}
|
||||
| stats stat SEMICOLON
|
||||
{
|
||||
$$ = $1;
|
||||
program_add_statement($$, $2);
|
||||
block_add_statement($$, $2);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
Loading…
Reference in a new issue