mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
contexts fixes
This commit is contained in:
parent
6850863f58
commit
ab29a785bf
7 changed files with 106 additions and 94 deletions
|
|
@ -6,7 +6,6 @@
|
|||
#include "contexts.hpp"
|
||||
#include "global_info.hpp"
|
||||
#include "interpreter_tree.hpp"
|
||||
#include "type_info_contexts.hpp"
|
||||
#include "types.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "values.hpp"
|
||||
|
|
|
|||
|
|
@ -3,15 +3,16 @@
|
|||
#include <ostream>
|
||||
|
||||
// for clangd
|
||||
#include "type_info_contexts.hpp"
|
||||
#include "visitor.hpp"
|
||||
#include "types.hpp"
|
||||
#include "contexts.hpp"
|
||||
|
||||
namespace interpreter {
|
||||
|
||||
class TypedPrintVisitor : public Visitor {
|
||||
public:
|
||||
explicit TypedPrintVisitor(std::ostream& out,
|
||||
info::TypeInfoContextManager& context_manager)
|
||||
info::ContextManager<info::type::Type, info::type::TypeManager>& context_manager)
|
||||
: out_(out), context_manager_(context_manager) {}
|
||||
|
||||
private:
|
||||
|
|
@ -123,7 +124,7 @@ private:
|
|||
|
||||
private:
|
||||
std::ostream& out_;
|
||||
info::TypeInfoContextManager& context_manager_;
|
||||
info::ContextManager<info::type::Type, info::type::TypeManager>& context_manager_;
|
||||
};
|
||||
|
||||
} // namespace interpreter
|
||||
|
|
|
|||
|
|
@ -13,24 +13,19 @@ namespace info::value {
|
|||
|
||||
struct Unit {};
|
||||
|
||||
|
||||
|
||||
struct InternalValue {
|
||||
public:
|
||||
InternalValue() = default;
|
||||
explicit InternalValue(std::variant<double,
|
||||
long long,
|
||||
std::string,
|
||||
char,
|
||||
bool,
|
||||
Unit>&& value) : value(std::move(value)) {}
|
||||
|
||||
template<typename T>
|
||||
explicit InternalValue(const T& value) : value(value) {} // move ??
|
||||
|
||||
template<typename T>
|
||||
std::optional<T*> GetValue() {
|
||||
if (!std::holds_alternative<T>(value)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::get<T>(value);
|
||||
return &std::get<T>(value);
|
||||
}
|
||||
public:
|
||||
std::variant<double,
|
||||
|
|
@ -107,6 +102,13 @@ public:
|
|||
};
|
||||
|
||||
struct Value { // DefinedValue ??
|
||||
public:
|
||||
Value() = default;
|
||||
|
||||
template<typename T>
|
||||
explicit Value(const T& value) : value(value) {} // move ??
|
||||
|
||||
public:
|
||||
std::variant<InternalValue,
|
||||
TupleValue,
|
||||
VariantValue,
|
||||
|
|
@ -120,7 +122,7 @@ class ValueManager {
|
|||
public:
|
||||
template<typename T>
|
||||
utils::IdType AddValue(const T& value, utils::ValueType value_type) {
|
||||
values_.push_back(std::pair<Value, utils::ValueType> {value, value_type});
|
||||
values_.push_back(std::pair<Value, utils::ValueType> {Value(value), value_type});
|
||||
return values_.size() - 1;
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +146,11 @@ public:
|
|||
utils::ValueType GetValueType(utils::IdType value_id) {
|
||||
return values_.at(value_id).second;
|
||||
}
|
||||
|
||||
bool EqualTypes(utils::IdType first_type, utils::IdType second_type) = delete; // TODO
|
||||
|
||||
bool AddTypeRequirement(utils::IdType type, utils::IdType requrement) = delete;
|
||||
|
||||
private:
|
||||
std::vector<std::pair<Value, utils::ValueType>> values_;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue