r/Compilers • u/Routine_School_1966 • Jun 26 '26
I’m thinking about building a crazy language that lets you mix Python and C++ libraries, handles memory, and spits out a standard C file. Does this sound like a tool you’d use it or it'd help you ?
Hi everyone,
I've been obsessing over a workflow bottleneck lately: the absolute nightmare of writing glue-code (Cython, Pybind11, manual wrappers) just to make rapid Python logic talk to high-performance C++ libraries.
So, I’m conceptualizing a "glue language" to fix this once and for all.
would this language help you?
0
Upvotes
12
u/Farados55 Jun 26 '26
I think it’s called Cython
5
u/javascript Jun 26 '26
Why not just write everything in C++ if you're willing to go through the build step?
2
u/mamcx Jun 26 '26
YES | NO | MAYBE?Your pitch is too vague! You need to give more details to us have a clue what to say.
1
u/math_code_nerd5 Jul 14 '26
More important than a language, in my opinion, would be IDE-type software to automate the compilation process, and do things like add the necessary type checks on the Python side to be sure it's giving the C code the types it has been compiled for, as well as to generate the boilerplate on the C side to allow importing from Python and to wrap/unwrap the Python objects. In other words, you'd point it to the directory of your Python install and it would automatically set up the compiler with all the headers it needs to include in order to be able to compile the C file, all you'd have to give it was the C file with a set of functions and the parameters/types it takes. Then it would put the compiled object file in the right place to be importable from Python, as well as write the Python stub with the corresponding parameters.
Trying to mix Python and C isn't really a worthwhile goal, you generally want a quite bright-line interface. C code works best when all containers contain elements of identical type that don't change run to run, when the size of all "scratch space" for the computation is known at call time (in other words, you're not consuming or generating lists of things that expand or contract in size on the fly--rather it's something like "for each float in this input list, emit two integers"), and where by-value types like dicts can be replaced by static enums. Python works best to take a "messy" problem and rearrange it to this form.
What's annoying though is that you can't just compile a my_module.c file defining my_function() with any random compiler and tell Python to import it, so something that would make it "that easy" would be a great help. It's like with Shadertoy, the website relieves you of the need to tell your browser HOW it should use your shader and where it should pipe the values emitted by the shader, so you can work totally in "shader land". Where solutions like Numba and Cython fall short is that they firstly try to turn something like Python INTO C, which means you have to "think in" Python while still making sure not to use the "messy" aspects OF Python that will negate all the benefit, and also these tools (particularly Numba) become part of the runtime toolchain of your software, bloating it very considerably.
2
u/[deleted] Jun 27 '26
[removed] — view removed comment