-
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
Changes from all commits
8ac8887
2e43145
aa24f22
c15728a
f1f0255
cec2af7
1977b60
beecbc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from ltypes import i32, f32, dataclass, CPtr, Pointer, c_p_pointer, pointer | ||
|
||
@dataclass | ||
class A: | ||
x: i32 | ||
y: f32 | ||
|
||
@ccallable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @certik How will we support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its not supported in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Note the update - #614 (comment) |
||
def f(a: CPtr) -> None: | ||
x: i32 | ||
y: f32 | ||
a1: A | ||
a2: Pointer[A] | ||
a1 = A(3, 3.25) | ||
a2 = pointer(a1) | ||
print(a2, pointer(a1)) | ||
x = a2.x | ||
y = a2.y | ||
assert x == 3 | ||
assert y == 3.25 | ||
c_p_pointer(a, a2) | ||
print(a, a2, pointer(a1)) | ||
|
||
def g(): | ||
b: CPtr | ||
f(b) | ||
|
||
g() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from ltypes import i32, f32, dataclass, Pointer, pointer | ||
|
||
@dataclass | ||
class A: | ||
x: i32 | ||
y: f32 | ||
|
||
def f(pa: Pointer[A]): | ||
print(pa.x) | ||
print(pa.y) | ||
|
||
def g(): | ||
x: A | ||
x = A(5, 5.5) | ||
px: Pointer[A] | ||
px = pointer(x) | ||
px.x = 5 | ||
px.y = 5.5 | ||
f(px) | ||
|
||
g() |
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 becauseccallable
isn't supported there. Forstruct_03.py
I get the following error,@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 testccallable
using cpython.Regarding the above error, I think
Pointer[A]
does not work in CPython yet. That one we should get working.