Add an io_writer var to gif's decoder.decode_id

This commit is contained in:
Nigel Tao committed 2018-05-13 10:40:44 +10:00
1 parent 0f32650064
commit 2d3b3b1dae
7 files changed
+47 -15

No files matched your search

+21 -5
View File
@@ -165,10 +165,16 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
b.writes("{\n")
for i := 0; i < len(inFields); i++ {
e := inFields[i].Expr()
prefix := vPrefix
if e.Operator() != 0 {
prefix = aPrefix
}
name := e.Ident().Str(g.tm)
// TODO: stash the whole io_reader, not just its bounds.
for j := 0; j < 2; j++ {
// TODO: insert the prefix in %d_%s.
b.printf("uint8_t* %s%d_bounds%d_%s = %s%s.private_impl.bounds[%d];\n",
oPrefix, ioBindNum, j, name, aPrefix, name, j)
oPrefix, ioBindNum, j, name, prefix, name, j)
}
}
@@ -180,10 +186,14 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
for i := len(inFields) - 1; i >= 0; i-- {
e := inFields[i].Expr()
prefix := vPrefix
if e.Operator() != 0 {
prefix = aPrefix
}
name := e.Ident().Str(g.tm)
for j := 1; j >= 0; j-- {
b.printf("%s%s.private_impl.bounds[%d] = %s%d_bounds%d_%s;\n",
aPrefix, name, j, oPrefix, ioBindNum, j, name)
prefix, name, j, oPrefix, ioBindNum, j, name)
}
}
b.writes("}\n")
@@ -352,10 +362,10 @@ func (g *gen) writeStatementVar(b *buffer, n *a.Var, depth uint32) error {
return err
}
}
if n.XType().IsArrayType() {
if nTyp := n.XType(); nTyp.IsArrayType() {
if n.Value() != nil {
// TODO: something like:
// cv := n.XType().ArrayLength().ConstValue()
// cv := nTyp.ArrayLength().ConstValue()
// // TODO: check that cv is within size_t's range.
// g.printf("{ size_t i; for (i = 0; i < %d; i++) { %s%s[i] = $DEFAULT_VALUE; }}\n",
// cv, vPrefix, n.Name().Str(g.tm))
@@ -371,9 +381,15 @@ func (g *gen) writeStatementVar(b *buffer, n *a.Var, depth uint32) error {
if err := g.writeExpr(b, v, replaceCallSuspendibles, parenthesesMandatory, 0); err != nil {
return err
}
} else if n.XType().IsSliceType() {
} else if nTyp.IsSliceType() {
// TODO: don't assume that the slice is a slice of base.u8.
b.printf("((wuffs_base__slice_u8){})")
} else if nTyp.IsIOType() {
s := "reader"
if nTyp.QID()[1] == t.IDIOWriter {
s = "writer"
}
b.printf("((wuffs_base__io_%s){})", s)
} else {
b.writeb('0')
}
+2
View File
@@ -282,11 +282,13 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool, initBoolTyp
local := fmt.Sprintf("%s%s", vPrefix, n.Name().Str(g.tm))
if typ := n.XType(); typ.HasPointers() {
// TODO: drop the initBoolTypedVars.
if suspend || initBoolTypedVars {
return nil
}
rhs := ""
// TODO: move this initialization to writeVars?
switch typ.Decorator() {
case 0:
if qid := typ.QID(); qid[0] == t.IDBase {
+7
View File
@@ -2659,6 +2659,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id(
uint32_t v_i;
uint8_t v_lw;
uint64_t v_block_size;
wuffs_base__io_writer v_w;
wuffs_gif__status v_z;
uint8_t* b_rptr_src = NULL;
@@ -2682,6 +2683,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id(
v_i = self->private_impl.c_decode_id[0].v_i;
v_lw = self->private_impl.c_decode_id[0].v_lw;
v_block_size = self->private_impl.c_decode_id[0].v_block_size;
v_w = ((wuffs_base__io_writer){});
v_z = self->private_impl.c_decode_id[0].v_z;
} else {
}
@@ -2874,9 +2876,12 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id(
}
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
while (true) {
v_w = ((wuffs_base__io_writer){});
{
uint8_t* o_0_bounds0_src = a_src.private_impl.bounds[0];
uint8_t* o_0_bounds1_src = a_src.private_impl.bounds[1];
uint8_t* o_0_bounds0_w = v_w.private_impl.bounds[0];
uint8_t* o_0_bounds1_w = v_w.private_impl.bounds[1];
wuffs_base__io_reader__set_limit(&a_src, b_rptr_src, v_block_size);
wuffs_base__io_reader__set_mark(&a_src, b_rptr_src);
{
@@ -2900,6 +2905,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id(
a_src.private_impl.bounds[0]),
})
.len)));
v_w.private_impl.bounds[1] = o_0_bounds1_w;
v_w.private_impl.bounds[0] = o_0_bounds0_w;
a_src.private_impl.bounds[1] = o_0_bounds1_src;
a_src.private_impl.bounds[0] = o_0_bounds0_src;
}
+6
View File
@@ -495,6 +495,8 @@ func NewField(name t.ID, xType *TypeExpr, defaultValue *Expr) *Field {
// IOBind is "io_bind (in_fields) { List2 }":
// - List0: <Expr> in.something fields
// - List2: <Statement> body
//
// TODO: in_fields and "in.something" isn't right.
type IOBind Node
func (n *IOBind) Node() *Node { return (*Node)(n) }
@@ -705,6 +707,10 @@ func (n *TypeExpr) IsIdeal() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDDoubleZ
}
func (n *TypeExpr) IsIOType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && (n.id2 == t.IDIOReader || n.id2 == t.IDIOWriter)
}
func (n *TypeExpr) IsNumType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsNumType()
}
+2 -8
View File
@@ -123,15 +123,9 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if err := q.tcheckExpr(o.Expr(), 0); err != nil {
return err
}
isIOType := false
if typ := o.Expr().MType(); typ.Decorator() == 0 {
if qid := typ.QID(); qid[0] == t.IDBase && (qid[1] == t.IDIOReader || qid[1] == t.IDIOWriter) {
isIOType = true
}
}
if !isIOType {
if typ := o.Expr().MType(); !typ.IsIOType() {
return fmt.Errorf("check: io_bind expression %q, of type %q, does not have an I/O type",
o.Expr().Str(q.tm), o.Expr().MType().Str(q.tm))
o.Expr().Str(q.tm), typ.Str(q.tm))
}
}
for _, o := range n.Body() {
+4 -1
View File
@@ -845,7 +845,10 @@ func (p *parser) parseIOBindExprNode() (*a.Node, error) {
if err != nil {
return nil, err
}
if e.Operator() == t.IDDot {
switch e.Operator() {
case 0:
return e.Node(), nil
case t.IDDot:
if lhs := e.LHS().Expr(); lhs.Operator() == 0 && lhs.Ident() == t.IDIn {
return e.Node(), nil
}
+5 -1
View File
@@ -279,6 +279,8 @@ pri func decoder.decode_ae?(src base.io_reader)() {
// been read.
//
// See the spec section 20 "Image Descriptor" on page 11.
//
// TODO: dst should be a ptr base.image_buffer, not a base.io_writer.
pri func decoder.decode_id?(dst base.io_writer, src base.io_reader)() {
// TODO: check that the frame rect is inside the image rect??
this.frame_left = in.src.read_u16le?() as base.u32
@@ -338,7 +340,8 @@ pri func decoder.decode_id?(dst base.io_writer, src base.io_reader)() {
this.previous_lzw_decode_ended_abruptly = true
while true {
io_bind (in.src) {
var w base.io_writer
io_bind (in.src, w) {
// TODO: enforce that calling r.set_limit has a precondition
// that r.is_bound(), and that you can't suspend inside an
// io_bind? Otherwise, the cgen implementation becomes more
@@ -347,6 +350,7 @@ pri func decoder.decode_id?(dst base.io_writer, src base.io_reader)() {
// Should calling r.set_mark also require r.is_bound()?
in.src.set_limit!(l:block_size)
in.src.set_mark!()
// TODO: in.dst should be w.
var z base.status = try this.lzw.decode?(dst:in.dst, src:in.src)
block_size ~sat-= in.src.since_mark().length()
}