// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details #pragma once #include #include #include namespace Luau::EqSat { #define LUAU_EQSAT_ATOM(name, value) LUAU_EQSAT_ATOM_CUSTOM(name, #name, value) #define LUAU_EQSAT_ATOM_CUSTOM(name, custom, value) \ struct name : public ::Luau::EqSat::Atom \ { \ static constexpr const char* tag = custom; \ } template struct Atom { T value; }; // `Language` is very similar to `Luau::Variant` with enough differences warranting a different type altogether. // // Firstly, where `Luau::Variant` uses an `int` to decide which type the variant currently holds, we use // a `const char*` instead. We use the pointer address for tag checking, and the string buffer for stringification. // // Secondly, we need `Language` to have additional methods such as: // - `children()` to get child operands, // - `operator==` to decide equality, and // - `hash()` function. // // And finally, each `T` in `Ts` have additional requirements which `Luau::Variant` doesn't need. template class Language { const char* tag; char buffer[std::max({sizeof(Ts)...})]; public: template Language(T&& t) { using TT = std::decay_t; static_assert(std::disjunction_v...>); tag = T::tag; new (&buffer) TT(std::forward(t)); } template const T* get() const { static_assert(std::disjunction_v, Ts>...>); return tag == T::tag ? reinterpret_cast(&buffer) : nullptr; } public: struct Hash { size_t operator()(const Language& lang) { // TODO. Currently here so I can build and test this project. return 0; } }; }; } // namespace Luau::EqSat