Add a std/flate decode_blocks method.

This commit is contained in:
Nigel Tao committed 2017-08-31 11:16:23 +10:00
1 parent b328529e00
commit 209178a2c6
6 files changed
+64 -10

No files matched your search

+8
View File
@@ -1089,6 +1089,14 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
}
b.writes("if (status) { goto suspend; }\n")
} else if isThisMethod(g.tm, n, "decode_blocks", 2) {
b.printf("status = %s%s_decode_blocks(self, %sdst, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix, aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
return err
}
b.writes("if (status) { goto suspend; }\n")
} else if isThisMethod(g.tm, n, "decode_uncompressed", 2) {
b.printf("status = %s%s_decode_uncompressed(self, %sdst, %ssrc);\n",
g.pkgPrefix, g.currFunk.astFunc.Receiver().String(g.tm), aPrefix, aPrefix)
+45 -9
View File
@@ -160,11 +160,14 @@ typedef struct {
uint32_t f_n_huffs_bits[2];
uint8_t f_code_lengths[320];
struct {
uint32_t coro_susp_point;
} c_decode[1];
struct {
uint32_t coro_susp_point;
uint32_t v_final;
uint32_t v_type;
} c_decode[1];
} c_decode_blocks[1];
struct {
uint32_t coro_susp_point;
uint32_t v_n;
@@ -413,6 +416,10 @@ static const uint32_t puffs_flate_dcode_magic_numbers[32] = {
// ---------------- Private Function Prototypes
puffs_flate_status puffs_flate_decoder_decode_blocks(puffs_flate_decoder* self,
puffs_base_writer1 a_dst,
puffs_base_reader1 a_src);
puffs_flate_status puffs_flate_decoder_decode_uncompressed(
puffs_flate_decoder* self,
puffs_base_writer1 a_dst,
@@ -514,6 +521,35 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
}
puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
if (coro_susp_point) {
}
switch (coro_susp_point) {
PUFFS_COROUTINE_SUSPENSION_POINT(0);
PUFFS_COROUTINE_SUSPENSION_POINT(1);
status = puffs_flate_decoder_decode_blocks(self, a_dst, a_src);
if (status) {
goto suspend;
}
self->private_impl.c_decode[0].coro_susp_point = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.c_decode[0].coro_susp_point = coro_susp_point;
exit:
self->private_impl.status = status;
return status;
}
puffs_flate_status puffs_flate_decoder_decode_blocks(puffs_flate_decoder* self,
puffs_base_writer1 a_dst,
puffs_base_reader1 a_src) {
puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
uint32_t v_final;
uint32_t v_type;
@@ -531,10 +567,11 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
b_rend_src = b_rptr_src + len;
}
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
uint32_t coro_susp_point =
self->private_impl.c_decode_blocks[0].coro_susp_point;
if (coro_susp_point) {
v_final = self->private_impl.c_decode[0].v_final;
v_type = self->private_impl.c_decode[0].v_type;
v_final = self->private_impl.c_decode_blocks[0].v_final;
v_type = self->private_impl.c_decode_blocks[0].v_type;
}
switch (coro_susp_point) {
PUFFS_COROUTINE_SUSPENSION_POINT(0);
@@ -648,15 +685,15 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
goto suspend;
}
}
self->private_impl.c_decode[0].coro_susp_point = 0;
self->private_impl.c_decode_blocks[0].coro_susp_point = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.c_decode[0].coro_susp_point = coro_susp_point;
self->private_impl.c_decode[0].v_final = v_final;
self->private_impl.c_decode[0].v_type = v_type;
self->private_impl.c_decode_blocks[0].coro_susp_point = coro_susp_point;
self->private_impl.c_decode_blocks[0].v_final = v_final;
self->private_impl.c_decode_blocks[0].v_type = v_type;
exit:
if (a_src.buf) {
@@ -670,7 +707,6 @@ exit:
}
}
self->private_impl.status = status;
return status;
short_read_src:
+4 -1
View File
@@ -160,11 +160,14 @@ typedef struct {
uint32_t f_n_huffs_bits[2];
uint8_t f_code_lengths[320];
struct {
uint32_t coro_susp_point;
} c_decode[1];
struct {
uint32_t coro_susp_point;
uint32_t v_final;
uint32_t v_type;
} c_decode[1];
} c_decode_blocks[1];
struct {
uint32_t coro_susp_point;
uint32_t v_n;
+1
View File
@@ -652,6 +652,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
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_huffman", 2) ||
isThisMethod(q.tm, n, "decode_blocks", 2) ||
isThisMethod(q.tm, n, "init_fixed_huffman", 0) || isThisMethod(q.tm, n, "init_dynamic_huffman", 1) ||
isThisMethod(q.tm, n, "init_huff", 4) {
+1
View File
@@ -352,6 +352,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
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_huffman", 2) ||
isThisMethod(q.tm, n, "decode_blocks", 2) ||
isThisMethod(q.tm, n, "init_fixed_huffman", 0) || isThisMethod(q.tm, n, "init_dynamic_huffman", 1) ||
isThisMethod(q.tm, n, "init_huff", 4) {
+5
View File
@@ -90,6 +90,11 @@ pub struct decoder?(
)
pub func decoder.decode?(dst writer1, src reader1)() {
// TODO: copy from dst to history, if we aren't finished.
this.decode_blocks?(dst:in.dst, src:in.src)
}
pri func decoder.decode_blocks?(dst writer1, src reader1)() {
var final u32
while final == 0 {
while this.n_bits < 3,