挺大的改动。增加 as运算符,转换不了抛出 TypeError。import语法更新。修复try一点错误。现在表达式运算返回ExprResult。通过3个宏实现简便错误传播与解包 unwrap

This commit is contained in:
2026-02-04 18:14:30 +08:00
parent 27cf09cad0
commit b98c1b7dd8
26 changed files with 693 additions and 206 deletions

View File

@@ -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>())
{
// 运算符重载