48 bool is_checked =
false;
50 Type() : type_kind(TypeKind::NonExistent), type_data(std::monostate()) {}
51 static Type I64_t() {
return Type{TypeKind::I64_t, std::monostate()}; }
52 static Type F64_t() {
return Type{TypeKind::F64_t, std::monostate()}; }
53 static Type Bool() {
return Type{TypeKind::Bool, std::monostate()}; }
54 static Type Poisoned() {
return Type{TypeKind::Poisoned, std::monostate()}; }
55 static Type Unit() {
return Type{TypeKind::Unit, std::monostate()}; }
56 static Type String(
const std::string &str) {
57 return Type{TypeKind::String, str};
59 static Type NonExistent() {
60 return Type{TypeKind::NonExistent, std::monostate()};
62 static Type Function(std::vector<Type> params);
63 explicit operator bool()
const {
64 return this->type_kind != TypeKind::Poisoned;
66 bool synthesized()
const {
67 return this->type_kind != TypeKind::NonExistent &&
68 this->type_kind == TypeKind::Poisoned;
70 bool checked()
const {
71 return this->is_checked || this->type_kind == TypeKind::Poisoned;
73 Type(TypeKind type_kind, TypeData type_data)
74 : type_kind(type_kind), type_data(type_data) {}
76 bool operator==(
const Type &other)
const;
78 bool operator!=(
const Type &other)
const;
79 bool operator<(
const Type &t)
const;
80 bool operator>(
const Type &t)
const;
82 std::string to_string()
const {
92 case TypeKind::Function: {
93 std::string res =
"(";
94 auto fn_type = std::get<FunctionType>(type_data);
95 auto param = fn_type.get_params_types();
96 for (
size_t i = 0; i < param.size(); i++) {
97 res += param[i].to_string();
98 if (i != param.size() - 1)
102 res += fn_type.get_return_type().to_string();
106 case TypeKind::NonExistent:
108 case TypeKind::Poisoned:
110 case TypeKind::String:
111 return fmt::format(
"\"{}\"", std::get<std::string>(type_data));
113 sammine_util::abort(
"Reaching the end of switch case and still cant "
114 "convert to string, blame Jasmine (badumbatish)!!!!!");
118 operator std::string() {
return to_string(); }