cartesi / machine-emulator

The off-chain implementation of the Cartesi Machine
GNU Lesser General Public License v3.0
58 stars 32 forks source link

refactor!: design new simplified C API #253

Open edubart opened 6 days ago

edubart commented 6 days ago

This PR is very WIP, it will be a long road before this is finished and polished. I created the PR before the time so I can document here a changelog of what is being changed while I change them. Also to request for comments on the changes.

You can look around the C API files to see how the new simplified API feels. I have also update each function documentation along the way.

Changes

Added:

Removed:

Renames:

Changed:

Changes rationale

First have in mind the goal of the changes was to simplify usage of the C API in other languages, to minimize the binding work and make easier to create binding generators.

edubart commented 4 days ago

Addressed some comments:

diegonehab commented 4 days ago

Addressed some comments:

* Avoid splitting IFLAGS, introduce CSR views of its fields instead, to avoid creating unpack/pack methods.

* Removed addition of `cm_write_word`.

* Improved documentation of `cm_replace_memory_range`

* Renamed `*_uarch_step*` -> `*_step_uarch*`

* Removed read/write for CSRs `pc` and `uarch_pc`.

I think we should keep reset_iflags_Y at least. And we might want to keep read_iflags_X, read_iflags_Y, and read_iflags_H just because everybody uses them.

diegonehab commented 4 days ago

One thing to consider. Are we doing to offer a “raw” version of these JSON functions in the binds, ones that return/receive JSON and other that receive/return parsed objects (like lua tables) or not?

edubart commented 4 days ago

One thing to consider. Are we doing to offer a “raw” version of these JSON functions in the binds, ones that return/receive JSON and other that receive/return parsed objects (like lua tables) or not?

I think I could try making a generic function to translate JSON <-> Lua table, so we don't use raw JSON strings on Lua side. In the worst case if that turns out to be a bit of work or having flaws (such as JSON special values like its NULL), we could have a raw JSON string and on Lua side and use lua-dkjson. For now my concerns is the C API, later I will think more about Lua goodies.

edubart commented 4 days ago

I updated the PR adding back some iflags methods and trying to clarify more how string lifetime for JSON will work (thread local storage per function).