49 bool is_checked =
false;
51 Type() : type_kind(TypeKind::NonExistent), type_data(std::monostate()) {}
52 static Type I64_t() {
return Type{TypeKind::I64_t, std::monostate()}; }
53 static Type F64_t() {
return Type{TypeKind::F64_t, std::monostate()}; }
54 static Type Bool() {
return Type{TypeKind::Bool, std::monostate()}; }
55 static Type Poisoned() {
return Type{TypeKind::Poisoned, std::monostate()}; }
56 static Type Unit() {
return Type{TypeKind::Unit, std::monostate()}; }
57 static Type String(
const std::string &str) {
58 return Type{TypeKind::String, str};
60 static Type NonExistent() {
61 return Type{TypeKind::NonExistent, std::monostate()};
63 static Type Function(std::vector<Type> params);
64 explicit operator bool()
const {
65 return this->type_kind != TypeKind::Poisoned;
67 bool synthesized()
const {
68 return this->type_kind != TypeKind::NonExistent &&
69 this->type_kind == TypeKind::Poisoned;
71 bool checked()
const {
72 return this->is_checked || this->type_kind == TypeKind::Poisoned;
74 Type(TypeKind type_kind, TypeData type_data)
75 : type_kind(type_kind), type_data(type_data) {}
77 bool operator==(
const Type &other)
const;
79 bool operator!=(
const Type &other)
const;
80 bool operator<(
const Type &t)
const;
81 bool operator>(
const Type &t)
const;
83 std::string to_string()
const {
93 case TypeKind::Function: {
94 std::string res =
"(";
95 auto fn_type = std::get<FunctionType>(type_data);
96 auto param = fn_type.get_params_types();
97 for (
size_t i = 0; i < param.size(); i++) {
98 res += param[i].to_string();
99 if (i != param.size() - 1)
103 res += fn_type.get_return_type().to_string();
107 case TypeKind::NonExistent:
109 case TypeKind::Poisoned:
111 case TypeKind::String:
112 return fmt::format(
"\"{}\"", std::get<std::string>(type_data));
114 sammine_util::abort(
"Reaching the end of switch case and still cant "
115 "convert to string, blame Jasmine (badumbatish)!!!!!");
119 operator std::string() {
return to_string(); }