diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2026-01-11 19:08:32 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2026-01-11 19:08:32 -0500 |
| commit | 6068a746896407b5ef33bca72a8be6fced14439b (patch) | |
| tree | b2eaae9885555148b45c9de3d4d719fbf3ce3550 /src/compile | |
| parent | 479788ab3a9297fc68fc6f753241291ba37a7539 (diff) | |
Implement some missing logic for reals
Diffstat (limited to 'src/compile')
| -rw-r--r-- | src/compile/comparisons.c | 3 | ||||
| -rw-r--r-- | src/compile/expressions.c | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/compile/comparisons.c b/src/compile/comparisons.c index afb5dc15..99f220e3 100644 --- a/src/compile/comparisons.c +++ b/src/compile/comparisons.c @@ -50,6 +50,8 @@ Text_t compile_comparison(env_t *env, ast_t *ast) { switch (operand_t->tag) { case BigIntType: return Texts(ast->tag == Equals ? EMPTY_TEXT : Text("!"), "Int$equal_value(", lhs, ", ", rhs, ")"); + case RealType: + return Texts(ast->tag == Equals ? EMPTY_TEXT : Text("!"), "Real$equal_values(", lhs, ", ", rhs, ")"); case BoolType: case ByteType: case IntType: @@ -94,6 +96,7 @@ Text_t compile_comparison(env_t *env, ast_t *ast) { const char *op = comparison_operator(ast->tag); switch (operand_t->tag) { case BigIntType: return Texts("(Int$compare_value(", lhs, ", ", rhs, ") ", op, " 0)"); + case RealType: return Texts("(Real$compare_values(", lhs, ", ", rhs, ") ", op, " 0)"); case BoolType: case ByteType: case IntType: diff --git a/src/compile/expressions.c b/src/compile/expressions.c index e2c1d68a..321f5f9f 100644 --- a/src/compile/expressions.c +++ b/src/compile/expressions.c @@ -85,6 +85,7 @@ Text_t compile_empty(type_t *t) { case FloatType: { return Match(t, FloatType)->bits == TYPE_NBITS32 ? Text("F32(0.0f)") : Text("F64(0.0)"); } + case RealType: return Text("Real$from_float64(0.0)"); case StructType: return compile_empty_struct(t); case EnumType: return compile_empty_enum(t); default: return EMPTY_TEXT; @@ -157,7 +158,7 @@ Text_t compile(env_t *env, ast_t *ast) { return Texts(b->code, "(", compile_arguments(env, ast, fn->args, new (arg_ast_t, .value = value)), ")"); } - if (t->tag == IntType || t->tag == FloatType) return Texts("-(", compile(env, value), ")"); + if (t->tag == IntType || t->tag == FloatType || t->tag == RealType) return Texts("-(", compile(env, value), ")"); code_err(ast, "I don't know how to get the negative value of type ", type_to_text(t)); } @@ -213,6 +214,8 @@ Text_t compile(env_t *env, ast_t *ast) { if (key_t->tag == BigIntType) comparison = Texts("(Int$compare_value(", lhs_key, ", ", rhs_key, ")", (ast->tag == Min ? "<=" : ">="), "0)"); + else if (key_t->tag == RealType) + comparison = Texts("(Real$compare_values(", lhs_key, ", ", rhs_key, ")", (ast->tag == Min ? "<=" : ">="), "0)"); else if (key_t->tag == IntType || key_t->tag == FloatType || key_t->tag == BoolType || key_t->tag == PointerType || key_t->tag == ByteType) comparison = Texts("((", lhs_key, ")", (ast->tag == Min ? "<=" : ">="), "(", rhs_key, "))"); |
