调整了项目文件夹层次,evaluator.cpp拆分
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "Value/value.hpp"
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Value/value_forward.hpp>
|
||||
#include <Value/Type.hpp>
|
||||
#include <Evaluator/Value/value_forward.hpp>
|
||||
#include <Evaluator/Value/Type.hpp>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Value/VariableSlot.hpp>
|
||||
#include <Value/value.hpp>
|
||||
#include <Evaluator/Value/VariableSlot.hpp>
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
|
||||
@@ -14,44 +14,32 @@ namespace Fig
|
||||
private:
|
||||
size_t id;
|
||||
|
||||
std::map<FString, size_t> &getTypeMap()
|
||||
{
|
||||
static std::map<FString, size_t> typeMap;
|
||||
return typeMap;
|
||||
}
|
||||
|
||||
public:
|
||||
friend class TypeInfoHash;
|
||||
|
||||
FString name;
|
||||
|
||||
FString toString() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
FString toString() const { return name; }
|
||||
|
||||
static std::map<FString, size_t> typeMap;
|
||||
|
||||
static size_t getID(FString _name)
|
||||
{
|
||||
return typeMap.at(_name);
|
||||
}
|
||||
size_t getInstanceID() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
size_t getInstanceID() const { return id; }
|
||||
|
||||
TypeInfo();
|
||||
explicit TypeInfo(const FString &_name, bool reg = false);
|
||||
TypeInfo(const TypeInfo &other) = default;
|
||||
|
||||
bool operator==(const TypeInfo &other) const
|
||||
{
|
||||
return id == other.id;
|
||||
}
|
||||
bool operator==(const TypeInfo &other) const { return id == other.id; }
|
||||
};
|
||||
|
||||
|
||||
class TypeInfoHash
|
||||
{
|
||||
public:
|
||||
std::size_t operator()(const TypeInfo &ti) const
|
||||
{
|
||||
return std::hash<size_t>{}(ti.id);
|
||||
}
|
||||
std::size_t operator()(const TypeInfo &ti) const { return std::hash<size_t>{}(ti.id); }
|
||||
};
|
||||
|
||||
// class Value;
|
||||
@@ -77,39 +65,31 @@ namespace Fig
|
||||
using NullClass = std::monostate;
|
||||
using StringClass = FString;
|
||||
|
||||
static const std::unordered_set<TypeInfo, TypeInfoHash> builtinTypes
|
||||
{
|
||||
Any,
|
||||
Null,
|
||||
Int,
|
||||
String,
|
||||
Bool,
|
||||
Double,
|
||||
Function,
|
||||
StructType,
|
||||
StructInstance,
|
||||
List,
|
||||
Map,
|
||||
Module,
|
||||
InterfaceType
|
||||
};
|
||||
|
||||
inline bool isTypeBuiltin(const TypeInfo &type)
|
||||
{
|
||||
static const std::unordered_set<TypeInfo, TypeInfoHash> builtinTypes{Any,
|
||||
Null,
|
||||
Int,
|
||||
String,
|
||||
Bool,
|
||||
Double,
|
||||
Function,
|
||||
StructType,
|
||||
StructInstance,
|
||||
List,
|
||||
Map,
|
||||
Module,
|
||||
InterfaceType};
|
||||
return builtinTypes.contains(type);
|
||||
}
|
||||
}; // namespace ValueType
|
||||
}; // namespace Fig
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<Fig::TypeInfo>
|
||||
{
|
||||
size_t operator()(const Fig::TypeInfo &t)
|
||||
{
|
||||
return std::hash<size_t>{}(t.getInstanceID());
|
||||
}
|
||||
size_t operator()(const Fig::TypeInfo &t) { return std::hash<size_t>{}(t.getInstanceID()); }
|
||||
};
|
||||
};
|
||||
}; // namespace std
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <Ast/AccessModifier.hpp>
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Value/Type.hpp>
|
||||
#include <Value/value_forward.hpp>
|
||||
#include <Evaluator/Value/Type.hpp>
|
||||
#include <Evaluator/Value/value_forward.hpp>
|
||||
|
||||
#include <memory>
|
||||
namespace Fig
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Ast/functionParameters.hpp>
|
||||
#include <Context/context_forward.hpp>
|
||||
#include <Evaluator/Context/context_forward.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Ast/Statements/InterfaceDefSt.hpp>
|
||||
#include <Value/Type.hpp>
|
||||
#include <Evaluator/Value/Type.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <Core/fig_string.hpp>
|
||||
|
||||
#include <Context/context_forward.hpp>
|
||||
#include <Evaluator/Context/context_forward.hpp>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Context/context_forward.hpp>
|
||||
#include <Value/Type.hpp>
|
||||
#include <Evaluator/Context/context_forward.hpp>
|
||||
#include <Evaluator/Value/Type.hpp>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <Core/fig_string.hpp>
|
||||
#include <Ast/Statements/StructDefSt.hpp>
|
||||
|
||||
#include <Value/Type.hpp>
|
||||
#include <Evaluator/Value/Type.hpp>
|
||||
|
||||
#include <Context/context_forward.hpp>
|
||||
#include <Evaluator/Context/context_forward.hpp>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "Value/structType.hpp"
|
||||
#include <Value/Type.hpp>
|
||||
#include <Value/value.hpp>
|
||||
#include <Context/context.hpp>
|
||||
#include <Evaluator/Value/structType.hpp>
|
||||
#include <Evaluator/Value/value_forward.hpp>
|
||||
#include <Evaluator/Value/Type.hpp>
|
||||
#include <Evaluator/Value/value.hpp>
|
||||
#include <Evaluator/Context/context.hpp>
|
||||
|
||||
// #include <iostream>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
std::map<FString, size_t> TypeInfo::typeMap = {};
|
||||
|
||||
TypeInfo::TypeInfo() : // only allow use in evaluate time !! <---- dynamic type system requirement
|
||||
id(1), name(FString(u8"Any"))
|
||||
@@ -20,17 +20,17 @@ namespace Fig
|
||||
// std::cerr << "TypeInfo constructor called for type name: " << name.toBasicString() << "\n";
|
||||
if (reg)
|
||||
{
|
||||
typeMap[name] = ++id_count;
|
||||
getTypeMap()[name] = ++id_count;
|
||||
id = id_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!typeMap.contains(_name))
|
||||
if (!getTypeMap().contains(_name))
|
||||
{
|
||||
throw RuntimeError(FString(std::format("No type named '{}'", _name.toBasicString())));
|
||||
// *this = ValueType::String;
|
||||
}
|
||||
id = typeMap.at(name); // may throw
|
||||
id = getTypeMap().at(name); // may throw
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
#include <Value/function.hpp>
|
||||
#include <Value/interface.hpp>
|
||||
#include <Value/structType.hpp>
|
||||
#include <Value/structInstance.hpp>
|
||||
#include <Value/Type.hpp>
|
||||
#include <Value/valueError.hpp>
|
||||
#include <Value/module.hpp>
|
||||
#include <Value/value_forward.hpp>
|
||||
#include <Evaluator/Value/function.hpp>
|
||||
#include <Evaluator/Value/interface.hpp>
|
||||
#include <Evaluator/Value/structType.hpp>
|
||||
#include <Evaluator/Value/structInstance.hpp>
|
||||
#include <Evaluator/Value/Type.hpp>
|
||||
#include <Evaluator/Value/valueError.hpp>
|
||||
#include <Evaluator/Value/module.hpp>
|
||||
#include <Evaluator/Value/value_forward.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
Reference in New Issue
Block a user