-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transient and opaque instances #79
Conversation
@lmichaelis kindly poking for code-review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about embedding checks for specific instance types directly into the VM, even if they are technically VM internals. Specifically with the transient_instance
, embedding these tests will prevent additional type checks on instances which may be unsafe.
Even though it might introduce a small performance degradation, I think we should instead opt for a more uniform virtual API through which instance members are accessed. Why did you choose to implement it this way?
include/phoenix/vm.hh
Outdated
[[nodiscard]] PHOENIX_API std::int32_t | ||
get_int(std::shared_ptr<instance>& context, | ||
std::variant<int32_t, float, symbol*, std::shared_ptr<instance>>& value, | ||
uint16_t index); | ||
[[nodiscard]] PHOENIX_API float | ||
get_float(std::shared_ptr<instance>& context, | ||
std::variant<int32_t, float, symbol*, std::shared_ptr<instance>>& value, | ||
uint16_t index); | ||
|
||
PHOENIX_API void set_int(std::shared_ptr<instance>& context, symbol* ref, uint16_t index, std::int32_t value); | ||
PHOENIX_API void set_float(std::shared_ptr<instance>& context, symbol* ref, uint16_t index, float value); | ||
PHOENIX_API void | ||
set_string(std::shared_ptr<instance>& context, symbol* ref, uint16_t index, std::string_view value); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm probably missing something here: Why are we moving the symbol accesses into a separate function? To me it looks like nothing has changed about the actual logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was introduces, when solution was callback based, yet decide to keep it - this helps avoids code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, but they should probably be private or protected then, I think, since they're basically an implementation detail.
In principle, it would be nice to have entire memory access into single function, in for example Speaking of virtual functions: can you clarify on how interface can look like? |
Maybe something like: class base_instance {
protected:
virtual int* int_storage(size_t offset) = 0;
virtual float* float_storage(size_t offset) = 0;
virtual std::string* string_storage(size_t offset) = 0;
friend class vm;
};
class instance : protected base_instance { /*...*/ }; Which is then implemented as a You need to differentiate between read an write they you could also use I might be missing something here but since we only access symbol values through |
While evaluating In interface, parameter I've considered to make solution based on |
Okay, I'm happy with that 👍. We're good to merge after making |
This is done; also decide to change |
This PR introduces 2 new special types for instances:
opaque_instance
- almost same as you propose in ticket, intended as replacement forC_SVM
,C_FightAi
transient_instance
- callback-based workflow, that delegates read/write operations to the engine.When working on Ikarus support, there are several use-cases:
opaque_instance
, likeC_SVM
- works straighttransient_instance
- allocated via mem32 framework, works straightC_ITEM
for speculative purposes (get description). This creates scenario when someC_ITEM
instances are 'normal' instances and some - transient. Should work, as mapping done atsymbol::get_*
/symbol::set_
level._@
) and create projection astransient_instance