@@ -52,20 +52,31 @@ var (
52
52
tEface = types .NewInterfaceType (nil , nil ).Complete ()
53
53
tDeferStack = types .NewPointer (typeutil .NewDeferStack ())
54
54
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
-
59
55
vDeferStack = & Builtin {
60
56
name : "ssa:deferstack" ,
61
57
sig : types .NewSignatureType (nil , nil , nil , nil , types .NewTuple (anonVar (tDeferStack )), false ),
62
58
}
63
59
)
64
60
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
69
80
}
70
81
71
82
// 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,
2737
2748
bodies [1 ] = fn .newBasicBlock ("rangefunc.resume.ready" )
2738
2749
2739
2750
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 () )
2742
2753
2743
2754
fn .currentBlock = bodies [0 ]
2744
2755
fn .emit (
@@ -2750,7 +2761,7 @@ func (b *builder) buildYieldResume(fn *Function, jump *types.Var, exits []*exit,
2750
2761
addEdge (fn .currentBlock , fn .Exit )
2751
2762
2752
2763
fn .currentBlock = bodies [1 ]
2753
- storeVar (fn , jump , emitConst (fn , jDone ), nil )
2764
+ storeVar (fn , jump , emitConst (fn , jDone () ), nil )
2754
2765
emitJump (fn , done , nil )
2755
2766
2756
2767
for _ , e := range exits {
@@ -3184,7 +3195,7 @@ func (b *builder) buildYieldFunc(fn *Function) {
3184
3195
// return true
3185
3196
saved := fn .currentBlock
3186
3197
fn .currentBlock = ycont
3187
- storeVar (fn , fn .jump , emitConst (fn , jReady ), s .Body )
3198
+ storeVar (fn , fn .jump , emitConst (fn , jReady () ), s .Body )
3188
3199
vTrue := emitConst (fn , NewConst (constant .MakeBool (true ), tBool , nil ))
3189
3200
emitReturn (fn , []Value {vTrue }, nil )
3190
3201
@@ -3198,7 +3209,7 @@ func (b *builder) buildYieldFunc(fn *Function) {
3198
3209
invalid := fn .newBasicBlock ("yield-invalid" )
3199
3210
3200
3211
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 )
3202
3213
fn .currentBlock = invalid
3203
3214
fn .emit (
3204
3215
& Panic {
@@ -3209,7 +3220,7 @@ func (b *builder) buildYieldFunc(fn *Function) {
3209
3220
addEdge (fn .currentBlock , fn .Exit )
3210
3221
3211
3222
fn .currentBlock = yloop
3212
- storeVar (fn , fn .jump , emitConst (fn , jBusy ), s .Body )
3223
+ storeVar (fn , fn .jump , emitConst (fn , jBusy () ), s .Body )
3213
3224
3214
3225
// Initialize k and v from params.
3215
3226
var tk , tv types.Type
0 commit comments