aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-12-04 11:04:16 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2024-12-04 11:04:16 +0200
commit5d4b4ef80d8dc427b0e2803d50e439f76f06e17a (patch)
treea5869136c1e5e869d8e232927e06f27422f31234 /src
parent2253da61e9b3dd5408bed182ea08e5270156c17e (diff)
downloadfwd-5d4b4ef80d8dc427b0e2803d50e439f76f06e17a.tar.gz
fwd-5d4b4ef80d8dc427b0e2803d50e439f76f06e17a.zip
implement expression handling further
+ Add some notes about returning functions that I started thinking about as a result of the fib example
Diffstat (limited to 'src')
-rw-r--r--src/lower.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lower.c b/src/lower.c
index ad3d1b9..46ce2c3 100644
--- a/src/lower.c
+++ b/src/lower.c
@@ -44,6 +44,13 @@ static int lower_binop(struct state *state, struct ast *binop)
return -1;
switch (binop->k) {
+ case AST_ADD: printf(" + "); break;
+ case AST_SUB: printf(" - "); break;
+ case AST_MUL: printf(" * "); break;
+ case AST_DIV: printf(" / "); break;
+ case AST_REM: printf(" %% "); break;
+ case AST_LSHIFT: printf(" << "); break;
+ case AST_RSHIFT: printf(" >> "); break;
default:
internal_error("missing binop lowering");
return -1;
@@ -63,6 +70,12 @@ static int lower_comparison(struct state *state, struct ast *comp)
return -1;
switch (comp->k) {
+ case AST_LT: printf(" < "); break;
+ case AST_GT: printf(" > "); break;
+ case AST_LE: printf(" <= "); break;
+ case AST_GE: printf(" <= "); break;
+ case AST_NE: printf(" != "); break;
+ case AST_EQ: printf(" == "); break;
default:
internal_error("missing comparison lowering");
return -1;
@@ -148,8 +161,25 @@ static int lower_init(struct state *state, struct ast *init)
return 0;
}
+static int lower_unop(struct state *state, struct ast *expr)
+{
+ switch (expr->k) {
+ case AST_LNOT: printf("-"); break;
+ case AST_NOT: printf("~"); break;
+ case AST_NEG: printf("-"); break;
+ default:
+ internal_error("missing unop lowering");
+ return -1;
+ }
+
+ return lower_expr(state, unop_expr(expr));
+}
+
static int lower_expr(struct state *state, struct ast *expr)
{
+ if (is_unop(expr))
+ return lower_unop(state, expr);
+
if (is_binop(expr))
return lower_binop(state, expr);