Open edubart opened 9 months ago
Those changes would help as well with the Node.js binding I'm working on. I have ~400 lines (probably badly written) only to handle config.
Side node: cm_reset_uarch
should be called cm_reset_uarch_halt_flag
, for consistency with other reset methods.
That’s not what it does. It really resets the entirety of uarch. Including RAM and all other registers.
That’s not what it does. It really resets the entirety of uarch. Including RAM and all other registers.
So documentation should be fixed. https://github.com/cartesi/machine-emulator/blob/77fb1736e280720921292f9175f0a0217b9804cf/src/machine-c-api.h#L1845
@mpernambuco can you take a look?
@mpernambuco can you take a look?
I wanted to relate our experience on creating Rust binding.
cartesi-machine.lua
. I also copied some of the asserts.I was initially confused me about the machine config. I think it's because there are instances of it created and managed by us (like in the create function), and there are instances of it created and managed by the emulator. It was easy to deal with the one created and managed by the emulator. I had no problem accessing the fields. No problem freeing memory either, we just need to wrap it in another Rust object and implement Drop
correctly.
On using json for machine config. For creating a machine, I think that may help a lot. For querying the machine about the initial config, I think it would not be super ergonomic, but it would be easy, and it may be the best solution
I have a feeling most users will be after the same few fields in the machine config (like the address and length of the tx/rx buffer). Maybe dedicated methods to read commonly needed fields could help?
Or maybe specific functions for common operations, like clearing rx/tx buffer. Or writing an input (setting all the correct registers and buffers). Or reading an input (parsing all the correct registers). I was copying these operations from cartesi-machine.lua
. Having them on the API would be more ergonomic, but I don't know if it makes sense. It could give you more freedom to change things though.
Context
Our C API is currently being used to create machine bindings in Lua, Rust, Go and TypeScript languages. Since this, we noticed there are some pain points when creating C bindings in those languages, we could make a refactor to improve it, make it smaller and simpler.
Subtasks
uint64
into a single write/read method shared for all registers and CSRs, and use a new enumeration.cm_get_last_error_message(machine)
.cm_delete_*
methods, for examplecm_delete_semantic_version
could be removed by making it always static allocated.cm_merkle_tree_proof
we could removecm_delete_merkle_tree_proof
. Similar we could maybe removecm_delete_memory_range_config
andcm_delete_memory_range_descr_array
.