lpython icon indicating copy to clipboard operation
lpython copied to clipboard

BindPython ABI

Open Vipul-Cariappa opened this issue 1 year ago • 5 comments

Vipul-Cariappa avatar Aug 02 '24 15:08 Vipul-Cariappa

The right solution here is to have an ASR->ASR pass that takes the bind(Python) and replaces it with calls to Python C/API. This should not be hardwired into all the backends.

If you think you can get something working with relatively short code, you can finish the PR, but I think having a pass is a better solution long term.

certik avatar Aug 03 '24 07:08 certik

The right solution here is to have an ASR->ASR pass that takes the bind(Python) and replaces it with calls to Python C/API. This should not be hardwired into all the backends.

Yes. I am implementing this using an ASR to ASR pass. The python_bind.py implements the ASR to ASR pass.

Vipul-Cariappa avatar Aug 03 '24 10:08 Vipul-Cariappa

@Shaikh-Ubaid, @certik, Please have a look at this. This ASR pass currently supports, primitive datatypes, i.e. integers, unsigned integers, floats, and strings. I will add support for arrays in the following PRs. I have not tested this in interactive mode. I will also do it in the following PRs.

Vipul-Cariappa avatar Aug 05 '24 04:08 Vipul-Cariappa

Otherwise it looks like the right approach, it seems you are doing the type translation to/from Python in the ASR->ASR pass already, which is perfect.

certik avatar Aug 05 '24 15:08 certik

@Shaikh-Ubaid, I believe if the CI passes and these changes look good to you, then we can merge.

Vipul-Cariappa avatar Aug 11 '24 14:08 Vipul-Cariappa

@certik The tests that use arrays (i.e. call into a CPython function that accepts arrays or returns an array) are skipped. Conversion from LPython arrays to CPython arrays (numpy array) needs to be implemented. I will do it in the next PR.

Vipul-Cariappa avatar Aug 12 '24 06:08 Vipul-Cariappa