aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--boot/ast.cc11
-rw-r--r--boot/parser.yy12
-rw-r--r--boot/semantic.cc22
-rw-r--r--doc/appendix.tex5
-rw-r--r--gcc/gcc/elna-generic.cc3
-rw-r--r--include/elna/boot/ast.h3
-rw-r--r--source/command_line_interface.elna6
-rw-r--r--source/common.elna22
-rw-r--r--source/lexer.elna90
-rw-r--r--source/main.elna129
-rw-r--r--testsuite/compilable/assign_record_to_base.elna1
-rw-r--r--testsuite/compilable/empty_proc.elna2
-rw-r--r--testsuite/compilable/empty_statements_in_a_row.elna2
-rw-r--r--testsuite/compilable/float_literals.elna2
-rw-r--r--testsuite/compilable/pointer_cast.elna2
-rw-r--r--testsuite/compilable/pointer_subtraction.elna4
-rw-r--r--testsuite/compilable/semicolon_parameter_separator.elna2
-rw-r--r--testsuite/fail_compilation/local_const_exported.elna4
-rw-r--r--testsuite/fail_compilation/local_var_exported.elna4
-rw-r--r--testsuite/fail_compilation/module_without_return.elna6
-rw-r--r--testsuite/runnable/aggregate_argument.elna17
-rw-r--r--testsuite/runnable/aggregate_equality.elna17
-rw-r--r--testsuite/runnable/array_constructor.elna1
-rw-r--r--testsuite/runnable/define_multiple_local_variables.elna16
-rw-r--r--testsuite/runnable/record_base_assignment.elna11
-rw-r--r--testsuite/runnable/record_construction.elna1
-rw-r--r--testsuite/runnable/record_extension.elna3
-rw-r--r--testsuite/runnable/return_aggregate.elna7
-rw-r--r--testsuite/runnable/two_fields_same_type.elna6
-rw-r--r--testsuite/runnable/two_parameters_same_type.elna7
30 files changed, 144 insertions, 274 deletions
diff --git a/boot/ast.cc b/boot/ast.cc
index 14bad30..2a22d69 100644
--- a/boot/ast.cc
+++ b/boot/ast.cc
@@ -348,10 +348,6 @@ namespace elna::boot
{
entry_statement->accept(this);
}
- if (unit->return_expression != nullptr)
- {
- unit->return_expression->accept(this);
- }
}
void walking_visitor::visit(type_declaration *declaration)
@@ -879,10 +875,9 @@ namespace elna::boot
std::vector<type_declaration *>&& types,
std::vector<variable_declaration *>&& variables,
std::vector<procedure_declaration *>&& procedures,
- std::vector<statement *>&& entry_point,
- expression *const return_expression)
+ std::vector<statement *>&& entry_point)
: node(position),
- procedure_body(std::move(constants), std::move(variables), std::move(entry_point), return_expression),
+ procedure_body(std::move(constants), std::move(variables), std::move(entry_point)),
imports(std::move(imports)), types(std::move(types)), procedures(std::move(procedures))
{
}
@@ -894,7 +889,7 @@ namespace elna::boot
bool unit::has_body() const
{
- return !this->entry_point.empty() || this->return_expression != nullptr;
+ return !this->entry_point.empty();
}
unit::~unit()
diff --git a/boot/parser.yy b/boot/parser.yy
index ef887ab..9f610ee 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -136,7 +136,7 @@ along with GCC; see the file COPYING3. If not see
%type <elna::boot::type_expression *> type_expression;
%type <std::vector<elna::boot::type_expression *>> type_expressions;
%type <elna::boot::traits_expression *> traits_expression;
-%type <elna::boot::expression *> expression operand simple_expression return_statement;
+%type <elna::boot::expression *> expression operand simple_expression procedure_return;
%type <elna::boot::unary_expression *> unary_expression;
%type <elna::boot::binary_expression *> binary_expression;
%type <std::vector<elna::boot::expression *>> expressions actual_parameter_list;
@@ -164,13 +164,13 @@ along with GCC; see the file COPYING3. If not see
%type <std::vector<elna::boot::import_declaration *>> import_declarations import_part;
%%
program:
- import_part constant_part type_part variable_part procedure_part statement_part return_statement "end" "."
+ import_part constant_part type_part variable_part procedure_part statement_part "end" "."
{
- boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4, $5, $6, $7);
+ boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4, $5, $6);
driver.tree.reset(tree);
}
procedure_body:
- constant_part variable_part statement_part return_statement "end"
+ constant_part variable_part statement_part procedure_return
{ $$ = std::make_unique<boot::procedure_body>($1, $2, $3, $4); }
statement_part:
@@ -233,9 +233,9 @@ elsif_then_statements:
$$.emplace($$.begin(), branch);
}
| /* no branches */ {}
-return_statement:
+procedure_return:
"return" expression { $$ = $2; }
- | /* no return statement */ { $$ = nullptr; }
+ | "return" { $$ = nullptr; }
literal:
INTEGER { $$ = new boot::literal<std::int32_t>(boot::make_position(@$), $1); }
| WORD { $$ = new boot::literal<std::uint32_t>(boot::make_position(@$), $1); }
diff --git a/boot/semantic.cc b/boot/semantic.cc
index d7a23be..dd9022b 100644
--- a/boot/semantic.cc
+++ b/boot/semantic.cc
@@ -177,24 +177,6 @@ namespace elna::boot
void type_analysis_visitor::visit(unit *unit)
{
walking_visitor::visit(unit);
-
- if (unit->has_body())
- {
- if (unit->return_expression != nullptr)
- {
- type return_type = this->bag.lookup("Int")->is_type()->symbol;
-
- if (!is_assignable_from(return_type, unit->return_expression->type_decoration))
- {
- add_error<type_expectation_error>(type_expectation_error::kind::result,
- unit->return_expression->position());
- }
- }
- else
- {
- add_error<return_error>("module", unit->position());
- }
- }
}
void type_analysis_visitor::visit(assign_statement *statement)
@@ -773,10 +755,6 @@ namespace elna::boot
{
statement->accept(this);
}
- if (unit->return_expression != nullptr)
- {
- unit->return_expression->accept(this);
- }
this->bag.leave();
}
}
diff --git a/doc/appendix.tex b/doc/appendix.tex
index 36bb72a..1e3ba4e 100644
--- a/doc/appendix.tex
+++ b/doc/appendix.tex
@@ -173,13 +173,12 @@
<procedure-heading> = `(' [<parameter> \{`;' <parameter>\}] `)' <return-declaration>.
-<procedure-body> = <constant-part> <variable-part> <statement-part> [`return' <expression>] `end'.
+<procedure-body> = <constant-part> <variable-part> <statement-part> `return' [<expression>].
<procedure-declaration> = `proc' <identifier-definition> <procedure-heading> \\
(<procedure-body> | `extern').
<program> = <import-part>
<constant-part> <type-part> <variable-part>
- \{<procedure-declaration>\}
- <statement-part> [`return' <expression>] `end' `.\@'.
+ \{<procedure-declaration>\} <statement-part> `end' `.\@'.
\end{grammar}
diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc
index f29828f..18d31d6 100644
--- a/gcc/gcc/elna-generic.cc
+++ b/gcc/gcc/elna-generic.cc
@@ -272,9 +272,8 @@ namespace elna::gcc
parameter_type = TREE_CHAIN(parameter_type);
}
visit_statements(unit->entry_point);
- unit->return_expression->accept(this);
tree set_result = build2(INIT_EXPR, void_type_node, DECL_RESULT(fndecl),
- this->current_expression);
+ integer_zero_node);
tree return_stmt = build1(RETURN_EXPR, void_type_node, set_result);
append_statement(return_stmt);
this->current_expression = NULL_TREE;
diff --git a/include/elna/boot/ast.h b/include/elna/boot/ast.h
index 04ffc22..6a5f32d 100644
--- a/include/elna/boot/ast.h
+++ b/include/elna/boot/ast.h
@@ -766,8 +766,7 @@ namespace elna::boot
std::vector<type_declaration *>&& types,
std::vector<variable_declaration *>&& variables,
std::vector<procedure_declaration *>&& procedures,
- std::vector<statement *>&& entry_point,
- expression *const return_expression = nullptr);
+ std::vector<statement *>&& entry_point);
bool has_body() const;
virtual void accept(parser_visitor *visitor) override;
diff --git a/source/command_line_interface.elna b/source/command_line_interface.elna
index b9006f1..54eb87f 100644
--- a/source/command_line_interface.elna
+++ b/source/command_line_interface.elna
@@ -83,9 +83,7 @@ begin
if result <> nil & result^.input = nil then
write_s("Fatal error: no input files.\n");
result := nil
- end;
-
- return result
-end
+ end
+return result
end.
diff --git a/source/common.elna b/source/common.elna
index 9e6a314..b6f85f1 100644
--- a/source/common.elna
+++ b/source/common.elna
@@ -21,12 +21,12 @@ proc write_s*(value: String)
begin
(* fwrite(cast(value.ptr: Pointer), value.length, 1u, stdout) *)
write(1, cast(value.ptr: Pointer), cast(value.length: Int))
-end
+return
proc write_z*(value: ^Char)
begin
write(1, cast(value: Pointer), cast(strlen(value): Int))
-end
+return
proc write_b*(value: Bool)
begin
@@ -35,13 +35,13 @@ begin
else
write_s("false")
end
-end
+return
proc write_c*(value: Char)
begin
putchar(cast(value: Int));
fflush(nil)
-end
+return
proc write_i*(value: Int)
var
@@ -65,18 +65,17 @@ begin
n := n + 1u;
write_c(buffer[n])
end
-end
+return
proc write_u*(value: Word)
begin
write_i(cast(value: Int))
-end
+return
proc free_and_nil*(pointer: Pointer): Pointer
begin
- free(pointer);
- return nil
-end
+ free(pointer)
+return nil
(* Returns true or false depending whether two strings are equal. *)
proc string_compare*(lhs_pointer: ^Char; lhs_length: Word; rhs_pointer: String): Bool
@@ -87,8 +86,7 @@ begin
result := memcmp(lhs_pointer, rhs_pointer.ptr, lhs_length) = 0
else
result := false
- end;
- return result
-end
+ end
+return result
end.
diff --git a/source/lexer.elna b/source/lexer.elna
index 62ad3b1..63ca3d3 100644
--- a/source/lexer.elna
+++ b/source/lexer.elna
@@ -180,7 +180,7 @@ begin
classification[14] := ElnaLexerClass.space;
classification[33] := ElnaLexerClass.space;
classification[34] := ElnaLexerClass.single
-end
+return
proc elna_lexer_classifications2()
begin
@@ -214,7 +214,7 @@ begin
classification[62] := ElnaLexerClass.equals;
classification[63] := ElnaLexerClass.greater;
classification[64] := ElnaLexerClass.other
-end
+return
proc elna_lexer_classifications3()
begin
@@ -252,7 +252,7 @@ begin
classification[96] := ElnaLexerClass.alpha;
classification[97] := ElnaLexerClass.other;
classification[98] := ElnaLexerClass.hex
-end
+return
proc elna_lexer_classifications4()
begin
@@ -285,7 +285,7 @@ begin
classification[125] := ElnaLexerClass.single;
classification[126] := ElnaLexerClass.other;
classification[127] := ElnaLexerClass.single
-end
+return
(**
* Initializes the array with character classes.
@@ -312,14 +312,12 @@ begin
classification[code] := ElnaLexerClass.other;
code := code + 1u
end
-end
+return
proc elna_lexer_get_transition(current_state: ElnaLexerState; character_class: ElnaLexerClass): ^ElnaLexerTransition
(* Each state is 8 bytes long (2 words: action and next state).
There are 23 character classes, so a transition row 8 * 23 = 184 bytes long. *)
-
- return @transition_table[cast(current_state: Word)][cast(character_class: Word)]
-end
+return @transition_table[cast(current_state: Word)][cast(character_class: Word)]
(**
* Parameters:
@@ -337,7 +335,7 @@ begin
transition^.action := action;
transition^.next_state := next_state
-end
+return
(**
* Sets same action and state transition for all character classes in one transition row.
@@ -373,7 +371,7 @@ begin
elna_lexer_set_transition(current_state, ElnaLexerClass.less, default_action, next_state);
elna_lexer_set_transition(current_state, ElnaLexerClass.other, default_action, next_state);
elna_lexer_set_transition(current_state, ElnaLexerClass.number_sign, default_action, next_state)
-end
+return
(**
* The transition table describes transitions from one state to another, given
@@ -508,13 +506,13 @@ begin
elna_lexer_set_transition(ElnaLexerState.trait, ElnaLexerClass.hex, ElnaLexerAction.accumulate, ElnaLexerState.trait);
elna_lexer_set_transition(ElnaLexerState.trait, ElnaLexerClass.zero, ElnaLexerAction.accumulate, ElnaLexerState.trait);
elna_lexer_set_transition(ElnaLexerState.trait, ElnaLexerClass.x, ElnaLexerAction.accumulate, ElnaLexerState.trait)
-end
+return
proc elna_lexer_advance(cursor: ^ElnaLexerCursor)
begin
cursor^.finish := cursor^.finish + 1;
cursor^.position.end_location.column := cursor^.position.end_location.column + 1u
-end
+return
proc elna_lexer_classify_space(start_position: ^Char; location: ^ElnaLocation)
begin
@@ -524,7 +522,7 @@ begin
else
location^.column := location^.column + 1u
end
-end
+return
proc elna_lexer_token_create(kind: ElnaLexerKind; position: ^ElnaPosition): ^ElnaLexerToken
var
@@ -532,10 +530,8 @@ var
begin
result := malloc(#size(ElnaLexerToken));
result^.kind := kind;
- result^.position := position^;
-
- return result
-end
+ result^.position := position^
+return result
proc elna_lexer_classify_keyword(position_start, position_end: ^Char; position: ^ElnaPosition): ^ElnaLexerToken
var
@@ -589,9 +585,8 @@ begin
result^.kind := ElnaLexerKind.boolean
elsif string_compare(position_start, result_length, "cast") then
result^.kind := ElnaLexerKind._cast
- end;
- return result
-end
+ end
+return result
proc elna_lexer_classify_delimited(start_position, end_position: ^Char; position: ^ElnaPosition): ^ElnaLexerToken
var
@@ -607,20 +602,16 @@ begin
elsif delimiter = '"' then
result := elna_lexer_token_create(ElnaLexerKind.string, position)
end;
- result^.start := String(start_position, cast(end_position - start_position: Word));
-
- return result
-end
+ result^.start := String(start_position, cast(end_position - start_position: Word))
+return result
proc elna_lexer_classify_integer(start_position, end_position: ^Char; position: ^ElnaPosition): ^ElnaLexerToken
var
result: ^ElnaLexerToken
begin
result := elna_lexer_token_create(ElnaLexerKind.integer, position);
- result^.start := String(start_position, cast(end_position - start_position: Word));
-
- return result
-end
+ result^.start := String(start_position, cast(end_position - start_position: Word))
+return result
proc elna_lexer_classify_finalize(start_position: ^Char; position: ^ElnaPosition): ^ElnaLexerToken
var
@@ -641,9 +632,8 @@ begin
result := elna_lexer_token_create(ElnaLexerKind.less_than, position)
elsif character = '>' then
result := elna_lexer_token_create(ElnaLexerKind.greater_than, position)
- end;
- return result
-end
+ end
+return result
proc elna_lexer_classify_single(start_position: ^Char; position: ^ElnaPosition): ^ElnaLexerToken
var
@@ -683,9 +673,8 @@ begin
result := elna_lexer_token_create(ElnaLexerKind.left_square, position)
elsif character = ']' then
result := elna_lexer_token_create(ElnaLexerKind.right_square, position)
- end;
- return result
-end
+ end
+return result
proc elna_lexer_classify_composite(start_position, one_before_last: ^Char; position: ^ElnaPosition): ^ElnaLexerToken
var
@@ -708,9 +697,8 @@ begin
if last_character = '=' then
result := elna_lexer_token_create(ElnaLexerKind.greater_equal, position)
end
- end;
- return result
-end
+ end
+return result
proc elna_lexer_execute_action(cursor: ^ElnaLexerCursor; action_to_perform: ElnaLexerAction): ^ElnaLexerToken
var
@@ -746,9 +734,8 @@ begin
elna_lexer_advance(cursor);
token := elna_lexer_classify_delimited(cursor^.start, cursor^.finish, @cursor^.position)
- end;
- return token
-end
+ end
+return token
proc elna_lexer_execute_transition(cursor: ^ElnaLexerCursor): ^ElnaLexerToken
var
@@ -758,10 +745,8 @@ begin
current_character := cursor^.finish^;
next_transition := elna_lexer_get_transition(cursor^.state,
classification[cast(current_character: Word) + 1u]);
- cursor^.state := next_transition^.next_state;
-
- return elna_lexer_execute_action(cursor, next_transition^.action)
-end
+ cursor^.state := next_transition^.next_state
+return elna_lexer_execute_action(cursor, next_transition^.action)
(**
* One time lexer initialization.
@@ -775,8 +760,8 @@ begin
cursor^.finish := code_pointer;
cursor^.token := nil;
cursor^.position.start_location := ElnaLocation(1u, 1u);
- cursor^.position.end_location := ElnaLocation(1u, 1u);
-end
+ cursor^.position.end_location := ElnaLocation(1u, 1u)
+return
(**
* Reads the next token and writes its type into the address in the kind parameter.
@@ -793,9 +778,8 @@ begin
token := elna_lexer_execute_transition(cursor)
end;
cursor^.token := token
- end;
- return cursor^.token
-end
+ end
+return cursor^.token
(**
* Reads the token and advance the lexer.
@@ -807,10 +791,8 @@ begin
token := elna_lexer_peek(cursor);
cursor^.token := nil;
cursor^.start := cursor^.finish;
- cursor^.position.start_location := cursor^.position.end_location;
-
- return token
-end
+ cursor^.position.start_location := cursor^.position.end_location
+return token
(**
* Skips comments.
@@ -825,6 +807,6 @@ begin
elna_lexer_read(cursor);
token := elna_lexer_peek(cursor)
end
-end
+return
end.
diff --git a/source/main.elna b/source/main.elna
index b7ce29c..fdfc49f 100644
--- a/source/main.elna
+++ b/source/main.elna
@@ -38,26 +38,21 @@ var
Standard procedures.
*)
proc reallocarray(ptr: Pointer; n: Word; size: Word): Pointer
- return realloc(ptr, n * size)
-end
+return realloc(ptr, n * size)
proc substring(string: String; start: Word; count: Word): String
- return String(string.ptr + start, count)
-end
+return String(string.ptr + start, count)
proc open_substring(string: String; start: Word): String
- return substring(string, start, string.length - start)
-end
+return substring(string, start, string.length - start)
proc string_dup(origin: String): String
var
copy: ^Char
begin
copy := malloc(origin.length);
- strncpy(copy, origin.ptr, origin.length);
-
- return String(copy, origin.length)
-end
+ strncpy(copy, origin.ptr, origin.length)
+return String(copy, origin.length)
proc string_buffer_new(): StringBuffer
var
@@ -65,10 +60,8 @@ var
begin
result.capacity := 64u;
result.data := malloc(result.capacity);
- result.size := 0u;
-
- return result
-end
+ result.size := 0u
+return result
proc string_buffer_push(buffer: ^StringBuffer; char: Char)
begin
@@ -78,21 +71,20 @@ begin
end;
cast(buffer^.data + buffer^.size: ^Char)^ := cast(char: Char);
buffer^.size := buffer^.size + 1u
-end
+return
proc string_buffer_pop(buffer: ^StringBuffer; count: Word)
begin
buffer^.size := buffer^.size - count
-end
+return
proc string_buffer_clear(buffer: ^StringBuffer): String
var
result: String
begin
result := String(cast(buffer^.data: ^Char), buffer^.size);
- buffer^.size := 0u;
- return result
-end
+ buffer^.size := 0u
+return result
(*
Source code stream procedures.
@@ -110,9 +102,8 @@ begin
result^.handle := file_handle;
result^.size := 0u;
result^.index := 1u
- end;
- return result
-end
+ end
+return result
proc source_file_empty(source_input: Pointer): Bool
var
@@ -123,19 +114,15 @@ begin
if source_file^.index > source_file^.size then
source_file^.size := fread(cast(@source_file^.buffer: Pointer), 1u, 1024u, source_file^.handle);
source_file^.index := 1u
- end;
-
- return source_file^.size = 0u
-end
+ end
+return source_file^.size = 0u
proc source_file_head(source_input: Pointer): Char
var
source_file: ^SourceFile
begin
- source_file := cast(source_input: ^SourceFile);
-
- return source_file^.buffer[source_file^.index]
-end
+ source_file := cast(source_input: ^SourceFile)
+return source_file^.buffer[source_file^.index]
proc source_file_advance(source_input: Pointer)
var
@@ -144,31 +131,28 @@ begin
source_file := cast(source_input: ^SourceFile);
source_file^.index := source_file^.index + 1u
-end
+return
proc source_code_empty(source_code: ^SourceCode): Bool
- return source_code^.empty(source_code^.input)
-end
+return source_code^.empty(source_code^.input)
proc source_code_head(source_code: SourceCode): Char
- return source_code.head(source_code.input)
-end
+return source_code.head(source_code.input)
proc source_code_advance(source_code: ^SourceCode)
begin
source_code^.advance(source_code^.input);
source_code^.position.column := source_code^.position.column
-end
+return
proc source_code_break(source_code: ^SourceCode)
begin
source_code^.position.line := source_code^.position.line + 1u;
source_code^.position.column := 0u
-end
+return
proc source_code_expect(source_code: ^SourceCode; expected: Char): Bool
- return ~source_code_empty(source_code) & source_code_head(source_code^) = expected
-end
+return ~source_code_empty(source_code) & source_code_head(source_code^) = expected
(*
Token procedures.
@@ -208,9 +192,8 @@ begin
successful := true
else
successful := false
- end;
- return successful
-end
+ end
+return successful
(* Skip spaces. *)
proc lexer_spaces(source_code: ^SourceCode)
@@ -225,12 +208,11 @@ begin
end;
source_code_advance(source_code)
end
-end
+return
(* Checker whether the character is allowed in an identificator. *)
proc lexer_is_ident(char: Char): Bool
- return isalnum(cast(char: Int)) <> 0 or char = '_'
-end
+return isalnum(cast(char: Int)) <> 0 or char = '_'
proc lexer_identifier(source_code: ^SourceCode; token_content: ^StringBuffer)
var
@@ -240,7 +222,7 @@ begin
string_buffer_push(token_content, source_code_head(source_code^));
source_code_advance(source_code)
end
-end
+return
proc lexer_comment(source_code: ^SourceCode; token_content: ^StringBuffer): Bool
var
@@ -260,10 +242,8 @@ begin
trailing := 0u
end;
source_code_advance(source_code)
- end;
-
- return trailing = 2u
-end
+ end
+return trailing = 2u
proc lexer_character(source_code: ^SourceCode; token_content: ^Char): Bool
var
@@ -283,9 +263,8 @@ begin
end;
if successful then
source_code_advance(source_code)
- end;
- return successful
-end
+ end
+return successful
proc lexer_string(source_code: ^SourceCode; token_content: ^StringBuffer): Bool
var
@@ -306,9 +285,8 @@ begin
source_code_advance(source_code)
else
is_valid := false
- end;
- return is_valid
-end
+ end
+return is_valid
proc lexer_number(source_code: ^SourceCode; token_content: ^Int)
begin
@@ -319,7 +297,7 @@ begin
source_code_advance(source_code)
end
-end
+return
(* Categorize an identifier. *)
proc lexer_categorize(token_content: String): ^ElnaLexerToken
@@ -404,10 +382,8 @@ begin
current_token := malloc(#size(ElnaLexerStringToken));
current_token^.kind := ElnaLexerKind.identifier;
cast(current_token: ^ElnaLexerStringToken)^.value := string_dup(token_content)
- end;
-
- return current_token
-end
+ end
+return current_token
proc lexer_add_token(lexer: ^Tokenizer; token: ^ElnaLexerToken)
var
@@ -417,7 +393,7 @@ begin
lexer^.data := cast(reallocarray(cast(lexer^.data: Pointer), new_length, #size(Pointer)): ^^ElnaLexerToken);
(lexer^.data + lexer^.length)^ := token;
lexer^.length := new_length
-end
+return
(* Read the next token from the input. *)
proc lexer_next(source_code: SourceCode; token_buffer: ^StringBuffer): ^ElnaLexerToken
@@ -599,10 +575,8 @@ begin
current_token := malloc(#size(ElnaLexerToken));
current_token^.kind := ElnaLexerKind.pipe;
source_code_advance(@source_code)
- end;
-
- return current_token
-end
+ end
+return current_token
(* Split the source text into tokens. *)
proc lexer_text(source_code: SourceCode): Tokenizer
@@ -627,10 +601,8 @@ begin
write_c(source_code_head(source_code));
write_s("\".\n")
end
- end;
-
- return lexer
-end
+ end
+return lexer
(*
Parser.
@@ -782,7 +754,7 @@ begin
i := i + 1u
end;
write_c('\n')
-end
+return
(*
Compilation entry.
@@ -798,10 +770,8 @@ begin
end;
if command_line^.parse then
parse(lexer.data, lexer.length)
- end;
-
- return return_code
-end
+ end
+return return_code
proc process(argc: Int; argv: ^^Char): Int
var
@@ -838,19 +808,18 @@ begin
source_code.advance := source_file_advance;
return_code := compile_in_stages(command_line, source_code)
- end;
- return return_code
-end
+ end
+return return_code
proc initialize_global_state()
begin
stdin := fdopen(0, "r\0".ptr);
stdout := fdopen(1, "w\0".ptr);
stderr := fdopen(2, "w\0".ptr)
-end
+return
begin
initialize_global_state();
- return process(count, parameters)
+ exit(process(count, parameters))
end.
diff --git a/testsuite/compilable/assign_record_to_base.elna b/testsuite/compilable/assign_record_to_base.elna
index 7583c70..fb28e7b 100644
--- a/testsuite/compilable/assign_record_to_base.elna
+++ b/testsuite/compilable/assign_record_to_base.elna
@@ -12,5 +12,4 @@ var
begin
x := y;
- return 0
end.
diff --git a/testsuite/compilable/empty_proc.elna b/testsuite/compilable/empty_proc.elna
index fb07285..bf3bd84 100644
--- a/testsuite/compilable/empty_proc.elna
+++ b/testsuite/compilable/empty_proc.elna
@@ -1,4 +1,4 @@
proc f()
-end
+return
end.
diff --git a/testsuite/compilable/empty_statements_in_a_row.elna b/testsuite/compilable/empty_statements_in_a_row.elna
index 3cc283c..7cf723c 100644
--- a/testsuite/compilable/empty_statements_in_a_row.elna
+++ b/testsuite/compilable/empty_statements_in_a_row.elna
@@ -1,6 +1,6 @@
proc f()
begin
;
-end
+return
end.
diff --git a/testsuite/compilable/float_literals.elna b/testsuite/compilable/float_literals.elna
index 1ce914d..ed23989 100644
--- a/testsuite/compilable/float_literals.elna
+++ b/testsuite/compilable/float_literals.elna
@@ -4,6 +4,6 @@ const
y := 1e10
z := 4.567e8
t := 2.5E-3
-end
+return
end.
diff --git a/testsuite/compilable/pointer_cast.elna b/testsuite/compilable/pointer_cast.elna
index 64b99ca..ab4b071 100644
--- a/testsuite/compilable/pointer_cast.elna
+++ b/testsuite/compilable/pointer_cast.elna
@@ -5,6 +5,4 @@ var
begin
p := c;
c := p;
-
- return 0
end.
diff --git a/testsuite/compilable/pointer_subtraction.elna b/testsuite/compilable/pointer_subtraction.elna
index 400d4f1..c268113 100644
--- a/testsuite/compilable/pointer_subtraction.elna
+++ b/testsuite/compilable/pointer_subtraction.elna
@@ -1,4 +1,4 @@
proc test(a, b: ^Char): Int
- return a - b
-end
+return a - b
+
end.
diff --git a/testsuite/compilable/semicolon_parameter_separator.elna b/testsuite/compilable/semicolon_parameter_separator.elna
index 36c8f29..229fde0 100644
--- a/testsuite/compilable/semicolon_parameter_separator.elna
+++ b/testsuite/compilable/semicolon_parameter_separator.elna
@@ -1,4 +1,4 @@
proc f(a: Int; b: Word)
-end
+return
end.
diff --git a/testsuite/fail_compilation/local_const_exported.elna b/testsuite/fail_compilation/local_const_exported.elna
index c914af5..1c6c728 100644
--- a/testsuite/fail_compilation/local_const_exported.elna
+++ b/testsuite/fail_compilation/local_const_exported.elna
@@ -1,6 +1,6 @@
proc test_local_export()
const
c* := 42 (* @Error Local symbol 'c' cannot be exported *)
-begin
-end
+return
+
end.
diff --git a/testsuite/fail_compilation/local_var_exported.elna b/testsuite/fail_compilation/local_var_exported.elna
index 77b408c..5323e5e 100644
--- a/testsuite/fail_compilation/local_var_exported.elna
+++ b/testsuite/fail_compilation/local_var_exported.elna
@@ -1,6 +1,6 @@
proc test_local_export()
var
v* : Int (* @Error Local symbol 'v' cannot be exported *)
-begin
-end
+return
+
end.
diff --git a/testsuite/fail_compilation/module_without_return.elna b/testsuite/fail_compilation/module_without_return.elna
deleted file mode 100644
index f2ece07..0000000
--- a/testsuite/fail_compilation/module_without_return.elna
+++ /dev/null
@@ -1,6 +0,0 @@
-var (* @Error Procedure 'module' is expected to return, but does not have a return statement *)
- x: Int
-
-begin
- x := 42
-end.
diff --git a/testsuite/runnable/aggregate_argument.elna b/testsuite/runnable/aggregate_argument.elna
index b92e460..89059db 100644
--- a/testsuite/runnable/aggregate_argument.elna
+++ b/testsuite/runnable/aggregate_argument.elna
@@ -4,18 +4,9 @@ type
b: Int
end
-proc f(r: R): Int
-var
- result: Int
-begin
- if r.a = 1 & r.b = 2 then
- result := 0
- else
- result := 1
- end;
- return result
-end
-
-return f(R(1, 2))
+proc f(r: R): Bool
+return r.a = 1 & r.b = 2
+begin
+ assert(f(R(1, 2)))
end.
diff --git a/testsuite/runnable/aggregate_equality.elna b/testsuite/runnable/aggregate_equality.elna
index 9f9e8fc..9cd9ab5 100644
--- a/testsuite/runnable/aggregate_equality.elna
+++ b/testsuite/runnable/aggregate_equality.elna
@@ -4,18 +4,9 @@ type
b: Int
end
-proc f(): Int
-var
- result: Int
-begin
- if R(1, 2) = R(1, 2) then
- result := 0
- else
- result := 1
- end;
- return result
-end
-
-return f()
+proc f(): Bool
+return R(1, 2) = R(1, 2)
+begin
+ assert(f())
end.
diff --git a/testsuite/runnable/array_constructor.elna b/testsuite/runnable/array_constructor.elna
index 2ce3578..feefbe7 100644
--- a/testsuite/runnable/array_constructor.elna
+++ b/testsuite/runnable/array_constructor.elna
@@ -8,5 +8,4 @@ begin
a := [3]Int{5, 6, 7};
assert(a[1] = 5 & a[2] = 6 & a[3] = 7)
-return 0
end.
diff --git a/testsuite/runnable/define_multiple_local_variables.elna b/testsuite/runnable/define_multiple_local_variables.elna
index afae692..51b99ac 100644
--- a/testsuite/runnable/define_multiple_local_variables.elna
+++ b/testsuite/runnable/define_multiple_local_variables.elna
@@ -1,16 +1,8 @@
-proc f(): Int
+proc f(): Bool
var
a, b: Int := 5
- result: Int
-begin
- if a = 5 & b = 5 then
- result := 0
- else
- result := 1
- end;
- return result
-end
-
-return f()
+return a = 5 & b = 5
+begin
+ assert(f())
end.
diff --git a/testsuite/runnable/record_base_assignment.elna b/testsuite/runnable/record_base_assignment.elna
index c91383d..2a15d0f 100644
--- a/testsuite/runnable/record_base_assignment.elna
+++ b/testsuite/runnable/record_base_assignment.elna
@@ -6,17 +6,16 @@ type
y: Word
end
-proc f(): Int
+proc f()
var
r: R
begin
r.x := 3u;
r.y := 2u;
- assert(r.x = 3u & r.y = 2u);
+ assert(r.x = 3u & r.y = 2u)
+return
- return 0
-end
-
- return f()
+begin
+ f()
end.
diff --git a/testsuite/runnable/record_construction.elna b/testsuite/runnable/record_construction.elna
index 00e60db..2bbc493 100644
--- a/testsuite/runnable/record_construction.elna
+++ b/testsuite/runnable/record_construction.elna
@@ -8,5 +8,4 @@ var
begin
assert(r.x = 1 & r.y = 2)
-return 0
end.
diff --git a/testsuite/runnable/record_extension.elna b/testsuite/runnable/record_extension.elna
index 161361b..1aae5b3 100644
--- a/testsuite/runnable/record_extension.elna
+++ b/testsuite/runnable/record_extension.elna
@@ -14,6 +14,5 @@ begin
current_token := @token_memory;
cast(current_token: ^ElnaLexerStringToken)^.value := "Some string";
- assert(token_memory.value = "Some string");
- return 0
+ assert(token_memory.value = "Some string")
end.
diff --git a/testsuite/runnable/return_aggregate.elna b/testsuite/runnable/return_aggregate.elna
index fc37565..820f72f 100644
--- a/testsuite/runnable/return_aggregate.elna
+++ b/testsuite/runnable/return_aggregate.elna
@@ -5,11 +5,8 @@ type
end
proc f(): R
- return R(1, 2)
-end
+return R(1, 2)
begin
- assert(f() = R(1, 2));
-
- return 0
+ assert(f() = R(1, 2))
end.
diff --git a/testsuite/runnable/two_fields_same_type.elna b/testsuite/runnable/two_fields_same_type.elna
index b881dda..0ebcb4e 100644
--- a/testsuite/runnable/two_fields_same_type.elna
+++ b/testsuite/runnable/two_fields_same_type.elna
@@ -6,11 +6,9 @@ type
proc f(): Int
var
r: R := R(3, 2)
+return r.x + r.y
- return r.x + r.y
-end
begin
- assert(f() = 5);
- return 0
+ assert(f() = 5)
end.
diff --git a/testsuite/runnable/two_parameters_same_type.elna b/testsuite/runnable/two_parameters_same_type.elna
index 34e70eb..bd9b271 100644
--- a/testsuite/runnable/two_parameters_same_type.elna
+++ b/testsuite/runnable/two_parameters_same_type.elna
@@ -1,9 +1,6 @@
proc f(x, y: Int): Int
- return x + y
-end
+return x + y
begin
- assert(f(2, 3) = 5);
- return 0
-
+ assert(f(2, 3) = 5)
end.