@@ -52,20 +52,31 @@ var (
5252 tEface = types .NewInterfaceType (nil , nil ).Complete ()
5353 tDeferStack = types .NewPointer (typeutil .NewDeferStack ())
5454
55- jReady = intConst (0 , nil ) // range-over-func jump is READY
56- jBusy = intConst (- 1 , nil ) // range-over-func jump is BUSY
57- jDone = intConst (- 2 , nil ) // range-over-func jump is DONE
58-
5955 vDeferStack = & Builtin {
6056 name : "ssa:deferstack" ,
6157 sig : types .NewSignatureType (nil , nil , nil , nil , types .NewTuple (anonVar (tDeferStack )), false ),
6258 }
6359)
6460
65- func init () {
66- jReady .comment = "rangefunc.exit.ready"
67- jBusy .comment = "rangefunc.exit.busy"
68- jDone .comment = "rangefunc.exit.done"
61+ // range-over-func jump is READY
62+ func jReady () * Const {
63+ c := intConst (0 , nil )
64+ c .comment = "rangefunc.exit.ready"
65+ return c
66+ }
67+
68+ // range-over-func jump is BUSY
69+ func jBusy () * Const {
70+ c := intConst (- 1 , nil )
71+ c .comment = "rangefunc.exit.busy"
72+ return c
73+ }
74+
75+ // range-over-func jump is DONE
76+ func jDone () * Const {
77+ c := intConst (- 2 , nil )
78+ c .comment = "rangefunc.exit.done"
79+ return c
6980}
7081
7182// builder holds state associated with the package currently being built.
@@ -2737,8 +2748,8 @@ func (b *builder) buildYieldResume(fn *Function, jump *types.Var, exits []*exit,
27372748 bodies [1 ] = fn .newBasicBlock ("rangefunc.resume.ready" )
27382749
27392750 conds := make ([]Value , 2 , 2 + len (exits ))
2740- conds [0 ] = emitConst (fn , jBusy )
2741- conds [1 ] = emitConst (fn , jReady )
2751+ conds [0 ] = emitConst (fn , jBusy () )
2752+ conds [1 ] = emitConst (fn , jReady () )
27422753
27432754 fn .currentBlock = bodies [0 ]
27442755 fn .emit (
@@ -2750,7 +2761,7 @@ func (b *builder) buildYieldResume(fn *Function, jump *types.Var, exits []*exit,
27502761 addEdge (fn .currentBlock , fn .Exit )
27512762
27522763 fn .currentBlock = bodies [1 ]
2753- storeVar (fn , jump , emitConst (fn , jDone ), nil )
2764+ storeVar (fn , jump , emitConst (fn , jDone () ), nil )
27542765 emitJump (fn , done , nil )
27552766
27562767 for _ , e := range exits {
@@ -3184,7 +3195,7 @@ func (b *builder) buildYieldFunc(fn *Function) {
31843195 // return true
31853196 saved := fn .currentBlock
31863197 fn .currentBlock = ycont
3187- storeVar (fn , fn .jump , emitConst (fn , jReady ), s .Body )
3198+ storeVar (fn , fn .jump , emitConst (fn , jReady () ), s .Body )
31883199 vTrue := emitConst (fn , NewConst (constant .MakeBool (true ), tBool , nil ))
31893200 emitReturn (fn , []Value {vTrue }, nil )
31903201
@@ -3198,7 +3209,7 @@ func (b *builder) buildYieldFunc(fn *Function) {
31983209 invalid := fn .newBasicBlock ("yield-invalid" )
31993210
32003211 jumpVal := emitLoad (fn , fn .lookup (fn .jump , true ), nil )
3201- emitIf (fn , emitCompare (fn , token .EQL , jumpVal , emitConst (fn , jReady ), nil ), yloop , invalid , nil )
3212+ emitIf (fn , emitCompare (fn , token .EQL , jumpVal , emitConst (fn , jReady () ), nil ), yloop , invalid , nil )
32023213 fn .currentBlock = invalid
32033214 fn .emit (
32043215 & Panic {
@@ -3209,7 +3220,7 @@ func (b *builder) buildYieldFunc(fn *Function) {
32093220 addEdge (fn .currentBlock , fn .Exit )
32103221
32113222 fn .currentBlock = yloop
3212- storeVar (fn , fn .jump , emitConst (fn , jBusy ), s .Body )
3223+ storeVar (fn , fn .jump , emitConst (fn , jBusy () ), s .Body )
32133224
32143225 // Initialize k and v from params.
32153226 var tk , tv types.Type
0 commit comments