From aabb070962546dd83cf2ac5e2c05114835262e96 Mon Sep 17 00:00:00 2001 From: kalashnikovni Date: Wed, 9 Oct 2024 11:13:50 -0300 Subject: [PATCH] Updated eval interface --- eval/defs.cpp | 10 +++---- eval/defs.hpp | 2 +- eval/visitors/eval_expr.cpp | 42 ++++++------------------------ parser/expr.cpp | 4 +-- test/eval/gt_data/interval/SBG.log | 12 ++++----- 5 files changed, 22 insertions(+), 48 deletions(-) diff --git a/eval/defs.cpp b/eval/defs.cpp index c682076..71b58f7 100755 --- a/eval/defs.cpp +++ b/eval/defs.cpp @@ -43,11 +43,11 @@ MaybeVValue VarEnv::operator[](VKey k) const FuncEnv::FuncEnv() {} FuncEnvType FuncEnv::mapping_ = { - {"isEmpty", 0}, {"isMember", 1}, {"minElem", 2}, {"maxElem", 3} - , {"compose", 4}, {"inv", 5}, {"image", 6}, {"preImage", 7}, {"dom", 8} - , {"combine", 9}, {"firstInv", 10}, {"minMap", 11}, {"reduce", 12} - , {"minAdj", 13}, {"mapInf", 14}, {"CC", 15}, {"matching", 16}, {"scc", 17} - , {"sort", 18}, {"matchSCC", 19}, {"matchSCCTS", 20}, {"cut", 21} + {"isEmpty", 0}, {"minElem", 1}, {"maxElem", 2} + , {"compose", 3}, {"inv", 4}, {"image", 5}, {"preImage", 6}, {"dom", 7} + , {"combine", 8}, {"firstInv", 9}, {"minMap", 10}, {"reduce", 11} + , {"minAdj", 12}, {"mapInf", 13}, {"CC", 14}, {"matching", 15}, {"scc", 16} + , {"sort", 17}, {"matchSCC", 18}, {"matchSCCTS", 19}, {"cut", 20} }; MaybeFValue FuncEnv::operator[](FKey k) const diff --git a/eval/defs.hpp b/eval/defs.hpp index b4f7b88..6fecb7a 100755 --- a/eval/defs.hpp +++ b/eval/defs.hpp @@ -121,7 +121,7 @@ struct FuncEnv{ static FuncEnvType mapping_; }; -typedef enum { empty, member, min, max, comp, inv, im, preim, dom, comb +typedef enum { empty, min, max, comp, inv, im, preim, dom, comb , first_inv, min_map, red, min_adj, inf, connected, matching, scc, ts , match_scc, match_scc_ts, cut_set } Func; diff --git a/eval/visitors/eval_expr.cpp b/eval/visitors/eval_expr.cpp index afa1fdf..20503c9 100755 --- a/eval/visitors/eval_expr.cpp +++ b/eval/visitors/eval_expr.cpp @@ -27,15 +27,6 @@ namespace Eval { // Function visitors ----------------------------------------------------------- // ----------------------------------------------------------------------------- -auto member_visitor_ = Util::Overload { - [](Util::NAT a, LIB::Interval b) { return b.isMember(a); }, - [](auto a, auto b) { - Util::ERROR("member_visitor_: wrong arguments ", a, ", ", b - , " for isMember\n"); - return false; - } -}; - auto min_visitor_ = Util::Overload { [](LIB::Interval a) { return Util::MD_NAT(a.begin()); }, [](LIB::MultiDimInter a) { return a.minElem(); }, @@ -407,24 +398,6 @@ ExprBaseType EvalExpression::operator()(AST::Call v) const } break; - case Eval::Func::member: - if (eval_args.size() == 2) { - arity_ok = true; - - NatBaseType x = std::visit(EvalNatBT{}, eval_args[0]); - Util::MD_NAT aux = std::get(x); - if (aux.arity() == 1) { - ContainerBaseType container - = std::visit(EvalContainer{}, eval_args[1]); - bool result = std::visit(member_visitor_, NatBaseType(aux[0]) - , container); - return Util::MD_NAT(result); - } - - return Util::MD_NAT(0); - } - break; - case Eval::Func::min: if (eval_args.size() == 1) { arity_ok = true; @@ -754,8 +727,8 @@ ExprBaseType EvalExpression::operator()(AST::MultiDimInter v) const { SBG::LIB::SetPiece mdi = boost::apply_visitor(EvalMDI(env_), AST::Expr(v)); - Util::ERROR_UNLESS(mdi.arity() == nmbr_dims_ - , "EvalExpr: nmbr_dims_: ", nmbr_dims_, "!= arity(", mdi, ")\n"); + Util::ERROR_UNLESS(mdi.arity() == nmbr_dims_ || mdi.arity() == 0 + , "EvalExpr: nmbr_dims_: ", nmbr_dims_, " != arity(", mdi, ")\n"); return mdi; } @@ -765,8 +738,8 @@ ExprBaseType EvalExpression::operator()(AST::MDInterUnaryOp v) const EvalMDI visit_mdi(env_); LIB::MultiDimInter mdi = boost::apply_visitor(visit_mdi, v.e()); - Util::ERROR_UNLESS(mdi.arity() == nmbr_dims_ - , "EvalExpr: nmbr_dims_: ", nmbr_dims_, "!= arity(", mdi, ")\n"); + Util::ERROR_UNLESS(mdi.arity() == nmbr_dims_ || mdi.arity() == 0 + , "EvalExpr: nmbr_dims_: ", nmbr_dims_, " != arity(", mdi, ")\n"); switch (v.op()) { case AST::ContainerUOp::card: @@ -786,9 +759,10 @@ ExprBaseType EvalExpression::operator()(AST::MDInterBinOp v) const LIB::MultiDimInter l = boost::apply_visitor(visit_mdi, v.left()); LIB::MultiDimInter r = boost::apply_visitor(visit_mdi, v.right()); - Util::ERROR_UNLESS(l.arity() == nmbr_dims_ && r.arity() == nmbr_dims_ - ,"EvalExpr: nmbr_dims_: ", nmbr_dims_ - , " != arity(", l, ") or arity(", r, ")\n"); + Util::ERROR_UNLESS((l.arity() == nmbr_dims_ && r.arity() == nmbr_dims_) + || l.arity() == 0 || r.arity() == 0 + ,"EvalExpr: nmbr_dims_: ", nmbr_dims_, " != arity(", l, ") or arity(", r + , ")\n"); switch (v.op()) { case AST::ContainerOp::cap: diff --git a/parser/expr.cpp b/parser/expr.cpp index 2035195..cf53424 100755 --- a/parser/expr.cpp +++ b/parser/expr.cpp @@ -444,8 +444,8 @@ ExprRule::ExprRule(Iterator &it) : | lexp_expr | arithmetic_expr | set_expr - | interval_expr - | mdi_expr; + | mdi_expr + | interval_expr; expr_list = expr[phx::push_back(qi::_val, qi::_1)] >> *(COMA >> expr)[phx::push_back(qi::_val, qi::_1)]; diff --git a/test/eval/gt_data/interval/SBG.log b/test/eval/gt_data/interval/SBG.log index 2779952..b79ded9 100755 --- a/test/eval/gt_data/interval/SBG.log +++ b/test/eval/gt_data/interval/SBG.log @@ -20,31 +20,31 @@ isEmpty([100:1:5]) --> 1 [1:1:0]/\[100:1:500] - --> [1:0] + --> [100:1:500]/\[1:1:0] - --> [1:0] + --> [1:2:20]/\[4:3:20] --> [7:6:19] [1:2:20]/\[2:2:20] - --> [1:0] + --> [201:2:399]/\[200:4:400] - --> [1:0] + --> [300:1:1000000]/\[300:1:500] --> [300:500] minElem([500:5:499]) - --> 1 + --> minElem([500:5:600]) --> 500 maxElem([500:5:499]) - --> 0 + --> maxElem([500:5:600]) --> 600