| … | … | @@ -64,6 +64,7 @@ ValuePtr PureExecLink::execute(AtomSpace* as, |
| 64 | 64 | { |
| 65 | 65 | ValueSeq vseq; |
| 66 | 66 | AtomSpace* ctxt = nullptr; |
| 67 | AtomSpacePtr scratch = nullptr; |
| 67 | 68 | for (const Handle& h : _outgoing) |
| 68 | 69 | { |
| 69 | 70 | if (h->is_type(ATOM_SPACE)) |
| … | … | @@ -77,26 +78,30 @@ ValuePtr PureExecLink::execute(AtomSpace* as, |
| 77 | 78 | vseq.push_back(h); |
| 78 | 79 | continue; |
| 79 | 80 | } |
| 80 | | if (ctxt) |
| 81 | |
| 82 | // If we don't have a context to run in, create a scratch space. |
| 83 | if (nullptr == ctxt) |
| 81 | 84 | { |
| 82 | | ValuePtr vp(h->execute(ctxt, silent)); |
| 83 | | // Should not really happen except it sometimes does: |
| 84 | | // null pointers. Yuck. Oh well. |
| 85 | | if (nullptr == vp) |
| 86 | | continue; |
| 85 | scratch = createAtomSpace(as); |
| 86 | ctxt = scratch.get(); |
| 87 | } |
| 87 | 88 | |
| 88 | | // Special case. New context. |
| 89 | | if (vp->is_type(ATOM_SPACE)) |
| 90 | | ctxt = AtomSpaceCast(vp).get(); |
| 89 | ValuePtr vp(h->execute(ctxt, silent)); |
| 91 | 90 | |
| 92 | | vseq.emplace_back(vp); |
| 91 | // Should not really happen except it sometimes does: |
| 92 | // null pointers. Yuck. Oh well. |
| 93 | if (nullptr == vp) |
| 93 | 94 | continue; |
| 94 | | } |
| 95 | 95 | |
| 96 | | // No AtomSpace provided. Use a temporary. |
| 97 | | AtomSpacePtr scratch = createAtomSpace(as); |
| 98 | | vseq.emplace_back(h->execute(scratch.get(), silent)); |
| 99 | | scratch->clear(); |
| 96 | // Special case. New context. |
| 97 | if (vp->is_type(ATOM_SPACE)) |
| 98 | ctxt = AtomSpaceCast(vp).get(); |
| 99 | |
| 100 | vseq.emplace_back(vp); |
| 101 | |
| 102 | // If we are using a scratch space, clear it. |
| 103 | if (scratch.get() == ctxt) |
| 104 | scratch->clear(); |
| 100 | 105 | } |
| 101 | 106 | |
| 102 | 107 | return createLinkValue(std::move(vseq)); |