From 8d1bf15d707bdfe0b749e83353ab6627d017615f Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 18 Jun 2017 09:45:09 +1000 Subject: [PATCH] Add a decoder.decode_lsd skeleton. --- cmd/puffs-gen-c/main.go | 11 ++++++++--- gen/c/std/gif.c | 14 ++++++++++++++ lang/check/bounds.go | 2 +- lang/check/type.go | 6 +++--- std/gif/decode_gif.puffs | 9 +++++++++ 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/cmd/puffs-gen-c/main.go b/cmd/puffs-gen-c/main.go index 7d4329d6..ba6860b6 100644 --- a/cmd/puffs-gen-c/main.go +++ b/cmd/puffs-gen-c/main.go @@ -1020,11 +1020,16 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error { } g.writes(";\n") - } else if isThisDecodeHeader(g.tm, n) { + } else if isThisMethod(g.tm, n, "decode_header") { g.printf("status = puffs_%s_%s_decode_header(self, %ssrc);\n", g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix) g.writes("if (status) { goto cleanup0; }\n") + } else if isThisMethod(g.tm, n, "decode_lsd") { + g.printf("status = puffs_%s_%s_decode_lsd(self, %ssrc);\n", + g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix) + g.writes("if (status) { goto cleanup0; }\n") + } else { // TODO: fix this. // @@ -1190,13 +1195,13 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool { return n.ID0() == 0 && n.ID1().Key() == t.KeyIn } -func isThisDecodeHeader(tm *t.Map, n *a.Expr) bool { +func isThisMethod(tm *t.Map, n *a.Expr, methodName string) bool { // TODO: check that n.Args() is "(src:in.src)". if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 { return false } n = n.LHS().Expr() - if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName("decode_header") { + if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName(methodName) { return false } n = n.LHS().Expr() diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index b234c452..da74f0e5 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -208,6 +208,9 @@ const char* puffs_gif_status_string(puffs_gif_status s) { puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self, puffs_base_buf1* a_src); +puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self, + puffs_base_buf1* a_src); + // ---------------- Constructor and Destructor Implementations // PUFFS_MAGIC is a magic number to check that constructors are called. It's @@ -297,6 +300,10 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self, if (status) { goto cleanup0; } + status = puffs_gif_decoder_decode_lsd(self, a_src); + if (status) { + goto cleanup0; + } cleanup0: self->private_impl.status = status; @@ -332,6 +339,13 @@ puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self, return status; } +puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self, + puffs_base_buf1* a_src) { + puffs_gif_status status = self->private_impl.status; + + return status; +} + void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self, uint32_t a_lw) { if (!self) { diff --git a/lang/check/bounds.go b/lang/check/bounds.go index b852ead9..71cc9b47 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -600,7 +600,7 @@ 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 isInSrcReadU8(q.tm, n) || isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) || - isThisDecodeHeader(q.tm, n) { + isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") { for _, o := range n.Args() { // TODO: check that the arg range at the caller and the diff --git a/lang/check/type.go b/lang/check/type.go index 0da52900..9d79539b 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -328,7 +328,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { // n is a function call. // TODO: delete this hack that only matches "in.src.read_u8?()" etc. if isInSrcReadU8(q.tm, n) || isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) || - isThisDecodeHeader(q.tm, n) { + isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") { if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil { return err @@ -424,13 +424,13 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool { return n.ID0() == 0 && n.ID1().Key() == t.KeyIn } -func isThisDecodeHeader(tm *t.Map, n *a.Expr) bool { +func isThisMethod(tm *t.Map, n *a.Expr, methodName string) bool { // TODO: check that n.Args() is "(src:in.src)". if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 { return false } n = n.LHS().Expr() - if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName("decode_header") { + if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName(methodName) { return false } n = n.LHS().Expr() diff --git a/std/gif/decode_gif.puffs b/std/gif/decode_gif.puffs index d0db35a0..27933537 100644 --- a/std/gif/decode_gif.puffs +++ b/std/gif/decode_gif.puffs @@ -11,9 +11,12 @@ pub struct decoder?( pub func decoder.decode?(dst ptr buf1, src ptr buf1)() { this.decode_header?(src:in.src) + this.decode_lsd?(src:in.src) } // decode_header reads either "GIF87a" or "GIF89a". +// +// See the spec section 17 "Header" on page 7. pri func decoder.decode_header?(src ptr buf1)() { var c[6] u8 var i u8 @@ -26,3 +29,9 @@ pri func decoder.decode_header?(src ptr buf1)() { return error "bad GIF header" } } + +// decode_lsd reads the Logical Screen Descriptor. +// +// See the spec section 18 "Logical Screen Descriptor" on page 8. +pri func decoder.decode_lsd?(src ptr buf1)() { +}