Skip to content

Commit 7aa7084

Browse files
authored
[asr-python] remove extra lines in codegen (#2590)
* [asr-python] remove extra lines in codegen * remove lines
1 parent 8ad6975 commit 7aa7084

20 files changed

+35
-31
lines changed

src/libasr/codegen/asr_to_python.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,13 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
165165
if (is_a<ASR::Module_t>(*item.second)) {
166166
visit_symbol(*item.second);
167167
r += s;
168-
r += "\n";
169168
}
170169
}
171170

172171
for (auto &item : x.m_symtab->get_scope()) {
173172
if (is_a<ASR::Function_t>(*item.second)) {
174173
visit_symbol(*item.second);
175174
r += s;
176-
r += "\n";
177175
}
178176
}
179177

@@ -240,8 +238,6 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
240238
r += s;
241239
}
242240
}
243-
244-
r += "\n";
245241
s = r;
246242
}
247243

@@ -347,7 +343,6 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor<ASRToLpythonVisitor>
347343
visit_stmt(*x.m_orelse[i]);
348344
r += s;
349345
dec_indent();
350-
r += "\n";
351346
}
352347
}
353348
s = r;

tests/reference/python-assert1-192ca6c.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "python-assert1-192ca6c.stdout",
9-
"stdout_hash": "2120f9dd9a8d41e4d67cced7ceb14c4ded9d56335058f66b24cfe12e",
9+
"stdout_hash": "0de7de97bd936f6a66e73ba9789e50ed968b66edce04acfcc168c6db",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/python-assert1-192ca6c.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ def test_assert():
33
a = 5
44
assert (a) == (5), "a is not 5"
55
assert (a) != (10)
6-
7-

tests/reference/python-assign1-f87bafa.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "python-assign1-f87bafa.stdout",
9-
"stdout_hash": "6fa5f5e1492cac718631d3c05d27ab2ddda15dd2e56cc37a1ce188b9",
9+
"stdout_hash": "bd60a7791394a67503473530adb0369f2f12407e0108423397f3e4e4",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/python-assign1-f87bafa.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ def test_augassign():
1111
r = r / s
1212
a = ""
1313
a = a + "test"
14-
15-

tests/reference/python-expr11-e6681c8.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "python-expr11-e6681c8.stdout",
9-
"stdout_hash": "6ae1afc8767434e703cfd38bbdd22275c73effa90a5e86c5c09bab5b",
9+
"stdout_hash": "425a18a0b44e596e166ce94fad47878623b4dd9b4d534419b7f18683",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/python-expr11-e6681c8.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ def test_StrOp_repeat():
66
s = "bb" * 4
77
s = "bb" * -(40)
88
s = "a" * 3 * 3
9-
10-
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "python-expr14-2e6ab03",
3+
"cmd": "lpython --no-color --show-python {infile}",
4+
"infile": "tests/expr14.py",
5+
"infile_hash": "d18abc152939c944f6a1e493754cea8b72f0d03d360ab4c9e75ad697",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": "python-expr14-2e6ab03.stdout",
9+
"stdout_hash": "52e647db794a391cb9ebd5978bb97de935a62e1b85d890232b1a878a",
10+
"stderr": null,
11+
"stderr_hash": null,
12+
"returncode": 0
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def test_boolean_comparison():
2+
b1: bool
3+
b2: bool
4+
b3: bool
5+
b1 = True
6+
b2 = True
7+
b3 = False
8+
b1 = (b1) > (b2)
9+
b1 = (b1) == (b2)
10+
b1 = (b2) != (b3)
11+
b1 = (b2) >= (b3)
12+
b1 = (b2) <= (b3)

tests/reference/python-expr17-3b84714.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "python-expr17-3b84714.stdout",
9-
"stdout_hash": "c5754f71e1cd9a019d7289d5ccee634a42d75ac775b0e115eea48f03",
9+
"stdout_hash": "9daa5ee66df347ea965190959be6eee3c070b52b38b0c9b52de04e2d",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/python-expr17-3b84714.stdout

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,3 @@ def if_check():
88
print("positive value")
99
else:
1010
print("zero")
11-
12-
13-
14-

tests/reference/python-expr2-6b69018.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "python-expr2-6b69018.stdout",
9-
"stdout_hash": "849450cb39ead48c1935431e54d989370ecece8c711f34e4ca38fd2b",
9+
"stdout_hash": "b9e6fef7e82bbf96d66869ae6fd739c46c8d20e5bafabb48a6a15fce",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/python-expr2-6b69018.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ def test_boolOp():
99
a = a and b == b
1010
a = a and b != b
1111
a = b or b
12-
13-

tests/reference/python-expr4-161a0ec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "python-expr4-161a0ec.stdout",
9-
"stdout_hash": "1378e1d01da96646ba0d45dbc6f5d30f7956e1c874c558df95a9f733",
9+
"stdout_hash": "6dbfa328171f15601ab250ddecda5d36beb85a4922a60f583c932d4a",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/python-expr4-161a0ec.stdout

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ def test_del():
33
b: i32
44
a = 4
55
b = 20
6-
del a, b
7-
6+
del a, b

tests/reference/python-expr5-dee0e5c.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "python-expr5-dee0e5c.stdout",
9-
"stdout_hash": "cef56dbae8b4efd362ea96bcbdc080667fd46930c1d7cfbca92bbe8e",
9+
"stdout_hash": "e4b6285bbd4e701c75f2abdeb7c21dc8b489f5c5ef848074c5ce1e3b",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/python-expr5-dee0e5c.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ def test_StrOp_concat():
33
s = "3" + "4"
44
s = "a " + "test"
55
s = "test" + "test" + "test"
6-
7-

tests/reference/python-expr6-1a1d4fb.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "python-expr6-1a1d4fb.stdout",
9-
"stdout_hash": "f7e339254436fdf45988c26786265c1d00bfcc23c0c5419fc07c0e6c",
9+
"stdout_hash": "36557786797da33792a4a672d4f5e5b0a6ced2c51e674c5ad9426d62",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/python-expr6-1a1d4fb.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ def test_ifexp():
55
a = 2
66
b = 6 if (a) == (2) else 8
77
c = True if (b) > (5) else False
8-
9-

tests/tests.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ asr = true
131131
filename = "expr14.py"
132132
llvm = true
133133
wat = true
134+
python = true
134135

135136
[[test]]
136137
filename = "expr15.py"

0 commit comments

Comments
 (0)