diff options
Diffstat (limited to 'src/compile/binops.c')
| -rw-r--r-- | src/compile/binops.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/compile/binops.c b/src/compile/binops.c index acf1e031..a84e34ba 100644 --- a/src/compile/binops.c +++ b/src/compile/binops.c @@ -113,14 +113,15 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { switch (ast->tag) { case Power: { - if (overall_t->tag != NumType) - code_err(ast, "Exponentiation is only supported for Num types, not ", type_to_text(overall_t)); - if (overall_t->tag == NumType && Match(overall_t, NumType)->bits == TYPE_NBITS32) + if (overall_t->tag != FloatType) + code_err(ast, "Exponentiation is only supported for floating point number types, not ", + type_to_text(overall_t)); + if (overall_t->tag == FloatType && Match(overall_t, FloatType)->bits == TYPE_NBITS32) return Texts("powf(", lhs, ", ", rhs, ")"); else return Texts("pow(", lhs, ", ", rhs, ")"); } case Multiply: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -128,7 +129,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " * ", rhs, ")"); } case Divide: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -136,7 +137,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " / ", rhs, ")"); } case Mod: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -144,7 +145,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " % ", rhs, ")"); } case Mod1: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -152,7 +153,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("((((", lhs, ")-1) % (", rhs, ")) + 1)"); } case Plus: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -160,7 +161,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " + ", rhs, ")"); } case Minus: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -168,7 +169,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " - ", rhs, ")"); } case LeftShift: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -176,7 +177,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " << ", rhs, ")"); } case RightShift: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -184,7 +185,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " >> ", rhs, ")"); } case UnsignedLeftShift: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -192,7 +193,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", compile_type(overall_t), ")((", compile_unsigned_type(lhs_t), ")", lhs, " << ", rhs, ")"); } case UnsignedRightShift: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", |
