eval: (*evalCtx).copy -> fork

This commit is contained in:
Qi Xiao 2016-01-28 22:04:31 +01:00
parent d0a88e4961
commit d794dbf210
3 changed files with 7 additions and 7 deletions

View File

@ -297,7 +297,7 @@ func each(ec *evalCtx, f *closure) exitus {
in := ec.ports[0].ch
in:
for v := range in {
e := f.Exec(ec.copy("closure of each"), []Value{v})
e := f.Exec(ec.fork("closure of each"), []Value{v})
switch e.Sort {
case Ok, Continue:
// nop

View File

@ -81,7 +81,7 @@ func (cp *compiler) pipeline(n *parse.Pipeline) valuesOp {
// For each form, create a dedicated evalCtx and run asynchronously
for i, op := range ops {
newEc := ec.copy(fmt.Sprintf("form op %v", op))
newEc := ec.fork(fmt.Sprintf("form op %v", op))
if i > 0 {
newEc.ports[0] = nextIn
}
@ -444,7 +444,7 @@ func (cp *compiler) outputCapture(n *parse.Primary) valuesOp {
p := n.Chunk.Begin()
return func(ec *evalCtx) []Value {
vs := []Value{}
newEc := ec.copy(fmt.Sprintf("channel output capture %v", op))
newEc := ec.fork(fmt.Sprintf("channel output capture %v", op))
pipeRead, pipeWrite, err := os.Pipe()
if err != nil {

View File

@ -143,10 +143,10 @@ func newTopEvalCtx(ev *Evaler, name, text string) (*evalCtx, chan bool) {
}, done
}
// copy returns a copy of ec. The ports are copied deeply, with shouldClose
// flags reset, and the context is changed to the given value. Other fields are
// copied shallowly.
func (ec *evalCtx) copy(newContext string) *evalCtx {
// fork returns a modified copy of ec. The ports are copied deeply, with
// shouldClose flags reset, and the context is changed to the given value.
// Other fields are copied shallowly.
func (ec *evalCtx) fork(newContext string) *evalCtx {
newPorts := make([]*port, len(ec.ports))
for i, p := range ec.ports {
newPorts[i] = &port{p.f, p.ch, false, false}