Skip to content

Support for pointer to structs #614

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

Merged
merged 8 commits into from
Jun 17, 2022
Merged

Conversation

czgdp1807
Copy link
Collaborator

@czgdp1807 czgdp1807 commented Jun 16, 2022

@czgdp1807 czgdp1807 added asr ASR related changes llvm LLVM related changes labels Jun 16, 2022
x: i32
y: f32

@ccallable
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@certik How will we support ccallable in CPython?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its not supported in LPython as well. What do we mean by ccallable? Anything that can be called from C code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. LPython supports it, it works with both LLVM and C. It can't work with CPython, since we can't build the C library that expects this function. The only way to support it from CPython would be to somehow expose LPython as a Python library and use it to generate C code, and then link it, etc. Too complex, we can maybe do that later, but for now we do not support @ccallable in CPython.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following error,

semantic error: Decorator: ccallable is not supported
  --> integration_tests/structs_02.py:10:1 - 17:12
   |
10 |    def f(a: CPtr) -> None:
   |    ^^^^^^^^^^^^^^^^^^^^^^^...
...
   |
17 |        y = a2.y
   | ...^^^^^^^^^^^^ 


Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that needs to be fixed).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the update - #614 (comment)

@@ -1978,7 +1978,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
if (name == "ccall") {
current_procedure_abi_type = ASR::abiType::BindC;
current_procedure_interface = true;
} else if (name == "ccallback") {
} else if (name == "ccallback" || name == "ccallable") {
current_procedure_abi_type = ASR::abiType::BindC;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the above change make sense? @certik

@czgdp1807 czgdp1807 marked this pull request as ready for review June 16, 2022 14:40
@czgdp1807 czgdp1807 requested a review from certik June 16, 2022 14:41
@@ -169,6 +169,8 @@ RUN(NAME test_unary_minus LABELS cpython llvm)
RUN(NAME test_unary_plus LABELS cpython llvm)
RUN(NAME test_issue_518 LABELS cpython llvm)
RUN(NAME structs_01 LABELS cpython llvm)
RUN(NAME structs_02 LABELS llvm)
RUN(NAME structs_03 LABELS llvm)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can figure out, structs_02.py isn't possible with CPython because ccallable isn't supported there. For struct_03.py I get the following error,

Traceback (most recent call last):
  File "/Users/czgdp1807/lpython_project/lpython/integration_tests/structs_03.py", line 8, in <module>
    def f(pa: Pointer[A]):
TypeError: 'type' object is not subscriptable

@certik Do you know how to fix the above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPython can't use ccallable, at least in the near future. The only way to make it work is by wrapping LPython itself into Python and calling it to take care of this. Which might not be a bad idea, but it's heavyweight and we should do that later. For now we won't test ccallable using cpython.

Regarding the above error, I think Pointer[A] does not work in CPython yet. That one we should get working.

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine to merge, thanks!!

@czgdp1807 czgdp1807 merged commit 70fef49 into lcompilers:main Jun 17, 2022
@czgdp1807 czgdp1807 deleted the structs_03 branch June 17, 2022 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asr ASR related changes llvm LLVM related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants