aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-14 13:50:24 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-03-14 13:50:24 -0400
commit6f70286a4be2bfaa6a2dc9314b72518db930333a (patch)
tree8fa61455ff2bd60fff4f3a9a6eee31183a6354da /compile.c
parent80ffb8044ab60cedfe2ce1c3025419c282cb0965 (diff)
Clean up codegen to not use macros
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/compile.c b/compile.c
index 5f30d815..cc2bbf28 100644
--- a/compile.c
+++ b/compile.c
@@ -286,8 +286,8 @@ CORD compile_statement(env_t *env, ast_t *ast)
switch (update->op) {
case BINOP_MULT: return CORD_asprintf("%r *= %r;", lhs, rhs);
case BINOP_DIVIDE: return CORD_asprintf("%r /= %r;", lhs, rhs);
- case BINOP_MOD: return CORD_asprintf("%r = mod(%r, %r);", lhs, lhs, rhs);
- case BINOP_MOD1: return CORD_asprintf("%r = mod1(%r, %r);", lhs, lhs, rhs);
+ case BINOP_MOD: return CORD_asprintf("%r = %r %% %r;", lhs, lhs, rhs);
+ case BINOP_MOD1: return CORD_asprintf("%r = (%r %% %r) + 1;", lhs, lhs, rhs);
case BINOP_PLUS: return CORD_asprintf("%r += %r;", lhs, rhs);
case BINOP_MINUS: return CORD_asprintf("%r -= %r;", lhs, rhs);
case BINOP_POWER: {
@@ -842,12 +842,12 @@ CORD compile(env_t *env, ast_t *ast)
case BINOP_MOD: {
if (operand_t->tag != IntType && operand_t->tag != NumType)
code_err(ast, "Math operations are only supported for numeric types");
- return CORD_asprintf("mod(%r, %r)", lhs, rhs);
+ return CORD_asprintf("(%r %% %r)", lhs, rhs);
}
case BINOP_MOD1: {
if (operand_t->tag != IntType && operand_t->tag != NumType)
code_err(ast, "Math operations are only supported for numeric types");
- return CORD_asprintf("mod1(%r, %r)", lhs, rhs);
+ return CORD_asprintf("((%r %% %r) + 1)", lhs, rhs);
}
case BINOP_PLUS: {
if (operand_t->tag != IntType && operand_t->tag != NumType)