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 {
+9
View File
@@ -266,6 +266,9 @@ const (
KeySkip32 = Key(IDSkip32 >> KeyShift)
KeySkip64 = Key(IDSkip64 >> KeyShift)
KeyCopyHistory32 = Key(IDCopyHistory32 >> KeyShift)
KeyIsError = Key(IDIsError >> KeyShift)
KeyIsOK = Key(IDIsOK >> KeyShift)
KeyIsSuspension = Key(IDIsSuspension >> KeyShift)
KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift)
KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift)
@@ -436,6 +439,9 @@ const (
IDSkip32 = ID(0xC2<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDSkip64 = ID(0xC3<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDCopyHistory32 = ID(0xC4<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDIsError = ID(0xC5<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDIsOK = ID(0xC6<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDIsSuspension = ID(0xC7<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
)
// The IDXFoo IDs are not returned by the tokenizer. They are used by the
@@ -628,6 +634,9 @@ var builtInsByKey = [nBuiltInKeys]struct {
KeySkip32: {"skip32", IDSkip32},
KeySkip64: {"skip64", IDSkip64},
KeyCopyHistory32: {"copy_history32", IDCopyHistory32},
KeyIsError: {"is_error", IDIsError},
KeyIsOK: {"is_ok", IDIsOK},
KeyIsSuspension: {"is_suspension", IDIsSuspension},
}
var builtInsByName = map[string]ID{}