diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-11-09 18:42:16 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-11-09 18:42:16 -0500 |
| commit | 1d461611bac782c272d0e082d5da74b4fe353ae6 (patch) | |
| tree | 0b1687a3edb507835f9aa3b7666fd590975b73ff /src/compile | |
| parent | 78fd9141bb7dfcf817158a7a4d098e0e4b3d515b (diff) | |
Rename Num -> Float64, Num32 -> Float32
Diffstat (limited to 'src/compile')
| -rw-r--r-- | src/compile/assignments.c | 8 | ||||
| -rw-r--r-- | src/compile/binops.c | 27 | ||||
| -rw-r--r-- | src/compile/comparisons.c | 4 | ||||
| -rw-r--r-- | src/compile/expressions.c | 8 | ||||
| -rw-r--r-- | src/compile/functions.c | 20 | ||||
| -rw-r--r-- | src/compile/integers.c | 8 | ||||
| -rw-r--r-- | src/compile/lists.c | 4 | ||||
| -rw-r--r-- | src/compile/optionals.c | 6 | ||||
| -rw-r--r-- | src/compile/promotions.c | 7 | ||||
| -rw-r--r-- | src/compile/statements.c | 2 | ||||
| -rw-r--r-- | src/compile/text.c | 2 | ||||
| -rw-r--r-- | src/compile/types.c | 8 |
12 files changed, 52 insertions, 52 deletions
diff --git a/src/compile/assignments.c b/src/compile/assignments.c index c0f45f5b..84c43153 100644 --- a/src/compile/assignments.c +++ b/src/compile/assignments.c @@ -22,22 +22,22 @@ Text_t compile_update_assignment(env_t *env, ast_t *ast) { Text_t update_assignment = EMPTY_TEXT; switch (ast->tag) { case PlusUpdate: { - if (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType) + if (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType) update_assignment = Texts(lhs, " += ", compile_to_type(env, update.rhs, lhs_t), ";"); break; } case MinusUpdate: { - if (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType) + if (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType) update_assignment = Texts(lhs, " -= ", compile_to_type(env, update.rhs, lhs_t), ";"); break; } case MultiplyUpdate: { - if (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType) + if (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType) update_assignment = Texts(lhs, " *= ", compile_to_type(env, update.rhs, lhs_t), ";"); break; } case DivideUpdate: { - if (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType) + if (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType) update_assignment = Texts(lhs, " /= ", compile_to_type(env, update.rhs, lhs_t), ";"); break; } 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 ", diff --git a/src/compile/comparisons.c b/src/compile/comparisons.c index ffa04b9d..bc927599 100644 --- a/src/compile/comparisons.c +++ b/src/compile/comparisons.c @@ -50,7 +50,7 @@ Text_t compile_comparison(env_t *env, ast_t *ast) { case BoolType: case ByteType: case IntType: - case NumType: + case FloatType: case PointerType: case FunctionType: return Texts("(", lhs, ast->tag == Equals ? " == " : " != ", rhs, ")"); default: @@ -92,7 +92,7 @@ Text_t compile_comparison(env_t *env, ast_t *ast) { case BoolType: case ByteType: case IntType: - case NumType: + case FloatType: case PointerType: case FunctionType: return Texts("(", lhs, " ", op, " ", rhs, ")"); default: diff --git a/src/compile/expressions.c b/src/compile/expressions.c index 108bda80..ce44dafc 100644 --- a/src/compile/expressions.c +++ b/src/compile/expressions.c @@ -53,8 +53,8 @@ Text_t compile_empty(type_t *t) { return empty_pointed.length == 0 ? EMPTY_TEXT : Texts(ptr->is_stack ? Text("stack(") : Text("heap("), empty_pointed, ")"); } - case NumType: { - return Match(t, NumType)->bits == TYPE_NBITS32 ? Text("N32(0.0f)") : Text("N64(0.0)"); + case FloatType: { + return Match(t, FloatType)->bits == TYPE_NBITS32 ? Text("F32(0.0f)") : Text("F64(0.0)"); } case StructType: return compile_empty_struct(t); case EnumType: return compile_empty_enum(t); @@ -109,7 +109,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 == NumType) return Texts("-(", compile(env, value), ")"); + if (t->tag == IntType || t->tag == FloatType) return Texts("-(", compile(env, value), ")"); code_err(ast, "I don't know how to get the negative value of type ", type_to_text(t)); } @@ -165,7 +165,7 @@ 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 == IntType || key_t->tag == NumType || key_t->tag == BoolType || key_t->tag == PointerType + 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, "))"); else diff --git a/src/compile/functions.c b/src/compile/functions.c index 4a2812ba..a14c0455 100644 --- a/src/compile/functions.c +++ b/src/compile/functions.c @@ -4,8 +4,8 @@ #include "../environment.h" #include "../naming.h" #include "../stdlib/datatypes.h" +#include "../stdlib/floats.h" #include "../stdlib/integers.h" -#include "../stdlib/nums.h" #include "../stdlib/tables.h" #include "../stdlib/text.h" #include "../stdlib/util.h" @@ -79,12 +79,12 @@ Text_t compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_ Text_t value; if (spec_arg->type->tag == IntType && call_arg->value->tag == Int) { value = compile_int_to_type(env, call_arg->value, spec_arg->type); - } else if (spec_arg->type->tag == NumType && call_arg->value->tag == Int) { + } else if (spec_arg->type->tag == FloatType && call_arg->value->tag == Int) { OptionalInt_t int_val = Int$from_str(Match(call_arg->value, Int)->str); if (int_val.small == 0) code_err(call_arg->value, "Failed to parse this integer"); - if (Match(spec_arg->type, NumType)->bits == TYPE_NBITS64) - value = Text$from_str(String(hex_double(Num$from_int(int_val, false)))); - else value = Text$from_str(String(hex_double((double)Num32$from_int(int_val, false)), "f")); + if (Match(spec_arg->type, FloatType)->bits == TYPE_NBITS64) + value = Text$from_str(String(hex_double(Float64$from_int(int_val, false)))); + else value = Text$from_str(String(hex_double((double)Float32$from_int(int_val, false)), "f")); } else { env_t *arg_env = with_enum_scope(env, spec_arg->type); value = compile_maybe_incref(arg_env, call_arg->value, spec_arg->type); @@ -103,12 +103,12 @@ Text_t compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_ Text_t value; if (spec_arg->type->tag == IntType && call_arg->value->tag == Int) { value = compile_int_to_type(env, call_arg->value, spec_arg->type); - } else if (spec_arg->type->tag == NumType && call_arg->value->tag == Int) { + } else if (spec_arg->type->tag == FloatType && call_arg->value->tag == Int) { OptionalInt_t int_val = Int$from_str(Match(call_arg->value, Int)->str); if (int_val.small == 0) code_err(call_arg->value, "Failed to parse this integer"); - if (Match(spec_arg->type, NumType)->bits == TYPE_NBITS64) - value = Text$from_str(String(hex_double(Num$from_int(int_val, false)))); - else value = Text$from_str(String(hex_double((double)Num32$from_int(int_val, false)), "f")); + if (Match(spec_arg->type, FloatType)->bits == TYPE_NBITS64) + value = Text$from_str(String(hex_double(Float64$from_int(int_val, false)))); + else value = Text$from_str(String(hex_double((double)Float32$from_int(int_val, false)), "f")); } else { env_t *arg_env = with_enum_scope(env, spec_arg->type); value = compile_maybe_incref(arg_env, call_arg->value, spec_arg->type); @@ -179,7 +179,7 @@ Text_t compile_function_call(env_t *env, ast_t *ast) { // not go through any conversion, just a cast: if (is_numeric_type(t) && call->args && !call->args->next && call->args->value->tag == Int) return compile_to_type(env, call->args->value, t); - else if (t->tag == NumType && call->args && !call->args->next && call->args->value->tag == Num) + else if (t->tag == FloatType && call->args && !call->args->next && call->args->value->tag == Num) return compile_to_type(env, call->args->value, t); binding_t *constructor = diff --git a/src/compile/integers.c b/src/compile/integers.c index 78d48b70..219847cf 100644 --- a/src/compile/integers.c +++ b/src/compile/integers.c @@ -49,11 +49,11 @@ Text_t compile_int_to_type(env_t *env, ast_t *ast, type_t *target) { if (target->tag == ByteType) { if (mpz_cmp_si(i, UINT8_MAX) <= 0 && mpz_cmp_si(i, 0) >= 0) return Texts("(Byte_t)(", c_literal, ")"); code_err(ast, "This integer cannot fit in a byte"); - } else if (target->tag == NumType) { - if (Match(target, NumType)->bits == TYPE_NBITS64) { - return Texts("N64(", c_literal, ")"); + } else if (target->tag == FloatType) { + if (Match(target, FloatType)->bits == TYPE_NBITS64) { + return Texts("F64(", c_literal, ")"); } else { - return Texts("N32(", c_literal, ")"); + return Texts("F32(", c_literal, ")"); } } else if (target->tag == IntType) { int64_t target_bits = (int64_t)Match(target, IntType)->bits; diff --git a/src/compile/lists.c b/src/compile/lists.c index 54ad6e7f..1f3590a9 100644 --- a/src/compile/lists.c +++ b/src/compile/lists.c @@ -113,12 +113,12 @@ Text_t compile_list_method_call(env_t *env, ast_t *ast) { return Texts("List$has_value(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", compile_type_info(self_value_t), ")"); } else if (streq(call->name, "sample")) { - type_t *random_num_type = parse_type_string(env, "func(->Num)?"); + type_t *random_num_type = parse_type_string(env, "func(->Float64)?"); self = compile_to_pointer_depth(env, call->self, 0, false); arg_t *arg_spec = new (arg_t, .name = "count", .type = INT_TYPE, .next = new ( - arg_t, .name = "weights", .type = Type(ListType, .item_type = Type(NumType, .bits = TYPE_NBITS64)), + arg_t, .name = "weights", .type = Type(ListType, .item_type = Type(FloatType, .bits = TYPE_NBITS64)), .default_val = FakeAST(None), .next = new (arg_t, .name = "random", .type = random_num_type, .default_val = FakeAST(None)))); return Texts("List$sample(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", diff --git a/src/compile/optionals.c b/src/compile/optionals.c index b4930d02..7da50b0b 100644 --- a/src/compile/optionals.c +++ b/src/compile/optionals.c @@ -75,7 +75,7 @@ Text_t compile_none(type_t *t) { case CStringType: return Text("NULL"); case PointerType: return Texts("((", compile_type(t), ")NULL)"); case ClosureType: return Text("NONE_CLOSURE"); - case NumType: return Text("nan(\"none\")"); + case FloatType: return Text("nan(\"none\")"); case StructType: return Texts("((", compile_type(Type(OptionalType, .type = t)), "){.has_value=false})"); case EnumType: { env_t *enum_env = Match(t, EnumType)->env; @@ -96,8 +96,8 @@ Text_t check_none(type_t *t, Text_t value) { else if (t == PATH_TYPE_TYPE) return Texts("((", value, ").$tag == PATHTYPE_NONE)"); else if (t->tag == BigIntType) return Texts("((", value, ").small == 0)"); else if (t->tag == ClosureType) return Texts("((", value, ").fn == NULL)"); - else if (t->tag == NumType) - return Texts(Match(t, NumType)->bits == TYPE_NBITS64 ? "Num$isnan(" : "Num32$isnan(", value, ")"); + else if (t->tag == FloatType) + return Texts(Match(t, FloatType)->bits == TYPE_NBITS64 ? "Float64$isnan(" : "Float32$isnan(", value, ")"); else if (t->tag == ListType) return Texts("((", value, ").data == NULL)"); else if (t->tag == TableType) return Texts("((", value, ").entries.data == NULL)"); else if (t->tag == BoolType) return Texts("((", value, ") == NONE_BOOL)"); diff --git a/src/compile/promotions.c b/src/compile/promotions.c index b3cbb361..2a346668 100644 --- a/src/compile/promotions.c +++ b/src/compile/promotions.c @@ -56,7 +56,8 @@ bool promote(env_t *env, ast_t *ast, Text_t *code, type_t *actual, type_t *neede if (actual->tag == TextType && needed->tag == TextType && streq(Match(needed, TextType)->lang, "Text")) return true; // Automatic optional checking for nums: - if (needed->tag == NumType && actual->tag == OptionalType && Match(actual, OptionalType)->type->tag == NumType) { + if (needed->tag == FloatType && actual->tag == OptionalType + && Match(actual, OptionalType)->type->tag == FloatType) { int64_t line = get_line_number(ast->file, ast->start); *code = Texts("({ ", compile_declaration(actual, Text("opt")), " = ", *code, "; ", "if unlikely (", @@ -129,9 +130,9 @@ Text_t compile_to_type(env_t *env, ast_t *ast, type_t *t) { if (ast->tag == Int && is_numeric_type(non_optional(t))) { return compile_int_to_type(env, ast, t); - } else if (ast->tag == Num && t->tag == NumType) { + } else if (ast->tag == Num && t->tag == FloatType) { double n = Match(ast, Num)->n; - switch (Match(t, NumType)->bits) { + switch (Match(t, FloatType)->bits) { case TYPE_NBITS64: return Text$from_str(String(hex_double(n))); case TYPE_NBITS32: return Text$from_str(String(hex_double(n), "f")); default: code_err(ast, "This is not a valid number bit width"); diff --git a/src/compile/statements.c b/src/compile/statements.c index 0cd85b5d..f554263c 100644 --- a/src/compile/statements.c +++ b/src/compile/statements.c @@ -28,7 +28,7 @@ Text_t with_source_info(env_t *env, ast_t *ast, Text_t code) { static Text_t compile_simple_update_assignment(env_t *env, ast_t *ast, const char *op) { binary_operands_t update = BINARY_OPERANDS(ast); type_t *lhs_t = get_type(env, update.lhs); - if (is_idempotent(update.lhs) && (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType)) + if (is_idempotent(update.lhs) && (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType)) return Texts(compile_lvalue(env, update.lhs), " ", op, "= ", compile_to_type(env, update.rhs, lhs_t), ";"); return compile_update_assignment(env, ast); } diff --git a/src/compile/text.c b/src/compile/text.c index 3a8a227c..25a6e9a7 100644 --- a/src/compile/text.c +++ b/src/compile/text.c @@ -24,7 +24,7 @@ Text_t expr_as_text(Text_t expr, type_t *t, Text_t color) { case BigIntType: case IntType: case ByteType: - case NumType: { + case FloatType: { Text_t name = type_to_text(t); return Texts(name, "$as_text(stack(", expr, "), ", color, ", &", name, "$info)"); } diff --git a/src/compile/types.c b/src/compile/types.c index 2b345b41..94da1c49 100644 --- a/src/compile/types.c +++ b/src/compile/types.c @@ -24,9 +24,7 @@ Text_t compile_type(type_t *t) { case CStringType: return Text("const char*"); case BigIntType: return Text("Int_t"); case IntType: return Texts("Int", (int32_t)Match(t, IntType)->bits, "_t"); - case NumType: - return Match(t, NumType)->bits == TYPE_NBITS64 ? Text("Num_t") - : Texts("Num", (int32_t)Match(t, NumType)->bits, "_t"); + case FloatType: return Texts("Float", (int32_t)Match(t, FloatType)->bits, "_t"); case TextType: { DeclareMatch(text, t, TextType); if (!text->lang || streq(text->lang, "Text")) return Text("Text_t"); @@ -66,7 +64,7 @@ Text_t compile_type(type_t *t) { case TextType: case IntType: case BigIntType: - case NumType: + case FloatType: case BoolType: case ByteType: case ListType: @@ -97,7 +95,7 @@ Text_t compile_type_info(type_t *t) { case ByteType: case IntType: case BigIntType: - case NumType: + case FloatType: case CStringType: return Texts("&", type_to_text(t), "$info"); case TextType: { DeclareMatch(text, t, TextType); |
