mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 16:32:11 +01:00
cgen: simplify 1-elem in-case-of-recursion arrays
This commit is contained in:
1 parent
df1d4f64e2
commit
2c2bb9baa5
6 files changed
+1025
-1034
No files matched your search
@@ -1247,8 +1247,7 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
}
|
||||
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s.scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("%s = ", scratchName)
|
||||
@@ -1285,8 +1284,7 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
switch method.Ident() {
|
||||
case t.IDWriteU8:
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s.scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("%s = ", scratchName)
|
||||
@@ -1338,8 +1336,7 @@ func (g *gen) writeReadUxxAsUyy(b *buffer, n *a.Expr, preName string, xx uint8,
|
||||
}
|
||||
|
||||
g.currFunk.usesScratch = true
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
|
||||
scratchName := fmt.Sprintf("self->private_data.%s%s.scratch",
|
||||
sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
b.printf("if (WUFFS_BASE__LIKELY(io2_%s - iop_%s >= %d)) {\n", recvName, recvName, xx/8)
|
||||
|
||||
@@ -1081,9 +1081,6 @@ func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
||||
// TODO: allow max depth > 1 for recursive coroutines.
|
||||
const maxDepth = 1
|
||||
|
||||
b.writes("// Do not access the private_impl's or private_data's fields directly. There\n")
|
||||
b.writes("// is no API/ABI compatibility or safety guarantee if you do so. Instead, use\n")
|
||||
b.writes("// the wuffs_foo__bar__baz functions.\n")
|
||||
@@ -1135,7 +1132,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
||||
needEmptyLine = false
|
||||
b.writeb('\n')
|
||||
}
|
||||
b.printf("uint32_t %s%s[%d];\n", pPrefix, o.FuncName().Str(g.tm), maxDepth)
|
||||
b.printf("uint32_t %s%s;\n", pPrefix, o.FuncName().Str(g.tm))
|
||||
|
||||
} else if o.Choosy() {
|
||||
if needEmptyLine {
|
||||
@@ -1200,7 +1197,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
||||
b.writes("uint64_t scratch;\n")
|
||||
}
|
||||
if oldInnerLenB1 != len(*b) {
|
||||
b.printf("} %s%s[%d];\n", sPrefix, o.FuncName().Str(g.tm), maxDepth)
|
||||
b.printf("} %s%s;\n", sPrefix, o.FuncName().Str(g.tm))
|
||||
} else {
|
||||
*b = (*b)[:oldInnerLenB0]
|
||||
needEmptyLine = oldNeedEmptyLine
|
||||
|
||||
@@ -66,8 +66,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, sideEffectsOnly bool, depth u
|
||||
|
||||
} else if ident == t.IDCoroutineResumed {
|
||||
if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
b.printf("(self->private_impl.%s%s[0] != 0)",
|
||||
b.printf("(self->private_impl.%s%s != 0)",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
} else {
|
||||
b.writes("false")
|
||||
|
||||
@@ -470,8 +470,7 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||
|
||||
func (g *gen) writeFuncImplBodyResume(b *buffer) error {
|
||||
if g.currFunk.coroSuspPoint > 0 {
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0];\n",
|
||||
b.printf("uint32_t coro_susp_point = self->private_impl.%s%s;\n",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
|
||||
resumeBuffer := buffer{}
|
||||
@@ -514,13 +513,13 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
// We've reached the end of the function body. Reset the coroutine
|
||||
// suspension point so that the next call to this function starts at
|
||||
// the top.
|
||||
b.printf("self->private_impl.%s%s[0] = 0;\n",
|
||||
b.printf("self->private_impl.%s%s = 0;\n",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
b.writes("goto exit;\n}\n\n") // Close the coroutine switch.
|
||||
|
||||
b.writes("goto suspend;\nsuspend:\n") // The goto avoids the "unused label" warning.
|
||||
|
||||
b.printf("self->private_impl.%s%s[0] = "+
|
||||
b.printf("self->private_impl.%s%s = "+
|
||||
"wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;\n",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
if g.currFunk.astFunc.Public() {
|
||||
|
||||
@@ -280,8 +280,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, f *funk, n *a.Var, suspend bool) er
|
||||
} else {
|
||||
local := fmt.Sprintf("%s%s", vPrefix, n.Name().Str(g.tm))
|
||||
lhs := local
|
||||
// TODO: don't hard-code [0], and allow recursive coroutines.
|
||||
rhs := fmt.Sprintf("self->private_data.%s%s[0].%s", sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
|
||||
rhs := fmt.Sprintf("self->private_data.%s%s.%s", sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
|
||||
if suspend {
|
||||
lhs, rhs = rhs, lhs
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user