text: void Gadget::emit (int out, Value msg) {
      //assert(_owner != nullptr);
      _owner->propagate(*this, out, msg);
  }
  
  uint16_t Circuit::add (Gadget* g) {
      auto i = _gadgets.size();
      _gadgets.append(g);
      g->_owner = this;
      g->inited();
      return i;
  }
  
  int Circuit::indexOf (Gadget& g) const {
      for (auto& e : _gadgets)
          if (e == &g)
              return &e - _gadgets.begin();
      return -1;
  }
  
  void Circuit::propagate (Gadget& src, int out, Value msg) const {
      // TODO this is immediate propagation, not yet collected messages w/ a pump
      int id = indexOf(src);
      //assert(id >= 0);
      for (auto e : _wires)
          if (id == e.s && out == e.o)
              _gadgets[e.d]->trigger(e.i, msg);
  }
  
  void Outlet::trigger (int, Value msg) {
      auto out = _owner->indexOf(*this) - _owner->_ins;
      //assert(out >= 0);
      _owner->emit(out, msg);
  }
  