Simplify StreamType

This commit is contained in:
Cheer Xiao 2015-01-21 20:33:02 +01:00
parent 5911d955a6
commit 14ae68daf8
2 changed files with 5 additions and 29 deletions

View File

@ -26,7 +26,7 @@ var builtinFuncs = map[string]builtinFunc{
"printchan": builtinFunc{printchan, [2]StreamType{chanStream, fdStream}},
"feedchan": builtinFunc{feedchan, [2]StreamType{fdStream, chanStream}},
"unpack": builtinFunc{unpack, [2]StreamType{0, chanStream}},
"each": builtinFunc{each, [2]StreamType{chanStream, chanStream}},
"each": builtinFunc{each, [2]StreamType{chanStream, hybridStream}},
"cd": builtinFunc{cd, [2]StreamType{}},
"+": builtinFunc{plus, [2]StreamType{0, chanStream}},
"-": builtinFunc{minus, [2]StreamType{0, chanStream}},

View File

@ -31,36 +31,12 @@ type StreamType byte
// Possible values of StreamType.
const (
unusedStream StreamType = iota
fdStream // Corresponds to port.f.
chanStream // Corresponds to port.ch.
unusedStream StreamType = 0
fdStream = 1 << iota // Corresponds to port.f.
chanStream // Corresponds to port.ch.
hybridStream = fdStream | chanStream
)
// commonType returns a StreamType compatible with both StreamType's. A
// StreamType is compatible with itself or unusedStream.
func (typ StreamType) commonType(typ2 StreamType) (StreamType, bool) {
switch {
case typ == unusedStream, typ == typ2:
return typ2, true
case typ2 == unusedStream:
return typ, true
default:
return 0, false
}
}
// mayConvey returns whether port may convey a stream of typ.
func (i *port) mayConvey(typ StreamType) bool {
switch typ {
case fdStream:
return i != nil && i.f != nil
case chanStream:
return i != nil && i.ch != nil
default: // Actually case unusedStream:
return true
}
}
// closePorts closes the suitable components of all ports in ev.ports that were
// marked marked for closing.
func (ev *Evaluator) closePorts() {