Allow only one return statement

This commit is contained in:
2025-05-17 23:12:44 +02:00
parent 573d812f1c
commit 8206b48dbd
6 changed files with 69 additions and 91 deletions

View File

@ -154,7 +154,6 @@ proc exit(code: Int) -> !; extern
*)
proc reallocarray(ptr: ^Byte, n: Word, size: Word) -> ^Byte;
begin
return realloc(ptr, n * size)
end
@ -212,32 +211,26 @@ begin
end
proc is_digit(c: Char) -> Bool;
begin
return cast(c: Int) >= cast('0': Int) & cast(c: Int) <= cast('9': Int)
end
proc is_alpha(c: Char) -> Bool;
begin
return cast(c: Int) >= cast('A': Int) & 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
@ -339,12 +332,10 @@ 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
@ -361,7 +352,6 @@ begin
end
proc source_code_expect(source_code: ^SourceCode, expected: Char) -> Bool;
begin
return ~source_code_empty(source_code) & source_code_head(source_code^) = expected
end
@ -375,7 +365,7 @@ var
begin
if escape = 'n' then
result^ := '\n';
successful := true;
successful := true
elsif escape = 'a' then
result^ := '\a';
successful := true
@ -419,12 +409,10 @@ proc skip_spaces(source_code: ^SourceCode);
var
current: Char
begin
while ~source_code_empty(source_code) do
while ~source_code_empty(source_code) & is_space(source_code_head(source_code^)) do
current := source_code_head(source_code^);
if ~is_space(current) then
return
elsif current = '\n' then
if current = '\n' then
source_code_break(source_code)
end;
source_code_advance(source_code)
@ -432,7 +420,6 @@ begin
end
proc is_ident(char: Char) -> Bool;
begin
return is_alnum(char) or char = '_'
end
@ -681,7 +668,7 @@ begin
end;
write_c(' ');
i := i + 1u;
i := i + 1u
end;
write_c('\n')
end
@ -962,7 +949,7 @@ begin
result^.parse := false;
result^.input := nil;
while i < argc do
while i < argc & result <> nil do
parameter := argv + i;
if strcmp(parameter^, "--lex\0".ptr) = 0 then
@ -972,23 +959,24 @@ begin
elsif parameter^^ <> '-' then
if result^.input <> nil then
write_s("Fatal error: Only one source file can be given.\n");
return nil
end;
result^.input := parameter^
result := nil
else
result^.input := parameter^
end
else
write_s("Fatal error: Unknown command line options: ");
write_z(parameter^);
write_s(".\n");
return nil
result := nil
end;
i := i + 1
end;
if result^.input = nil then
if result <> nil & result^.input = nil then
write_s("Fatal error: no input files.\n");
return nil
result := nil
end;
return result