mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Generate C return's.
This commit is contained in:
1 parent
2d0f9d7669
commit
ec19f601d5
3 files changed
+30
-10
No files matched your search
+19
-8
@@ -105,7 +105,8 @@ type perFunc struct {
|
|||||||
jumpTargets map[*a.While]uint32
|
jumpTargets map[*a.While]uint32
|
||||||
tempW uint32
|
tempW uint32
|
||||||
tempR uint32
|
tempR uint32
|
||||||
cleanup0 bool
|
public bool
|
||||||
|
suspendible bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type gen struct {
|
type gen struct {
|
||||||
@@ -421,11 +422,13 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
|
|||||||
|
|
||||||
// Check the previous status and the args.
|
// Check the previous status and the args.
|
||||||
if n.Public() {
|
if n.Public() {
|
||||||
|
g.perFunc.public = true
|
||||||
if n.Receiver() != 0 {
|
if n.Receiver() != 0 {
|
||||||
g.printf("if (!self) { return puffs_%s_error_bad_receiver; }\n", g.pkgName)
|
g.printf("if (!self) { return puffs_%s_error_bad_receiver; }\n", g.pkgName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n.Suspendible() {
|
if n.Suspendible() {
|
||||||
|
g.perFunc.suspendible = true
|
||||||
g.printf("puffs_%s_status status = ", g.pkgName)
|
g.printf("puffs_%s_status status = ", g.pkgName)
|
||||||
if n.Receiver() != 0 {
|
if n.Receiver() != 0 {
|
||||||
g.printf("self->status;\n")
|
g.printf("self->status;\n")
|
||||||
@@ -438,7 +441,6 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
|
|||||||
if n.Public() {
|
if n.Public() {
|
||||||
g.printf("if (self->magic != PUFFS_MAGIC) {"+
|
g.printf("if (self->magic != PUFFS_MAGIC) {"+
|
||||||
"status = puffs_%s_error_constructor_not_called; goto cleanup0; }\n", g.pkgName)
|
"status = puffs_%s_error_constructor_not_called; goto cleanup0; }\n", g.pkgName)
|
||||||
g.perFunc.cleanup0 = true
|
|
||||||
}
|
}
|
||||||
} else if r := n.Receiver(); r != 0 {
|
} else if r := n.Receiver(); r != 0 {
|
||||||
// TODO: fix this.
|
// TODO: fix this.
|
||||||
@@ -487,10 +489,10 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
|
|||||||
}
|
}
|
||||||
g.writes("\n")
|
g.writes("\n")
|
||||||
|
|
||||||
if g.perFunc.cleanup0 {
|
if g.perFunc.suspendible {
|
||||||
g.printf("cleanup0: self->status = status;\n")
|
if g.perFunc.public {
|
||||||
}
|
g.printf("cleanup0: self->status = status;\n")
|
||||||
if n.Suspendible() {
|
}
|
||||||
g.printf("return status;\n")
|
g.printf("return status;\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,7 +652,16 @@ func (g *gen) writeStatement(n *a.Node, depth uint32) error {
|
|||||||
return nil
|
return nil
|
||||||
|
|
||||||
case a.KReturn:
|
case a.KReturn:
|
||||||
// TODO, including considering suspendible calls.
|
if !g.perFunc.suspendible {
|
||||||
|
// TODO: consider the return values, especially if they involve
|
||||||
|
// suspendible function calls.
|
||||||
|
g.writes("return;\n")
|
||||||
|
} else if g.perFunc.public {
|
||||||
|
g.printf("status = puffs_%s_status_ok; goto cleanup0;\n", g.pkgName)
|
||||||
|
} else {
|
||||||
|
g.printf("return puffs_%s_status_ok;\n", g.pkgName)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
case a.KVar:
|
case a.KVar:
|
||||||
n := n.Var()
|
n := n.Var()
|
||||||
@@ -743,7 +754,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr) error {
|
|||||||
// src_final.
|
// src_final.
|
||||||
g.printf("if (%ssrc->ri >= %ssrc->wi) { status = puffs_%s_status_short_read;",
|
g.printf("if (%ssrc->ri >= %ssrc->wi) { status = puffs_%s_status_short_read;",
|
||||||
aPrefix, aPrefix, g.pkgName)
|
aPrefix, aPrefix, g.pkgName)
|
||||||
if g.perFunc.cleanup0 {
|
if g.perFunc.public && g.perFunc.suspendible {
|
||||||
g.writes("goto cleanup0;")
|
g.writes("goto cleanup0;")
|
||||||
} else {
|
} else {
|
||||||
g.writes("return status;")
|
g.writes("return status;")
|
||||||
|
|||||||
@@ -210,12 +210,14 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
uint32_t v_bits;
|
uint32_t v_bits;
|
||||||
uint32_t v_n_bits;
|
uint32_t v_n_bits;
|
||||||
uint32_t v_clear_code;
|
uint32_t v_clear_code;
|
||||||
|
uint32_t v_end_code;
|
||||||
uint32_t v_width;
|
uint32_t v_width;
|
||||||
uint32_t v_code;
|
uint32_t v_code;
|
||||||
|
|
||||||
v_bits = 0;
|
v_bits = 0;
|
||||||
v_n_bits = 0;
|
v_n_bits = 0;
|
||||||
v_clear_code = (((uint32_t)(1)) << self->f_literal_width);
|
v_clear_code = (((uint32_t)(1)) << self->f_literal_width);
|
||||||
|
v_end_code = (v_clear_code + 1);
|
||||||
v_width = (self->f_literal_width + 1);
|
v_width = (self->f_literal_width + 1);
|
||||||
label_0_continue:;
|
label_0_continue:;
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -234,7 +236,11 @@ label_0_continue:;
|
|||||||
if (v_code < v_clear_code) {
|
if (v_code < v_clear_code) {
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
} else if (v_code == v_clear_code) {
|
} else if (v_code == v_clear_code) {
|
||||||
|
v_width = (self->f_literal_width + 1);
|
||||||
goto label_0_continue;
|
goto label_0_continue;
|
||||||
|
} else if (v_code == v_end_code) {
|
||||||
|
status = puffs_gif_status_ok;
|
||||||
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ pub struct lzw_decoder?(
|
|||||||
pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
||||||
var bits u32
|
var bits u32
|
||||||
var n_bits u32
|
var n_bits u32
|
||||||
var clear_code u32 = (1 as u32) << this.literal_width
|
var clear_code u32[4..256] = (1 as u32) << this.literal_width
|
||||||
// TODO: set end_code.
|
var end_code u32[5..257] = clear_code + 1
|
||||||
var width u32[..12] = this.literal_width + 1
|
var width u32[..12] = this.literal_width + 1
|
||||||
|
|
||||||
// TODO: implement.
|
// TODO: implement.
|
||||||
@@ -33,7 +33,10 @@ pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
|||||||
if code < clear_code {
|
if code < clear_code {
|
||||||
break
|
break
|
||||||
} else if code == clear_code {
|
} else if code == clear_code {
|
||||||
|
width = this.literal_width + 1
|
||||||
continue
|
continue
|
||||||
|
} else if code == end_code {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement.
|
// TODO: implement.
|
||||||
|
|||||||
Reference in new issue
Block a user