mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-15 03:37:52 +08:00
Simplify StreamType
This commit is contained in:
parent
5911d955a6
commit
14ae68daf8
|
@ -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}},
|
||||
|
|
32
eval/exec.go
32
eval/exec.go
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user