-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BindPython ASR Pass: aggregate type conversions (#2803)
* native to cpython tuple conversion and refactoring * PythonBind ABI: native to cpython list conversion * PythonBind ABI: native to cpython set conversion Backend does not support yet. * PythonBind ABI: native to cpython dict conversion * PythonBind ABI: cpython to native list conversion * PythonBind ABI: cpython to native tuple conversion * PythonBind ABI: cpython to native set conversion * PythonBind ABI: cpython to native dict conversion * PythonBind ABI: testing aggregate type conversions * NOFAST for bindpy_06 test
- Loading branch information
1 parent
61a27d5
commit ba2dff6
Showing
4 changed files
with
699 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from lpython import i32, f64, pythoncall, Const | ||
from numpy import empty, int32, float64 | ||
|
||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_cpython_version() -> str: | ||
pass | ||
|
||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_modified_dict(d: dict[str, i32]) -> dict[str, i32]: | ||
pass | ||
|
||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_modified_list(d: list[str]) -> list[str]: | ||
pass | ||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_modified_tuple(t: tuple[i32, i32]) -> tuple[i32, i32, i32]: | ||
pass | ||
|
||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_modified_set(s: set[i32]) -> set[i32]: | ||
pass | ||
|
||
|
||
def test_list(): | ||
l: list[str] = ["LPython"] | ||
lr: list[str] = get_modified_list(l) | ||
assert len(lr) == 2 | ||
assert lr[0] == "LPython" | ||
assert lr[1] == "LFortran" | ||
|
||
|
||
def test_tuple(): | ||
t: tuple[i32, i32] = (2, 4) | ||
tr: tuple[i32, i32, i32] = get_modified_tuple(t) | ||
assert tr[0] == t[0] | ||
assert tr[1] == t[1] | ||
assert tr[2] == t[0] + t[1] | ||
|
||
|
||
def test_set(): | ||
s: set[i32] = {1, 2, 3} | ||
sr: set[i32] = get_modified_set(s) | ||
assert len(sr) == 4 | ||
assert 1 in sr | ||
assert 2 in sr | ||
assert 3 in sr | ||
assert 100 in sr | ||
|
||
|
||
def test_dict(): | ||
d: dict[str, i32] = { | ||
"LPython": 50 | ||
} | ||
dr: dict[str, i32] = get_modified_dict(d) | ||
assert len(dr) == 2 | ||
assert dr["LPython"] == 50 | ||
assert dr["LFortran"] == 100 | ||
|
||
|
||
def main0(): | ||
test_list() | ||
test_tuple() | ||
test_set() | ||
test_dict() | ||
|
||
|
||
main0() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import platform | ||
|
||
|
||
def get_cpython_version(): | ||
return platform.python_version() | ||
|
||
|
||
def get_modified_dict(d): | ||
d["LFortran"] = 100 | ||
return d | ||
|
||
|
||
def get_modified_list(l): | ||
l.append("LFortran") | ||
return l | ||
|
||
|
||
def get_modified_tuple(t): | ||
return (t[0], t[1], t[0] + t[1]) | ||
|
||
|
||
def get_modified_set(s): | ||
s.add(100) | ||
return s |
Oops, something went wrong.