Add a status.is_suspension method.

This commit is contained in:
Nigel Tao committed 2017-09-02 09:40:39 +10:00
1 parent 935cd73686
commit 0f86add17e
7 files changed
+68 -4

No files matched your search

+4
View File
@@ -687,6 +687,10 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
}
return zero, bitMask(int(aMax.Int64())), nil
}
// TODO: delete this hack that only matches "foo.is_suspension(etc)".
if isIsErrorOKSuspension(q.tm, n, t.KeyIsSuspension) {
return nil, nil, nil
}
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
if isSetLiteralWidth(q.tm, n) {
a := n.Args()[0].Arg().Value()
+24
View File
@@ -391,6 +391,22 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
n.SetMType(foo.MType().Unrefined())
return nil
}
// TODO: delete this hack that only matches "foo.is_suspension(etc)".
if isIsErrorOKSuspension(q.tm, n, t.KeyIsSuspension) {
foo := n.LHS().Expr().LHS().Expr()
if err := q.tcheckExpr(foo, depth); err != nil {
return err
}
n.LHS().SetTypeChecked()
n.LHS().Expr().SetMType(typeExprPlaceholder) // HACK.
for _, o := range n.Args() {
if err := q.tcheckArg(o.Arg(), depth); err != nil {
return err
}
}
n.SetMType(typeExprBool)
return nil
}
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
if isSetLiteralWidth(q.tm, n) {
foo := n.LHS().Expr().LHS().Expr()
@@ -553,6 +569,14 @@ func isLowHighBits(tm *t.Map, n *a.Expr, methodName t.Key) bool {
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == methodName
}
func isIsErrorOKSuspension(tm *t.Map, n *a.Expr, methodName t.Key) bool {
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 0 {
return false
}
n = n.LHS().Expr()
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == methodName
}
func isSetLiteralWidth(tm *t.Map, n *a.Expr) bool {
// TODO: check that n.Args() is "(lw:bar)".
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {