-
Notifications
You must be signed in to change notification settings - Fork 2
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
Some ideas =) #1
Comments
I'm considering looking into libclang + file generation (later a template engine would help for sure): in fact you can find already a starting point in https://github.com/kunitoki/june/blob/main/tools/inspect_juce.py where it parses the juce_core.h and list all classes and methods. I was thinking about implementing a configurable system like a simple Nice idea of using cppyy, maybe it's easier to get out the reflection data there (as we can do |
Theoretically, we could use https://github.com/deech/libclang_bindings if we want to make the codegen in nim |
I've tweaked a bit the juce inspector using liblang and cindex, it's super hacky and not complete, but i was able to generate some bindings that had to manually tweak but not that much. once i had a minimal juce_core, i could add the other ones and in the end i was able to get a window on screen ! look at https://github.com/kunitoki/june/blob/main/examples/test_app.nim it's a good milestone i would say, and apart from the codegen, we need to think on how we could use nim templates and macros to make writing the boilerplate easier (because juce uses a lot of inheritance, and that's bad for the current nim c++ interop capabilites). |
because of those nim limitations, i find it hard to make a good codegen that needs no modification. for example the so i had to make all this will be difficult to do with a codegen (or it can be done, but really tedious and error prone). |
Compiling and running https://github.com/kunitoki/june/blob/main/examples/test_app.nim will produce:
Then closing the window...
|
Hello, thank you for the collaboration invite =D
I have been investigating + experimenting with converting C++ headers to Dlang
extern (C++)
bindings and also more recently to Nim.Maybe I can share some thoughts/findings with you 🙂
libclang vs LibTooling
Probably not so important for just one library, but I have been doing reading on which approach is best for translating headers to other languages + bindgen/codegen.
There are some screenshots of experiences from the authors of c2rust and dpp:
🌟 Click for relevant parts of conversation 👇
It's possible to use
cppyy
for LibTooling access, if you build LLVM on Linux/MinGW withBUILD_SHARED_LIBS
set toON
(I think it's also possible withLLVM_BUILD_DYLIB
)Doing this gives you:
API/codegen approach
I found two interesting approaches others have taken for the actual codegen that I have been experimenting with. Maybe you have some ideas?
The first
Create decorators in Python which hold rules, the argument is a
clang::QualType
orclang::Type
. Nodes are evaluated against rules, the one matching is chosen for codegen.Each class is a "frontend" driver/generator for a language to create from C++ headers. It's very clever! Currently he has:
Here is the repo where I found this. In his approach, he has used
PyBind
for binding the Clang/LibTooling C++ API to Python, which could also be used instead ofcppyy
I suppose (not sure why you'd do that)The second
Use template languages like Jinja/Moustache to create declarative template files for codegen. This allows easy visualization of what the output will be, and for people to tweak it or pass a custom template file easily.
I saw this approach here:
I imagine that if clang nodes were passed into here, and a template language was used which allowed to evaluate expressions like
t.is_pointer()
then it could actually be pretty okay.The approach with this library for evaluating expressions is by using a custom "hooks" file for defining pre-processing logic.
It's very basic though and does not use clang, but a custom Python preprocessor.
The text was updated successfully, but these errors were encountered: