mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Tighten cgen's funk.jumpTarget return type
This commit is contained in:
1 parent
21682f403f
commit
16867779be
2 files changed
+11
-9
No files matched your search
@@ -17,6 +17,7 @@ package cgen
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strconv"
|
||||
|
||||
a "github.com/google/wuffs/lang/ast"
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
@@ -37,7 +38,7 @@ type funk struct {
|
||||
varList []*a.Var
|
||||
varResumables map[t.ID]bool
|
||||
derivedVars map[t.ID]struct{}
|
||||
jumpTargets map[a.Loop]uint32
|
||||
jumpTargets map[a.Loop]string
|
||||
coroSuspPoint uint32
|
||||
ioBinds uint32
|
||||
tempW uint32
|
||||
@@ -47,20 +48,21 @@ type funk struct {
|
||||
hasGotoOK bool
|
||||
}
|
||||
|
||||
func (k *funk) jumpTarget(tm *t.Map, n a.Loop) (interface{}, error) {
|
||||
func (k *funk) jumpTarget(tm *t.Map, n a.Loop) (string, error) {
|
||||
if label := n.Label(); label != 0 {
|
||||
return label.Str(tm), nil
|
||||
}
|
||||
if k.jumpTargets == nil {
|
||||
k.jumpTargets = map[a.Loop]uint32{}
|
||||
k.jumpTargets = map[a.Loop]string{}
|
||||
}
|
||||
if jt, ok := k.jumpTargets[n]; ok {
|
||||
return jt, nil
|
||||
}
|
||||
jt := uint32(len(k.jumpTargets))
|
||||
if jt == 1000000 {
|
||||
return 0, fmt.Errorf("too many jump targets")
|
||||
jtInt := len(k.jumpTargets)
|
||||
if jtInt == 1000000 {
|
||||
return "", fmt.Errorf("too many jump targets")
|
||||
}
|
||||
jt := strconv.Itoa(jtInt)
|
||||
k.jumpTargets[n] = jt
|
||||
return jt, nil
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ func (g *gen) writeStatementJump(b *buffer, n *a.Jump, depth uint32) error {
|
||||
if n.Keyword() == t.IDBreak {
|
||||
keyword = "break"
|
||||
}
|
||||
b.printf("goto label__%v__%s;\n", jt, keyword)
|
||||
b.printf("goto label__%s__%s;\n", jt, keyword)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -496,7 +496,7 @@ func (g *gen) writeStatementWhile(b *buffer, n *a.While, depth uint32) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("label__%v__continue:;\n", jt)
|
||||
b.printf("label__%s__continue:;\n", jt)
|
||||
}
|
||||
condition := buffer(nil)
|
||||
if err := g.writeExpr(&condition, n.Condition(), 0); err != nil {
|
||||
@@ -515,7 +515,7 @@ func (g *gen) writeStatementWhile(b *buffer, n *a.While, depth uint32) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("label__%v__break:;\n", jt)
|
||||
b.printf("label__%s__break:;\n", jt)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user