diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2026-01-11 20:06:45 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2026-01-11 20:06:45 -0500 |
| commit | b97ea6b6ac3498b21321e1f93ccc1a2dd145e9d7 (patch) | |
| tree | 834180f2c5a2ad29424279153d01c2bd52679823 /src | |
| parent | 573656fce2b7e1b0fc36944f60fd135117b6bbb6 (diff) | |
Rename AST nodes: Int -> Integer, Num -> Number
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast.c | 12 | ||||
| -rw-r--r-- | src/ast.h | 8 | ||||
| -rw-r--r-- | src/compile/assertions.c | 4 | ||||
| -rw-r--r-- | src/compile/assignments.c | 2 | ||||
| -rw-r--r-- | src/compile/comparisons.c | 8 | ||||
| -rw-r--r-- | src/compile/expressions.c | 10 | ||||
| -rw-r--r-- | src/compile/functions.c | 22 | ||||
| -rw-r--r-- | src/compile/indexing.c | 2 | ||||
| -rw-r--r-- | src/compile/integers.c | 6 | ||||
| -rw-r--r-- | src/compile/lists.c | 28 | ||||
| -rw-r--r-- | src/compile/loops.c | 6 | ||||
| -rw-r--r-- | src/compile/promotions.c | 6 | ||||
| -rw-r--r-- | src/formatter/formatter.c | 12 | ||||
| -rw-r--r-- | src/parse/functions.c | 4 | ||||
| -rw-r--r-- | src/parse/numbers.c | 8 | ||||
| -rw-r--r-- | src/typecheck.c | 37 |
16 files changed, 90 insertions, 85 deletions
@@ -178,8 +178,8 @@ Text_t ast_to_sexp(ast_t *ast) { T(None, "(None)"); T(Bool, "(Bool ", data.b ? "yes" : "no", ")"); T(Var, "(Var ", quoted_text(data.name), ")"); - T(Int, "(Int ", Text$quoted(ast_source(ast), false, Text("\"")), ")"); - T(Num, "(Num ", Text$quoted(ast_source(ast), false, Text("\"")), ")"); + T(Integer, "(Integer ", Text$quoted(ast_source(ast), false, Text("\"")), ")"); + T(Number, "(Number ", Text$quoted(ast_source(ast), false, Text("\"")), ")"); T(TextLiteral, Text$quoted(data.text, false, Text("\""))); T(TextJoin, "(Text", data.lang ? Texts(" :lang ", quoted_text(data.lang)) : EMPTY_TEXT, ast_list_to_sexp(data.children), ")"); @@ -294,9 +294,9 @@ OptionalText_t ast_source(ast_t *ast) { PUREFUNC bool is_idempotent(ast_t *ast) { switch (ast->tag) { - case Int: + case Integer: case Bool: - case Num: + case Number: case Var: case None: case TextLiteral: return true; @@ -466,8 +466,8 @@ void ast_visit(ast_t *ast, visit_behavior_t (*visitor)(ast_t *, void *), void *u case None: case Bool: case Var: - case Int: - case Num: + case Integer: + case Number: case Path: case TextLiteral: case Metadata: return; @@ -197,8 +197,8 @@ typedef enum { None, Bool, Var, - Int, - Num, + Integer, + Number, TextLiteral, TextJoin, Path, @@ -301,10 +301,10 @@ struct ast_s { } Var; struct { const char *str; - } Int; + } Integer; struct { double n; - } Num; + } Number; struct { Text_t text; } TextLiteral; diff --git a/src/compile/assertions.c b/src/compile/assertions.c index 7cb202e8..2875a441 100644 --- a/src/compile/assertions.c +++ b/src/compile/assertions.c @@ -35,9 +35,9 @@ Text_t compile_assertion(env_t *env, ast_t *ast) { type_t *operand_t; if (type_eq(lhs_t, rhs_t)) { operand_t = lhs_t; - } else if (cmp.lhs->tag == Int && is_numeric_type(rhs_t)) { + } else if (cmp.lhs->tag == Integer && is_numeric_type(rhs_t)) { operand_t = rhs_t; - } else if (cmp.rhs->tag == Int && is_numeric_type(lhs_t)) { + } else if (cmp.rhs->tag == Integer && is_numeric_type(lhs_t)) { operand_t = lhs_t; } else if (can_compile_to_type(with_enum_scope(env, lhs_t), cmp.rhs, lhs_t)) { operand_t = lhs_t; diff --git a/src/compile/assignments.c b/src/compile/assignments.c index 8c6af3ee..07ca4590 100644 --- a/src/compile/assignments.c +++ b/src/compile/assignments.c @@ -165,7 +165,7 @@ Text_t compile_lvalue(env_t *env, ast_t *ast) { Text_t target_code = compile_to_pointer_depth(env, index->indexed, 1, false); type_t *item_type = Match(container_t, ListType)->item_type; Text_t index_code = - index->index->tag == Int + index->index->tag == Integer ? compile_int_to_type(env, index->index, Type(IntType, .bits = TYPE_IBITS64)) : (index_t->tag == BigIntType ? Texts("Int64$from_int(", compile(env, index->index), ", no)") : Texts("(Int64_t)(", compile(env, index->index), ")")); diff --git a/src/compile/comparisons.c b/src/compile/comparisons.c index 99f220e3..5a02735f 100644 --- a/src/compile/comparisons.c +++ b/src/compile/comparisons.c @@ -30,9 +30,9 @@ Text_t compile_comparison(env_t *env, ast_t *ast) { type_t *operand_t; if (type_eq(lhs_t, rhs_t)) { operand_t = lhs_t; - } else if (binop.lhs->tag == Int && is_numeric_type(rhs_t)) { + } else if (binop.lhs->tag == Integer && is_numeric_type(rhs_t)) { operand_t = rhs_t; - } else if (binop.rhs->tag == Int && is_numeric_type(lhs_t)) { + } else if (binop.rhs->tag == Integer && is_numeric_type(lhs_t)) { operand_t = lhs_t; } else if (can_compile_to_type(with_enum_scope(env, lhs_t), binop.rhs, lhs_t)) { operand_t = lhs_t; @@ -75,9 +75,9 @@ Text_t compile_comparison(env_t *env, ast_t *ast) { type_t *operand_t; if (type_eq(lhs_t, rhs_t)) { operand_t = lhs_t; - } else if (cmp.lhs->tag == Int && is_numeric_type(rhs_t)) { + } else if (cmp.lhs->tag == Integer && is_numeric_type(rhs_t)) { operand_t = rhs_t; - } else if (cmp.rhs->tag == Int && is_numeric_type(lhs_t)) { + } else if (cmp.rhs->tag == Integer && is_numeric_type(lhs_t)) { operand_t = lhs_t; } else if (can_compile_to_type(env, cmp.rhs, lhs_t)) { operand_t = lhs_t; diff --git a/src/compile/expressions.c b/src/compile/expressions.c index 321f5f9f..ae57204b 100644 --- a/src/compile/expressions.c +++ b/src/compile/expressions.c @@ -107,8 +107,8 @@ Text_t compile(env_t *env, ast_t *ast) { // return Texts("_$", Match(ast, Var)->name); code_err(ast, "I don't know of any variable by this name"); } - case Int: return compile_int(ast); - case Num: { + case Integer: return compile_int(ast); + case Number: { const char *src = String(string_slice(ast->start, (size_t)(ast->end - ast->start))); Text_t corrected = Text$from_str(src); corrected = Text$replace(corrected, Text("_"), EMPTY_TEXT); @@ -158,7 +158,8 @@ 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 || t->tag == RealType) 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)); } @@ -215,7 +216,8 @@ Text_t compile(env_t *env, ast_t *ast) { 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)"); + 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, "))"); diff --git a/src/compile/functions.c b/src/compile/functions.c index cadd0453..2784bedd 100644 --- a/src/compile/functions.c +++ b/src/compile/functions.c @@ -79,10 +79,10 @@ Text_t compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_ continue; Text_t value; - if (spec_arg->type->tag == IntType && call_arg->value->tag == Int) { + if (spec_arg->type->tag == IntType && call_arg->value->tag == Integer) { value = compile_int_to_type(env, call_arg->value, spec_arg->type); - } 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); + } else if (spec_arg->type->tag == FloatType && call_arg->value->tag == Integer) { + OptionalInt_t int_val = Int$from_str(Match(call_arg->value, Integer)->str); if (int_val.small == 0) code_err(call_arg->value, "Failed to parse this integer"); if (Match(spec_arg->type, FloatType)->bits == TYPE_NBITS64) value = Text$from_str(String(hex_double(Float64$from_int(int_val, false)))); @@ -103,10 +103,10 @@ Text_t compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_ const char *pseudoname = String(i++); if (!Table$str_get(used_args, pseudoname)) { Text_t value; - if (spec_arg->type->tag == IntType && call_arg->value->tag == Int) { + if (spec_arg->type->tag == IntType && call_arg->value->tag == Integer) { value = compile_int_to_type(env, call_arg->value, spec_arg->type); - } 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); + } else if (spec_arg->type->tag == FloatType && call_arg->value->tag == Integer) { + OptionalInt_t int_val = Int$from_str(Match(call_arg->value, Integer)->str); if (int_val.small == 0) code_err(call_arg->value, "Failed to parse this integer"); if (Match(spec_arg->type, FloatType)->bits == TYPE_NBITS64) value = Text$from_str(String(hex_double(Float64$from_int(int_val, false)))); @@ -179,9 +179,9 @@ Text_t compile_function_call(env_t *env, ast_t *ast) { // Literal constructors for numeric types like `Byte(123)` should // not go through any conversion, just a cast: - if (is_numeric_type(t) && call->args && !call->args->next && call->args->value->tag == Int) + if (is_numeric_type(t) && call->args && !call->args->next && call->args->value->tag == Integer) return compile_to_type(env, call->args->value, t); - else if (t->tag == FloatType && call->args && !call->args->next && call->args->value->tag == Num) + else if (t->tag == FloatType && call->args && !call->args->next && call->args->value->tag == Number) return compile_to_type(env, call->args->value, t); binding_t *constructor = @@ -827,11 +827,11 @@ Text_t compile_function(env_t *env, Text_t name_code, ast_t *ast, Text_t *static "return cached_result;\n" "}\n"); definition = Texts(definition, wrapper); - } else if (cache && cache->tag == Int) { + } else if (cache && cache->tag == Integer) { assert(args); - OptionalInt64_t cache_size = Int64$parse(Text$from_str(Match(cache, Int)->str), NONE_INT, NULL); + OptionalInt64_t cache_size = Int64$parse(Text$from_str(Match(cache, Integer)->str), NONE_INT, NULL); Text_t pop_code = EMPTY_TEXT; - if (cache->tag == Int && cache_size.has_value && cache_size.value > 0) { + if (cache->tag == Integer && cache_size.has_value && cache_size.value > 0) { // FIXME: this currently just deletes the first entry, but this // should be more like a least-recently-used cache eviction policy // or least-frequently-used diff --git a/src/compile/indexing.c b/src/compile/indexing.c index 031ef9a0..0c0ab770 100644 --- a/src/compile/indexing.c +++ b/src/compile/indexing.c @@ -37,7 +37,7 @@ Text_t compile_indexing(env_t *env, ast_t *ast, bool checked) { type_t *item_type = Match(container_t, ListType)->item_type; Text_t list = compile_to_pointer_depth(env, indexing->indexed, 0, false); Text_t index_code = - indexing->index->tag == Int + indexing->index->tag == Integer ? compile_int_to_type(env, indexing->index, Type(IntType, .bits = TYPE_IBITS64)) : (index_t->tag == BigIntType ? Texts("Int64$from_int(", compile(env, indexing->index), ", no)") : Texts("(Int64_t)(", compile(env, indexing->index), ")")); diff --git a/src/compile/integers.c b/src/compile/integers.c index 219847cf..ea316218 100644 --- a/src/compile/integers.c +++ b/src/compile/integers.c @@ -14,7 +14,7 @@ public Text_t compile_int_to_type(env_t *env, ast_t *ast, type_t *target) { - if (ast->tag != Int) { + if (ast->tag != Integer) { Text_t code = compile(env, ast); type_t *actual_type = get_type(env, ast); if (!promote(env, ast, &code, actual_type, target)) @@ -30,7 +30,7 @@ Text_t compile_int_to_type(env_t *env, ast_t *ast, type_t *target) { ", .has_value=true})"); } - const char *literal = Match(ast, Int)->str; + const char *literal = Match(ast, Integer)->str; OptionalInt_t int_val = Int$from_str(literal); if (int_val.small == 0) code_err(ast, "Failed to parse this integer"); @@ -82,7 +82,7 @@ Text_t compile_int_to_type(env_t *env, ast_t *ast, type_t *target) { public Text_t compile_int(ast_t *ast) { - const char *str = Match(ast, Int)->str; + const char *str = Match(ast, Integer)->str; OptionalInt_t int_val = Int$from_str(str); if (int_val.small == 0) code_err(ast, "Failed to parse this integer"); mpz_t i; diff --git a/src/compile/lists.c b/src/compile/lists.c index f39f61d8..9c969d2c 100644 --- a/src/compile/lists.c +++ b/src/compile/lists.c @@ -83,28 +83,28 @@ Text_t compile_list_method_call(env_t *env, ast_t *ast) { EXPECT_POINTER(); arg_t *arg_spec = new (arg_t, .name = "item", .type = item_t, - .next = new (arg_t, .name = "at", .type = INT_TYPE, .default_val = FakeAST(Int, .str = "0"))); + .next = new (arg_t, .name = "at", .type = INT_TYPE, .default_val = FakeAST(Integer, .str = "0"))); return Texts("List$insert_value(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", padded_item_size, ")"); } else if (streq(call->name, "insert_all")) { EXPECT_POINTER(); arg_t *arg_spec = new (arg_t, .name = "items", .type = self_value_t, - .next = new (arg_t, .name = "at", .type = INT_TYPE, .default_val = FakeAST(Int, .str = "0"))); + .next = new (arg_t, .name = "at", .type = INT_TYPE, .default_val = FakeAST(Integer, .str = "0"))); return Texts("List$insert_all(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", padded_item_size, ")"); } else if (streq(call->name, "remove_at")) { EXPECT_POINTER(); arg_t *arg_spec = - new (arg_t, .name = "index", .type = INT_TYPE, .default_val = FakeAST(Int, .str = "-1"), - .next = new (arg_t, .name = "count", .type = INT_TYPE, .default_val = FakeAST(Int, .str = "1"))); + new (arg_t, .name = "index", .type = INT_TYPE, .default_val = FakeAST(Integer, .str = "-1"), + .next = new (arg_t, .name = "count", .type = INT_TYPE, .default_val = FakeAST(Integer, .str = "1"))); return Texts("List$remove_at(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", padded_item_size, ")"); } else if (streq(call->name, "remove_item")) { EXPECT_POINTER(); - arg_t *arg_spec = - new (arg_t, .name = "item", .type = item_t, - .next = new (arg_t, .name = "max_count", .type = INT_TYPE, .default_val = FakeAST(Int, .str = "-1"))); + arg_t *arg_spec = new ( + arg_t, .name = "item", .type = item_t, + .next = new (arg_t, .name = "max_count", .type = INT_TYPE, .default_val = FakeAST(Integer, .str = "-1"))); return Texts("List$remove_item_value(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", compile_type_info(self_value_t), ")"); } else if (streq(call->name, "has")) { @@ -115,12 +115,12 @@ Text_t compile_list_method_call(env_t *env, ast_t *ast) { } else if (streq(call->name, "sample")) { 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(FloatType, .bits = TYPE_NBITS64)), - .default_val = FakeAST(None), - .next = new (arg_t, .name = "random", .type = random_num_type, .default_val = FakeAST(None)))); + arg_t *arg_spec = new ( + arg_t, .name = "count", .type = INT_TYPE, + .next = new (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), ", ", padded_item_size, ")"); } else if (streq(call->name, "shuffle")) { @@ -257,7 +257,7 @@ Text_t compile_list_method_call(env_t *env, ast_t *ast) { return Texts("Table$from_entries(", self, ", Table$info(", compile_type_info(item_t), ", &Present$$info))"); } else if (streq(call->name, "pop")) { EXPECT_POINTER(); - arg_t *arg_spec = new (arg_t, .name = "index", .type = INT_TYPE, .default_val = FakeAST(Int, "-1")); + arg_t *arg_spec = new (arg_t, .name = "index", .type = INT_TYPE, .default_val = FakeAST(Integer, "-1")); Text_t index = compile_arguments(env, ast, arg_spec, call->args); return Texts("List$pop(", self, ", ", index, ", ", compile_type(item_t), ", _, ", promote_to_optional(item_t, Text("_")), ", ", compile_none(item_t), ")"); diff --git a/src/compile/loops.c b/src/compile/loops.c index 96299c5e..f3ae9b59 100644 --- a/src/compile/loops.c +++ b/src/compile/loops.c @@ -125,7 +125,7 @@ Text_t compile_for_loop(env_t *env, ast_t *ast) { // Special case for Int.onward() arg_ast_t *args = Match(for_->iter, MethodCall)->args; arg_t *arg_spec = - new (arg_t, .name = "step", .type = INT_TYPE, .default_val = FakeAST(Int, .str = "1"), .next = NULL); + new (arg_t, .name = "step", .type = INT_TYPE, .default_val = FakeAST(Integer, .str = "1"), .next = NULL); Text_t step = compile_arguments(env, for_->iter, arg_spec, args); Text_t value = for_->vars ? compile(body_scope, for_->vars->ast) : Text("i"); return Texts("for (Int_t ", value, " = ", compile(env, Match(for_->iter, MethodCall)->self), ", ", @@ -231,8 +231,8 @@ Text_t compile_for_loop(env_t *env, ast_t *ast) { } case BigIntType: { Text_t n; - if (for_->iter->tag == Int) { - const char *str = Match(for_->iter, Int)->str; + if (for_->iter->tag == Integer) { + const char *str = Match(for_->iter, Integer)->str; Int_t int_val = Int$from_str(str); if (int_val.small == 0) code_err(for_->iter, "Failed to parse this integer"); mpz_t i; diff --git a/src/compile/promotions.c b/src/compile/promotions.c index 151850f0..a13108e5 100644 --- a/src/compile/promotions.c +++ b/src/compile/promotions.c @@ -137,10 +137,10 @@ Text_t compile_to_type(env_t *env, ast_t *ast, type_t *t) { ast = Match(ast, Block)->statements->ast; } - if (ast->tag == Int && is_numeric_type(non_optional(t))) { + if (ast->tag == Integer && is_numeric_type(non_optional(t))) { return compile_int_to_type(env, ast, t); - } else if (ast->tag == Num && t->tag == FloatType) { - double n = Match(ast, Num)->n; + } else if (ast->tag == Number && t->tag == FloatType) { + double n = Match(ast, Number)->n; 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")); diff --git a/src/formatter/formatter.c b/src/formatter/formatter.c index 5cb5d3cc..3a6001b6 100644 --- a/src/formatter/formatter.c +++ b/src/formatter/formatter.c @@ -327,13 +327,13 @@ OptionalText_t format_inline_code(ast_t *ast, Table_t comments) { return Text("none"); /*inline*/ case Bool: return Match(ast, Bool)->b ? Text("yes") : Text("no"); - /*inline*/ case Int: { + /*inline*/ case Integer: { OptionalText_t source = ast_source(ast); - return source.length > 0 ? source : Text$from_str(Match(ast, Int)->str); + return source.length > 0 ? source : Text$from_str(Match(ast, Integer)->str); } - /*inline*/ case Num: { + /*inline*/ case Number: { OptionalText_t source = ast_source(ast); - return source.length > 0 ? source : Text$from_str(String(Match(ast, Num)->n)); + return source.length > 0 ? source : Text$from_str(String(Match(ast, Number)->n)); } /*inline*/ case Var: return Text$from_str(Match(ast, Var)->name); @@ -747,8 +747,8 @@ Text_t format_code(ast_t *ast, Table_t comments, Text_t indent) { /*multiline*/ case Skip: /*multiline*/ case None: /*multiline*/ case Bool: - /*multiline*/ case Int: - /*multiline*/ case Num: + /*multiline*/ case Integer: + /*multiline*/ case Number: /*multiline*/ case Var: { assert(inlined.tag != TEXT_NONE); return inlined; diff --git a/src/parse/functions.c b/src/parse/functions.c index 8fb9f78e..e4eb1317 100644 --- a/src/parse/functions.c +++ b/src/parse/functions.c @@ -119,7 +119,7 @@ ast_t *parse_func_def(parse_ctx_t *ctx, const char *pos) { if (match_word(&pos, "inline")) { is_inline = true; } else if (match_word(&pos, "cached")) { - if (!cache_ast) cache_ast = NewAST(ctx->file, pos, pos, Int, .str = "-1"); + if (!cache_ast) cache_ast = NewAST(ctx->file, pos, pos, Integer, .str = "-1"); } else if (match_word(&pos, "cache_size")) { whitespace(ctx, &pos); if (!match(&pos, "=")) parser_err(ctx, flag_start, pos, "I expected a value for 'cache_size'"); @@ -153,7 +153,7 @@ ast_t *parse_convert_def(parse_ctx_t *ctx, const char *pos) { if (match_word(&pos, "inline")) { is_inline = true; } else if (match_word(&pos, "cached")) { - if (!cache_ast) cache_ast = NewAST(ctx->file, pos, pos, Int, .str = "-1"); + if (!cache_ast) cache_ast = NewAST(ctx->file, pos, pos, Integer, .str = "-1"); } else if (match_word(&pos, "cache_size")) { whitespace(ctx, &pos); if (!match(&pos, "=")) parser_err(ctx, flag_start, pos, "I expected a value for 'cache_size'"); diff --git a/src/parse/numbers.c b/src/parse/numbers.c index 4e746525..1ab774b4 100644 --- a/src/parse/numbers.c +++ b/src/parse/numbers.c @@ -40,13 +40,13 @@ ast_t *parse_int(parse_ctx_t *ctx, const char *pos) { if (match(&pos, "%")) { double n = strtod(str, NULL) / 100.; - return NewAST(ctx->file, start, pos, Num, .n = n); + return NewAST(ctx->file, start, pos, Number, .n = n); } else if (match(&pos, "deg")) { double n = strtod(str, NULL) * RADIANS_PER_DEGREE; - return NewAST(ctx->file, start, pos, Num, .n = n); + return NewAST(ctx->file, start, pos, Number, .n = n); } - return NewAST(ctx->file, start, pos, Int, .str = str); + return NewAST(ctx->file, start, pos, Integer, .str = str); } ast_t *parse_num(parse_ctx_t *ctx, const char *pos) { @@ -77,5 +77,5 @@ ast_t *parse_num(parse_ctx_t *ctx, const char *pos) { if (match(&pos, "%")) d /= 100.; else if (match(&pos, "deg")) d *= RADIANS_PER_DEGREE; - return NewAST(ctx->file, start, pos, Num, .n = d); + return NewAST(ctx->file, start, pos, Number, .n = d); } diff --git a/src/typecheck.c b/src/typecheck.c index dc234bac..166ae2e1 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -691,10 +691,10 @@ type_t *get_type(env_t *env, ast_t *ast) { case Bool: { return Type(BoolType); } - case Int: { + case Integer: { return Type(BigIntType); } - case Num: { + case Number: { return Type(RealType); } case HeapAllocate: { @@ -1104,8 +1104,8 @@ type_t *get_type(env_t *env, ast_t *ast) { type_t *lhs_t = get_type(env, binop.lhs); type_t *rhs_t = get_type(env, binop.rhs); - if (binop.lhs->tag == Int && is_int_type(rhs_t)) return rhs_t; - else if (binop.rhs->tag == Int && is_int_type(lhs_t)) return lhs_t; + if (binop.lhs->tag == Integer && is_int_type(rhs_t)) return rhs_t; + else if (binop.rhs->tag == Integer && is_int_type(lhs_t)) return lhs_t; // `opt? or (x == y)` / `(x == y) or opt?` is a boolean conditional: if ((lhs_t->tag == OptionalType && rhs_t->tag == BoolType) @@ -1147,8 +1147,8 @@ type_t *get_type(env_t *env, ast_t *ast) { type_t *lhs_t = get_type(env, binop.lhs); type_t *rhs_t = get_type(env, binop.rhs); - if (binop.lhs->tag == Int && is_int_type(rhs_t)) return rhs_t; - else if (binop.rhs->tag == Int && is_int_type(lhs_t)) return lhs_t; + if (binop.lhs->tag == Integer && is_int_type(rhs_t)) return rhs_t; + else if (binop.rhs->tag == Integer && is_int_type(lhs_t)) return lhs_t; // `and` between optionals/bools is a boolean expression like `if opt? and opt?:` or `if x > 0 and opt?:` if ((lhs_t->tag == OptionalType || lhs_t->tag == BoolType) @@ -1177,8 +1177,8 @@ type_t *get_type(env_t *env, ast_t *ast) { type_t *lhs_t = get_type(env, binop.lhs); type_t *rhs_t = get_type(env, binop.rhs); - if (binop.lhs->tag == Int && is_int_type(rhs_t)) return rhs_t; - else if (binop.rhs->tag == Int && is_int_type(lhs_t)) return lhs_t; + if (binop.lhs->tag == Integer && is_int_type(rhs_t)) return rhs_t; + else if (binop.rhs->tag == Integer && is_int_type(lhs_t)) return lhs_t; // `xor` between optionals/bools is a boolean expression like `if opt? xor opt?:` or `if x > 0 xor opt?:` if ((lhs_t->tag == OptionalType || lhs_t->tag == BoolType) @@ -1214,8 +1214,9 @@ type_t *get_type(env_t *env, ast_t *ast) { type_t *rhs_t = get_type(env, binop.rhs); if (type_eq(lhs_t, rhs_t)) return ast->tag == Compare ? Type(IntType, .bits = TYPE_IBITS32) : Type(BoolType); - if ((binop.lhs->tag == Int && is_numeric_type(rhs_t)) || (binop.rhs->tag == Int && is_numeric_type(lhs_t)) - || can_compile_to_type(env, binop.rhs, lhs_t) || can_compile_to_type(env, binop.lhs, rhs_t)) + if ((binop.lhs->tag == Integer && is_numeric_type(rhs_t)) + || (binop.rhs->tag == Integer && is_numeric_type(lhs_t)) || can_compile_to_type(env, binop.rhs, lhs_t) + || can_compile_to_type(env, binop.lhs, rhs_t)) return ast->tag == Compare ? Type(IntType, .bits = TYPE_IBITS32) : Type(BoolType); code_err(ast, "I don't know how to compare ", type_to_text(lhs_t), " and ", type_to_text(rhs_t)); @@ -1241,9 +1242,9 @@ type_t *get_type(env_t *env, ast_t *ast) { code_err(binop.rhs, "I only know how to do bit shifting by integer amounts, not ", type_to_text(rhs_t)); } - if (is_numeric_type(lhs_t) && binop.rhs->tag == Int) { + if (is_numeric_type(lhs_t) && binop.rhs->tag == Integer) { return lhs_t; - } else if (is_numeric_type(rhs_t) && binop.lhs->tag == Int) { + } else if (is_numeric_type(rhs_t) && binop.lhs->tag == Integer) { return rhs_t; } else { switch (compare_precision(lhs_t, rhs_t)) { @@ -1648,14 +1649,16 @@ type_t *parse_type_string(env_t *env, const char *str) { PUREFUNC bool is_constant(env_t *env, ast_t *ast) { switch (ast->tag) { case Bool: - case Num: case None: return true; - case Int: { - DeclareMatch(info, ast, Int); + case Integer: { + DeclareMatch(info, ast, Integer); Int_t int_val = Int$parse(Text$from_str(info->str), NONE_INT, NULL); if (int_val.small == 0) return false; // Failed to parse return (Int$compare_value(int_val, I(BIGGEST_SMALL_INT)) <= 0); } + case Number: { + return false; + } case TextJoin: { DeclareMatch(text, ast, TextJoin); if (!text->children) return true; // Empty string, OK @@ -1698,8 +1701,8 @@ PUREFUNC bool can_compile_to_type(env_t *env, ast_t *ast, type_t *needed) { if (needed->tag == OptionalType && ast->tag == None) return true; env = with_enum_scope(env, needed); - if (is_numeric_type(needed) && ast->tag == Int) return true; - if (needed->tag == FloatType && ast->tag == Num) return true; + if (is_numeric_type(needed) && ast->tag == Integer) return true; + if (needed->tag == FloatType && ast->tag == Number) return true; type_t *non_optional_needed = non_optional(needed); if (non_optional_needed->tag == ListType && ast->tag == List) { |
