mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Have write_{u8,token} save args across suspension
This commit is contained in:
1 parent
4c7c296015
commit
8e7efa67b9
3 files changed
+43
-22
No files matched your search
+27
-13
@@ -634,29 +634,36 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
case t.IDIOWriter:
|
||||
switch method.Ident() {
|
||||
case t.IDWriteU8:
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("if (iop_a_dst == io2_a_dst) {\n" +
|
||||
"status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n" +
|
||||
"*iop_a_dst++ = ")
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("%s = ", scratchName)
|
||||
x := n.Args()[0].AsArg().Value()
|
||||
if err := g.writeExpr(b, x, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(";\n")
|
||||
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("if (iop_a_dst == io2_a_dst) {\n"+
|
||||
"status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n"+
|
||||
"*iop_a_dst++ = ((uint8_t)(%s));\n", scratchName)
|
||||
return nil
|
||||
}
|
||||
|
||||
case t.IDTokenWriter:
|
||||
switch method.Ident() {
|
||||
case t.IDWriteToken:
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("if (iop_a_dst == io2_a_dst) {\n" +
|
||||
"status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n" +
|
||||
"*iop_a_dst++ = wuffs_base__make_token(((")
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("%s = ((", scratchName)
|
||||
if err := g.writeExpr(b, n.Args()[0].AsArg().Value(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -664,7 +671,14 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
if err := g.writeExpr(b, n.Args()[1].AsArg().Value(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(") << WUFFS_BASE__TOKEN__LENGTH_SHIFT));\n")
|
||||
b.writes(") << WUFFS_BASE__TOKEN__LENGTH_SHIFT);\n")
|
||||
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("if (iop_a_dst == io2_a_dst) {\n"+
|
||||
"status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n"+
|
||||
"*iop_a_dst++ = wuffs_base__make_token(%s);\n", scratchName)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,8 +266,8 @@ func (h *livenessHelper) doAssign(r livenesses, n *a.Assign, depth uint32) error
|
||||
func (h *livenessHelper) doExpr(r livenesses, n *a.Expr) error {
|
||||
allToStrong := false
|
||||
if n.Effect().Coroutine() {
|
||||
method := n.LHS().AsExpr().Ident()
|
||||
if (method == t.IDSkip) || (method == t.IDSkip32) {
|
||||
recv := n.LHS().AsExpr().LHS().AsExpr()
|
||||
if recv.MType().IsIOTokenType() {
|
||||
// No-op. These methods already save their args across suspensions.
|
||||
} else {
|
||||
allToStrong = true
|
||||
|
||||
@@ -3861,6 +3861,7 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
|
||||
@@ -5050,7 +5051,7 @@ struct wuffs_json__decoder__struct {
|
||||
|
||||
struct {
|
||||
struct {
|
||||
uint64_t v_length;
|
||||
uint64_t scratch;
|
||||
} s_decode_tokens[1];
|
||||
} private_data;
|
||||
|
||||
@@ -11960,12 +11961,15 @@ wuffs_deflate__decoder__decode_huffman_slow(wuffs_deflate__decoder* self,
|
||||
}
|
||||
label_1_break:;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
self->private_data.s_decode_huffman_slow[0].scratch =
|
||||
((uint8_t)(((v_table_entry >> 8) & 255)));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (iop_a_dst == io2_a_dst) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
goto suspend;
|
||||
}
|
||||
*iop_a_dst++ = ((uint8_t)(((v_table_entry >> 8) & 255)));
|
||||
*iop_a_dst++ =
|
||||
((uint8_t)(self->private_data.s_decode_huffman_slow[0].scratch));
|
||||
goto label_0_continue;
|
||||
} else if ((v_table_entry >> 30) != 0) {
|
||||
} else if ((v_table_entry >> 29) != 0) {
|
||||
@@ -11999,13 +12003,16 @@ wuffs_deflate__decoder__decode_huffman_slow(wuffs_deflate__decoder* self,
|
||||
}
|
||||
label_2_break:;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
self->private_data.s_decode_huffman_slow[0].scratch =
|
||||
((uint8_t)(((v_table_entry >> 8) & 255)));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (iop_a_dst == io2_a_dst) {
|
||||
status =
|
||||
wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
goto suspend;
|
||||
}
|
||||
*iop_a_dst++ = ((uint8_t)(((v_table_entry >> 8) & 255)));
|
||||
*iop_a_dst++ =
|
||||
((uint8_t)(self->private_data.s_decode_huffman_slow[0].scratch));
|
||||
goto label_0_continue;
|
||||
} else if ((v_table_entry >> 30) != 0) {
|
||||
} else if ((v_table_entry >> 29) != 0) {
|
||||
@@ -18136,20 +18143,21 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_tokens[0];
|
||||
if (coro_susp_point) {
|
||||
v_length = self->private_data.s_decode_tokens[0].v_length;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
v_length = 456;
|
||||
self->private_data.s_decode_tokens[0].scratch =
|
||||
((123) << WUFFS_BASE__TOKEN__VALUE_SHIFT) |
|
||||
((v_length) << WUFFS_BASE__TOKEN__LENGTH_SHIFT);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (iop_a_dst == io2_a_dst) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
goto suspend;
|
||||
}
|
||||
*iop_a_dst++ =
|
||||
wuffs_base__make_token(((123) << WUFFS_BASE__TOKEN__VALUE_SHIFT) |
|
||||
((v_length) << WUFFS_BASE__TOKEN__LENGTH_SHIFT));
|
||||
wuffs_base__make_token(self->private_data.s_decode_tokens[0].scratch);
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
goto ok;
|
||||
@@ -18164,7 +18172,6 @@ suspend:
|
||||
wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine =
|
||||
wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_decode_tokens[0].v_length = v_length;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
|
||||
Reference in new issue
Block a user