diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-07-14 19:42:32 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-07-14 19:42:32 +0200 |
| commit | 308a2addf655fe45f2098f8542f0ff1290612cd9 (patch) | |
| tree | 19230bdb673d306d59b32427ad2a3ad5e9850631 /source/main.elna | |
| parent | a32a61813ebaecf0c1e69fd1481bf09d8c8b1420 (diff) | |
| download | elna-308a2addf655fe45f2098f8542f0ff1290612cd9.tar.gz | |
Replace procedure end with return
Diffstat (limited to 'source/main.elna')
| -rw-r--r-- | source/main.elna | 129 |
1 files changed, 49 insertions, 80 deletions
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. |
