-
Notifications
You must be signed in to change notification settings - Fork 14
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
Replace assembly code responsible for doing generic C calls #18
Comments
The wrapper generation will happen in the C interface generator since this generator also generates the procedure bodies. Since it is undesirable that the wrapper methods "clutter" the interface implementation files they will be stored in a separate file called *__wrapper.c. The interface implementations are currently already "cluttered" with functions that are generated for calling virtual methods. It would make sense to also store these method implementations in *__wrapper.c. |
Extended the interface generator to generate wrappers for procedures. Modified the load generator to point to the wrappers. Regenerated the parser. TODO: modify the core to work with the new wrapper signature. TODO: modify generated virtual methods & delegates to properly forward to the new signature when they detect it’s a C function.
The core is now using the new call convention consistently. It doesn’t build yet since the wrapper functions for the core-procedures are not yet implemented. TODO: generate procedures for core.
This change enforces naming conventions of the C language binding on the core by generating the interfaces. It also generates the wrappers for the core procedures, which is required because of #18. Additionally, the change also moves interface/api into the core. TODO: xml deserializer crashes on fast.xml TODO: warning in generated wrappers TODO: core is missing some procedures
This issue is solved now that dependent issue #21 is fixed. |
The file db_cdecl_x86.s contains assembly code that is capable of generically invoking subroutines without knowing their signature at compile-time. This is something that is not possible in C, hence the need for assembly (you can't manipulate the stack directly in C). Note that this is a problem only in C and C++.
The assembly however makes it very hard to port the code other platforms / architectures / compilers. To encourage porting the code to other platforms the dependency on assembly code must be removed.
An alternative approach is to wrap the calls in an interface that is mandated by the language binding. Consider the following C-function:
Suppose that now a script run by the virtual machine wants to call this function. Since the virtual machine doesn't know this function and doesn't know its signature it cannot call the function directly. However, when this function would be wrapped into a mandated interface:
... the function could be generically called from anywhere even when the callee signature is not known by the caller. This approach is likely to be faster than the assembly approach since the assembly had to figure out based on metadata how to call the function, while this approach hard-codes the mapping to a generic interface.
The only downside of this approach is that wrapper functions have to be created and executable footprint is increased by a little bit. Wrapper functions can be generated though so this wouldn't be visible for a user.
The wrapper function pointer will be stored in the "impl" field of the function.
The text was updated successfully, but these errors were encountered: