From 6f93c4383b55c32fe125628369b2e7b375a3d829 Mon Sep 17 00:00:00 2001 From: ujjwaltwitx Date: Mon, 11 Dec 2023 16:09:29 +0530 Subject: [PATCH 1/5] Implemented visit_AsyncFunctionDef in the AST->ASR visitor --- src/lpython/semantics/python_ast_to_asr.cpp | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index a3bb17a49a..1526a284df 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4051,6 +4051,17 @@ class SymbolTableVisitor : public CommonVisitor { // Implement visit_Global for Symbol Table visitor. void visit_Global(const AST::Global_t &/*x*/) {} + void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x){ + try + { + // to be implemented + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + } + void visit_FunctionDef(const AST::FunctionDef_t &x) { dependencies.clear(al); SymbolTable *parent_scope = current_scope; @@ -4823,6 +4834,19 @@ class BodyVisitor : public CommonVisitor { tmp = nullptr; } + void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x) { + try + { + // BodyVisitor for visit_AsyncFunctionDef to be implemented + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + + } + + void visit_Import(const AST::Import_t &x) { // All the modules are imported in the SymbolTable visitor for (size_t i = 0; i < x.n_names; i++) { From 6737a0647db2595d01972c51aeb99884210fb125 Mon Sep 17 00:00:00 2001 From: ujjwaltwitx Date: Mon, 11 Dec 2023 16:36:45 +0530 Subject: [PATCH 2/5] Removed unused parameters --- src/lpython/semantics/python_ast_to_asr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 1526a284df..1dd2392335 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4051,7 +4051,7 @@ class SymbolTableVisitor : public CommonVisitor { // Implement visit_Global for Symbol Table visitor. void visit_Global(const AST::Global_t &/*x*/) {} - void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x){ + void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &/*x*/){ try { // to be implemented @@ -4834,7 +4834,7 @@ class BodyVisitor : public CommonVisitor { tmp = nullptr; } - void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x) { + void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &/*x*/) { try { // BodyVisitor for visit_AsyncFunctionDef to be implemented From 0f4dc32b4892917273b6eabc624dfd5024d7f736 Mon Sep 17 00:00:00 2001 From: ujjwaltwitx Date: Thu, 14 Dec 2023 00:00:55 +0530 Subject: [PATCH 3/5] Added appropriate throw block for error and added test for async implementation --- src/lpython/semantics/python_ast_to_asr.cpp | 5 +++-- tests/errors/test_async.py | 4 ++++ tests/reference/asr-test_async-361297c.json | 13 +++++++++++++ tests/reference/asr-test_async-361297c.stderr | 9 +++++++++ tests/tests.toml | 4 ++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/errors/test_async.py create mode 100644 tests/reference/asr-test_async-361297c.json create mode 100644 tests/reference/asr-test_async-361297c.stderr diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 1dd2392335..a68de08ace 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4051,7 +4051,7 @@ class SymbolTableVisitor : public CommonVisitor { // Implement visit_Global for Symbol Table visitor. void visit_Global(const AST::Global_t &/*x*/) {} - void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &/*x*/){ + void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x){ try { // to be implemented @@ -4059,7 +4059,8 @@ class SymbolTableVisitor : public CommonVisitor { catch(const std::exception& e) { std::cerr << e.what() << '\n'; - } + } + throw SemanticError("The `async` keyword is currently not supported", x.base.base.loc); } void visit_FunctionDef(const AST::FunctionDef_t &x) { diff --git a/tests/errors/test_async.py b/tests/errors/test_async.py new file mode 100644 index 0000000000..a435c814aa --- /dev/null +++ b/tests/errors/test_async.py @@ -0,0 +1,4 @@ +async def test_async(): + print("done") + +test_async() \ No newline at end of file diff --git a/tests/reference/asr-test_async-361297c.json b/tests/reference/asr-test_async-361297c.json new file mode 100644 index 0000000000..4477cbad49 --- /dev/null +++ b/tests/reference/asr-test_async-361297c.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_async-361297c", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_async.py", + "infile_hash": "f4d737246effd50f1798a81f07042ad15a045e275448fe0226334f03", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_async-361297c.stderr", + "stderr_hash": "abf614594f89a7a6d93d469d512e31de5adc64feef866957de80cd03", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_async-361297c.stderr b/tests/reference/asr-test_async-361297c.stderr new file mode 100644 index 0000000000..c24b2174ae --- /dev/null +++ b/tests/reference/asr-test_async-361297c.stderr @@ -0,0 +1,9 @@ +semantic error: The `async` keyword is currently not supported + --> tests/errors/test_async.py:1:1 - 2:17 + | +1 | async def test_async(): + | ^^^^^^^^^^^^^^^^^^^^^^^... +... + | +2 | print("done") + | ...^^^^^^^^^^^^^^^^^ diff --git a/tests/tests.toml b/tests/tests.toml index 9ed98dd2f7..5f6f56a9cf 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -784,6 +784,10 @@ ast_new = true # tests/errors +[[test]] +filename = "errors/test_async.py" +asr = true + [[test]] filename = "errors/test_str_indexing.py" asr = true From 3ee163ed615a643d565607842fd01d231d2dde61 Mon Sep 17 00:00:00 2001 From: ujjwaltwitx Date: Thu, 14 Dec 2023 12:33:11 +0530 Subject: [PATCH 4/5] removed unnecessary lines from the function, removed the visit_AsyncFunctionDef function from BodyVisitor and moved the function to common visitor --- src/lpython/semantics/python_ast_to_asr.cpp | 29 +++++---------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index a68de08ace..8e62bdd301 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -592,6 +592,11 @@ class CommonVisitor : public AST::BaseVisitor { return nullptr; } + + void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x){ + throw SemanticError("The `async` keyword is currently not supported", x.base.base.loc); + } + void visit_expr_list(AST::expr_t** exprs, size_t n, Vec& exprs_vec) { LCOMPILERS_ASSERT(exprs_vec.reserve_called); @@ -4051,17 +4056,7 @@ class SymbolTableVisitor : public CommonVisitor { // Implement visit_Global for Symbol Table visitor. void visit_Global(const AST::Global_t &/*x*/) {} - void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &x){ - try - { - // to be implemented - } - catch(const std::exception& e) - { - std::cerr << e.what() << '\n'; - } - throw SemanticError("The `async` keyword is currently not supported", x.base.base.loc); - } + void visit_FunctionDef(const AST::FunctionDef_t &x) { dependencies.clear(al); @@ -4835,18 +4830,6 @@ class BodyVisitor : public CommonVisitor { tmp = nullptr; } - void visit_AsyncFunctionDef(const AST::AsyncFunctionDef_t &/*x*/) { - try - { - // BodyVisitor for visit_AsyncFunctionDef to be implemented - } - catch(const std::exception& e) - { - std::cerr << e.what() << '\n'; - } - - } - void visit_Import(const AST::Import_t &x) { // All the modules are imported in the SymbolTable visitor From 31ccd837893e453ccbfcfce4b40992caa711e669 Mon Sep 17 00:00:00 2001 From: ujjwaltwitx Date: Thu, 14 Dec 2023 22:07:03 +0530 Subject: [PATCH 5/5] Removed whitespaces --- src/lpython/semantics/python_ast_to_asr.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 8e62bdd301..5eb253f8f0 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4056,8 +4056,6 @@ class SymbolTableVisitor : public CommonVisitor { // Implement visit_Global for Symbol Table visitor. void visit_Global(const AST::Global_t &/*x*/) {} - - void visit_FunctionDef(const AST::FunctionDef_t &x) { dependencies.clear(al); SymbolTable *parent_scope = current_scope; @@ -4830,7 +4828,6 @@ class BodyVisitor : public CommonVisitor { tmp = nullptr; } - void visit_Import(const AST::Import_t &x) { // All the modules are imported in the SymbolTable visitor for (size_t i = 0; i < x.n_names; i++) {