mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
Add a zlib decoder to std/flate.
This commit is contained in:
1 parent
2e6b364dcc
commit
b3710e583f
13 files changed
+566
-117
No files matched your search
+12
-1
@@ -643,7 +643,9 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
|
||||
case t.KeyOpenParen:
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||
if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
|
||||
if isInSrc(q.tm, n, t.KeyReadU8, 0) ||
|
||||
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
|
||||
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
|
||||
isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
||||
isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) ||
|
||||
isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) ||
|
||||
@@ -891,6 +893,15 @@ func (q *checker) bcheckExprBinaryOp1(op t.Key, lhs *a.Expr, lMin *big.Int, lMax
|
||||
case t.KeyXBinaryHat:
|
||||
// TODO.
|
||||
|
||||
case t.KeyXBinaryPercent:
|
||||
if lMin.Cmp(zero) < 0 {
|
||||
return nil, nil, fmt.Errorf("check: modulus op argument %q is possibly negative", lhs.String(q.tm))
|
||||
}
|
||||
if rMin.Cmp(zero) <= 0 {
|
||||
return nil, nil, fmt.Errorf("check: modulus op argument %q is possibly non-positive", rhs.String(q.tm))
|
||||
}
|
||||
return zero, big.NewInt(0).Sub(rMax, one), nil
|
||||
|
||||
case t.KeyXBinaryNotEq, t.KeyXBinaryLessThan, t.KeyXBinaryLessEq, t.KeyXBinaryEqEq,
|
||||
t.KeyXBinaryGreaterEq, t.KeyXBinaryGreaterThan, t.KeyXBinaryAnd, t.KeyXBinaryOr:
|
||||
return zero, one, nil
|
||||
|
||||
@@ -63,6 +63,7 @@ var (
|
||||
|
||||
// TODO: delete this.
|
||||
typeExprPlaceholder = a.NewTypeExpr(0, t.IDU8, nil, nil, nil)
|
||||
typeExprPlaceholder16 = a.NewTypeExpr(0, t.IDU16, nil, nil, nil)
|
||||
typeExprPlaceholder32 = a.NewTypeExpr(0, t.IDU32, nil, nil, nil)
|
||||
)
|
||||
|
||||
|
||||
+11
-2
@@ -343,7 +343,9 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
case t.KeyOpenParen:
|
||||
// n is a function call.
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||
if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
|
||||
if isInSrc(q.tm, n, t.KeyReadU8, 0) ||
|
||||
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
|
||||
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
|
||||
isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
||||
isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) ||
|
||||
isInDst(q.tm, n, t.KeyCopyFrom32, 2) || isInDst(q.tm, n, t.KeyCopyHistory32, 2) ||
|
||||
@@ -361,8 +363,10 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if isInSrc(q.tm, n, t.KeyReadU32LE, 0) {
|
||||
if isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) {
|
||||
n.SetMType(typeExprPlaceholder32) // HACK.
|
||||
} else if isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU16LE, 0) {
|
||||
n.SetMType(typeExprPlaceholder16) // HACK.
|
||||
} else {
|
||||
n.SetMType(typeExprPlaceholder) // HACK.
|
||||
}
|
||||
@@ -774,6 +778,11 @@ func evalConstValueBinaryOp(tm *t.Map, n *a.Expr, l *big.Int, r *big.Int) (*big.
|
||||
return big.NewInt(0).Or(l, r), nil
|
||||
case t.KeyXBinaryHat:
|
||||
return big.NewInt(0).Xor(l, r), nil
|
||||
case t.KeyXBinaryPercent:
|
||||
if r.Cmp(zero) == 0 {
|
||||
return nil, fmt.Errorf("check: division by zero in const expression %q", n.String(tm))
|
||||
}
|
||||
return big.NewInt(0).Mod(l, r), nil
|
||||
case t.KeyXBinaryNotEq:
|
||||
return btoi(l.Cmp(r) != 0), nil
|
||||
case t.KeyXBinaryLessThan:
|
||||
|
||||
Reference in new issue
Block a user