mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Add a reader1.skip32 method.
This commit is contained in:
1 parent
07e96d7055
commit
1a42706bf1
6 files changed
+76
-62
No files matched your search
+38
-7
@@ -956,7 +956,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
// TODO: delete these hacks that only matches "in.src.read_u8?()" etc.
|
// TODO: delete these hacks that only matches "in.src.read_u8?()" etc.
|
||||||
//
|
//
|
||||||
// TODO: check reader1.buf and writer1.buf is non-NULL.
|
// TODO: check reader1.buf and writer1.buf is non-NULL.
|
||||||
if isInSrcReadU8(g.tm, n) {
|
if isInSrc(g.tm, n, t.KeyReadU8, 0) {
|
||||||
if g.perFunc.tempW > maxTemp {
|
if g.perFunc.tempW > maxTemp {
|
||||||
return fmt.Errorf("too many temporary variables required")
|
return fmt.Errorf("too many temporary variables required")
|
||||||
}
|
}
|
||||||
@@ -964,9 +964,9 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
g.perFunc.tempW++
|
g.perFunc.tempW++
|
||||||
|
|
||||||
// TODO: suspend coroutine state.
|
// TODO: suspend coroutine state.
|
||||||
g.printf("if (%ssrc.buf->ri >= %ssrc.buf->wi) { status = "+
|
g.printf("if (%ssrc.buf->ri >= %ssrc.buf->wi) {", aPrefix, aPrefix)
|
||||||
"%ssrc.buf->closed ? puffs_%s_error_unexpected_eof : puffs_%s_status_short_read;",
|
g.printf("status = %ssrc.buf->closed ? puffs_%s_error_unexpected_eof : puffs_%s_status_short_read;",
|
||||||
aPrefix, aPrefix, aPrefix, g.pkgName, g.pkgName)
|
aPrefix, g.pkgName, g.pkgName)
|
||||||
if g.perFunc.public && g.perFunc.suspendible {
|
if g.perFunc.public && g.perFunc.suspendible {
|
||||||
g.writes("goto cleanup0;")
|
g.writes("goto cleanup0;")
|
||||||
} else {
|
} else {
|
||||||
@@ -980,6 +980,37 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
g.printf(" = %ssrc.buf->ptr[%ssrc.buf->ri++];\n", aPrefix, aPrefix)
|
g.printf(" = %ssrc.buf->ptr[%ssrc.buf->ri++];\n", aPrefix, aPrefix)
|
||||||
|
|
||||||
|
} else if isInSrc(g.tm, n, t.KeySkip32, 1) {
|
||||||
|
if g.perFunc.tempW > maxTemp {
|
||||||
|
return fmt.Errorf("too many temporary variables required")
|
||||||
|
}
|
||||||
|
temp := g.perFunc.tempW
|
||||||
|
g.perFunc.tempW++
|
||||||
|
g.perFunc.tempR++
|
||||||
|
|
||||||
|
g.printf("size_t %s%d = ", tPrefix, temp)
|
||||||
|
x := n.Args()[0].Arg().Value()
|
||||||
|
if err := g.writeExpr(x, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
g.writes(";\n")
|
||||||
|
|
||||||
|
g.printf("if (%s%d > %ssrc.buf->wi - %ssrc.buf->ri) {\n", tPrefix, temp, aPrefix, aPrefix)
|
||||||
|
// TODO: save tPrefix+temp as coroutine state, and suspend.
|
||||||
|
g.printf("%s%d -= %ssrc.buf->wi - %ssrc.buf->ri;\n", tPrefix, temp, aPrefix, aPrefix)
|
||||||
|
g.printf("%ssrc.buf->ri = %ssrc.buf->wi;\n", aPrefix, aPrefix)
|
||||||
|
|
||||||
|
g.printf("status = %ssrc.buf->closed ? puffs_%s_error_unexpected_eof : puffs_%s_status_short_read;",
|
||||||
|
aPrefix, g.pkgName, g.pkgName)
|
||||||
|
if g.perFunc.public && g.perFunc.suspendible {
|
||||||
|
g.writes("goto cleanup0;")
|
||||||
|
} else {
|
||||||
|
g.writes("return status;")
|
||||||
|
}
|
||||||
|
|
||||||
|
g.writes("}\n")
|
||||||
|
g.printf("%ssrc.buf->ri += %s%d;\n", aPrefix, tPrefix, temp)
|
||||||
|
|
||||||
} else if isInDst(g.tm, n, t.KeyWrite) {
|
} else if isInDst(g.tm, n, t.KeyWrite) {
|
||||||
// TODO: suspend coroutine state.
|
// TODO: suspend coroutine state.
|
||||||
//
|
//
|
||||||
@@ -1175,12 +1206,12 @@ func (g *gen) writeExprOther(n *a.Expr, rp replacementPolicy, depth uint32) erro
|
|||||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther", n.ID0().Key())
|
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther", n.ID0().Key())
|
||||||
}
|
}
|
||||||
|
|
||||||
func isInSrcReadU8(tm *t.Map, n *a.Expr) bool {
|
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 0 {
|
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != t.KeyReadU8 {
|
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != methodName {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
|
|||||||
+18
-28
@@ -453,9 +453,7 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
|||||||
puffs_gif_status status = self->private_impl.status;
|
puffs_gif_status status = self->private_impl.status;
|
||||||
|
|
||||||
uint8_t v_label;
|
uint8_t v_label;
|
||||||
uint32_t v_block_size;
|
uint8_t v_block_size;
|
||||||
uint32_t v_j;
|
|
||||||
uint8_t v_temp;
|
|
||||||
|
|
||||||
if (a_src.buf->ri >= a_src.buf->wi) {
|
if (a_src.buf->ri >= a_src.buf->wi) {
|
||||||
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
@@ -482,18 +480,15 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
|||||||
if (v_block_size == 0) {
|
if (v_block_size == 0) {
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
}
|
}
|
||||||
v_j = 0;
|
size_t t_2 = ((uint32_t)(v_block_size));
|
||||||
while (v_j < v_block_size) {
|
if (t_2 > a_src.buf->wi - a_src.buf->ri) {
|
||||||
if (a_src.buf->ri >= a_src.buf->wi) {
|
t_2 -= a_src.buf->wi - a_src.buf->ri;
|
||||||
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
a_src.buf->ri = a_src.buf->wi;
|
||||||
: puffs_gif_status_short_read;
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
return status;
|
: puffs_gif_status_short_read;
|
||||||
}
|
return status;
|
||||||
uint8_t t_2 = a_src.buf->ptr[a_src.buf->ri++];
|
|
||||||
v_temp = t_2;
|
|
||||||
v_temp *= 0;
|
|
||||||
v_j += 1;
|
|
||||||
}
|
}
|
||||||
|
a_src.buf->ri += t_2;
|
||||||
}
|
}
|
||||||
label_0_break:;
|
label_0_break:;
|
||||||
|
|
||||||
@@ -508,9 +503,7 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
|||||||
uint32_t v_i;
|
uint32_t v_i;
|
||||||
bool v_interlace;
|
bool v_interlace;
|
||||||
uint8_t v_literal_width;
|
uint8_t v_literal_width;
|
||||||
uint32_t v_block_size;
|
uint8_t v_block_size;
|
||||||
uint32_t v_j;
|
|
||||||
uint8_t v_temp;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < 9; i++) {
|
for (size_t i = 0; i < 9; i++) {
|
||||||
v_c[i] = 0;
|
v_c[i] = 0;
|
||||||
@@ -551,18 +544,15 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
|||||||
if (v_block_size == 0) {
|
if (v_block_size == 0) {
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
}
|
}
|
||||||
v_j = 0;
|
size_t t_3 = ((uint32_t)(v_block_size));
|
||||||
while (v_j < v_block_size) {
|
if (t_3 > a_src.buf->wi - a_src.buf->ri) {
|
||||||
if (a_src.buf->ri >= a_src.buf->wi) {
|
t_3 -= a_src.buf->wi - a_src.buf->ri;
|
||||||
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
a_src.buf->ri = a_src.buf->wi;
|
||||||
: puffs_gif_status_short_read;
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
return status;
|
: puffs_gif_status_short_read;
|
||||||
}
|
return status;
|
||||||
uint8_t t_3 = a_src.buf->ptr[a_src.buf->ri++];
|
|
||||||
v_temp = t_3;
|
|
||||||
v_temp *= 0;
|
|
||||||
v_j += 1;
|
|
||||||
}
|
}
|
||||||
|
a_src.buf->ri += t_3;
|
||||||
}
|
}
|
||||||
label_0_break:;
|
label_0_break:;
|
||||||
|
|
||||||
|
|||||||
@@ -599,7 +599,8 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
|||||||
|
|
||||||
case t.KeyOpenParen:
|
case t.KeyOpenParen:
|
||||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
// 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) ||
|
if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
||||||
|
isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) ||
|
||||||
isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") ||
|
isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") ||
|
||||||
isThisMethod(q.tm, n, "decode_extension") || isThisMethod(q.tm, n, "decode_id") {
|
isThisMethod(q.tm, n, "decode_extension") || isThisMethod(q.tm, n, "decode_id") {
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -327,7 +327,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
case t.KeyOpenParen:
|
case t.KeyOpenParen:
|
||||||
// n is a function call.
|
// n is a function call.
|
||||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
// 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) ||
|
if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
||||||
|
isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) ||
|
||||||
isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") ||
|
isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") ||
|
||||||
isThisMethod(q.tm, n, "decode_extension") || isThisMethod(q.tm, n, "decode_id") {
|
isThisMethod(q.tm, n, "decode_extension") || isThisMethod(q.tm, n, "decode_id") {
|
||||||
|
|
||||||
@@ -392,12 +393,12 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprOther", n.ID0().Key())
|
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprOther", n.ID0().Key())
|
||||||
}
|
}
|
||||||
|
|
||||||
func isInSrcReadU8(tm *t.Map, n *a.Expr) bool {
|
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 0 {
|
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != t.KeyReadU8 {
|
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != methodName {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
|
|||||||
@@ -252,6 +252,9 @@ const (
|
|||||||
KeyWriteU64BE = Key(IDWriteU64BE >> KeyShift)
|
KeyWriteU64BE = Key(IDWriteU64BE >> KeyShift)
|
||||||
KeyWriteU64LE = Key(IDWriteU64LE >> KeyShift)
|
KeyWriteU64LE = Key(IDWriteU64LE >> KeyShift)
|
||||||
|
|
||||||
|
KeySkip32 = Key(IDSkip32 >> KeyShift)
|
||||||
|
KeySkip64 = Key(IDSkip64 >> KeyShift)
|
||||||
|
|
||||||
KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift)
|
KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift)
|
||||||
KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift)
|
KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift)
|
||||||
KeyXUnaryNot = Key(IDXUnaryNot >> KeyShift)
|
KeyXUnaryNot = Key(IDXUnaryNot >> KeyShift)
|
||||||
@@ -405,6 +408,9 @@ const (
|
|||||||
IDWriteU32LE = ID(0xBD<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDWriteU32LE = ID(0xBD<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDWriteU64BE = ID(0xBE<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDWriteU64BE = ID(0xBE<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDWriteU64LE = ID(0xBF<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDWriteU64LE = ID(0xBF<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
|
|
||||||
|
IDSkip32 = ID(0xC0<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
|
IDSkip64 = ID(0xC1<<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
|
||||||
@@ -581,6 +587,9 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
|||||||
KeyWriteU32LE: {"write_u32le", IDWriteU32LE},
|
KeyWriteU32LE: {"write_u32le", IDWriteU32LE},
|
||||||
KeyWriteU64BE: {"write_u64be", IDWriteU64BE},
|
KeyWriteU64BE: {"write_u64be", IDWriteU64BE},
|
||||||
KeyWriteU64LE: {"write_u64le", IDWriteU64LE},
|
KeyWriteU64LE: {"write_u64le", IDWriteU64LE},
|
||||||
|
|
||||||
|
KeySkip32: {"skip32", IDSkip32},
|
||||||
|
KeySkip64: {"skip64", IDSkip64},
|
||||||
}
|
}
|
||||||
|
|
||||||
var builtInsByName = map[string]ID{}
|
var builtInsByName = map[string]ID{}
|
||||||
|
|||||||
@@ -104,20 +104,11 @@ pri func decoder.decode_extension?(src reader1)() {
|
|||||||
|
|
||||||
// Skip the data blocks.
|
// Skip the data blocks.
|
||||||
while true {
|
while true {
|
||||||
var block_size u32[..255] = in.src.read_u8?() as u32
|
var block_size u8 = in.src.read_u8?() as u32
|
||||||
if block_size == 0 {
|
if block_size == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var j u32
|
in.src.skip32?(n:block_size as u32)
|
||||||
while j < block_size {
|
|
||||||
assert j < 255 via "a < b: a < c; c <= b"(c:block_size)
|
|
||||||
// TODO: we shouldn't need a temp variable.
|
|
||||||
//
|
|
||||||
// TODO: have an in.src.skip?(n:block_size) method?
|
|
||||||
var temp u8 = in.src.read_u8?()
|
|
||||||
temp *= 0 // Avoid "unused variable" C compiler warning.
|
|
||||||
j += 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,19 +142,10 @@ pri func decoder.decode_id?(src reader1)() {
|
|||||||
|
|
||||||
// TODO: pass the data blocks' payload to this.lzw.
|
// TODO: pass the data blocks' payload to this.lzw.
|
||||||
while true {
|
while true {
|
||||||
var block_size u32[..255] = in.src.read_u8?() as u32
|
var block_size u8 = in.src.read_u8?() as u32
|
||||||
if block_size == 0 {
|
if block_size == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var j u32
|
in.src.skip32?(n:block_size as u32)
|
||||||
while j < block_size {
|
|
||||||
assert j < 255 via "a < b: a < c; c <= b"(c:block_size)
|
|
||||||
// TODO: we shouldn't need a temp variable.
|
|
||||||
//
|
|
||||||
// TODO: have an in.src.skip?(n:block_size) method?
|
|
||||||
var temp u8 = in.src.read_u8?()
|
|
||||||
temp *= 0 // Avoid "unused variable" C compiler warning.
|
|
||||||
j += 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user