mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
Rename unread_u8? to undo_byte!; add can_undo_byte
This commit is contained in:
1 parent
ce3d99a6d5
commit
9e300fc4f8
14 files changed
+148
-154
No files matched your search
@@ -24,7 +24,6 @@ package check
|
||||
// code but never actually suspend.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
a "github.com/google/wuffs/lang/ast"
|
||||
@@ -175,46 +174,6 @@ check2:
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *checker) optimizeSuspendible(n *a.Expr, depth uint32) error {
|
||||
if depth > a.MaxExprDepth {
|
||||
return fmt.Errorf("check: expression recursion depth too large")
|
||||
}
|
||||
depth++
|
||||
|
||||
if !n.CallSuspendible() {
|
||||
for _, o := range n.AsNode().AsRaw().SubNodes() {
|
||||
if o != nil && o.Kind() == a.KExpr {
|
||||
if err := q.optimizeSuspendible(o.AsExpr(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
if o != nil && o.Kind() == a.KExpr {
|
||||
if err := q.optimizeSuspendible(o.AsExpr(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
nReceiver, nMethod, _ := splitReceiverMethodArgs(n)
|
||||
if nReceiver == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: check that nReceiver's type is actually a io_reader or io_writer.
|
||||
|
||||
if nMethod == t.IDUnreadU8 {
|
||||
// unread_u8 can never suspend, only succeed or fail.
|
||||
n.SetProvenNotToSuspend()
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, update bool) (retOK bool, retErr error) {
|
||||
// TODO: do two passes? The first one to non-destructively check retOK. The
|
||||
// second one to drop facts if indeed retOK? Otherwise, an advance
|
||||
|
||||
Reference in new issue
Block a user