Aria

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

commit 0fbc603267f4d2795fbd5592da1465528ed2d768
parent da01b5b34350799af71e675af4de842c6242409d
Author: m21c  <ho*******@gmail.com>
Date:   Tue, 20 Jul 2021 22:09:53 +0200

minor code clean-up + fixed env-stack on empty param-list

Diffstat:
Maria.c | 52++++++++++++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/aria.c b/aria.c @@ -1859,11 +1859,14 @@ declaration(Source *source, Type *ty) { functionenv->kind = SFUNCTION; node = expr(source, PASSIGN); result->lhs = node; + + popenv(source); } else { result->lhs = NULL; + + popenv(source); } - popenv(source); assert(decl); assert(decl->functionenv == NULL); @@ -1988,14 +1991,14 @@ stmtlist(Source *source, int indent, EnvKind envkind) { source->currenv->kind = SFUNCTION; env = source->currenv; } else if (env) { - popenv(source); - head = makenode(&source->tok, head); head->kind = ASCOPE; head->u.env = env; env->stmts = head; } + popenv(source); + return head; } @@ -2994,13 +2997,13 @@ typecheck(Env *env, Node *expr) { assert(rhs); /* TODO(m21c): make sure that typechecking is done - * correctly, since comma might be re- - * ordered: - * - check that maketype is NOT called - * multiple times and/or discarded on - * the same node. - * - check wether the resulting type - * does account for nesting on rhs */ + * correctly, since comma might be re- + * ordered: + * - check that maketype is NOT called + * multiple times and/or discarded on + * the same node. + * - check wether the resulting type + * does account for nesting on rhs */ if (lhs->type->kind == TERRTYPE || rhs->type->kind == TERRTYPE) { expr->type = prim + TERRTYPE; @@ -3032,13 +3035,9 @@ typecheck(Env *env, Node *expr) { expr->lhs = typecheck(env, expr->lhs); expr->lhs = conv(expr->lhs); - return expr; - default: return expr; } - - return expr; } Node * @@ -3094,7 +3093,7 @@ foldexpr(Env *env, Node *expr) { } } while (0); - break; + return expr; case OADD: case OSUB: if (lhs->kind == 'N' && rhs->kind == 'N') { @@ -3114,7 +3113,7 @@ foldexpr(Env *env, Node *expr) { /* delete(lhs); delete(rhs) */ } - break; + return expr; case OMUL: case ODIV: case OMOD: if (lhs->kind == 'N' && rhs->kind == 'N') { @@ -3151,13 +3150,13 @@ foldexpr(Env *env, Node *expr) { /* delete(lhs); delete(rhs) */ } - break; + return expr; case OPLUS: *expr = *lhs; /* delete(lhs) */ - break; + return expr; case OMINUS: if (lhs->kind == 'N') { @@ -3175,7 +3174,7 @@ foldexpr(Env *env, Node *expr) { /* delete(lhs) */ } - break; + return expr; case OBAND: case OBOR: case OXOR: if (lhs->kind == 'N' && rhs->kind == 'N') { @@ -3201,7 +3200,7 @@ foldexpr(Env *env, Node *expr) { expr->u.u = maskint(ty->size, expr->u.u); } - break; + return expr; case ASTMT: rhs = expr; @@ -3213,12 +3212,12 @@ foldexpr(Env *env, Node *expr) { rhs = rhs->rhs, lhs = rhs->lhs; goto advancestmt; } - break; + return expr; case ACOMMA: expr->lhs = foldexpr(env, lhs); expr->rhs = foldexpr(env, rhs); - break; + return expr; case ASCOPE: assert(expr->lhs); @@ -3234,10 +3233,10 @@ foldexpr(Env *env, Node *expr) { if (lhs->type->kind == expr->type->kind) *expr = *lhs /*, delete(lhs) */; - break; - } - return expr; + default: + return expr; + } } @@ -3621,7 +3620,8 @@ printexpr(FILE *out, Node *expr, int indent) { case OCALL: n += highlight(out, HLDELIM); n += fprintf(out, "%c", nodestrings[expr->kind][0]); - n += printexpr(out, expr->rhs, indent); + if (expr->rhs) + n += printexpr(out, expr->rhs, indent); n += highlight(out, HLDELIM); n += fprintf(out, "%c", nodestrings[expr->kind][1]); break;