[VER] 0.3.5-alpha
[FEAT] 现在,我们的内置类型 Int, String等也有构造函数了!像是StructType一样调用,Int{10}
[FEAT] List,Map赋值默认为Alias, 现在,通过 List{other}/Map{other} 来创建新的container! 复制出新的容器
[IMPL] Object toString对于 String type 输出进行修改!
[IMPL] ... 还有一些忘记了!
[ALL] Happy new year! And hope Fig-lang become better! Let's build a new world!
This commit is contained in:
@@ -53,7 +53,7 @@ namespace Fig
|
||||
if (numIndex >= list.size())
|
||||
throw RuntimeError(FString(
|
||||
std::format("Index {} out of range {}", numIndex, value->toString().toBasicString())));
|
||||
return list.at(numIndex);
|
||||
return list.at(numIndex).value;
|
||||
}
|
||||
else if (kind == Kind::MapElement) // map
|
||||
{
|
||||
|
||||
@@ -37,9 +37,11 @@ namespace Fig
|
||||
ContextPtr defContext; // 定义时的上下文
|
||||
std::vector<Field> fields;
|
||||
|
||||
bool builtin = false;
|
||||
|
||||
// ===== Constructors =====
|
||||
StructType(TypeInfo _type, ContextPtr _defContext, std::vector<Field> _fields) :
|
||||
type(std::move(_type)), defContext(std::move(_defContext)), fields(std::move(_fields)) {}
|
||||
StructType(TypeInfo _type, ContextPtr _defContext, std::vector<Field> _fields, bool _builtin = false) :
|
||||
type(std::move(_type)), defContext(std::move(_defContext)), fields(std::move(_fields)), builtin(_builtin) {}
|
||||
|
||||
StructType(const StructType &other) = default;
|
||||
StructType(StructType &&) noexcept = default;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Value/Type.hpp"
|
||||
#include <Value/Type.hpp>
|
||||
#include <Value/value.hpp>
|
||||
#include <Context/context.hpp>
|
||||
|
||||
|
||||
@@ -33,15 +33,37 @@ namespace Fig
|
||||
}
|
||||
class Object;
|
||||
using ObjectPtr = std::shared_ptr<Object>;
|
||||
using List = std::vector<ObjectPtr>;
|
||||
|
||||
|
||||
FString prettyType(std::shared_ptr<const Object> obj);
|
||||
|
||||
bool operator==(const Object &, const Object &);
|
||||
|
||||
struct Element
|
||||
{
|
||||
ObjectPtr value;
|
||||
Element(ObjectPtr _value) :
|
||||
value(_value) {}
|
||||
|
||||
bool operator==(const Element &other) const
|
||||
{
|
||||
return *value == *other.value;
|
||||
}
|
||||
|
||||
void deepCopy(const Element &e)
|
||||
{
|
||||
value = std::make_shared<Object>(*e.value);
|
||||
}
|
||||
};
|
||||
using List = std::vector<Element>;
|
||||
|
||||
struct ValueKey
|
||||
{
|
||||
ObjectPtr value;
|
||||
ValueKey(ObjectPtr _value) :
|
||||
value(_value) {}
|
||||
|
||||
void deepCopy(const ValueKey &vk) { value = std::make_shared<Object>(*vk.value); }
|
||||
};
|
||||
|
||||
struct ValueKeyHash
|
||||
@@ -180,7 +202,7 @@ namespace Fig
|
||||
const List &list = as<List>();
|
||||
if (i >= list.size())
|
||||
return Object::getNullInstance();
|
||||
return list[i];
|
||||
return list[i].value;
|
||||
}},
|
||||
{u8"push", [this](std::vector<ObjectPtr> args) -> ObjectPtr {
|
||||
if (args.size() != 1)
|
||||
@@ -407,7 +429,7 @@ namespace Fig
|
||||
if (is<ValueType::NullClass>()) return FString(u8"null");
|
||||
if (is<ValueType::IntClass>()) return FString(std::to_string(as<ValueType::IntClass>()));
|
||||
if (is<ValueType::DoubleClass>()) return FString(std::format("{}", as<ValueType::DoubleClass>()));
|
||||
if (is<ValueType::StringClass>()) return FString(u8"<String \"") + as<ValueType::StringClass>() + FString(u8"\" >");
|
||||
if (is<ValueType::StringClass>()) return FString(u8"\"" + as<ValueType::StringClass>() + u8"\"");
|
||||
if (is<ValueType::BoolClass>()) return as<ValueType::BoolClass>() ? FString(u8"true") : FString(u8"false");
|
||||
if (is<Function>())
|
||||
return FString(std::format("<Function '{}' at {:p}>",
|
||||
@@ -430,7 +452,7 @@ namespace Fig
|
||||
{
|
||||
if (!first_flag)
|
||||
output += u8", ";
|
||||
output += ele->toString();
|
||||
output += ele.value->toString();
|
||||
first_flag = false;
|
||||
}
|
||||
output += u8"]";
|
||||
|
||||
Reference in New Issue
Block a user