From 43bec5e5dd4c777cd40214c36b4aa1c6bc1a844b Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Mon, 22 May 2023 07:10:01 +0530 Subject: [PATCH 01/31] Added SymbolicSymbol as Intrinsic Function --- src/libasr/ASR.asdl | 1 + src/libasr/asr_utils.h | 11 +++++ src/libasr/pass/intrinsic_function_registry.h | 49 +++++++++++++++++-- src/lpython/semantics/python_ast_to_asr.cpp | 4 +- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/libasr/ASR.asdl b/src/libasr/ASR.asdl index 29cf337c62..97be2a81f9 100644 --- a/src/libasr/ASR.asdl +++ b/src/libasr/ASR.asdl @@ -370,6 +370,7 @@ ttype | Const(ttype type) | CPtr() | TypeParameter(identifier param, dimension* dims) + | SymbolicExpression() | FunctionType(ttype* arg_types, ttype? return_var_type, abi abi, deftype deftype, string? bindc_name, bool elemental, bool pure, bool module, bool inline, bool static, ttype* type_params, diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index b1da17c7ec..f5c71458c8 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -1214,6 +1214,9 @@ static inline std::string type_to_str_python(const ASR::ttype_t *t, ASR::TypeParameter_t *p = ASR::down_cast(t); return p->m_param; } + case ASR::ttypeType::SymbolicExpression: { + return "S"; + } default : throw LCompilersException("Not implemented " + std::to_string(t->type)); } } @@ -1617,6 +1620,11 @@ inline int extract_dimensions_from_ttype(ASR::ttype_t *x, m_dims = tp->m_dims; break; } + case ASR::ttypeType::SymbolicExpression: { + n_dims = 0; + m_dims = nullptr; + break; + } default: throw LCompilersException("Not implemented " + std::to_string(x->type) + "."); } @@ -2205,6 +2213,9 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, case ASR::ttypeType::CPtr: { return true; } + case ASR::ttypeType::SymbolicExpression: { + return true; + } case (ASR::ttypeType::Real) : { ASR::Real_t *a2 = ASR::down_cast(a); ASR::Real_t *b2 = ASR::down_cast(b); diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 1d93b0bada..9a798e89fe 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -58,6 +58,7 @@ enum class IntrinsicFunctions : int64_t { ListIndex, Partition, ListReverse, + SymbolicSymbol // ... }; @@ -1243,6 +1244,41 @@ namespace Partition { } } // namespace Partition +namespace SymbolicSymbol { + + static inline ASR::expr_t *eval_SymbolicSymbol(Allocator &al, const Location &loc, + Vec &args) { + // TODO + return nullptr; + } + + static inline ASR::asr_t* create_SymbolicSymbol(Allocator& al, const Location& loc, + Vec& args, + const std::function err) { + if (args.size() != 1) { + err("Intrinsic Symbol function accepts exactly 1 argument", loc); + } + + ASR::ttype_t *type = ASRUtils::expr_type(args[0]); + if (!ASRUtils::is_character(*type)) { + err("Argument of the abs function must be a Character", + args[0]->base.loc); + } + + ASR::ttype_t *to_type = ASRUtils::TYPE(ASR::make_SymbolicExpression_t(al, loc)); + return UnaryIntrinsicFunction::create_UnaryFunction(al, loc, args, eval_SymbolicSymbol, + static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), 0, to_type); + } + + static inline ASR::expr_t* instantiate_SymbolicSymbol(Allocator &al, const Location &loc, + SymbolTable *scope, Vec& arg_types, + Vec& new_args, int64_t /*overload_id*/, ASR::expr_t* compile_time_value) { + // TODO + return nullptr; + } + +} // namespace SymbolicSymbol + namespace IntrinsicFunctionRegistry { static const std::map& intrinsic_function_by_id_db = { @@ -1272,7 +1308,9 @@ namespace IntrinsicFunctionRegistry { {static_cast(ASRUtils::IntrinsicFunctions::Any), &Any::instantiate_Any}, {static_cast(ASRUtils::IntrinsicFunctions::Partition), - &Partition::instantiate_Partition} + &Partition::instantiate_Partition}, + {static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), + &SymbolicSymbol::instantiate_SymbolicSymbol} }; static const std::map& intrinsic_function_id_to_name = { @@ -1308,7 +1346,9 @@ namespace IntrinsicFunctionRegistry { {static_cast(ASRUtils::IntrinsicFunctions::ListIndex), "list.index"}, {static_cast(ASRUtils::IntrinsicFunctions::ListReverse), - "list.reverse"} + "list.reverse"}, + {static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), + "Symbol"} }; static const std::map { 4, dims.p, dims.size())); } else if (var_annotation == "CPtr") { type = ASRUtils::TYPE(ASR::make_CPtr_t(al, loc)); + } else if (var_annotation == "S") { + type = ASRUtils::TYPE(ASR::make_SymbolicExpression_t(al, loc)); } else if (var_annotation == "pointer") { LCOMPILERS_ASSERT(n_args == 1); AST::expr_t* underlying_type = m_args[0]; @@ -6980,7 +6982,7 @@ class BodyVisitor : public CommonVisitor { if (!s) { std::set not_cpython_builtin = { - "sin", "cos", "gamma", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "exp", "exp2", "expm1" + "sin", "cos", "gamma", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "exp", "exp2", "expm1", "symbol" }; if (ASRUtils::IntrinsicFunctionRegistry::is_intrinsic_function(call_name) && (not_cpython_builtin.find(call_name) == not_cpython_builtin.end() || From 6bdbdef32d8820c59b7544935a358e358aa15fcf Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Mon, 22 May 2023 09:53:37 +0530 Subject: [PATCH 02/31] Supporting sympy imports for CPython --- src/libasr/pass/intrinsic_function_registry.h | 2 +- src/lpython/semantics/python_ast_to_asr.cpp | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 9a798e89fe..48bb3fc4de 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -1261,7 +1261,7 @@ namespace SymbolicSymbol { ASR::ttype_t *type = ASRUtils::expr_type(args[0]); if (!ASRUtils::is_character(*type)) { - err("Argument of the abs function must be a Character", + err("Argument of the Symbol function must be a Character", args[0]->base.loc); } diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index b8b3e5f134..ca6fe26a55 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -303,16 +303,21 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab, const Location &loc, diag::Diagnostics &diagnostics, LocationManager &lm, bool intrinsic, std::vector &rl_path, - bool &lpython, bool& enum_py, bool& copy, + bool &lpython, bool& enum_py, bool& copy, bool& sympy, const std::function err, bool allow_implicit_casting) { lpython = false; enum_py = false; copy = false; + sympy = false; if( module_name == "copy" ) { copy = true; return nullptr; } + if (module_name == "sympy") { + sympy = true; + return nullptr; + } LCOMPILERS_ASSERT(symtab); if (symtab->get_scope().find(module_name) != symtab->get_scope().end()) { ASR::symbol_t *m = symtab->get_symbol(module_name); @@ -612,10 +617,10 @@ class CommonVisitor : public AST::BaseVisitor { SymbolTable *tu_symtab = ASRUtils::get_tu_symtab(current_scope); std::string rl_path = get_runtime_library_dir(); std::vector paths = {rl_path, parent_dir}; - bool lpython, enum_py, copy; + bool lpython, enum_py, copy, sympy; ASR::Module_t *m = load_module(al, tu_symtab, module_name, loc, diag, lm, true, paths, - lpython, enum_py, copy, + lpython, enum_py, copy, sympy, [&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); }, allow_implicit_casting); LCOMPILERS_ASSERT(!lpython && !enum_py) @@ -4128,13 +4133,13 @@ class SymbolTableVisitor : public CommonVisitor { if (!main_module) { st = st->parent; } - bool lpython, enum_py, copy; + bool lpython, enum_py, copy, sympy; set_module_symbol(msym, paths); t = (ASR::symbol_t*)(load_module(al, st, - msym, x.base.base.loc, diag, lm, false, paths, lpython, enum_py, copy, + msym, x.base.base.loc, diag, lm, false, paths, lpython, enum_py, copy, sympy, [&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); }, allow_implicit_casting)); - if (lpython || enum_py || copy) { + if (lpython || enum_py || copy || sympy) { // TODO: For now we skip lpython import completely. Later on we should note what symbols // got imported from it, and give an error message if an annotation is used without // importing it. @@ -4189,13 +4194,13 @@ class SymbolTableVisitor : public CommonVisitor { st = st->parent; } for (auto &mod_sym : mods) { - bool lpython, enum_py, copy; + bool lpython, enum_py, copy, sympy; set_module_symbol(mod_sym, paths); t = (ASR::symbol_t*)(load_module(al, st, - mod_sym, x.base.base.loc, diag, lm, false, paths, lpython, enum_py, copy, + mod_sym, x.base.base.loc, diag, lm, false, paths, lpython, enum_py, copy, sympy, [&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); }, allow_implicit_casting)); - if (lpython || enum_py || copy) { + if (lpython || enum_py || copy || sympy) { // TODO: For now we skip lpython import completely. Later on we should note what symbols // got imported from it, and give an error message if an annotation is used without // importing it. From be0f715e51b85c248f456256792525bb7fb7793f Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sat, 27 May 2023 15:13:33 +0530 Subject: [PATCH 03/31] Added some utilities and removed instantiate function --- src/libasr/asr_utils.h | 6 ++++++ src/libasr/pass/intrinsic_function_registry.h | 9 --------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index f5c71458c8..d203a958c7 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -311,6 +311,9 @@ static inline std::string type_to_str(const ASR::ttype_t *t) ASR::TypeParameter_t* tp = ASR::down_cast(t); return tp->m_param; } + case ASR::ttypeType::SymbolicExpression: { + return "symbolic expression"; + } default : throw LCompilersException("Not implemented " + std::to_string(t->type) + "."); } } @@ -1082,6 +1085,9 @@ static inline std::string get_type_code(const ASR::ttype_t *t, bool use_undersco return "Const[" + get_type_code(p->m_type, use_underscore_sep, encode_dimensions_, set_dimensional_hint) + "]"; } + case ASR::ttypeType::SymbolicExpression: { + return "S"; + } default: { throw LCompilersException("Type encoding not implemented for " + std::to_string(t->type)); diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 48bb3fc4de..7cd8d68781 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -1270,13 +1270,6 @@ namespace SymbolicSymbol { static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), 0, to_type); } - static inline ASR::expr_t* instantiate_SymbolicSymbol(Allocator &al, const Location &loc, - SymbolTable *scope, Vec& arg_types, - Vec& new_args, int64_t /*overload_id*/, ASR::expr_t* compile_time_value) { - // TODO - return nullptr; - } - } // namespace SymbolicSymbol namespace IntrinsicFunctionRegistry { @@ -1309,8 +1302,6 @@ namespace IntrinsicFunctionRegistry { &Any::instantiate_Any}, {static_cast(ASRUtils::IntrinsicFunctions::Partition), &Partition::instantiate_Partition}, - {static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), - &SymbolicSymbol::instantiate_SymbolicSymbol} }; static const std::map& intrinsic_function_id_to_name = { From efdfed8fa2425f92569870bfaad092f856e219da Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Mon, 29 May 2023 08:16:24 +0530 Subject: [PATCH 04/31] Initial code for supporting assignment and print statements --- src/libasr/codegen/asr_to_llvm.cpp | 73 +++++++++++++++++++++++++++++- src/libasr/codegen/llvm_utils.h | 13 ++++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 54bcb3ef14..eb25245da5 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -170,6 +170,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor bool prototype_only; llvm::StructType *complex_type_4, *complex_type_8; llvm::StructType *complex_type_4_ptr, *complex_type_8_ptr; + llvm::StructType *symbolic_expr_type; + llvm::StructType *symbolic_expr_type_ptr; llvm::PointerType *character_type; llvm::PointerType *list_type; @@ -451,6 +453,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor el_type = getComplexType(a_kind, true); break; } + case ASR::ttypeType::SymbolicExpression: { + el_type = getSymbolicExpressionType(true); + break; + } case ASR::ttypeType::Logical: { el_type = llvm::Type::getInt1Ty(context); break; @@ -489,6 +495,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor el_type = getComplexType(a_kind); break; } + case ASR::ttypeType::SymbolicExpression: { + el_type = getSymbolicExpressionType(); + break; + } case ASR::ttypeType::Logical: { el_type = llvm::Type::getInt1Ty(context); break; @@ -655,6 +665,15 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return nullptr; } + inline llvm::Type* getSymbolicExpressionType(bool get_pointer=false) { + llvm::Type* type = symbolic_expr_type; + if( get_pointer ){ + return type->getPointerTo(); + } else { + return type; + } + } + llvm::Type* getMemberType(ASR::ttype_t* mem_type, ASR::Variable_t* member) { llvm::Type* llvm_mem_type = nullptr; switch( mem_type->type ) { @@ -690,6 +709,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm_mem_type = getComplexType(a_kind); break; } + case ASR::ttypeType::SymbolicExpression: { + llvm_mem_type = getSymbolicExpressionType(); + break; + } case ASR::ttypeType::Character: { llvm_mem_type = character_type; break; @@ -825,6 +848,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor mem_type = getComplexType(a_kind); break; } + case ASR::ttypeType::SymbolicExpression: { + mem_type = getSymbolicExpressionType(); + break; + } default: throw CodeGenError("Cannot identify the type of member, '" + std::string(member->m_name) + @@ -1262,10 +1289,16 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor std::vector els_8_ptr = { llvm::Type::getDoublePtrTy(context), llvm::Type::getDoublePtrTy(context)}; + std::vector els_symbolic = { + llvm::Type::getInt8PtrTy(context)}; + std::vector els_symbolic_ptr = { + llvm::Type::getInt8PtrTy(context)->getPointerTo()}; complex_type_4 = llvm::StructType::create(context, els_4, "complex_4"); complex_type_8 = llvm::StructType::create(context, els_8, "complex_8"); complex_type_4_ptr = llvm::StructType::create(context, els_4_ptr, "complex_4_ptr"); complex_type_8_ptr = llvm::StructType::create(context, els_8_ptr, "complex_8_ptr"); + symbolic_expr_type = llvm::StructType::create(context, els_symbolic, "symbolic_expr"); + symbolic_expr_type_ptr = llvm::StructType::create(context, els_symbolic_ptr, "symbolic_expr_ptr"); character_type = llvm::Type::getInt8PtrTy(context); list_type = llvm::Type::getInt8PtrTy(context); @@ -1969,6 +2002,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor list_api->reverse(plist, asr_el_type, *module); } + void generate_SymbolicSymbol(ASR::expr_t* m_arg) { + // TODO + } + void visit_IntrinsicFunction(const ASR::IntrinsicFunction_t& x) { switch (static_cast(x.m_intrinsic_id)) { case ASRUtils::IntrinsicFunctions::ListIndex: { @@ -2032,6 +2069,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor generate_ListReverse(x.m_args[0]); break; } + case ASRUtils::IntrinsicFunctions::SymbolicSymbol: { + generate_SymbolicSymbol(x.m_args[0]); + break; + } default: { throw CodeGenError( ASRUtils::IntrinsicFunctionRegistry:: get_intrinsic_function_name(x.m_intrinsic_id) + @@ -3144,6 +3185,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor m_dims, n_dims, a_kind, m_abi); break; } + case (ASR::ttypeType::SymbolicExpression) : { + llvm_type = getSymbolicExpressionType(); + break; + } default : throw CodeGenError("Support for type " + ASRUtils::type_to_str(asr_type) + " not yet implemented."); @@ -3635,6 +3680,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } break; } + case (ASR::ttypeType::SymbolicExpression) : { + if (arg_m_abi == ASR::abiType::BindC) { + type = getSymbolicExpressionType(); + } else { + type = getSymbolicExpressionType(true); + } + break; + } case (ASR::ttypeType::Character) : if (arg_m_abi == ASR::abiType::BindC) { type = character_type; @@ -3996,6 +4049,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return_type = getFPType(a_kind); break; } + case (ASR::ttypeType::SymbolicExpression) : { + return_type = getSymbolicExpressionType(); + break; + } case (ASR::ttypeType::Complex) : { int a_kind = down_cast(return_var_type0)->m_kind; if (a_kind == 4) { @@ -4214,7 +4271,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (!prototype_only) { define_function_entry(x); - for (size_t i=0; ivisit_stmt(*x.m_body[i]); } @@ -6811,6 +6867,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor std::vector fmt; llvm::Value *sep = nullptr; llvm::Value *end = nullptr; + bool is_symbolic_expr = false; if (x.m_separator) { this->visit_expr_wrapper(x.m_separator, true); sep = tmp; @@ -6987,6 +7044,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // TODO: Use recursion to generalise for any underlying type in enum fmt.push_back("%d"); args.push_back(tmp); + } else if (t->type == ASR::ttypeType::SymbolicExpression) { + fmt.push_back("%s"); + args.push_back(tmp); + is_symbolic_expr = true; } else { throw LCompilersException("Printing support is not available for " + ASRUtils::type_to_str(t) + " type."); @@ -7002,7 +7063,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor std::vector printf_args; printf_args.push_back(fmt_ptr); printf_args.insert(printf_args.end(), args.begin(), args.end()); - printf(context, *module, *builder, printf_args); + if (is_symbolic_expr) { + symengine_str(context, *module, *builder, printf_args); + } else { + printf(context, *module, *builder, printf_args); + } } void visit_Stop(const ASR::Stop_t &x) { @@ -7325,6 +7390,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor target_type = getComplexType(a_kind); break; } + case (ASR::ttypeType::SymbolicExpression) : { + target_type = getSymbolicExpressionType(); + break; + } case (ASR::ttypeType::Character) : { ASR::Variable_t *orig_arg = nullptr; if( func_subrout->type == ASR::symbolType::Function ) { diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index e3a06ba977..0965436ae3 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -29,6 +29,19 @@ namespace LCompilers { builder.CreateCall(fn_printf, args); } + static inline void symengine_str(llvm::LLVMContext &context, llvm::Module &module, + llvm::IRBuilder<> &builder, const std::vector &args) + { + llvm::Function *fn_symengine_str = module.getFunction("symengine_str"); + if (!fn_symengine_str) { + llvm::FunctionType *function_type = llvm::FunctionType::get( + llvm::Type::getVoidTy(context), {llvm::Type::getInt8PtrTy(context)}, true); + fn_symengine_str = llvm::Function::Create(function_type, + llvm::Function::ExternalLinkage, "symengine_str", &module); + } + builder.CreateCall(fn_symengine_str, args); + } + static inline void print_error(llvm::LLVMContext &context, llvm::Module &module, llvm::IRBuilder<> &builder, const std::vector &args) { From 3d19dbfb13d8fdd87d9d744b161e883cfed3fc3c Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Mon, 29 May 2023 10:20:43 +0530 Subject: [PATCH 05/31] added verify_args for symbolicsymbol --- src/libasr/pass/intrinsic_function_registry.h | 10 ++++++++-- src/lpython/semantics/python_ast_to_asr.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 82ca99fed4..a89e03d720 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -1911,6 +1911,10 @@ namespace Partition { namespace SymbolicSymbol { + static inline void verify_args(const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) { + // TODO + } + static inline ASR::expr_t *eval_SymbolicSymbol(Allocator &al, const Location &loc, Vec &args) { // TODO @@ -1981,6 +1985,8 @@ namespace IntrinsicFunctionRegistry { {nullptr, &ListIndex::verify_args}}, {static_cast(ASRUtils::IntrinsicFunctions::ListReverse), {nullptr, &ListReverse::verify_args}}, + {static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), + {nullptr, &SymbolicSymbol::verify_args}}, }; static const std::map& intrinsic_function_id_to_name = { @@ -2018,11 +2024,11 @@ namespace IntrinsicFunctionRegistry { {static_cast(ASRUtils::IntrinsicFunctions::ListReverse), "list.reverse"}, {static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), - "Symbol"} + "Symbol"}, {static_cast(ASRUtils::IntrinsicFunctions::Any), "any"}, {static_cast(ASRUtils::IntrinsicFunctions::Sum), - "sum"}, + "sum"} }; diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 226449de0f..16915dc777 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -6992,7 +6992,7 @@ class BodyVisitor : public CommonVisitor { if (!s) { std::set not_cpython_builtin = { - "sin", "cos", "gamma", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "exp", "exp2", "expm1", "symbol" + "sin", "cos", "gamma", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "exp", "exp2", "expm1", "Symbol", "sum" // For sum called over lists }; if (ASRUtils::IntrinsicFunctionRegistry::is_intrinsic_function(call_name) && From 58580096c5a11adae49dc06cb48ee604057b3888 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 31 May 2023 15:54:41 +0530 Subject: [PATCH 06/31] Added verify_args function for symbolic symbol --- src/libasr/pass/intrinsic_function_registry.h | 10 +++++++++- tests/reference/asr-structs_02-f95782c.json | 2 +- tests/reference/asr-structs_02-f95782c.stderr | 8 ++++---- tests/reference/run_dbg-test_assert_01-2f34744.json | 2 +- tests/reference/run_dbg-test_assert_01-2f34744.stderr | 5 +---- tests/reference/run_dbg-test_assert_02-c6de25a.json | 2 +- tests/reference/run_dbg-test_assert_02-c6de25a.stderr | 5 +---- tests/reference/run_dbg-test_assert_03-bd7b7dd.json | 2 +- tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr | 9 +-------- tests/reference/run_dbg-test_quit_01-30889cc.json | 2 +- tests/reference/run_dbg-test_quit_01-30889cc.stderr | 5 +---- tests/reference/run_dbg-test_raise_01-dfd86ca.json | 2 +- tests/reference/run_dbg-test_raise_01-dfd86ca.stderr | 5 +---- 13 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index a89e03d720..3e35d2c0be 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -1912,7 +1912,15 @@ namespace Partition { namespace SymbolicSymbol { static inline void verify_args(const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) { - // TODO + const Location& loc = x.base.base.loc; + ASRUtils::require_impl(x.n_args == 1, + "SymbolicSymbol intrinsic must have exactly 1 input argument", + loc, diagnostics); + + ASR::ttype_t* input_type = ASRUtils::expr_type(x.m_args[0]); + ASRUtils::require_impl(ASR::is_a(*input_type), + "SymbolicSymbol intrinsic expects a character input argument", + loc, diagnostics); } static inline ASR::expr_t *eval_SymbolicSymbol(Allocator &al, const Location &loc, diff --git a/tests/reference/asr-structs_02-f95782c.json b/tests/reference/asr-structs_02-f95782c.json index 6a45542935..24140fd36d 100644 --- a/tests/reference/asr-structs_02-f95782c.json +++ b/tests/reference/asr-structs_02-f95782c.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-structs_02-f95782c.stderr", - "stderr_hash": "feebf3045d755a862d604df8c8ab0e0cb346f7fbc285256b18e9d559", + "stderr_hash": "25ebdf5faffdedaddac304fc25074c443954393b961263561cfc7ae3", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-structs_02-f95782c.stderr b/tests/reference/asr-structs_02-f95782c.stderr index 4ae0a08977..18e98ccace 100644 --- a/tests/reference/asr-structs_02-f95782c.stderr +++ b/tests/reference/asr-structs_02-f95782c.stderr @@ -1,5 +1,5 @@ -semantic error: struct S s must be initialized a value - --> tests/errors/structs_02.py:8:5 +semantic error: S not supported yet in Attribute. + --> tests/errors/structs_02.py:9:5 | -8 | s: S - | ^^^^ +9 | s.x = 2 + | ^^^ diff --git a/tests/reference/run_dbg-test_assert_01-2f34744.json b/tests/reference/run_dbg-test_assert_01-2f34744.json index 127eb3e44f..beccfbccb9 100644 --- a/tests/reference/run_dbg-test_assert_01-2f34744.json +++ b/tests/reference/run_dbg-test_assert_01-2f34744.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_assert_01-2f34744.stderr", - "stderr_hash": "5ded88da4106fc9a3cfbaad6f82cc820a79a6ef8cc1661ecfcb37924", + "stderr_hash": "9780f14da16190bb2efebe1c372b28a0ce6f57298236e40797358841", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_assert_01-2f34744.stderr b/tests/reference/run_dbg-test_assert_01-2f34744.stderr index c561678d44..8eb69e4b09 100644 --- a/tests/reference/run_dbg-test_assert_01-2f34744.stderr +++ b/tests/reference/run_dbg-test_assert_01-2f34744.stderr @@ -1,5 +1,2 @@ - File "tests/runtime_errors/test_assert_01.py", line 4 - test() - File "tests/runtime_errors/test_assert_01.py", line 2 - assert False +warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` AssertionError diff --git a/tests/reference/run_dbg-test_assert_02-c6de25a.json b/tests/reference/run_dbg-test_assert_02-c6de25a.json index 25aa716a99..34ef3d9f27 100644 --- a/tests/reference/run_dbg-test_assert_02-c6de25a.json +++ b/tests/reference/run_dbg-test_assert_02-c6de25a.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_assert_02-c6de25a.stderr", - "stderr_hash": "ddba8a92bcfd5a30016735589da0dc56f2785e7636afcc0edeca4139", + "stderr_hash": "406d7ca32a021df1d36f5cb743c61960b7f61026d710fdb73144f7f4", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_assert_02-c6de25a.stderr b/tests/reference/run_dbg-test_assert_02-c6de25a.stderr index 4fe6972010..2d9c0635d8 100644 --- a/tests/reference/run_dbg-test_assert_02-c6de25a.stderr +++ b/tests/reference/run_dbg-test_assert_02-c6de25a.stderr @@ -1,5 +1,2 @@ - File "tests/runtime_errors/test_assert_02.py", line 4 - test() - File "tests/runtime_errors/test_assert_02.py", line 2 - assert 1 != 1, "One is equal to one." +warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` AssertionError: One is equal to one. diff --git a/tests/reference/run_dbg-test_assert_03-bd7b7dd.json b/tests/reference/run_dbg-test_assert_03-bd7b7dd.json index c05b63780b..26e6fc4eee 100644 --- a/tests/reference/run_dbg-test_assert_03-bd7b7dd.json +++ b/tests/reference/run_dbg-test_assert_03-bd7b7dd.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_assert_03-bd7b7dd.stderr", - "stderr_hash": "7f97899439260443b40867e81d7c481c2fc23ec84ee777e7b43984d8", + "stderr_hash": "9780f14da16190bb2efebe1c372b28a0ce6f57298236e40797358841", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr b/tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr index 8ee39fc2e8..8eb69e4b09 100644 --- a/tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr +++ b/tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr @@ -1,9 +1,2 @@ - File "tests/runtime_errors/test_assert_03.py", line 10 - main() - File "tests/runtime_errors/test_assert_03.py", line 8 - f() - File "tests/runtime_errors/test_assert_03.py", line 2 - g() - File "tests/runtime_errors/test_assert_03.py", line 5 - assert False +warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` AssertionError diff --git a/tests/reference/run_dbg-test_quit_01-30889cc.json b/tests/reference/run_dbg-test_quit_01-30889cc.json index 4e50fcce5f..0fab2ac07c 100644 --- a/tests/reference/run_dbg-test_quit_01-30889cc.json +++ b/tests/reference/run_dbg-test_quit_01-30889cc.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_quit_01-30889cc.stderr", - "stderr_hash": "f5a660003a2da017d3ced437825a1e6f1c0c046d73cf68d183c92a40", + "stderr_hash": "038c4a17db8c6aa5dc2eba3d9c89c2f8c60c5a4cf9e39c571d40a98a", "returncode": 10 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_quit_01-30889cc.stderr b/tests/reference/run_dbg-test_quit_01-30889cc.stderr index c7e212253e..e28644b815 100644 --- a/tests/reference/run_dbg-test_quit_01-30889cc.stderr +++ b/tests/reference/run_dbg-test_quit_01-30889cc.stderr @@ -1,5 +1,2 @@ - File "tests/runtime_errors/test_quit_01.py", line 4 - test() - File "tests/runtime_errors/test_quit_01.py", line 2 - quit(10) +warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` STOP diff --git a/tests/reference/run_dbg-test_raise_01-dfd86ca.json b/tests/reference/run_dbg-test_raise_01-dfd86ca.json index 199a810c97..0d8a6716a0 100644 --- a/tests/reference/run_dbg-test_raise_01-dfd86ca.json +++ b/tests/reference/run_dbg-test_raise_01-dfd86ca.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_raise_01-dfd86ca.stderr", - "stderr_hash": "073aae20bbe7cf78e116825e3e825365b07230972ff7bcb3a5dddb93", + "stderr_hash": "a286a50e7f4c8aa1b734fc677923de139b9f185d0f1b57a8177691fe", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_raise_01-dfd86ca.stderr b/tests/reference/run_dbg-test_raise_01-dfd86ca.stderr index 9c5a4dafd0..a8150ed5b9 100644 --- a/tests/reference/run_dbg-test_raise_01-dfd86ca.stderr +++ b/tests/reference/run_dbg-test_raise_01-dfd86ca.stderr @@ -1,5 +1,2 @@ - File "tests/runtime_errors/test_raise_01.py", line 4 - test() - File "tests/runtime_errors/test_raise_01.py", line 2 - raise +warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` ERROR STOP From ab626c61e6f3eb0e9e4000eddbd941e4ffa5192e Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Tue, 13 Jun 2023 07:42:38 +0530 Subject: [PATCH 07/31] Add support in C backend for assignment, printing and addition operations --- src/libasr/codegen/asr_to_c.cpp | 8 +++ src/libasr/codegen/asr_to_c_cpp.h | 35 +++++++++++-- src/libasr/codegen/c_utils.h | 33 ++++++++++++ src/libasr/pass/intrinsic_function_registry.h | 51 ++++++++++++++++++- src/lpython/semantics/python_ast_to_asr.cpp | 20 ++++++++ 5 files changed, 141 insertions(+), 6 deletions(-) diff --git a/src/libasr/codegen/asr_to_c.cpp b/src/libasr/codegen/asr_to_c.cpp index b6837ad9f3..e449b75470 100644 --- a/src/libasr/codegen/asr_to_c.cpp +++ b/src/libasr/codegen/asr_to_c.cpp @@ -465,6 +465,11 @@ class ASRToCVisitor : public BaseCCPPVisitor dims = convert_dims_c(n_dims, m_dims, v_m_type, is_fixed_size); sub = format_type_c(dims, type_name, v_m_name, use_ref, dummy); } + } else if (ASR::is_a(*v_m_type)) { + headers.insert("symengine/cwrapper.h"); + std::string type_name = "basic"; + std::string v_m_name = v.m_name; + sub = format_type_c("", type_name, v_m_name, use_ref, dummy); } else if (ASRUtils::is_logical(*v_m_type)) { bool is_fixed_size = true; dims = convert_dims_c(n_dims, m_dims, v_m_type, is_fixed_size); @@ -1214,6 +1219,9 @@ R"( v.pop_back(); v.push_back("creal(" + src + ")"); v.push_back("cimag(" + src + ")"); + } else if(value_type->type == ASR::ttypeType::SymbolicExpression){ + v.pop_back(); + v.push_back("basic_str(" + src + ")"); } if (i+1!=x.n_values) { tmp_gen += "\%s"; diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h index 7adade6e6c..4b26d7136e 100644 --- a/src/libasr/codegen/asr_to_c_cpp.h +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -433,6 +433,8 @@ R"(#include sub = "double complex "; } } + } else if (ASR::is_a(*return_var->m_type)) { + sub = "basic "; } else if (ASR::is_a(*return_var->m_type)) { sub = "void* "; } else if (ASR::is_a(*return_var->m_type)) { @@ -664,6 +666,10 @@ R"(#include v->m_intent == ASRUtils::intent_return_var ) { d += ";\n"; } + if (ASR::is_a(*v->m_type)) { + std::string v_m_name = v->m_name; + d += indent + "basic_new_stack(" + v_m_name + ");\n"; + } decl += check_tmp_buffer() + d; } if (ASR::is_a(*v->m_type)) { @@ -1014,7 +1020,12 @@ R"(#include src += alloc + indent + c_ds_api->get_deepcopy(m_target_type, value, target) + "\n"; } } else { - src += alloc + indent + c_ds_api->get_deepcopy(m_target_type, value, target) + "\n"; + if (m_target_type->type == ASR::ttypeType::SymbolicExpression){ + ASR::expr_t* m_value_expr = x.m_value; + src += alloc + indent + c_ds_api->get_deepcopy_symbolic(m_value_expr, value, target) + "\n"; + } else { + src += alloc + indent + c_ds_api->get_deepcopy(m_target_type, value, target) + "\n"; + } } } else { src += indent + c_ds_api->get_deepcopy(m_target_type, value, target) + "\n"; @@ -2356,7 +2367,6 @@ R"(#include } void visit_IntrinsicFunction(const ASR::IntrinsicFunction_t &x) { - LCOMPILERS_ASSERT(x.n_args == 1) std::string out; switch (x.m_intrinsic_id) { SET_INTRINSIC_NAME(Sin, "sin"); @@ -2372,6 +2382,17 @@ R"(#include SET_INTRINSIC_NAME(Exp, "exp"); SET_INTRINSIC_NAME(Exp2, "exp2"); SET_INTRINSIC_NAME(Expm1, "expm1"); + SET_INTRINSIC_NAME(SymbolicSymbol, "Symbol"); + case (static_cast(ASRUtils::IntrinsicFunctions::SymbolicAdd)): { + LCOMPILERS_ASSERT(x.n_args == 2); + this->visit_expr(*x.m_args[0]); + std::string arg1 = src; + this->visit_expr(*x.m_args[1]); + std::string arg2 = src; + out = arg1 + "," + arg2; + src = out; + break; + } default : { throw LCompilersException("IntrinsicFunction: `" + ASRUtils::get_intrinsic_name(x.m_intrinsic_id) @@ -2379,9 +2400,13 @@ R"(#include } } headers.insert("math.h"); - this->visit_expr(*x.m_args[0]); - out += "(" + src + ")"; - src = out; + if (x.n_args == 1) { + this->visit_expr(*x.m_args[0]); + if (x.m_intrinsic_id != static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol)) { + out = "(" + src + ")"; + src = out; + } + } } }; diff --git a/src/libasr/codegen/c_utils.h b/src/libasr/codegen/c_utils.h index d79924a611..5abb49597c 100644 --- a/src/libasr/codegen/c_utils.h +++ b/src/libasr/codegen/c_utils.h @@ -3,6 +3,7 @@ #include #include +#include namespace LCompilers { @@ -527,6 +528,35 @@ class CCPPDSUtils { return result; } + std::string get_deepcopy_symbolic(ASR::expr_t *value_expr, std::string value, std::string target) { + std::string result; + if (ASR::is_a(*value_expr)) { + result = "basic_assign(" + target + ", " + value + ");"; + } else if (ASR::is_a(*value_expr)) { + ASR::IntrinsicFunction_t* intrinsic_func = ASR::down_cast(value_expr); + int64_t intrinsic_id = intrinsic_func->m_intrinsic_id; + switch (static_cast(intrinsic_id)) { + case LCompilers::ASRUtils::IntrinsicFunctions::SymbolicSymbol: { + result = "symbol_set(" + target + ", " + value + ");"; + break; + } + case LCompilers::ASRUtils::IntrinsicFunctions::SymbolicAdd: { + size_t delimiterPos = value.find(","); + std::string leftPart = value.substr(0, delimiterPos); + std::string rightPart = value.substr(delimiterPos + 1); + result = "basic_add(" + target + ", " + leftPart + ", " + rightPart + ");"; + break; + } + default: { + throw LCompilersException("IntrinsicFunction: `" + + LCompilers::ASRUtils::get_intrinsic_name(intrinsic_id) + + "` is not implemented"); + } + } + } + return result; + } + std::string get_type(ASR::ttype_t *t) { LCOMPILERS_ASSERT(CUtils::is_non_primitive_DT(t)); if (ASR::is_a(*t)) { @@ -594,6 +624,9 @@ class CCPPDSUtils { case ASR::ttypeType::Complex: { return "(%f, %f)"; } + case ASR::ttypeType::SymbolicExpression: { + return "%s"; + } case ASR::ttypeType::Pointer: { if( !deref_ptr ) { return "%p"; diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 1b0fb3e04c..61e1b6414a 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -65,6 +65,7 @@ enum class IntrinsicFunctions : int64_t { ListReverse, SymbolicSymbol, ListPop, + SymbolicAdd, Sum, // ... }; @@ -2035,6 +2036,48 @@ namespace SymbolicSymbol { } // namespace SymbolicSymbol +namespace SymbolicAdd { + + static inline void verify_args(const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) { + ASRUtils::require_impl(x.n_args == 2, "SymbolicAdd must have exactly two arguments", + x.base.base.loc, diagnostics); + + ASR::ttype_t* left_type = ASRUtils::expr_type(x.m_args[0]); + ASR::ttype_t* right_type = ASRUtils::expr_type(x.m_args[1]); + + ASRUtils::require_impl(ASR::is_a(*left_type) && + ASR::is_a(*right_type), + "Both arguments of SymbolicAdd must be of type SymbolicExpression", + x.base.base.loc, diagnostics); + } + + static inline ASR::expr_t *eval_SymbolicAdd(Allocator &al, const Location &loc, + Vec &args) { + // TODO + return nullptr; + } + + static inline ASR::asr_t* create_SymbolicAdd(Allocator& al, const Location& loc, + Vec& args, + const std::function err) { + if (args.size() != 2) { + err("Intrinsic Symbol Add operator accepts exactly 2 arguments", loc); + } + + Vec arg_values; + arg_values.reserve(al, args.size()); + for( size_t i = 0; i < args.size(); i++ ) { + arg_values.push_back(al, ASRUtils::expr_value(args[i])); + } + ASR::expr_t* compile_time_value = eval_SymbolicAdd(al, loc, arg_values); + ASR::ttype_t *to_type = ASRUtils::TYPE(ASR::make_SymbolicExpression_t(al, loc)); + return ASR::make_IntrinsicFunction_t(al, loc, + static_cast(ASRUtils::IntrinsicFunctions::SymbolicAdd), + args.p, args.size(), 0, to_type, compile_time_value); + } + +} // namespace SymbolicAdd + namespace IntrinsicFunctionRegistry { static const std::map(ASRUtils::IntrinsicFunctions::SymbolicSymbol), {nullptr, &SymbolicSymbol::verify_args}}, + {static_cast(ASRUtils::IntrinsicFunctions::SymbolicAdd), + {nullptr, &SymbolicAdd::verify_args}}, }; static const std::map& intrinsic_function_id_to_name = { @@ -2123,6 +2168,8 @@ namespace IntrinsicFunctionRegistry { "Symbol"}, {static_cast(ASRUtils::IntrinsicFunctions::ListPop), "list.pop"}, + {static_cast(ASRUtils::IntrinsicFunctions::SymbolicAdd), + "SymbolicAdd"}, {static_cast(ASRUtils::IntrinsicFunctions::Any), "any"}, {static_cast(ASRUtils::IntrinsicFunctions::Sum), @@ -2152,7 +2199,8 @@ namespace IntrinsicFunctionRegistry { {"list.index", {&ListIndex::create_ListIndex, &ListIndex::eval_list_index}}, {"list.reverse", {&ListReverse::create_ListReverse, &ListReverse::eval_list_reverse}}, {"Symbol", {&SymbolicSymbol::create_SymbolicSymbol, &SymbolicSymbol::eval_SymbolicSymbol}}, - {"list.pop", {&ListPop::create_ListPop, &ListPop::eval_list_pop}} + {"list.pop", {&ListPop::create_ListPop, &ListPop::eval_list_pop}}, + {"SymbolicAdd", {&SymbolicAdd::create_SymbolicAdd, &SymbolicAdd::eval_SymbolicAdd}}, }; static inline bool is_intrinsic_function(const std::string& name) { @@ -2260,6 +2308,7 @@ inline std::string get_intrinsic_name(int x) { INTRINSIC_NAME_CASE(ListReverse) INTRINSIC_NAME_CASE(SymbolicSymbol) INTRINSIC_NAME_CASE(ListPop) + INTRINSIC_NAME_CASE(SymbolicAdd) INTRINSIC_NAME_CASE(Sum) default : { throw LCompilersException("pickle: intrinsic_id not implemented"); diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index e2b53867d9..303ec05cf3 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2193,6 +2193,26 @@ class CommonVisitor : public AST::BaseVisitor { tuple_type_vec.p, tuple_type_vec.n)); tmp = ASR::make_TupleConcat_t(al, loc, left, right, tuple_type, value); return; + } else if (ASR::is_a(*left_type) + && ASR::is_a(*right_type)) { + switch (op) { + case ASR::binopType::Add: { + Vec args_with_symbolic; + args_with_symbolic.reserve(al, 2); + args_with_symbolic.push_back(al, left); + args_with_symbolic.push_back(al, right); + ASRUtils::create_intrinsic_function create_function = + ASRUtils::IntrinsicFunctionRegistry::get_create_function("SymbolicAdd"); + tmp = create_function(al, loc, args_with_symbolic, [&](const std::string& msg, const Location& loc) { + throw SemanticError(msg, loc); + }); + return; + } + default: { + throw SemanticError("Not implemented: The following symbolic binary operator has not been implemented", loc); + break; + } + } } else { std::string ltype = ASRUtils::type_to_str_python(ASRUtils::expr_type(left)); std::string rtype = ASRUtils::type_to_str_python(ASRUtils::expr_type(right)); From 53aaa99253b5312445d06216e0019eec8020ef8c Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 14 Jun 2023 08:47:32 +0530 Subject: [PATCH 08/31] Introduced symbolic constant pi --- src/libasr/codegen/asr_to_c_cpp.h | 5 ++- src/libasr/codegen/c_utils.h | 4 +++ src/libasr/pass/intrinsic_function_registry.h | 31 +++++++++++++++++++ src/lpython/semantics/python_ast_to_asr.cpp | 15 +++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h index 4b26d7136e..0ea3bd3fa6 100644 --- a/src/libasr/codegen/asr_to_c_cpp.h +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -2383,6 +2383,7 @@ R"(#include SET_INTRINSIC_NAME(Exp2, "exp2"); SET_INTRINSIC_NAME(Expm1, "expm1"); SET_INTRINSIC_NAME(SymbolicSymbol, "Symbol"); + SET_INTRINSIC_NAME(SymbolicPi, "pi"); case (static_cast(ASRUtils::IntrinsicFunctions::SymbolicAdd)): { LCOMPILERS_ASSERT(x.n_args == 2); this->visit_expr(*x.m_args[0]); @@ -2400,7 +2401,9 @@ R"(#include } } headers.insert("math.h"); - if (x.n_args == 1) { + if (x.n_args == 0){ + src = out; + } else if (x.n_args == 1) { this->visit_expr(*x.m_args[0]); if (x.m_intrinsic_id != static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol)) { out = "(" + src + ")"; diff --git a/src/libasr/codegen/c_utils.h b/src/libasr/codegen/c_utils.h index 5abb49597c..bd68a3485a 100644 --- a/src/libasr/codegen/c_utils.h +++ b/src/libasr/codegen/c_utils.h @@ -547,6 +547,10 @@ class CCPPDSUtils { result = "basic_add(" + target + ", " + leftPart + ", " + rightPart + ");"; break; } + case LCompilers::ASRUtils::IntrinsicFunctions::SymbolicPi: { + result = "basic_const_pi(" + target + ");"; + break; + } default: { throw LCompilersException("IntrinsicFunction: `" + LCompilers::ASRUtils::get_intrinsic_name(intrinsic_id) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 61e1b6414a..99c1a06cf4 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -67,6 +67,7 @@ enum class IntrinsicFunctions : int64_t { ListPop, SymbolicAdd, Sum, + SymbolicPi, // ... }; @@ -2078,6 +2079,30 @@ namespace SymbolicAdd { } // namespace SymbolicAdd +namespace SymbolicPi { + + static inline void verify_args(const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) { + return; + } + + static inline ASR::expr_t *eval_SymbolicPi(Allocator &al, const Location &loc, + Vec &args) { + // TODO + return nullptr; + } + + static inline ASR::asr_t* create_SymbolicPi(Allocator& al, const Location& loc, + Vec& args, + const std::function err) { + ASR::expr_t* compile_time_value = eval_SymbolicPi(al, loc, args); + ASR::ttype_t *to_type = ASRUtils::TYPE(ASR::make_SymbolicExpression_t(al, loc)); + return ASR::make_IntrinsicFunction_t(al, loc, + static_cast(ASRUtils::IntrinsicFunctions::SymbolicPi), + nullptr, 0, 0, to_type, compile_time_value); + } + +} // namespace SymbolicPi + namespace IntrinsicFunctionRegistry { static const std::map(ASRUtils::IntrinsicFunctions::SymbolicAdd), {nullptr, &SymbolicAdd::verify_args}}, + {static_cast(ASRUtils::IntrinsicFunctions::SymbolicPi), + {nullptr, &SymbolicPi::verify_args}}, }; static const std::map& intrinsic_function_id_to_name = { @@ -2170,6 +2197,8 @@ namespace IntrinsicFunctionRegistry { "list.pop"}, {static_cast(ASRUtils::IntrinsicFunctions::SymbolicAdd), "SymbolicAdd"}, + {static_cast(ASRUtils::IntrinsicFunctions::SymbolicPi), + "pi"}, {static_cast(ASRUtils::IntrinsicFunctions::Any), "any"}, {static_cast(ASRUtils::IntrinsicFunctions::Sum), @@ -2201,6 +2230,7 @@ namespace IntrinsicFunctionRegistry { {"Symbol", {&SymbolicSymbol::create_SymbolicSymbol, &SymbolicSymbol::eval_SymbolicSymbol}}, {"list.pop", {&ListPop::create_ListPop, &ListPop::eval_list_pop}}, {"SymbolicAdd", {&SymbolicAdd::create_SymbolicAdd, &SymbolicAdd::eval_SymbolicAdd}}, + {"pi", {&SymbolicPi::create_SymbolicPi, &SymbolicPi::eval_SymbolicPi}}, }; static inline bool is_intrinsic_function(const std::string& name) { @@ -2309,6 +2339,7 @@ inline std::string get_intrinsic_name(int x) { INTRINSIC_NAME_CASE(SymbolicSymbol) INTRINSIC_NAME_CASE(ListPop) INTRINSIC_NAME_CASE(SymbolicAdd) + INTRINSIC_NAME_CASE(SymbolicPi) INTRINSIC_NAME_CASE(Sum) default : { throw LCompilersException("pickle: intrinsic_id not implemented"); diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 303ec05cf3..849c157d3d 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -585,6 +585,8 @@ class CommonVisitor : public AST::BaseVisitor { std::vector rt_vec; SetChar dependencies; bool allow_implicit_casting; + // Stores the name of imported functions and the modules they are imported from + std::map imported_functions; CommonVisitor(Allocator &al, LocationManager &lm, SymbolTable *symbol_table, diag::Diagnostics &diagnostics, bool main_module, @@ -3066,6 +3068,8 @@ class CommonVisitor : public AST::BaseVisitor { void visit_Name(const AST::Name_t &x) { std::string name = x.m_id; ASR::symbol_t *s = current_scope->resolve_symbol(name); + std::set not_cpython_builtin = { + "pi"}; if (s) { tmp = ASR::make_Var_t(al, x.base.base.loc, s); } else if (name == "i32" || name == "i64" || name == "f32" || @@ -3089,6 +3093,14 @@ class CommonVisitor : public AST::BaseVisitor { ASR::symbol_t *s = current_scope->resolve_symbol(name); LCOMPILERS_ASSERT(s); tmp = ASR::make_Var_t(al, x.base.base.loc, s); + } else if (ASRUtils::IntrinsicFunctionRegistry::is_intrinsic_function(name) && + (not_cpython_builtin.find(name) == not_cpython_builtin.end() || + imported_functions.find(name) != imported_functions.end() )) { + ASRUtils::create_intrinsic_function create_func = + ASRUtils::IntrinsicFunctionRegistry::get_create_function(name); + Vec args_; + tmp = create_func(al, x.base.base.loc, args_, [&](const std::string &msg, const Location &loc) { + throw SemanticError(msg, loc); }); } else { throw SemanticError("Variable '" + name + "' not declared", x.base.base.loc); @@ -4423,9 +4435,6 @@ class BodyVisitor : public CommonVisitor { public: ASR::asr_t *asr; std::vector do_loop_variables; - // Stores the name of imported functions and the modules they are imported from - std::map imported_functions; - BodyVisitor(Allocator &al, LocationManager &lm, ASR::asr_t *unit, diag::Diagnostics &diagnostics, bool main_module, std::map &ast_overload, From 9010ebae0ccea39c1a0c0cad39e92bc20fbe87ed Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 14 Jun 2023 22:47:48 +0530 Subject: [PATCH 09/31] Added support for symengine through the C backend --- src/bin/lpython.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index 4d0d9de724..5fcf1744d8 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1244,8 +1244,10 @@ int link_executable(const std::vector &infiles, cmd += s + " "; } cmd += " -I " + rtlib_header_dir; + cmd += " -I${CONDA_PREFIX}/include"; cmd += " -L" + base_path + " -Wl,-rpath," + base_path + " -l" + runtime_lib + " -lm"; + cmd += " -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lsymengine"; if (compiler_options.enable_cpython) { std::string py_version = "3.10"; std::string py_flags = R"(-I $CONDA_PREFIX/include/python)" + py_version + R"( -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lpython)" + py_version + R"()"; From 645fa7d48898f1c35ab6725676938ed59472121e Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 09:14:28 +0530 Subject: [PATCH 10/31] Removed changes related to the LLVM backend and removed warnings --- src/libasr/codegen/asr_to_llvm.cpp | 73 +------------------ src/libasr/codegen/llvm_utils.h | 13 ---- src/libasr/pass/intrinsic_function_registry.h | 16 ++-- 3 files changed, 10 insertions(+), 92 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 09f97648f1..4f1c7f1fae 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -170,8 +170,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor bool prototype_only; llvm::StructType *complex_type_4, *complex_type_8; llvm::StructType *complex_type_4_ptr, *complex_type_8_ptr; - llvm::StructType *symbolic_expr_type; - llvm::StructType *symbolic_expr_type_ptr; llvm::PointerType *character_type; llvm::PointerType *list_type; std::vector struct_type_stack; @@ -458,10 +456,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor el_type = getComplexType(a_kind, true); break; } - case ASR::ttypeType::SymbolicExpression: { - el_type = getSymbolicExpressionType(true); - break; - } case ASR::ttypeType::Logical: { el_type = llvm::Type::getInt1Ty(context); break; @@ -500,10 +494,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor el_type = getComplexType(a_kind); break; } - case ASR::ttypeType::SymbolicExpression: { - el_type = getSymbolicExpressionType(); - break; - } case ASR::ttypeType::Logical: { el_type = llvm::Type::getInt1Ty(context); break; @@ -671,15 +661,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return nullptr; } - inline llvm::Type* getSymbolicExpressionType(bool get_pointer=false) { - llvm::Type* type = symbolic_expr_type; - if( get_pointer ){ - return type->getPointerTo(); - } else { - return type; - } - } - llvm::Type* getMemberType(ASR::ttype_t* mem_type, ASR::Variable_t* member) { llvm::Type* llvm_mem_type = nullptr; switch( mem_type->type ) { @@ -715,10 +696,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm_mem_type = getComplexType(a_kind); break; } - case ASR::ttypeType::SymbolicExpression: { - llvm_mem_type = getSymbolicExpressionType(); - break; - } case ASR::ttypeType::Character: { llvm_mem_type = character_type; break; @@ -886,10 +863,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor mem_type = getComplexType(a_kind); break; } - case ASR::ttypeType::SymbolicExpression: { - mem_type = getSymbolicExpressionType(); - break; - } default: throw CodeGenError("Cannot identify the type of member, '" + std::string(member->m_name) + @@ -1331,16 +1304,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor std::vector els_8_ptr = { llvm::Type::getDoublePtrTy(context), llvm::Type::getDoublePtrTy(context)}; - std::vector els_symbolic = { - llvm::Type::getInt8PtrTy(context)}; - std::vector els_symbolic_ptr = { - llvm::Type::getInt8PtrTy(context)->getPointerTo()}; complex_type_4 = llvm::StructType::create(context, els_4, "complex_4"); complex_type_8 = llvm::StructType::create(context, els_8, "complex_8"); complex_type_4_ptr = llvm::StructType::create(context, els_4_ptr, "complex_4_ptr"); complex_type_8_ptr = llvm::StructType::create(context, els_8_ptr, "complex_8_ptr"); - symbolic_expr_type = llvm::StructType::create(context, els_symbolic, "symbolic_expr"); - symbolic_expr_type_ptr = llvm::StructType::create(context, els_symbolic_ptr, "symbolic_expr_ptr"); character_type = llvm::Type::getInt8PtrTy(context); list_type = llvm::Type::getInt8PtrTy(context); @@ -2083,10 +2050,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *pos = tmp; tmp = list_api->pop_position(plist, pos, asr_el_type, module.get(), name2memidx); } - - void generate_SymbolicSymbol(ASR::expr_t* m_arg) { - // TODO - } void visit_IntrinsicFunction(const ASR::IntrinsicFunction_t& x) { switch (static_cast(x.m_intrinsic_id)) { @@ -2162,10 +2125,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } break ; } - case ASRUtils::IntrinsicFunctions::SymbolicSymbol: { - generate_SymbolicSymbol(x.m_args[0]); - break; - } default: { throw CodeGenError( ASRUtils::IntrinsicFunctionRegistry:: get_intrinsic_function_name(x.m_intrinsic_id) + @@ -3215,10 +3174,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor m_dims, n_dims, a_kind, m_abi); break; } - case (ASR::ttypeType::SymbolicExpression) : { - llvm_type = getSymbolicExpressionType(); - break; - } case (ASR::ttypeType::FunctionType) : { ASR::Function_t* fn = ASR::down_cast( symbol_get_past_external(type_declaration)); @@ -3688,14 +3643,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } break; } - case (ASR::ttypeType::SymbolicExpression) : { - if (arg_m_abi == ASR::abiType::BindC) { - type = getSymbolicExpressionType(); - } else { - type = getSymbolicExpressionType(true); - } - break; - } case (ASR::ttypeType::Character) : { ASR::Character_t* v_type = down_cast(asr_type); a_kind = v_type->m_kind; @@ -4053,10 +4000,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return_type = getFPType(a_kind); break; } - case (ASR::ttypeType::SymbolicExpression) : { - return_type = getSymbolicExpressionType(); - break; - } case (ASR::ttypeType::Complex) : { int a_kind = down_cast(return_var_type0)->m_kind; if (a_kind == 4) { @@ -4284,6 +4227,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (!prototype_only) { define_function_entry(x); + for (size_t i=0; ivisit_stmt(*x.m_body[i]); } @@ -7168,7 +7112,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor std::vector fmt; llvm::Value *sep = nullptr; llvm::Value *end = nullptr; - bool is_symbolic_expr = false; if (x.m_separator) { this->visit_expr_wrapper(x.m_separator, true); sep = tmp; @@ -7346,10 +7289,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // TODO: Use recursion to generalise for any underlying type in enum fmt.push_back("%d"); args.push_back(tmp); - } else if (t->type == ASR::ttypeType::SymbolicExpression) { - fmt.push_back("%s"); - args.push_back(tmp); - is_symbolic_expr = true; } else { throw LCompilersException("Printing support is not available for " + ASRUtils::type_to_str(t) + " type."); @@ -7365,11 +7304,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor std::vector printf_args; printf_args.push_back(fmt_ptr); printf_args.insert(printf_args.end(), args.begin(), args.end()); - if (is_symbolic_expr) { - symengine_str(context, *module, *builder, printf_args); - } else { - printf(context, *module, *builder, printf_args); - } + printf(context, *module, *builder, printf_args); } void visit_Stop(const ASR::Stop_t &x) { @@ -7715,10 +7650,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor target_type = getComplexType(a_kind); break; } - case (ASR::ttypeType::SymbolicExpression) : { - target_type = getSymbolicExpressionType(); - break; - } case (ASR::ttypeType::Character) : { ASR::Variable_t *orig_arg = nullptr; if( func_subrout->type == ASR::symbolType::Function ) { diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index 29fae39eb8..106e32ad7f 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -29,19 +29,6 @@ namespace LCompilers { builder.CreateCall(fn_printf, args); } - static inline void symengine_str(llvm::LLVMContext &context, llvm::Module &module, - llvm::IRBuilder<> &builder, const std::vector &args) - { - llvm::Function *fn_symengine_str = module.getFunction("symengine_str"); - if (!fn_symengine_str) { - llvm::FunctionType *function_type = llvm::FunctionType::get( - llvm::Type::getVoidTy(context), {llvm::Type::getInt8PtrTy(context)}, true); - fn_symengine_str = llvm::Function::Create(function_type, - llvm::Function::ExternalLinkage, "symengine_str", &module); - } - builder.CreateCall(fn_symengine_str, args); - } - static inline void print_error(llvm::LLVMContext &context, llvm::Module &module, llvm::IRBuilder<> &builder, const std::vector &args) { diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 99c1a06cf4..bc28405ea8 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2011,8 +2011,8 @@ namespace SymbolicSymbol { loc, diagnostics); } - static inline ASR::expr_t *eval_SymbolicSymbol(Allocator &al, const Location &loc, - Vec &args) { + static inline ASR::expr_t *eval_SymbolicSymbol(Allocator &/*al*/, + const Location &/*loc*/, Vec& /*args*/) { // TODO return nullptr; } @@ -2052,8 +2052,8 @@ namespace SymbolicAdd { x.base.base.loc, diagnostics); } - static inline ASR::expr_t *eval_SymbolicAdd(Allocator &al, const Location &loc, - Vec &args) { + static inline ASR::expr_t *eval_SymbolicAdd(Allocator &/*al*/, + const Location &/*loc*/, Vec& /*args*/) { // TODO return nullptr; } @@ -2081,19 +2081,19 @@ namespace SymbolicAdd { namespace SymbolicPi { - static inline void verify_args(const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) { + static inline void verify_args(const ASR::IntrinsicFunction_t& /*x*/, diag::Diagnostics& /*diagnostics*/) { return; } - static inline ASR::expr_t *eval_SymbolicPi(Allocator &al, const Location &loc, - Vec &args) { + static inline ASR::expr_t *eval_SymbolicPi(Allocator &/*al*/, + const Location &/*loc*/, Vec& /*args*/) { // TODO return nullptr; } static inline ASR::asr_t* create_SymbolicPi(Allocator& al, const Location& loc, Vec& args, - const std::function err) { + const std::function /*err*/) { ASR::expr_t* compile_time_value = eval_SymbolicPi(al, loc, args); ASR::ttype_t *to_type = ASRUtils::TYPE(ASR::make_SymbolicExpression_t(al, loc)); return ASR::make_IntrinsicFunction_t(al, loc, From fccbdde924804a5081e3e0e5a0019b88e8013904 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 10:02:28 +0530 Subject: [PATCH 11/31] Updated references --- src/lpython/semantics/python_ast_to_asr.cpp | 5 +-- tests/reference/asr-structs_02-f95782c.json | 2 +- tests/reference/asr-structs_02-f95782c.stderr | 8 ++--- .../cpp-test_builtin_pow-56b3f92.json | 2 +- .../cpp-test_builtin_pow-56b3f92.stdout | 34 +++++++++---------- .../run_dbg-test_assert_01-2f34744.json | 2 +- .../run_dbg-test_assert_01-2f34744.stderr | 5 ++- .../run_dbg-test_assert_02-c6de25a.json | 2 +- .../run_dbg-test_assert_02-c6de25a.stderr | 5 ++- .../run_dbg-test_assert_03-bd7b7dd.json | 2 +- .../run_dbg-test_assert_03-bd7b7dd.stderr | 9 ++++- .../run_dbg-test_quit_01-30889cc.json | 2 +- .../run_dbg-test_quit_01-30889cc.stderr | 5 ++- .../run_dbg-test_raise_01-dfd86ca.json | 2 +- .../run_dbg-test_raise_01-dfd86ca.stderr | 5 ++- 15 files changed, 55 insertions(+), 35 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index f453d00667..af54189dcf 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1042,8 +1042,6 @@ class CommonVisitor : public AST::BaseVisitor { type = ASRUtils::make_Array_t_util(al, loc, type, dims.p, dims.size()); } else if (var_annotation == "CPtr") { type = ASRUtils::TYPE(ASR::make_CPtr_t(al, loc)); - } else if (var_annotation == "S") { - type = ASRUtils::TYPE(ASR::make_SymbolicExpression_t(al, loc)); } else if (var_annotation == "pointer") { LCOMPILERS_ASSERT(n_args == 1); AST::expr_t* underlying_type = m_args[0]; @@ -1075,6 +1073,9 @@ class CommonVisitor : public AST::BaseVisitor { } } } + } else if (var_annotation == "S") { + type = ASRUtils::TYPE(ASR::make_SymbolicExpression_t(al, loc)); + return type; } if( raise_error ) { throw SemanticError("Unsupported type annotation: " + var_annotation, loc); diff --git a/tests/reference/asr-structs_02-f95782c.json b/tests/reference/asr-structs_02-f95782c.json index 24140fd36d..6a45542935 100644 --- a/tests/reference/asr-structs_02-f95782c.json +++ b/tests/reference/asr-structs_02-f95782c.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-structs_02-f95782c.stderr", - "stderr_hash": "25ebdf5faffdedaddac304fc25074c443954393b961263561cfc7ae3", + "stderr_hash": "feebf3045d755a862d604df8c8ab0e0cb346f7fbc285256b18e9d559", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-structs_02-f95782c.stderr b/tests/reference/asr-structs_02-f95782c.stderr index 18e98ccace..4ae0a08977 100644 --- a/tests/reference/asr-structs_02-f95782c.stderr +++ b/tests/reference/asr-structs_02-f95782c.stderr @@ -1,5 +1,5 @@ -semantic error: S not supported yet in Attribute. - --> tests/errors/structs_02.py:9:5 +semantic error: struct S s must be initialized a value + --> tests/errors/structs_02.py:8:5 | -9 | s.x = 2 - | ^^^ +8 | s: S + | ^^^^ diff --git a/tests/reference/cpp-test_builtin_pow-56b3f92.json b/tests/reference/cpp-test_builtin_pow-56b3f92.json index 35e93ea482..ff0359ca3b 100644 --- a/tests/reference/cpp-test_builtin_pow-56b3f92.json +++ b/tests/reference/cpp-test_builtin_pow-56b3f92.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-test_builtin_pow-56b3f92.stdout", - "stdout_hash": "91af820d143a62722ec2b753462b130c48fbcd87665c001823f64282", + "stdout_hash": "2691b799159bf9807468796c6ed130f1bf09469ae62a0bf0e942274e", "stderr": "cpp-test_builtin_pow-56b3f92.stderr", "stderr_hash": "859ce76c74748f2d32c7eab92cfbba789a78d4cbf5818646b99806ea", "returncode": 0 diff --git a/tests/reference/cpp-test_builtin_pow-56b3f92.stdout b/tests/reference/cpp-test_builtin_pow-56b3f92.stdout index 08b4d9ff1c..6351a10c59 100644 --- a/tests/reference/cpp-test_builtin_pow-56b3f92.stdout +++ b/tests/reference/cpp-test_builtin_pow-56b3f92.stdout @@ -255,26 +255,26 @@ void test_pow() assert (__lpython_overloaded_8__pow(false, false) == 1); a1 = 4.50000000000000000e+00; a2 = 2.29999999999999982e+00; - assert (abs(__lpython_overloaded_3__pow(a1, a2) - 3.17971929089206000e+01) < eps); - assert (abs(__lpython_overloaded_3__pow(a2, a1) - 4.24399889427765871e+01) < eps); + assert ((__lpython_overloaded_3__pow(a1, a2) - 3.17971929089206000e+01) < eps); + assert ((__lpython_overloaded_3__pow(a2, a1) - 4.24399889427765871e+01) < eps); x = 3; y = 2.29999999999999982e+00; - assert (abs(__lpython_overloaded_6__pow(x, y) - 1.25135025328431819e+01) < eps); - assert (abs(__lpython_overloaded_7__pow(y, x) - 1.21669999999999980e+01) < eps); - assert (abs(__lpython_overloaded_6__pow(x, 5.50000000000000000e+00) - 4.20888346239237194e+02) < eps); - assert (abs(__lpython_overloaded_1__pow(2, -1) - 5.00000000000000000e-01) < eps); - assert (abs(__lpython_overloaded_1__pow(6, -4) - 7.71604938271604895e-04) < eps); - assert (abs(__lpython_overloaded_1__pow(-3, -5) + 4.11522633744856002e-03) < eps); - assert (abs(__lpython_overloaded_1__pow(6, -4) - 7.71604938271604895e-04) < eps); - assert (abs(__lpython_overloaded_3__pow( 4.50000000000000000e+00, 2.29999999999999982e+00) - 3.17971929089206000e+01) < eps); - assert (abs(__lpython_overloaded_3__pow( 2.29999999999999982e+00, 0.00000000000000000e+00) - 1.00000000000000000e+00) < eps); - assert (abs(__lpython_overloaded_3__pow( 2.29999999999999982e+00, - 1.50000000000000000e+00) - 2.86687162345994395e-01) < eps); - assert (abs(__lpython_overloaded_6__pow(2, 3.39999999999999991e+00) - 1.05560632861831536e+01) < eps); - assert (abs(__lpython_overloaded_6__pow(2, - 3.39999999999999991e+00) - 9.47322854068998882e-02) < eps); - assert (abs(__lpython_overloaded_7__pow( 3.39999999999999991e+00, 9) - 6.07169927664639836e+04) < eps); - assert (abs(__lpython_overloaded_7__pow( 0.00000000000000000e+00, 53) - 0.00000000000000000e+00) < eps); + assert ((__lpython_overloaded_6__pow(x, y) - 1.25135025328431819e+01) < eps); + assert ((__lpython_overloaded_7__pow(y, x) - 1.21669999999999980e+01) < eps); + assert ((__lpython_overloaded_6__pow(x, 5.50000000000000000e+00) - 4.20888346239237194e+02) < eps); + assert ((__lpython_overloaded_1__pow(2, -1) - 5.00000000000000000e-01) < eps); + assert ((__lpython_overloaded_1__pow(6, -4) - 7.71604938271604895e-04) < eps); + assert ((__lpython_overloaded_1__pow(-3, -5) + 4.11522633744856002e-03) < eps); + assert ((__lpython_overloaded_1__pow(6, -4) - 7.71604938271604895e-04) < eps); + assert ((__lpython_overloaded_3__pow( 4.50000000000000000e+00, 2.29999999999999982e+00) - 3.17971929089206000e+01) < eps); + assert ((__lpython_overloaded_3__pow( 2.29999999999999982e+00, 0.00000000000000000e+00) - 1.00000000000000000e+00) < eps); + assert ((__lpython_overloaded_3__pow( 2.29999999999999982e+00, - 1.50000000000000000e+00) - 2.86687162345994395e-01) < eps); + assert ((__lpython_overloaded_6__pow(2, 3.39999999999999991e+00) - 1.05560632861831536e+01) < eps); + assert ((__lpython_overloaded_6__pow(2, - 3.39999999999999991e+00) - 9.47322854068998882e-02) < eps); + assert ((__lpython_overloaded_7__pow( 3.39999999999999991e+00, 9) - 6.07169927664639836e+04) < eps); + assert ((__lpython_overloaded_7__pow( 0.00000000000000000e+00, 53) - 0.00000000000000000e+00) < eps); assert ((int32_t)(__lpython_overloaded_0__pow(4, 2)) == 16); - assert (abs(__lpython_overloaded_7__pow(- 4.23500000000000000e+03, 52) - 3.94800380598526379e+188) < eps); + assert ((__lpython_overloaded_7__pow(- 4.23500000000000000e+03, 52) - 3.94800380598526379e+188) < eps); i = 7; j = 2; k = 5; diff --git a/tests/reference/run_dbg-test_assert_01-2f34744.json b/tests/reference/run_dbg-test_assert_01-2f34744.json index beccfbccb9..127eb3e44f 100644 --- a/tests/reference/run_dbg-test_assert_01-2f34744.json +++ b/tests/reference/run_dbg-test_assert_01-2f34744.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_assert_01-2f34744.stderr", - "stderr_hash": "9780f14da16190bb2efebe1c372b28a0ce6f57298236e40797358841", + "stderr_hash": "5ded88da4106fc9a3cfbaad6f82cc820a79a6ef8cc1661ecfcb37924", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_assert_01-2f34744.stderr b/tests/reference/run_dbg-test_assert_01-2f34744.stderr index 8eb69e4b09..c561678d44 100644 --- a/tests/reference/run_dbg-test_assert_01-2f34744.stderr +++ b/tests/reference/run_dbg-test_assert_01-2f34744.stderr @@ -1,2 +1,5 @@ -warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` + File "tests/runtime_errors/test_assert_01.py", line 4 + test() + File "tests/runtime_errors/test_assert_01.py", line 2 + assert False AssertionError diff --git a/tests/reference/run_dbg-test_assert_02-c6de25a.json b/tests/reference/run_dbg-test_assert_02-c6de25a.json index 34ef3d9f27..25aa716a99 100644 --- a/tests/reference/run_dbg-test_assert_02-c6de25a.json +++ b/tests/reference/run_dbg-test_assert_02-c6de25a.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_assert_02-c6de25a.stderr", - "stderr_hash": "406d7ca32a021df1d36f5cb743c61960b7f61026d710fdb73144f7f4", + "stderr_hash": "ddba8a92bcfd5a30016735589da0dc56f2785e7636afcc0edeca4139", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_assert_02-c6de25a.stderr b/tests/reference/run_dbg-test_assert_02-c6de25a.stderr index 2d9c0635d8..4fe6972010 100644 --- a/tests/reference/run_dbg-test_assert_02-c6de25a.stderr +++ b/tests/reference/run_dbg-test_assert_02-c6de25a.stderr @@ -1,2 +1,5 @@ -warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` + File "tests/runtime_errors/test_assert_02.py", line 4 + test() + File "tests/runtime_errors/test_assert_02.py", line 2 + assert 1 != 1, "One is equal to one." AssertionError: One is equal to one. diff --git a/tests/reference/run_dbg-test_assert_03-bd7b7dd.json b/tests/reference/run_dbg-test_assert_03-bd7b7dd.json index 26e6fc4eee..c05b63780b 100644 --- a/tests/reference/run_dbg-test_assert_03-bd7b7dd.json +++ b/tests/reference/run_dbg-test_assert_03-bd7b7dd.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_assert_03-bd7b7dd.stderr", - "stderr_hash": "9780f14da16190bb2efebe1c372b28a0ce6f57298236e40797358841", + "stderr_hash": "7f97899439260443b40867e81d7c481c2fc23ec84ee777e7b43984d8", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr b/tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr index 8eb69e4b09..8ee39fc2e8 100644 --- a/tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr +++ b/tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr @@ -1,2 +1,9 @@ -warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` + File "tests/runtime_errors/test_assert_03.py", line 10 + main() + File "tests/runtime_errors/test_assert_03.py", line 8 + f() + File "tests/runtime_errors/test_assert_03.py", line 2 + g() + File "tests/runtime_errors/test_assert_03.py", line 5 + assert False AssertionError diff --git a/tests/reference/run_dbg-test_quit_01-30889cc.json b/tests/reference/run_dbg-test_quit_01-30889cc.json index 0fab2ac07c..4e50fcce5f 100644 --- a/tests/reference/run_dbg-test_quit_01-30889cc.json +++ b/tests/reference/run_dbg-test_quit_01-30889cc.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_quit_01-30889cc.stderr", - "stderr_hash": "038c4a17db8c6aa5dc2eba3d9c89c2f8c60c5a4cf9e39c571d40a98a", + "stderr_hash": "f5a660003a2da017d3ced437825a1e6f1c0c046d73cf68d183c92a40", "returncode": 10 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_quit_01-30889cc.stderr b/tests/reference/run_dbg-test_quit_01-30889cc.stderr index e28644b815..c7e212253e 100644 --- a/tests/reference/run_dbg-test_quit_01-30889cc.stderr +++ b/tests/reference/run_dbg-test_quit_01-30889cc.stderr @@ -1,2 +1,5 @@ -warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` + File "tests/runtime_errors/test_quit_01.py", line 4 + test() + File "tests/runtime_errors/test_quit_01.py", line 2 + quit(10) STOP diff --git a/tests/reference/run_dbg-test_raise_01-dfd86ca.json b/tests/reference/run_dbg-test_raise_01-dfd86ca.json index 0d8a6716a0..199a810c97 100644 --- a/tests/reference/run_dbg-test_raise_01-dfd86ca.json +++ b/tests/reference/run_dbg-test_raise_01-dfd86ca.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run_dbg-test_raise_01-dfd86ca.stderr", - "stderr_hash": "a286a50e7f4c8aa1b734fc677923de139b9f185d0f1b57a8177691fe", + "stderr_hash": "073aae20bbe7cf78e116825e3e825365b07230972ff7bcb3a5dddb93", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run_dbg-test_raise_01-dfd86ca.stderr b/tests/reference/run_dbg-test_raise_01-dfd86ca.stderr index a8150ed5b9..9c5a4dafd0 100644 --- a/tests/reference/run_dbg-test_raise_01-dfd86ca.stderr +++ b/tests/reference/run_dbg-test_raise_01-dfd86ca.stderr @@ -1,2 +1,5 @@ -warning: The `runtime stacktrace` is not enabled. To get the stacktraces, re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes` + File "tests/runtime_errors/test_raise_01.py", line 4 + test() + File "tests/runtime_errors/test_raise_01.py", line 2 + raise ERROR STOP From 81c4dbaab4196f3280974472da92447e3802c61a Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 10:26:51 +0530 Subject: [PATCH 12/31] fixed failing test --- src/libasr/codegen/asr_to_c_cpp.h | 2 +- .../cpp-test_builtin_pow-56b3f92.json | 2 +- .../cpp-test_builtin_pow-56b3f92.stdout | 34 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h index d6a4866cb8..3a9954b61b 100644 --- a/src/libasr/codegen/asr_to_c_cpp.h +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -2405,7 +2405,7 @@ R"(#include } else if (x.n_args == 1) { this->visit_expr(*x.m_args[0]); if (x.m_intrinsic_id != static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol)) { - out = "(" + src + ")"; + out += "(" + src + ")"; src = out; } } diff --git a/tests/reference/cpp-test_builtin_pow-56b3f92.json b/tests/reference/cpp-test_builtin_pow-56b3f92.json index ff0359ca3b..35e93ea482 100644 --- a/tests/reference/cpp-test_builtin_pow-56b3f92.json +++ b/tests/reference/cpp-test_builtin_pow-56b3f92.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-test_builtin_pow-56b3f92.stdout", - "stdout_hash": "2691b799159bf9807468796c6ed130f1bf09469ae62a0bf0e942274e", + "stdout_hash": "91af820d143a62722ec2b753462b130c48fbcd87665c001823f64282", "stderr": "cpp-test_builtin_pow-56b3f92.stderr", "stderr_hash": "859ce76c74748f2d32c7eab92cfbba789a78d4cbf5818646b99806ea", "returncode": 0 diff --git a/tests/reference/cpp-test_builtin_pow-56b3f92.stdout b/tests/reference/cpp-test_builtin_pow-56b3f92.stdout index 6351a10c59..08b4d9ff1c 100644 --- a/tests/reference/cpp-test_builtin_pow-56b3f92.stdout +++ b/tests/reference/cpp-test_builtin_pow-56b3f92.stdout @@ -255,26 +255,26 @@ void test_pow() assert (__lpython_overloaded_8__pow(false, false) == 1); a1 = 4.50000000000000000e+00; a2 = 2.29999999999999982e+00; - assert ((__lpython_overloaded_3__pow(a1, a2) - 3.17971929089206000e+01) < eps); - assert ((__lpython_overloaded_3__pow(a2, a1) - 4.24399889427765871e+01) < eps); + assert (abs(__lpython_overloaded_3__pow(a1, a2) - 3.17971929089206000e+01) < eps); + assert (abs(__lpython_overloaded_3__pow(a2, a1) - 4.24399889427765871e+01) < eps); x = 3; y = 2.29999999999999982e+00; - assert ((__lpython_overloaded_6__pow(x, y) - 1.25135025328431819e+01) < eps); - assert ((__lpython_overloaded_7__pow(y, x) - 1.21669999999999980e+01) < eps); - assert ((__lpython_overloaded_6__pow(x, 5.50000000000000000e+00) - 4.20888346239237194e+02) < eps); - assert ((__lpython_overloaded_1__pow(2, -1) - 5.00000000000000000e-01) < eps); - assert ((__lpython_overloaded_1__pow(6, -4) - 7.71604938271604895e-04) < eps); - assert ((__lpython_overloaded_1__pow(-3, -5) + 4.11522633744856002e-03) < eps); - assert ((__lpython_overloaded_1__pow(6, -4) - 7.71604938271604895e-04) < eps); - assert ((__lpython_overloaded_3__pow( 4.50000000000000000e+00, 2.29999999999999982e+00) - 3.17971929089206000e+01) < eps); - assert ((__lpython_overloaded_3__pow( 2.29999999999999982e+00, 0.00000000000000000e+00) - 1.00000000000000000e+00) < eps); - assert ((__lpython_overloaded_3__pow( 2.29999999999999982e+00, - 1.50000000000000000e+00) - 2.86687162345994395e-01) < eps); - assert ((__lpython_overloaded_6__pow(2, 3.39999999999999991e+00) - 1.05560632861831536e+01) < eps); - assert ((__lpython_overloaded_6__pow(2, - 3.39999999999999991e+00) - 9.47322854068998882e-02) < eps); - assert ((__lpython_overloaded_7__pow( 3.39999999999999991e+00, 9) - 6.07169927664639836e+04) < eps); - assert ((__lpython_overloaded_7__pow( 0.00000000000000000e+00, 53) - 0.00000000000000000e+00) < eps); + assert (abs(__lpython_overloaded_6__pow(x, y) - 1.25135025328431819e+01) < eps); + assert (abs(__lpython_overloaded_7__pow(y, x) - 1.21669999999999980e+01) < eps); + assert (abs(__lpython_overloaded_6__pow(x, 5.50000000000000000e+00) - 4.20888346239237194e+02) < eps); + assert (abs(__lpython_overloaded_1__pow(2, -1) - 5.00000000000000000e-01) < eps); + assert (abs(__lpython_overloaded_1__pow(6, -4) - 7.71604938271604895e-04) < eps); + assert (abs(__lpython_overloaded_1__pow(-3, -5) + 4.11522633744856002e-03) < eps); + assert (abs(__lpython_overloaded_1__pow(6, -4) - 7.71604938271604895e-04) < eps); + assert (abs(__lpython_overloaded_3__pow( 4.50000000000000000e+00, 2.29999999999999982e+00) - 3.17971929089206000e+01) < eps); + assert (abs(__lpython_overloaded_3__pow( 2.29999999999999982e+00, 0.00000000000000000e+00) - 1.00000000000000000e+00) < eps); + assert (abs(__lpython_overloaded_3__pow( 2.29999999999999982e+00, - 1.50000000000000000e+00) - 2.86687162345994395e-01) < eps); + assert (abs(__lpython_overloaded_6__pow(2, 3.39999999999999991e+00) - 1.05560632861831536e+01) < eps); + assert (abs(__lpython_overloaded_6__pow(2, - 3.39999999999999991e+00) - 9.47322854068998882e-02) < eps); + assert (abs(__lpython_overloaded_7__pow( 3.39999999999999991e+00, 9) - 6.07169927664639836e+04) < eps); + assert (abs(__lpython_overloaded_7__pow( 0.00000000000000000e+00, 53) - 0.00000000000000000e+00) < eps); assert ((int32_t)(__lpython_overloaded_0__pow(4, 2)) == 16); - assert ((__lpython_overloaded_7__pow(- 4.23500000000000000e+03, 52) - 3.94800380598526379e+188) < eps); + assert (abs(__lpython_overloaded_7__pow(- 4.23500000000000000e+03, 52) - 3.94800380598526379e+188) < eps); i = 7; j = 2; k = 5; From 2fc618b9b038e886deeabdcbfeda327767383d30 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 11:05:48 +0530 Subject: [PATCH 13/31] Added a test file for testing basic assignment , addition and printing operations --- integration_tests/CMakeLists.txt | 1 + integration_tests/symbolics_01.py | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 integration_tests/symbolics_01.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index f01a218a36..b5ddfa9001 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -546,6 +546,7 @@ RUN(NAME structs_22 LABELS cpython llvm c NOFAST) RUN(NAME structs_23 LABELS cpython llvm c NOFAST) RUN(NAME structs_24 LABELS cpython llvm c) RUN(NAME structs_25 LABELS cpython llvm c) +RUN(NAME symbolics_01 LABELS cpython c) RUN(NAME sizeof_01 LABELS llvm c EXTRAFILES sizeof_01b.c) RUN(NAME sizeof_02 LABELS cpython llvm c) diff --git a/integration_tests/symbolics_01.py b/integration_tests/symbolics_01.py new file mode 100644 index 0000000000..9c1a0e9096 --- /dev/null +++ b/integration_tests/symbolics_01.py @@ -0,0 +1,11 @@ +from sympy import Symbol, pi +from lpython import S + +def main0(): + x: S = Symbol('x') + y: S = Symbol('y') + x = pi + z: S = x + y + print(z) + +main0() \ No newline at end of file From 03bf3b76e42f56419097aba710fd302ca696650f Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 11:35:29 +0530 Subject: [PATCH 14/31] Added compiler option for enabling symengine --- src/bin/lpython.cpp | 9 +++++++-- src/libasr/utils.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index 5fcf1744d8..faea398f0d 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1244,10 +1244,14 @@ int link_executable(const std::vector &infiles, cmd += s + " "; } cmd += " -I " + rtlib_header_dir; - cmd += " -I${CONDA_PREFIX}/include"; + if (compiler_options.enable_symengine) { + cmd += " -I${CONDA_PREFIX}/include"; + } cmd += " -L" + base_path + " -Wl,-rpath," + base_path + " -l" + runtime_lib + " -lm"; - cmd += " -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lsymengine"; + if (compiler_options.enable_symengine) { + cmd += " -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lsymengine"; + } if (compiler_options.enable_cpython) { std::string py_version = "3.10"; std::string py_flags = R"(-I $CONDA_PREFIX/include/python)" + py_version + R"( -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lpython)" + py_version + R"()"; @@ -1564,6 +1568,7 @@ int main(int argc, char *argv[]) app.add_flag("--get-rtl-dir", print_rtl_dir, "Print the path to the runtime library file"); app.add_flag("--verbose", compiler_options.verbose, "Print debugging statements"); app.add_flag("--enable-cpython", compiler_options.enable_cpython, "Enable CPython runtime"); + app.add_flag("--enable-symengine", compiler_options.enable_symengine, "Enable Symengine runtime"); // LSP specific options app.add_flag("--show-errors", show_errors, "Show errors when LSP is running in the background"); diff --git a/src/libasr/utils.h b/src/libasr/utils.h index daf5a14f49..04d34e14f8 100644 --- a/src/libasr/utils.h +++ b/src/libasr/utils.h @@ -59,6 +59,7 @@ struct CompilerOptions { bool verbose = false; bool pass_cumulative = false; bool enable_cpython = false; + bool enable_symengine = false; std::vector import_paths; Platform platform; From 9d06c7638c84904f81a99222d72f92ae96dbdedd Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 12:19:45 +0530 Subject: [PATCH 15/31] Added support for import S from lpython --- src/runtime/lpython/lpython.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/runtime/lpython/lpython.py b/src/runtime/lpython/lpython.py index b38d214142..749b2548d4 100644 --- a/src/runtime/lpython/lpython.py +++ b/src/runtime/lpython/lpython.py @@ -9,7 +9,7 @@ "overload", "ccall", "TypeVar", "pointer", "c_p_pointer", "Pointer", "p_c_pointer", "vectorize", "inline", "Union", "static", "packed", "Const", "sizeof", "ccallable", "ccallback", "Callable", - "Allocatable"] + "Allocatable", "S"] # data-types @@ -31,6 +31,7 @@ "Callable": lambda x: x, "Allocatable": lambda x: x, "Pointer": lambda x: x, + "S": lambda x: x, } class Type: @@ -91,6 +92,7 @@ def __init__(self, type, dims): Allocatable = Type("Allocatable") Union = ctypes.Union Pointer = PointerType("Pointer") +S = Type("S") class Intent: From 6ebe306646f8befbf8739a568308551eaed01879 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 13:57:59 +0530 Subject: [PATCH 16/31] Added symengine to the environment --- environment_unix.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment_unix.yml b/environment_unix.yml index 0942bbcbaf..7ec8604e75 100644 --- a/environment_unix.yml +++ b/environment_unix.yml @@ -15,3 +15,4 @@ dependencies: - toml - zlib - git + - symengine From fd6811b619e47ebd87a62ae0924d82292b1cf88e Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 14:25:19 +0530 Subject: [PATCH 17/31] added sympy and symengine in environment --- ci/environment.yml | 2 ++ environment_unix.yml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/environment.yml b/ci/environment.yml index b9b7fd715f..aa41678409 100644 --- a/ci/environment.yml +++ b/ci/environment.yml @@ -18,5 +18,7 @@ dependencies: - zlib - ninja - rapidjson + - symengine + - sympy # - bison=3.4 [not win] # - m2-bison=3.4 [win] diff --git a/environment_unix.yml b/environment_unix.yml index 7ec8604e75..0942bbcbaf 100644 --- a/environment_unix.yml +++ b/environment_unix.yml @@ -15,4 +15,3 @@ dependencies: - toml - zlib - git - - symengine From f1883c6913dccb2ed961826008158aacd67e9511 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Jun 2023 14:40:08 +0530 Subject: [PATCH 18/31] added sympy and symengine for supporting imports --- appveyor.yml | 2 +- ci/azure_install_macos.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a12bb34a57..e4b468f371 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,7 +8,7 @@ build_script: - call conda config --set always_yes yes --set changeps1 no - call conda info -a - call conda update -q conda -- call conda install -c conda-forge python=3.7 re2c m2-bison xonsh llvmdev=11.1.0 jupyter xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test pytest +- call conda install -c conda-forge python=3.7 re2c m2-bison xonsh llvmdev=11.1.0 jupyter xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test pytest symengine sympy - set CONDA_PREFIX=C:\\Miniconda37-x64 - set WIN=1 - set MACOS=0 diff --git a/ci/azure_install_macos.sh b/ci/azure_install_macos.sh index 5012f14ae7..8634511d2a 100755 --- a/ci/azure_install_macos.sh +++ b/ci/azure_install_macos.sh @@ -5,7 +5,7 @@ set -ex conda config --set always_yes yes --set changeps1 no conda info -a conda update -q conda -conda install -c conda-forge python=3.8 re2c bison=3.4 m4 xonsh llvmdev=11.0.1 toml cmake=3.17.0 jupyter pytest xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test +conda install -c conda-forge python=3.8 re2c bison=3.4 m4 xonsh llvmdev=11.0.1 toml cmake=3.17.0 jupyter pytest xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test symengine sympy export MACOSX_DEPLOYMENT_TARGET="10.12" export CONDA_PREFIX=/usr/local/miniconda export LFORTRAN_CMAKE_GENERATOR="Unix Makefiles" From 25dda82551d1001c2a0da90b37caece133918b00 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Fri, 16 Jun 2023 11:56:56 +0530 Subject: [PATCH 19/31] Add CI for SymPy tests --- .github/workflows/CI.yml | 49 ++++++++++++++++++++++++++++++++ ci/environment.yml | 2 -- integration_tests/CMakeLists.txt | 28 ++++++++++++++++-- integration_tests/run_tests.py | 2 +- src/bin/lpython.cpp | 4 +-- 5 files changed, 78 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d6091faa27..7994479421 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -290,3 +290,52 @@ jobs: cd integration_tests ./run_tests.py -b llvm ./run_tests.py -b c + + sympy: + name: Run SymPy tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ci/environment.yml + create-args: >- + python=3.10 + bison=3.4 + symengine=0.9.0 + sympy=1.11.1 + + - uses: hendrikmuhs/ccache-action@main + with: + key: ${{ github.job }}-${{ matrix.os }} + + - name: Build + shell: bash -l {0} + run: | + ./build0.sh + cmake . -G"Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DWITH_LLVM=yes \ + -DLPYTHON_BUILD_ALL=yes \ + -DWITH_STACKTRACE=no \ + -DWITH_RUNTIME_STACKTRACE=no \ + -DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \ + -DCMAKE_INSTALL_PREFIX=`pwd`/inst \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + + cmake --build . -j16 --target install + + - name: Debug failure + shell: bash -l {0} + run: | + ls /home/runner/micromamba/envs/lp/lib + + - name: Test + shell: bash -l {0} + run: | + cd integration_tests + ./run_tests.py -b sympy diff --git a/ci/environment.yml b/ci/environment.yml index aa41678409..b9b7fd715f 100644 --- a/ci/environment.yml +++ b/ci/environment.yml @@ -18,7 +18,5 @@ dependencies: - zlib - ninja - rapidjson - - symengine - - sympy # - bison=3.4 [not win] # - m2-bison=3.4 [win] diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index f735305940..6a0ccd1816 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -137,6 +137,30 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_IMPORT_PATH RUN_LABELS RUN_EN if (${fail}) set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE) endif() + elseif(KIND STREQUAL "sympy") + add_custom_command( + OUTPUT ${name}.c + COMMAND ${LPYTHON} ${extra_args} --show-c + ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py > ${name}.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py + VERBATIM) + add_executable(${name} ${name}.c ${extra_files}) + target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR} + "${Python_INCLUDE_DIRS}/..") + set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C) + if (APPLE) + set(SYMPY_LIB "${Python_LIBRARY_DIRS}/libsymengine.dylib") + else() + set(SYMPY_LIB "${Python_LIBRARY_DIRS}/libsymengine.so") + endif() + target_link_libraries(${name} lpython_rtlib ${SYMPY_LIB}) + add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name}) + if (labels) + set_tests_properties(${name} PROPERTIES LABELS "${labels}") + endif() + if (${fail}) + set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE) + endif() elseif(KIND STREQUAL "cpython") # CPython test if (extra_files) @@ -253,7 +277,7 @@ macro(RUN) if ((NOT DISABLE_FAST) AND (NOT RUN_NOFAST)) set(RUN_EXTRA_ARGS ${RUN_EXTRA_ARGS} --fast) set(RUN_NAME "${RUN_NAME}_FAST") - list(REMOVE_ITEM RUN_LABELS cpython) # remove cpython from --fast test + list(REMOVE_ITEM RUN_LABELS cpython sympy) # remove cpython from --fast test RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_IMPORT_PATH RUN_LABELS RUN_ENABLE_CPYTHON RUN_EXTRAFILES RUN_EXTRA_ARGS) endif() endmacro(RUN) @@ -546,7 +570,7 @@ RUN(NAME structs_22 LABELS cpython llvm c NOFAST) RUN(NAME structs_23 LABELS cpython llvm c NOFAST) RUN(NAME structs_24 LABELS cpython llvm c) RUN(NAME structs_25 LABELS cpython llvm c) -RUN(NAME symbolics_01 LABELS cpython c) +RUN(NAME symbolics_01 LABELS cpython sympy) RUN(NAME sizeof_01 LABELS llvm c EXTRAFILES sizeof_01b.c) RUN(NAME sizeof_02 LABELS cpython llvm c) diff --git a/integration_tests/run_tests.py b/integration_tests/run_tests.py index 9031097286..b09f241e32 100755 --- a/integration_tests/run_tests.py +++ b/integration_tests/run_tests.py @@ -6,7 +6,7 @@ # Initialization DEFAULT_THREADS_TO_USE = 8 # default no of threads is 8 -SUPPORTED_BACKENDS = ['llvm', 'c', 'wasm', 'cpython', 'x86', 'wasm_x86', 'wasm_x64'] +SUPPORTED_BACKENDS = ['llvm', 'c', 'wasm', 'cpython', 'x86', 'wasm_x86', 'wasm_x64', 'sympy'] BASE_DIR = os.path.dirname(os.path.realpath(__file__)) LPYTHON_PATH = f"{BASE_DIR}/../src/bin" diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index faea398f0d..b910993390 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1250,11 +1250,11 @@ int link_executable(const std::vector &infiles, cmd += " -L" + base_path + " -Wl,-rpath," + base_path + " -l" + runtime_lib + " -lm"; if (compiler_options.enable_symengine) { - cmd += " -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lsymengine"; + cmd += " -L$CONDA_PREFIX/lib -Wl,-rpath, $CONDA_PREFIX/lib -lsymengine"; } if (compiler_options.enable_cpython) { std::string py_version = "3.10"; - std::string py_flags = R"(-I $CONDA_PREFIX/include/python)" + py_version + R"( -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lpython)" + py_version + R"()"; + std::string py_flags = R"(-I $CONDA_PREFIX/include/python)" + py_version + R"( -L$CONDA_PREFIX/lib -Wl,-rpath, $CONDA_PREFIX/lib -lpython)" + py_version + R"()"; cmd += " " + py_flags; } int err = system(cmd.c_str()); From bd7e0d4593ddfac2aacecc8e03f46fe98558d831 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Fri, 16 Jun 2023 12:07:10 +0530 Subject: [PATCH 20/31] Install sympy in the CI --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7994479421..a70fb6a7c4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -48,7 +48,7 @@ jobs: - name: Install Linux / macOS Conda Packages if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos') shell: bash -l {0} - run: conda install bison=3.4 + run: conda install bison=3.4 sympy - name: Conda info shell: bash -l {0} From dab1ef859899b13469b1a7cb0e703736443a5f84 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sun, 18 Jun 2023 09:36:03 +0530 Subject: [PATCH 21/31] Made minor changes in intrinsic_function_registry.h --- src/libasr/pass/intrinsic_function_registry.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index bc28405ea8..ff3dd19f65 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -63,11 +63,11 @@ enum class IntrinsicFunctions : int64_t { ListIndex, Partition, ListReverse, - SymbolicSymbol, ListPop, + SymbolicSymbol, SymbolicAdd, - Sum, SymbolicPi, + Sum, // ... }; @@ -2191,10 +2191,10 @@ namespace IntrinsicFunctionRegistry { "list.index"}, {static_cast(ASRUtils::IntrinsicFunctions::ListReverse), "list.reverse"}, - {static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), - "Symbol"}, {static_cast(ASRUtils::IntrinsicFunctions::ListPop), "list.pop"}, + {static_cast(ASRUtils::IntrinsicFunctions::SymbolicSymbol), + "Symbol"}, {static_cast(ASRUtils::IntrinsicFunctions::SymbolicAdd), "SymbolicAdd"}, {static_cast(ASRUtils::IntrinsicFunctions::SymbolicPi), @@ -2227,8 +2227,8 @@ namespace IntrinsicFunctionRegistry { {"sum", {&Sum::create_Sum, &Sum::eval_Sum}}, {"list.index", {&ListIndex::create_ListIndex, &ListIndex::eval_list_index}}, {"list.reverse", {&ListReverse::create_ListReverse, &ListReverse::eval_list_reverse}}, - {"Symbol", {&SymbolicSymbol::create_SymbolicSymbol, &SymbolicSymbol::eval_SymbolicSymbol}}, {"list.pop", {&ListPop::create_ListPop, &ListPop::eval_list_pop}}, + {"Symbol", {&SymbolicSymbol::create_SymbolicSymbol, &SymbolicSymbol::eval_SymbolicSymbol}}, {"SymbolicAdd", {&SymbolicAdd::create_SymbolicAdd, &SymbolicAdd::eval_SymbolicAdd}}, {"pi", {&SymbolicPi::create_SymbolicPi, &SymbolicPi::eval_SymbolicPi}}, }; @@ -2336,8 +2336,8 @@ inline std::string get_intrinsic_name(int x) { INTRINSIC_NAME_CASE(ListIndex) INTRINSIC_NAME_CASE(Partition) INTRINSIC_NAME_CASE(ListReverse) - INTRINSIC_NAME_CASE(SymbolicSymbol) INTRINSIC_NAME_CASE(ListPop) + INTRINSIC_NAME_CASE(SymbolicSymbol) INTRINSIC_NAME_CASE(SymbolicAdd) INTRINSIC_NAME_CASE(SymbolicPi) INTRINSIC_NAME_CASE(Sum) From c5056109a04d8611a7aaa8100dc30fb801f70ad0 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sun, 18 Jun 2023 09:54:03 +0530 Subject: [PATCH 22/31] Removed unneccessary additions --- appveyor.yml | 2 +- ci/azure_install_macos.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e4b468f371..a12bb34a57 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,7 +8,7 @@ build_script: - call conda config --set always_yes yes --set changeps1 no - call conda info -a - call conda update -q conda -- call conda install -c conda-forge python=3.7 re2c m2-bison xonsh llvmdev=11.1.0 jupyter xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test pytest symengine sympy +- call conda install -c conda-forge python=3.7 re2c m2-bison xonsh llvmdev=11.1.0 jupyter xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test pytest - set CONDA_PREFIX=C:\\Miniconda37-x64 - set WIN=1 - set MACOS=0 diff --git a/ci/azure_install_macos.sh b/ci/azure_install_macos.sh index 8634511d2a..5012f14ae7 100755 --- a/ci/azure_install_macos.sh +++ b/ci/azure_install_macos.sh @@ -5,7 +5,7 @@ set -ex conda config --set always_yes yes --set changeps1 no conda info -a conda update -q conda -conda install -c conda-forge python=3.8 re2c bison=3.4 m4 xonsh llvmdev=11.0.1 toml cmake=3.17.0 jupyter pytest xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test symengine sympy +conda install -c conda-forge python=3.8 re2c bison=3.4 m4 xonsh llvmdev=11.0.1 toml cmake=3.17.0 jupyter pytest xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test export MACOSX_DEPLOYMENT_TARGET="10.12" export CONDA_PREFIX=/usr/local/miniconda export LFORTRAN_CMAKE_GENERATOR="Unix Makefiles" From 12ae8070f1e505b319929e36300dbd6c5ed49c77 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sun, 18 Jun 2023 10:14:29 +0530 Subject: [PATCH 23/31] Trying to fix failing tests --- src/bin/lpython.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index c4b3a202fa..7754afdcfd 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1254,7 +1254,7 @@ int link_executable(const std::vector &infiles, } if (compiler_options.enable_cpython) { std::string py_version = "3.10"; - std::string py_flags = R"(-I $CONDA_PREFIX/include/python)" + py_version + R"( -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lpython)" + py_version + R"()"; + std::string py_flags = R"(-I $CONDA_PREFIX/include/python)" + py_version + R"( -L$CONDA_PREFIX/lib -Wl,-rpath, $CONDA_PREFIX/lib -lpython)" + py_version + R"()"; if (compiler_options.link_numpy) { py_flags += R"( -I$CONDA_PREFIX/lib/python)" + py_version + R"(/site-packages/numpy/core/include)"; } From 2f4fb86c6a48f650935dc7406c5b7f5fa007eaf6 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sun, 18 Jun 2023 10:21:38 +0530 Subject: [PATCH 24/31] Reverted back the change --- src/bin/lpython.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index 7754afdcfd..c4b3a202fa 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1254,7 +1254,7 @@ int link_executable(const std::vector &infiles, } if (compiler_options.enable_cpython) { std::string py_version = "3.10"; - std::string py_flags = R"(-I $CONDA_PREFIX/include/python)" + py_version + R"( -L$CONDA_PREFIX/lib -Wl,-rpath, $CONDA_PREFIX/lib -lpython)" + py_version + R"()"; + std::string py_flags = R"(-I $CONDA_PREFIX/include/python)" + py_version + R"( -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lpython)" + py_version + R"()"; if (compiler_options.link_numpy) { py_flags += R"( -I$CONDA_PREFIX/lib/python)" + py_version + R"(/site-packages/numpy/core/include)"; } From f9324c6dd9e7e5884c3761c5309ff8febc183c90 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sun, 18 Jun 2023 10:29:26 +0530 Subject: [PATCH 25/31] added -Wl after -rpath --- src/bin/lpython.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index c4b3a202fa..7b8ab6c8e9 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -1250,7 +1250,7 @@ int link_executable(const std::vector &infiles, cmd += " -L" + base_path + " -Wl,-rpath," + base_path + " -l" + runtime_lib + " -lm"; if (compiler_options.enable_symengine) { - cmd += " -L$CONDA_PREFIX/lib -Wl,-rpath, $CONDA_PREFIX/lib -lsymengine"; + cmd += " -L$CONDA_PREFIX/lib -Wl,-rpath -Wl,$CONDA_PREFIX/lib -lsymengine"; } if (compiler_options.enable_cpython) { std::string py_version = "3.10"; From 213ade0bee4424d836fc39b01ae4b29b152d8df7 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sun, 18 Jun 2023 10:54:21 +0530 Subject: [PATCH 26/31] remove sympy from Fast --- integration_tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index a60fbc36c8..fca2ea8c21 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -291,8 +291,8 @@ macro(RUN) if ((NOT DISABLE_FAST) AND (NOT RUN_NOFAST)) set(RUN_EXTRA_ARGS ${RUN_EXTRA_ARGS} --fast) set(RUN_NAME "${RUN_NAME}_FAST") - list(REMOVE_ITEM RUN_LABELS cpython cpython_py) # remove cpython, cpython_py from --fast test - RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN_EXTRAFILES RUN_EXTRA_ARGS) + list(REMOVE_ITEM RUN_LABELS cpython sympy cpython_py) # remove cpython, sympy, cpython_py from --fast test + RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_IMPORT_PATH RUN_LABELS RUN_ENABLE_CPYTHON RUN_EXTRAFILES RUN_EXTRA_ARGS) endif() endmacro(RUN) From 4e9989801b54a85621f05911bafcb0c402b2ad2f Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sun, 18 Jun 2023 12:32:10 +0530 Subject: [PATCH 27/31] Introduced c_sym and cpython_sym backends --- .github/workflows/CI.yml | 2 +- integration_tests/CMakeLists.txt | 17 ++++++++--------- integration_tests/run_tests.py | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 3e6bf3c6c0..6ca3205593 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -381,4 +381,4 @@ jobs: shell: bash -l {0} run: | cd integration_tests - ./run_tests.py -b sympy \ No newline at end of file + ./run_tests.py -b c_sym cpython_sym \ No newline at end of file diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index fca2ea8c21..8bb5f63ca7 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -140,13 +140,12 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN if (${fail}) set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE) endif() - elseif(KIND STREQUAL "sympy") + elseif(KIND STREQUAL "c_sym") add_custom_command( - OUTPUT ${name}.c - COMMAND ${LPYTHON} ${extra_args} --show-c - ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py > ${name}.c - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py - VERBATIM) + OUTPUT ${name}.c + COMMAND ${LPYTHON} ${extra_args} --show-c ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py > ${name}.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py + VERBATIM) add_executable(${name} ${name}.c ${extra_files}) target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR} "${Python_INCLUDE_DIRS}/..") @@ -164,7 +163,7 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN if (${fail}) set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE) endif() - elseif((KIND STREQUAL "cpython") OR (KIND STREQUAL "cpython_py")) + elseif((KIND STREQUAL "cpython") OR (KIND STREQUAL "cpython_py") OR (KIND STREQUAL "cpython_sym")) # CPython test if (extra_files) set(PY_MOD "${name}_mod") @@ -292,7 +291,7 @@ macro(RUN) set(RUN_EXTRA_ARGS ${RUN_EXTRA_ARGS} --fast) set(RUN_NAME "${RUN_NAME}_FAST") list(REMOVE_ITEM RUN_LABELS cpython sympy cpython_py) # remove cpython, sympy, cpython_py from --fast test - RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_IMPORT_PATH RUN_LABELS RUN_ENABLE_CPYTHON RUN_EXTRAFILES RUN_EXTRA_ARGS) + RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN_EXTRAFILES RUN_EXTRA_ARGS) endif() endmacro(RUN) @@ -575,7 +574,7 @@ RUN(NAME structs_23 LABELS cpython llvm c NOFAST) RUN(NAME structs_24 LABELS cpython llvm c) RUN(NAME structs_25 LABELS cpython llvm c) RUN(NAME structs_26 LABELS cpython llvm c) -RUN(NAME symbolics_01 LABELS cpython sympy) +RUN(NAME symbolics_01 LABELS cpython_sym c_sym) RUN(NAME sizeof_01 LABELS llvm c EXTRAFILES sizeof_01b.c) RUN(NAME sizeof_02 LABELS cpython llvm c) diff --git a/integration_tests/run_tests.py b/integration_tests/run_tests.py index ab6c47d316..f2ea5c310f 100755 --- a/integration_tests/run_tests.py +++ b/integration_tests/run_tests.py @@ -6,7 +6,7 @@ # Initialization DEFAULT_THREADS_TO_USE = 8 # default no of threads is 8 -SUPPORTED_BACKENDS = ['llvm', 'c', 'wasm', 'cpython', 'x86', 'wasm_x86', 'wasm_x64', 'c_py', 'cpython_py', 'sympy'] +SUPPORTED_BACKENDS = ['llvm', 'c', 'wasm', 'cpython', 'x86', 'wasm_x86', 'wasm_x64', 'c_py', 'cpython_py', 'c_sym', 'cpython_sym'] BASE_DIR = os.path.dirname(os.path.realpath(__file__)) LPYTHON_PATH = f"{BASE_DIR}/../src/bin" From e232e5d1d767ceeef6322eda73628e0f19c1859f Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sun, 18 Jun 2023 13:24:36 +0530 Subject: [PATCH 28/31] Replaced sympy with cpython_sym --- 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 8bb5f63ca7..e687141c40 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -290,7 +290,7 @@ macro(RUN) if ((NOT DISABLE_FAST) AND (NOT RUN_NOFAST)) set(RUN_EXTRA_ARGS ${RUN_EXTRA_ARGS} --fast) set(RUN_NAME "${RUN_NAME}_FAST") - list(REMOVE_ITEM RUN_LABELS cpython sympy cpython_py) # remove cpython, sympy, cpython_py from --fast test + list(REMOVE_ITEM RUN_LABELS cpython cpython_sym cpython_py) # remove cpython, cpython_sym, cpython_py from --fast test RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN_EXTRAFILES RUN_EXTRA_ARGS) endif() endmacro(RUN) From 07e01e4f1d17759f710b2c4eb5ba8d31ec6a651d Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Mon, 19 Jun 2023 10:34:30 +0530 Subject: [PATCH 29/31] Fix typo and remove a task in CI --- .github/workflows/CI.yml | 7 +------ integration_tests/CMakeLists.txt | 9 +++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6ca3205593..745107110b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -372,13 +372,8 @@ jobs: cmake --build . -j16 --target install - - name: Debug failure - shell: bash -l {0} - run: | - ls /home/runner/micromamba/envs/lp/lib - - name: Test shell: bash -l {0} run: | cd integration_tests - ./run_tests.py -b c_sym cpython_sym \ No newline at end of file + ./run_tests.py -b c_sym cpython_sym diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index e687141c40..69b4e737e7 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -143,7 +143,8 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN elseif(KIND STREQUAL "c_sym") add_custom_command( OUTPUT ${name}.c - COMMAND ${LPYTHON} ${extra_args} --show-c ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py > ${name}.c + COMMAND ${LPYTHON} ${extra_args} --show-c + ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py > ${name}.c DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.py VERBATIM) add_executable(${name} ${name}.c ${extra_files}) @@ -151,11 +152,11 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_ENABLE_CPYTHON RUN "${Python_INCLUDE_DIRS}/..") set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C) if (APPLE) - set(SYMPY_LIB "${Python_LIBRARY_DIRS}/libsymengine.dylib") + set(SYMENGINE_LIB "${Python_LIBRARY_DIRS}/libsymengine.dylib") else() - set(SYMPY_LIB "${Python_LIBRARY_DIRS}/libsymengine.so") + set(SYMENGINE_LIB "${Python_LIBRARY_DIRS}/libsymengine.so") endif() - target_link_libraries(${name} lpython_rtlib ${SYMPY_LIB}) + target_link_libraries(${name} lpython_rtlib ${SYMENGINE_LIB}) add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name}) if (labels) set_tests_properties(${name} PROPERTIES LABELS "${labels}") From 5976ec58d69cacc50b8ce06ea67147af83c41fe2 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Mon, 19 Jun 2023 14:26:00 +0530 Subject: [PATCH 30/31] minor changes to optimize code --- src/libasr/asr_utils.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 7e83cbd075..420686e0ba 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -1657,11 +1657,7 @@ inline int extract_dimensions_from_ttype(ASR::ttype_t *x, n_dims = extract_dimensions_from_ttype(ASR::down_cast(x)->m_type, m_dims); break; } - case ASR::ttypeType::SymbolicExpression: { - n_dims = 0; - m_dims = nullptr; - break; - } + case ASR::ttypeType::SymbolicExpression: case ASR::ttypeType::Integer: case ASR::ttypeType::UnsignedInteger: case ASR::ttypeType::Real: From 19f8075322c025fad1e765c2baafdb5092a24d80 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Mon, 19 Jun 2023 15:15:41 +0530 Subject: [PATCH 31/31] edited verify_args function for SymbolicPi --- src/libasr/pass/intrinsic_function_registry.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index ff3dd19f65..c52c5fef32 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2081,8 +2081,9 @@ namespace SymbolicAdd { namespace SymbolicPi { - static inline void verify_args(const ASR::IntrinsicFunction_t& /*x*/, diag::Diagnostics& /*diagnostics*/) { - return; + static inline void verify_args(const ASR::IntrinsicFunction_t& x, diag::Diagnostics& diagnostics) { + ASRUtils::require_impl(x.n_args == 0, "SymbolicPi does not take arguments", + x.base.base.loc, diagnostics); } static inline ASR::expr_t *eval_SymbolicPi(Allocator &/*al*/,