|
#pragma once
|
|
|
|
#include "gp/containers/vector.hpp"
|
|
#include "gp/dynamic/compiler/type/type.hpp"
|
|
#include "gp/dynamic/compiler/mangle/decls.hpp"
|
|
#include "gp/utils/allocators/allocator.hpp"
|
|
|
|
using string = gp::vector<char>;
|
|
|
|
/// Returns an array GrType of `subType` subtype.
|
|
inline gr_type gr_array(gr_type subType, gp::allocator& alloc) {
|
|
auto list = gp::vector<gr_type>(alloc);
|
|
list.push_back(subType);
|
|
return gr_type(gr_base_type::array_, gr_mangle_function(list, alloc), alloc);
|
|
}
|
|
|
|
/// Returns a channel GrType of `subType` subtype.
|
|
inline gr_type gr_channel(gr_type subType, gp::allocator& alloc) {
|
|
auto list = gp::vector<gr_type>(alloc);
|
|
list.push_back(subType);
|
|
return gr_type(gr_base_type::chan, gr_mangle_function(list, alloc), alloc);
|
|
}
|
|
|
|
/// Pack multiple types as a single one.
|
|
inline gr_type gr_pack_tuple(gp::vector<gr_type> types, gp::allocator& alloc) {
|
|
const string mangledName = gr_mangle_function(types, alloc);
|
|
gr_type type(gr_base_type::internalTuple, mangledName, alloc);
|
|
return type;
|
|
}
|
|
|
|
/// Unpack multiple types from a single one.
|
|
inline gp::vector<gr_type> gr_unpack_tuple(gr_type type, gp::allocator& alloc) {
|
|
gp_config::assertion(type.base_type != gr_base_type::internalTuple, "Cannot unpack a not tuple type.");
|
|
return gr_unmangle_signature(type.mangled_type);
|
|
}
|