-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.go
76 lines (66 loc) · 1.39 KB
/
select.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package ego
import (
"go/ast"
"reflect"
)
func (s *Scope) execSelect(stmt *ast.SelectStmt, label string) (*Scope, *branch, error) {
origScope := s
var (
rcases []reflect.SelectCase
commClauses []*ast.CommClause
)
for _, sub := range stmt.Body.List {
clause, ok := sub.(*ast.CommClause)
if !ok {
// xxx err
}
commClauses = append(commClauses, clause)
var rcase reflect.SelectCase
switch comm := clause.Comm.(type) {
case nil:
rcase.Dir = reflect.SelectDefault
case *ast.SendStmt:
ch, err := s.Eval1(clause.Chan)
if err != nil {
return nil, err
}
if ch.Kind() != refl.Chan {
// xxx err
}
sendval, err := s.Eval1(clause.Value)
if err != nil {
return nil, err
}
if sendval.Type() != ch.Type().Elem() {
// xxx err
}
rcase.Dir = reflect.SelectSend
rcase.Chan = ch
rcase.Send = sendval
case *ast.AssignStmt:
// xxx
case *ast.ExprStmt:
// xxx
default:
// xxx err
}
rcases = append(rcases, rcase)
}
chosen, received, ok := reflect.Select(rcases)
clause := commClauses[chosen]
// xxx maybe assign to vars for received and/or ok, maybe in a new scope
_, b, err := s.ExecStmts(clause.Body)
if err != nil {
return nil, nil, err
}
if b != nil {
switch b.typ {
case branchBreak:
case branchContinue:
case branchGoto:
case branchFallthrough:
case branchReturn:
}
}
return origScope, nil, nil
}