-
Notifications
You must be signed in to change notification settings - Fork 170
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
Conversation
x: i32 | ||
y: f32 | ||
|
||
@ccallable |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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!!
#608
#607