Add reader1.limitt and writer1.limitt methods.

The "limitt" typo will be renamed to "limit" once we remove the keyword
named "limit".
This commit is contained in:
Nigel Tao committed 2017-10-26 15:06:59 +11:00
1 parent b886e3a1ea
commit a9ba7e85ac
10 files changed
+88 -20

No files matched your search

+18 -4
View File
@@ -274,17 +274,31 @@ static inline uint32_t puffs_base__writer1__copy_from_slice32(
return n;
}
static inline puffs_base__empty_struct puffs_base__reader1__limit(
puffs_base__reader1* r,
uint64_t limit) {
// TODO: implement.
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__reader1__mark(
puffs_base__reader1* r,
uint8_t* m) {
r->private_impl.mark = m;
uint8_t* mark) {
r->private_impl.mark = mark;
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__writer1__limit(
puffs_base__writer1* w,
uint64_t limit) {
// TODO: implement.
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__writer1__mark(
puffs_base__writer1* w,
uint8_t* m) {
w->private_impl.mark = m;
uint8_t* mark) {
w->private_impl.mark = mark;
return ((puffs_base__empty_struct){});
}
+2 -1
View File
@@ -32,7 +32,8 @@ const baseImpl = "" +
"_ij(\n puffs_base__slice_u8 s,\n uint64_t i,\n uint64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base__slice_u8){\n .ptr = s.ptr + i,\n .len = j - i,\n });\n }\n return ((puffs_base__slice_u8){});\n}\n\n// puffs_base__slice_u8__prefix returns up to the first up_to bytes of s.\nstatic inline puffs_base__slice_u8 puffs_base__slice_u8__prefix(\n puffs_base__slice_u8 s,\n uint64_t up_to) {\n if ((uint64_t)(s.len) > up_to) {\n s.len = up_to;\n }\n return s;\n}\n\n// puffs_base__slice_u8__suffix returns up to the last up_to bytes of s.\nstatic inline puffs_base__slice_u8 puffs_base__slice_u8_suffix(\n puffs_base__slice_u8 s,\n uint64_t up_to) {\n if ((uint64_t)(s.len) > up_to) {\n s.ptr += (uint64_t)(s.len) - up_to;\n s.len = up_to;\n }\n return s;\n}\n\n// puffs_base__slice_u8__copy_from_slice calls memmove(dst.ptr, src.ptr,\n// length) where length is the minimum of dst.len and src.len.\n//\n// Passing a puffs_base__slice_u8 with all fields NULL or zero (a v" +
"alid, empty\n// slice) is valid and results in a no-op.\nstatic inline uint64_t puffs_base__slice_u8__copy_from_slice(\n puffs_base__slice_u8 dst,\n puffs_base__slice_u8 src) {\n size_t length = dst.len < src.len ? dst.len : src.len;\n if (length > 0) {\n memmove(dst.ptr, src.ptr, length);\n }\n return length;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_history32(\n uint8_t** ptr_ptr,\n uint8_t* start, // May be NULL, meaning an unmarked writer1.\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n if (!start) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n size_t d = ptr - start;\n if ((d == 0) || (d < (size_t)(distance))) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: is manual unrolling actually helpful?\n for (; n >= 8; n -= 8) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *star" +
"t++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_reader32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n uint8_t** ptr_rptr,\n uint8_t* rend,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = length;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (n > rend - rptr) {\n n = rend - rptr;\n }\n if (n > 0) {\n memmove(wptr, rptr, n);\n *ptr_wptr += n;\n *ptr_rptr += n;\n }\n return n;\n}\n\nstatic inline uint64_t puffs_base__writer1__copy_from_slice(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n puffs_base__slice_u8 src) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_slice32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n " +
" puffs_base__slice_u8 src,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline puffs_base__empty_struct puffs_base__reader1__mark(\n puffs_base__reader1* r,\n uint8_t* m) {\n r->private_impl.mark = m;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__mark(\n puffs_base__writer1* w,\n uint8_t* m) {\n w->private_impl.mark = m;\n return ((puffs_base__empty_struct){});\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" +
" puffs_base__slice_u8 src,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline puffs_base__empty_struct puffs_base__reader1__limit(\n puffs_base__reader1* r,\n uint64_t limit) {\n // TODO: implement.\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__reader1__mark(\n puffs_base__reader1* r,\n uint8_t* mark) {\n r->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__limit(\n puffs_base__writer1* w,\n uint64_t limit) {\n // TODO: implement.\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__mark(\n puffs_base__writer1* w,\n uint8_t* mark) {\n w->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\n#e" +
"ndif // PUFFS_BASE_IMPL_H\n" +
""
type template_args_short_read struct {
+16
View File
@@ -168,6 +168,14 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
b.writes(")")
return nil
}
if isInSrc(g.tm, n, t.KeyLimitt, 1) {
b.printf("puffs_base__reader1__limit(&%ssrc,", aPrefix)
if err := g.writeExpr(b, n.Args()[0].Arg().Value(), rp, parenthesesOptional, depth); err != nil {
return err
}
b.writes(")")
return nil
}
if isInSrc(g.tm, n, t.KeyMark, 0) {
b.printf("puffs_base__reader1__mark(&%ssrc, %srptr_src)", aPrefix, bPrefix)
return nil
@@ -179,6 +187,14 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
aPrefix, aPrefix, bPrefix, aPrefix)
return nil
}
if isInDst(g.tm, n, t.KeyLimitt, 1) {
b.printf("puffs_base__writer1__limit(&%sdst,", aPrefix)
if err := g.writeExpr(b, n.Args()[0].Arg().Value(), rp, parenthesesOptional, depth); err != nil {
return err
}
b.writes(")")
return nil
}
if isInDst(g.tm, n, t.KeyMark, 0) {
// TODO: is a private_impl.mark the right representation? What if
// the function is passed a (ptr writer1) instead of a (writer1)?
+4 -2
View File
@@ -676,7 +676,8 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
callSuspendible := methodName != t.KeySinceMark &&
methodName != t.KeyMark
methodName != t.KeyMark &&
methodName != t.KeyLimitt
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
return false
}
@@ -698,7 +699,8 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
methodName != t.KeyCopyFromSlice32 &&
methodName != t.KeyCopyFromSlice &&
methodName != t.KeySinceMark &&
methodName != t.KeyMark
methodName != t.KeyMark &&
methodName != t.KeyLimitt
// TODO: check that n.Args() is "(x:bar)".
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
return false
+18 -4
View File
@@ -601,17 +601,31 @@ static inline uint32_t puffs_base__writer1__copy_from_slice32(
return n;
}
static inline puffs_base__empty_struct puffs_base__reader1__limit(
puffs_base__reader1* r,
uint64_t limit) {
// TODO: implement.
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__reader1__mark(
puffs_base__reader1* r,
uint8_t* m) {
r->private_impl.mark = m;
uint8_t* mark) {
r->private_impl.mark = mark;
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__writer1__limit(
puffs_base__writer1* w,
uint64_t limit) {
// TODO: implement.
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__writer1__mark(
puffs_base__writer1* w,
uint8_t* m) {
w->private_impl.mark = m;
uint8_t* mark) {
w->private_impl.mark = mark;
return ((puffs_base__empty_struct){});
}
+19 -4
View File
@@ -549,17 +549,31 @@ static inline uint32_t puffs_base__writer1__copy_from_slice32(
return n;
}
static inline puffs_base__empty_struct puffs_base__reader1__limit(
puffs_base__reader1* r,
uint64_t limit) {
// TODO: implement.
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__reader1__mark(
puffs_base__reader1* r,
uint8_t* m) {
r->private_impl.mark = m;
uint8_t* mark) {
r->private_impl.mark = mark;
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__writer1__limit(
puffs_base__writer1* w,
uint64_t limit) {
// TODO: implement.
return ((puffs_base__empty_struct){});
}
static inline puffs_base__empty_struct puffs_base__writer1__mark(
puffs_base__writer1* w,
uint8_t* m) {
w->private_impl.mark = m;
uint8_t* mark) {
w->private_impl.mark = mark;
return ((puffs_base__empty_struct){});
}
@@ -1246,6 +1260,7 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
}
while (true) {
puffs_base__reader1__mark(&a_src, b_rptr_src);
puffs_base__reader1__limit(&a_src, v_block_size);
l_lzw_src = v_block_size;
v_lzw_src = (puffs_base__reader1){.buf = a_src.buf,
.limit = (puffs_base__limit1){
+1 -1
View File
@@ -721,7 +721,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
isInSrc(q.tm, n, t.KeySkip32, 1) || isInSrc(q.tm, n, t.KeySinceMark, 0) ||
isInSrc(q.tm, n, t.KeyMark, 0) ||
isInSrc(q.tm, n, t.KeyMark, 0) || isInSrc(q.tm, n, t.KeyLimitt, 1) ||
isInDst(q.tm, n, t.KeyCopyFromSlice, 1) || isInDst(q.tm, n, t.KeyCopyFromSlice32, 2) ||
isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) ||
isInDst(q.tm, n, t.KeyWriteU8, 1) || isInDst(q.tm, n, t.KeySinceMark, 0) ||
+5 -3
View File
@@ -439,7 +439,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
isInSrc(q.tm, n, t.KeySkip32, 1) || isInSrc(q.tm, n, t.KeySinceMark, 0) ||
isInSrc(q.tm, n, t.KeyMark, 0) ||
isInSrc(q.tm, n, t.KeyMark, 0) || isInSrc(q.tm, n, t.KeyLimitt, 1) ||
isInDst(q.tm, n, t.KeyCopyFromSlice, 1) || isInDst(q.tm, n, t.KeyCopyFromSlice32, 2) ||
isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) ||
isInDst(q.tm, n, t.KeyWriteU8, 1) || isInDst(q.tm, n, t.KeySinceMark, 0) ||
@@ -694,7 +694,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
callSuspendible := methodName != t.KeySinceMark &&
methodName != t.KeyMark
methodName != t.KeyMark &&
methodName != t.KeyLimitt
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
return false
}
@@ -716,7 +717,8 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
methodName != t.KeyCopyFromSlice32 &&
methodName != t.KeyCopyFromSlice &&
methodName != t.KeySinceMark &&
methodName != t.KeyMark
methodName != t.KeyMark &&
methodName != t.KeyLimitt
// TODO: check that n.Args() is "(x:bar)".
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
return false
+4 -1
View File
@@ -237,7 +237,7 @@ const (
KeyPri = Key(IDPri >> KeyShift)
KeyError = Key(IDError >> KeyShift)
KeySuspension = Key(IDSuspension >> KeyShift)
KeyLimit = Key(IDLimit >> KeyShift)
KeyLimit = Key(IDLimit >> KeyShift) // TODO: delete.
KeyPackageID = Key(IDPackageID >> KeyShift)
KeyConst = Key(IDConst >> KeyShift)
KeyTry = Key(IDTry >> KeyShift)
@@ -301,6 +301,7 @@ const (
KeyAvailable = Key(IDAvailable >> KeyShift)
KeyPrefix = Key(IDPrefix >> KeyShift)
KeySuffix = Key(IDSuffix >> KeyShift)
KeyLimitt = Key(IDLimitt >> KeyShift) // TODO: rename Limitt to Limit.
KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift)
KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift)
@@ -488,6 +489,7 @@ const (
IDAvailable = ID(0xCA<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDPrefix = ID(0xCB<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDSuffix = ID(0xCC<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDLimitt = ID(0xCD<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
)
// The IDXFoo IDs are not returned by the tokenizer. They are used by the
@@ -693,6 +695,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
KeyAvailable: {"available", IDAvailable},
KeyPrefix: {"prefix", IDPrefix},
KeySuffix: {"suffix", IDSuffix},
KeyLimitt: {"limitt", IDLimitt},
}
var builtInsByName = map[string]ID{}
+1
View File
@@ -164,6 +164,7 @@ pri func decoder.decode_id?(dst writer1, src reader1)() {
}
while true {
in.src.mark()
in.src.limitt(l:block_size)
// TODO: how should this reader1-typed variable (which is implemented
// by containing pointers) work across resume/suspend? We don't want to
// have a dangling pointer to an earlier src buffer.