diff --git a/libs/ir/source/compiler.cpp b/libs/ir/source/compiler.cpp index 3009d00..c33eb20 100644 --- a/libs/ir/source/compiler.cpp +++ b/libs/ir/source/compiler.cpp @@ -341,6 +341,13 @@ namespace pslang::ir node_ref apply(ast::cast_operation const & node) { + if (types::is_array_type(*get_type(*node.expression)) && types::is_pointer_type(*node.inferred_type)) + { + if (auto result = apply_get_address(node.expression)) + return *result; + throw std::runtime_error("Unable to cast array to pointer"); + } + auto arg = apply(*node.expression); mcontext.nodes->emplace_back(cast_operation{arg, node.inferred_type}, node.inferred_type); return last(); diff --git a/libs/types/include/pslang/types/type_fwd.hpp b/libs/types/include/pslang/types/type_fwd.hpp index a66049c..d004aa5 100644 --- a/libs/types/include/pslang/types/type_fwd.hpp +++ b/libs/types/include/pslang/types/type_fwd.hpp @@ -22,6 +22,7 @@ namespace pslang::types bool is_floating_point_type(type const & type); bool is_numeric_type(type const & type); bool is_builtin_type(type const & type); + bool is_array_type(type const & type); bool is_function_type(type const & type); bool is_pointer_type(type const & type); diff --git a/libs/types/source/type.cpp b/libs/types/source/type.cpp index 533c62e..2b7ff69 100644 --- a/libs/types/source/type.cpp +++ b/libs/types/source/type.cpp @@ -123,6 +123,14 @@ namespace pslang::types return false; } + bool is_array_type(type const & type) + { + if (std::get_if(&type)) + return true; + + return false; + } + bool is_function_type(type const & type) { if (std::get_if(&type))