From: Michael D. Lowis Date: Fri, 28 May 2021 16:08:18 +0000 (-0400) Subject: moved TODO to dedicated file. removed offset from item type. Defined types for possib... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=8da072286dad77f31fa131e7b4d31966ff30e07a;p=proto%2Fobnc.git moved TODO to dedicated file. removed offset from item type. Defined types for possible SSA form --- diff --git a/cerise/TODO.md b/cerise/TODO.md index a75a7b7..e7a684c 100644 --- a/cerise/TODO.md +++ b/cerise/TODO.md @@ -1 +1,32 @@ -* Optimize variable initialization to use constants +# Doing + +* Cleanup the lexer + +# Up Next + +* Fix array access in structs +* Implement module scoped identifiers +* Implement an SSA backend +* Implement pointers + * Ownership semantics: Ownership you can count on + * Concurrency: Biased reference counting + +# Backlog + +* Implement record extension +* Implement logical operators: and, or, not +* Implement string types +* Implement while, for, do/repeat loops +* Track uninitialized variables/globals +* Nested procedure definitions +* check that module name matches filename + +# Order of Operations for Implementing Memory Management + +* Implement new operator +* Enforce single owner pointers +* Implement borrowed pointers +* Implement biased refcounting for borrowed pointers + + + diff --git a/cerise/backend/c99/codegen.c b/cerise/backend/c99/codegen.c index 6f00c37..71378b1 100644 --- a/cerise/backend/c99/codegen.c +++ b/cerise/backend/c99/codegen.c @@ -149,7 +149,7 @@ static char* temp(Item* a) } else if (a->mode == ITEM_FIELD) { - snprintf(name, sizeof(name), "*((%s)(_T%d + %d))", typetoptr(a->type), a->reg, a->offset); + snprintf(name, sizeof(name), "*((%s)(_T%d + %lld))", typetoptr(a->type), a->reg, a->imm.i); } else { @@ -184,6 +184,7 @@ static void load_var(Parser* p, Item* item) { printf(" = %c%s;\n", (isref ? '&' : ' '), item->imm.s); } + item->imm.i = 0; break; case ITEM_MVAR: @@ -196,6 +197,7 @@ static void load_var(Parser* p, Item* item) { printf(" = %c%s_%s;\n", (isref ? '&' : ' '), p->name, item->imm.s); } + item->imm.i = 0; break; default: @@ -495,5 +497,5 @@ void codegen_field(Parser* p, Item* record, char* name) Field* f = get_field(p, record->type, name); record->mode = ITEM_FIELD; record->type = f->type; - record->offset += f->offset; + record->imm.i += f->offset; } diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index f05cf0b..941562f 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -133,7 +133,6 @@ typedef struct Item { Symbol* sym; Type* type; int reg; - int offset; ImmValue imm; } Item; @@ -226,6 +225,27 @@ void codegen_return(Parser* p, Item* item); void codegen_index(Parser* p, Item* array, Item* index); void codegen_field(Parser* p, Item* record, char* name); +typedef union { + struct { + char* name; + long version; + } var; + ImmValue imm; +} Operand; + +typedef struct { + int opcode; + Operand dest; + Operand arg1; + Operand arg2; +} Operation; + +typedef struct { + size_t nops; + size_t mops; + Operation** ops; +} Block; + /* typedef struct AnfNode { diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index b1e38d9..e17d873 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -4,30 +4,6 @@ #include #include -/* TODO - * Implement logical operators: and, or, not - * Implement module scoped identifiers - * Implement strings types - * Implement records and record access - * Implement while, for, do/repeat loops - * Track uninitialized variables/globals - * Implement pointers - * Ownership semantics: Ownership you can count on - * Concurrency: Biased reference counting - * Nested procedure definitions - * Implement record extension - * Cleanup the lexer -*/ - -/* Order of Operations for Implementing Memory Management - - * Implement new operator - * Enforce single owner pointers - * Implement borrowed pointers - * Implement biased refcounting for borrowed pointers - -*/ - //#define TRACE #ifdef TRACE static int Indent = 0; diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index 665c1eb..4421a0f 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -114,5 +114,5 @@ begin # c = e[1][c]; # c = f.dim.w; f.dim.h = 0; -# f.label[0] = 42; + f.label[0] = 42; end