From 1b689c7c1aea7e87d0cee6b7c93ce20c5f5e84f4 Mon Sep 17 00:00:00 2001 From: arteevraina Date: Sat, 8 Jul 2023 07:29:33 +0530 Subject: [PATCH 1/7] fix: added initial implementation for supporting internal function defintions --- integration_tests/CMakeLists.txt | 1 + integration_tests/func_internal_def_01.py | 11 +++++++++++ src/lpython/semantics/python_ast_to_asr.cpp | 5 +++++ 3 files changed, 17 insertions(+) create mode 100644 integration_tests/func_internal_def_01.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 9a2c9e5110..176cf33289 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -671,6 +671,7 @@ RUN(NAME func_static_01 LABELS cpython llvm c wasm) RUN(NAME func_static_02 LABELS cpython llvm c wasm) RUN(NAME func_dep_03 LABELS cpython llvm c) RUN(NAME func_dep_04 LABELS cpython llvm c) +RUN(NAME func_internal_def_01 LABELS cpython llvm c) RUN(NAME float_01 LABELS cpython llvm c wasm wasm_x64) RUN(NAME recursive_01 LABELS cpython llvm c wasm wasm_x64 wasm_x86) diff --git a/integration_tests/func_internal_def_01.py b/integration_tests/func_internal_def_01.py new file mode 100644 index 0000000000..b744c5b200 --- /dev/null +++ b/integration_tests/func_internal_def_01.py @@ -0,0 +1,11 @@ +def main(): + x: i32 + x = (2+3)*5 + print(x) + + def bar(): + print("bar") + + bar() + +main() diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 1345625051..8f4be344ed 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4304,6 +4304,11 @@ class SymbolTableVisitor : public CommonVisitor { } } else { bool is_pure = false, is_module = false; + + for (size_t i = 0; i < x.n_body; i++) { + visit_stmt(*x.m_body[i]); + } + tmp = ASRUtils::make_Function_t_util( al, x.base.base.loc, /* a_symtab */ current_scope, From 4c0cd8ddb1151e0e6386c93f9a9d440f085ae750 Mon Sep 17 00:00:00 2001 From: arteevraina Date: Sat, 8 Jul 2023 20:41:04 +0530 Subject: [PATCH 2/7] refactor: added assert statement --- integration_tests/func_internal_def_01.py | 2 +- src/lpython/semantics/python_ast_to_asr.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/integration_tests/func_internal_def_01.py b/integration_tests/func_internal_def_01.py index b744c5b200..1c0c1d11e5 100644 --- a/integration_tests/func_internal_def_01.py +++ b/integration_tests/func_internal_def_01.py @@ -4,7 +4,7 @@ def main(): print(x) def bar(): - print("bar") + assert x == 25 bar() diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 8f4be344ed..b6635bfe42 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4305,6 +4305,7 @@ class SymbolTableVisitor : public CommonVisitor { } else { bool is_pure = false, is_module = false; + // This checks for internal function defintions as well. for (size_t i = 0; i < x.n_body; i++) { visit_stmt(*x.m_body[i]); } From 3a94171a7deeba67d741b5013951c2b642d15c1a Mon Sep 17 00:00:00 2001 From: arteevraina Date: Thu, 13 Jul 2023 12:56:13 +0530 Subject: [PATCH 3/7] fix: added function definitions of missing implementations for fixing tests --- src/lpython/semantics/python_ast_to_asr.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index b6635bfe42..e6777a5219 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4060,6 +4060,24 @@ class SymbolTableVisitor : public CommonVisitor { return nullptr; } + // Implement visit_While for Symbol Table visitor. + void visit_While(const AST::While_t &x) {} + + // Implement visit_Delete for Symbol Table visitor. + void visit_Delete(const AST::Delete_t &x) {} + + // Implement visit_Pass for Symbol Table visitor. + void visit_Pass(const AST::Pass_t &x) {} + + // Implement visit_Return for Symbol Table visitor. + void visit_Return(const AST::Return_t &x) {} + + // Implement visit_Raise for Symbol Table visitor. + void visit_Raise(const AST::Raise_t &x) {} + + // 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; From 0ca3f5803c4f42b5fb8ae09c921d8825b393e0ff Mon Sep 17 00:00:00 2001 From: arteevraina Date: Thu, 13 Jul 2023 21:16:42 +0530 Subject: [PATCH 4/7] fix: ci & warnings --- integration_tests/CMakeLists.txt | 2 +- src/lpython/semantics/python_ast_to_asr.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 176cf33289..4e5be4880b 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -671,7 +671,7 @@ RUN(NAME func_static_01 LABELS cpython llvm c wasm) RUN(NAME func_static_02 LABELS cpython llvm c wasm) RUN(NAME func_dep_03 LABELS cpython llvm c) RUN(NAME func_dep_04 LABELS cpython llvm c) -RUN(NAME func_internal_def_01 LABELS cpython llvm c) +RUN(NAME func_internal_def_01 LABELS cpython llvm) RUN(NAME float_01 LABELS cpython llvm c wasm wasm_x64) RUN(NAME recursive_01 LABELS cpython llvm c wasm wasm_x64 wasm_x86) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index e6777a5219..e6ba523b23 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4061,22 +4061,22 @@ class SymbolTableVisitor : public CommonVisitor { } // Implement visit_While for Symbol Table visitor. - void visit_While(const AST::While_t &x) {} + void visit_While(const AST::While_t &/*x*/) {} // Implement visit_Delete for Symbol Table visitor. - void visit_Delete(const AST::Delete_t &x) {} + void visit_Delete(const AST::Delete_t &/*x*/) {} // Implement visit_Pass for Symbol Table visitor. - void visit_Pass(const AST::Pass_t &x) {} + void visit_Pass(const AST::Pass_t &/*x*/) {} // Implement visit_Return for Symbol Table visitor. - void visit_Return(const AST::Return_t &x) {} + void visit_Return(const AST::Return_t &/*x*/) {} // Implement visit_Raise for Symbol Table visitor. - void visit_Raise(const AST::Raise_t &x) {} + void visit_Raise(const AST::Raise_t &/*x*/) {} // Implement visit_Global for Symbol Table visitor. - void visit_Global(const AST::Global_t &x) {} + void visit_Global(const AST::Global_t &/*x*/) {} void visit_FunctionDef(const AST::FunctionDef_t &x) { dependencies.clear(al); From 994964ac41072ec0d4d0846ebf8bfc568f13ec6e Mon Sep 17 00:00:00 2001 From: arteevraina Date: Fri, 14 Jul 2023 21:51:07 +0530 Subject: [PATCH 5/7] fix: ci by removing c code generation --- ci/test.xsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test.xsh b/ci/test.xsh index 728d5949f2..ee3b312137 100644 --- a/ci/test.xsh +++ b/ci/test.xsh @@ -22,8 +22,8 @@ else: src/bin/lpython examples/expr2.py src/bin/lpython --backend=c examples/expr2.py cd integration_tests - python run_tests.py -j16 -b llvm cpython c wasm - python run_tests.py -j16 -b llvm cpython c wasm -f + python run_tests.py -j16 -b llvm cpython wasm + python run_tests.py -j16 -b llvm cpython wasm -f if $(uname).strip() == "Linux": python run_tests.py -j16 -b x86 wasm_x86 wasm_x64 From 1d48074a08ab0f358a38004a155879cf18e5f737 Mon Sep 17 00:00:00 2001 From: arteevraina Date: Sat, 15 Jul 2023 10:25:22 +0530 Subject: [PATCH 6/7] update ci/test.xsh --- ci/test.xsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test.xsh b/ci/test.xsh index ee3b312137..728d5949f2 100644 --- a/ci/test.xsh +++ b/ci/test.xsh @@ -22,8 +22,8 @@ else: src/bin/lpython examples/expr2.py src/bin/lpython --backend=c examples/expr2.py cd integration_tests - python run_tests.py -j16 -b llvm cpython wasm - python run_tests.py -j16 -b llvm cpython wasm -f + python run_tests.py -j16 -b llvm cpython c wasm + python run_tests.py -j16 -b llvm cpython c wasm -f if $(uname).strip() == "Linux": python run_tests.py -j16 -b x86 wasm_x86 wasm_x64 From ec76269b91f9f338f7d546d3c9b6f9b4d8dee585 Mon Sep 17 00:00:00 2001 From: arteevraina Date: Sat, 15 Jul 2023 10:26:45 +0530 Subject: [PATCH 7/7] update integration_tests/CMAKELists.txt --- integration_tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 4e5be4880b..834ce77b36 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -671,7 +671,7 @@ RUN(NAME func_static_01 LABELS cpython llvm c wasm) RUN(NAME func_static_02 LABELS cpython llvm c wasm) RUN(NAME func_dep_03 LABELS cpython llvm c) RUN(NAME func_dep_04 LABELS cpython llvm c) -RUN(NAME func_internal_def_01 LABELS cpython llvm) +RUN(NAME func_internal_def_01 LABELS cpython llvm NOFAST) RUN(NAME float_01 LABELS cpython llvm c wasm wasm_x64) RUN(NAME recursive_01 LABELS cpython llvm c wasm wasm_x64 wasm_x86)