aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-09-05 23:44:04 +0200
committerEugen Wissner <belka@caraus.de>2026-09-05 23:44:04 +0200
commit93d251251ff926718b81fd62fba88dfa66d469e9 (patch)
treeb4b06a137b1807bce4f98653ef6ec0c4a2aaa37a
parent6eaec8726f716b2ab6b48c8cd3d7fee6aaf86977 (diff)
downloadelna-93d251251ff926718b81fd62fba88dfa66d469e9.tar.gz
Generate repeat-until condition outside body scope
-rw-r--r--boot/type_check.cc8
-rw-r--r--gcc/gcc/elna-generic.cc16
2 files changed, 13 insertions, 11 deletions
diff --git a/boot/type_check.cc b/boot/type_check.cc
index 4ceab18..fd47998 100644
--- a/boot/type_check.cc
+++ b/boot/type_check.cc
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/type_check.h"
#include "elna/boot/evaluator.h"
+#include <ranges>
#include <utility>
namespace elna::boot
@@ -1027,12 +1028,13 @@ namespace elna::boot
type_mismatch_error::expected_type{ type(std::make_shared<array_type>(type(), 0)) });
return;
}
- for (auto *element : expression->elements)
+ // The first element of the array literal determines the array type and
+ // does not have to be checked.
+ for (auto *element : expression->elements | std::views::drop(1))
{
if (!is_assignable_from(array->base, element->type_decoration))
{
- add_error<type_mismatch_error>(
- element->position(), element->type_decoration,
+ add_error<type_mismatch_error>(element->position(), element->type_decoration,
type_mismatch_error::expected_type{ array->base });
}
}
diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc
index fb68136..b786688 100644
--- a/gcc/gcc/elna-generic.cc
+++ b/gcc/gcc/elna-generic.cc
@@ -891,22 +891,22 @@ namespace elna::gcc
void generic_visitor::visit(boot::repeat_statement *statement)
{
- enter_scope();
tree loop_label = create_artificial_label(get_location(&statement->position()));
tree goto_loop = build1(GOTO_EXPR, void_type_node, loop_label);
append_statement(build1(LABEL_EXPR, void_type_node, loop_label));
- for (auto *body_statement : statement->body)
- {
- body_statement->accept(this);
- }
+ enter_scope();
+ visit_statements(statement->body);
+
+ tree repeat_binding = leave_scope();
+ append_statement(repeat_binding);
+
statement->condition().accept(this);
tree condition_statement = build3(COND_EXPR, void_type_node,
this->current_expression, NULL_TREE, goto_loop);
- append_statement(condition_statement);
- tree repeat_binding = leave_scope();
- append_statement(repeat_binding);
+ append_statement(condition_statement);
+ this->current_expression = NULL_TREE;
}
void generic_visitor::visit(boot::for_statement *statement)