sparkslabs/pyxie

Compiling Python functions to C++

jarble opened this issue · 4 comments

Is Pyxie currently able to compile Python functions to C++ functions?

For example, it should be possible to compile this Python function:

def add(a,b):
    return a + b

...and generate a C++ function, using auto to infer the parameter types:

auto add(auto a, auto b){
    return a + b;
}

At present no.

I've used this sort of approach before with Pyxie's predecessor (pycc / py2cc), but not with Pyxie.

Will it do this? At some point, but at present (and for some time), life and then life/pandemic has somewhat gotten in the way of this sort of thing recently.

What I'm planning on doing in pyxie (when I get around to it) is proper type inference, that falls back to auto (Which is equivalent to saying a pling type in something like SML that has full type inference). For that I've been testing a bunch of ideas in a local repo.

Can it work and can it work well though? Absolutely. Up to a point, but that point might be useful to you. I'm not likely to get around to implementing this any time soon and I think the codebase internals really need an overhaul before doing that... Would be fun though :-)

BTW, I see you've got your own transpiler project - which looks neat. If you're primarily asking for a sanity check as to whether it works - yes it does. I think as an easy win it's a pretty good way of doing things. In the other projects I mention, I had a general rule that variables had to be initialised with a value. This meant that I could sidestep full type inference.

With pyxie I'm a bit more interested in the type inference approach because of how I want to integrate with other systems and libaries. And just because :-)

Dunno how that fits in with your question, but your projects just struck me as related on some level and interesting, so I thought a bit more context might be useful.

It is possible to infer types of functions using mypy, including generic types, so it might be a good starting point for a project like this.

I also found an implementation of Hindley-Milner type inference in Python, which may be useful as well.

Yes, I am aware of both of these. If you want to use them, use them. I'm closing this issue now since it isn't relevant to me.
You seem to have ignored the comment about there being more important things in my life right now.