mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Make Iterate contain Assign's not Var's
This commit is contained in:
1 parent
cd9ab50f63
commit
d552f88738
13 files changed
+91
-91
No files matched your search
@@ -736,7 +736,7 @@ func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
||||
b.writes("struct {\n")
|
||||
if k.coroSuspPoint != 0 {
|
||||
b.writes("uint32_t coro_susp_point;\n")
|
||||
if err := g.writeVars(b, &k, true, true, true); err != nil {
|
||||
if err := g.writeVars(b, &k, true, true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||
b.writes("\n")
|
||||
|
||||
// Generate the local variables.
|
||||
if err := g.writeVars(b, &g.currFunk, false, true, false); err != nil {
|
||||
if err := g.writeVars(b, &g.currFunk, false, false); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
@@ -380,13 +380,14 @@ func (h *resumabilityHelper) doIf(r resumabilities, n *a.If, depth uint32) error
|
||||
func (h *resumabilityHelper) doIterate(r resumabilities, n *a.Iterate, depth uint32) error {
|
||||
// TODO: ban jumps, rets and coroutine calls inside an iterate. Also ensure
|
||||
// that the iterate variable values are all pure expressions.
|
||||
for _, v := range n.Variables() {
|
||||
v := v.AsVar()
|
||||
if err := h.doExpr(r, v.Value()); err != nil {
|
||||
for _, o := range n.Assigns() {
|
||||
o := o.AsAssign()
|
||||
if err := h.doExpr(r, o.RHS()); err != nil {
|
||||
return err
|
||||
}
|
||||
if i, ok := h.vars[v.Name()]; !ok {
|
||||
return fmt.Errorf("unrecognized variable %q", v.Name().Str(h.tm))
|
||||
name := o.LHS().Ident()
|
||||
if i, ok := h.vars[name]; !ok {
|
||||
return fmt.Errorf("unrecognized variable %q", name.Str(h.tm))
|
||||
} else {
|
||||
r.lowerWeakToNone(i)
|
||||
}
|
||||
|
||||
@@ -339,26 +339,26 @@ func (g *gen) writeStatementIf(b *buffer, n *a.If, depth uint32) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeStatementIterate(b *buffer, n *a.Iterate, depth uint32) error {
|
||||
vars := n.Variables()
|
||||
if len(vars) == 0 {
|
||||
assigns := n.Assigns()
|
||||
if len(assigns) == 0 {
|
||||
return nil
|
||||
}
|
||||
if len(vars) != 1 {
|
||||
return fmt.Errorf("TODO: iterate over more than one variable")
|
||||
if len(assigns) != 1 {
|
||||
return fmt.Errorf("TODO: iterate over more than one assign")
|
||||
}
|
||||
v := vars[0].AsVar()
|
||||
name := v.Name().Str(g.tm)
|
||||
o := assigns[0].AsAssign()
|
||||
name := o.LHS().Ident().Str(g.tm)
|
||||
b.writes("{\n")
|
||||
|
||||
// TODO: don't assume that the slice is a slice of base.u8. In
|
||||
// particular, the code gen can be subtle if the slice element type has
|
||||
// zero size, such as the empty struct.
|
||||
b.printf("wuffs_base__slice_u8 %sslice_%s =", iPrefix, name)
|
||||
if err := g.writeExpr(b, v.Value(), 0); err != nil {
|
||||
if err := g.writeExpr(b, o.RHS(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(";\n")
|
||||
b.printf("wuffs_base__slice_u8 %s%s = %sslice_%s;\n", vPrefix, name, iPrefix, name)
|
||||
b.printf("%s%s = %sslice_%s;\n", vPrefix, name, iPrefix, name)
|
||||
// TODO: look at n.HasContinue() and n.HasBreak().
|
||||
|
||||
round := uint32(0)
|
||||
|
||||
@@ -344,15 +344,12 @@ func (g *gen) writeResumeSuspend(b *buffer, f *funk, suspend bool, initBoolTyped
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) writeVars(b *buffer, f *funk, skipPointerTypes bool, skipIterateVariables bool, skipNonresumable bool) error {
|
||||
func (g *gen) writeVars(b *buffer, f *funk, skipPointerTypes bool, skipNonresumable bool) error {
|
||||
for _, n := range f.varList {
|
||||
typ := n.XType()
|
||||
if skipPointerTypes && typ.HasPointers() {
|
||||
continue
|
||||
}
|
||||
if skipIterateVariables && n.IterateVariable() {
|
||||
continue
|
||||
}
|
||||
if skipNonresumable && (f.varResumables == nil || !f.varResumables[n.Name()]) {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user