mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-24 07:48:46 +00:00
function type
This commit is contained in:
parent
7f3dfd71a1
commit
fa01d36a84
10 changed files with 87 additions and 64 deletions
|
|
@ -9,6 +9,7 @@
|
|||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -207,10 +208,11 @@ class TypeStorage {
|
|||
|
||||
public:
|
||||
TypeProxy primitive_type(builtin::types::Type type) {
|
||||
if (unit_type_id.has_value()) {
|
||||
return TypeProxy(*this, unit_type_id.value());
|
||||
auto iter = primitive_type_ids_.find(type);
|
||||
if (iter != primitive_type_ids_.end()) {
|
||||
return TypeProxy(*this, iter->second);
|
||||
} else {
|
||||
unit_type_id = storage_.size();
|
||||
primitive_type_ids_[type] = storage_.size();
|
||||
return add_type(Type(Identifier(Node(), Identifier::SIMPLE_TYPE,
|
||||
builtin::types::to_string(type))));
|
||||
}
|
||||
|
|
@ -251,72 +253,27 @@ public:
|
|||
return TypeProxy(*this, storage_.size() - 1);
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// bool try_resolve_all_generic_names
|
||||
// bool add_generic_type
|
||||
// bool add_local_type
|
||||
// // add local type requirement
|
||||
// // deduce generic type
|
||||
// void clear_local_types
|
||||
// ...
|
||||
|
||||
private:
|
||||
Type *get_type(size_t id) { return &storage_.at(id); }
|
||||
|
||||
const Type *get_type(size_t id) const { return &storage_.at(id); }
|
||||
|
||||
private:
|
||||
std::optional<size_t> unit_type_id;
|
||||
|
||||
// TODO
|
||||
// std::unordered_map<std::string, size_t> named_local_types_;
|
||||
std::unordered_map<builtin::types::Type, size_t> primitive_type_ids_;
|
||||
std::vector<Type> storage_;
|
||||
};
|
||||
|
||||
// class ModifiedTypeProxy {
|
||||
// public:
|
||||
// ModifiedTypeProxy(nodes::TypeProxy type,
|
||||
// nodes::Modifier modifier = nodes::Modifier::NONE)
|
||||
// : type_(type), modifier_(modifier) {}
|
||||
//
|
||||
// //
|
||||
//
|
||||
// nodes::Modifier get_modifier() const { return modifier_; }
|
||||
//
|
||||
// void set_modifier(nodes::Modifier modifier) { modifier_ = modifier; }
|
||||
//
|
||||
// //
|
||||
//
|
||||
// nodes::Type *get_type() { return type_.get(); }
|
||||
//
|
||||
// const nodes::Type *get_type() const { return type_.get(); }
|
||||
//
|
||||
// const nodes::TypeProxy get_type_proxy() const { return type_; }
|
||||
//
|
||||
// //
|
||||
//
|
||||
// bool operator==(const ModifiedTypeProxy &other) const {
|
||||
// return *type_.get() == *other.type_.get() && modifier_ ==
|
||||
// other.modifier_;
|
||||
// }
|
||||
//
|
||||
// bool operator!=(const ModifiedTypeProxy &other) const {
|
||||
// return !(*this == other);
|
||||
// }
|
||||
//
|
||||
// //
|
||||
//
|
||||
// bool operator<(const ModifiedTypeProxy &other) const {
|
||||
// return *type_.get() < *other.type_.get() ||
|
||||
// (*type_.get() == *other.type_.get() && modifier_ <
|
||||
// other.modifier_);
|
||||
// }
|
||||
//
|
||||
// bool operator>(const ModifiedTypeProxy &other) const { return other <
|
||||
// *this; }
|
||||
//
|
||||
// bool operator<=(const ModifiedTypeProxy &other) const {
|
||||
// return !operator>(other);
|
||||
// }
|
||||
//
|
||||
// bool operator>=(const ModifiedTypeProxy &other) const {
|
||||
// return !operator<(other);
|
||||
// }
|
||||
//
|
||||
// private:
|
||||
// nodes::TypeProxy type_;
|
||||
// nodes::Modifier modifier_;
|
||||
// };
|
||||
|
||||
class TypeCheckResult {
|
||||
public:
|
||||
// for invalid type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue