aboutsummaryrefslogtreecommitdiff
path: root/boot/symbol.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/symbol.cc')
-rw-r--r--boot/symbol.cc59
1 files changed, 44 insertions, 15 deletions
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<variable_info>(shared_from_this());
}
- std::shared_ptr<symbol_table> builtin_symbol_table()
+ 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)
+ {
+ 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<primitive_type>(type_name, properties[i]));
+
+ symbols->enter(type_name, std::make_shared<type_info>(variant_type));
+ }
+ if (!symbols->contains(integer_name))
+ {
+ auto variant_type = type(std::make_shared<primitive_type>(integer_name, properties.front()));
+
+ symbols->enter(integer_name, std::make_shared<type_info>(variant_type));
+ }
+ }
+
+ std::shared_ptr<symbol_table> builtin_symbol_table(const target_info& target)
{
auto result = std::make_shared<symbol_table>();
- result->enter("Int", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Int"))));
- result->enter("Word", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Word"))));
- result->enter("Char", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Char"))));
- result->enter("Pointer", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Pointer"))));
- result->enter("Float", std::make_shared<type_info>(type(std::make_shared<primitive_type>("Float"))));
- type const boolean = type(std::make_shared<primitive_type>("Bool"));
+ builtin_integers(result, target.int_properties, "Int");
+ builtin_integers(result, target.word_properties, "Word");
+
+ result->enter("Char",
+ std::make_shared<type_info>(type(std::make_shared<primitive_type>("Char", target.char_properties))));
+
+ const type pointer = type(std::make_shared<primitive_type>("Pointer", target.pointer_properties));
+ result->enter("Pointer", std::make_shared<type_info>(pointer));
+ result->enter("Float",
+ std::make_shared<type_info>(type(std::make_shared<primitive_type>("Float", target.float_properties))));
+
+ const type boolean = type(std::make_shared<primitive_type>("Bool", target.bool_properties));
result->enter("Bool", std::make_shared<type_info>(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<primitive_type>())
+ {
+ return primitive_checked->identifier.starts_with("Int")
+ || primitive_checked->identifier.starts_with("Word");
+ }
+ return false;
}
bool is_discrete_type(const type& checked)