mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 06:58:45 +00:00
96 lines
2 KiB
C++
96 lines
2 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <variant>
|
|
#include <optional>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
// for clangd
|
|
|
|
namespace interpreter {
|
|
class Node;
|
|
} // namespace interpreter
|
|
|
|
namespace info {
|
|
|
|
using NumberValue = long long;
|
|
using FloatNumberValue = float;
|
|
using StringValue = std::string;
|
|
|
|
struct SimpleValue {
|
|
std::variant<NumberValue, FloatNumberValue, StringValue> value;
|
|
};
|
|
|
|
struct Value {
|
|
enum class ValueStructure {
|
|
Simple, // one value
|
|
Variant, // one value from list, can have arguments
|
|
// MultiVariant, // constructed variant // ??
|
|
Tuple, // tuple of values
|
|
};
|
|
ValueStructure structure;
|
|
std::vector<std::variant<SimpleValue, Value>> values;
|
|
};
|
|
// better variant value storage (then string) ??
|
|
|
|
struct Info {
|
|
std::string name;
|
|
};
|
|
|
|
struct VariantTypeInfo;
|
|
struct TupleTypeInfo;
|
|
struct AliasTypeInfo;
|
|
|
|
enum class BuiltInTypeInfo {
|
|
StringT,
|
|
IntT,
|
|
FloatT,
|
|
};
|
|
|
|
using TypeInfo = std::variant<VariantTypeInfo, TupleTypeInfo, AliasTypeInfo, BuiltInTypeInfo>;
|
|
|
|
struct VariableInfo : public Info {
|
|
Value value;
|
|
TypeInfo* type = nullptr;
|
|
};
|
|
// TODO lambda functions as values
|
|
|
|
// TODO aliases ??
|
|
|
|
struct TupleTypeInfo : public Info {
|
|
std::vector<std::pair<std::optional<std::string>, TypeInfo>> fields;
|
|
};
|
|
|
|
struct VariantTypeInfo : public Info {
|
|
std::vector<std::variant<std::string, TupleTypeInfo>> constructors;
|
|
// ?? any type instead of tuple type ??
|
|
};
|
|
|
|
struct AliasTypeInfo : public Info {
|
|
bool isAnotherType; // = true by default ??
|
|
TypeInfo* type = nullptr;
|
|
};
|
|
|
|
struct TypeclassInfo : public Info {
|
|
// TODO
|
|
};
|
|
|
|
struct PointerInfo {
|
|
VariableInfo* variable;
|
|
};
|
|
|
|
struct FunctionInfo : public Info {
|
|
interpreter::Node* definition;
|
|
std::vector<VariableInfo> args;
|
|
// add requirements ??
|
|
};
|
|
|
|
struct NamespaceInfo : public Info {
|
|
std::unordered_map<std::string, TypeInfo> types;
|
|
std::unordered_map<std::string, VariableInfo> variables;
|
|
std::unordered_map<std::string, FunctionInfo> functions;
|
|
std::unordered_map<std::string, NamespaceInfo> namespaces;
|
|
};
|
|
|
|
} // namespace info
|