From e9cd3e5d0157f145dc0c3fea59f434fdd5ae55c6 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 1 Aug 2026 20:03:34 +0200 Subject: Evaluate strings at compile time --- boot/evaluator.cc | 93 +++++++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 51 deletions(-) (limited to 'boot/evaluator.cc') diff --git a/boot/evaluator.cc b/boot/evaluator.cc index 56ba270..afa72db 100644 --- a/boot/evaluator.cc +++ b/boot/evaluator.cc @@ -231,6 +231,10 @@ namespace elna::boot { return constant_value{ std::nullptr_t{} }; } + else if (is_string_type(decoration)) + { + return constant_value{ static_cast&>(subject).value }; + } return std::nullopt; } @@ -356,72 +360,59 @@ namespace elna::boot std::optional evaluator::evaluate_unary(unary_expression& subject) { - if (subject.operation() == unary_operator::reference) - { - if (auto *designator = subject.operand().is_designator()) - { - if (auto *named = designator->is_named()) - { - return constant_value{ global_address{ .name = named->name } }; - } - } - return std::nullopt; - } auto operand = evaluate(subject.operand()); if (!operand) { return std::nullopt; } - if (subject.operation() == unary_operator::minus) + switch (subject.operation()) { - return std::visit([](auto&& value) -> std::optional { - using T = std::decay_t; + using enum unary_operator; + case minus: + return std::visit([](auto&& value) -> std::optional { + using T = std::decay_t; - if constexpr (std::is_same_v) - { - if (auto result = value.neg()) + if constexpr (std::is_same_v) + { + if (auto result = value.neg()) + { + return constant_value{ result.value() }; + } + return std::nullopt; + } + if constexpr (std::is_same_v) { - return constant_value{ result.value() }; + return constant_value{ -value }; } return std::nullopt; - } - if constexpr (std::is_same_v) - { - return constant_value{ -value }; - } - return std::nullopt; - }, operand.value()); - } - if (subject.operation() == unary_operator::logical_negation) - { - return std::visit([](const auto& value) -> std::optional { - using T = std::decay_t; + }, operand.value()); + case logical_negation: + return std::visit([](const auto& value) -> std::optional { + using T = std::decay_t; - if constexpr (std::is_same_v) - { - return constant_value{ !value }; - } - return std::nullopt; - }, operand.value()); - } - if (subject.operation() == unary_operator::bitwise_negation) - { - return std::visit([](const auto& value) -> std::optional { - using T = std::decay_t; + if constexpr (std::is_same_v) + { + return constant_value{ !value }; + } + return std::nullopt; + }, operand.value()); + case bitwise_negation: + return std::visit([](const auto& value) -> std::optional { + using T = std::decay_t; - if constexpr (std::is_same_v) - { - return constant_value{ ~value }; - } + if constexpr (std::is_same_v) + { + return constant_value{ ~value }; + } + return std::nullopt; + }, operand.value()); + case plus: + return operand; + case negation: + case reference: return std::nullopt; - }, operand.value()); } - if (subject.operation() == unary_operator::plus) - { - return operand; - } - return std::nullopt; } template -- cgit v1.2.3