From 90fb1a035ee96a85529ca866726c06bc444008de Mon Sep 17 00:00:00 2001 From: Niels Bross Date: Thu, 26 Sep 2024 16:47:34 +0200 Subject: [PATCH] Add Properties prefix. Fix semantic check regression. --- Codegen.jai | 17 ++++++++++++++--- Semantic_Analysis.jai | 18 ++++++++++-------- .../basic_property_and_return_value.golden | 4 ++-- test/codegen/meta_block.golden | 4 ++-- test/semant_all.suite | 2 -- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Codegen.jai b/Codegen.jai index db80225..8f193ac 100644 --- a/Codegen.jai +++ b/Codegen.jai @@ -91,11 +91,15 @@ emit_field :: (state : *Codegen_State, node : *AST_Node, indentation : int) { field := h2tv(state.type_variables, find_result.type_variable); indent(state, indentation); + print_to_builder(*state.builder, "% ", dx11_type_to_string(field)); - print("% %", node.parent.kind, node.parent.parent.kind); - if node.parent.parent.kind == .Properties { - // append(*state.builder, "__PROPERTIES__"); + if field.struct_field_parent { + parent_tv := h2tv(state.type_variables, field.struct_field_parent.type_variable); + + if parent_tv.typename == "properties" { + append(*state.builder, "__PROPERTIES__"); + } } print_to_builder(*state.builder, "%", node.name); @@ -379,6 +383,13 @@ emit_node :: (state : *Codegen_State, node : *AST_Node, indentation : int) { is_properties := type_var.typename == "properties"; if !is_properties { + if type_var.struct_field_parent { + parent_tv := h2tv(state.type_variables, type_var.struct_field_parent.type_variable); + + if parent_tv.typename == "properties" { + append(*state.builder, "__PROPERTIES__"); + } + } print_to_builder(*state.builder, "%", node.name); } diff --git a/Semantic_Analysis.jai b/Semantic_Analysis.jai index 4fefdcc..31bd7fd 100644 --- a/Semantic_Analysis.jai +++ b/Semantic_Analysis.jai @@ -1391,7 +1391,7 @@ create_call_constraint :: (checker : *Semantic_Checker, node : *AST_Node, type_v for arg : arg_vars { function_param := function.children[it_index]; - if !types_compatible(checker, arg.var, function_param) { + if !types_compatible(checker, arg.var, function_param, true) { if all_args_match { arg_node = arg.node; } @@ -1571,7 +1571,7 @@ Unification_Result :: enum { Unification_Failure; } -types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rhs : Type_Variable_Handle) -> bool { +types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rhs : Type_Variable_Handle, param_matching : bool = false) -> bool { lhs_var := h2tv(checker, lhs); rhs_var := h2tv(checker, rhs); @@ -1580,12 +1580,14 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh case .Half; #through; case .Float; #through; case .Double; { - if rhs_var.type == .Struct { - if rhs_var.typename == { - case "float2"; #through; - case "float3"; #through; - case "float4"; { - return true; + if !param_matching { + if rhs_var.type == .Struct { + if rhs_var.typename == { + case "float2"; #through; + case "float3"; #through; + case "float4"; { + return true; + } } } } diff --git a/test/codegen/basic_property_and_return_value.golden b/test/codegen/basic_property_and_return_value.golden index bb2bba0..07e79ad 100644 --- a/test/codegen/basic_property_and_return_value.golden +++ b/test/codegen/basic_property_and_return_value.golden @@ -1,6 +1,6 @@ cbuffer __PROPERTIES : register(b0) { - float4 color; + float4 __PROPERTIES__color; } @@ -11,6 +11,6 @@ float3 vs_main(float3 pos : POSITION) : SV_POSITION float4 ps_main() : SV_TARGET { - return color; + return __PROPERTIES__color; } diff --git a/test/codegen/meta_block.golden b/test/codegen/meta_block.golden index 62a3b98..6dd5a4a 100644 --- a/test/codegen/meta_block.golden +++ b/test/codegen/meta_block.golden @@ -1,6 +1,6 @@ cbuffer __PROPERTIES : register(b0) { - float4 color; + float4 __PROPERTIES__color; } @@ -11,6 +11,6 @@ float3 vs_main(float3 pos : POSITION, float2 uv : TEXCOORD0) : SV_POSITION float4 ps_main() : SV_TARGET { - return color; + return __PROPERTIES__color; } diff --git a/test/semant_all.suite b/test/semant_all.suite index 7fe1602..08cf5e5 100644 --- a/test/semant_all.suite +++ b/test/semant_all.suite @@ -6,8 +6,6 @@ test/empty_struct.shd semant test/empty_vertex_main.shd semant test/empty_vertex_main_with_position_parameter.shd semant test/field_assignment.shd semant -test/field_without_type_specifier.shd semant -test/float_suffix.shd semant test/function_call.shd semant test/function_call_out_of_order_declaration.shd semant test/function_call_return.shd semant