Aria

A low-level systems programming language
git clone git://git.m21c.me/Aria.git
Log | Files | Refs | LICENSE

commit f437a5f5768026fb458cb71cdf2ffd2cce3b2e0c
parent df1c9223c123a87119428b6eff480bb730c5cc25
Author: m21c  <ho*******@gmail.com>
Date:   Sun,  5 Feb 2023 16:25:16 +0100

worked on record parsing

Diffstat:
Mcompiler.c | 38++++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/compiler.c b/compiler.c @@ -481,10 +481,8 @@ struct Type { size_t size, align; union { - Env *recordenv; - struct { - int offset, size; + int offset, size; /* in bits */ } bit; struct { @@ -496,21 +494,33 @@ struct Type { Type *rtarget; /* for tuples (rht) and function return-type */ } u; - Decl *module; + Decl *module; /* module and record info */ }; +typedef struct Field { + Decl *fielddecl; + + size_t offset, size; /* in bytes */ + + bool use; +} Field; + struct Decl { DeclKind kind; SrcLoc loc; - Type *type, *typemodule; + Type *type; + Type *typemodule; /* the parent module type (is needed to associate a + variable declaration inside a module to the parent + module type) */ int key; Env *parentenv, *contentenv; union { Node *content; /* init or function body */ - Decl *target; /* for field aliases */ + + bool usefield; } u; Decl *prev, *next; @@ -565,6 +575,15 @@ struct Source { Node *lastis; } Source; +typedef struct FieldExpand FieldExpand; +struct FieldExpand { + Type *type; + Field *field; + + FieldExpand *parent; + FieldExpand *prev, *next; +}; + struct AnnotParam { AnnotParamKind kind; @@ -2818,6 +2837,7 @@ readrecord(Source *source, bool isunion) recordnode->kind = getkind(source); gettok(source); + /* read record tag-name */ if (getkind(source) == IDENT) { recordnode->lhs = tokennode(source, NULL); gettok(source); @@ -2836,6 +2856,12 @@ readrecord(Source *source, bool isunion) module->type->module = module; recordnode->type = module->type; + /* read record body */ + + /* NOTE(m21c): we will stmtlist() for parsing the record body, + since we have to parse statements or expressions beside + field declarations */ + /* TODO(m21c): check for new-line and only then read body */ recordnode->rhs = stmtlist(source, indent, envkind, module, false);