Revert "Allow only one return"

This reverts commit 18602d00a1.
This commit is contained in:
2025-03-02 10:45:54 +01:00
parent 75561fd18a
commit 09f204bd16
10 changed files with 231 additions and 79 deletions

View File

@ -140,6 +140,7 @@ proc exit(code: Int) -> !; extern
Standard procedures.
*)
proc reallocarray(ptr: ^Byte, n: Word, size: Word) -> ^Byte;
begin
return realloc(ptr, n * size)
end
@ -197,26 +198,32 @@ begin
end
proc is_digit(c: Char) -> Bool;
begin
return cast(c: Int) >= cast('0': Int) and cast(c: Int) <= cast('9': Int)
end
proc is_alpha(c: Char) -> Bool;
begin
return cast(c: Int) >= cast('A': Int) and cast(c: Int) <= cast('z': Int)
end
proc is_alnum(c: Char) -> Bool;
begin
return is_digit(c) or is_alpha(c)
end
proc is_space(c: Char) -> Bool;
begin
return c = ' ' or c = '\n' or c = '\t'
end
proc substring(string: String, start: Word, count: Word) -> String;
begin
return String(string.ptr + start, count)
end
proc open_substring(string: String, start: Word) -> String;
begin
return substring(string, start, string.length - start)
end
@ -270,6 +277,7 @@ end
*)
proc make_position() -> Position;
begin
return Position(1u, 1u)
end
@ -285,7 +293,7 @@ begin
result^.handle := file_handle;
result^.size := 0u;
result^.index := 1u
end
end;
return result
end
@ -344,7 +352,7 @@ begin
if source_file^.index > source_file^.size then
source_file^.size := fread(cast(@source_file^.buffer: ^Byte), 1u, 1024u, source_file^.handle);
source_file^.index := 1u
end
end;
return source_file^.size = 0u
end
@ -368,10 +376,12 @@ begin
end
proc source_code_empty(source_code: ^SourceCode) -> Bool;
begin
return source_code^.empty(source_code^.input)
end
proc source_code_head(source_code: SourceCode) -> Char;
begin
return source_code.head(source_code.input)
end
@ -388,6 +398,7 @@ begin
end
proc source_code_expect(source_code: ^SourceCode, expected: Char) -> Bool;
begin
return not source_code_empty(source_code) and source_code_head(source_code^) = expected
end
@ -402,6 +413,7 @@ begin
end
proc is_ident(char: Char) -> Bool;
begin
return is_alnum(char) or char = '_'
end
@ -433,7 +445,7 @@ begin
trailing := 0u
end;
source_code_advance(source_code)
end
end;
return trailing = 2u
end
@ -456,7 +468,7 @@ begin
end;
if successful then
source_code_advance(source_code)
end
end;
return successful
end
@ -481,7 +493,7 @@ begin
source_code_advance(source_code)
else
is_valid := false
end
end;
return is_valid
end
@ -710,7 +722,7 @@ begin
else
current_token.kind := TOKEN_IDENTIFIER;
current_token.value.string := string_dup(token_content)
end
end;
return current_token
end
@ -887,7 +899,7 @@ begin
write_c(first_char);
write_s("\".\n")
end
end
end;
return tokens
end
@ -904,7 +916,7 @@ begin
result^.syntax_tree := false;
result^.input := nil;
while i < argc and result <> nil do
while i < argc do
parameter := argv + i;
if strcmp(parameter^, "--tokenize\0".ptr) = 0 then
@ -920,15 +932,15 @@ begin
write_z(parameter^);
write_s(".\n");
result := nil
return nil
end;
i := i + 1
end;
if result <> nil and result^.input = nil then
if result^.input = nil then
write_s("Fatal error: no input files.\n");
result := nil
end
return nil
end;
return result
end
@ -969,7 +981,7 @@ begin
if command_line^.tokenize then
print_tokens(tokens, tokens_size)
end
end
end;
return return_code
end