From 6f70286a4be2bfaa6a2dc9314b72518db930333a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 14 Mar 2024 13:50:24 -0400 Subject: Clean up codegen to not use macros --- compile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'compile.c') 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) -- cgit v1.2.3