From 4f77ad5d019618893c59a0f8d5bfa6b98e50a3be Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 18 Aug 2026 13:31:47 +0200 Subject: Make Int and Word aliases to fixed-size types --- boot/ast.cc | 4 ++-- boot/evaluator.cc | 10 +++++----- boot/lexer.ll | 2 +- boot/name_analysis.cc | 6 +++--- boot/parser.yy | 2 +- boot/symbol.cc | 22 +++++++++++++++++----- boot/type_check.cc | 6 ++++-- 7 files changed, 33 insertions(+), 19 deletions(-) (limited to 'boot') diff --git a/boot/ast.cc b/boot/ast.cc index fb1e276..9b21f56 100644 --- a/boot/ast.cc +++ b/boot/ast.cc @@ -196,7 +196,7 @@ namespace elna::boot __builtin_unreachable(); } - void empty_visitor::visit(literal *) + void empty_visitor::visit(literal *) { __builtin_unreachable(); } @@ -517,7 +517,7 @@ namespace elna::boot { } - void walking_visitor::visit(literal *) + void walking_visitor::visit(literal *) { } diff --git a/boot/evaluator.cc b/boot/evaluator.cc index b37d1fa..d43ef11 100644 --- a/boot/evaluator.cc +++ b/boot/evaluator.cc @@ -245,7 +245,7 @@ namespace elna::boot { return constant_value{ boolean_subject->value }; } - else if (auto *character_subject = subject.is_a()) + else if (auto *character_subject = subject.is_a()) { return constant_value{ character_subject->value }; } @@ -686,7 +686,7 @@ namespace elna::boot } else if constexpr (std::is_same_v || std::is_same_v - || std::is_same_v) + || std::is_same_v) { return integer_literal::from(static_cast(source_value)); } @@ -716,7 +716,7 @@ namespace elna::boot } else if constexpr (std::is_same_v || std::is_same_v - || std::is_same_v) + || std::is_same_v) { return integer_literal::from(static_cast(source_value)); } @@ -809,7 +809,7 @@ namespace elna::boot } if (is_primitive_type(resolved, "Char")) { - return constant_value{ static_cast(0) }; + return constant_value{ static_cast(0) }; } if (is_primitive_type(resolved, "Bool")) { @@ -851,7 +851,7 @@ namespace elna::boot } if (is_primitive_type(resolved, "Char")) { - return constant_value{ std::numeric_limits::max() }; + return constant_value{ std::numeric_limits::max() }; } if (is_primitive_type(resolved, "Bool")) { diff --git a/boot/lexer.ll b/boot/lexer.ll index c6d3b17..888c17d 100644 --- a/boot/lexer.ll +++ b/boot/lexer.ll @@ -359,7 +359,7 @@ to { } return yy::parser::make_WORD8(std::make_pair(result.value(), integer_sign::_unsigned), this->location); } -`([^'\\\n]|\\.|\\\n)+` { +`([^`\\\n]|\\.|\\\n)+` { std::optional result = parse_character_literal(yytext); if (!result.has_value()) { diff --git a/boot/name_analysis.cc b/boot/name_analysis.cc index 0889ef9..4b69f9c 100644 --- a/boot/name_analysis.cc +++ b/boot/name_analysis.cc @@ -662,7 +662,7 @@ namespace elna::boot auto variable_type = lookup_primitive_type("Int"); this->bag.enter("count", std::make_shared(variable_type, false)); - variable_type = lookup_primitive_type("Char"); + variable_type = lookup_primitive_type("Word8"); variable_type = type(std::make_shared(variable_type)); variable_type = type(std::make_shared(variable_type)); this->bag.enter("parameters", std::make_shared(variable_type, false)); @@ -924,7 +924,7 @@ namespace elna::boot this->current_type = type(); } - void name_analysis_visitor::visit(literal *literal) + void name_analysis_visitor::visit(literal *literal) { literal->type_decoration = lookup_primitive_type("Char"); this->current_type = type(); @@ -939,7 +939,7 @@ namespace elna::boot void name_analysis_visitor::visit(literal *literal) { literal->type_decoration = type(std::make_shared( - type(std::make_shared(lookup_primitive_type("Char"))))); + type(std::make_shared(lookup_primitive_type("Word8"))))); this->current_type = type(); } diff --git a/boot/parser.yy b/boot/parser.yy index 1b3005e..411922d 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -308,7 +308,7 @@ literal: } | CHARACTER { - $$ = new boot::literal(boot::make_position(@$), $1, boot::integer_sign::_unsigned); + $$ = new boot::literal(boot::make_position(@$), $1, boot::integer_sign::_unsigned); } | "nil" { diff --git a/boot/symbol.cc b/boot/symbol.cc index 9854acc..05eea31 100644 --- a/boot/symbol.cc +++ b/boot/symbol.cc @@ -284,7 +284,8 @@ namespace elna::boot static void builtin_integers(const std::shared_ptr& symbols, const std::array& properties, - const std::string& integer_name) + const std::string& integer_name, + std::vector>& alias_owners) { for (std::size_t i = 1; i < properties.size(); ++i) { @@ -293,6 +294,16 @@ namespace elna::boot const type variant_type = type(std::make_shared(type_name, properties[i])); symbols->enter(type_name, std::make_shared(variant_type)); + + // The unsuffixed integer type is an alias of the fixed-size type + // matching the machine word. + if (bit_size == properties.front().size * CHAR_BIT) + { + auto alias = std::make_shared(integer_name, variant_type); + + alias_owners.push_back(alias); + symbols->enter(integer_name, std::make_shared(type(alias))); + } } if (!symbols->contains(integer_name)) { @@ -302,12 +313,13 @@ namespace elna::boot } } - std::shared_ptr builtin_symbol_table(const target_info& target) + std::shared_ptr builtin_symbol_table(const target_info& target, + std::vector>& alias_owners) { auto result = std::make_shared(); - builtin_integers(result, target.int_properties, "Int"); - builtin_integers(result, target.word_properties, "Word"); + builtin_integers(result, target.int_properties, "Int", alias_owners); + builtin_integers(result, target.word_properties, "Word", alias_owners); result->enter("Char", std::make_shared(type(std::make_shared("Char", target.char_properties)))); @@ -494,7 +506,7 @@ namespace elna::boot { if (auto base = resolve_aliases(slice->base).get()) { - return is_primitive_type(resolve_aliases(base->unqualified), "Char"); + return is_primitive_type(resolve_aliases(base->unqualified), "Word8"); } } return false; diff --git a/boot/type_check.cc b/boot/type_check.cc index e58a50e..d830763 100644 --- a/boot/type_check.cc +++ b/boot/type_check.cc @@ -569,7 +569,8 @@ namespace elna::boot .right = case_label->type_decoration, .operation = binary_operator::equals }; - add_error(case_label->position(), condition_type, binary_error); + add_error(case_label->position(), + statement->condition().type_decoration, binary_error); } } } @@ -843,7 +844,8 @@ namespace elna::boot } else if (operation == unary_operator::minus) { - if (!is_primitive_type(resolved, "Int") + auto signed_primitive = resolved.get(); + if ((signed_primitive == nullptr || !signed_primitive->identifier.starts_with("Int")) && !is_primitive_type(resolved, "Float")) { add_error(expression->position(), -- cgit v1.2.3