Allow assigning nil to any pointer
This commit is contained in:
60
source.elna
60
source.elna
@ -40,7 +40,8 @@ type
|
||||
dummy: Int
|
||||
end,
|
||||
CommandLine = record
|
||||
input: pointer to Char
|
||||
input: pointer to Char;
|
||||
tokenize: Bool
|
||||
end,
|
||||
Literal = record
|
||||
value: Int
|
||||
@ -76,6 +77,7 @@ proc reallocarray(ptr: pointer to Byte, n: Word, size: Word): pointer to Byte; e
|
||||
|
||||
proc memset(ptr: pointer to Char, c: Int, n: Int): pointer to Char; extern;
|
||||
|
||||
proc strcmp(s1: pointer to Char, s2: pointer to Char): Int; extern;
|
||||
proc strncmp(s1: pointer to Char, s2: pointer to Char, n: Word): Int; extern;
|
||||
proc strncpy(dst: pointer to Char, src: pointer to Char, dsize: Word): pointer to Char; extern;
|
||||
proc strcpy(dst: pointer to Char, src: pointer to Char): pointer to Char; extern;
|
||||
@ -185,7 +187,7 @@ begin
|
||||
|
||||
input := calloc(source_size + 1, 1);
|
||||
if fread(input, source_size, 1, input_file) <> 1u then
|
||||
input := cast(nil as pointer to Byte)
|
||||
input := nil
|
||||
end;
|
||||
fclose(input_file);
|
||||
|
||||
@ -548,7 +550,7 @@ var
|
||||
token_length: Word;
|
||||
begin
|
||||
tokens_size^ := 0u;
|
||||
tokens := cast(nil as pointer to Token);
|
||||
tokens := nil;
|
||||
|
||||
input_pointer := skip_spaces(input_pointer);
|
||||
|
||||
@ -564,7 +566,7 @@ begin
|
||||
|
||||
input_pointer := token_end
|
||||
elsif is_digit(input_pointer^) then
|
||||
token_end := cast(nil as pointer to Char);
|
||||
token_end := nil;
|
||||
current_token^.value.int_value := strtol(input_pointer, @token_end, 10);
|
||||
|
||||
if token_end^ = 'u' then
|
||||
@ -731,7 +733,7 @@ var
|
||||
begin
|
||||
result := cast(calloc(1, sizeof(Program)) as pointer to Program);
|
||||
|
||||
result^.constants.elements := cast(nil as pointer to pointer to ConstantDefinition);
|
||||
result^.constants.elements := nil;
|
||||
result^.constants.count := 0u;
|
||||
|
||||
if tokens^^.kind = TOKEN_CONST then
|
||||
@ -760,28 +762,34 @@ var
|
||||
i: Int,
|
||||
result: pointer to CommandLine;
|
||||
begin
|
||||
if argc < 2 then
|
||||
i := 1;
|
||||
result := cast(malloc(sizeof(CommandLine)) as pointer to CommandLine);
|
||||
result^.tokenize := false;
|
||||
result^.input := nil;
|
||||
|
||||
while i < argc do
|
||||
parameter := argv + i * cast(sizeof(pointer to Char) as Int);
|
||||
|
||||
if strcmp(parameter^, "--tokenize") = 0 then
|
||||
result^.tokenize := true
|
||||
elsif parameter^^ <> '-' then
|
||||
result^.input := parameter^
|
||||
else
|
||||
write_s("Fatal error: Unknown command line options:");
|
||||
|
||||
write_c(' ');
|
||||
write_s(parameter^);
|
||||
write_s(".\n");
|
||||
|
||||
return nil
|
||||
end;
|
||||
|
||||
i := i + 1
|
||||
end;
|
||||
if result^.input = nil then
|
||||
write_s("Fatal error: no input files.\n");
|
||||
return nil
|
||||
end;
|
||||
if argc > 2 then
|
||||
write_s("Fatal error: Unknown command line options:");
|
||||
|
||||
i := 2;
|
||||
while i < argc do
|
||||
parameter := argv + i * cast(sizeof(pointer to Char) as Int);
|
||||
|
||||
write_c(' ');
|
||||
write_s(parameter^);
|
||||
i := i + 1
|
||||
end;
|
||||
write_s(".\n");
|
||||
return nil
|
||||
end;
|
||||
|
||||
parameter := argv + cast(sizeof(pointer to Char) as Int);
|
||||
result := cast(malloc(sizeof(CommandLine)) as pointer to CommandLine);
|
||||
result^.input := parameter^;
|
||||
|
||||
return result
|
||||
end;
|
||||
@ -805,7 +813,9 @@ begin
|
||||
end;
|
||||
tokens := tokenize(input, @tokens_size);
|
||||
|
||||
print_tokens(tokens, tokens_size);
|
||||
if command_line^.tokenize then
|
||||
print_tokens(tokens, tokens_size)
|
||||
end;
|
||||
|
||||
parse_program(@tokens, @tokens_size);
|
||||
return 0
|
||||
|
Reference in New Issue
Block a user