Fix builtin parsing

This commit is contained in:
2024-07-02 22:51:55 +02:00
parent 274cb379b4
commit 22b70f88b6
4 changed files with 45 additions and 10 deletions

View File

@@ -138,7 +138,7 @@ Defined_Symbol :: struct {
type_variable : Type_Variable_Handle;
source_node : *AST_Node;
functions :[..]Defined_Symbol;
functions : [..]Defined_Symbol;
builtin : bool;
}
@@ -178,6 +178,8 @@ Semantic_Check_Result :: struct {
scope_stack : Scope_Stack;
type_variables : [..]Type_Variable;
property_name : string;
}
Checker_State :: enum {
@@ -928,6 +930,10 @@ current_buffer_index : u32 = 0;
declare_properties :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_Handle {
name := ifx node.name.count == 0 then "properties" else node.name;
if node.name.count > 0 {
checker.result.property_name = name;
}
type_var := declare_struct(checker, node, name);
var := h2tv(checker, type_var);
var.type = .Properties;
@@ -997,7 +1003,7 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
symbol.name = name_to_check;
symbol.source_node = node;
symbol.type_variable = 0;
array_reserve(*symbol.functions, 16);
array_reserve(*symbol.functions, 32);
array_add(*symbol.functions, function);
add_symbol_to_scope(checker, checker.current_scope, name_to_check, symbol);
@@ -1663,8 +1669,35 @@ union_find :: (checker : *Semantic_Checker) -> bool {
return true;
}
// HLSL_BUILTIN :: #run -> string {
// T := #load "hlsl_builtin.jai";
// return "";
// };
add_hlsl_builtins :: (checker : *Semantic_Checker) {
HLSL_BUILTIN := read_entire_file("hlsl_builtin.shd");
source_location := #location().fully_pathed_filename;
path_array := split(source_location, "/");
sb : String_Builder;
for i : 0..path_array.count - 2 {
print_to_builder(*sb, path_array[i]);
append(*sb, "/");
}
append(*sb, "hlsl_builtin.shd");
path := builder_to_string(*sb);
HLSL_BUILTIN, ok := read_entire_file(path);
if !ok {
messages : [..]Compiler_Message;
internal_error_message(*messages, "Error loading builtin functions.", checker.path);
print("%\n", report_messages(messages));
assert(false);
return;
}
checker.state = .Adding_Builtins;