挺大的改动。增加 as运算符,转换不了抛出 TypeError。import语法更新。修复try一点错误。现在表达式运算返回ExprResult。通过3个宏实现简便错误传播与解包 unwrap
This commit is contained in:
@@ -2,17 +2,18 @@
|
||||
#include <Evaluator/Value/LvObject.hpp>
|
||||
#include <Evaluator/evaluator.hpp>
|
||||
#include <Evaluator/evaluator_error.hpp>
|
||||
#include <Evaluator/Core/ExprResult.hpp>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
RvObject Evaluator::evalUnary(Ast::UnaryExpr un, ContextPtr ctx)
|
||||
ExprResult Evaluator::evalUnary(Ast::UnaryExpr un, ContextPtr ctx)
|
||||
{
|
||||
using Ast::Operator;
|
||||
Operator op = un->op;
|
||||
Ast::Expression exp = un->exp;
|
||||
ObjectPtr value = eval(exp, ctx);
|
||||
ObjectPtr value = check_unwrap(eval(exp, ctx));
|
||||
|
||||
const auto &tryInvokeOverloadFn = [ctx, op](const ObjectPtr &rhs, const std::function<ObjectPtr()> &rollback) {
|
||||
const auto &tryInvokeOverloadFn = [ctx, op](const ObjectPtr &rhs, const std::function<ExprResult()> &rollback) {
|
||||
if (rhs->is<StructInstance>())
|
||||
{
|
||||
// 运算符重载
|
||||
|
||||
Reference in New Issue
Block a user