Open
Description
We should allow calling C functions by directly importing them from C header files. We have to parse the header file, and create the corresponding declaration in ASR. In pure Python mode, we have to implement some equivalent functionality using some of the projects below.
Prior art:
- Zig: https://ziglang.org/documentation/master/#Import-from-C-Header-File
- CFFI: https://cffi.readthedocs.io/en/latest/
- cppyy: https://cppyy.readthedocs.io/en/latest/
- pycparser: https://github.com/eliben/pycparser
- pyheaders: https://github.com/Roynecro97/pyheaders
- robotpy-cppheaderparser: https://github.com/robotpy/robotpy-cppheaderparser
Metadata
Metadata
Assignees
Labels
No labels
Activity
certik commentedon Jun 1, 2022
To keep things simple, possibly a good way is to first write a script that takes a C headerfile and produces an equivalent Python file with C declarations using
@ccall. That way we do not need any special handling in LPython and things are explicit and automatic. Once we gain more experience, we can include a C parser as part of libasr and/or lpython.