mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
.
This commit is contained in:
parent
66a5dcfb4a
commit
05eccf3a2e
5 changed files with 21 additions and 27 deletions
|
|
@ -17,26 +17,6 @@ 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 VariantTypeInfo;
|
||||
struct TupleTypeInfo;
|
||||
struct AliasTypeInfo;
|
||||
|
|
@ -49,16 +29,17 @@ enum class BuiltInTypeInfo {
|
|||
StringT,
|
||||
IntT,
|
||||
FloatT,
|
||||
UnitT,
|
||||
};
|
||||
|
||||
struct TypeUsageInfo {
|
||||
interpreter::tokens::ParametrizedType* node;
|
||||
interpreter::tokens::TypeExpression* node;
|
||||
TypeInfo* info = nullptr;
|
||||
};
|
||||
|
||||
struct ParameterInfo {
|
||||
std::string type;
|
||||
std::vector<interpreter::tokens::TypeclassUsage*> typeclass_nodes;
|
||||
std::vector<interpreter::tokens::TypeclassExpression*> typeclass_nodes;
|
||||
std::vector<TypeclassInfo*> typeclass_types;
|
||||
};
|
||||
|
||||
|
|
@ -79,7 +60,9 @@ struct AnyTypeInfo {
|
|||
interpreter::tokens::AnyType* value;
|
||||
};
|
||||
|
||||
struct TypeInfo { std::variant<AbstractTypeInfo, AliasTypeInfo, AnyTypeInfo> type; };
|
||||
struct TypeInfo {
|
||||
std::variant<AbstractTypeInfo, AliasTypeInfo, AnyTypeInfo> type;
|
||||
};
|
||||
|
||||
struct ConstructorInfo {
|
||||
std::string name;
|
||||
|
|
@ -122,6 +105,7 @@ struct NamespaceInfo {
|
|||
std::unordered_map<std::string, utils::IdType> types;
|
||||
std::unordered_map<std::string, utils::IdType> typeclasses;
|
||||
std::unordered_map<std::string, utils::IdType> functions;
|
||||
std::unordered_map<std::string, utils::IdType> constructors;
|
||||
std::unordered_map<std::string, NamespaceInfo> namespaces;
|
||||
std::unordered_map<std::string, std::vector<NamespaceInfo>> variable_namespaces;
|
||||
|
||||
|
|
|
|||
6
include/typeclass_graph.hpp
Normal file
6
include/typeclass_graph.hpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
class TypeclassGraph {
|
||||
public:
|
||||
private:
|
||||
};
|
||||
|
|
@ -16,6 +16,7 @@ struct AbstractType {
|
|||
std::vector<utils::IdType> paramaters;
|
||||
};
|
||||
|
||||
// TODO: check, if defined type is variant, etc.
|
||||
struct DefinedType {
|
||||
utils::IdType type_id;
|
||||
std::vector<utils::IdType> paramaters;
|
||||
|
|
@ -37,7 +38,7 @@ struct TupleType { //
|
|||
|
||||
struct VariantType {
|
||||
std::optional<std::string> type;
|
||||
std::vector<std::variant<std::string, TupleType>> constructors;
|
||||
std::vector<TupleType> constructors;
|
||||
};
|
||||
|
||||
struct OptionalType {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// for clangd
|
||||
#include "../include/find_symbols_visitor.hpp"
|
||||
|
||||
// TODO
|
||||
|
||||
namespace interpreter {
|
||||
|
||||
// Sources -----------------
|
||||
|
|
@ -122,7 +124,7 @@ void FindSymbolsVisitor::Visit(FunctionDeclaration* node) {
|
|||
if (was_in_statement) {
|
||||
current_info_ = std::move(info);
|
||||
} else {
|
||||
node->function_id_ = namespace_visitor_.AddFunctionDeclaration(node->name, std::move(info));
|
||||
node->function_id_ = namespace_visitor_.AddFunctionDeclaration(node->name.name, std::move(info));
|
||||
is_in_statement = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -152,7 +154,7 @@ void FindSymbolsVisitor::Visit(FunctionDefinitionStatement* node) {
|
|||
|
||||
info.node = node;
|
||||
|
||||
node->function_id_ = namespace_visitor_.AddFunctionDefinition(definition->name, std::move(info));
|
||||
node->function_id_ = namespace_visitor_.AddFunctionDefinition(definition->name.name, std::move(info));
|
||||
|
||||
is_in_statement = false;
|
||||
}
|
||||
|
|
@ -253,7 +255,7 @@ void FindSymbolsVisitor::Visit(AnyAnnotatedType* node) {
|
|||
|
||||
info.typeclass_nodes.resize(node->typeclasses.size());
|
||||
for (size_t i = 0; i < node->typeclasses.size(); ++i) {
|
||||
info.typeclass_nodes[i] = &node->typeclasses[i];
|
||||
info.typeclass_nodes[i] = node->typeclasses[i].get();
|
||||
}
|
||||
|
||||
node->type_graph_id_ = namespace_visitor_.GetAbstractTypeGraph()->AddVertex();
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDefinition(const std::str
|
|||
return id;
|
||||
}
|
||||
|
||||
// TODO - find constructors, etc.
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
||||
TypeInfo&& type_info) {
|
||||
size_t id = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue