Add a writer1.is_marked method.

This commit is contained in:
Nigel Tao committed 2017-11-09 10:38:24 +11:00
1 parent 545f043d94
commit e2ce9f1b1d
7 files changed
+38 -5

No files matched your search

+11
View File
@@ -185,6 +185,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
aPrefix, aPrefix, bPrefix, aPrefix)
return nil
}
// TODO: reader1.is_marked, not just writer1.is_marked?
if isInDst(g.tm, n, t.KeyLimit, 1) {
return fmt.Errorf(`TODO: cgen an "in.dst.limit" expression`)
}
@@ -203,6 +204,16 @@ 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.KeyIsMarked, 0) {
if pp == parenthesesMandatory {
b.writeb('(')
}
b.printf("%sdst.private_impl.mark != NULL", aPrefix)
if pp == parenthesesMandatory {
b.writeb(')')
}
return nil
}
if isInDst(g.tm, n, t.KeyCopyFromReader32, 2) {
b.printf("puffs_base__writer1__copy_from_reader32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
// TODO: don't assume that the first argument is "in.src".
+1
View File
@@ -785,6 +785,7 @@ 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.KeyIsMarked &&
methodName != t.KeyMark &&
methodName != t.KeyLimit
// TODO: check that n.Args() is "(x:bar)".
+4
View File
@@ -2017,6 +2017,10 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
b_rend_src = b_rptr_src + len;
}
if ((a_dst.private_impl.mark != NULL) != true) {
status = PUFFS_FLATE__ERROR_BAD_ARGUMENT;
goto exit;
}
if ((self->private_impl.f_n_bits >= 8) ||
((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
+1 -1
View File
@@ -750,7 +750,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
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) ||
isInDst(q.tm, n, t.KeyMark, 0) ||
isInDst(q.tm, n, t.KeyMark, 0) || isInDst(q.tm, n, t.KeyIsMarked, 0) ||
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) ||
isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_blocks", 2) ||
+4 -1
View File
@@ -415,7 +415,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
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) ||
isInDst(q.tm, n, t.KeyMark, 0) ||
isInDst(q.tm, n, t.KeyMark, 0) || isInDst(q.tm, n, t.KeyIsMarked, 0) ||
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) ||
isThisMethod(q.tm, n, "decode_uncompressed", 2) || isThisMethod(q.tm, n, "decode_blocks", 2) ||
@@ -446,6 +446,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
} else if isInDst(q.tm, n, t.KeyCopyFromSlice32, 2) || isInDst(q.tm, n, t.KeyCopyFromReader32, 2) ||
isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) {
n.SetMType(typeExprU32) // HACK.
} else if isInDst(q.tm, n, t.KeyIsMarked, 0) {
n.SetMType(typeExprBool) // HACK.
} else {
n.SetMType(typeExprPlaceholder) // HACK.
}
@@ -684,6 +686,7 @@ 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.KeyIsMarked &&
methodName != t.KeyMark &&
methodName != t.KeyLimit
// TODO: check that n.Args() is "(x:bar)".
+3
View File
@@ -303,6 +303,7 @@ const (
KeyLowBits = Key(IDLowBits >> KeyShift)
KeyHighBits = Key(IDHighBits >> KeyShift)
KeyUnreadU8 = Key(IDUnreadU8 >> KeyShift)
KeyIsMarked = Key(IDIsMarked >> KeyShift)
KeyXUnaryPlus = Key(IDXUnaryPlus >> KeyShift)
KeyXUnaryMinus = Key(IDXUnaryMinus >> KeyShift)
@@ -490,6 +491,7 @@ const (
IDLowBits = ID(0xAE<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDHighBits = ID(0xAF<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDUnreadU8 = ID(0xB0<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
IDIsMarked = ID(0xB1<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
)
// The IDXFoo IDs are not returned by the tokenizer. They are used by the
@@ -695,6 +697,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
KeyLowBits: {"low_bits", IDLowBits},
KeyHighBits: {"high_bits", IDHighBits},
KeyUnreadU8: {"unread_u8", IDUnreadU8},
KeyIsMarked: {"is_marked", IDIsMarked},
}
var builtInsByName = map[string]ID{}
+14 -3
View File
@@ -20,6 +20,11 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// decode_huffman_*.puffs files as small as possible, while retaining both
// correctness and performance.
// TODO: make this a func pre-condition.
if in.dst.is_marked() != true { // TODO: if not in.dst.is_marked() {
return error "bad argument"
}
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
return error "internal error: inconsistent n_bits"
}
@@ -59,7 +64,9 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// for each. There are also up to 13 extra bits, or 2 bytes. Thus, each
// code requires up to 2 + 2 + 2 == 6 bytes, and there are two codes (one
// from H-L and one from H-D). Therefore, we check for at least 12 bytes.
while:loop(in.dst.available() >= 258) and (in.src.available() >= 12) {
while:loop(in.dst.available() >= 258) and (in.src.available() >= 12),
inv in.dst.is_marked() == true, // TODO: remove the redundant "== true".
{
// Ensure that we have at least 15 bits of input.
if n_bits < 15 {
assert n_bits >= 0 // TODO: this shouldn't be necessary.
@@ -260,7 +267,9 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// The "while true { etc; break }" is a redundant version of "etc", but
// its presence minimizes the diff between decode_huffman_fast and
// decode_huffman_slow.
while true {
while true,
inv in.dst.is_marked() == true,
{
// Copy from this.history.
if (distance as u64) > in.dst.since_mark().length() {
// Set (hlen, hdist) to be the length-distance pair to copy
@@ -288,7 +297,9 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
// The "while true { etc; break }" is a redundant version of
// "etc", but its presence minimizes the diff between
// decode_huffman_fast and decode_huffman_slow.
while true {
while true,
inv in.dst.is_marked() == true,
{
n_copied = in.dst.copy_from_slice32(s:this.history[hdist:], length:hlen)
if hlen <= n_copied {
break