Try some things to figure out why overload resolution is broken.

This commit is contained in:
2024-06-20 07:00:46 +02:00
parent a9a67e3fac
commit 1be5072cbe
3 changed files with 72 additions and 54 deletions

View File

@@ -34,6 +34,8 @@ Semantic_Type :: enum {
Unresolved_Expression; Unresolved_Expression;
Struct; Struct;
Properties;
CBuffer;
Array; Array;
} }
@@ -927,6 +929,7 @@ declare_properties :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Va
name := ifx node.name.count == 0 then "properties" else node.name; name := ifx node.name.count == 0 then "properties" else node.name;
type_var := declare_struct(checker, node, name); type_var := declare_struct(checker, node, name);
var := h2tv(checker, type_var); var := h2tv(checker, type_var);
var.type = .Properties;
var.typename = "properties"; var.typename = "properties";
var.buffer_index = PROPERTIES_BUFFER_INDEX; var.buffer_index = PROPERTIES_BUFFER_INDEX;
return type_var; return type_var;
@@ -935,7 +938,7 @@ declare_properties :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Va
declare_cbuffer :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_Handle { declare_cbuffer :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_Handle {
type_var := declare_struct(checker, node); type_var := declare_struct(checker, node);
var := h2tv(checker, type_var); var := h2tv(checker, type_var);
var.typename = "constant_buffer"; var.type = .CBuffer;
current_custom_buffer_index += 1; current_custom_buffer_index += 1;
var.buffer_index = current_custom_buffer_index; var.buffer_index = current_custom_buffer_index;
return type_var; return type_var;
@@ -1006,59 +1009,56 @@ declare_function :: (checker : *Semantic_Checker, node : *AST_Node, builtin : bo
add_symbol_to_scope(checker, checker.current_scope, name_to_check, symbol); add_symbol_to_scope(checker, checker.current_scope, name_to_check, symbol);
} else { } else {
//@Note(niels): This is some ugly code, but it's probably fine for now. //@Note(niels): This is some ugly code, but it's probably fine for now.
for child : node.children { field_list := node.children[0];
if child.kind != .FieldList {
for function : find_result.functions {
func_var := h2tv(checker, function.type_variable);
if func_var.source_node.children[0].children.count != field_list.children.count {
continue; continue;
} }
for function : find_result.functions { all_same : bool = true;
func_var := h2tv(checker, function.type_variable); for i : 0..func_var.child_count - 1 {
if func_var.child_count != child.children.count { arg := func_var.children[i];
continue; node_child := field_list.children[it_index];
}
all_same : bool = true; typename : string;
for i : 0..func_var.child_count - 1 { arg_type := get_type_from_identifier(checker, checker.current_scope, node_child, *typename);
arg := func_var.children[i]; other_arg := h2tv(checker, arg);
node_child := child.children[it_index];
arg_type := get_type_from_identifier(checker, checker.current_scope, node_child);
other_arg := h2tv(checker, arg); if arg_type != other_arg.type {
all_same = false;
if arg_type != other_arg.type { break;
all_same = false; } else {
break; if arg_type == .Struct && other_arg.type == .Struct {
} else { if typename != other_arg.typename {
if arg_type == .Struct && other_arg.type == .Struct { all_same = false;
if node_child.token.ident_value != other_arg.typename { break;
all_same = false;
break;
}
} }
} }
} }
if all_same {
symbol_redeclaration(checker, node, find_result);
return 0;
} else {
function : Defined_Symbol;
function.name = name_to_check;
function.source_node = node;
function.type_variable = handle;
array_add(*find_result.functions, function);
break;
}
} }
function : Defined_Symbol; if all_same {
function.name = name_to_check; symbol_redeclaration(checker, node, find_result);
function.source_node = node; return 0;
function.type_variable = handle; } else {
function : Defined_Symbol;
function.name = name_to_check;
function.source_node = node;
function.type_variable = handle;
array_add(*find_result.functions, function); array_add(*find_result.functions, function);
break;
}
} }
function : Defined_Symbol;
function.name = name_to_check;
function.source_node = node;
function.type_variable = handle;
array_add(*find_result.functions, function);
} }
if !builtin { if !builtin {
@@ -1216,14 +1216,15 @@ create_variable :: (checker : *Semantic_Checker, node : *AST_Node, field_parent
} }
if node.children.count > 0 { if node.children.count > 0 {
if variable.type != .Struct { if variable.type != .Struct && variable.type != .Properties && variable.type != .CBuffer {
field_access_on_primitive_type(checker, node, find_result.type_variable); field_access_on_primitive_type(checker, node, find_result.type_variable);
return 0; return 0;
} else { } else {
lookup_name : string = variable.typename; lookup_name : string = variable.typename;
if variable.typename == "properties" { // if variable.typename == "properties" {
lookup_name = variable.name; // lookup_name = variable.name;
} // }
print("Lookup: %\n", lookup_name);
struct_symbol := find_symbol(checker, lookup_name, checker.current_scope); struct_symbol := find_symbol(checker, lookup_name, checker.current_scope);
type_variable := h2tv(checker, struct_symbol.type_variable); type_variable := h2tv(checker, struct_symbol.type_variable);
@@ -1891,6 +1892,8 @@ pretty_print_scope :: (checker : *Semantic_Checker, scope : *Scope, builder : *S
case .Function; { case .Function; {
pretty_print_function(checker, builder, key, type_variable, 1); pretty_print_function(checker, builder, key, type_variable, 1);
} }
case .CBuffer; #through;
case .Properties; #through;
case .Struct; { case .Struct; {
if type_variable.typename.count > 0 && type_variable.kind != .Declaration { if type_variable.typename.count > 0 && type_variable.kind != .Declaration {
indent(builder, indentation + 1); indent(builder, indentation + 1);
@@ -1915,6 +1918,8 @@ pretty_print_scope :: (checker : *Semantic_Checker, scope : *Scope, builder : *S
case .Function; { case .Function; {
pretty_print_function(checker, builder, key, type_variable, 1); pretty_print_function(checker, builder, key, type_variable, 1);
} }
case .CBuffer; #through;
case .Properties; #through;
case .Struct; { case .Struct; {
if type_variable.typename.count > 0 && type_variable.kind != .Declaration { if type_variable.typename.count > 0 && type_variable.kind != .Declaration {
indent(builder, indentation + 1); indent(builder, indentation + 1);
@@ -2107,7 +2112,8 @@ pretty_print_type_variable :: (checker : *Semantic_Checker, type_variable : *Typ
rep_var := h2tv(checker, rep); rep_var := h2tv(checker, rep);
if is_proper(type_variable) { if is_proper(type_variable) {
print_to_builder(builder, proper_type_to_string(checker, type_variable, temp)); print_to_builder(builder, proper_type_to_string(checker, type_variable, temp));
} else if type_variable.type == .Struct { } else if type_variable.type == .Struct || type_variable.type == .Properties ||
type_variable.type == .CBuffer {
if type_variable.kind == .Declaration { if type_variable.kind == .Declaration {
append(builder, "{"); append(builder, "{");

View File

@@ -96,10 +96,22 @@ int4x4 :: struct {
#foreign transpose :: (float4x4) -> float4x4; #foreign transpose :: (float4x4) -> float4x4;
//~ nbr: Multiplies //~ nbr: Multiplies
#foreign mul :: (float2, float2) -> float2; #foreign mul :: (float2, float2) -> float;
#foreign mul :: (float3, float3) -> float3; #foreign mul :: (float3, float3) -> float;
#foreign mul :: (float4, float4) -> float4; #foreign mul :: (float4, float4) -> float;
#foreign mul :: (float4x4, float4x4) -> float4x4; #foreign mul :: (float4x4, float4x4) -> float4x4;
#foreign mul :: (float, float2) -> float2;
#foreign mul :: (float, float3) -> float3;
#foreign mul :: (float, float4) -> float4;
#foreign mul :: (float, float4x4) -> float4x4;
#foreign mul :: (float4x4, float) -> float4x4;
#foreign mul :: (float4x4, float4) -> float4;
#foreign mul :: (float2, float) -> float2;
#foreign mul :: (float3, float) -> float3;
#foreign mul :: (float4, float) -> float4;
#foreign mul :: (float4, float4x4) -> float4x4;
//~ nbr: General //~ nbr: General
#foreign abs :: (float) -> float; #foreign abs :: (float) -> float;

View File

@@ -1,12 +1,12 @@
Camera_Data :: constant_buffer { camera :: constant_buffer {
projection : float4x4; projection : float4x4;
view : float4x4; view : float4x4;
} }
vertex main :: (pos : float4 @position) -> float4 @position { vertex main :: (pos : float4 @position) -> float4 @position {
return mul(projection, mul(view, pos)); return mul(camera.projection, mul(camera.view, pos));
} }
pixel main :: () -> float4 @target { pixel main :: () -> float4 @target {
return float(0.5, 0.5, 0.5, 1.0); return float4(0.5, 0.5, 0.5, 1.0);
} }