From bf7416a3ef9f0b787dcaebf816f3f3e6e385ff42 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 13 Aug 2026 22:55:06 +0200 Subject: Implement fixed-size integers --- boot/symbol.cc | 59 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 15 deletions(-) (limited to 'boot/symbol.cc') diff --git a/boot/symbol.cc b/boot/symbol.cc index 1cc652c..9854acc 100644 --- a/boot/symbol.cc +++ b/boot/symbol.cc @@ -184,8 +184,8 @@ namespace elna::boot }, payload); } - alias_type::alias_type(const std::string& name) - : name(name) + alias_type::alias_type(const std::string& name, type referent) + : name(name), referent(std::move(referent)) { } @@ -209,8 +209,8 @@ namespace elna::boot { } - primitive_type::primitive_type(const std::string& identifier) - : identifier(identifier) + primitive_type::primitive_type(const std::string& identifier, const type_properties& properties) + : identifier(identifier), properties(properties) { } @@ -282,16 +282,42 @@ namespace elna::boot return std::static_pointer_cast(shared_from_this()); } - std::shared_ptr builtin_symbol_table() + static void builtin_integers(const std::shared_ptr& symbols, + const std::array& properties, + const std::string& integer_name) + { + for (std::size_t i = 1; i < properties.size(); ++i) + { + const std::size_t bit_size = properties[i].size * CHAR_BIT; + const std::string type_name = integer_name + std::to_string(bit_size); + const type variant_type = type(std::make_shared(type_name, properties[i])); + + symbols->enter(type_name, std::make_shared(variant_type)); + } + if (!symbols->contains(integer_name)) + { + auto variant_type = type(std::make_shared(integer_name, properties.front())); + + symbols->enter(integer_name, std::make_shared(variant_type)); + } + } + + std::shared_ptr builtin_symbol_table(const target_info& target) { auto result = std::make_shared(); - result->enter("Int", std::make_shared(type(std::make_shared("Int")))); - result->enter("Word", std::make_shared(type(std::make_shared("Word")))); - result->enter("Char", std::make_shared(type(std::make_shared("Char")))); - result->enter("Pointer", std::make_shared(type(std::make_shared("Pointer")))); - result->enter("Float", std::make_shared(type(std::make_shared("Float")))); - type const boolean = type(std::make_shared("Bool")); + builtin_integers(result, target.int_properties, "Int"); + builtin_integers(result, target.word_properties, "Word"); + + result->enter("Char", + std::make_shared(type(std::make_shared("Char", target.char_properties)))); + + const type pointer = type(std::make_shared("Pointer", target.pointer_properties)); + result->enter("Pointer", std::make_shared(pointer)); + result->enter("Float", + std::make_shared(type(std::make_shared("Float", target.float_properties)))); + + const type boolean = type(std::make_shared("Bool", target.bool_properties)); result->enter("Bool", std::make_shared(boolean)); procedure_type assert_symbol{ procedure_type::return_t() }; @@ -426,15 +452,18 @@ namespace elna::boot bool is_numeric_type(const type& checked) { - return is_primitive_type(checked, "Int") - || is_primitive_type(checked, "Word") + return is_integral_type(checked) || is_primitive_type(checked, "Float"); } bool is_integral_type(const type& checked) { - return is_primitive_type(checked, "Int") - || is_primitive_type(checked, "Word"); + if (auto primitive_checked = checked.get()) + { + return primitive_checked->identifier.starts_with("Int") + || primitive_checked->identifier.starts_with("Word"); + } + return false; } bool is_discrete_type(const type& checked) -- cgit v1.2.3