Open edubart opened 6 days ago
Addressed some comments:
cm_write_word
.cm_replace_memory_range
*_uarch_step*
-> *_step_uarch*
pc
and uarch_pc
.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.
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?
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.
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).
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:
CM_MCYCLE_MAX
macro and set toUINT64_MAX
CM_ACCESS_LOG_TYPE
enum with bitwise flags for access log typecm_get_last_error_message
/cm_jsonrpc_get_last_error_message
, returning the error message for the most recent failed call.cm_get_default_runtime_config
/cm_jsonrpc_get_default_runtime_config
, for now it will return just{}
, but we might in the future return a value based on current environment variables, like the Cartesi Node does. People also asked for this function.CM_CSR_HTIF_TOHOST_DEV
), the idea is to write on fields of these CSRs throughcm_write_csr
/cm_read_csr
.CM_CSR_IFLAGS_H
), the idea is to write on fields of these CSRs throughcm_write_csr
/cm_read_csr
.Removed:
cm_read_*
/cm_write_*
of CSRs, except formcycle
/uarch_cycle
/uarch_halt_flag
.cm_delete_*
functions, now any function that returns a string guarantees to maintain the validity of the string pointer until next API call or machine destruction.cm_new_default_machine_config
cm_reset_iflags_*
/cm_set_iflags_*
/cm_packed_iflags
,iflags
can be read/written using CSR viewsCM_CSR_IFLAGS_PRV
,CM_CSR_IFLAGS_X
,CM_CSR_IFLAGS_Y
,CM_CSR_IFLAGS_H
.machine-c-defines.h
header, its contents was moved tomachine-c-api.h
.Renames:
*_uarch_reset*
->*_reset_uarch*
*_uarch_step*
->*_step_uarch*
cm_machine_run
->cm_run
cm_create_machine
->cm_create
cm_load_machine
->cm_load
,cm_machine_run_uarch
->cm_run_uarch
CM_PROC_CSR
->CM_CSR
cm_create_jsonrpc_machine
->cm_jsonrpc_create_machine
cm_load_jsonrpc_machine
->cm_jsonrpc_load_machine
cm_get_jsonrpc_machine
->cm_jsonrpc_get_machine
cm_create_jsonrpc_mgr
->cm_jsonrpc_create_mgr
cm_delete_jsonrpc_mgr
->cm_jsonrpc_destroy_mgr
Changed:
err_msg
arguments were removed, the latest error message can be retrieved fromcm_get_last_error_message()
.cm_replace_memory_range
, now it takes multiple arguments instead of a struct argument.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.
_machine
from some methods is that most API are related to the machine yet they don't contain the machine word, so here we make this the standard.cm_jsonrpc_
, this makes it easier for binding generators to categorize and filter jsonrpc related methods.cm_destroy
andcm_jsonrpc_destroy_mgr
.