mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +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 {
|
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 VariantTypeInfo;
|
||||||
struct TupleTypeInfo;
|
struct TupleTypeInfo;
|
||||||
struct AliasTypeInfo;
|
struct AliasTypeInfo;
|
||||||
|
|
@ -49,16 +29,17 @@ enum class BuiltInTypeInfo {
|
||||||
StringT,
|
StringT,
|
||||||
IntT,
|
IntT,
|
||||||
FloatT,
|
FloatT,
|
||||||
|
UnitT,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TypeUsageInfo {
|
struct TypeUsageInfo {
|
||||||
interpreter::tokens::ParametrizedType* node;
|
interpreter::tokens::TypeExpression* node;
|
||||||
TypeInfo* info = nullptr;
|
TypeInfo* info = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParameterInfo {
|
struct ParameterInfo {
|
||||||
std::string type;
|
std::string type;
|
||||||
std::vector<interpreter::tokens::TypeclassUsage*> typeclass_nodes;
|
std::vector<interpreter::tokens::TypeclassExpression*> typeclass_nodes;
|
||||||
std::vector<TypeclassInfo*> typeclass_types;
|
std::vector<TypeclassInfo*> typeclass_types;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -79,7 +60,9 @@ struct AnyTypeInfo {
|
||||||
interpreter::tokens::AnyType* value;
|
interpreter::tokens::AnyType* value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TypeInfo { std::variant<AbstractTypeInfo, AliasTypeInfo, AnyTypeInfo> type; };
|
struct TypeInfo {
|
||||||
|
std::variant<AbstractTypeInfo, AliasTypeInfo, AnyTypeInfo> type;
|
||||||
|
};
|
||||||
|
|
||||||
struct ConstructorInfo {
|
struct ConstructorInfo {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
@ -122,6 +105,7 @@ struct NamespaceInfo {
|
||||||
std::unordered_map<std::string, utils::IdType> types;
|
std::unordered_map<std::string, utils::IdType> types;
|
||||||
std::unordered_map<std::string, utils::IdType> typeclasses;
|
std::unordered_map<std::string, utils::IdType> typeclasses;
|
||||||
std::unordered_map<std::string, utils::IdType> functions;
|
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, NamespaceInfo> namespaces;
|
||||||
std::unordered_map<std::string, std::vector<NamespaceInfo>> variable_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;
|
std::vector<utils::IdType> paramaters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: check, if defined type is variant, etc.
|
||||||
struct DefinedType {
|
struct DefinedType {
|
||||||
utils::IdType type_id;
|
utils::IdType type_id;
|
||||||
std::vector<utils::IdType> paramaters;
|
std::vector<utils::IdType> paramaters;
|
||||||
|
|
@ -37,7 +38,7 @@ struct TupleType { //
|
||||||
|
|
||||||
struct VariantType {
|
struct VariantType {
|
||||||
std::optional<std::string> type;
|
std::optional<std::string> type;
|
||||||
std::vector<std::variant<std::string, TupleType>> constructors;
|
std::vector<TupleType> constructors;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OptionalType {
|
struct OptionalType {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
// for clangd
|
// for clangd
|
||||||
#include "../include/find_symbols_visitor.hpp"
|
#include "../include/find_symbols_visitor.hpp"
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
namespace interpreter {
|
namespace interpreter {
|
||||||
|
|
||||||
// Sources -----------------
|
// Sources -----------------
|
||||||
|
|
@ -122,7 +124,7 @@ void FindSymbolsVisitor::Visit(FunctionDeclaration* node) {
|
||||||
if (was_in_statement) {
|
if (was_in_statement) {
|
||||||
current_info_ = std::move(info);
|
current_info_ = std::move(info);
|
||||||
} else {
|
} 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;
|
is_in_statement = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +154,7 @@ void FindSymbolsVisitor::Visit(FunctionDefinitionStatement* node) {
|
||||||
|
|
||||||
info.node = 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;
|
is_in_statement = false;
|
||||||
}
|
}
|
||||||
|
|
@ -253,7 +255,7 @@ void FindSymbolsVisitor::Visit(AnyAnnotatedType* node) {
|
||||||
|
|
||||||
info.typeclass_nodes.resize(node->typeclasses.size());
|
info.typeclass_nodes.resize(node->typeclasses.size());
|
||||||
for (size_t i = 0; i < node->typeclasses.size(); ++i) {
|
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();
|
node->type_graph_id_ = namespace_visitor_.GetAbstractTypeGraph()->AddVertex();
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDefinition(const std::str
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - find constructors, etc.
|
||||||
utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
||||||
TypeInfo&& type_info) {
|
TypeInfo&& type_info) {
|
||||||
size_t id = 0;
|
size_t id = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue