Aria

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

commit 0b7f291572407fee68bac011a6f4a2c509a55f21
parent b336be00062e430465ef7d760bcbd1105c325454
Author: m21c  <ho*******@gmail.com>
Date:   Sat,  2 Oct 2021 14:15:36 +0200

added declaration-target for later field aliases

Diffstat:
Mcompiler.c | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/compiler.c b/compiler.c @@ -159,6 +159,7 @@ enum DeclKind { DVAR, DPARAM, DFUNCTION, + DFIELDALIAS, /* DMACRO, DENFOLD @@ -266,7 +267,10 @@ struct Decl { int key; Env *parentenv, *contentenv; + union { Node *content; /* init or function body */ + Decl *target; /* for field aliases */ + } u; Decl *prev, *next; }; @@ -2112,8 +2116,8 @@ declaration(Source *source, Type *ty) assert(decl->contentenv == NULL); decl->contentenv = functionenv; - assert(decl->content == NULL); - decl->content = body; + assert(decl->u.content == NULL); + decl->u.content = body; assert(decl->kind == DVAR); decl->kind = DFUNCTION; @@ -2131,16 +2135,16 @@ declaration(Source *source, Type *ty) if (getkind(source) == OASS) { gettok(source); assert(decl); - decl->content = readexpr(source, PASSIGN); + decl->u.content = readexpr(source, PASSIGN); /* no init */ } else { assert(decl); - decl->content = NULL; + decl->u.content = NULL; } finish: - result = tokennode(source, decl->content); + result = tokennode(source, decl->u.content); result->type = decl->type; result->u.declref = decl; result->loc = decl->loc; @@ -3897,14 +3901,14 @@ printdeclaration(FILE *out, Decl *decl, int indent) n += highlight(out, HLDELIM); n += fprintf(out, ")"); - if (decl->content) { + if (decl->u.content) { n += fprintf(out, "\n"); - n += printexpr(out, decl->content, indent + 1); + n += printexpr(out, decl->u.content, indent + 1); } - } else if (decl->content) { + } else if (decl->u.content) { n += highlight(out, HLDELIM); n += fprintf(out, " = "); - n += printoperant(out, decl->content, PASSIGN, false, indent); + n += printoperant(out, decl->u.content, PASSIGN, false, indent); } return n;