mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
partition syntax changed, interface modifier added
This commit is contained in:
parent
3fca384446
commit
b1aff1935d
22 changed files with 299 additions and 266 deletions
|
|
@ -23,8 +23,6 @@ private:
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void Visit(PartitionSources* node) override;
|
||||
void Visit(Partition* node) override;
|
||||
void Visit(NamespaceSources* node) override;
|
||||
void Visit(Namespace* node) override;
|
||||
|
||||
|
|
@ -38,9 +36,9 @@ private:
|
|||
void Visit(TypeDefinitionStatement* node) override;
|
||||
void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||
void Visit(TypeclassDefinitionStatement* node) override;
|
||||
void Visit(PartitionStatement* node) override;
|
||||
|
||||
void Visit(NamespaceStatement& node) override; // variant
|
||||
void Visit(PartitionStatement& node) override; // variant
|
||||
void Visit(SourceStatement& node) override; // variant
|
||||
|
||||
// Definition parts
|
||||
|
|
@ -101,6 +99,7 @@ private:
|
|||
|
||||
// Name
|
||||
|
||||
void Visit(PartitionName* node) override;
|
||||
void Visit(NameExpression* node) override;
|
||||
void Visit(TupleName* node) override;
|
||||
void Visit(VariantName* node) override;
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ private:
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void Visit(PartitionSources* node) override;
|
||||
void Visit(Partition* node) override;
|
||||
void Visit(NamespaceSources* node) override;
|
||||
void Visit(Namespace* node) override;
|
||||
|
||||
|
|
@ -41,6 +39,8 @@ private:
|
|||
void Visit(TypeDefinitionStatement* node) override;
|
||||
void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||
void Visit(TypeclassDefinitionStatement* node) override;
|
||||
void Visit(ExecutableStatement* node) override;
|
||||
void Visit(TestStatement* node) override;
|
||||
|
||||
// Definition parts
|
||||
|
||||
|
|
@ -89,6 +89,7 @@ private:
|
|||
|
||||
// Name
|
||||
|
||||
void Visit(PartitionName* node) override;
|
||||
void Visit(NameExpression* node) override;
|
||||
void Visit(TupleName* node) override;
|
||||
void Visit(VariantName* node) override;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ private:
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
// void Visit(PartitionSources* node) override; // default
|
||||
void Visit(Partition* node) override;
|
||||
// void Visit(NamespaceSources* node) override; // default
|
||||
void Visit(Namespace* node) override;
|
||||
|
||||
|
|
@ -36,6 +34,7 @@ private:
|
|||
void Visit(TypeDefinitionStatement* node) override;
|
||||
void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||
void Visit(TypeclassDefinitionStatement* node) override;
|
||||
void Visit(PartitionStatement* node) override;
|
||||
|
||||
// Definition parts
|
||||
|
||||
|
|
@ -84,6 +83,7 @@ private:
|
|||
|
||||
// Name
|
||||
|
||||
// // void Visit(PartitionName* node) override;
|
||||
// // void Visit(NameExpression* node) override;
|
||||
// // void Visit(TupleName* node) override;
|
||||
// // void Visit(VariantName* node) override;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <asm-generic/errno.h>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
|
@ -11,14 +12,22 @@
|
|||
|
||||
namespace info {
|
||||
|
||||
// TODO: partitions
|
||||
// TODO: better test / executable partitions support (tree, etc.)
|
||||
// TODO: add classes / structs and functions module interface
|
||||
class GlobalInfo {
|
||||
friend class NamespaceVisitor;
|
||||
public:
|
||||
struct PartitionInfo {
|
||||
std::vector<std::string> path;
|
||||
std::string name;
|
||||
interpreter::tokens::PartitionStatement* node = nullptr;
|
||||
};
|
||||
|
||||
class NamespaceVisitor {
|
||||
friend GlobalInfo;
|
||||
NamespaceVisitor() = delete;
|
||||
public:
|
||||
|
||||
struct Path {
|
||||
std::vector<std::optional<utils::IdType>> path_types;
|
||||
definition::Namespace* result;
|
||||
|
|
@ -57,6 +66,10 @@ public:
|
|||
definition::Constructor&& constructor_info,
|
||||
const interpreter::tokens::BaseNode& base_node);
|
||||
|
||||
utils::IdType AddPartition(const std::vector<std::string>& path,
|
||||
const std::string& name,
|
||||
interpreter::tokens::PartitionStatement* node);
|
||||
|
||||
std::optional<definition::Namespace*> FindNamespace(const std::optional<std::vector<std::string>>& path);
|
||||
|
||||
std::optional<utils::IdType> FindFunction(const std::optional<std::vector<std::string>>& path,
|
||||
|
|
@ -145,6 +158,11 @@ public:
|
|||
return constructors_.at(id);
|
||||
}
|
||||
|
||||
// remember about vector realloc
|
||||
const PartitionInfo& GetPartitionInfo(utils::IdType id) {
|
||||
return partitions_.at(id);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::vector<definition::Function> functions_;
|
||||
|
|
@ -156,6 +174,8 @@ private:
|
|||
std::unordered_map<std::string, utils::IdType> name_to_typeclass_;
|
||||
std::unordered_map<std::string, utils::IdType> name_to_abstract_type_;
|
||||
|
||||
std::vector<PartitionInfo> partitions_;
|
||||
|
||||
definition::Namespace global_namespace_;
|
||||
std::vector<definition::Import> imports_;
|
||||
std::unordered_map<std::string, definition::Import> usages_;
|
||||
|
|
|
|||
|
|
@ -35,8 +35,6 @@ struct SourceFile;
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
struct Partition;
|
||||
struct PartitionSources;
|
||||
struct Namespace;
|
||||
struct NamespaceSources;
|
||||
|
||||
|
|
@ -50,6 +48,7 @@ struct FunctionDefinitionStatement;
|
|||
struct TypeDefinitionStatement;
|
||||
struct AbstractTypeDefinitionStatement;
|
||||
struct TypeclassDefinitionStatement;
|
||||
struct PartitionStatement;
|
||||
|
||||
//
|
||||
using NamespaceStatement = std::variant<
|
||||
|
|
@ -57,17 +56,14 @@ using NamespaceStatement = std::variant<
|
|||
std::unique_ptr<FunctionDeclaration>,
|
||||
std::unique_ptr<FunctionDefinitionStatement>,
|
||||
std::unique_ptr<TypeDefinitionStatement>,
|
||||
std::unique_ptr<PartitionStatement>,
|
||||
std::unique_ptr<Namespace>>;
|
||||
//
|
||||
using PartitionStatement = std::variant<
|
||||
std::unique_ptr<AbstractTypeDefinitionStatement>,
|
||||
std::unique_ptr<TypeclassDefinitionStatement>,
|
||||
std::unique_ptr<NamespaceStatement>>;
|
||||
//
|
||||
using SourceStatement = std::variant<
|
||||
std::unique_ptr<ImportStatement>,
|
||||
std::unique_ptr<Partition>,
|
||||
std::unique_ptr<PartitionStatement>>;
|
||||
std::unique_ptr<AbstractTypeDefinitionStatement>,
|
||||
std::unique_ptr<TypeclassDefinitionStatement>,
|
||||
std::unique_ptr<NamespaceStatement>>;
|
||||
//
|
||||
|
||||
// Definition parts
|
||||
|
|
@ -193,6 +189,13 @@ struct ArrayExpression;
|
|||
|
||||
// Name
|
||||
|
||||
struct PartitionName {
|
||||
BaseNode base;
|
||||
|
||||
std::vector<TypeIdentifier> path;
|
||||
NameIdentifier name;
|
||||
};
|
||||
|
||||
struct NameExpression;
|
||||
struct TupleName;
|
||||
struct VariantName;
|
||||
|
|
@ -268,25 +271,6 @@ struct SourceFile {
|
|||
|
||||
// ----------------- Namespaces, partittions -----------------
|
||||
|
||||
struct PartitionSources {
|
||||
BaseNode base;
|
||||
|
||||
std::vector<PartitionStatement> statements;
|
||||
};
|
||||
|
||||
struct Partition {
|
||||
BaseNode base;
|
||||
|
||||
enum PartitionName {
|
||||
Test,
|
||||
Interface,
|
||||
Code,
|
||||
};
|
||||
|
||||
PartitionName name;
|
||||
PartitionSources scope;
|
||||
};
|
||||
|
||||
struct NamespaceSources {
|
||||
BaseNode base;
|
||||
|
||||
|
|
@ -337,6 +321,7 @@ struct VariableDefinitionStatement {
|
|||
struct FunctionDeclaration {
|
||||
BaseNode base;
|
||||
|
||||
bool is_in_interface = false;
|
||||
ExtendedName name;
|
||||
std::vector<std::unique_ptr<AnnotatedAbstractType>> parameters;
|
||||
std::unique_ptr<FunctionType> type;
|
||||
|
|
@ -347,7 +332,6 @@ struct FunctionDeclaration {
|
|||
struct FunctionDefinitionStatement {
|
||||
BaseNode base;
|
||||
|
||||
bool is_inline;
|
||||
std::unique_ptr<FunctionDefinition> definition;
|
||||
SuperExpression value;
|
||||
|
||||
|
|
@ -357,6 +341,7 @@ struct FunctionDefinitionStatement {
|
|||
struct TypeDefinitionStatement {
|
||||
BaseNode base;
|
||||
|
||||
bool is_in_interface = false;
|
||||
utils::ClassModifier modifier;
|
||||
std::unique_ptr<TypeDefinition> definition;
|
||||
AnyType value;
|
||||
|
|
@ -383,6 +368,16 @@ struct TypeclassDefinitionStatement {
|
|||
utils::IdType typeclass_id_;
|
||||
};
|
||||
|
||||
struct PartitionStatement {
|
||||
BaseNode base;
|
||||
|
||||
utils::PartitionModifier modifier;
|
||||
PartitionName name;
|
||||
SuperExpression value;
|
||||
|
||||
utils::IdType executable_id_;
|
||||
};
|
||||
|
||||
// Definition parts -----------------
|
||||
|
||||
struct FunctionDefinition {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ private:
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
// // void Visit(PartitionSources* node) override;
|
||||
// // void Visit(Partition* node) override;
|
||||
// // void Visit(NamespaceSources* node) override;
|
||||
void Visit(Namespace* node) override;
|
||||
|
||||
|
|
@ -36,6 +34,7 @@ private:
|
|||
// // void Visit(TypeDefinitionStatement* node) override;
|
||||
// // void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||
// // void Visit(TypeclassDefinitionStatement* node) override;
|
||||
// // void Visit(PartitionStatement* node) override;
|
||||
|
||||
// Definition parts
|
||||
|
||||
|
|
@ -83,6 +82,7 @@ private:
|
|||
|
||||
// Name
|
||||
|
||||
// // void Visit(PartitionName* node) override;
|
||||
// // void Visit(NameExpression* node) override;
|
||||
// // void Visit(TupleName* node) override;
|
||||
// // void Visit(VariantName* node) override;
|
||||
|
|
|
|||
|
|
@ -8,16 +8,12 @@ namespace parser::tokens {
|
|||
|
||||
const std::string SourceFile = "source_file";
|
||||
const std::string SourceStatement = "source_statement";
|
||||
const std::string PartitionSources = "partition_sources";
|
||||
const std::string PartitionStatement = "partition_statement";
|
||||
const std::string NamespaceSources = "namespace_sources";
|
||||
const std::string NamespaceStatement = "namespace_statement";
|
||||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
const std::string Namespace = "namespace";
|
||||
const std::string Partition = "partition";
|
||||
const std::string PartitionName = "partition_name";
|
||||
|
||||
// Definitions -----------------
|
||||
|
||||
|
|
@ -29,6 +25,7 @@ const std::string FunctionDefinitionStatement = "function_definition_statement";
|
|||
const std::string TypeDefinitionStatement = "type_definition_statement";
|
||||
const std::string AbstractTypeDefinitionStatement = "abstract_type_definition_statement";
|
||||
const std::string TypeclassDefinitionStatement = "typeclass_definition_statement";
|
||||
const std::string PartitionStatement = "partition_statement";
|
||||
|
||||
// Definition parts
|
||||
|
||||
|
|
@ -86,6 +83,7 @@ const std::string LoopControlExpression = "loop_control_expression";
|
|||
|
||||
// Name
|
||||
|
||||
const std::string PartitionName = "partition_name";
|
||||
const std::string NameExpression = "name_expression";
|
||||
const std::string TupleName = "tuple_name";
|
||||
const std::string VariantName = "variant_name";
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include <ostream>
|
||||
|
||||
// for clangd
|
||||
#include "interpreter_tree.hpp"
|
||||
#include "visitor.hpp"
|
||||
|
||||
namespace interpreter {
|
||||
|
|
@ -18,8 +19,6 @@ private:
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void Visit(PartitionSources* node) override;
|
||||
void Visit(Partition* node) override;
|
||||
void Visit(NamespaceSources* node) override;
|
||||
void Visit(Namespace* node) override;
|
||||
|
||||
|
|
@ -33,6 +32,8 @@ private:
|
|||
void Visit(TypeDefinitionStatement* node) override;
|
||||
void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||
void Visit(TypeclassDefinitionStatement* node) override;
|
||||
void Visit(PartitionStatement* node) override;
|
||||
|
||||
|
||||
// Definition parts
|
||||
|
||||
|
|
@ -81,6 +82,7 @@ private:
|
|||
|
||||
// Name
|
||||
|
||||
void Visit(PartitionName* node) override;
|
||||
void Visit(NameExpression* node) override;
|
||||
void Visit(TupleName* node) override;
|
||||
void Visit(VariantName* node) override;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ private:
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void Visit(PartitionSources* node) override;
|
||||
void Visit(Partition* node) override;
|
||||
void Visit(NamespaceSources* node) override;
|
||||
void Visit(Namespace* node) override;
|
||||
|
||||
|
|
@ -39,6 +37,7 @@ private:
|
|||
void Visit(TypeDefinitionStatement* node) override;
|
||||
void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||
void Visit(TypeclassDefinitionStatement* node) override;
|
||||
void Visit(PartitionStatement* node) override;
|
||||
|
||||
// Definition parts
|
||||
|
||||
|
|
@ -87,6 +86,7 @@ private:
|
|||
|
||||
// Name
|
||||
|
||||
void Visit(PartitionName* node) override;
|
||||
void Visit(NameExpression* node) override;
|
||||
void Visit(TupleName* node) override;
|
||||
void Visit(VariantName* node) override;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ private:
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
void Visit(PartitionSources* node) override;
|
||||
void Visit(Partition* node) override;
|
||||
void Visit(NamespaceSources* node) override;
|
||||
void Visit(Namespace* node) override;
|
||||
|
||||
|
|
@ -36,6 +34,7 @@ private:
|
|||
void Visit(TypeDefinitionStatement* node) override;
|
||||
void Visit(AbstractTypeDefinitionStatement* node) override;
|
||||
void Visit(TypeclassDefinitionStatement* node) override;
|
||||
void Visit(PartitionStatement* node) override;
|
||||
|
||||
// Definition parts
|
||||
|
||||
|
|
@ -84,6 +83,7 @@ private:
|
|||
|
||||
// Name
|
||||
|
||||
void Visit(PartitionName* node) override;
|
||||
void Visit(NameExpression* node) override;
|
||||
void Visit(TupleName* node) override;
|
||||
void Visit(VariantName* node) override;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ enum class AssignmentModifier { Assign = 0, Move = 1 };
|
|||
enum class AliasModifier { Alias = 0, Type = 1, Let = 2 };
|
||||
enum class AbstractTypeModifier { Basic = 0, Abstract = 1 };
|
||||
enum class FunctionTypeModifier { Function = 0, Operator = 1 };
|
||||
enum class PartitionModifier { Exec = 0, Test = 1 };
|
||||
|
||||
enum class ValueType { Const = 0, Var = 1, Tmp = 2 };
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ protected:
|
|||
|
||||
// Namespaces, partitions -----------------
|
||||
|
||||
virtual void Visit(PartitionSources* node);
|
||||
virtual void Visit(Partition* node);
|
||||
virtual void Visit(NamespaceSources* node);
|
||||
virtual void Visit(Namespace* node);
|
||||
|
||||
|
|
@ -35,9 +33,9 @@ protected:
|
|||
virtual void Visit(TypeDefinitionStatement* node);
|
||||
virtual void Visit(AbstractTypeDefinitionStatement* node);
|
||||
virtual void Visit(TypeclassDefinitionStatement* node);
|
||||
virtual void Visit(PartitionStatement* node);
|
||||
|
||||
virtual void Visit(NamespaceStatement& node); // variant
|
||||
virtual void Visit(PartitionStatement& node); // variant
|
||||
virtual void Visit(SourceStatement& node); // variant
|
||||
|
||||
// Definition parts
|
||||
|
|
@ -98,6 +96,7 @@ protected:
|
|||
|
||||
// Name
|
||||
|
||||
virtual void Visit(PartitionName* node);
|
||||
virtual void Visit(NameExpression* node);
|
||||
virtual void Visit(TupleName* node);
|
||||
virtual void Visit(VariantName* node);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue