Move command line handling into a module
This commit is contained in:
@@ -85,12 +85,15 @@ static elna::boot::dependency elna_parse_file(dependency_state& state, const cha
|
||||
for (const auto& sub_tree : outcome.tree->imports)
|
||||
{
|
||||
std::filesystem::path sub_path = "source" / elna::boot::build_path(sub_tree->segments);
|
||||
std::unordered_map<std::filesystem::path, elna::boot::symbol_bag>::const_iterator cached_import =
|
||||
state.cache.find(sub_path);
|
||||
|
||||
if (state.cache.find(sub_path) == state.cache.end())
|
||||
if (cached_import == state.cache.end())
|
||||
{
|
||||
elna_parse_file(state, state.allocate_path(sub_path));
|
||||
elna_parse_file(state, sub_path.c_str());
|
||||
cached_import = state.cache.find(sub_path);
|
||||
}
|
||||
outcome_bag.add_import(state.cache.find(sub_path)->second);
|
||||
outcome_bag.add_import(cached_import->second);
|
||||
}
|
||||
elna::boot::error_list semantic_errors = analyze_semantics(filename, outcome.tree, outcome_bag);
|
||||
|
||||
|
@@ -50,16 +50,5 @@ namespace elna::boot
|
||||
: globals(elna::boot::builtin_symbol_table()), custom(custom)
|
||||
{
|
||||
}
|
||||
|
||||
const char *allocate_path(const std::filesystem::path path)
|
||||
{
|
||||
std::size_t current_size = this->allocated_paths.size();
|
||||
this->allocated_paths += path.native() + '\0';
|
||||
|
||||
return this->allocated_paths.data() + current_size;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string allocated_paths;
|
||||
};
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
obtain one at https://mozilla.org/MPL/2.0/. *)
|
||||
module;
|
||||
|
||||
import cstdio, cstring, common;
|
||||
import cstdio, cstring, cctype, cstdlib, common;
|
||||
|
||||
const
|
||||
CHUNK_SIZE := 85536;
|
||||
@@ -301,21 +301,20 @@ proc compare_keyword(keyword: String, token_start: BufferPosition, token_end: ^C
|
||||
var
|
||||
result: Bool;
|
||||
index: Word;
|
||||
keyword_length: Word;
|
||||
continue: Bool;
|
||||
begin
|
||||
index := 0u;
|
||||
result := true;
|
||||
keyword_length := Length(keyword);
|
||||
continue := (index < keyword_length) & (token_start.iterator <> token_end);
|
||||
continue := (index < keyword.length) & (token_start.iterator <> token_end);
|
||||
|
||||
while continue & result do
|
||||
result := (keyword[index] = token_start.iterator^) or (Lower(keyword[index]) = token_start.iterator^);
|
||||
result := keyword[index] = token_start.iterator^
|
||||
or cast(tolower(cast(keyword[index]: Int)): Char) = token_start.iterator^;
|
||||
token_start.iterator := token_start.iterator + 1;
|
||||
index := index + 1u;
|
||||
continue := (index < keyword_length) & (token_start.iterator <> token_end)
|
||||
continue := (index < keyword.length) & (token_start.iterator <> token_end)
|
||||
end;
|
||||
result := result & (index = Length(keyword));
|
||||
result := result & index = keyword.length;
|
||||
|
||||
return result & (token_start.iterator = token_end)
|
||||
end;
|
||||
|
@@ -3,9 +3,12 @@
|
||||
obtain one at https://mozilla.org/MPL/2.0/. *)
|
||||
module;
|
||||
|
||||
proc isdigit(c: Int ) -> Int; extern;
|
||||
proc isalnum(c: Int) -> Int; extern;
|
||||
proc isalpha(c: Int) -> Int; extern;
|
||||
proc isspace(c: Int) -> Int; extern;
|
||||
proc isdigit*(c: Int ) -> Int; extern;
|
||||
proc isalnum*(c: Int) -> Int; extern;
|
||||
proc isalpha*(c: Int) -> Int; extern;
|
||||
proc isspace*(c: Int) -> Int; extern;
|
||||
|
||||
proc tolower*(c: Int) -> Int; extern;
|
||||
proc toupper*(c: Int) -> Int; extern;
|
||||
|
||||
end.
|
||||
|
@@ -1,6 +1,10 @@
|
||||
(* This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
obtain one at https://mozilla.org/MPL/2.0/. *)
|
||||
|
||||
(*
|
||||
Command line handling.
|
||||
*)
|
||||
module;
|
||||
|
||||
import cstdlib, cstring, common;
|
||||
@@ -52,7 +56,7 @@ begin
|
||||
end;
|
||||
parsed := true
|
||||
end;
|
||||
if (parameter[1] <> '-') & ~parsed then
|
||||
if (parameter^ <> '-') & ~parsed then
|
||||
parsed := true;
|
||||
|
||||
if result^.input <> nil then
|
@@ -3,7 +3,7 @@
|
||||
obtain one at https://mozilla.org/MPL/2.0/. *)
|
||||
program;
|
||||
|
||||
import cstdlib, cstdio, cctype, common, Lexer;
|
||||
import cstdio, cctype, common, command_line_interface, Lexer;
|
||||
|
||||
const
|
||||
SEEK_SET* := 0;
|
||||
@@ -113,11 +113,6 @@ type
|
||||
end;
|
||||
location: Location
|
||||
end;
|
||||
CommandLine = record
|
||||
input: ^Char;
|
||||
lex: Bool;
|
||||
parse: Bool
|
||||
end;
|
||||
Tokenizer* = record
|
||||
length: Word;
|
||||
data: ^Token
|
||||
@@ -702,55 +697,6 @@ begin
|
||||
return lexer
|
||||
end;
|
||||
|
||||
(*
|
||||
Command line handling.
|
||||
*)
|
||||
|
||||
proc parse_command_line*(argc: Int, argv: ^^Char) -> ^CommandLine;
|
||||
var
|
||||
parameter: ^^Char;
|
||||
i: Int;
|
||||
result: ^CommandLine;
|
||||
begin
|
||||
i := 1;
|
||||
result := cast(malloc(#size(CommandLine)): ^CommandLine);
|
||||
result^.lex := false;
|
||||
result^.parse := false;
|
||||
result^.input := nil;
|
||||
|
||||
while i < argc & result <> nil do
|
||||
parameter := argv + i;
|
||||
|
||||
if strcmp(parameter^, "--lex\0".ptr) = 0 then
|
||||
result^.lex := true
|
||||
elsif strcmp(parameter^, "--parse\0".ptr) = 0 then
|
||||
result^.parse := true
|
||||
elsif parameter^^ <> '-' then
|
||||
if result^.input <> nil then
|
||||
write_s("Fatal error: Only one source file can be given.\n");
|
||||
result := nil
|
||||
else
|
||||
result^.input := parameter^
|
||||
end
|
||||
else
|
||||
write_s("Fatal error: Unknown command line options: ");
|
||||
|
||||
write_z(parameter^);
|
||||
write_s(".\n");
|
||||
|
||||
result := nil
|
||||
end;
|
||||
|
||||
i := i + 1
|
||||
end;
|
||||
if result <> nil & result^.input = nil then
|
||||
write_s("Fatal error: no input files.\n");
|
||||
result := nil
|
||||
end;
|
||||
|
||||
return result
|
||||
end;
|
||||
|
||||
(*
|
||||
Parser.
|
||||
*)
|
||||
|
Reference in New Issue
Block a user