|
|
- #pragma once
-
- #include "gp/containers/vector.hpp"
- #include "gp/dynamic/compiler/mangle/decls.hpp"
-
- constexpr auto append = [] (string& target, auto... var) {
- constexpr auto append_str = [] (string& target, auto& var) {
- if constexpr (std::is_same_v<decltype(var), const char*&>) {
- for(auto it = var; *it != 0; it++) {
- char c = *it;
- target.push_back(c);
- }
- } else {
- for(char c : var) {
- target.push_back(c);
- }
- }
- };
-
- (append_str(target, var), ...);
- };
-
- string grMangleFunction(gp::vector<gr_type> signature, gp::allocator& alloc) {
- string mangledName(alloc);
-
- for(auto& type : signature) {
- append(mangledName, "$");
- switch(type.base_type){
- case gr_base_type::void_:
- append(mangledName, "*");
- break;
- case gr_base_type::null_:
- append(mangledName, "0");
- break;
- case gr_base_type::int_:
- append(mangledName, "i");
- break;
- case gr_base_type::float_:
- append(mangledName, "r");
- break;
- case gr_base_type::bool_:
- append(mangledName, "b");
- break;
- case gr_base_type::string_:
- append(mangledName, "s");
- break;
- case gr_base_type::array_:
- append(mangledName, "n(", type.mangled_type, ")");
- break;
- case gr_base_type::class_:
- append(mangledName, "p(", type.mangled_type, ")");
- break;
- case gr_base_type::enum_:
- append(mangledName, "e(", type.mangled_type, ")");
- break;
- case gr_base_type::foreign:
- append(mangledName, "u(", type.mangled_type, ")");
- break;
- case gr_base_type::function_:
- append(mangledName, "f(", type.mangled_type, ")(", type.mangled_return_type, ")");
- break;
- case gr_base_type::task:
- append(mangledName, "t(", type.mangled_type, ")");
- break;
- case gr_base_type::chan:
- append(mangledName, "c(", type.mangled_type, ")");
- break;
- case gr_base_type::reference:
- append(mangledName, "h(", type.mangled_type, ")");
- break;
- case gr_base_type::internalTuple:
- gp_config::assertion(false, "Trying to mangle a tuple. Tuples should not exist here.");
- }
- }
- return mangledName;
- }
-
- string grMangleNamedFunction(string name,gp::vector<gr_type> signature, gp::allocator& alloc) {
- string mangledName(alloc);
- append(mangledName, name, grMangleFunction(signature, alloc));
- return mangledName;
- }
|