mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 06:58:45 +00:00
fixes, part of execute_visitor
This commit is contained in:
parent
7d96fe5a86
commit
802b736e15
7 changed files with 345 additions and 92 deletions
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
namespace info::value {
|
||||
|
||||
struct ValueManager;
|
||||
|
||||
struct Unit {};
|
||||
|
||||
struct InternalValue {
|
||||
|
|
@ -27,6 +29,8 @@ public:
|
|||
}
|
||||
return &std::get<T>(value);
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GetFieldValue(const std::string& name);
|
||||
public:
|
||||
std::variant<double,
|
||||
long long,
|
||||
|
|
@ -38,67 +42,104 @@ public:
|
|||
|
||||
struct TupleValue {
|
||||
public:
|
||||
TupleValue() = default;
|
||||
explicit TupleValue(std::vector<std::pair<std::optional<std::string>, utils::IdType>>&& fields) : fields(std::move(fields)) {}
|
||||
explicit TupleValue(ValueManager* value_manager) : value_manager_(value_manager) {}
|
||||
|
||||
explicit TupleValue(std::vector<std::pair<std::optional<std::string>, utils::IdType>>&& fields,
|
||||
ValueManager* value_manager)
|
||||
: fields(std::move(fields)), value_manager_(value_manager) {}
|
||||
|
||||
std::optional<utils::IdType> GetFieldValue(const std::string& name);
|
||||
public:
|
||||
std::vector<std::pair<std::optional<std::string>, utils::IdType>> fields;
|
||||
|
||||
private:
|
||||
ValueManager* value_manager_;
|
||||
};
|
||||
|
||||
struct VariantValue {
|
||||
public:
|
||||
VariantValue() = default;
|
||||
VariantValue(utils::IdType value) // TupleValue ?? // TODO: add type & constructor??
|
||||
: value(value) {}
|
||||
explicit VariantValue(ValueManager* value_manager) : value_manager_(value_manager) {}
|
||||
|
||||
// TupleValue ?? // TODO: add type??
|
||||
VariantValue(utils::IdType value, size_t current_constructor, ValueManager* value_manager)
|
||||
: value(value), current_constructor(current_constructor), value_manager_(value_manager) {}
|
||||
|
||||
public:
|
||||
utils::IdType value;
|
||||
size_t current_constructor;
|
||||
|
||||
std::optional<utils::IdType> GetFieldValue(const std::string& name);
|
||||
private:
|
||||
ValueManager* value_manager_;
|
||||
};
|
||||
|
||||
struct ReferenceToValue {
|
||||
public:
|
||||
ReferenceToValue() = default;
|
||||
explicit ReferenceToValue(ValueManager* value_manager) : value_manager_(value_manager) {}
|
||||
|
||||
ReferenceToValue(const std::vector<utils::ReferenceModifier>& references,
|
||||
utils::IdType value)
|
||||
: references(references), value(value) {}
|
||||
utils::IdType value,
|
||||
ValueManager* value_manager)
|
||||
: references(references), value(value), value_manager_(value_manager) {}
|
||||
|
||||
public:
|
||||
std::vector<utils::ReferenceModifier> references;
|
||||
utils::IdType value;
|
||||
|
||||
std::optional<utils::IdType> GetFieldValue(const std::string& name);
|
||||
private:
|
||||
ValueManager* value_manager_;
|
||||
};
|
||||
|
||||
struct FunctionValue {
|
||||
public:
|
||||
FunctionValue() = default;
|
||||
FunctionValue(std::variant<interpreter::tokens::FunctionDeclaration*,
|
||||
interpreter::tokens::LambdaFunction*> function)
|
||||
: function(function) {}
|
||||
explicit FunctionValue(ValueManager* value_manager) : value_manager_(value_manager) {}
|
||||
|
||||
template<typename T>
|
||||
FunctionValue(const T& function, ValueManager* value_manager)
|
||||
: function(function), value_manager_(value_manager) {}
|
||||
|
||||
public:
|
||||
std::variant<interpreter::tokens::FunctionDeclaration*,
|
||||
interpreter::tokens::LambdaFunction*> function;
|
||||
|
||||
std::optional<utils::IdType> GetFieldValue(const std::string& name);
|
||||
private:
|
||||
ValueManager* value_manager_;
|
||||
};
|
||||
|
||||
|
||||
struct ArrayValue {
|
||||
public:
|
||||
ArrayValue() = default;
|
||||
explicit ArrayValue(ValueManager* value_manager) : value_manager_(value_manager) {}
|
||||
|
||||
explicit ArrayValue(std::vector<utils::IdType>&& elements,
|
||||
bool is_constant_size)
|
||||
: elements(std::move(elements)), is_constant_size(is_constant_size) {}
|
||||
bool is_constant_size,
|
||||
ValueManager* value_manager)
|
||||
: elements(std::move(elements)), is_constant_size(is_constant_size), value_manager_(value_manager) {}
|
||||
|
||||
public:
|
||||
std::vector<utils::IdType> elements;
|
||||
bool is_constant_size = false;
|
||||
|
||||
std::optional<utils::IdType> GetFieldValue(const std::string& name);
|
||||
private:
|
||||
ValueManager* value_manager_;
|
||||
};
|
||||
|
||||
struct OptionalValue {
|
||||
public:
|
||||
OptionalValue() = default;
|
||||
explicit OptionalValue(utils::IdType value) : value(value) {}
|
||||
explicit OptionalValue(ValueManager* value_manager) : value_manager_(value_manager) {}
|
||||
|
||||
explicit OptionalValue(utils::IdType value, ValueManager* value_manager)
|
||||
: value(value), value_manager_(value_manager) {}
|
||||
|
||||
std::optional<utils::IdType> GetFieldValue(const std::string& name);
|
||||
public:
|
||||
std::optional<utils::IdType> value;
|
||||
|
||||
private:
|
||||
ValueManager* value_manager_;
|
||||
};
|
||||
|
||||
struct Value { // DefinedValue ??
|
||||
|
|
@ -108,6 +149,7 @@ public:
|
|||
template<typename T>
|
||||
explicit Value(const T& value) : value(value) {} // move ??
|
||||
|
||||
std::optional<utils::IdType> GetFieldValue(const std::string& name);
|
||||
public:
|
||||
std::variant<InternalValue,
|
||||
TupleValue,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue