diff --git a/cmd/puffs-gen-c/main.go b/cmd/puffs-gen-c/main.go index b26f8205..43bb548b 100644 --- a/cmd/puffs-gen-c/main.go +++ b/cmd/puffs-gen-c/main.go @@ -1240,7 +1240,15 @@ func (g *gen) writeExprAs(lhs *a.Expr, rhs *a.TypeExpr, rp replacementPolicy, de } func (g *gen) writeExprAssociativeOp(n *a.Expr, rp replacementPolicy, depth uint32) error { - // TODO. + opName := cOpNames[0xFF&n.ID0().Key()] + for i, o := range n.Args() { + if i != 0 { + g.writes(opName) + } + if err := g.writeExpr(o.Expr(), rp, parenthesesMandatory, depth); err != nil { + return err + } + } return nil } diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 0018e617..884b06e4 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -297,7 +297,19 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self, goto cleanup0; } uint8_t t_1 = a_src->ptr[a_src->ri++]; - if ((t_0 != 71) || (t_1 != 73)) { + if (a_src->ri >= a_src->wi) { + status = a_src->closed ? puffs_gif_error_unexpected_eof + : puffs_gif_status_short_read; + goto cleanup0; + } + uint8_t t_2 = a_src->ptr[a_src->ri++]; + if (a_src->ri >= a_src->wi) { + status = a_src->closed ? puffs_gif_error_unexpected_eof + : puffs_gif_status_short_read; + goto cleanup0; + } + uint8_t t_3 = a_src->ptr[a_src->ri++]; + if ((t_0 != 71) || (t_1 != 73) || (t_2 != 70) || (t_3 != 56)) { status = puffs_gif_error_bad_gif_header; goto cleanup0; } diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 4a0dfc71..84e8aa8f 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -811,6 +811,24 @@ func (q *checker) bcheckExprBinaryOp(lhs *a.Expr, op t.Key, rhs *a.Expr, depth u } func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) { + switch n.ID0().Key() { + // TODO. + case t.KeyXAssociativePlus: + case t.KeyXAssociativeStar: + case t.KeyXAssociativeAmp: + case t.KeyXAssociativePipe: + case t.KeyXAssociativeHat: + + case t.KeyXAssociativeAnd, t.KeyXAssociativeOr: + for _, o := range n.Args() { + o := o.Expr() + if _, _, err := q.bcheckExpr(o, depth); err != nil { + return nil, nil, err + } + } + return zero, one, nil + } + return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprAssociativeOp", n.ID0().Key()) } diff --git a/lang/check/type.go b/lang/check/type.go index 092fc8e3..22e6f3fe 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -657,7 +657,29 @@ func (q *checker) setConstValueBinaryOp(n *a.Expr, l *big.Int, r *big.Int) error } func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error { + switch n.ID0().Key() { // TODO. + case t.KeyXAssociativePlus: + case t.KeyXAssociativeStar: + case t.KeyXAssociativeAmp: + case t.KeyXAssociativePipe: + case t.KeyXAssociativeHat: + + case t.KeyXAssociativeAnd, t.KeyXAssociativeOr: + for _, o := range n.Args() { + o := o.Expr() + if err := q.tcheckExpr(o, depth); err != nil { + return err + } + if !o.MType().IsBool() { + return fmt.Errorf("check: associative %q: %q, of type %q, does not have a boolean type", + n.ID0().AmbiguousForm().String(q.tm), o.String(q.tm), o.MType().String(q.tm)) + } + } + n.SetMType(typeExprBool) + return nil + } + return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprAssociativeOp", n.ID0().Key()) } diff --git a/std/gif/decode_gif.puffs b/std/gif/decode_gif.puffs index 6629dbcf..d162e484 100644 --- a/std/gif/decode_gif.puffs +++ b/std/gif/decode_gif.puffs @@ -8,7 +8,9 @@ pub struct decoder?( ) pub func decoder.decode?(dst ptr buf1, src ptr buf1)() { - if (in.src.read_u8?() != 0x47) or (in.src.read_u8?() != 0x49) { + // Read either "GIF87a" or "GIF89a". + if (in.src.read_u8?() != 0x47) or (in.src.read_u8?() != 0x49) or + (in.src.read_u8?() != 0x46) or (in.src.read_u8?() != 0x38) { return error "bad GIF header" } }