-
Notifications
You must be signed in to change notification settings - Fork 779
Proof of concept for autogenerating the C API for expressions #6291
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
base: main
Are you sure you want to change the base?
Conversation
Do you think this will scale to everything we will need, or do you think we will need to fall back to something like parsing wasm-delegations-fields.h with a Python script that then generates the APIs? |
Heh, you can see I fixed up capitalization and simple plurals, but not interesting ones yet... 😄 Fixing those would add a little code, but the number of such English oddities is pretty short for our use case here. I don't think a Python script could do anything more than this? It's all really very simple stuff. Though it would also be simple to parse it from Python, if we preferred that. I think last time we discussed this topic the preference was less Python and more C++ but I don't feel strongly either way. |
I just had a thought: It might improve readability if we first use the macros to collect information about each expression and its contents in some simple data structure, then separately emit the generated code based on that data structure. The main benefit would be that the macros and the core code generation logic could be understood and read separately. |
I suspect this approach might be a good example of the Pareto law i.e. 80% of the entry points are simple enough to be generated at 20% of the cost. But for complex entry points (such as |
@ericvergnaud This would not help with I do think that all Expressions are automatable (is that a word? 🤔 ). They are really just repeated boilerplate, and a lot of it. |
What about exceptions like |
Possibly there are more exceptions, since we didn't have a specific convention for most of the time. There isn't a way to know except to check, I'm afraid. But I would hope the amount is very small. |
This just handles child expressions and vectors of them, but hopefully shows what can be done here.
For example:
Those few lines take the ID of a class and the field name of that class, where the field is a vector of children, such as
Call
which has theoperands
list of values we send in the call. It generates this:The same code also generates proper code for all other vector fields like that, here is a sample (including non-vector fields too):
All that is autogenerated. The proof of concept here that generates API calls for children and vectors of them emits 139 bindings so far.
The benefit is that after writing stuff like the 4 lines at the top of this comment then we can autogenerate all relevant bindings automatically with no manual work per class or per field. And whenever we add new classes we can add support for them by just running the tool, with no manual work at all.
We could similarly autogenerate other bindings perhaps, like the JS API and others.