mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-23 23:38:44 +00:00
part of execute_visitor, minor fixes, function & operator fixes
This commit is contained in:
parent
d31979166e
commit
78de51f6f2
6 changed files with 345 additions and 247 deletions
|
|
@ -18,13 +18,20 @@ struct Unit {};
|
|||
struct InternalValue {
|
||||
public:
|
||||
InternalValue() = default;
|
||||
InternalValue(std::variant<double,
|
||||
long long,
|
||||
std::string,
|
||||
char,
|
||||
bool,
|
||||
Unit>&& value) : value(std::move(value)) {}
|
||||
explicit InternalValue(std::variant<double,
|
||||
long long,
|
||||
std::string,
|
||||
char,
|
||||
bool,
|
||||
Unit>&& value) : value(std::move(value)) {}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T*> GetValue() {
|
||||
if (!std::holds_alternative<T>(value)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::get<T>(value);
|
||||
}
|
||||
public:
|
||||
std::variant<double,
|
||||
long long,
|
||||
|
|
@ -37,20 +44,19 @@ public:
|
|||
struct TupleValue {
|
||||
public:
|
||||
TupleValue() = default;
|
||||
TupleValue(std::unordered_map<std::string, utils::IdType>&& fields) : fields(fields) {}
|
||||
explicit TupleValue(std::vector<std::pair<std::optional<std::string>, utils::IdType>>&& fields) : fields(std::move(fields)) {}
|
||||
|
||||
public:
|
||||
std::unordered_map<std::string, utils::IdType> fields;
|
||||
std::vector<std::pair<std::optional<std::string>, utils::IdType>> fields;
|
||||
};
|
||||
|
||||
struct VariantValue {
|
||||
public:
|
||||
VariantValue() = default;
|
||||
VariantValue(size_t constructor, TupleValue value)
|
||||
: constructor(constructor), value(value) {}
|
||||
VariantValue(TupleValue value) // TODO: add type & constructor??
|
||||
: value(value) {}
|
||||
|
||||
public:
|
||||
size_t constructor;
|
||||
TupleValue value;
|
||||
};
|
||||
|
||||
|
|
@ -58,7 +64,7 @@ struct ReferenceToValue {
|
|||
public:
|
||||
ReferenceToValue() = default;
|
||||
ReferenceToValue(const std::vector<utils::ReferenceModifier>& references,
|
||||
utils::IdType value)
|
||||
utils::IdType value)
|
||||
: references(references), value(value) {}
|
||||
|
||||
public:
|
||||
|
|
@ -70,7 +76,7 @@ struct FunctionValue {
|
|||
public:
|
||||
FunctionValue() = default;
|
||||
FunctionValue(std::variant<interpreter::tokens::FunctionDeclaration*,
|
||||
interpreter::tokens::LambdaFunction*> function)
|
||||
interpreter::tokens::LambdaFunction*> function)
|
||||
: function(function) {}
|
||||
|
||||
public:
|
||||
|
|
@ -82,17 +88,19 @@ public:
|
|||
struct ArrayValue {
|
||||
public:
|
||||
ArrayValue() = default;
|
||||
ArrayValue(const std::vector<utils::IdType>& elements)
|
||||
: elements(elements) {}
|
||||
explicit ArrayValue(const std::vector<utils::IdType>& elements,
|
||||
bool is_constant_size)
|
||||
: elements(elements), is_constant_size(is_constant_size) {}
|
||||
|
||||
public:
|
||||
std::vector<utils::IdType> elements;
|
||||
bool is_constant_size = false;
|
||||
};
|
||||
|
||||
struct OptionalValue {
|
||||
public:
|
||||
OptionalValue() = default;
|
||||
OptionalValue(utils::IdType value) : value(value) {}
|
||||
explicit OptionalValue(utils::IdType value) : value(value) {}
|
||||
|
||||
public:
|
||||
std::optional<utils::IdType> value;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue