50 bool install(
const char* path, std::uint64_t expected,
53 std::optional<std::uint64_t> expectedContract = std::nullopt) {
57 if (!next.module_.
open(path, expected, why))
return false;
58 if (expectedContract && next.module_.
contract() != 0 && next.module_.
contract() != *expectedContract) {
59 if (why) *why =
"module and manifest are from different builds";
62 next.components_ = components;
63 next.resources_ = resources;
64 next.candidates_ = candidates;
66 next.names_.push_back(decl.name !=
nullptr ? decl.name :
"");
67 next.bound_.push_back(
::esengine::aot::bind(decl, next.components_, next.resources_, next.candidates_));
69 next.arenas_ = std::vector<CallArena>(next.bound_.size());
71 std::swap(module_, next.module_);
72 names_.swap(next.names_);
73 bound_.swap(next.bound_);
74 arenas_.swap(next.arenas_);
75 components_.swap(next.components_);
76 resources_.swap(next.resources_);
77 candidates_.swap(next.candidates_);
82 std::size_t
count()
const {
return bound_.size(); }
86 std::uint64_t
contract()
const {
return module_.contract(); }
89 const char*
nameAt(std::size_t i)
const {
return i < names_.size() ? names_[i] :
""; }
92 bool boundAt(std::size_t i)
const {
return i < bound_.size() && bound_[i].fn !=
nullptr; }
102 if (i >= bound_.size() || bound_[i].fn ==
nullptr)
return false;
103 return ::esengine::aot::narrows(bound_[i].queries);
108 for (std::size_t i = 0; i < names_.size(); ++i) {
109 if (names_[i] !=
nullptr && name !=
nullptr && std::strcmp(names_[i], name) == 0)
return i;
122 std::span<const EsCmd>
run(std::size_t i, std::span<const std::uint32_t> candidates,
124 if (i >= bound_.size())
return {};
128 if (bound_[i].fn ==
nullptr) {
132 if (bound_[i].fn ==
nullptr)
return {};
133 bool runnable =
false;
134 const auto commands =
runBound(bound_[i], candidates, resources, arenas_[i], world, &runnable);
135 if (!runnable) bound_[i].fn =
nullptr;
141 return i < arenas_.size() ? arenas_[i].candidatesWalked() : 0u;
147 return i < arenas_.size() ? arenas_[i].rowsPacked() : 0u;
161 static constexpr std::size_t
npos =
static_cast<std::size_t
>(-1);
165 std::vector<const char*> names_;
166 std::vector<BoundSystem> bound_;
175 std::vector<CallArena> arenas_;
The host half of the Estella ABI.
A built module of compiled systems, opened by a host that links.
std::span< const EsCmd > run(std::size_t i, std::span< const std::uint32_t > candidates, const ResourceLookup &resources, WorldStamp world={})
bool install(const char *path, std::uint64_t expected, const ComponentLookup &components, const ResourceLookup &resources, std::string *why=nullptr, const CandidateLookup &candidates={}, std::optional< std::uint64_t > expectedContract=std::nullopt)
bool boundAt(std::size_t i) const
const char * nameAt(std::size_t i) const
std::uint32_t rowsPacked(std::size_t i) const
std::uint32_t candidatesWalked(std::size_t i) const
std::size_t count() const
static constexpr std::size_t npos
std::uint64_t contract() const
std::size_t indexOf(const char *name) const
bool narrowsAt(std::size_t i) const
std::uint64_t contract() const
std::span< const EsSystemDecl > systems() const
bool open(const char *path, std::uint64_t expected, std::string *why=nullptr)
std::function< CandidatesOf(const char *)> CandidateLookup
std::function< void *(const char *)> ResourceLookup
std::span< const EsCmd > runBound(const BoundSystem &bound, std::span< const std::uint32_t > fallback, const ResourceLookup &resources, CallArena &arena, WorldStamp world={}, bool *runnable=nullptr)
std::function< ComponentAt(const char *)> ComponentLookup
BoundSystem bind(const EsSystemDecl &decl, const ComponentLookup &components, const ResourceLookup &resources, const CandidateLookup &candidates={})