diff options
Diffstat (limited to 'boot')
| -rw-r--r-- | boot/ast.cc | 4 | ||||
| -rw-r--r-- | boot/evaluator.cc | 10 | ||||
| -rw-r--r-- | boot/lexer.ll | 2 | ||||
| -rw-r--r-- | boot/name_analysis.cc | 6 | ||||
| -rw-r--r-- | boot/parser.yy | 2 | ||||
| -rw-r--r-- | boot/symbol.cc | 22 | ||||
| -rw-r--r-- | boot/type_check.cc | 6 |
7 files changed, 33 insertions, 19 deletions
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<unsigned char> *) + void empty_visitor::visit(literal<std::uint32_t> *) { __builtin_unreachable(); } @@ -517,7 +517,7 @@ namespace elna::boot { } - void walking_visitor::visit(literal<unsigned char> *) + void walking_visitor::visit(literal<std::uint32_t> *) { } 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<unsigned char>()) + else if (auto *character_subject = subject.is_a<std::uint32_t>()) { return constant_value{ character_subject->value }; } @@ -686,7 +686,7 @@ namespace elna::boot } else if constexpr (std::is_same_v<T, double> || std::is_same_v<T, bool> - || std::is_same_v<T, unsigned char>) + || std::is_same_v<T, std::uint32_t>) { return integer_literal::from(static_cast<std::ptrdiff_t>(source_value)); } @@ -716,7 +716,7 @@ namespace elna::boot } else if constexpr (std::is_same_v<T, double> || std::is_same_v<T, bool> - || std::is_same_v<T, unsigned char>) + || std::is_same_v<T, std::uint32_t>) { return integer_literal::from(static_cast<std::size_t>(source_value)); } @@ -809,7 +809,7 @@ namespace elna::boot } if (is_primitive_type(resolved, "Char")) { - return constant_value{ static_cast<unsigned char>(0) }; + return constant_value{ static_cast<std::uint32_t>(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<unsigned char>::max() }; + return constant_value{ std::numeric_limits<std::uint32_t>::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<std::uint32_t> 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_info>(variable_type, false)); - variable_type = lookup_primitive_type("Char"); + variable_type = lookup_primitive_type("Word8"); variable_type = type(std::make_shared<pointer_type>(variable_type)); variable_type = type(std::make_shared<pointer_type>(variable_type)); this->bag.enter("parameters", std::make_shared<variable_info>(variable_type, false)); @@ -924,7 +924,7 @@ namespace elna::boot this->current_type = type(); } - void name_analysis_visitor::visit(literal<unsigned char> *literal) + void name_analysis_visitor::visit(literal<std::uint32_t> *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<std::string> *literal) { literal->type_decoration = type(std::make_shared<slice_type>( - type(std::make_shared<constant_type>(lookup_primitive_type("Char"))))); + type(std::make_shared<constant_type>(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<unsigned char>(boot::make_position(@$), $1, boot::integer_sign::_unsigned); + $$ = new boot::literal<std::uint32_t>(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<symbol_table>& symbols, const std::array<type_properties, target_integer_count>& properties, - const std::string& integer_name) + const std::string& integer_name, + std::vector<std::shared_ptr<alias_type>>& 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<primitive_type>(type_name, properties[i])); symbols->enter(type_name, std::make_shared<type_info>(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<alias_type>(integer_name, variant_type); + + alias_owners.push_back(alias); + symbols->enter(integer_name, std::make_shared<type_info>(type(alias))); + } } if (!symbols->contains(integer_name)) { @@ -302,12 +313,13 @@ namespace elna::boot } } - std::shared_ptr<symbol_table> builtin_symbol_table(const target_info& target) + std::shared_ptr<symbol_table> builtin_symbol_table(const target_info& target, + std::vector<std::shared_ptr<alias_type>>& alias_owners) { auto result = std::make_shared<symbol_table>(); - 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_info>(type(std::make_shared<primitive_type>("Char", target.char_properties)))); @@ -494,7 +506,7 @@ namespace elna::boot { if (auto base = resolve_aliases(slice->base).get<constant_type>()) { - 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<type_mismatch_error>(case_label->position(), condition_type, binary_error); + add_error<type_mismatch_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<primitive_type>(); + if ((signed_primitive == nullptr || !signed_primitive->identifier.starts_with("Int")) && !is_primitive_type(resolved, "Float")) { add_error<type_mismatch_error>(expression->position(), |
