Beginning of better API
This commit is contained in:
19
Lexing.jai
19
Lexing.jai
@@ -500,6 +500,25 @@ scan_next_token :: (lexer : *Lexer) -> *Token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lex :: (result : *Compile_Result) {
|
||||||
|
if result.had_error {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for file : result.files {
|
||||||
|
lexer : Lexer;
|
||||||
|
init_lexer_from_string(*lexer, file.file.source);
|
||||||
|
token : *Token = scan_next_token(*lexer);
|
||||||
|
while token && token.kind != .TOKEN_EOF {
|
||||||
|
token = scan_next_token(*lexer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Incomplete(nb): Temporary until we figure out a good way of passing this stuff around
|
||||||
|
copy_messages(lexer.result.messages, *result.messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lex :: (lexer : *Lexer, allocator : Allocator = context.allocator) -> Lexing_Result {
|
lex :: (lexer : *Lexer, allocator : Allocator = context.allocator) -> Lexing_Result {
|
||||||
lexer.result.tokens.allocator = allocator;
|
lexer.result.tokens.allocator = allocator;
|
||||||
token : *Token = scan_next_token(lexer);
|
token : *Token = scan_next_token(lexer);
|
||||||
|
|||||||
27
Parsing.jai
27
Parsing.jai
@@ -1051,6 +1051,33 @@ declaration :: (parse_state : *Parse_State) -> *AST_Node {
|
|||||||
return decl_node;
|
return decl_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parse :: (result : *Compile_Result) {
|
||||||
|
for *file : result.files {
|
||||||
|
parse_state : Parse_State;
|
||||||
|
init_parse_state(*parse_state, file.tokens.tokens, file.file.path, result.allocator);
|
||||||
|
advance(*parse_state);
|
||||||
|
|
||||||
|
if !match(*parse_state, .TOKEN_EOF) {
|
||||||
|
parse_state.result.root = make_node(*parse_state, .Program);
|
||||||
|
array_reserve(*parse_state.result.root.children, 1024);
|
||||||
|
program := parse_state.result.root;
|
||||||
|
|
||||||
|
while !check(*parse_state, .TOKEN_EOF) {
|
||||||
|
decl := declaration(*parse_state);
|
||||||
|
if decl {
|
||||||
|
add_child(program, decl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//@Incomplete(nb): will this straight copy just work?
|
||||||
|
// Might need to rething how we do this.
|
||||||
|
file.ast_root = parse_state.result.root;
|
||||||
|
file.ast_nodes = parse_state.result.nodes;
|
||||||
|
copy_messages(parse_state.result.messages, *result.messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parse :: (parse_state : *Parse_State) -> Parse_Result {
|
parse :: (parse_state : *Parse_State) -> Parse_Result {
|
||||||
advance(parse_state);
|
advance(parse_state);
|
||||||
|
|
||||||
|
|||||||
77
module.jai
77
module.jai
@@ -131,6 +131,68 @@ Shader_Variant_Collection :: struct {
|
|||||||
variants : [..]Shader_Variant;
|
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 {
|
Compilation_Result :: struct {
|
||||||
messages : [..]Compiler_Message;
|
messages : [..]Compiler_Message;
|
||||||
|
|
||||||
@@ -295,6 +357,21 @@ type_variable_to_field :: (checker : *Semantic_Checker, variable : *Type_Variabl
|
|||||||
return field;
|
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 {
|
compile_file :: (compiler : *Shader_Compiler, path : string) -> Compilation_Result {
|
||||||
result : Compilation_Result;
|
result : Compilation_Result;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user