From 1982c61bc46154c9783a728ccd694515ab976967 Mon Sep 17 00:00:00 2001 From: Khushi Agrawal Date: Fri, 8 Mar 2024 22:56:25 +0530 Subject: [PATCH 1/2] [asr-python] remove extra lines in codegen --- src/libasr/codegen/asr_to_python.cpp | 2 -- tests/reference/python-assert1-192ca6c.json | 2 +- tests/reference/python-assert1-192ca6c.stdout | 1 - tests/reference/python-assign1-f87bafa.json | 2 +- tests/reference/python-assign1-f87bafa.stdout | 1 - tests/reference/python-expr11-e6681c8.json | 2 +- tests/reference/python-expr11-e6681c8.stdout | 1 - tests/reference/python-expr14-2e6ab03.json | 13 +++++++++++++ tests/reference/python-expr14-2e6ab03.stdout | 13 +++++++++++++ tests/reference/python-expr2-6b69018.json | 2 +- tests/reference/python-expr2-6b69018.stdout | 1 - tests/reference/python-expr4-161a0ec.json | 2 +- tests/reference/python-expr4-161a0ec.stdout | 1 - tests/reference/python-expr5-dee0e5c.json | 2 +- tests/reference/python-expr5-dee0e5c.stdout | 1 - tests/reference/python-expr6-1a1d4fb.json | 2 +- tests/reference/python-expr6-1a1d4fb.stdout | 1 - tests/tests.toml | 1 + 18 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 tests/reference/python-expr14-2e6ab03.json create mode 100644 tests/reference/python-expr14-2e6ab03.stdout diff --git a/src/libasr/codegen/asr_to_python.cpp b/src/libasr/codegen/asr_to_python.cpp index 69f7a0bf4d..a899bcfd47 100644 --- a/src/libasr/codegen/asr_to_python.cpp +++ b/src/libasr/codegen/asr_to_python.cpp @@ -165,7 +165,6 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor if (is_a(*item.second)) { visit_symbol(*item.second); r += s; - r += "\n"; } } @@ -173,7 +172,6 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor if (is_a(*item.second)) { visit_symbol(*item.second); r += s; - r += "\n"; } } diff --git a/tests/reference/python-assert1-192ca6c.json b/tests/reference/python-assert1-192ca6c.json index ed9457882f..7b44c890f0 100644 --- a/tests/reference/python-assert1-192ca6c.json +++ b/tests/reference/python-assert1-192ca6c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-assert1-192ca6c.stdout", - "stdout_hash": "2120f9dd9a8d41e4d67cced7ceb14c4ded9d56335058f66b24cfe12e", + "stdout_hash": "d28831c2c0879234aa80d3f85627b420b548c9bc5de3ee6cb75939f3", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-assert1-192ca6c.stdout b/tests/reference/python-assert1-192ca6c.stdout index 77016e73f3..4c91797f0d 100644 --- a/tests/reference/python-assert1-192ca6c.stdout +++ b/tests/reference/python-assert1-192ca6c.stdout @@ -4,4 +4,3 @@ def test_assert(): assert (a) == (5), "a is not 5" assert (a) != (10) - diff --git a/tests/reference/python-assign1-f87bafa.json b/tests/reference/python-assign1-f87bafa.json index f4ce6903f8..99781ea83b 100644 --- a/tests/reference/python-assign1-f87bafa.json +++ b/tests/reference/python-assign1-f87bafa.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-assign1-f87bafa.stdout", - "stdout_hash": "6fa5f5e1492cac718631d3c05d27ab2ddda15dd2e56cc37a1ce188b9", + "stdout_hash": "422d7c12b74e9452e6208f58bce588e9c258fb27feb44fed948e9111", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-assign1-f87bafa.stdout b/tests/reference/python-assign1-f87bafa.stdout index caa7aaf2a6..455b8e457c 100644 --- a/tests/reference/python-assign1-f87bafa.stdout +++ b/tests/reference/python-assign1-f87bafa.stdout @@ -12,4 +12,3 @@ def test_augassign(): a = "" a = a + "test" - diff --git a/tests/reference/python-expr11-e6681c8.json b/tests/reference/python-expr11-e6681c8.json index 067b2c4518..6787f18555 100644 --- a/tests/reference/python-expr11-e6681c8.json +++ b/tests/reference/python-expr11-e6681c8.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr11-e6681c8.stdout", - "stdout_hash": "6ae1afc8767434e703cfd38bbdd22275c73effa90a5e86c5c09bab5b", + "stdout_hash": "6be7a0faee47ebe997764ba1e367368fd548073400ae59947f50be0e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr11-e6681c8.stdout b/tests/reference/python-expr11-e6681c8.stdout index da61c57b5a..cf350f6c44 100644 --- a/tests/reference/python-expr11-e6681c8.stdout +++ b/tests/reference/python-expr11-e6681c8.stdout @@ -7,4 +7,3 @@ def test_StrOp_repeat(): s = "bb" * -(40) s = "a" * 3 * 3 - diff --git a/tests/reference/python-expr14-2e6ab03.json b/tests/reference/python-expr14-2e6ab03.json new file mode 100644 index 0000000000..ff92bef390 --- /dev/null +++ b/tests/reference/python-expr14-2e6ab03.json @@ -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": "21575ff5209313762756f1f8c19f492df623221026258fbf9a3cec54", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/python-expr14-2e6ab03.stdout b/tests/reference/python-expr14-2e6ab03.stdout new file mode 100644 index 0000000000..d28e31027a --- /dev/null +++ b/tests/reference/python-expr14-2e6ab03.stdout @@ -0,0 +1,13 @@ +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) + diff --git a/tests/reference/python-expr2-6b69018.json b/tests/reference/python-expr2-6b69018.json index 784e5f3e6f..a6813d5361 100644 --- a/tests/reference/python-expr2-6b69018.json +++ b/tests/reference/python-expr2-6b69018.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr2-6b69018.stdout", - "stdout_hash": "849450cb39ead48c1935431e54d989370ecece8c711f34e4ca38fd2b", + "stdout_hash": "171c06006dcacfb474df73fff8456b1f03e3132bc90552cf871b72c2", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr2-6b69018.stdout b/tests/reference/python-expr2-6b69018.stdout index 45bd2f5ccc..c599303302 100644 --- a/tests/reference/python-expr2-6b69018.stdout +++ b/tests/reference/python-expr2-6b69018.stdout @@ -10,4 +10,3 @@ def test_boolOp(): a = a and b != b a = b or b - diff --git a/tests/reference/python-expr4-161a0ec.json b/tests/reference/python-expr4-161a0ec.json index 9823faecf8..132814fdcc 100644 --- a/tests/reference/python-expr4-161a0ec.json +++ b/tests/reference/python-expr4-161a0ec.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr4-161a0ec.stdout", - "stdout_hash": "1378e1d01da96646ba0d45dbc6f5d30f7956e1c874c558df95a9f733", + "stdout_hash": "5cba7a5d589f54fc31463e48903d5b46604fb64e3e64ba215339047c", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr4-161a0ec.stdout b/tests/reference/python-expr4-161a0ec.stdout index a6a301dd99..030b93569e 100644 --- a/tests/reference/python-expr4-161a0ec.stdout +++ b/tests/reference/python-expr4-161a0ec.stdout @@ -4,4 +4,3 @@ def test_del(): a = 4 b = 20 del a, b - diff --git a/tests/reference/python-expr5-dee0e5c.json b/tests/reference/python-expr5-dee0e5c.json index 5cf281a38d..c3baa433b9 100644 --- a/tests/reference/python-expr5-dee0e5c.json +++ b/tests/reference/python-expr5-dee0e5c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr5-dee0e5c.stdout", - "stdout_hash": "cef56dbae8b4efd362ea96bcbdc080667fd46930c1d7cfbca92bbe8e", + "stdout_hash": "20bce17d4ff3176a94a22f237882164d9c56ec3f11572c210f531ea8", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr5-dee0e5c.stdout b/tests/reference/python-expr5-dee0e5c.stdout index b63878db76..d6922a9d63 100644 --- a/tests/reference/python-expr5-dee0e5c.stdout +++ b/tests/reference/python-expr5-dee0e5c.stdout @@ -4,4 +4,3 @@ def test_StrOp_concat(): s = "a " + "test" s = "test" + "test" + "test" - diff --git a/tests/reference/python-expr6-1a1d4fb.json b/tests/reference/python-expr6-1a1d4fb.json index f1eb23d77b..a85f0485ea 100644 --- a/tests/reference/python-expr6-1a1d4fb.json +++ b/tests/reference/python-expr6-1a1d4fb.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr6-1a1d4fb.stdout", - "stdout_hash": "f7e339254436fdf45988c26786265c1d00bfcc23c0c5419fc07c0e6c", + "stdout_hash": "525f6f7fe224672ff3346a6f24658a1ff58e5da3f64dc136ef36255c", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr6-1a1d4fb.stdout b/tests/reference/python-expr6-1a1d4fb.stdout index ccb26aa61f..c23eff7601 100644 --- a/tests/reference/python-expr6-1a1d4fb.stdout +++ b/tests/reference/python-expr6-1a1d4fb.stdout @@ -6,4 +6,3 @@ def test_ifexp(): b = 6 if (a) == (2) else 8 c = True if (b) > (5) else False - diff --git a/tests/tests.toml b/tests/tests.toml index 9be71acb27..3eae0f1377 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -131,6 +131,7 @@ asr = true filename = "expr14.py" llvm = true wat = true +python = true [[test]] filename = "expr15.py" From f743b16dd8028639557765f7a72c675ee2cf3cd7 Mon Sep 17 00:00:00 2001 From: Khushi Agrawal Date: Fri, 8 Mar 2024 23:12:16 +0530 Subject: [PATCH 2/2] remove lines --- src/libasr/codegen/asr_to_python.cpp | 3 --- tests/reference/python-assert1-192ca6c.json | 2 +- tests/reference/python-assert1-192ca6c.stdout | 1 - tests/reference/python-assign1-f87bafa.json | 2 +- tests/reference/python-assign1-f87bafa.stdout | 1 - tests/reference/python-expr11-e6681c8.json | 2 +- tests/reference/python-expr11-e6681c8.stdout | 1 - tests/reference/python-expr14-2e6ab03.json | 2 +- tests/reference/python-expr14-2e6ab03.stdout | 1 - tests/reference/python-expr17-3b84714.json | 2 +- tests/reference/python-expr17-3b84714.stdout | 4 ---- tests/reference/python-expr2-6b69018.json | 2 +- tests/reference/python-expr2-6b69018.stdout | 1 - tests/reference/python-expr4-161a0ec.json | 2 +- tests/reference/python-expr4-161a0ec.stdout | 2 +- tests/reference/python-expr5-dee0e5c.json | 2 +- tests/reference/python-expr5-dee0e5c.stdout | 1 - tests/reference/python-expr6-1a1d4fb.json | 2 +- tests/reference/python-expr6-1a1d4fb.stdout | 1 - 19 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/libasr/codegen/asr_to_python.cpp b/src/libasr/codegen/asr_to_python.cpp index a899bcfd47..fa9a06adc4 100644 --- a/src/libasr/codegen/asr_to_python.cpp +++ b/src/libasr/codegen/asr_to_python.cpp @@ -238,8 +238,6 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor r += s; } } - - r += "\n"; s = r; } @@ -345,7 +343,6 @@ class ASRToLpythonVisitor : public ASR::BaseVisitor visit_stmt(*x.m_orelse[i]); r += s; dec_indent(); - r += "\n"; } } s = r; diff --git a/tests/reference/python-assert1-192ca6c.json b/tests/reference/python-assert1-192ca6c.json index 7b44c890f0..1db5a55ee7 100644 --- a/tests/reference/python-assert1-192ca6c.json +++ b/tests/reference/python-assert1-192ca6c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-assert1-192ca6c.stdout", - "stdout_hash": "d28831c2c0879234aa80d3f85627b420b548c9bc5de3ee6cb75939f3", + "stdout_hash": "0de7de97bd936f6a66e73ba9789e50ed968b66edce04acfcc168c6db", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-assert1-192ca6c.stdout b/tests/reference/python-assert1-192ca6c.stdout index 4c91797f0d..88a510476c 100644 --- a/tests/reference/python-assert1-192ca6c.stdout +++ b/tests/reference/python-assert1-192ca6c.stdout @@ -3,4 +3,3 @@ def test_assert(): a = 5 assert (a) == (5), "a is not 5" assert (a) != (10) - diff --git a/tests/reference/python-assign1-f87bafa.json b/tests/reference/python-assign1-f87bafa.json index 99781ea83b..ac0ac5afda 100644 --- a/tests/reference/python-assign1-f87bafa.json +++ b/tests/reference/python-assign1-f87bafa.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-assign1-f87bafa.stdout", - "stdout_hash": "422d7c12b74e9452e6208f58bce588e9c258fb27feb44fed948e9111", + "stdout_hash": "bd60a7791394a67503473530adb0369f2f12407e0108423397f3e4e4", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-assign1-f87bafa.stdout b/tests/reference/python-assign1-f87bafa.stdout index 455b8e457c..e083f35a45 100644 --- a/tests/reference/python-assign1-f87bafa.stdout +++ b/tests/reference/python-assign1-f87bafa.stdout @@ -11,4 +11,3 @@ def test_augassign(): r = r / s a = "" a = a + "test" - diff --git a/tests/reference/python-expr11-e6681c8.json b/tests/reference/python-expr11-e6681c8.json index 6787f18555..9f40e4dc6d 100644 --- a/tests/reference/python-expr11-e6681c8.json +++ b/tests/reference/python-expr11-e6681c8.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr11-e6681c8.stdout", - "stdout_hash": "6be7a0faee47ebe997764ba1e367368fd548073400ae59947f50be0e", + "stdout_hash": "425a18a0b44e596e166ce94fad47878623b4dd9b4d534419b7f18683", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr11-e6681c8.stdout b/tests/reference/python-expr11-e6681c8.stdout index cf350f6c44..a108676193 100644 --- a/tests/reference/python-expr11-e6681c8.stdout +++ b/tests/reference/python-expr11-e6681c8.stdout @@ -6,4 +6,3 @@ def test_StrOp_repeat(): s = "bb" * 4 s = "bb" * -(40) s = "a" * 3 * 3 - diff --git a/tests/reference/python-expr14-2e6ab03.json b/tests/reference/python-expr14-2e6ab03.json index ff92bef390..57dfc1ce5e 100644 --- a/tests/reference/python-expr14-2e6ab03.json +++ b/tests/reference/python-expr14-2e6ab03.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr14-2e6ab03.stdout", - "stdout_hash": "21575ff5209313762756f1f8c19f492df623221026258fbf9a3cec54", + "stdout_hash": "52e647db794a391cb9ebd5978bb97de935a62e1b85d890232b1a878a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr14-2e6ab03.stdout b/tests/reference/python-expr14-2e6ab03.stdout index d28e31027a..fcb9a3f182 100644 --- a/tests/reference/python-expr14-2e6ab03.stdout +++ b/tests/reference/python-expr14-2e6ab03.stdout @@ -10,4 +10,3 @@ def test_boolean_comparison(): b1 = (b2) != (b3) b1 = (b2) >= (b3) b1 = (b2) <= (b3) - diff --git a/tests/reference/python-expr17-3b84714.json b/tests/reference/python-expr17-3b84714.json index 11933a5b96..5ad1fd4c8d 100644 --- a/tests/reference/python-expr17-3b84714.json +++ b/tests/reference/python-expr17-3b84714.json @@ -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 diff --git a/tests/reference/python-expr17-3b84714.stdout b/tests/reference/python-expr17-3b84714.stdout index 48b07875e4..d0f78d5ffe 100644 --- a/tests/reference/python-expr17-3b84714.stdout +++ b/tests/reference/python-expr17-3b84714.stdout @@ -8,7 +8,3 @@ def if_check(): print("positive value") else: print("zero") - - - - diff --git a/tests/reference/python-expr2-6b69018.json b/tests/reference/python-expr2-6b69018.json index a6813d5361..07c3053bc1 100644 --- a/tests/reference/python-expr2-6b69018.json +++ b/tests/reference/python-expr2-6b69018.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr2-6b69018.stdout", - "stdout_hash": "171c06006dcacfb474df73fff8456b1f03e3132bc90552cf871b72c2", + "stdout_hash": "b9e6fef7e82bbf96d66869ae6fd739c46c8d20e5bafabb48a6a15fce", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr2-6b69018.stdout b/tests/reference/python-expr2-6b69018.stdout index c599303302..523311bbaa 100644 --- a/tests/reference/python-expr2-6b69018.stdout +++ b/tests/reference/python-expr2-6b69018.stdout @@ -9,4 +9,3 @@ def test_boolOp(): a = a and b == b a = a and b != b a = b or b - diff --git a/tests/reference/python-expr4-161a0ec.json b/tests/reference/python-expr4-161a0ec.json index 132814fdcc..abc691f0c0 100644 --- a/tests/reference/python-expr4-161a0ec.json +++ b/tests/reference/python-expr4-161a0ec.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr4-161a0ec.stdout", - "stdout_hash": "5cba7a5d589f54fc31463e48903d5b46604fb64e3e64ba215339047c", + "stdout_hash": "6dbfa328171f15601ab250ddecda5d36beb85a4922a60f583c932d4a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr4-161a0ec.stdout b/tests/reference/python-expr4-161a0ec.stdout index 030b93569e..81dfdff136 100644 --- a/tests/reference/python-expr4-161a0ec.stdout +++ b/tests/reference/python-expr4-161a0ec.stdout @@ -3,4 +3,4 @@ def test_del(): b: i32 a = 4 b = 20 - del a, b + del a, b \ No newline at end of file diff --git a/tests/reference/python-expr5-dee0e5c.json b/tests/reference/python-expr5-dee0e5c.json index c3baa433b9..1c3f9279d8 100644 --- a/tests/reference/python-expr5-dee0e5c.json +++ b/tests/reference/python-expr5-dee0e5c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr5-dee0e5c.stdout", - "stdout_hash": "20bce17d4ff3176a94a22f237882164d9c56ec3f11572c210f531ea8", + "stdout_hash": "e4b6285bbd4e701c75f2abdeb7c21dc8b489f5c5ef848074c5ce1e3b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr5-dee0e5c.stdout b/tests/reference/python-expr5-dee0e5c.stdout index d6922a9d63..92fb4ec53b 100644 --- a/tests/reference/python-expr5-dee0e5c.stdout +++ b/tests/reference/python-expr5-dee0e5c.stdout @@ -3,4 +3,3 @@ def test_StrOp_concat(): s = "3" + "4" s = "a " + "test" s = "test" + "test" + "test" - diff --git a/tests/reference/python-expr6-1a1d4fb.json b/tests/reference/python-expr6-1a1d4fb.json index a85f0485ea..4637905e1c 100644 --- a/tests/reference/python-expr6-1a1d4fb.json +++ b/tests/reference/python-expr6-1a1d4fb.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr6-1a1d4fb.stdout", - "stdout_hash": "525f6f7fe224672ff3346a6f24658a1ff58e5da3f64dc136ef36255c", + "stdout_hash": "36557786797da33792a4a672d4f5e5b0a6ced2c51e674c5ad9426d62", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr6-1a1d4fb.stdout b/tests/reference/python-expr6-1a1d4fb.stdout index c23eff7601..fe35320c4e 100644 --- a/tests/reference/python-expr6-1a1d4fb.stdout +++ b/tests/reference/python-expr6-1a1d4fb.stdout @@ -5,4 +5,3 @@ def test_ifexp(): a = 2 b = 6 if (a) == (2) else 8 c = True if (b) > (5) else False -