mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Generate temporary io_bind variables
This commit is contained in:
1 parent
4588cdcf5f
commit
3d1bb5e2a9
4 files changed
+40
-1
No files matched your search
@@ -52,6 +52,7 @@ const (
|
||||
cPrefix = "c_" // Coroutine state.
|
||||
fPrefix = "f_" // Struct field.
|
||||
iPrefix = "i_" // Iterate variable.
|
||||
oPrefix = "o_" // Temporary io_bind variable.
|
||||
tPrefix = "t_" // Temporary local variable.
|
||||
vPrefix = "v_" // Local variable.
|
||||
)
|
||||
@@ -145,7 +146,11 @@ const (
|
||||
priOnly
|
||||
)
|
||||
|
||||
const maxTemp = 10000
|
||||
const (
|
||||
maxIOBinds = 100
|
||||
maxIOBindInFields = 100
|
||||
maxTemp = 10000
|
||||
)
|
||||
|
||||
type status struct {
|
||||
name string
|
||||
|
||||
@@ -34,6 +34,7 @@ type funk struct {
|
||||
derivedVars map[t.ID]struct{}
|
||||
jumpTargets map[a.Loop]uint32
|
||||
coroSuspPoint uint32
|
||||
ioBinds uint32
|
||||
tempW uint32
|
||||
tempR uint32
|
||||
public bool
|
||||
|
||||
@@ -130,12 +130,41 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
|
||||
case a.KIOBind:
|
||||
n := n.IOBind()
|
||||
inFields := n.InFields()
|
||||
|
||||
if g.currFunk.ioBinds > maxIOBinds || len(inFields) > maxIOBindInFields {
|
||||
return fmt.Errorf("too many temporary variables required")
|
||||
}
|
||||
ioBindNum := g.currFunk.ioBinds
|
||||
g.currFunk.ioBinds++
|
||||
|
||||
// TODO: do these variables need to be func-scoped (bigger scope)
|
||||
// instead of block-scoped (smaller scope) if the coro_susp_point
|
||||
// switch can jump past this initialization??
|
||||
b.writes("{\n")
|
||||
for i := 0; i < len(inFields); i++ {
|
||||
e := inFields[i].Expr()
|
||||
name := e.Ident().Str(g.tm)
|
||||
for j := 0; j < 2; j++ {
|
||||
b.printf("uint8_t* %s%d_bounds%d_%s = %s%s.private_impl.bounds[%d];\n",
|
||||
oPrefix, ioBindNum, j, name, aPrefix, name, j)
|
||||
}
|
||||
}
|
||||
|
||||
for _, o := range n.Body() {
|
||||
if err := g.writeStatement(b, o, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for i := len(inFields) - 1; i >= 0; i-- {
|
||||
e := inFields[i].Expr()
|
||||
name := e.Ident().Str(g.tm)
|
||||
for j := 1; j >= 0; j-- {
|
||||
b.printf("%s%s.private_impl.bounds[%d] = %s%d_bounds%d_%s;\n",
|
||||
aPrefix, name, j, oPrefix, ioBindNum, j, name)
|
||||
}
|
||||
}
|
||||
b.writes("}\n")
|
||||
return nil
|
||||
|
||||
|
||||
Reference in new issue
Block a user