From dc87ff4b0c9f311be7fad652594e3766a4ddb0c6 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Tue, 25 Mar 2025 12:05:20 +0800 Subject: refactor name --- src/as_analyzer.c | 18 +++++++------- src/as_analyzer.h | 6 ++--- src/as_main.c | 4 +-- src/as_parser.c | 40 +++++++++++++++--------------- src/as_parser.h | 30 +++++++++-------------- src/as_tokenizer.c | 24 +++++++++--------- src/as_tokenizer.h | 15 +++++------- src/fvm.c | 62 +++++++++++++++++++++++------------------------ src/fvm.h | 37 +++++++++++++--------------- src/main.c | 2 +- src/utils.c | 8 +++--- src/utils.h | 7 +++--- tests/test_as_analyzer.c | 6 ++--- tests/test_as_parser.c | 8 +++--- tests/test_as_tokenizer.c | 4 +-- 15 files changed, 129 insertions(+), 142 deletions(-) diff --git a/src/as_analyzer.c b/src/as_analyzer.c index a3e7ea4..f48353f 100644 --- a/src/as_analyzer.c +++ b/src/as_analyzer.c @@ -3,7 +3,7 @@ #include #include -const char * compose_section_label(allocator_t alct, const char * section, const char * name) { +const char * compose_section_label(struct allocator * alct, const char * section, const char * name) { size_t section_len = strlen(section); size_t name_len = strlen(name); size_t sz = section_len + name_len; @@ -14,9 +14,9 @@ const char * compose_section_label(allocator_t alct, const char * section, const return buf; } -void process_section_label(allocator_t alct, prog_t prog) { +void process_section_label(struct allocator * alct, struct prog * prog) { const char * section = ""; - stmt_t* stmts = prog->stmts->stmts; + struct stmt ** stmts = prog->stmts->stmts; for (size_t i = 0; ; i++) { if (stmts[i] == NULL) break; if (stmts[i]->label == NULL) continue; @@ -30,11 +30,11 @@ void process_section_label(allocator_t alct, prog_t prog) { } } -size_t instr_size(instr_t instr) { +size_t instr_size(struct instr * instr) { return op_size(instr->op); } -struct sym_table new_sym_table(allocator_t alct) { +struct sym_table new_sym_table(struct allocator * alct) { struct sym_table tbl; tbl.cap = 16; tbl.size = 0; @@ -42,7 +42,7 @@ struct sym_table new_sym_table(allocator_t alct) { return tbl; } -void sym_table_add(allocator_t alct, struct sym_table* tbl, const char* name, int pos) { +void sym_table_add(struct allocator * alct, struct sym_table* tbl, const char* name, int pos) { if (tbl->cap == tbl->size) { void *old_buf = tbl->buf; tbl->buf = allocate(alct, sizeof(struct sym_table_entry) * tbl->cap * 2); @@ -53,14 +53,14 @@ void sym_table_add(allocator_t alct, struct sym_table* tbl, const char* name, in tbl->size += 1; } -struct sym_table analyze_prog(allocator_t alct, prog_t prog) { +struct sym_table analyze_prog(struct allocator * alct, struct prog * prog) { process_section_label(alct, prog); - stmt_t * stmts = prog->stmts->stmts; + struct stmt * * stmts = prog->stmts->stmts; struct sym_table tbl = new_sym_table(alct); size_t cur_pos = 0; for (int i = 0; ; i++) { if (stmts[i] == NULL) break; - stmt_t stmt = stmts[i]; + struct stmt * stmt = stmts[i]; if (stmt->label) { sym_table_add(alct, &tbl, stmt->label->name, cur_pos); } diff --git a/src/as_analyzer.h b/src/as_analyzer.h index 988cca0..b59fe3c 100644 --- a/src/as_analyzer.h +++ b/src/as_analyzer.h @@ -15,9 +15,9 @@ struct sym_table { struct sym_table_entry *buf; }; -struct sym_table new_sym_table(allocator_t alct); -void sym_table_add(allocator_t alct, struct sym_table* tbl, const char* name, int pos); +struct sym_table new_sym_table(struct allocator * alct); +void sym_table_add(struct allocator * alct, struct sym_table* tbl, const char* name, int pos); -struct sym_table analyze_prog(allocator_t alct, prog_t prog); +struct sym_table analyze_prog(struct allocator * alct, struct prog * prog); #endif // FVM_AS_ANALYZER_H_ diff --git a/src/as_main.c b/src/as_main.c index dc61ea9..6c91a5f 100644 --- a/src/as_main.c +++ b/src/as_main.c @@ -8,9 +8,9 @@ int main(int argc, char** argv) { fprintf(stderr, "usage: fvm-as \n"); return 1; } - allocator_t alct = new_allocator(); + struct allocator * alct = new_allocator(); FILE *fp = fopen(argv[1], "r"); - token_stream_t ts = new_token_stream(alct, fp); + struct token_stream * ts = new_token_stream(alct, fp); delete_allocator(alct); return 0; diff --git a/src/as_parser.c b/src/as_parser.c index 1044e3f..39f8859 100644 --- a/src/as_parser.c +++ b/src/as_parser.c @@ -16,25 +16,25 @@ //