Beginning of better API

This commit is contained in:
2024-09-02 12:34:48 +02:00
parent c8cd15456d
commit d9dfcc6354
3 changed files with 124 additions and 1 deletions

View File

@@ -131,6 +131,68 @@ Shader_Variant_Collection :: struct {
variants : [..]Shader_Variant;
}
Input_File :: struct {
source : string;
path : string;
}
Token_Stream :: struct {
tokens : [..]Token;
}
Compiled_File :: struct {
file : Input_File;
tokens : Token_Stream;
ast_root : *AST_Node;
ast_nodes : [..]AST_Node;
}
Compile_Result :: struct {
files : [..]Compiled_File;
had_error : bool;
messages : [..]Compiler_Message;
allocator : Allocator;
arena : Arena;
}
//@Incomplete(niels): need to consider allocation
add_file :: (result : *Compile_Result, path : string) {
file_string, ok := read_entire_file(path);
if !ok {
// record_error(.File_Load_Failed, "Unable to load file: %", path);
return;
}
input_file : Input_File;
input_file.source = file_string;
input_file.path = path;
compiled_file : Compiled_File;
compiled_file.file = input_file;
array_add(*result.files, compiled_file);
}
// @Incomplete(nb): Will we ever even use this?
from_file :: (path : string) -> Compile_Result {
arr : [1]string;
arr[0] = path;
return from_files(arr);
}
from_files :: (paths : []string) -> Compile_Result {
result : Compile_Result;
for path : paths {
add_file(*result, path);
}
return result;
}
Compilation_Result :: struct {
messages : [..]Compiler_Message;
@@ -295,9 +357,24 @@ type_variable_to_field :: (checker : *Semantic_Checker, variable : *Type_Variabl
return field;
}
compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Result {
result : Compile_Result;
for path : paths {
add_file(*result, path);
}
lex(*result);
// parse(*result);
// check(*result);
// codegen(*result);
return result;
}
compile_file :: (compiler : *Shader_Compiler, path : string) -> Compilation_Result {
result : Compilation_Result;
lexer : Lexer;
init_lexer_from_file(*lexer, path);