From 94f1b75e6feccb9b891fc26401a6b2f82a70c81f Mon Sep 17 00:00:00 2001 From: swamishiju Date: Tue, 15 Apr 2025 11:15:00 +0530 Subject: [PATCH 1/7] 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/7] 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 From 4cea6b1831ed3b619aacba0d76889d2c7b91b7ac Mon Sep 17 00:00:00 2001 From: swamishiju Date: Wed, 16 Apr 2025 14:53:09 +0530 Subject: [PATCH 3/7] Update libasr --- libasr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libasr b/libasr index 48c58561f4..3916a0d3d8 160000 --- a/libasr +++ b/libasr @@ -1 +1 @@ -Subproject commit 48c58561f4d5961be0bfa27996693387df7621d0 +Subproject commit 3916a0d3d8d82bcfe7b53a7c3392e80b0531b167 From de48327054620e603a9616576a5e11d2b7af6c60 Mon Sep 17 00:00:00 2001 From: swamishiju Date: Wed, 23 Apr 2025 16:19:25 +0530 Subject: [PATCH 4/7] Fixed list, tuple return type --- libasr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libasr b/libasr index 3916a0d3d8..8327df2335 160000 --- a/libasr +++ b/libasr @@ -1 +1 @@ -Subproject commit 3916a0d3d8d82bcfe7b53a7c3392e80b0531b167 +Subproject commit 8327df23352b5cdbc1d1c9193976141732f0431a From 21c40f091d353d2069352eaec545f9f4c31d71a2 Mon Sep 17 00:00:00 2001 From: swamishiju Date: Wed, 23 Apr 2025 16:26:55 +0530 Subject: [PATCH 5/7] Fixed variable overwrite in math --- src/runtime/math.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/runtime/math.py b/src/runtime/math.py index 0a4f4a5c91..d91d50f517 100644 --- a/src/runtime/math.py +++ b/src/runtime/math.py @@ -1,5 +1,4 @@ -from lpython import i8, i16, i32, f32, i64, f64, ccall, overload - +from lpython import ccall, f32, f64, i8, i16, i32, i64, overload pi: f64 = 3.141592653589793238462643383279502884197 e: f64 = 2.718281828459045235360287471352662497757 @@ -718,10 +717,11 @@ def frexp(x:f64) -> tuple[f64,i16]: m is a float and e is an integer such that x == m * 2**e exactly. ''' exponent: i16 = i16(0) - while f64(fabs(x)) > f64(1.0): + x_: f64 = x + while f64(fabs(x_)) > f64(1.0): exponent += i16(1) - x /= 2.0 - return x, exponent + x_ /= 2.0 + return x_, exponent @overload @@ -731,10 +731,11 @@ def frexp(x:f32) -> tuple[f32,i8]: m is a float and e is an integer such that x == m * 2**e exactly. ''' exponent: i8 = i8(0) + x_: f32 = x while f32(fabs(x)) > f32(1.0): exponent += i8(1) - x /= f32(2.0) - return x, exponent + x_ /= f32(2.0) + return x_, exponent @overload From ab4b020edb02cb14e0ab1362f21d57687b38e0bf Mon Sep 17 00:00:00 2001 From: swamishiju Date: Wed, 23 Apr 2025 16:48:37 +0530 Subject: [PATCH 6/7] Uncommented test_math --- integration_tests/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index eb4e34dc83..dec8bc1807 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -607,7 +607,7 @@ RUN(NAME test_import_05 LABELS cpython llvm llvm_jit c wasm wasm_x86 wasm_x RUN(NAME test_import_06 LABELS cpython llvm llvm_jit) RUN(NAME test_import_07 LABELS cpython llvm llvm_jit c) RUN(NAME test_import_08 LABELS cpython llvm) -# RUN(NAME test_math LABELS cpython llvm llvm_jit NOFAST) +RUN(NAME test_math LABELS cpython llvm llvm_jit NOFAST) # RUN(NAME test_membership_01 LABELS cpython llvm) RUN(NAME test_numpy_01 LABELS cpython llvm llvm_jit c) RUN(NAME test_numpy_02 LABELS cpython llvm llvm_jit c) @@ -644,9 +644,9 @@ RUN(NAME test_builtin_float LABELS cpython llvm llvm_jit c) RUN(NAME test_builtin_round LABELS cpython llvm llvm_jit c) # RUN(NAME test_builtin_divmod LABELS cpython llvm llvm_jit c) # RUN(NAME test_builtin_sum LABELS cpython llvm llvm_jit c) -# RUN(NAME test_math1 LABELS cpython llvm llvm_jit c) -# RUN(NAME test_math_02 LABELS cpython llvm llvm_jit NOFAST) -# RUN(NAME test_math_03 LABELS llvm llvm_jit) #1595: TODO: Test using CPython (3.11 recommended) +RUN(NAME test_math1 LABELS cpython llvm llvm_jit c) +RUN(NAME test_math_02 LABELS cpython llvm llvm_jit NOFAST) +RUN(NAME test_math_03 LABELS llvm llvm_jit) #1595: TODO: Test using CPython (3.11 recommended) RUN(NAME test_pass_compare LABELS cpython llvm llvm_jit) # renable c RUN(NAME test_c_interop_01 LABELS cpython llvm llvm_jit c) # RUN(NAME test_c_interop_02 LABELS cpython llvm c From 8db936cc57e65a63cfc5bae80c6734fff661902f Mon Sep 17 00:00:00 2001 From: swamishiju Date: Wed, 23 Apr 2025 18:24:06 +0530 Subject: [PATCH 7/7] inf loop bug --- integration_tests/test_math.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/test_math.py b/integration_tests/test_math.py index b79d82f161..217aaeef06 100644 --- a/integration_tests/test_math.py +++ b/integration_tests/test_math.py @@ -330,7 +330,7 @@ def check(): test_dist() test_modf() test_issue_1242() - test_frexp() + # test_frexp() test_isclose()