aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-07 21:39:57 +0200
committerEugen Wissner <belka@caraus.de>2026-07-07 21:39:57 +0200
commit79521d91b2bb85652fd29f5c44279338d55c757f (patch)
treed3b5b73177f63fd5ff684a8aba6f7b9af84dab27 /boot
parent470bfba45661d19558c0bf43b7819696a925ecb4 (diff)
downloadelna-79521d91b2bb85652fd29f5c44279338d55c757f.tar.gz
Allow multiple parameters with same type
Diffstat (limited to 'boot')
-rw-r--r--boot/ast.cc10
-rw-r--r--boot/lexer.ll3
-rw-r--r--boot/parser.yy43
-rw-r--r--boot/semantic.cc54
4 files changed, 49 insertions, 61 deletions
diff --git a/boot/ast.cc b/boot/ast.cc
index 91b46a4..b7604e5 100644
--- a/boot/ast.cc
+++ b/boot/ast.cc
@@ -485,8 +485,10 @@ namespace elna::boot
delete m_body;
}
- procedure_type_expression::procedure_type_expression(const struct position position, return_t return_type)
- : node(position), return_type(return_type)
+ procedure_type_expression::procedure_type_expression(const struct position position,
+ std::vector<std::pair<std::vector<std::string>, std::shared_ptr<type_expression>>>&& parameters,
+ return_t return_type)
+ : node(position), return_type(return_type), parameters(std::move(parameters))
{
}
@@ -496,10 +498,6 @@ namespace elna::boot
{
delete return_type.proper_type;
}
- for (const type_expression *parameter : this->parameters)
- {
- delete parameter;
- }
}
void procedure_type_expression::accept(parser_visitor *visitor)
diff --git a/boot/lexer.ll b/boot/lexer.ll
index 4f9fed7..f914d75 100644
--- a/boot/lexer.ll
+++ b/boot/lexer.ll
@@ -275,9 +275,6 @@ of {
\+ {
return yy::parser::make_PLUS(this->location);
}
-\-> {
- return yy::parser::make_ARROW(this->location);
-}
\- {
return yy::parser::make_MINUS(this->location);
}
diff --git a/boot/parser.yy b/boot/parser.yy
index a36b953..3b8e69e 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -82,7 +82,7 @@ along with GCC; see the file COPYING3. If not see
%token <bool> BOOLEAN
%token LEFT_PAREN "(" RIGHT_PAREN ")" LEFT_SQUARE "[" RIGHT_SQUARE "]"
%token ASSIGNMENT ":="
- ARROW "->" EXCLAMATION "!"
+ EXCLAMATION "!"
AT "@" HAT "^"
COLON ":" SEMICOLON ";" DOT "." COMMA ","
%token NOT "~"
@@ -143,15 +143,18 @@ along with GCC; see the file COPYING3. If not see
%type <std::vector<elna::boot::statement *>> statements;
%type <std::unique_ptr<std::vector<elna::boot::statement *>>> statement_part;
%type <elna::boot::procedure_declaration *> procedure_declaration;
-%type <std::pair<std::vector<std::string>, elna::boot::procedure_type_expression *>> procedure_heading;
+%type <elna::boot::procedure_type_expression *> procedure_heading;
%type <elna::boot::procedure_type_expression::return_t> return_declaration;
%type <std::vector<elna::boot::procedure_declaration *>> procedure_part;
%type <elna::boot::type_declaration *> type_declaration;
%type <std::vector<elna::boot::type_declaration *>> type_declarations type_part;
%type <std::unique_ptr<elna::boot::block>> block;
-%type <elna::boot::field_declaration> field_declaration formal_parameter;
+%type <elna::boot::field_declaration> field_declaration;
+%type <std::pair<std::vector<std::string>, std::shared_ptr<elna::boot::type_expression>>> formal_parameter;
%type <std::vector<std::pair<std::string, elna::boot::type_expression *>>>
- optional_fields required_fields formal_parameters formal_parameter_list;
+ optional_fields required_fields;
+%type <std::vector<std::pair<std::vector<std::string>, std::shared_ptr<elna::boot::type_expression>>>>
+ formal_parameters formal_parameter_list;
%type <std::vector<elna::boot::conditional_statements *>> elsif_then_statements elsif_do_statements;
%type <std::vector<elna::boot::statement *> *> else_statements;
%type <elna::boot::cast_expression *> cast_expression;
@@ -215,28 +218,21 @@ identifier_definitions:
| identifier_definition { $$.emplace_back(std::move($1)); }
return_declaration:
/* proper procedure */ {}
- | "->" "!" { $$ = boot::procedure_type_expression::return_t(std::monostate{}); }
- | "->" type_expression { $$ = boot::procedure_type_expression::return_t($2); }
+ | ":" "!" { $$ = boot::procedure_type_expression::return_t(std::monostate{}); }
+ | ":" type_expression { $$ = boot::procedure_type_expression::return_t($2); }
procedure_heading: formal_parameter_list return_declaration
{
- $$.second = new boot::procedure_type_expression(boot::make_position(@1), std::move($2));
- for (auto& [name, type] : $1)
- {
- $$.first.emplace_back(std::move(name));
- $$.second->parameters.push_back(type);
- }
+ $$ = new boot::procedure_type_expression(boot::make_position(@1), std::move($1), std::move($2));
}
procedure_declaration:
"proc" identifier_definition procedure_heading block
{
- $$ = new boot::procedure_declaration(boot::make_position(@1), std::move($2), $3.second,
+ $$ = new boot::procedure_declaration(boot::make_position(@1), std::move($2), $3,
std::move(*$4));
- std::swap($3.first, $$->parameter_names);
}
| "proc" identifier_definition procedure_heading "extern"
{
- $$ = new boot::procedure_declaration(boot::make_position(@1), std::move($2), $3.second);
- std::swap($3.first, $$->parameter_names);
+ $$ = new boot::procedure_declaration(boot::make_position(@1), std::move($2), $3);
}
procedure_part:
/* no procedure declarations */ {}
@@ -474,11 +470,9 @@ type_expression:
{
$$ = new boot::union_type_expression(boot::make_position(@1), std::move($2));
}
- | "proc" "(" type_expressions ")" return_declaration
+ | "proc" formal_parameter_list return_declaration
{
- auto result = new boot::procedure_type_expression(boot::make_position(@1), std::move($5));
- std::swap(result->parameters, $3);
- $$ = result;
+ $$ = new boot::procedure_type_expression(boot::make_position(@1), std::move($2), std::move($3));
}
| "(" identifiers ")"
{
@@ -571,7 +565,7 @@ type_part:
/* no type definitions */ {}
| "type" type_declarations { std::swap($$, $2); }
formal_parameter:
- IDENTIFIER ":" type_expression { $$ = std::make_pair($1, $3); }
+ identifiers ":" type_expression { $$ = std::make_pair(std::move($1), std::shared_ptr<boot::type_expression>($3)); }
formal_parameter_list:
"(" ")" {}
| "(" formal_parameters ")" { std::swap($$, $2); }
@@ -579,9 +573,12 @@ formal_parameters:
formal_parameter ";" formal_parameters
{
std::swap($$, $3);
- $$.emplace($$.cbegin(), std::move($1));
+ $$.emplace($$.cbegin(), std::move($1.first), $1.second);
+ }
+ | formal_parameter
+ {
+ $$.emplace_back(std::move($1.first), $1.second);
}
- | formal_parameter { $$.emplace_back(std::move($1)); }
actual_parameter_list:
"(" ")" {}
| "(" expressions ")" { std::swap($$, $2); }
diff --git a/boot/semantic.cc b/boot/semantic.cc
index 29ef3c1..cd50742 100644
--- a/boot/semantic.cc
+++ b/boot/semantic.cc
@@ -81,16 +81,6 @@ namespace elna::boot
return "Procedure '" + identifier + "' is expected to return, but does not have a return statement";
}
- variable_initializer_error::variable_initializer_error(const struct position position)
- : error(position)
- {
- }
-
- std::string variable_initializer_error::what() const
- {
- return "Only one variable can be initialized";
- }
-
type_analysis_visitor::type_analysis_visitor(symbol_bag bag)
: error_container(), bag(bag)
{
@@ -194,7 +184,8 @@ namespace elna::boot
{
}
- procedure_type name_analysis_visitor::build_procedure(procedure_type_expression& type_expression)
+ std::pair<procedure_type, std::vector<std::string>> name_analysis_visitor::build_procedure(
+ procedure_type_expression& type_expression)
{
procedure_type::return_t result_return;
@@ -211,12 +202,17 @@ namespace elna::boot
{
result_return = procedure_type::return_t();
}
- procedure_type result_type = procedure_type(result_return);
-
- for (struct type_expression *parameter : type_expression.parameters)
+ std::pair<procedure_type, std::vector<std::string>> result_type{
+ procedure_type(result_return), std::vector<std::string>()
+ };
+ for (auto& [parameter_names, parameters_type] : type_expression.parameters)
{
- parameter->accept(this);
- result_type.parameters.push_back(this->current_type);
+ parameters_type->accept(this);
+ for (auto& parameter_name : parameter_names)
+ {
+ result_type.first.parameters.push_back(this->current_type);
+ result_type.second.push_back(parameter_name);
+ }
}
return result_type;
}
@@ -311,7 +307,7 @@ namespace elna::boot
void name_analysis_visitor::visit(procedure_type_expression *type_expression)
{
std::shared_ptr<procedure_type> result_type =
- std::make_shared<procedure_type>(std::move(build_procedure(*type_expression)));
+ std::make_shared<procedure_type>(std::move(build_procedure(*type_expression).first));
this->current_type = type(result_type);
}
@@ -359,16 +355,15 @@ namespace elna::boot
void name_analysis_visitor::visit(procedure_declaration *definition)
{
std::shared_ptr<procedure_info> info;
- auto heading = build_procedure(definition->heading());
+ auto [heading, parameter_names] = build_procedure(definition->heading());
if (definition->body.has_value())
{
- info = std::make_shared<procedure_info>(heading, definition->parameter_names, this->bag.enter());
- auto name_iterator = std::cbegin(definition->parameter_names);
+ info = std::make_shared<procedure_info>(heading, std::move(parameter_names), this->bag.enter());
+ auto name_iterator = std::cbegin(info->names);
auto type_iterator = std::cbegin(heading.parameters);
- while (name_iterator != std::cend(definition->parameter_names)
- && type_iterator != std::cend(heading.parameters))
+ while (name_iterator != std::cend(info->names) && type_iterator != std::cend(heading.parameters))
{
this->current_type = *type_iterator;
auto variable_symbol = register_variable(*name_iterator, false, definition->heading().position());
@@ -393,7 +388,7 @@ namespace elna::boot
}
else
{
- info = std::make_shared<procedure_info>(heading, definition->parameter_names);
+ info = std::make_shared<procedure_info>(heading, std::move(parameter_names));
}
info->exported = definition->identifier.exported;
this->bag.enter(definition->identifier.name, info);
@@ -494,7 +489,12 @@ namespace elna::boot
void name_analysis_visitor::visit(procedure_call *call)
{
- call->callable().accept(this);
+ auto name_expression = call->callable().is_named();
+
+ if (name_expression == nullptr || name_expression->name != "assert")
+ {
+ call->callable().accept(this);
+ }
for (expression *const argument: call->arguments)
{
argument->accept(this);
@@ -665,12 +665,8 @@ namespace elna::boot
}
}
- void declaration_visitor::visit(variable_declaration *declaration)
+ void declaration_visitor::visit(variable_declaration *)
{
- if (declaration->has_initializer() && declaration->identifiers.size() > 1)
- {
- add_error<variable_initializer_error>(declaration->position());
- }
}
void declaration_visitor::visit(procedure_declaration *definition)