Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[asr-python] remove extra lines in codegen #2590

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 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/libasr/codegen/asr_to_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,13 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
if (is_a<ASR::Module_t>(*item.second)) {
visit_symbol(*item.second);
r += s;
r += "\n";
}
}

for (auto &item : x.m_symtab->get_scope()) {
if (is_a<ASR::Function_t>(*item.second)) {
visit_symbol(*item.second);
r += s;
r += "\n";
}
}

Expand Down Expand Up @@ -240,8 +238,6 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
r += s;
}
}

r += "\n";
s = r;
}

Expand Down Expand Up @@ -347,7 +343,6 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
visit_stmt(*x.m_orelse[i]);
r += s;
dec_indent();
r += "\n";
}
}
s = r;
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/python-assert1-192ca6c.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "python-assert1-192ca6c.stdout",
"stdout_hash": "2120f9dd9a8d41e4d67cced7ceb14c4ded9d56335058f66b24cfe12e",
"stdout_hash": "0de7de97bd936f6a66e73ba9789e50ed968b66edce04acfcc168c6db",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 0 additions & 2 deletions tests/reference/python-assert1-192ca6c.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ def test_assert():
a = 5
assert (a) == (5), "a is not 5"
assert (a) != (10)


2 changes: 1 addition & 1 deletion tests/reference/python-assign1-f87bafa.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "python-assign1-f87bafa.stdout",
"stdout_hash": "6fa5f5e1492cac718631d3c05d27ab2ddda15dd2e56cc37a1ce188b9",
"stdout_hash": "bd60a7791394a67503473530adb0369f2f12407e0108423397f3e4e4",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 0 additions & 2 deletions tests/reference/python-assign1-f87bafa.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ def test_augassign():
r = r / s
a = ""
a = a + "test"


2 changes: 1 addition & 1 deletion tests/reference/python-expr11-e6681c8.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "python-expr11-e6681c8.stdout",
"stdout_hash": "6ae1afc8767434e703cfd38bbdd22275c73effa90a5e86c5c09bab5b",
"stdout_hash": "425a18a0b44e596e166ce94fad47878623b4dd9b4d534419b7f18683",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 0 additions & 2 deletions tests/reference/python-expr11-e6681c8.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ def test_StrOp_repeat():
s = "bb" * 4
s = "bb" * -(40)
s = "a" * 3 * 3


13 changes: 13 additions & 0 deletions tests/reference/python-expr14-2e6ab03.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "python-expr14-2e6ab03",
"cmd": "lpython --no-color --show-python {infile}",
"infile": "tests/expr14.py",
"infile_hash": "d18abc152939c944f6a1e493754cea8b72f0d03d360ab4c9e75ad697",
"outfile": null,
"outfile_hash": null,
"stdout": "python-expr14-2e6ab03.stdout",
"stdout_hash": "52e647db794a391cb9ebd5978bb97de935a62e1b85d890232b1a878a",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
12 changes: 12 additions & 0 deletions tests/reference/python-expr14-2e6ab03.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def test_boolean_comparison():
b1: bool
b2: bool
b3: bool
b1 = True
b2 = True
b3 = False
b1 = (b1) > (b2)
b1 = (b1) == (b2)
b1 = (b2) != (b3)
b1 = (b2) >= (b3)
b1 = (b2) <= (b3)
2 changes: 1 addition & 1 deletion tests/reference/python-expr17-3b84714.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "python-expr17-3b84714.stdout",
"stdout_hash": "c5754f71e1cd9a019d7289d5ccee634a42d75ac775b0e115eea48f03",
"stdout_hash": "9daa5ee66df347ea965190959be6eee3c070b52b38b0c9b52de04e2d",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 0 additions & 4 deletions tests/reference/python-expr17-3b84714.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ def if_check():
print("positive value")
else:
print("zero")




2 changes: 1 addition & 1 deletion tests/reference/python-expr2-6b69018.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "python-expr2-6b69018.stdout",
"stdout_hash": "849450cb39ead48c1935431e54d989370ecece8c711f34e4ca38fd2b",
"stdout_hash": "b9e6fef7e82bbf96d66869ae6fd739c46c8d20e5bafabb48a6a15fce",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 0 additions & 2 deletions tests/reference/python-expr2-6b69018.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ def test_boolOp():
a = a and b == b
a = a and b != b
a = b or b


2 changes: 1 addition & 1 deletion tests/reference/python-expr4-161a0ec.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "python-expr4-161a0ec.stdout",
"stdout_hash": "1378e1d01da96646ba0d45dbc6f5d30f7956e1c874c558df95a9f733",
"stdout_hash": "6dbfa328171f15601ab250ddecda5d36beb85a4922a60f583c932d4a",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
3 changes: 1 addition & 2 deletions tests/reference/python-expr4-161a0ec.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ def test_del():
b: i32
a = 4
b = 20
del a, b

del a, b
2 changes: 1 addition & 1 deletion tests/reference/python-expr5-dee0e5c.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "python-expr5-dee0e5c.stdout",
"stdout_hash": "cef56dbae8b4efd362ea96bcbdc080667fd46930c1d7cfbca92bbe8e",
"stdout_hash": "e4b6285bbd4e701c75f2abdeb7c21dc8b489f5c5ef848074c5ce1e3b",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 0 additions & 2 deletions tests/reference/python-expr5-dee0e5c.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ def test_StrOp_concat():
s = "3" + "4"
s = "a " + "test"
s = "test" + "test" + "test"


2 changes: 1 addition & 1 deletion tests/reference/python-expr6-1a1d4fb.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "python-expr6-1a1d4fb.stdout",
"stdout_hash": "f7e339254436fdf45988c26786265c1d00bfcc23c0c5419fc07c0e6c",
"stdout_hash": "36557786797da33792a4a672d4f5e5b0a6ced2c51e674c5ad9426d62",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 0 additions & 2 deletions tests/reference/python-expr6-1a1d4fb.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ def test_ifexp():
a = 2
b = 6 if (a) == (2) else 8
c = True if (b) > (5) else False


1 change: 1 addition & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ asr = true
filename = "expr14.py"
llvm = true
wat = true
python = true

[[test]]
filename = "expr15.py"
Expand Down