aboutsummaryrefslogtreecommitdiff
path: root/boot/evaluator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/evaluator.cc')
-rw-r--r--boot/evaluator.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/boot/evaluator.cc b/boot/evaluator.cc
index 4b37668..40a6533 100644
--- a/boot/evaluator.cc
+++ b/boot/evaluator.cc
@@ -61,25 +61,32 @@ namespace elna::boot
}
else if (auto *record_constructor = subject.is_record_constructor())
{
+ ordered_map<constant_value> aggregate;
+
for (const field_initializer& field_initializer : record_constructor->field_initializers)
{
- if (!evaluate(field_initializer.value()))
+ auto value = evaluate(field_initializer.value());
+ if (!value)
{
return std::nullopt;
}
+ aggregate.insert(field_initializer.name(), std::move(*value));
}
- return constant_value{ compound_constant{} };
+ return constant_value{ constant_aggregate<ordered_map>{ std::move(aggregate) } };
}
else if (auto *array_constructor = subject.is_array_constructor())
{
+ std::vector<constant_value> elements;
for (expression *element : array_constructor->elements)
{
- if (!evaluate(*element))
+ auto value = evaluate(*element);
+ if (!value)
{
return std::nullopt;
}
+ elements.push_back(std::move(*value));
}
- return constant_value{ compound_constant{} };
+ return constant_value{ constant_aggregate<std::vector>{ std::move(elements) } };
}
return std::nullopt;
}
@@ -171,7 +178,7 @@ namespace elna::boot
}
if (subject.operation() == unary_operator::logical_negation)
{
- return std::visit([](auto value) -> std::optional<constant_value> {
+ return std::visit([](const auto& value) -> std::optional<constant_value> {
using T = std::decay_t<decltype(value)>;
if constexpr (std::is_same_v<T, bool>)
@@ -183,7 +190,7 @@ namespace elna::boot
}
if (subject.operation() == unary_operator::bitwise_negation)
{
- return std::visit([](auto value) -> std::optional<constant_value> {
+ return std::visit([](const auto& value) -> std::optional<constant_value> {
using T = std::decay_t<decltype(value)>;
if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>)
@@ -240,10 +247,11 @@ namespace elna::boot
}
template<typename T>
- static std::optional<constant_value> evaluate_operation(binary_operator operation, T lhs, T rhs)
+ static std::optional<constant_value> evaluate_operation(binary_operator operation, const T& lhs, const T& rhs)
{
if constexpr (std::is_same_v<T, std::nullptr_t>
- || std::is_same_v<T, compound_constant>)
+ || std::is_same_v<T, constant_aggregate<ordered_map>>
+ || std::is_same_v<T, constant_aggregate<std::vector>>)
{
switch (operation)
{