commit 3ea40cb3df5e88073884252d125b3a161a232d28
parent e6889688789016e98b0b76f6a4ae7ec8856535e4
Author: m21c <ho*******@gmail.com>
Date: Thu, 2 Feb 2023 05:15:55 +0100
added print cases for while and loop-until + minor printing fixes
Diffstat:
| M | compiler.c | | | 46 | ++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 46 insertions(+), 0 deletions(-)
diff --git a/compiler.c b/compiler.c
@@ -5377,6 +5377,10 @@ printexpr(FILE *out, Node *expr, int indent)
n += highlight(out, HLKEYWORD);
n += fprintf(out, "continue");
break;
+ case KWHILE:
+ n += highlight(out, HLKEYWORD);
+ n += fprintf(out, "while ");
+ goto joinifelse;
case KIF:
n += highlight(out, HLKEYWORD);
@@ -5398,7 +5402,34 @@ printexpr(FILE *out, Node *expr, int indent)
n += fprintf(out, "else");
n += printclause(out, expr->rhs, indent);
}
+ break;
+
+ case KLOOP:
+ case ALOOPUNTIL:
+ n += highlight(out, HLKEYWORD);
+ n += fprintf(out, "loop");
+ n += printclause(out, expr->lhs, indent);
+ if (expr->kind == KLOOP)
+ break;
+
+ do {
+ int i;
+ n += fprintf(out, "\n");
+ for (i = 0; i < indent; ++i)
+ n += fprintf(out, "\t");
+
+ } while (0);
+
+ n += highlight(out, HLKEYWORD);
+ n += fprintf(out, "until ");
+ n += printexpr(out, expr->u.payload, indent);
+
+ if (expr->rhs) {
+ n += highlight(out, HLKEYWORD);
+ n += fprintf(out, " else");
+ n += printclause(out, expr->rhs, indent);
+ }
break;
@@ -5447,7 +5478,22 @@ printexpr(FILE *out, Node *expr, int indent)
break;
case ASCOPE:
+ /* TODO(m21c): improve this piece of code */
+ if (expr->lhs &&
+ expr->lhs->kind == ASTMT &&
+ expr->u.env &&
+ expr->u.env->kind != SFUNCTION &&
+ expr->u.env->kind != SSTRUCT)
+ {
+ Node *stmt = expr->lhs;
+
+ if (!stmt->rhs && isclauseorempty(stmt)) {
+ n += printexpr(out, stmt->lhs, indent);
+ break;
+ }
+ }
n += printexpr(out, expr->lhs, indent);
+ n += fprintf(out, "\n"); /* blank line */
break;
case ACONV: