-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASR -> CPython: Add visitors for
ListConstant
, TupleConstant
& `S…
…etConstant` (#2690) * Add an aggregate visitor for `ListConstant`, `TupleConstant` and `SetConstant` * Add type annotations for `Tuple` and `Set` variables * Tests: Add tests and update references * Tests: Rename test and update references * Remove unnecessary function `std::string get_type()`
- Loading branch information
Showing
5 changed files
with
217 additions
and
30 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
13 changes: 13 additions & 0 deletions
13
tests/reference/python-test_aggregate_constants-26c89d6.json
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,13 @@ | ||
{ | ||
"basename": "python-test_aggregate_constants-26c89d6", | ||
"cmd": "lpython --no-color --show-python {infile}", | ||
"infile": "tests/test_aggregate_constants.py", | ||
"infile_hash": "e4f25c9787536c0ecc60a1d53b4bca5f250e2a4f3646b45565867e86", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": "python-test_aggregate_constants-26c89d6.stdout", | ||
"stdout_hash": "813b11b4ee92df0eebccb3031a1b73355957795a72b487115093c3ce", | ||
"stderr": null, | ||
"stderr_hash": null, | ||
"returncode": 0 | ||
} |
74 changes: 74 additions & 0 deletions
74
tests/reference/python-test_aggregate_constants-26c89d6.stdout
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,74 @@ | ||
def __main__global_init(): | ||
my_first_list = [1, 2, 3, 4] | ||
my_second_list = ["a", "b", "c", "d"] | ||
my_third_list = [[1, 2], [3, 4], [5, 6]] | ||
my_fourth_list = [[1.000000, 2.200000], [3.600000, 4.900000], [5.100000, 6.300000]] | ||
my_fifth_list = [{"a", "b"}, {"c", "d"}] | ||
my_sixth_list = [(1, "a"), (2, "b")] | ||
my_first_tuple = (1, "hello", 2.400000) | ||
my_second_tuple = ((1, "hello"), "world") | ||
my_third_tuple = (["hello", "world"], "world") | ||
my_fourth_tuple = ({"hello", "world"}, "world") | ||
my_first_set = {1, 2, 3, 2, 4} | ||
my_second_set = {1.100000, 2.500000, 6.800000} | ||
my_third_set = {"a", "b", "a", "c"} | ||
my_fourth_set = {(1, "a"), (2, "b"), (3, "c")} | ||
def __main__global_stmts(): | ||
print(my_first_list) | ||
print(my_second_list) | ||
print(my_third_list) | ||
print(my_fourth_list) | ||
print(my_fifth_list) | ||
print(my_sixth_list) | ||
print(my_first_tuple) | ||
print(my_second_tuple) | ||
print(my_third_tuple) | ||
print(my_fourth_tuple) | ||
print(my_first_set) | ||
print(my_second_set) | ||
print(my_third_set) | ||
print(my_fourth_set) | ||
fn() | ||
def fn(): | ||
my_fifth_list: list[set[str]] | ||
my_first_list: list[i32] | ||
my_first_set: set[i32] | ||
my_first_tuple: tuple[i32, str, f64] | ||
my_fourth_list: list[list[f64]] | ||
my_fourth_set: set[tuple[i32, str]] | ||
my_fourth_tuple: tuple[set[str], str] | ||
my_second_list: list[str] | ||
my_second_set: set[f64] | ||
my_second_tuple: tuple[tuple[i32, str], str] | ||
my_sixth_list: list[tuple[i32, str]] | ||
my_third_list: list[list[i32]] | ||
my_third_set: set[str] | ||
my_third_tuple: tuple[list[str], str] | ||
my_first_list = [1, 2, 3, 4] | ||
print(my_first_list) | ||
my_second_list = ["a", "b", "c", "d"] | ||
print(my_second_list) | ||
my_third_list = [[1, 2], [3, 4], [5, 6]] | ||
print(my_third_list) | ||
my_fourth_list = [[1.000000, 2.200000], [3.600000, 4.900000], [5.100000, 6.300000]] | ||
print(my_fourth_list) | ||
my_fifth_list = [{"a", "b"}, {"c", "d"}] | ||
print(my_fifth_list) | ||
my_sixth_list = [(1, "a"), (2, "b")] | ||
print(my_sixth_list) | ||
my_first_tuple = (1, "hello", 2.400000) | ||
print(my_first_tuple) | ||
my_second_tuple = ((1, "hello"), "world") | ||
print(my_second_tuple) | ||
my_third_tuple = (["hello", "world"], "world") | ||
print(my_third_tuple) | ||
my_fourth_tuple = ({"hello", "world"}, "world") | ||
print(my_fourth_tuple) | ||
my_first_set = {1, 2, 3, 2, 4} | ||
print(my_first_set) | ||
my_second_set = {1.100000, 2.500000, 6.800000} | ||
print(my_second_set) | ||
my_third_set = {"a", "b", "a", "c"} | ||
print(my_third_set) | ||
my_fourth_set = {(1, "a"), (2, "b"), (3, "c")} | ||
print(my_fourth_set) |
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,97 @@ | ||
from lpython import i32, f64 | ||
|
||
# Test codegen for global scope | ||
|
||
# List | ||
my_first_list: list[i32] = [1, 2, 3 , 4] | ||
print(my_first_list) | ||
|
||
my_second_list: list[str] = ["a", "b", "c", "d"] | ||
print(my_second_list) | ||
|
||
my_third_list: list[list[i32]] = [[1, 2], [3, 4], [5, 6]] | ||
print(my_third_list) | ||
|
||
my_fourth_list: list[list[f64]] = [[1.0, 2.2], [3.6, 4.9], [5.1, 6.3]] | ||
print(my_fourth_list) | ||
|
||
my_fifth_list: list[set[str]] = [{"a", "b"}, {"c", "d"}] | ||
print(my_fifth_list) | ||
|
||
my_sixth_list: list[tuple[i32, str]] = [(1, "a"), (2, "b")] | ||
print(my_sixth_list) | ||
|
||
# Tuple | ||
my_first_tuple: tuple[i32, str, f64] = (1, "hello", 2.4) | ||
print(my_first_tuple) | ||
|
||
my_second_tuple: tuple[tuple[i32, str], str] = ((1, "hello"), "world") | ||
print(my_second_tuple) | ||
|
||
my_third_tuple: tuple[list[str], str] = (["hello", "world"], "world") | ||
print(my_third_tuple) | ||
|
||
my_fourth_tuple: tuple[set[str], str] = ({"hello", "world"}, "world") | ||
print(my_fourth_tuple) | ||
|
||
# Set | ||
my_first_set: set[i32] = {1, 2, 3, 2, 4} | ||
print(my_first_set) | ||
|
||
my_second_set: set[f64] = {1.1, 2.5, 6.8} | ||
print(my_second_set) | ||
|
||
my_third_set: set[str] = {"a", "b", "a", "c"} | ||
print(my_third_set) | ||
|
||
my_fourth_set: set[tuple[i32, str]] = {(1, "a"), (2, "b"), (3, "c")} | ||
print(my_fourth_set) | ||
|
||
# Test codegen for local scope | ||
def fn(): | ||
# List | ||
my_first_list: list[i32] = [1, 2, 3 , 4] | ||
print(my_first_list) | ||
|
||
my_second_list: list[str] = ["a", "b", "c", "d"] | ||
print(my_second_list) | ||
|
||
my_third_list: list[list[i32]] = [[1, 2], [3, 4], [5, 6]] | ||
print(my_third_list) | ||
|
||
my_fourth_list: list[list[f64]] = [[1.0, 2.2], [3.6, 4.9], [5.1, 6.3]] | ||
print(my_fourth_list) | ||
|
||
my_fifth_list: list[set[str]] = [{"a", "b"}, {"c", "d"}] | ||
print(my_fifth_list) | ||
|
||
my_sixth_list: list[tuple[i32, str]] = [(1, "a"), (2, "b")] | ||
print(my_sixth_list) | ||
|
||
# Tuple | ||
my_first_tuple: tuple[i32, str, f64] = (1, "hello", 2.4) | ||
print(my_first_tuple) | ||
|
||
my_second_tuple: tuple[tuple[i32, str], str] = ((1, "hello"), "world") | ||
print(my_second_tuple) | ||
|
||
my_third_tuple: tuple[list[str], str] = (["hello", "world"], "world") | ||
print(my_third_tuple) | ||
|
||
my_fourth_tuple: tuple[set[str], str] = ({"hello", "world"}, "world") | ||
print(my_fourth_tuple) | ||
|
||
# Set | ||
my_first_set: set[i32] = {1, 2, 3, 2, 4} | ||
print(my_first_set) | ||
|
||
my_second_set: set[f64] = {1.1, 2.5, 6.8} | ||
print(my_second_set) | ||
|
||
my_third_set: set[str] = {"a", "b", "a", "c"} | ||
print(my_third_set) | ||
|
||
my_fourth_set: set[tuple[i32, str]] = {(1, "a"), (2, "b"), (3, "c")} | ||
print(my_fourth_set) | ||
|
||
fn() |
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