Aria

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

commit b52b7e96f0bf69f84ee33f6648d9a16fc1fc08bb
parent 46c999dcf0b4531ddc2701966f403ecbeec79d3f
Author: m21c <ho*******@gmail.com>
Date:   Fri, 27 Jun 2025 18:47:34 +0200

added unpool-macro for memory-managment

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

diff --git a/compiler.c b/compiler.c @@ -842,6 +842,11 @@ const uint8_t opinfo[] = { #define lengthof(array) ((int) sizeof(array) / (int) sizeof(*(array))) #endif +#define unpool(pool, top) \ + (assert((top) < lengthof(pool)), \ + memset((pool) + (top), 0, sizeof*(pool)), \ + (pool) + (top)++) + static int mystrncasecmp(const char *str1, const char *str2, size_t max_len) { @@ -2625,6 +2630,7 @@ gettype(Source *source, Type *basetype) advance: flags = qualifiers(source, QTYPE); + (void) flags; if (getkind(source) == LSQRDELIM) { Type *tmp = maketype(getloc(source), primitive(TARRAY), basetype); @@ -2739,6 +2745,7 @@ redodeclaration: if (getkind(source) == ODISP || getkind(source) == COLONDELIM) { selfparam = getkind(source) == COLONDELIM; + (void) selfparam; gettok(source); } else { error(getloc(source), "expected '.' or ':'"); @@ -3412,6 +3419,7 @@ readexpr(Source *source, int minprec) return lhs; } +#if 0 static Node * todeclaration(Node *curr, Node **ty) { @@ -3436,6 +3444,7 @@ todeclaration(Node *curr, Node **ty) return curr; } +#endif /* TODO(m21c): this is stupid! There should be a simpler way to parse the * comma-expressions (comma-operator, param-list, declaration-list, @@ -4483,13 +4492,7 @@ int gisttop; static Block * makeblock(BlockKind kind, Env *env) { - Block *block; - - assert(blocktop < lengthof(blockbuf)); - - block = blockbuf + blocktop++; - - memset(block, 0, sizeof(*block)); + Block *block = unpool(blockbuf, blocktop); block->kind = kind; block->env = env; @@ -4500,13 +4503,7 @@ makeblock(BlockKind kind, Env *env) static Conduct * makeconduct(ConductKind kind, Node *label) { - Conduct *conduct; - - assert(conducttop < lengthof(conductbuf)); - - conduct = conductbuf + conducttop++; - - memset(conduct, 0, sizeof(*conduct)); + Conduct *conduct = unpool(conductbuf, conducttop); conduct->kind = kind; conduct->label = label; @@ -4553,12 +4550,7 @@ appendblock(Conduct *parent, BlockKind kind, Env *env) static Gist * makegist(Decl *decl, Node *where, bool init) { - Gist *gist; - assert(gisttop < lengthof(gistbuf)); - - gist = gistbuf + gisttop++; - - memset(gist, 0, sizeof(*gist)); + Gist *gist = unpool(gistbuf, gisttop); gist->decl = decl; gist->where = where;