aboutsummaryrefslogtreecommitdiff
path: root/src/compile
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2026-01-11 20:06:45 -0500
committerBruce Hill <bruce@bruce-hill.com>2026-01-11 20:06:45 -0500
commitb97ea6b6ac3498b21321e1f93ccc1a2dd145e9d7 (patch)
tree834180f2c5a2ad29424279153d01c2bd52679823 /src/compile
parent573656fce2b7e1b0fc36944f60fd135117b6bbb6 (diff)
Rename AST nodes: Int -> Integer, Num -> Number
Diffstat (limited to 'src/compile')
-rw-r--r--src/compile/assertions.c4
-rw-r--r--src/compile/assignments.c2
-rw-r--r--src/compile/comparisons.c8
-rw-r--r--src/compile/expressions.c10
-rw-r--r--src/compile/functions.c22
-rw-r--r--src/compile/indexing.c2
-rw-r--r--src/compile/integers.c6
-rw-r--r--src/compile/lists.c28
-rw-r--r--src/compile/loops.c6
-rw-r--r--src/compile/promotions.c6
10 files changed, 48 insertions, 46 deletions
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"));