forked from PuqiAR/Fig-TreeWalker
挺大的改动。增加 as运算符,转换不了抛出 TypeError。import语法更新。修复try一点错误。现在表达式运算返回ExprResult。通过3个宏实现简便错误传播与解包 unwrap
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <Evaluator/Value/value_forward.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
// #include <iostream>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <variant>
|
||||
@@ -37,6 +37,11 @@ namespace Fig
|
||||
return d > intMaxAsDouble || d < intMinAsDouble;
|
||||
}
|
||||
|
||||
inline bool nearlyEqual(ValueType::DoubleClass l, ValueType::DoubleClass r, ValueType::DoubleClass epsilon = 1e-9)
|
||||
{
|
||||
return std::abs(l - r) < epsilon;
|
||||
}
|
||||
|
||||
TypeInfo actualType(std::shared_ptr<const Object> obj);
|
||||
FString prettyType(std::shared_ptr<const Object> obj);
|
||||
|
||||
@@ -646,7 +651,13 @@ namespace Fig
|
||||
}
|
||||
|
||||
// comparison
|
||||
friend bool operator==(const Object &lhs, const Object &rhs) { return lhs.data == rhs.data; }
|
||||
friend bool operator==(const Object &lhs, const Object &rhs) {
|
||||
if (lhs.isNumeric() && rhs.isNumeric())
|
||||
{
|
||||
return nearlyEqual(lhs.getNumericValue(), rhs.getNumericValue());
|
||||
}
|
||||
return lhs.data == rhs.data;
|
||||
}
|
||||
friend bool operator!=(const Object &lhs, const Object &rhs) { return !(lhs == rhs); }
|
||||
friend bool operator<(const Object &lhs, const Object &rhs)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user