diff --git a/Semantic_Analysis.jai b/Semantic_Analysis.jai index 9d3ccb8..71adf51 100644 --- a/Semantic_Analysis.jai +++ b/Semantic_Analysis.jai @@ -1693,7 +1693,8 @@ add_builtins :: (checker : *Semantic_Checker) { checker.state = .Adding_Builtins; - add_file_from_string(checker.result, BUILTIN); + checker.result.file = make_file_from_string(BUILTIN); + checker.result.allocator = make_arena(*checker.result.arena); lexer : Lexer; diff --git a/Test.jai b/Test.jai index c0b343b..f7bcf6b 100644 --- a/Test.jai +++ b/Test.jai @@ -154,7 +154,8 @@ do_golden_comparison :: (golden_path : string, comparison_text : string, result_ } run_codegen_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result { - add_file(result, file_path); + result.file = make_file(result, file_path); + result.allocator = make_arena(*result.arena); result_data : Result; result_data.path = file_path; @@ -219,7 +220,9 @@ run_lexer_test :: (file_path : string, result : *Compile_Result, output_type : O result_text : string; - add_file(result, file_path); + result.file = make_file(result, file_path); + result.allocator = make_arena(*result.arena); + lex(result); if result.had_error { result_data.type = .Failed; @@ -243,7 +246,8 @@ run_parser_test :: (file_path : string, result : *Compile_Result, output_type : result_data : Result; result_data.path = file_path; - add_file(result, file_path); + result.file = make_file(result, file_path); + result.allocator = make_arena(*result.arena); lex(result); if result.had_error { @@ -306,7 +310,8 @@ run_semantic_analysis_test :: (result : *Compile_Result, output_type : Output_Ty } run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result { - add_file(result, file_path); + result.file = make_file(result, file_path); + result.allocator = make_arena(*result.arena); result_data : Result; result_data.path = file_path; @@ -334,7 +339,10 @@ make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := contex run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) { compile_result : Compile_Result; - add_file(*compile_result, file_path); + + compile_result.file = make_file(*compile_result, file_path); + compile_result.allocator = make_arena(*compile_result.arena); + result : Result; if stage_flags & .Lexer { result = run_lexer_test(file_path, *compile_result, output_type); diff --git a/module.jai b/module.jai index 4838c78..ec60c73 100644 --- a/module.jai +++ b/module.jai @@ -142,12 +142,6 @@ Token_Stream :: struct { tokens : [..]Token; } -// Compiled_File :: struct { - -// allocator : Allocator; -// arena : Arena; -// } - Compile_Result :: struct { file : Input_File; tokens : Token_Stream; @@ -196,43 +190,24 @@ record_error :: (result : *Compile_Result, format : string, args : .. Any) { array_add(*result.messages, error); } -//@Incomplete(niels): need to consider allocation -add_file :: (result : *Compile_Result, path : string) { +make_file :: (result : *Compile_Result, path : string) -> Input_File { file_string, ok := read_entire_file(path); if !ok { record_error(result, "Unable to load file: %", path); - return; + return .{}; } - add_file_from_string(result, file_string, path); + return make_file_from_string(file_string, path); } -add_file_from_string :: (result : *Compile_Result, source : string, path : string = "") { +make_file_from_string :: (source : string, path : string = "") -> Input_File { input_file : Input_File; input_file.source = source; input_file.path = path; - result.file = input_file; - - result.allocator = make_arena(*result.arena); -} - -// @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; + return input_file; } pretty_print_field :: (field : *Field) -> string { @@ -493,7 +468,9 @@ generate_output_data :: (result : *Compile_Result) { compile_file :: (compiler : *Shader_Compiler, path : string) -> Compile_Result { result : Compile_Result; - add_file(*result, path); + result.allocator = make_arena(*result.arena); + + result.file = make_file(*result, path); lex(*result); parse(*result); @@ -503,21 +480,3 @@ compile_file :: (compiler : *Shader_Compiler, path : string) -> Compile_Result { return result; } - -compile_files :: (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); - generate_output_data(*result); - - return result; -} - - diff --git a/test/lex/field_assignment.golden b/test/lex/field_assignment.golden index 4b18557..541f78b 100644 --- a/test/lex/field_assignment.golden +++ b/test/lex/field_assignment.golden @@ -27,5 +27,4 @@ {kind = TOKEN_IDENTIFIER; ; index = 103 ; length = 3 line = 5 ; column = 7 ; value ='pos'; } {kind = TOKEN_SEMICOLON; ; index = 106 ; length = 1 line = 5 ; column = 10 ; value =';'; } {kind = TOKEN_RIGHTBRACE; ; index = 109 ; length = 1 line = 6 ; column = 0 ; value ='}'; } -{kind = TOKEN_IDENTIFIER; ; index = 110 ; length = 1 line = 6 ; column = 1 ; value ='x'; } -{kind = TOKEN_EOF; ; index = 113 ; length = 0 line = 7 ; column = 0 ; value =''; } +{kind = TOKEN_EOF; ; index = 112 ; length = 0 line = 7 ; column = 0 ; value =''; }