Change the bootstrap compiler license to GPL3

This commit is contained in:
2025-02-09 12:30:31 +01:00
parent d88bd652a4
commit 207ae0fa0a
25 changed files with 1251 additions and 65 deletions

View File

@ -191,6 +191,23 @@ begin
return string
end
proc substring(string: String, start: Word, count: Word): String;
begin
string.ptr := string.ptr + start;
string.length := count
end
proc string_dup(origin: String): String;
var
copy: pointer to Char;
begin
copy := cast(malloc(origin.length) as pointer to Char);
strncpy(copy, origin.ptr, origin.length);
origin.ptr := copy;
return origin
end
proc char_at(string: String, position: Word): Char;
begin
return (string.ptr + position)^
@ -307,36 +324,38 @@ begin
return source_code
end
proc lex_identifier(input: pointer to Char): pointer to Char;
proc lex_identifier(source_code: pointer to SourceCode, token_content: pointer to String);
var
content_length: Word;
begin
while is_alnum(input^) or input^ = '_' do
input := input + 1
content_length := 0u;
token_content^ := source_code^.text;
while is_alnum(char_at(source_code^.text, 0)) or char_at(source_code^.text, 0) = '_' do
content_length := content_length + 1u;
source_code^ := advance_source(source_code^, 1u)
end;
return input
token_content^ := substring(token_content^, 0u, content_length)
end
proc lex_comment(source_code: pointer to SourceCode, token_content: pointer to String): Bool;
var
result: pointer to Char;
content_length: Word;
begin
token_content^.ptr := source_code^.text.ptr;
token_content^.length := 0u;
content_length := 0u;
token_content^ := source_code^.text;
while source_code^.text.length > 1u do
if char_at(source_code^.text, 0) = '*' and char_at(source_code^.text, 1) = ')' then
source_code^ := advance_source(source_code^, 2u);
result := cast(malloc(token_content^.length) as pointer to Char);
strncpy(result, token_content^.ptr, token_content^.length);
token_content^.ptr := result;
token_content^ := substring(token_content^, 0, content_length);
return true
end;
token_content^.length := token_content^.length + 1u;
content_length := content_length + 1u;
source_code^ := advance_source(source_code^, 1)
end;
token_content^.ptr := nil;
token_content^.length := 0u;
return false
end
@ -633,12 +652,10 @@ begin
first_char := char_at(source_code.text, 0);
if is_alpha(first_char) or first_char = '_' then
token_end := lex_identifier(source_code.text.ptr + 1);
token_length := cast(token_end - source_code.text.ptr as Word);
lex_identifier(@source_code, @token_content);
current_token^ := categorize_identifier(token_content.ptr, token_content.length);
current_token^ := categorize_identifier(source_code.text.ptr, token_length);
source_code := advance_source(source_code, token_length)
source_code := advance_source(source_code, 1u)
elsif is_digit(first_char) then
token_end := nil;
current_token^.value.int_value := strtol(source_code.text.ptr, @token_end, 10);
@ -660,7 +677,7 @@ begin
source_code := advance_source(source_code, 1u);
if lex_comment(@source_code, @token_content) then
current_token^.value.string := token_content;
current_token^.value.string := string_dup(token_content);
current_token^.kind := TOKEN_COMMENT
else
current_token^.kind := 0