Change result to context for clarity. Fix a bunch of stuff in builtin functions and structs.
This commit is contained in:
240
Ink.jai
240
Ink.jai
@@ -127,215 +127,203 @@ get_golden_path :: (file_path : string, stage : Stage_Flags) -> string {
|
||||
return final_path;
|
||||
}
|
||||
|
||||
do_golden_comparison :: (golden_path : string, comparison_text : string, result_data : *Result, output_type : Output_Type) {
|
||||
do_golden_comparison :: (golden_path : string, comparison_text : string, result : *Result, output_type : Output_Type) {
|
||||
sc := get_scratch();
|
||||
defer scratch_end(sc);
|
||||
if output_type & .Golden {
|
||||
// Output the comparison file
|
||||
write_entire_file(golden_path, comparison_text);
|
||||
result_data.golden_path = copy_string(golden_path);
|
||||
result_data.type = .Golden_Output;
|
||||
result.golden_path = copy_string(golden_path);
|
||||
result.type = .Golden_Output;
|
||||
return;
|
||||
} else {
|
||||
// Do the comparison
|
||||
if !file_exists(golden_path) {
|
||||
result_data.info_text = tprint("Golden file % does not exist. Please run with -output-as-golden at least once.\n", golden_path);
|
||||
result_data.type = .Golden_File_Not_Found;
|
||||
result.info_text = tprint("Golden file % does not exist. Please run with -output-as-golden at least once.\n", golden_path);
|
||||
result.type = .Golden_File_Not_Found;
|
||||
return;
|
||||
}
|
||||
|
||||
golden_text, ok := read_entire_file(golden_path,, sc.allocator);
|
||||
if !ok {
|
||||
result_data.info_text = tprint("Unable to open golden file %\n", golden_path);
|
||||
result_data.type = .Golden_File_Not_Found;
|
||||
result.info_text = tprint("Unable to open golden file %\n", golden_path);
|
||||
result.type = .Golden_File_Not_Found;
|
||||
return;
|
||||
}
|
||||
|
||||
comp := replace(comparison_text, "\r\n", "\n",, sc.allocator);
|
||||
gold := replace(golden_text, "\r\n", "\n",, sc.allocator);
|
||||
result := compare(comp, gold) == 0;
|
||||
if !result {
|
||||
result_data.type = .Failed;
|
||||
result_data.info_text = tprint("Golden file:\n%\n===============\n%", gold, comp);
|
||||
ok = compare(comp, gold) == 0;
|
||||
if !ok {
|
||||
result.type = .Failed;
|
||||
result.info_text = tprint("Golden file:\n%\n===============\n%", gold, comp);
|
||||
} else {
|
||||
result_data.type = .Passed;
|
||||
result.type = .Passed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run_codegen_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result.file = make_file(result, file_path);
|
||||
result.allocator = make_arena(Megabytes(128));
|
||||
run_codegen_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
|
||||
result : Result;
|
||||
result.path = file_path;
|
||||
|
||||
result_data : Result;
|
||||
result_data.path = file_path;
|
||||
lex(ctx);
|
||||
parse(ctx);
|
||||
check(ctx);
|
||||
|
||||
lex(result);
|
||||
parse(result);
|
||||
check(result);
|
||||
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
return result_data;
|
||||
if ctx.had_error {
|
||||
result.type = .Failed;
|
||||
return result;
|
||||
}
|
||||
result_data = run_codegen_test(result, output_type);
|
||||
result = run_codegen_test(ctx, output_type);
|
||||
|
||||
return result_data;
|
||||
return result;
|
||||
}
|
||||
|
||||
run_codegen_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result_data : Result;
|
||||
result_data.path = result.file.path;
|
||||
run_codegen_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
|
||||
result : Result;
|
||||
result.path = ctx.file.path;
|
||||
result_text : string;
|
||||
|
||||
codegen(result);
|
||||
codegen(ctx);
|
||||
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_text = report_messages(result.messages);
|
||||
return result_data;
|
||||
if ctx.had_error {
|
||||
result.type = .Failed;
|
||||
result_text = report_messages(ctx.messages);
|
||||
return result;
|
||||
}
|
||||
|
||||
result_text = result.codegen_result_text;
|
||||
result_text = ctx.codegen_result_text;
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.info_text = result_text;
|
||||
result_data.type = .StdOut;
|
||||
return result_data;
|
||||
result.info_text = result_text;
|
||||
result.type = .StdOut;
|
||||
return result;
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(result.file.path, .Codegen);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data;
|
||||
golden_path := get_golden_path(ctx.file.path, .Codegen);
|
||||
do_golden_comparison(golden_path, result_text, *result, output_type);
|
||||
return result;
|
||||
}
|
||||
|
||||
run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compile_Result {
|
||||
compiler : Shader_Compiler;
|
||||
run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Compiler_Context {
|
||||
compiler : Compiler_Context;
|
||||
result : Result;
|
||||
compilation_result := compile_file(*compiler, path);
|
||||
compile_file(*compiler, path);
|
||||
print("\n");
|
||||
|
||||
if compilation_result.had_error {
|
||||
if compiler.had_error {
|
||||
result.type = .Failed;
|
||||
result.info_text = tprint("Failed compiling: %\n", path);
|
||||
}
|
||||
|
||||
return result, compilation_result;
|
||||
return result, compiler;
|
||||
}
|
||||
|
||||
run_lexer_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result_data : Result;
|
||||
result_data.path = file_path;
|
||||
result_data.stage = .Lexer;
|
||||
run_lexer_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
|
||||
result : Result;
|
||||
result.path = file_path;
|
||||
result.stage = .Lexer;
|
||||
|
||||
result_text : string;
|
||||
|
||||
result.file = make_file(result, file_path);
|
||||
result.allocator = make_arena(Megabytes(128));
|
||||
|
||||
lex(result);
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_text = report_messages(result.messages);
|
||||
lex(ctx);
|
||||
if ctx.had_error {
|
||||
result.type = .Failed;
|
||||
result_text = report_messages(ctx.messages);
|
||||
} else {
|
||||
result_text = pretty_print_tokens(result.tokens, *temp);
|
||||
result_text = pretty_print_tokens(ctx.tokens, *temp);
|
||||
}
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.info_text = result_text;
|
||||
result_data.type = .StdOut;
|
||||
return result_data;
|
||||
result.info_text = result_text;
|
||||
result.type = .StdOut;
|
||||
return result;
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(file_path, .Lexer);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data;
|
||||
do_golden_comparison(golden_path, result_text, *result, output_type);
|
||||
return result;
|
||||
}
|
||||
|
||||
run_parser_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result_data : Result;
|
||||
result_data.path = file_path;
|
||||
run_parser_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
|
||||
result : Result;
|
||||
result.path = file_path;
|
||||
|
||||
result.file = make_file(result, file_path);
|
||||
result.allocator = make_arena(Megabytes(128));
|
||||
|
||||
lex(result);
|
||||
if result.had_error {
|
||||
result_data.type = .Passed;
|
||||
return result_data;
|
||||
lex(ctx);
|
||||
if ctx.had_error {
|
||||
result.type = .Passed;
|
||||
return result;
|
||||
}
|
||||
|
||||
result_data = run_parser_test(result, output_type);
|
||||
result = run_parser_test(ctx, output_type);
|
||||
|
||||
return result_data;
|
||||
return result;
|
||||
}
|
||||
|
||||
run_parser_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
parse(result);
|
||||
result_data : Result;
|
||||
result_data.path = result.file.path;
|
||||
run_parser_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
|
||||
parse(ctx);
|
||||
result : Result;
|
||||
result.path = ctx.file.path;
|
||||
result_text : string;
|
||||
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_text = report_messages(result.messages,, temp);
|
||||
if ctx.had_error {
|
||||
result.type = .Failed;
|
||||
result_text = report_messages(ctx.messages,, temp);
|
||||
} else {
|
||||
result_text = pretty_print_ast(result.root, *temp);
|
||||
result_text = pretty_print_ast(ctx.root, *temp);
|
||||
}
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.info_text = result_text;
|
||||
result_data.type = .StdOut;
|
||||
return result_data;
|
||||
result.info_text = result_text;
|
||||
result.type = .StdOut;
|
||||
return result;
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(result.file.path, .Parser);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data;
|
||||
golden_path := get_golden_path(ctx.file.path, .Parser);
|
||||
do_golden_comparison(golden_path, result_text, *result, output_type);
|
||||
return result;
|
||||
}
|
||||
|
||||
run_semantic_analysis_test :: (result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result_data : Result;
|
||||
result_data.path = result.file.path;
|
||||
run_semantic_analysis_test :: (ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
|
||||
result : Result;
|
||||
result.path = ctx.file.path;
|
||||
result_text : string;
|
||||
|
||||
check(result);
|
||||
check(ctx);
|
||||
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
result_text = report_messages(result.messages);
|
||||
if ctx.had_error {
|
||||
result.type = .Failed;
|
||||
result_text = report_messages(ctx.messages);
|
||||
} else {
|
||||
result_text = pretty_print_symbol_table(result, temp);
|
||||
result_text = pretty_print_symbol_table(ctx, temp);
|
||||
}
|
||||
|
||||
if output_type & .StdOut {
|
||||
result_data.info_text = result_text;
|
||||
result_data.type = .StdOut;
|
||||
return result_data;
|
||||
result.info_text = result_text;
|
||||
result.type = .StdOut;
|
||||
return result;
|
||||
}
|
||||
|
||||
golden_path := get_golden_path(result.file.path, .Semantic_Analysis);
|
||||
do_golden_comparison(golden_path, result_text, *result_data, output_type);
|
||||
return result_data;
|
||||
golden_path := get_golden_path(ctx.file.path, .Semantic_Analysis);
|
||||
do_golden_comparison(golden_path, result_text, *result, output_type);
|
||||
return result;
|
||||
}
|
||||
|
||||
run_semantic_analysis_test :: (file_path : string, result : *Compile_Result, output_type : Output_Type = 0) -> Result {
|
||||
result.file = make_file(result, file_path,, result.allocator);
|
||||
result.allocator = make_arena(Megabytes(128));
|
||||
run_semantic_analysis_test :: (file_path : string, ctx : *Compiler_Context, output_type : Output_Type = 0) -> Result {
|
||||
result : Result;
|
||||
result.path = file_path;
|
||||
|
||||
result_data : Result;
|
||||
result_data.path = file_path;
|
||||
|
||||
lex(result);
|
||||
parse(result);
|
||||
if result.had_error {
|
||||
result_data.type = .Failed;
|
||||
return result_data;
|
||||
lex(ctx);
|
||||
parse(ctx);
|
||||
if ctx.had_error {
|
||||
result.type = .Failed;
|
||||
return result;
|
||||
}
|
||||
|
||||
result_data = run_semantic_analysis_test(result, output_type);
|
||||
result = run_semantic_analysis_test(ctx, output_type);
|
||||
|
||||
return result_data;
|
||||
return result;
|
||||
}
|
||||
|
||||
make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := context.allocator) -> Test_Case {
|
||||
@@ -348,40 +336,40 @@ 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;
|
||||
ctx : Compiler_Context;
|
||||
|
||||
compile_result.allocator = make_arena(Megabytes(128));
|
||||
compile_result.file = make_file(*compile_result, file_path,, compile_result.allocator);
|
||||
ctx.allocator = make_arena(Megabytes(128));
|
||||
ctx.file = make_file(*ctx, file_path,, ctx.allocator);
|
||||
|
||||
result : Result;
|
||||
if stage_flags & .Lexer {
|
||||
result = run_lexer_test(file_path, *compile_result, output_type);
|
||||
result = run_lexer_test(file_path, *ctx, output_type);
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
if stage_flags & .Parser {
|
||||
if stage_flags & .Lexer && result.type == .Passed || result.type == .Golden_Output {
|
||||
result = run_parser_test(*compile_result, output_type);
|
||||
result = run_parser_test(*ctx, output_type);
|
||||
} else {
|
||||
result = run_parser_test(file_path, *compile_result, output_type);
|
||||
result = run_parser_test(file_path, *ctx, output_type);
|
||||
}
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
if stage_flags & .Semantic_Analysis {
|
||||
if stage_flags & .Parser && (result.type == .Passed || result.type == .Golden_Output) {
|
||||
result = run_semantic_analysis_test(*compile_result, output_type);
|
||||
result = run_semantic_analysis_test(*ctx, output_type);
|
||||
} else {
|
||||
result = run_semantic_analysis_test(file_path, *compile_result, output_type);
|
||||
result = run_semantic_analysis_test(file_path, *ctx, output_type);
|
||||
}
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
if stage_flags & .Codegen {
|
||||
if stage_flags & .Semantic_Analysis && (result.type == .Passed || result.type == .Golden_Output) {
|
||||
result = run_codegen_test(*compile_result, output_type);
|
||||
result = run_codegen_test(*ctx, output_type);
|
||||
} else {
|
||||
result = run_codegen_test(file_path, *compile_result, output_type);
|
||||
result = run_codegen_test(file_path, *ctx, output_type);
|
||||
}
|
||||
record_result(results, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user