From 94f1b75e6feccb9b891fc26401a6b2f82a70c81f Mon Sep 17 00:00:00 2001 From: swamishiju Date: Tue, 15 Apr 2025 11:15:00 +0530 Subject: [PATCH 1/2] Optional args --- integration_tests/CMakeLists.txt | 2 +- libasr | 2 +- src/lpython/semantics/python_ast_to_asr.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index cf7be4b65f..eb4e34dc83 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -805,7 +805,7 @@ RUN(NAME test_statistics_01 LABELS cpython llvm llvm_jit NOFAST) RUN(NAME test_attributes LABELS cpython llvm llvm_jit) # RUN(NAME test_str_attributes LABELS cpython llvm llvm_jit c) RUN(NAME kwargs_01 LABELS cpython llvm llvm_jit NOFAST) # renable c -# RUN(NAME def_func_01 LABELS cpython llvm llvm_jit c) +RUN(NAME def_func_01 LABELS cpython llvm llvm_jit) # renable c RUN(NAME func_inline_01 LABELS llvm llvm_jit c wasm) RUN(NAME func_inline_02 LABELS cpython llvm llvm_jit c) diff --git a/libasr b/libasr index 4a52ccea1b..8f61f60494 160000 --- a/libasr +++ b/libasr @@ -1 +1 @@ -Subproject commit 4a52ccea1b6157a259ac478bd84477d119d4adbd +Subproject commit 8f61f6049404b0b7c46dd15ca6dbcb24022b3bc1 diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 8b832f0c5b..1bf8c1e8d4 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1178,7 +1178,7 @@ class CommonVisitor : public AST::BaseVisitor { size_t missed_args_count =0; for (size_t def_arg = args.size(); def_arg < func->n_args; def_arg++){ ASR::Variable_t* var = ASRUtils::EXPR2VAR(func->m_args[def_arg]); - if(var->m_symbolic_value == nullptr) { + if(var->m_presence != ASR::presenceType::Optional) { missed_args_names+= "'" + std::string(var->m_name) + "' and "; missed_args_count++; } else { @@ -4570,7 +4570,8 @@ class SymbolTableVisitor : public CommonVisitor { std::string arg_s = arg; ASR::expr_t *value = nullptr; ASR::expr_t *init_expr = nullptr; - if (i >= default_arg_index_start){ + bool is_optional_arg = i>=default_arg_index_start; + if (is_optional_arg){ size_t default_arg_index = i - default_arg_index_start; this->visit_expr(*(x.m_args.m_defaults[default_arg_index])); init_expr = ASRUtils::EXPR(tmp); @@ -4593,7 +4594,7 @@ class SymbolTableVisitor : public CommonVisitor { } ASR::accessType s_access = ASR::accessType::Public; ASR::presenceType s_presence = ASR::presenceType::Required; - if (i >= default_arg_index_start){ + if (is_optional_arg){ s_presence = ASR::presenceType::Optional; } bool value_attr = false; From 39f24976e9747b9f4df1177cfecf565324706a18 Mon Sep 17 00:00:00 2001 From: swamishiju Date: Wed, 16 Apr 2025 09:50:58 +0530 Subject: [PATCH 2/2] update libasr --- libasr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libasr b/libasr index 8f61f60494..3916a0d3d8 160000 --- a/libasr +++ b/libasr @@ -1 +1 @@ -Subproject commit 8f61f6049404b0b7c46dd15ca6dbcb24022b3bc1 +Subproject commit 3916a0d3d8d82bcfe7b53a7c3392e80b0531b167