Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
ajreynol committed Oct 1, 2024
1 parent 510ad6b commit dca0971
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 25 deletions.
19 changes: 15 additions & 4 deletions src/attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,34 @@ std::ostream& operator<<(std::ostream& o, Attr a)
return o;
}

bool isNAryAttr(Attr a)
bool isNAryNilAttr(Attr a)
{
switch (a)
{
case Attr::LEFT_ASSOC:
case Attr::RIGHT_ASSOC:
case Attr::LEFT_ASSOC_NIL:
case Attr::RIGHT_ASSOC_NIL:
case Attr::LEFT_ASSOC_NIL_COLLAPSE:
case Attr::RIGHT_ASSOC_NIL_COLLAPSE:
return true;
default:
break;
}
return false;
}

bool isNAryAttr(Attr a)
{
switch (a)
{
case Attr::LEFT_ASSOC:
case Attr::RIGHT_ASSOC:
case Attr::CHAINABLE:
case Attr::PAIRWISE:
return true;
default:
break;
}
return false;
return isNAryNilAttr(a);
}

bool isConstructorKindAttr(Attr a)
Expand Down
6 changes: 5 additions & 1 deletion src/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ enum class Attr
};

/**
* Is the Attr indicate that any number of children can be passed to the given
* Does the Attr indicate a nil terminated n-ary kind?
*/
bool isNAryNilAttr(Attr a);
/**
* Does the Attr indicate that any number of children can be passed to the given
* operator?
*/
bool isNAryAttr(Attr a);
Expand Down
2 changes: 2 additions & 0 deletions src/expr_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,8 @@ void ExprParser::parseAttributeList(Kind k, Expr& e, AttrMap& attrs, bool& pushe
break;
case Attr::RIGHT_ASSOC_NIL:
case Attr::LEFT_ASSOC_NIL:
case Attr::RIGHT_ASSOC_NIL_COLLAPSE:
case Attr::LEFT_ASSOC_NIL_COLLAPSE:
case Attr::CHAINABLE:
case Attr::PAIRWISE:
case Attr::BINDER:
Expand Down
2 changes: 1 addition & 1 deletion src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ bool State::getActualPremises(const ExprValue* rule,
// the nil terminator if applied to empty list
AppInfo* aic = getAppInfo(plCons.getValue());
Attr ck = aic->d_attrCons;
if (ck==Attr::RIGHT_ASSOC_NIL || ck==Attr::LEFT_ASSOC_NIL)
if (isNAryNilAttr(ck))
{
ap = aic->d_attrConsTerm;
}
Expand Down
4 changes: 2 additions & 2 deletions src/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,12 +1235,12 @@ Expr TypeChecker::evaluateLiteralOpInternal(
return d_null;
}
Attr ck = ac->d_attrCons;
if (ck!=Attr::RIGHT_ASSOC_NIL && ck!=Attr::LEFT_ASSOC_NIL)
if (!isNAryNilAttr(ck))
{
// not an associative operator
return d_null;
}
bool isLeft = (ck==Attr::LEFT_ASSOC_NIL);
bool isLeft = (ck==Attr::LEFT_ASSOC_NIL || ck==Attr::LEFT_ASSOC_NIL_COLLAPSE);
Trace("type_checker_debug") << "EVALUATE-LIT (list) " << k << " " << isLeft << " " << args << std::endl;
// infer the nil expression, which depends on the type of args[1]
std::vector<Expr> eargs;
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ set(ethos_test_file_list
simple-reference.eo
simple-quant-reference.eo
simple-lra-reference.eo
rare-example-collapse.eo
)

if(ENABLE_ORACLES)
Expand Down
19 changes: 2 additions & 17 deletions tests/rare-example.eo
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,9 @@
:conclusion (= (or xs true ys) true)
)

(program elim_singleton_list_rhs ((T Type) (f (-> T T T)) (t T) (s T :list))
((-> T T T) T) T
(
((elim_singleton_list_rhs f (f t s)) (eo::ite (eo::is_eq s (eo::nil f)) t (f t s)))
((elim_singleton_list_rhs f t) t)
)
)
(program elim_singleton_list_lhs ((T Type) (f (-> T T T)) (t T :list) (s T))
((-> T T T) T) T
(
((elim_singleton_list_lhs f (f t s)) (eo::ite (eo::is_eq t (eo::nil f)) s (f t s)))
((elim_singleton_list_lhs f s) s)
)
)

(declare-rule bool-or-false ((xs Bool :list) (ys Bool :list))
:args (xs ys)
:conclusion (= (or xs false ys) (elim_singleton_list_rhs or (eo::list_concat or xs ys)))
:conclusion (= (or xs false ys) (eo::list_collapse or (or xs ys)))
)

(step @p0 (= (or a b true c) true) :rule bool-or-true :args ((or a b) (or c)))
Expand All @@ -41,7 +26,7 @@

(declare-rule bool-and-true ((xs Bool :list) (ys Bool :list))
:args (xs ys)
:conclusion (= (and xs true ys) (elim_singleton_list_lhs and (eo::list_concat and xs ys)))
:conclusion (= (and xs true ys) (eo::list_collapse and (and xs ys)))
)

(declare-rule bool-and-false ((xs Bool :list) (ys Bool :list))
Expand Down

0 comments on commit dca0971

Please sign in to comment.