mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Generate C "goto suspend" statements.
This commit is contained in:
1 parent
9ec2ad7e0c
commit
24c8509242
2 files changed
+47
-47
No files matched your search
+19
-19
@@ -617,7 +617,7 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
|
||||
}
|
||||
if n.Public() {
|
||||
g.printf("if (self->private_impl.magic != PUFFS_MAGIC) {"+
|
||||
"status = puffs_%s_error_constructor_not_called; goto cleanup0; }\n", g.pkgName)
|
||||
"status = puffs_%s_error_constructor_not_called; goto exit; }\n", g.pkgName)
|
||||
}
|
||||
} else if n.Receiver() != 0 && n.Public() {
|
||||
g.writes("if (self->private_impl.status & 1) { return; }")
|
||||
@@ -665,17 +665,17 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
|
||||
if err := g.writeSuspend(); err != nil {
|
||||
return err
|
||||
}
|
||||
g.writes("}\n") // Close the coroutine switch.
|
||||
g.writes("goto cleanup0;\n\n")
|
||||
// Avoid the "unused label" warning.
|
||||
//
|
||||
// TODO: delete this.
|
||||
g.writes("goto suspend;\n")
|
||||
g.writes("}\n\n") // Close the coroutine switch.
|
||||
|
||||
g.writes("goto suspend;\n") // Avoid the "unused label" warning.
|
||||
g.writes("suspend:\n")
|
||||
if err := g.writeResumeSuspend(n.Body(), true); err != nil {
|
||||
return err
|
||||
}
|
||||
g.writes("\ncleanup0:")
|
||||
g.writes("\n")
|
||||
|
||||
g.writes("goto exit;\n") // Avoid the "unused label" warning.
|
||||
g.writes("exit:")
|
||||
if g.perFunc.public {
|
||||
g.writes("self->private_impl.status = status;\n")
|
||||
}
|
||||
@@ -747,7 +747,7 @@ func (g *gen) writeFuncImplArgChecks(n *a.Func) error {
|
||||
}
|
||||
g.writes(") {")
|
||||
if n.Suspendible() {
|
||||
g.printf("status = puffs_%s_error_bad_argument; goto cleanup0;", g.pkgName)
|
||||
g.printf("status = puffs_%s_error_bad_argument; goto exit;", g.pkgName)
|
||||
} else if n.Receiver() != 0 {
|
||||
g.printf("self->private_impl.status = puffs_%s_error_bad_argument; return;", g.pkgName)
|
||||
} else {
|
||||
@@ -963,7 +963,7 @@ func (g *gen) writeStatement(n *a.Node, depth uint32) error {
|
||||
// suspendible function calls.
|
||||
g.writes("return;\n")
|
||||
} else if g.perFunc.public {
|
||||
g.printf("status = %s; goto cleanup0;\n", ret)
|
||||
g.printf("status = %s; goto suspend;\n", ret)
|
||||
} else {
|
||||
g.printf("return %s;\n", ret)
|
||||
}
|
||||
@@ -1106,7 +1106,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
"puffs_%s_error_unexpected_eof : puffs_%s_status_short_read;",
|
||||
aPrefix, aPrefix, aPrefix, g.pkgName, g.pkgName)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto cleanup0;")
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
@@ -1143,7 +1143,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
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;")
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
@@ -1155,7 +1155,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
// TODO: don't assume that the argument is "this.stack[s:]".
|
||||
g.printf("if (%sdst.buf->closed) { status = puffs_%s_error_closed_for_writes;", aPrefix, g.pkgName)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto cleanup0;")
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
@@ -1164,7 +1164,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
aPrefix, aPrefix)
|
||||
g.printf("status = puffs_%s_status_short_write;", g.pkgName)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto cleanup0;")
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
@@ -1179,7 +1179,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
g.printf("if (%sdst.buf->wi >= %sdst.buf->len) { status = puffs_%s_status_short_write;",
|
||||
aPrefix, aPrefix, g.pkgName)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto cleanup0;")
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
@@ -1194,22 +1194,22 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
} else if isThisMethod(g.tm, n, "decode_header", 1) {
|
||||
g.printf("status = puffs_%s_%s_decode_header(self, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||
g.writes("if (status) { goto cleanup0; }\n")
|
||||
g.writes("if (status) { goto suspend; }\n")
|
||||
|
||||
} else if isThisMethod(g.tm, n, "decode_lsd", 1) {
|
||||
g.printf("status = puffs_%s_%s_decode_lsd(self, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||
g.writes("if (status) { goto cleanup0; }\n")
|
||||
g.writes("if (status) { goto suspend; }\n")
|
||||
|
||||
} else if isThisMethod(g.tm, n, "decode_extension", 1) {
|
||||
g.printf("status = puffs_%s_%s_decode_extension(self, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||
g.writes("if (status) { goto cleanup0; }\n")
|
||||
g.writes("if (status) { goto suspend; }\n")
|
||||
|
||||
} else if isThisMethod(g.tm, n, "decode_id", 2) {
|
||||
g.printf("status = puffs_%s_%s_decode_id(self, %sdst, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix, aPrefix)
|
||||
g.writes("if (status) { goto cleanup0; }\n")
|
||||
g.writes("if (status) { goto suspend; }\n")
|
||||
|
||||
} else if isDecode(g.tm, n) {
|
||||
g.printf("status = puffs_%s_lzw_decoder_decode(&self->private_impl.f_lzw, %sdst, %s%s);\n",
|
||||
|
||||
+28
-28
@@ -375,7 +375,7 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
status = puffs_gif_error_constructor_not_called;
|
||||
goto cleanup0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
uint8_t v_c;
|
||||
@@ -389,12 +389,12 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||
case 1:;
|
||||
status = puffs_gif_decoder_decode_header(self, a_src);
|
||||
if (status) {
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
case 2:;
|
||||
status = puffs_gif_decoder_decode_lsd(self, a_src);
|
||||
if (status) {
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
while (true) {
|
||||
case 3:;
|
||||
@@ -403,7 +403,7 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? puffs_gif_error_unexpected_eof
|
||||
: puffs_gif_status_short_read;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = a_src.buf->ptr[a_src.buf->ri++];
|
||||
if (a_src.limit.ptr_to_len) {
|
||||
@@ -414,31 +414,31 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||
case 4:;
|
||||
status = puffs_gif_decoder_decode_extension(self, a_src);
|
||||
if (status) {
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
} else if (v_c == 44) {
|
||||
case 5:;
|
||||
status = puffs_gif_decoder_decode_id(self, a_dst, a_src);
|
||||
if (status) {
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
} else if (v_c == 59) {
|
||||
status = puffs_gif_status_ok;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
} else {
|
||||
status = puffs_gif_error_bad_gif_block;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
case 6:;
|
||||
}
|
||||
goto cleanup0;
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.c_decode[0].v_c = v_c;
|
||||
|
||||
cleanup0:
|
||||
goto exit;
|
||||
exit:
|
||||
self->private_impl.status = status;
|
||||
return status;
|
||||
}
|
||||
@@ -484,14 +484,14 @@ puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
||||
}
|
||||
case 2:;
|
||||
}
|
||||
goto cleanup0;
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
memcpy(self->private_impl.c_decode_header[0].v_c, v_c, 6);
|
||||
self->private_impl.c_decode_header[0].v_i = v_i;
|
||||
|
||||
cleanup0:
|
||||
goto exit;
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -584,7 +584,6 @@ puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
||||
}
|
||||
case 5:;
|
||||
}
|
||||
goto cleanup0;
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
@@ -592,7 +591,8 @@ suspend:
|
||||
self->private_impl.c_decode_lsd[0].v_i = v_i;
|
||||
self->private_impl.c_decode_lsd[0].v_gct_size = v_gct_size;
|
||||
|
||||
cleanup0:
|
||||
goto exit;
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -661,14 +661,14 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
label_0_break:;
|
||||
case 4:;
|
||||
}
|
||||
goto cleanup0;
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.c_decode_extension[0].v_label = v_label;
|
||||
self->private_impl.c_decode_extension[0].v_block_size = v_block_size;
|
||||
|
||||
cleanup0:
|
||||
goto exit;
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -774,7 +774,6 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
label_0_break:;
|
||||
case 5:;
|
||||
}
|
||||
goto cleanup0;
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
@@ -786,7 +785,8 @@ suspend:
|
||||
self->private_impl.c_decode_id[0].l_lzw_src = l_lzw_src;
|
||||
self->private_impl.c_decode_id[0].v_lzw_src = v_lzw_src;
|
||||
|
||||
cleanup0:
|
||||
goto exit;
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -822,7 +822,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
status = puffs_gif_error_constructor_not_called;
|
||||
goto cleanup0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
uint32_t v_clear_code;
|
||||
@@ -870,7 +870,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? puffs_gif_error_unexpected_eof
|
||||
: puffs_gif_status_short_read;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = a_src.buf->ptr[a_src.buf->ri++];
|
||||
if (a_src.limit.ptr_to_len) {
|
||||
@@ -886,7 +886,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
case 2:;
|
||||
if (a_dst.buf->wi >= a_dst.buf->len) {
|
||||
status = puffs_gif_status_short_write;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
a_dst.buf->ptr[a_dst.buf->wi++] = ((uint8_t)(v_code));
|
||||
if (v_use_save_code) {
|
||||
@@ -902,7 +902,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
goto label_0_continue;
|
||||
} else if (v_code == v_end_code) {
|
||||
status = puffs_gif_status_ok;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
} else if (v_code <= v_save_code) {
|
||||
v_s = 4095;
|
||||
v_c = v_code;
|
||||
@@ -915,7 +915,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
self->private_impl.f_suffixes[v_c];
|
||||
if (v_s == 0) {
|
||||
status = puffs_gif_error_lzw_prefix_chain_is_cyclical;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
v_s -= 1;
|
||||
v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c]));
|
||||
@@ -927,12 +927,12 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
case 3:;
|
||||
if (a_dst.buf->closed) {
|
||||
status = puffs_gif_error_closed_for_writes;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
if ((a_dst.buf->len - a_dst.buf->wi) <
|
||||
(sizeof(self->private_impl.f_stack) - v_s)) {
|
||||
status = puffs_gif_status_short_write;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
memmove(a_dst.buf->ptr + a_dst.buf->wi,
|
||||
self->private_impl.f_stack + v_s,
|
||||
@@ -945,7 +945,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
}
|
||||
} else {
|
||||
status = puffs_gif_error_lzw_code_is_out_of_range;
|
||||
goto cleanup0;
|
||||
goto suspend;
|
||||
}
|
||||
v_use_save_code = (v_save_code < 4095);
|
||||
if (v_use_save_code) {
|
||||
@@ -958,7 +958,6 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
}
|
||||
case 4:;
|
||||
}
|
||||
goto cleanup0;
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
@@ -974,7 +973,8 @@ suspend:
|
||||
self->private_impl.c_decode[0].v_s = v_s;
|
||||
self->private_impl.c_decode[0].v_c = v_c;
|
||||
|
||||
cleanup0:
|
||||
goto exit;
|
||||
exit:
|
||||
self->private_impl.status = status;
|
||||
return status;
|
||||
}
|
||||
Reference in new issue
Block a user