mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Add a status.is_suspension method.
This commit is contained in:
1 parent
935cd73686
commit
0f86add17e
7 files changed
+68
-4
No files matched your search
@@ -673,7 +673,7 @@ func (g *gen) writeCtorImpl(b *buffer, n *a.Struct) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, rp replacementPolicy, depth uint32) error {
|
func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||||
// TODO.
|
// TODO.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1320,11 +1320,11 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthes
|
|||||||
|
|
||||||
switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||||
case 0:
|
case 0:
|
||||||
if err := g.writeExprOther(b, n, rp, depth); err != nil {
|
if err := g.writeExprOther(b, n, rp, pp, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case t.FlagsUnaryOp:
|
case t.FlagsUnaryOp:
|
||||||
if err := g.writeExprUnaryOp(b, n, rp, depth); err != nil {
|
if err := g.writeExprUnaryOp(b, n, rp, pp, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case t.FlagsBinaryOp:
|
case t.FlagsBinaryOp:
|
||||||
@@ -1342,7 +1342,7 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthes
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth uint32) error {
|
func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||||
switch n.ID0().Key() {
|
switch n.ID0().Key() {
|
||||||
case 0:
|
case 0:
|
||||||
if id1 := n.ID1(); id1.Key() == t.KeyThis {
|
if id1 := n.ID1(); id1.Key() == t.KeyThis {
|
||||||
@@ -1394,6 +1394,21 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
|
|||||||
b.writes(")))")
|
b.writes(")))")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if isIsErrorOKSuspension(g.tm, n, t.KeyIsSuspension) {
|
||||||
|
if pp == parenthesesMandatory {
|
||||||
|
b.writeb('(')
|
||||||
|
}
|
||||||
|
x := n.LHS().Expr().LHS().Expr()
|
||||||
|
if err := g.writeExpr(b, x, rp, parenthesesMandatory, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// TODO: write < or == instead of > for KeyIsError or KeyIsOK.
|
||||||
|
b.writes(" > 0")
|
||||||
|
if pp == parenthesesMandatory {
|
||||||
|
b.writeb(')')
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// TODO.
|
// TODO.
|
||||||
|
|
||||||
case t.KeyOpenBracket:
|
case t.KeyOpenBracket:
|
||||||
@@ -1504,6 +1519,14 @@ func isLowHighBits(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
|||||||
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == methodName
|
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 {
|
func isSetLiteralWidth(tm *t.Map, n *a.Expr) bool {
|
||||||
// TODO: check that n.Args() is "(lw:bar)".
|
// TODO: check that n.Args() is "(lw:bar)".
|
||||||
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {
|
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {
|
||||||
|
|||||||
@@ -536,6 +536,8 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
|||||||
puffs_flate_status t_0 =
|
puffs_flate_status t_0 =
|
||||||
puffs_flate_decoder_decode_blocks(self, a_dst, a_src);
|
puffs_flate_decoder_decode_blocks(self, a_dst, a_src);
|
||||||
v_z = t_0;
|
v_z = t_0;
|
||||||
|
if (v_z > 0) {
|
||||||
|
}
|
||||||
status = v_z;
|
status = v_z;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
self->private_impl.c_decode[0].coro_susp_point = 0;
|
self->private_impl.c_decode[0].coro_susp_point = 0;
|
||||||
|
|||||||
@@ -687,6 +687,10 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
|||||||
}
|
}
|
||||||
return zero, bitMask(int(aMax.Int64())), nil
|
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)".
|
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
|
||||||
if isSetLiteralWidth(q.tm, n) {
|
if isSetLiteralWidth(q.tm, n) {
|
||||||
a := n.Args()[0].Arg().Value()
|
a := n.Args()[0].Arg().Value()
|
||||||
|
|||||||
@@ -391,6 +391,22 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
n.SetMType(foo.MType().Unrefined())
|
n.SetMType(foo.MType().Unrefined())
|
||||||
return nil
|
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)".
|
// TODO: delete this hack that only matches "foo.set_literal_width(etc)".
|
||||||
if isSetLiteralWidth(q.tm, n) {
|
if isSetLiteralWidth(q.tm, n) {
|
||||||
foo := n.LHS().Expr().LHS().Expr()
|
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
|
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 {
|
func isSetLiteralWidth(tm *t.Map, n *a.Expr) bool {
|
||||||
// TODO: check that n.Args() is "(lw:bar)".
|
// TODO: check that n.Args() is "(lw:bar)".
|
||||||
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {
|
if n.ID0().Key() != t.KeyOpenParen || n.CallImpure() || len(n.Args()) != 1 {
|
||||||
|
|||||||
@@ -266,6 +266,9 @@ const (
|
|||||||
KeySkip32 = Key(IDSkip32 >> KeyShift)
|
KeySkip32 = Key(IDSkip32 >> KeyShift)
|
||||||
KeySkip64 = Key(IDSkip64 >> KeyShift)
|
KeySkip64 = Key(IDSkip64 >> KeyShift)
|
||||||
KeyCopyHistory32 = Key(IDCopyHistory32 >> KeyShift)
|
KeyCopyHistory32 = Key(IDCopyHistory32 >> KeyShift)
|
||||||
|
KeyIsError = Key(IDIsError >> KeyShift)
|
||||||
|
KeyIsOK = Key(IDIsOK >> KeyShift)
|
||||||
|
KeyIsSuspension = Key(IDIsSuspension >> KeyShift)
|
||||||
|
|
||||||
KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift)
|
KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift)
|
||||||
KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift)
|
KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift)
|
||||||
@@ -436,6 +439,9 @@ const (
|
|||||||
IDSkip32 = ID(0xC2<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDSkip32 = ID(0xC2<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDSkip64 = ID(0xC3<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDSkip64 = ID(0xC3<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDCopyHistory32 = ID(0xC4<<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
|
// 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},
|
KeySkip32: {"skip32", IDSkip32},
|
||||||
KeySkip64: {"skip64", IDSkip64},
|
KeySkip64: {"skip64", IDSkip64},
|
||||||
KeyCopyHistory32: {"copy_history32", IDCopyHistory32},
|
KeyCopyHistory32: {"copy_history32", IDCopyHistory32},
|
||||||
|
KeyIsError: {"is_error", IDIsError},
|
||||||
|
KeyIsOK: {"is_ok", IDIsOK},
|
||||||
|
KeyIsSuspension: {"is_suspension", IDIsSuspension},
|
||||||
}
|
}
|
||||||
|
|
||||||
var builtInsByName = map[string]ID{}
|
var builtInsByName = map[string]ID{}
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ pub struct decoder?(
|
|||||||
pub func decoder.decode?(dst writer1, src reader1)() {
|
pub func decoder.decode?(dst writer1, src reader1)() {
|
||||||
// TODO: copy from dst to history, if we aren't finished.
|
// TODO: copy from dst to history, if we aren't finished.
|
||||||
var z status = try this.decode_blocks?(dst:in.dst, src:in.src)
|
var z status = try this.decode_blocks?(dst:in.dst, src:in.src)
|
||||||
|
if z.is_suspension() {
|
||||||
|
}
|
||||||
return z
|
return z
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user