From 308a2addf655fe45f2098f8542f0ff1290612cd9 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 14 Jul 2026 19:42:32 +0200 Subject: Replace procedure end with return --- source/command_line_interface.elna | 6 +- source/common.elna | 22 +++---- source/lexer.elna | 90 +++++++++++--------------- source/main.elna | 129 ++++++++++++++----------------------- 4 files changed, 97 insertions(+), 150 deletions(-) (limited to 'source') 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. -- cgit v1.2.3