This is an initial port of the VM from Nim. It is not 100% complete, still missing a few things, but this seemed like a good checkpoint. This is pretty much a straight port with few modifications. Of note is that the original RuntimeState structure is broken out into c4m_vm_t and c4m_vmthread_t. The former is shared state for all threads and the latter is per-thread state. The idea is to let the host decide what constitutes a thread and where that state data comes from. It's probably not a great idea to run multiple threads against the same object code at present, as there are absolutely some data race issues that need to be addressed in some fashion, but the framework is there.
Nothing is tested since there is no code generation yet, but it builds at least on Linux (Fedora 39). There's also a handful of miscellaneous bug fixes for issues in existing C code found along the way.
Notably missing, code is commented with more explanation where appropriate:
Proper error reporting
FFI support
Marshalling
Attribute validation and default population
My plan is to do marshaling next assuming what I've done here, specifically with how the structures are laid out, is what you had in mind.
This is an initial port of the VM from Nim. It is not 100% complete, still missing a few things, but this seemed like a good checkpoint. This is pretty much a straight port with few modifications. Of note is that the original
RuntimeState
structure is broken out intoc4m_vm_t
andc4m_vmthread_t
. The former is shared state for all threads and the latter is per-thread state. The idea is to let the host decide what constitutes a thread and where that state data comes from. It's probably not a great idea to run multiple threads against the same object code at present, as there are absolutely some data race issues that need to be addressed in some fashion, but the framework is there.Nothing is tested since there is no code generation yet, but it builds at least on Linux (Fedora 39). There's also a handful of miscellaneous bug fixes for issues in existing C code found along the way.
Notably missing, code is commented with more explanation where appropriate:
My plan is to do marshaling next assuming what I've done here, specifically with how the structures are laid out, is what you had in mind.