diff --git a/grammar/ASR.asdl b/grammar/ASR.asdl index 974a8ef5cb..613df62ded 100644 --- a/grammar/ASR.asdl +++ b/grammar/ASR.asdl @@ -83,7 +83,7 @@ symbol = Program(symbol_table symtab, identifier name, identifier* dependencies, stmt* body) | Module(symbol_table symtab, identifier name, identifier* dependencies, - bool loaded_from_mod) + bool loaded_from_mod, bool intrinsic) | Subroutine(symbol_table symtab, identifier name, expr* args, stmt* body, abi abi, access access, deftype deftype, string? bindc_name, bool pure, bool module) diff --git a/integration_tests/run_tests.py b/integration_tests/run_tests.py index 187cecd7bb..aa122f7bc4 100755 --- a/integration_tests/run_tests.py +++ b/integration_tests/run_tests.py @@ -13,6 +13,8 @@ "modules_01.py", #"modules_02.py", "test_math.py", + #"test_builtin.py", + "test_builtin_abs.py", ] def main(): diff --git a/integration_tests/test_builtin.py b/integration_tests/test_builtin.py new file mode 100644 index 0000000000..f277d81d66 --- /dev/null +++ b/integration_tests/test_builtin.py @@ -0,0 +1,20 @@ +from ltypes import i32 + +def test_ord(): + i: i32 + s: str + s = "1" + i = ord(s) + assert i == 49 + + +#def test_chr(): +# i: i32 +# i = 48 +# s: str +# s = chr(i) +# assert s == "0" + + +test_ord() +#test_chr() diff --git a/integration_tests/test_builtin_abs.py b/integration_tests/test_builtin_abs.py new file mode 100644 index 0000000000..43379ff1c6 --- /dev/null +++ b/integration_tests/test_builtin_abs.py @@ -0,0 +1,11 @@ +from ltypes import f64 + +def test_abs(): + x: f64 + x = 5.5 + assert abs(x) == 5.5 + x = -5.5 + assert abs(x) == 5.5 + + +test_abs() diff --git a/src/lpython/pickle.cpp b/src/lpython/pickle.cpp index 5cca10f47c..ffcc7731df 100644 --- a/src/lpython/pickle.cpp +++ b/src/lpython/pickle.cpp @@ -236,7 +236,7 @@ class ASRPickleVisitor : } void visit_Module(const ASR::Module_t &x) { if (!show_intrinsic_modules && - startswith(x.m_name, "lfortran_intrinsic_")) { + (x.m_intrinsic || startswith(x.m_name, "lfortran_intrinsic_"))) { s.append("("); if (use_colors) { s.append(color(style::bold)); diff --git a/src/lpython/semantics/ast_symboltable_visitor.cpp b/src/lpython/semantics/ast_symboltable_visitor.cpp index f9497be5dc..c62664bb55 100644 --- a/src/lpython/semantics/ast_symboltable_visitor.cpp +++ b/src/lpython/semantics/ast_symboltable_visitor.cpp @@ -160,7 +160,7 @@ class SymbolTableVisitor : public CommonVisitor { /* a_name */ s2c(al, to_lower(x.m_name)), nullptr, 0, - false); + false, false); current_module_sym = ASR::down_cast(tmp0); if( x.class_type == AST::modType::Submodule ) { std::string rl_path = get_runtime_library_dir(); diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 358ab822e1..bba07ddf8c 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -58,14 +58,14 @@ LFortran::Result get_full_path(const std::string &filename, return filename; } else { std::string filename_intrinsic = runtime_library_dir + "/" + filename; - bool status = read_file(filename_intrinsic, input); + status = read_file(filename_intrinsic, input); if (status) { return filename_intrinsic; } else { // If this is `ltypes`, do a special lookup if (filename == "ltypes.py") { - std::string filename_intrinsic = runtime_library_dir + "/ltypes/" + filename; - bool status = read_file(filename_intrinsic, input); + filename_intrinsic = runtime_library_dir + "/ltypes/" + filename; + status = read_file(filename_intrinsic, input); if (status) { ltypes = true; return filename_intrinsic; @@ -81,7 +81,7 @@ LFortran::Result get_full_path(const std::string &filename, ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab, const std::string &module_name, - const Location &loc, bool /*intrinsic*/, + const Location &loc, bool intrinsic, const std::string &rl_path, bool <ypes, const std::function err) { @@ -132,6 +132,7 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab, mod2->m_name = s2c(al, module_name); symtab->scope[module_name] = (ASR::symbol_t*)mod2; mod2->m_symtab->parent = symtab; + mod2->m_intrinsic = intrinsic; // and return it return mod2; @@ -371,7 +372,7 @@ class SymbolTableVisitor : public CommonVisitor { /* a_name */ s2c(al, mod_name), nullptr, 0, - false); + false, false); if (parent_scope->scope.find(mod_name) != parent_scope->scope.end()) { throw SemanticError("Module '" + mod_name + "' already defined", tmp1->loc); @@ -1898,398 +1899,519 @@ class BodyVisitor : public CommonVisitor { args.push_back(al, expr); } - // Intrinsic functions - if (call_name == "size") { - // TODO: size should be part of ASR. That way - // ASR itself does not need a runtime library - // a runtime library thus becomes optional --- can either be - // implemented using ASR, or the backend can link it at runtime - ASR::ttype_t *a_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, - 4, nullptr, 0)); - /* - ASR::symbol_t *a_name = nullptr; - throw SemanticError("TODO: add the size() function and look it up", - x.base.base.loc); - tmp = ASR::make_FunctionCall_t(al, x.base.base.loc, a_name, - nullptr, args.p, args.size(), nullptr, 0, a_type, nullptr, nullptr); - */ + ASR::symbol_t *s = current_scope->resolve_symbol(call_name); - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, 1234, a_type); - return; - } else if (call_name == "len") { - if (args.size() != 1) { - throw SemanticError(call_name + "() takes exactly one argument (" + - std::to_string(args.size()) + " given)", x.base.base.loc); - } - ASR::expr_t *arg = ASRUtils::expr_value(args[0]); - ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Integer_t(al, - x.base.base.loc, 4, nullptr, 0)); - if (arg->type == ASR::exprType::ConstantString) { - char* str_value = ASR::down_cast(arg)->m_s; - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, - (int64_t)strlen(s2c(al, std::string(str_value))), type); - } else if (arg->type == ASR::exprType::ConstantArray) { - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, - (int64_t)ASR::down_cast(arg)->n_args, type); - } else if (arg->type == ASR::exprType::ConstantTuple) { - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, - (int64_t)ASR::down_cast(arg)->n_elements, type); - } else if (arg->type == ASR::exprType::ConstantDictionary) { - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, - (int64_t)ASR::down_cast(arg)->n_keys, type); - } else if (arg->type == ASR::exprType::ConstantSet) { - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, - (int64_t)ASR::down_cast(arg)->n_elements, type); - } else { - throw SemanticError("len() only works on strings, lists, tuples, dictionaries and sets", + if (!s) { + // Intrinsic functions + if (call_name == "size") { + // TODO: size should be part of ASR. That way + // ASR itself does not need a runtime library + // a runtime library thus becomes optional --- can either be + // implemented using ASR, or the backend can link it at runtime + ASR::ttype_t *a_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, + 4, nullptr, 0)); + /* + ASR::symbol_t *a_name = nullptr; + throw SemanticError("TODO: add the size() function and look it up", x.base.base.loc); - } - return; + tmp = ASR::make_FunctionCall_t(al, x.base.base.loc, a_name, + nullptr, args.p, args.size(), nullptr, 0, a_type, nullptr, nullptr); + */ - } else if (call_name == "ord") { - LFORTRAN_ASSERT(ASRUtils::all_args_evaluated(args)); - ASR::expr_t* char_expr = args[0]; - ASR::ttype_t* char_type = ASRUtils::expr_type(char_expr); - if (ASRUtils::is_character(*char_type)) { - char* c = ASR::down_cast(ASRUtils::expr_value(char_expr))->m_s; - ASR::ttype_t* int_type = - ASRUtils::TYPE(ASR::make_Integer_t(al, - x.base.base.loc, 4, nullptr, 0)); - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, - c[0], int_type); + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, 1234, a_type); return; - } else { - throw SemanticError("ord() must have one character argument", x.base.base.loc); - } - } else if (call_name == "chr") { - LFORTRAN_ASSERT(ASRUtils::all_args_evaluated(args)); - ASR::expr_t* real_expr = args[0]; - ASR::ttype_t* real_type = ASRUtils::expr_type(real_expr); - if (ASRUtils::is_integer(*real_type)) { - int64_t c = ASR::down_cast(real_expr)->m_n; - ASR::ttype_t* str_type = ASRUtils::TYPE(ASR::make_Character_t(al, - x.base.base.loc, 1, 1, nullptr, nullptr, 0)); - if (! (c >= 0 && c <= 127) ) { - throw SemanticError("The argument 'x' in chr(x) must be in the range 0 <= x <= 127.", - x.base.base.loc); + + } else if (call_name == "len") { + if (args.size() != 1) { + throw SemanticError(call_name + "() takes exactly one argument (" + + std::to_string(args.size()) + " given)", x.base.base.loc); + } + ASR::expr_t *arg = ASRUtils::expr_value(args[0]); + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Integer_t(al, + x.base.base.loc, 4, nullptr, 0)); + if (arg->type == ASR::exprType::ConstantString) { + char* str_value = ASR::down_cast(arg)->m_s; + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, + (int64_t)strlen(s2c(al, std::string(str_value))), type); + } else if (arg->type == ASR::exprType::ConstantArray) { + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, + (int64_t)ASR::down_cast(arg)->n_args, type); + } else if (arg->type == ASR::exprType::ConstantTuple) { + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, + (int64_t)ASR::down_cast(arg)->n_elements, type); + } else if (arg->type == ASR::exprType::ConstantDictionary) { + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, + (int64_t)ASR::down_cast(arg)->n_keys, type); + } else if (arg->type == ASR::exprType::ConstantSet) { + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, + (int64_t)ASR::down_cast(arg)->n_elements, type); + } else { + throw SemanticError("len() only works on strings, lists, tuples, dictionaries and sets", + x.base.base.loc); } - char cc = c; - std::string svalue; - svalue += cc; - tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, svalue), str_type); return; - } else { - throw SemanticError("chr() must have one integer argument", x.base.base.loc); - } - } else if (call_name == "complex") { - int16_t n_args = args.size(); - ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Complex_t(al, x.base.base.loc, - 8, nullptr, 0)); - if( n_args > 2 || n_args < 0 ) { // n_args shouldn't be less than 0 but added this check for safety - throw SemanticError("Only constant integer or real values are supported as " - "the (at most two) arguments of complex()", x.base.base.loc); - } - double c1 = 0.0, c2 = 0.0; // Default if n_args = 0 - if (n_args >= 1) { // Handles both n_args = 1 and n_args = 2 - if (ASR::is_a(*args[0])) { - c1 = ASR::down_cast(args[0])->m_n; - } else if (ASR::is_a(*args[0])) { - c1 = ASR::down_cast(ASRUtils::expr_value(args[0]))->m_r; + + } else if (call_name == "ord") { + std::string rl_path = get_runtime_library_dir(); + SymbolTable *st = current_scope; + while (st->parent != nullptr) { + st = st->parent; } - } - if (n_args == 2) { // Extracts imaginary component if n_args = 2 - if (ASR::is_a(*args[1])) { - c2 = ASR::down_cast(args[1])->m_n; - } else if (ASR::is_a(*args[1])) { - c2 = ASR::down_cast(ASRUtils::expr_value(args[1]))->m_r; + bool ltypes; + std::string msym = "lpython_builtin"; + ASR::symbol_t *t = (ASR::symbol_t*)(load_module(al, st, + msym, x.base.base.loc, true, rl_path, ltypes, + [&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); } + )); + LFORTRAN_ASSERT(!ltypes) + if (!t) { + throw SemanticError("The module '" + msym + "' cannot be loaded", + x.base.base.loc); } - } - tmp = ASR::make_ConstantComplex_t(al, x.base.base.loc, c1, c2, type); - return; - } else if (call_name == "pow") { - if (args.size() != 2) { - throw SemanticError("Two arguments are expected in pow", - x.base.base.loc); - } - ASR::expr_t *left = args[0]; - ASR::expr_t *right = args[1]; - ASR::binopType op = ASR::binopType::Pow; - make_BinOp_helper(left, right, op, x.base.base.loc, false); - return; - } else if (call_name == "bin" || call_name == "oct" || call_name == "hex") { - if (args.size() != 1) { - throw SemanticError(call_name + "() takes exactly one argument (" + - std::to_string(args.size()) + " given)", x.base.base.loc); - } - ASR::expr_t* expr = ASRUtils::expr_value(args[0]); - ASR::ttype_t* type = ASRUtils::expr_type(expr); - if (ASRUtils::is_integer(*type)) { - int64_t n = ASR::down_cast(expr)->m_n; - ASR::ttype_t* str_type = ASRUtils::TYPE(ASR::make_Character_t(al, - x.base.base.loc, 1, 1, nullptr, nullptr, 0)); - std::string s, prefix; - std::stringstream ss; - if (call_name == "oct") { - prefix = n > 0 ? "0o" : "-0o"; - ss << std::oct << std::abs(n); - s += ss.str(); - } else if (call_name == "bin") { - prefix = n > 0 ? "0b" : "-0b"; - s += std::bitset<64>(std::abs(n)).to_string(); - s.erase(0, s.find_first_not_of('0')); + + ASR::Module_t *m = ASR::down_cast(t); + + std::string local_sym = "ord"; + t = m->m_symtab->resolve_symbol(local_sym); + if (!t) { + throw SemanticError("ICE: The symbol '" + local_sym + "' not found in the module '" + msym + "'", + x.base.base.loc); + } + if (ASR::is_a(*t)) { + if (current_scope->scope.find(local_sym) != current_scope->scope.end()) { + throw SemanticError("Function already defined", + x.base.base.loc); + } + ASR::Function_t *mfn = ASR::down_cast(t); + // `mfn` is the Function in a module. Now we construct + // an ExternalSymbol that points to it. + Str name; + name.from_str(al, local_sym); + char *cname = name.c_str(al); + ASR::asr_t *fn = ASR::make_ExternalSymbol_t( + al, mfn->base.base.loc, + /* a_symtab */ current_scope, + /* a_name */ cname, + (ASR::symbol_t*)mfn, + m->m_name, nullptr, 0, mfn->m_name, + ASR::accessType::Public + ); + current_scope->scope[local_sym] = ASR::down_cast(fn); + + ASR::ttype_t *a_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, + 4, nullptr, 0)); + tmp = ASR::make_FunctionCall_t(al, x.base.base.loc, ASR::down_cast(fn), + nullptr, args.p, args.size(), nullptr, 0, a_type, nullptr, nullptr); + return; + } else { + throw SemanticError("ICE: Ord expected to be a function", x.base.base.loc); + } + /* + LFORTRAN_ASSERT(ASRUtils::all_args_evaluated(args)); + ASR::expr_t* char_expr = args[0]; + ASR::ttype_t* char_type = ASRUtils::expr_type(char_expr); + if (ASRUtils::is_character(*char_type)) { + char* c = ASR::down_cast(ASRUtils::expr_value(char_expr))->m_s; + ASR::ttype_t* int_type = + ASRUtils::TYPE(ASR::make_Integer_t(al, + x.base.base.loc, 4, nullptr, 0)); + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, + c[0], int_type); + return; + } else { + throw SemanticError("ord() must have one character argument", x.base.base.loc); + } + */ + } else if (call_name == "chr") { + LFORTRAN_ASSERT(ASRUtils::all_args_evaluated(args)); + ASR::expr_t* real_expr = args[0]; + ASR::ttype_t* real_type = ASRUtils::expr_type(real_expr); + if (ASRUtils::is_integer(*real_type)) { + int64_t c = ASR::down_cast(real_expr)->m_n; + ASR::ttype_t* str_type = ASRUtils::TYPE(ASR::make_Character_t(al, + x.base.base.loc, 1, 1, nullptr, nullptr, 0)); + if (! (c >= 0 && c <= 127) ) { + throw SemanticError("The argument 'x' in chr(x) must be in the range 0 <= x <= 127.", + x.base.base.loc); + } + char cc = c; + std::string svalue; + svalue += cc; + tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, svalue), str_type); + return; } else { - prefix = n > 0 ? "0x" : "-0x"; - ss << std::hex << std::abs(n); - s += ss.str(); + throw SemanticError("chr() must have one integer argument", x.base.base.loc); + } + } else if (call_name == "complex") { + int16_t n_args = args.size(); + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Complex_t(al, x.base.base.loc, + 8, nullptr, 0)); + if( n_args > 2 || n_args < 0 ) { // n_args shouldn't be less than 0 but added this check for safety + throw SemanticError("Only constant integer or real values are supported as " + "the (at most two) arguments of complex()", x.base.base.loc); + } + double c1 = 0.0, c2 = 0.0; // Default if n_args = 0 + if (n_args >= 1) { // Handles both n_args = 1 and n_args = 2 + if (ASR::is_a(*args[0])) { + c1 = ASR::down_cast(args[0])->m_n; + } else if (ASR::is_a(*args[0])) { + c1 = ASR::down_cast(ASRUtils::expr_value(args[0]))->m_r; + } + } + if (n_args == 2) { // Extracts imaginary component if n_args = 2 + if (ASR::is_a(*args[1])) { + c2 = ASR::down_cast(args[1])->m_n; + } else if (ASR::is_a(*args[1])) { + c2 = ASR::down_cast(ASRUtils::expr_value(args[1]))->m_r; + } } - s.insert(0, prefix); - tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); + tmp = ASR::make_ConstantComplex_t(al, x.base.base.loc, c1, c2, type); return; - } else { - throw SemanticError(call_name + "() must have one integer argument", - x.base.base.loc); - } - } else if (call_name == "abs") { - if (args.size() != 1) { - throw SemanticError(call_name + "() takes exactly one argument (" + - std::to_string(args.size()) + " given)", x.base.base.loc); - } - ASR::expr_t* arg = ASRUtils::expr_value(args[0]); - ASR::ttype_t* t = ASRUtils::expr_type(arg); - ASR::ttype_t* real_type = ASRUtils::TYPE(ASR::make_Real_t(al, - x.base.base.loc, 8, nullptr, 0)); - if (ASRUtils::is_real(*t)) { - double rv = ASR::down_cast(arg)->m_r; - double val = std::abs(rv); - tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, val, t); - } else if (ASRUtils::is_integer(*t)) { - int64_t rv = ASR::down_cast(arg)->m_n; - int64_t val = std::abs(rv); - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, val, t); - } else if (ASRUtils::is_complex(*t)) { - double re = ASR::down_cast(arg)->m_re; - double im = ASR::down_cast(arg)->m_im; - std::complex c(re, im); - double result = std::abs(c); - tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, result, real_type); - } else if (ASRUtils::is_logical(*t)) { - bool rv = ASR::down_cast(arg)->m_value; - int8_t val = rv ? 1 : 0; - ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Integer_t(al, + } else if (call_name == "pow") { + if (args.size() != 2) { + throw SemanticError("Two arguments are expected in pow", + x.base.base.loc); + } + ASR::expr_t *left = args[0]; + ASR::expr_t *right = args[1]; + ASR::binopType op = ASR::binopType::Pow; + make_BinOp_helper(left, right, op, x.base.base.loc, false); + return; + } else if (call_name == "bin" || call_name == "oct" || call_name == "hex") { + if (args.size() != 1) { + throw SemanticError(call_name + "() takes exactly one argument (" + + std::to_string(args.size()) + " given)", x.base.base.loc); + } + ASR::expr_t* expr = ASRUtils::expr_value(args[0]); + ASR::ttype_t* type = ASRUtils::expr_type(expr); + if (ASRUtils::is_integer(*type)) { + int64_t n = ASR::down_cast(expr)->m_n; + ASR::ttype_t* str_type = ASRUtils::TYPE(ASR::make_Character_t(al, + x.base.base.loc, 1, 1, nullptr, nullptr, 0)); + std::string str, prefix; + std::stringstream ss; + if (call_name == "oct") { + prefix = n > 0 ? "0o" : "-0o"; + ss << std::oct << std::abs(n); + str += ss.str(); + } else if (call_name == "bin") { + prefix = n > 0 ? "0b" : "-0b"; + str += std::bitset<64>(std::abs(n)).to_string(); + str.erase(0, str.find_first_not_of('0')); + } else { + prefix = n > 0 ? "0x" : "-0x"; + ss << std::hex << std::abs(n); + str += ss.str(); + } + str.insert(0, prefix); + tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, str), str_type); + return; + } else { + throw SemanticError(call_name + "() must have one integer argument", + x.base.base.loc); + } + } else if (call_name == "abs") { + if (args.size() != 1) { + throw SemanticError(call_name + "() takes exactly one argument (" + + std::to_string(args.size()) + " given)", x.base.base.loc); + } + std::string rl_path = get_runtime_library_dir(); + SymbolTable *st = current_scope; + while (st->parent != nullptr) { + st = st->parent; + } + bool ltypes; + std::string msym = "lpython_builtin"; + ASR::symbol_t *t = (ASR::symbol_t*)(load_module(al, st, + msym, x.base.base.loc, true, rl_path, ltypes, + [&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); } + )); + LFORTRAN_ASSERT(!ltypes) + if (!t) { + throw SemanticError("The module '" + msym + "' cannot be loaded", + x.base.base.loc); + } + + ASR::Module_t *m = ASR::down_cast(t); + + std::string local_sym = "abs"; + t = m->m_symtab->resolve_symbol(local_sym); + if (!t) { + throw SemanticError("ICE: The symbol '" + local_sym + "' not found in the module '" + msym + "'", + x.base.base.loc); + } + if (ASR::is_a(*t)) { + if (current_scope->scope.find(local_sym) != current_scope->scope.end()) { + throw SemanticError("Function already defined", + x.base.base.loc); + } + ASR::Function_t *mfn = ASR::down_cast(t); + // `mfn` is the Function in a module. Now we construct + // an ExternalSymbol that points to it. + Str name; + name.from_str(al, local_sym); + char *cname = name.c_str(al); + ASR::asr_t *fn = ASR::make_ExternalSymbol_t( + al, mfn->base.base.loc, + /* a_symtab */ current_scope, + /* a_name */ cname, + (ASR::symbol_t*)mfn, + m->m_name, nullptr, 0, mfn->m_name, + ASR::accessType::Public + ); + current_scope->scope[local_sym] = ASR::down_cast(fn); + + ASR::ttype_t *a_type = ASRUtils::TYPE(ASR::make_Real_t(al, + x.base.base.loc, 8, nullptr, 0)); + tmp = ASR::make_FunctionCall_t(al, x.base.base.loc, ASR::down_cast(fn), + nullptr, args.p, args.size(), nullptr, 0, a_type, nullptr, nullptr); + return; + } else { + throw SemanticError("ICE: Abs expected to be a function", x.base.base.loc); + } + // Compile time value implementation: + /* + ASR::expr_t* arg = ASRUtils::expr_value(args[0]); + ASR::ttype_t* t = ASRUtils::expr_type(arg); + ASR::ttype_t* real_type = ASRUtils::TYPE(ASR::make_Real_t(al, + x.base.base.loc, 8, nullptr, 0)); + ASR::ttype_t *int_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, 4, nullptr, 0)); - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, val, type); - } else { - throw SemanticError(call_name + "() must have one real, integer, complex, or logical argument", - x.base.base.loc); - } - return; - } else if (call_name == "bool") { - if (args.size() != 1) { - throw SemanticError(call_name + "() takes exactly one argument (" + - std::to_string(args.size()) + " given)", x.base.base.loc); - } - ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Logical_t(al, x.base.base.loc, - 1, nullptr, 0)); - ASR::expr_t* arg = ASRUtils::expr_value(args[0]); - ASR::ttype_t* t = ASRUtils::expr_type(arg); - bool result; - if (ASRUtils::is_real(*t)) { - double rv = ASR::down_cast(arg)->m_r; - result = rv ? true : false; - } else if (ASRUtils::is_integer(*t)) { - int64_t rv = ASR::down_cast(arg)->m_n; - result = rv ? true : false; - } else if (ASRUtils::is_complex(*t)) { - double re = ASR::down_cast(arg)->m_re; - double im = ASR::down_cast(arg)->m_im; - std::complex c(re, im); - result = (re || im) ? true : false; - } else if (ASRUtils::is_logical(*t)) { - bool rv = ASR::down_cast(arg)->m_value; - result = rv; - } else if (ASRUtils::is_character(*t)) { - char* c = ASR::down_cast(ASRUtils::expr_value(arg))->m_s; - result = strlen(s2c(al, std::string(c))) ? true : false; - } else { - throw SemanticError(call_name + "() must have one real, integer, character," - " complex, or logical argument", x.base.base.loc); - } - tmp = ASR::make_ConstantLogical_t(al, x.base.base.loc, result, type); - return; - } else if (call_name == "callable") { - if (args.size() != 1) { - throw SemanticError(call_name + "() takes exactly one argument (" + - std::to_string(args.size()) + " given)", x.base.base.loc); - } - ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Logical_t(al, x.base.base.loc, - 1, nullptr, 0)); - ASR::expr_t *arg = args[0]; - bool result = false; - if (ASR::is_a(*arg)) { - ASR::symbol_t *t = ASR::down_cast(arg)->m_v; - result = (ASR::is_a(*t) || - ASR::is_a(*t)); - } - tmp = ASR::make_ConstantLogical_t(al, x.base.base.loc, result, type); - return; - } else if (call_name == "int") { - ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Integer_t(al, - x.base.base.loc, 4, nullptr, 0)); - if (args.size() == 0) { - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, 0, type); + if (ASRUtils::is_real(*t)) { + double rv = ASR::down_cast(arg)->m_r; + double val = std::abs(rv); + tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, val, t); + } else if (ASRUtils::is_integer(*t)) { + int64_t rv = ASR::down_cast(arg)->m_n; + int64_t val = std::abs(rv); + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, val, t); + } else if (ASRUtils::is_complex(*t)) { + double re = ASR::down_cast(arg)->m_re; + double im = ASR::down_cast(arg)->m_im; + std::complex c(re, im); + double result = std::abs(c); + tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, result, real_type); + } else if (ASRUtils::is_logical(*t)) { + bool rv = ASR::down_cast(arg)->m_value; + int8_t val = rv ? 1 : 0; + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, val, int_type); + } else { + throw SemanticError(call_name + "() must have one real, integer, complex, or logical argument", + x.base.base.loc); + } return; - } - ASR::expr_t* int_expr = args[0]; - ASR::ttype_t* int_type = ASRUtils::expr_type(int_expr); - if (ASRUtils::expr_value(int_expr) == nullptr) { - throw SemanticError("runtime int(x) is not supported, only compile time for now", - x.base.base.loc); - } - if (ASRUtils::is_integer(*int_type)) { - int64_t ival = ASR::down_cast(ASRUtils::expr_value(int_expr))->m_n; - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, ival, type); - - } else if (ASRUtils::is_character(*int_type)) { - // convert a string to an int - char* c = ASR::down_cast(ASRUtils::expr_value(int_expr))->m_s; - std::string s = std::string(c); - int64_t ival = std::stoll(s); - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, ival, type); - - } else if (ASRUtils::is_real(*int_type)) { - int64_t ival = ASR::down_cast(ASRUtils::expr_value(int_expr))->m_r; - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, ival, type); - } else if (ASRUtils::is_logical(*int_type)) { - bool rv = ASR::down_cast(int_expr)->m_value; - int8_t val = rv ? 1 : 0; - tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, val, type); - } else { - throw SemanticError("int() argument must be real, integer, logical, or a string, not '" + - ASRUtils::type_to_str(int_type) + "'", x.base.base.loc); - } - return; - } else if (call_name == "float") { - ASR::ttype_t* type = ASRUtils::TYPE(ASR::make_Real_t(al, - x.base.base.loc, 8, nullptr, 0)); - if (args.size() == 0) { - tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, 0.0, type); + */ + } else if (call_name == "bool") { + if (args.size() != 1) { + throw SemanticError(call_name + "() takes exactly one argument (" + + std::to_string(args.size()) + " given)", x.base.base.loc); + } + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Logical_t(al, x.base.base.loc, + 1, nullptr, 0)); + ASR::expr_t* arg = ASRUtils::expr_value(args[0]); + ASR::ttype_t* t = ASRUtils::expr_type(arg); + bool result; + if (ASRUtils::is_real(*t)) { + double rv = ASR::down_cast(arg)->m_r; + result = rv ? true : false; + } else if (ASRUtils::is_integer(*t)) { + int64_t rv = ASR::down_cast(arg)->m_n; + result = rv ? true : false; + } else if (ASRUtils::is_complex(*t)) { + double re = ASR::down_cast(arg)->m_re; + double im = ASR::down_cast(arg)->m_im; + std::complex c(re, im); + result = (re || im) ? true : false; + } else if (ASRUtils::is_logical(*t)) { + bool rv = ASR::down_cast(arg)->m_value; + result = rv; + } else if (ASRUtils::is_character(*t)) { + char* c = ASR::down_cast(ASRUtils::expr_value(arg))->m_s; + result = strlen(s2c(al, std::string(c))) ? true : false; + } else { + throw SemanticError(call_name + "() must have one real, integer, character," + " complex, or logical argument", x.base.base.loc); + } + tmp = ASR::make_ConstantLogical_t(al, x.base.base.loc, result, type); return; - } - ASR::expr_t* float_expr = args[0]; - ASR::ttype_t* float_type = ASRUtils::expr_type(float_expr); - if (ASRUtils::expr_value(float_expr) == nullptr) { - throw SemanticError("runtime float(x) is not supported, only compile time for now", - x.base.base.loc); - } - if (ASRUtils::is_real(*float_type)) { - float rv = ASR::down_cast(ASRUtils::expr_value(float_expr))->m_r; - tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, rv, type); - } else if (ASRUtils::is_integer(*float_type)) { - // convert an int to a float using implicit cast - double rv = ASR::down_cast(ASRUtils::expr_value(float_expr))->m_n; - tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, rv, type); - } else if (ASRUtils::is_logical(*float_type)) { - bool rv = ASR::down_cast(float_expr)->m_value; - float val = rv ? 1.0 : 0.0; - tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, val, type); - } else if (ASRUtils::is_character(*float_type)) { - // convert a string to a float - char* c = ASR::down_cast(ASRUtils::expr_value(float_expr))->m_s; - std::string s = std::string(c); - float rv = std::stof(s); - tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, rv, type); - } else { - throw SemanticError("float() argument must be real, integer, logical, or a string, not '" + - ASRUtils::type_to_str(float_type) + "'", x.base.base.loc); - } - return; - } else if (call_name == "str") { - ASR::ttype_t* str_type = ASRUtils::TYPE(ASR::make_Character_t(al, - x.base.base.loc, 1, 1, nullptr, nullptr, 0)); - if (args.size() == 0) { // create an empty string - tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, ""), str_type); + } else if (call_name == "callable") { + if (args.size() != 1) { + throw SemanticError(call_name + "() takes exactly one argument (" + + std::to_string(args.size()) + " given)", x.base.base.loc); + } + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Logical_t(al, x.base.base.loc, + 1, nullptr, 0)); + ASR::expr_t *arg = args[0]; + bool result = false; + if (ASR::is_a(*arg)) { + ASR::symbol_t *t = ASR::down_cast(arg)->m_v; + result = (ASR::is_a(*t) || + ASR::is_a(*t)); + } + tmp = ASR::make_ConstantLogical_t(al, x.base.base.loc, result, type); return; - } - ASR::expr_t* arg = ASRUtils::expr_value(args[0]); - ASR::ttype_t* arg_type = ASRUtils::expr_type(arg); - if (arg == nullptr) { - throw SemanticError("runtime str(x) is not supported, only compile time for now", - x.base.base.loc); - } - if (ASRUtils::is_integer(*arg_type)) { - int64_t ival = ASR::down_cast(arg)->m_n; - std::string s = std::to_string(ival); - tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); - } else if (ASRUtils::is_real(*arg_type)) { - double rval = ASR::down_cast(arg)->m_r; - std::string s = std::to_string(rval); - tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); - } else if (ASRUtils::is_logical(*arg_type)) { - bool rv = ASR::down_cast(arg)->m_value; - std::string s = rv ? "True" : "False"; - tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); - } else if (ASRUtils::is_character(*arg_type)) { - char* c = ASR::down_cast(arg)->m_s; - std::string s = std::string(c); - tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); - } else { - throw SemanticError("str() argument must be real, integer, logical, or a string, not '" + - ASRUtils::type_to_str(arg_type) + "'", x.base.base.loc); - } - return; - } else if (call_name == "divmod") { - if (args.size() != 2) { - throw SemanticError(call_name + "() takes exactly two arguments (" + - std::to_string(args.size()) + " given)", x.base.base.loc); - } - ASR::expr_t* arg1 = ASRUtils::expr_value(args[0]); - ASR::expr_t* arg2 = ASRUtils::expr_value(args[1]); - ASR::ttype_t* arg1_type = ASRUtils::expr_type(arg1); - ASR::ttype_t* arg2_type = ASRUtils::expr_type(arg2); - Vec tuple; // pair consisting of quotient and remainder - tuple.reserve(al, 2); - Vec tuple_type_vec; - tuple_type_vec.reserve(al, 2); - if (arg1 == nullptr || arg2 == nullptr) { - throw SemanticError("runtime divmod(x, y) is not supported, only compile time for now", - x.base.base.loc); - } - if (ASRUtils::is_integer(*arg1_type) && ASRUtils::is_integer(*arg2_type)) { - int64_t ival1 = ASR::down_cast(arg1)->m_n; - int64_t ival2 = ASR::down_cast(arg2)->m_n; - if (ival2 == 0) { - throw SemanticError("Integer division or modulo by zero not possible", + } else if (call_name == "int") { + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Integer_t(al, + x.base.base.loc, 4, nullptr, 0)); + if (args.size() == 0) { + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, 0, type); + return; + } + ASR::expr_t* int_expr = args[0]; + ASR::ttype_t* int_type = ASRUtils::expr_type(int_expr); + if (ASRUtils::expr_value(int_expr) == nullptr) { + throw SemanticError("runtime int(x) is not supported, only compile time for now", x.base.base.loc); + } + if (ASRUtils::is_integer(*int_type)) { + int64_t ival = ASR::down_cast(ASRUtils::expr_value(int_expr))->m_n; + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, ival, type); + + } else if (ASRUtils::is_character(*int_type)) { + // convert a string to an int + char* c = ASR::down_cast(ASRUtils::expr_value(int_expr))->m_s; + std::string s = std::string(c); + int64_t ival = std::stoll(s); + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, ival, type); + + } else if (ASRUtils::is_real(*int_type)) { + int64_t ival = ASR::down_cast(ASRUtils::expr_value(int_expr))->m_r; + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, ival, type); + } else if (ASRUtils::is_logical(*int_type)) { + bool rv = ASR::down_cast(int_expr)->m_value; + int8_t val = rv ? 1 : 0; + tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, val, type); } else { - int64_t div = ival1 / ival2; - int64_t mod = ival1 % ival2; - tuple.push_back(al, ASRUtils::EXPR( - ASR::make_ConstantInteger_t(al, x.base.base.loc, div, arg1_type))); - tuple.push_back(al, ASRUtils::EXPR( - ASR::make_ConstantInteger_t(al, x.base.base.loc, mod, arg1_type))); - tuple_type_vec.push_back(al, arg1_type); - tuple_type_vec.push_back(al, arg2_type); - ASR::ttype_t *tuple_type = ASRUtils::TYPE(ASR::make_Tuple_t(al, x.base.base.loc, - tuple_type_vec.p, tuple_type_vec.n)); - tmp = ASR::make_ConstantTuple_t(al, x.base.base.loc, tuple.p, tuple.size(), tuple_type); + throw SemanticError("int() argument must be real, integer, logical, or a string, not '" + + ASRUtils::type_to_str(int_type) + "'", x.base.base.loc); + } + return; + } else if (call_name == "float") { + ASR::ttype_t* type = ASRUtils::TYPE(ASR::make_Real_t(al, + x.base.base.loc, 8, nullptr, 0)); + if (args.size() == 0) { + tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, 0.0, type); return; } + ASR::expr_t* float_expr = args[0]; + ASR::ttype_t* float_type = ASRUtils::expr_type(float_expr); + if (ASRUtils::expr_value(float_expr) == nullptr) { + throw SemanticError("runtime float(x) is not supported, only compile time for now", + x.base.base.loc); + } + if (ASRUtils::is_real(*float_type)) { + float rv = ASR::down_cast(ASRUtils::expr_value(float_expr))->m_r; + tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, rv, type); + } else if (ASRUtils::is_integer(*float_type)) { + // convert an int to a float using implicit cast + double rv = ASR::down_cast(ASRUtils::expr_value(float_expr))->m_n; + tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, rv, type); + } else if (ASRUtils::is_logical(*float_type)) { + bool rv = ASR::down_cast(float_expr)->m_value; + float val = rv ? 1.0 : 0.0; + tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, val, type); + } else if (ASRUtils::is_character(*float_type)) { + // convert a string to a float + char* c = ASR::down_cast(ASRUtils::expr_value(float_expr))->m_s; + std::string s = std::string(c); + float rv = std::stof(s); + tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, rv, type); + } else { + throw SemanticError("float() argument must be real, integer, logical, or a string, not '" + + ASRUtils::type_to_str(float_type) + "'", x.base.base.loc); + } + return; + } else if (call_name == "str") { + ASR::ttype_t* str_type = ASRUtils::TYPE(ASR::make_Character_t(al, + x.base.base.loc, 1, 1, nullptr, nullptr, 0)); + if (args.size() == 0) { // create an empty string + tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, ""), str_type); + return; + } + ASR::expr_t* arg = ASRUtils::expr_value(args[0]); + ASR::ttype_t* arg_type = ASRUtils::expr_type(arg); + if (arg == nullptr) { + throw SemanticError("runtime str(x) is not supported, only compile time for now", + x.base.base.loc); + } + if (ASRUtils::is_integer(*arg_type)) { + int64_t ival = ASR::down_cast(arg)->m_n; + std::string s = std::to_string(ival); + tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); + } else if (ASRUtils::is_real(*arg_type)) { + double rval = ASR::down_cast(arg)->m_r; + std::string s = std::to_string(rval); + tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); + } else if (ASRUtils::is_logical(*arg_type)) { + bool rv = ASR::down_cast(arg)->m_value; + std::string s = rv ? "True" : "False"; + tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); + } else if (ASRUtils::is_character(*arg_type)) { + char* c = ASR::down_cast(arg)->m_s; + std::string s = std::string(c); + tmp = ASR::make_ConstantString_t(al, x.base.base.loc, s2c(al, s), str_type); + } else { + throw SemanticError("str() argument must be real, integer, logical, or a string, not '" + + ASRUtils::type_to_str(arg_type) + "'", x.base.base.loc); + } + return; + } else if (call_name == "divmod") { + if (args.size() != 2) { + throw SemanticError(call_name + "() takes exactly two arguments (" + + std::to_string(args.size()) + " given)", x.base.base.loc); + } + ASR::expr_t* arg1 = ASRUtils::expr_value(args[0]); + ASR::expr_t* arg2 = ASRUtils::expr_value(args[1]); + ASR::ttype_t* arg1_type = ASRUtils::expr_type(arg1); + ASR::ttype_t* arg2_type = ASRUtils::expr_type(arg2); + Vec tuple; // pair consisting of quotient and remainder + tuple.reserve(al, 2); + Vec tuple_type_vec; + tuple_type_vec.reserve(al, 2); + if (arg1 == nullptr || arg2 == nullptr) { + throw SemanticError("runtime divmod(x, y) is not supported, only compile time for now", + x.base.base.loc); + } + if (ASRUtils::is_integer(*arg1_type) && ASRUtils::is_integer(*arg2_type)) { + int64_t ival1 = ASR::down_cast(arg1)->m_n; + int64_t ival2 = ASR::down_cast(arg2)->m_n; + if (ival2 == 0) { + throw SemanticError("Integer division or modulo by zero not possible", + x.base.base.loc); + } else { + int64_t div = ival1 / ival2; + int64_t mod = ival1 % ival2; + tuple.push_back(al, ASRUtils::EXPR( + ASR::make_ConstantInteger_t(al, x.base.base.loc, div, arg1_type))); + tuple.push_back(al, ASRUtils::EXPR( + ASR::make_ConstantInteger_t(al, x.base.base.loc, mod, arg1_type))); + tuple_type_vec.push_back(al, arg1_type); + tuple_type_vec.push_back(al, arg2_type); + ASR::ttype_t *tuple_type = ASRUtils::TYPE(ASR::make_Tuple_t(al, x.base.base.loc, + tuple_type_vec.p, tuple_type_vec.n)); + tmp = ASR::make_ConstantTuple_t(al, x.base.base.loc, tuple.p, tuple.size(), tuple_type); + return; + } + } else { + throw SemanticError("Both arguments of divmod() must be integers, not '" + + ASRUtils::type_to_str(arg1_type) + "' and '" + ASRUtils::type_to_str(arg2_type) + "'", + x.base.base.loc); + } } else { - throw SemanticError("Both arguments of divmod() must be integers, not '" + - ASRUtils::type_to_str(arg1_type) + "' and '" + ASRUtils::type_to_str(arg2_type) + "'", + // The function was not found and it is not intrinsic + throw SemanticError("Function '" + call_name + "' is not declared and not intrinsic", x.base.base.loc); } } - // Other functions - ASR::symbol_t *stemp = current_scope->resolve_symbol(call_name); - // handling ExternalSymbol - ASR::symbol_t *s = ASRUtils::symbol_get_past_external(stemp); if (!s) { throw SemanticError("Function '" + call_name + "' is not declared", x.base.base.loc); } + // handling ExternalSymbol + ASR::symbol_t *stemp = s; + s = ASRUtils::symbol_get_past_external(s); if(ASR::is_a(*s)) { ASR::Function_t *func = ASR::down_cast(s); diff --git a/src/runtime/lpython_builtin.py b/src/runtime/lpython_builtin.py new file mode 100644 index 0000000000..c6e5234cc8 --- /dev/null +++ b/src/runtime/lpython_builtin.py @@ -0,0 +1,40 @@ +from ltypes import i32 +#from sys import exit + + +def ord(s: str) -> i32: + """ + Returns an integer representing the Unicode code + point of a given unicode character. This is the inverse of `chr()`. + """ + if s == '0': + return 48 + elif s == '1': + return 49 +# else: +# exit(1) + + +def chr(i: i32) -> str: + """ + Returns the string representing a unicode character from + the given Unicode code point. This is the inverse of `ord()`. + """ + if i == 48: + return '0' + elif i == 49: + return '1' +# else: +# exit(1) + + +# This is an implementation for f64. +# TODO: implement abs() as a generic procedure, and implement for all types +def abs(x: f64) -> f64: + """ + Return the absolute value of `x`. + """ + if x >= 0.0: + return x + else: + return -x diff --git a/tests/constants1.py b/tests/constants1.py index 9735371d3e..fd3471d782 100644 --- a/tests/constants1.py +++ b/tests/constants1.py @@ -19,15 +19,15 @@ def test_ord_chr(): def test_abs(): - a: i32 - a = abs(5) - a = abs(-500) - a = abs(False) - a = abs(True) + # a: i32 + # a = abs(5) + # a = abs(-500) + # a = abs(False) + # a = abs(True) b: f32 b = abs(3.45) b = abs(-5346.34) - b = abs(complex(3.45, 5.6)) + # b = abs(complex(3.45, 5.6)) def test_len(): diff --git a/tests/reference/asr-constants1-5828e8a.json b/tests/reference/asr-constants1-5828e8a.json index ca34cae7e2..1a4c4ea745 100644 --- a/tests/reference/asr-constants1-5828e8a.json +++ b/tests/reference/asr-constants1-5828e8a.json @@ -2,12 +2,12 @@ "basename": "asr-constants1-5828e8a", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/constants1.py", - "infile_hash": "96e60b5d3b6cb09a1198932629c9974ac3cf8854e3b1c7ba8959ea83", + "infile_hash": "6adf0c1cf8ec1667bf19edaf62d087483e6229370ed0f10a207ee0b4", "outfile": null, "outfile_hash": null, "stdout": "asr-constants1-5828e8a.stdout", - "stdout_hash": "0bf1393bd5bfba3cb0593f45cdd27141825b57fa5e2e547ef7a84875", + "stdout_hash": "82599c6a0114feef56f5e9198dd5cfbd06d87638efc14126af92a89e", "stderr": null, "stderr_hash": null, "returncode": 0 -} +} \ No newline at end of file diff --git a/tests/reference/asr-constants1-5828e8a.stdout b/tests/reference/asr-constants1-5828e8a.stdout index 0d00a68695..d53f6e2e4a 100644 --- a/tests/reference/asr-constants1-5828e8a.stdout +++ b/tests/reference/asr-constants1-5828e8a.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 12 {}) main_program [] []), test_abs: (Subroutine (SymbolTable 4 {a: (Variable 4 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 4 b Local () () Default (Real 4 []) Source Public Required .false.)}) test_abs [] [(= (Var 4 a) (ConstantInteger 5 (Integer 4 [])) ()) (= (Var 4 a) (ConstantInteger 500 (Integer 4 [])) ()) (= (Var 4 a) (ConstantInteger 0 (Integer 4 [])) ()) (= (Var 4 a) (ConstantInteger 1 (Integer 4 [])) ()) (= (Var 4 b) (ConstantReal 3.450000 (Real 8 [])) ()) (= (Var 4 b) (ConstantReal 5346.340000 (Real 8 [])) ()) (= (Var 4 b) (ConstantReal 6.577424 (Real 8 [])) ())] Source Public Implementation () .false. .false.), test_bool: (Subroutine (SymbolTable 6 {a: (Variable 6 a Local () () Default (Logical 1 []) Source Public Required .false.)}) test_bool [] [(= (Var 6 a) (ConstantLogical .false. (Logical 1 [])) ()) (= (Var 6 a) (ConstantLogical .true. (Logical 1 [])) ()) (= (Var 6 a) (ConstantLogical .false. (Logical 1 [])) ()) (= (Var 6 a) (ConstantLogical .false. (Logical 1 [])) ()) (Assert (Compare (Var 6 a) Eq (ConstantLogical .false. (Logical 1 [])) (Logical 4 []) () ()) ()) (= (Var 6 a) (ConstantLogical .true. (Logical 1 [])) ()) (= (Var 6 a) (ConstantLogical .true. (Logical 1 [])) ()) (Assert (Compare (Var 6 a) Eq (ConstantLogical .true. (Logical 1 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.), test_boz: (Subroutine (SymbolTable 2 {b: (Variable 2 b Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_boz [] [(= (Var 2 b) (ConstantString "0b101" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0b1000000" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "-0b1000010110" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0o10" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0o70" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "-0o1026" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0x2a" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0xc0ffee" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "-0x216" (Character 1 1 () [])) ())] Source Public Implementation () .false. .false.), test_callable: (Subroutine (SymbolTable 8 {a: (Variable 8 a Local () () Default (Logical 1 []) Source Public Required .false.), b: (Variable 8 b Local () () Default (Integer 4 []) Source Public Required .false.)}) test_callable [] [(= (Var 8 b) (ConstantInteger 2 (Integer 4 [])) ()) (= (Var 8 a) (ConstantLogical .true. (Logical 1 [])) ()) (Assert (Compare (Var 8 a) Eq (ConstantLogical .true. (Logical 1 [])) (Logical 4 []) () ()) ()) (= (Var 8 a) (ConstantLogical .false. (Logical 1 [])) ()) (Assert (Compare (Var 8 a) Eq (ConstantLogical .false. (Logical 1 [])) (Logical 4 []) () ()) ()) (= (Var 8 a) (ConstantLogical .false. (Logical 1 [])) ()) (Assert (Compare (Var 8 a) Eq (ConstantLogical .false. (Logical 1 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.), test_divmod: (Subroutine (SymbolTable 11 {a: (Variable 11 a Local () () Default (Integer 4 []) Source Public Required .false.)}) test_divmod [] [(= (Var 11 a) (ConstantTuple [(ConstantInteger 3 (Integer 4 [])) (ConstantInteger 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) (= (Var 11 a) (ConstantTuple [(ConstantInteger -3 (Integer 4 [])) (ConstantInteger 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) (= (Var 11 a) (ConstantTuple [(ConstantInteger 1 (Integer 4 [])) (ConstantInteger 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) (= (Var 11 a) (ConstantTuple [(ConstantInteger 0 (Integer 4 [])) (ConstantInteger 4 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) (= (Var 11 a) (ConstantTuple [(ConstantInteger 0 (Integer 4 [])) (ConstantInteger 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ())] Source Public Implementation () .false. .false.), test_float: (Subroutine (SymbolTable 10 {a: (Variable 10 a Local () () Default (Real 8 []) Source Public Required .false.)}) test_float [] [(= (Var 10 a) (ConstantReal 0.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 4.560000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 5.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal -1.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 1.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 0.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 5346.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 423.533997 (Real 8 [])) ())] Source Public Implementation () .false. .false.), test_int: (Subroutine (SymbolTable 9 {a: (Variable 9 a Local () () Default (Integer 8 []) Source Public Required .false.)}) test_int [] [(= (Var 9 a) (ImplicitCast (ConstantInteger 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 4 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 5 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger -5 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 5346 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ())] Source Public Implementation () .false. .false.), test_len: (Subroutine (SymbolTable 5 {a: (Variable 5 a Local () () Default (Integer 4 []) Source Public Required .false.)}) test_len [] [(= (Var 5 a) (ConstantInteger 0 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 4 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 14 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 3 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 2 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 3 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 2 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 3 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 3 (Integer 4 [])) ())] Source Public Implementation () .false. .false.), test_ord_chr: (Subroutine (SymbolTable 3 {a: (Variable 3 a Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 3 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_ord_chr [] [(= (Var 3 a) (ConstantInteger 53 (Integer 4 [])) ()) (= (Var 3 s) (ConstantString "+" (Character 1 1 () [])) ())] Source Public Implementation () .false. .false.), test_str: (Subroutine (SymbolTable 7 {s: (Variable 7 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_str [] [(= (Var 7 s) (ConstantString "" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "5" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "-4" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "5.600000" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "True" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "False" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "5346" (Character 1 1 () [])) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 17 {}) main_program [] []), test_abs: (Subroutine (SymbolTable 4 {abs: (ExternalSymbol 4 abs 13 abs lpython_builtin [] abs Public), b: (Variable 4 b Local () () Default (Real 4 []) Source Public Required .false.)}) test_abs [] [(= (Var 4 b) (FunctionCall 4 abs () [(ConstantReal 3.450000 (Real 8 []))] [] (Real 8 []) () ()) ()) (= (Var 4 b) (FunctionCall 4 abs () [(UnaryOp USub (ConstantReal 5346.340000 (Real 8 [])) (Real 8 []) (ConstantReal -5346.340000 (Real 8 [])))] [] (Real 8 []) () ()) ())] Source Public Implementation () .false. .false.), test_bool: (Subroutine (SymbolTable 6 {a: (Variable 6 a Local () () Default (Logical 1 []) Source Public Required .false.)}) test_bool [] [(= (Var 6 a) (ConstantLogical .false. (Logical 1 [])) ()) (= (Var 6 a) (ConstantLogical .true. (Logical 1 [])) ()) (= (Var 6 a) (ConstantLogical .false. (Logical 1 [])) ()) (= (Var 6 a) (ConstantLogical .false. (Logical 1 [])) ()) (Assert (Compare (Var 6 a) Eq (ConstantLogical .false. (Logical 1 [])) (Logical 4 []) () ()) ()) (= (Var 6 a) (ConstantLogical .true. (Logical 1 [])) ()) (= (Var 6 a) (ConstantLogical .true. (Logical 1 [])) ()) (Assert (Compare (Var 6 a) Eq (ConstantLogical .true. (Logical 1 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.), test_boz: (Subroutine (SymbolTable 2 {b: (Variable 2 b Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_boz [] [(= (Var 2 b) (ConstantString "0b101" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0b1000000" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "-0b1000010110" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0o10" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0o70" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "-0o1026" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0x2a" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "0xc0ffee" (Character 1 1 () [])) ()) (= (Var 2 b) (ConstantString "-0x216" (Character 1 1 () [])) ())] Source Public Implementation () .false. .false.), test_callable: (Subroutine (SymbolTable 8 {a: (Variable 8 a Local () () Default (Logical 1 []) Source Public Required .false.), b: (Variable 8 b Local () () Default (Integer 4 []) Source Public Required .false.)}) test_callable [] [(= (Var 8 b) (ConstantInteger 2 (Integer 4 [])) ()) (= (Var 8 a) (ConstantLogical .true. (Logical 1 [])) ()) (Assert (Compare (Var 8 a) Eq (ConstantLogical .true. (Logical 1 [])) (Logical 4 []) () ()) ()) (= (Var 8 a) (ConstantLogical .false. (Logical 1 [])) ()) (Assert (Compare (Var 8 a) Eq (ConstantLogical .false. (Logical 1 [])) (Logical 4 []) () ()) ()) (= (Var 8 a) (ConstantLogical .false. (Logical 1 [])) ()) (Assert (Compare (Var 8 a) Eq (ConstantLogical .false. (Logical 1 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.), test_divmod: (Subroutine (SymbolTable 11 {a: (Variable 11 a Local () () Default (Integer 4 []) Source Public Required .false.)}) test_divmod [] [(= (Var 11 a) (ConstantTuple [(ConstantInteger 3 (Integer 4 [])) (ConstantInteger 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) (= (Var 11 a) (ConstantTuple [(ConstantInteger -3 (Integer 4 [])) (ConstantInteger 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) (= (Var 11 a) (ConstantTuple [(ConstantInteger 1 (Integer 4 [])) (ConstantInteger 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) (= (Var 11 a) (ConstantTuple [(ConstantInteger 0 (Integer 4 [])) (ConstantInteger 4 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) (= (Var 11 a) (ConstantTuple [(ConstantInteger 0 (Integer 4 [])) (ConstantInteger 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ())] Source Public Implementation () .false. .false.), test_float: (Subroutine (SymbolTable 10 {a: (Variable 10 a Local () () Default (Real 8 []) Source Public Required .false.)}) test_float [] [(= (Var 10 a) (ConstantReal 0.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 4.560000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 5.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal -1.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 1.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 0.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 5346.000000 (Real 8 [])) ()) (= (Var 10 a) (ConstantReal 423.533997 (Real 8 [])) ())] Source Public Implementation () .false. .false.), test_int: (Subroutine (SymbolTable 9 {a: (Variable 9 a Local () () Default (Integer 8 []) Source Public Required .false.)}) test_int [] [(= (Var 9 a) (ImplicitCast (ConstantInteger 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 4 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 5 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger -5 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (ImplicitCast (ConstantInteger 5346 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ())] Source Public Implementation () .false. .false.), test_len: (Subroutine (SymbolTable 5 {a: (Variable 5 a Local () () Default (Integer 4 []) Source Public Required .false.)}) test_len [] [(= (Var 5 a) (ConstantInteger 0 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 4 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 14 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 3 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 2 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 3 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 2 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 3 (Integer 4 [])) ()) (= (Var 5 a) (ConstantInteger 3 (Integer 4 [])) ())] Source Public Implementation () .false. .false.), test_ord_chr: (Subroutine (SymbolTable 3 {a: (Variable 3 a Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 3 ord 13 ord lpython_builtin [] ord Public), s: (Variable 3 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_ord_chr [] [(= (Var 3 a) (FunctionCall 3 ord () [(ConstantString "5" (Character 1 1 () []))] [] (Integer 4 []) () ()) ()) (= (Var 3 s) (ConstantString "+" (Character 1 1 () [])) ())] Source Public Implementation () .false. .false.), test_str: (Subroutine (SymbolTable 7 {s: (Variable 7 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_str [] [(= (Var 7 s) (ConstantString "" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "5" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "-4" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "5.600000" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "True" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "False" (Character 1 1 () [])) ()) (= (Var 7 s) (ConstantString "5346" (Character 1 1 () [])) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr1-8df2d66.json b/tests/reference/asr-expr1-8df2d66.json index 067c74acb0..f61e510dfe 100644 --- a/tests/reference/asr-expr1-8df2d66.json +++ b/tests/reference/asr-expr1-8df2d66.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr1-8df2d66.stdout", - "stdout_hash": "f91e20cb7a51634aa2d7a0a405c291e3739bc0ab721ba7f22b1d5189", + "stdout_hash": "3386132d1619fd644c4ff66843325b74795f6565389176b4bf9968bc", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr1-8df2d66.stdout b/tests/reference/asr-expr1-8df2d66.stdout index 453aa8234a..809084fb91 100644 --- a/tests/reference/asr-expr1-8df2d66.stdout +++ b/tests/reference/asr-expr1-8df2d66.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_namedexpr: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Integer 4 []) Source Public Required .false.)}) test_namedexpr [] [(= (Var 2 x) (NamedExpr (Var 2 y) (ConstantInteger 0 (Integer 4 [])) (Integer 4 [])) ()) (If (NamedExpr (Var 2 a) (ConstantInteger 51 (Integer 4 [])) (Integer 4 [])) [(= (Var 2 x) (ConstantInteger 1 (Integer 4 [])) ())] []) (WhileLoop (NamedExpr (Var 2 a) (ConstantInteger 1 (Integer 4 [])) (Integer 4 [])) [(= (Var 2 y) (ConstantInteger 1 (Integer 4 [])) ())])] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 8 {}) main_program [] []), test_namedexpr: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 2 ord 4 ord lpython_builtin [] ord Public), x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Integer 4 []) Source Public Required .false.)}) test_namedexpr [] [(= (Var 2 x) (NamedExpr (Var 2 y) (ConstantInteger 0 (Integer 4 [])) (Integer 4 [])) ()) (If (NamedExpr (Var 2 a) (FunctionCall 2 ord () [(ConstantString "3" (Character 1 1 () []))] [] (Integer 4 []) () ()) (Integer 4 [])) [(= (Var 2 x) (ConstantInteger 1 (Integer 4 [])) ())] []) (WhileLoop (NamedExpr (Var 2 a) (ConstantInteger 1 (Integer 4 [])) (Integer 4 [])) [(= (Var 2 y) (ConstantInteger 1 (Integer 4 [])) ())])] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr13-81bdb5a.stdout b/tests/reference/asr-expr13-81bdb5a.stdout index 31b6a6c0b0..71fe55755c 100644 --- a/tests/reference/asr-expr13-81bdb5a.stdout +++ b/tests/reference/asr-expr13-81bdb5a.stdout @@ -1,2 +1 @@ (TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_Compare: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Logical 1 []) Source Public Required .false.)}) test_Compare [] [(= (Var 2 a) (Compare (ConstantInteger 5 (Integer 4 [])) Gt (ConstantInteger 4 (Integer 4 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantInteger 5 (Integer 4 [])) LtE (ConstantInteger 4 (Integer 4 [])) (Logical 4 []) (ConstantLogical .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantInteger 5 (Integer 4 [])) Lt (ConstantInteger 4 (Integer 4 [])) (Logical 4 []) (ConstantLogical .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantReal 5.600000 (Real 8 [])) GtE (ConstantReal 5.599990 (Real 8 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantReal 3.300000 (Real 8 [])) Eq (ConstantReal 3.300000 (Real 8 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantReal 3.300000 (Real 8 [])) NotEq (ConstantReal 3.400000 (Real 8 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantComplex 3.000000 4.000000 (Complex 8 [])) Eq (ConstantComplex 3.000000 4.000000 (Complex 8 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantString "abc" (Character 1 3 () [])) Gt (ConstantString "abd" (Character 1 3 () [])) (Logical 4 []) (ConstantLogical .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantString "" (Character 1 0 () [])) Lt (ConstantString "s" (Character 1 1 () [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantString "-abs" (Character 1 4 () [])) GtE (ConstantString "abs" (Character 1 3 () [])) (Logical 4 []) (ConstantLogical .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantString "abcd" (Character 1 4 () [])) LtE (ConstantString "abcde" (Character 1 5 () [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantString "abc" (Character 1 3 () [])) Eq (ConstantString "abc" (Character 1 3 () [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantString "abc" (Character 1 3 () [])) NotEq (ConstantString "abd" (Character 1 3 () [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (ConstantString "" (Character 1 0 () [])) Eq (ConstantString "+" (Character 1 1 () [])) (Logical 4 []) (ConstantLogical .false. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) - diff --git a/tests/reference/asr-loop2-e874469.json b/tests/reference/asr-loop2-e874469.json index c68252798f..1601eb424b 100644 --- a/tests/reference/asr-loop2-e874469.json +++ b/tests/reference/asr-loop2-e874469.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-loop2-e874469.stdout", - "stdout_hash": "d1dc630006e0a7a21748d0a8bd26f3c99b277d5c208ed6d8077ac9e9", + "stdout_hash": "e310c8c30a336eecd524851e7d6664a09f9b3910b7d641c7fea48f8d", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-loop2-e874469.stdout b/tests/reference/asr-loop2-e874469.stdout index e584554edf..f552ab847c 100644 --- a/tests/reference/asr-loop2-e874469.stdout +++ b/tests/reference/asr-loop2-e874469.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {exit: (ExternalSymbol 1 exit 3 exit sys [] exit Public), main_program: (Program (SymbolTable 6 {}) main_program [] []), sys: (Module (SymbolTable 3 {exit: (Subroutine (SymbolTable 4 {error_code: (Variable 4 error_code In () () Default (Integer 4 []) Source Public Required .false.)}) exit [(Var 4 error_code)] [(Stop (Var 4 error_code))] Source Public Implementation () .false. .false.)}) sys [] .false.), test_for: (Subroutine (SymbolTable 5 {i: (Variable 5 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_for [] [(DoLoop ((Var 5 i) (ConstantInteger 0 (Integer 4 [])) (BinOp (ConstantInteger 10 (Integer 4 [])) Sub (ConstantInteger 1 (Integer 4 [])) (Integer 4 []) (ConstantInteger 9 (Integer 4 [])) ()) (ConstantInteger 1 (Integer 4 []))) [(If (Compare (Var 5 i) Eq (ConstantInteger 0 (Integer 4 [])) (Logical 4 []) () ()) [(Cycle)] []) (If (Compare (Var 5 i) Gt (ConstantInteger 5 (Integer 4 [])) (Logical 4 []) () ()) [(Exit)] []) (If (Compare (Var 5 i) Eq (ConstantInteger 3 (Integer 4 [])) (Logical 4 []) () ()) [(Stop ())] [])]) (SubroutineCall 1 exit () [(ConstantInteger 0 (Integer 4 []))] ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {exit: (ExternalSymbol 1 exit 3 exit sys [] exit Public), main_program: (Program (SymbolTable 6 {}) main_program [] []), sys: (Module (SymbolTable 3 {exit: (Subroutine (SymbolTable 4 {error_code: (Variable 4 error_code In () () Default (Integer 4 []) Source Public Required .false.)}) exit [(Var 4 error_code)] [(Stop (Var 4 error_code))] Source Public Implementation () .false. .false.)}) sys [] .false. .false.), test_for: (Subroutine (SymbolTable 5 {i: (Variable 5 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_for [] [(DoLoop ((Var 5 i) (ConstantInteger 0 (Integer 4 [])) (BinOp (ConstantInteger 10 (Integer 4 [])) Sub (ConstantInteger 1 (Integer 4 [])) (Integer 4 []) (ConstantInteger 9 (Integer 4 [])) ()) (ConstantInteger 1 (Integer 4 []))) [(If (Compare (Var 5 i) Eq (ConstantInteger 0 (Integer 4 [])) (Logical 4 []) () ()) [(Cycle)] []) (If (Compare (Var 5 i) Gt (ConstantInteger 5 (Integer 4 [])) (Logical 4 []) () ()) [(Exit)] []) (If (Compare (Var 5 i) Eq (ConstantInteger 3 (Integer 4 [])) (Logical 4 []) () ()) [(Stop ())] [])]) (SubroutineCall 1 exit () [(ConstantInteger 0 (Integer 4 []))] ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin-aa64615.json b/tests/reference/asr-test_builtin-aa64615.json new file mode 100644 index 0000000000..c83af44483 --- /dev/null +++ b/tests/reference/asr-test_builtin-aa64615.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_builtin-aa64615", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_builtin.py", + "infile_hash": "ae35e47ddbc0b804969350668b6eb9dc37be2807d8050451ffb22e9f", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-test_builtin-aa64615.stdout", + "stdout_hash": "699f7bacfe37c1de4ea3f6c7029c84ba01eb3e81d738ea39a1cd1cd8", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-test_builtin-aa64615.stdout b/tests/reference/asr-test_builtin-aa64615.stdout new file mode 100644 index 0000000000..b90e25f433 --- /dev/null +++ b/tests/reference/asr-test_builtin-aa64615.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lfortran_main_program: (Subroutine (SymbolTable 9 {}) _lfortran_main_program [] [(SubroutineCall 1 test_ord () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 8 {}) main_program [] [(SubroutineCall 1 _lfortran_main_program () [] ())]), test_ord: (Subroutine (SymbolTable 2 {i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 2 ord 4 ord lpython_builtin [] ord Public), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_ord [] [(= (Var 2 s) (ConstantString "1" (Character 1 1 () [])) ()) (= (Var 2 i) (FunctionCall 2 ord () [(Var 2 s)] [] (Integer 4 []) () ()) ()) (Assert (Compare (Var 2 i) Eq (ConstantInteger 49 (Integer 4 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_abs-c74d2c9.json b/tests/reference/asr-test_builtin_abs-c74d2c9.json new file mode 100644 index 0000000000..f8d50d9419 --- /dev/null +++ b/tests/reference/asr-test_builtin_abs-c74d2c9.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_builtin_abs-c74d2c9", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_builtin_abs.py", + "infile_hash": "6469a8f5b27cd216944f1dcde21c25cce6aa28435399b0b862cead11", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-test_builtin_abs-c74d2c9.stdout", + "stdout_hash": "7bd2db29560606cab8ff10b4a418637743bc3e8083dead814e8f9c0a", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-test_builtin_abs-c74d2c9.stdout b/tests/reference/asr-test_builtin_abs-c74d2c9.stdout new file mode 100644 index 0000000000..d6c082242c --- /dev/null +++ b/tests/reference/asr-test_builtin_abs-c74d2c9.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lfortran_main_program: (Subroutine (SymbolTable 9 {}) _lfortran_main_program [] [(SubroutineCall 1 test_abs () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 8 {}) main_program [] [(SubroutineCall 1 _lfortran_main_program () [] ())]), test_abs: (Subroutine (SymbolTable 2 {abs: (ExternalSymbol 2 abs 4 abs lpython_builtin [] abs Public), x: (Variable 2 x Local () () Default (Real 8 []) Source Public Required .false.)}) test_abs [] [(= (Var 2 x) (ConstantReal 5.500000 (Real 8 [])) ()) (Assert (Compare (FunctionCall 2 abs () [(Var 2 x)] [] (Real 8 []) () ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) () ()) ()) (= (Var 2 x) (UnaryOp USub (ConstantReal 5.500000 (Real 8 [])) (Real 8 []) (ConstantReal -5.500000 (Real 8 []))) ()) (Assert (Compare (FunctionCall 2 abs () [(Var 2 x)] [] (Real 8 []) () ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/ast-constants1-91cb6ff.json b/tests/reference/ast-constants1-91cb6ff.json index 59c4d37347..15253b852c 100644 --- a/tests/reference/ast-constants1-91cb6ff.json +++ b/tests/reference/ast-constants1-91cb6ff.json @@ -2,11 +2,11 @@ "basename": "ast-constants1-91cb6ff", "cmd": "lpython --show-ast --no-color {infile} -o {outfile}", "infile": "tests/constants1.py", - "infile_hash": "96e60b5d3b6cb09a1198932629c9974ac3cf8854e3b1c7ba8959ea83", + "infile_hash": "6adf0c1cf8ec1667bf19edaf62d087483e6229370ed0f10a207ee0b4", "outfile": null, "outfile_hash": null, "stdout": "ast-constants1-91cb6ff.stdout", - "stdout_hash": "e7906b7058bcb0974b8d5bf25eff5d2841d308688c9689dd4bd7b65b", + "stdout_hash": "3c238eeeb457cbc223572db7626e55d0b8fdff79b1d03393d7734a66", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-constants1-91cb6ff.stdout b/tests/reference/ast-constants1-91cb6ff.stdout index 06b29efc7d..97d6c4bc95 100644 --- a/tests/reference/ast-constants1-91cb6ff.stdout +++ b/tests/reference/ast-constants1-91cb6ff.stdout @@ -1 +1 @@ -(Module [(FunctionDef test_boz ([] [] [] [] [] [] []) [(AnnAssign (Name b Store) (Name str Load) () 1) (Assign [(Name b Store)] (Call (Name bin Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name b Store)] (Call (Name bin Load) [(ConstantInt 64 ())] []) ()) (Assign [(Name b Store)] (Call (Name bin Load) [(UnaryOp USub (ConstantInt 534 ()))] []) ()) (Assign [(Name b Store)] (Call (Name oct Load) [(ConstantInt 8 ())] []) ()) (Assign [(Name b Store)] (Call (Name oct Load) [(ConstantInt 56 ())] []) ()) (Assign [(Name b Store)] (Call (Name oct Load) [(UnaryOp USub (ConstantInt 534 ()))] []) ()) (Assign [(Name b Store)] (Call (Name hex Load) [(ConstantInt 42 ())] []) ()) (Assign [(Name b Store)] (Call (Name hex Load) [(ConstantInt 12648430 ())] []) ()) (Assign [(Name b Store)] (Call (Name hex Load) [(UnaryOp USub (ConstantInt 534 ()))] []) ())] [] () ()) (FunctionDef test_ord_chr ([] [] [] [] [] [] []) [(AnnAssign (Name s Store) (Name str Load) () 1) (AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Call (Name ord Load) [(ConstantStr "5" ())] []) ()) (Assign [(Name s Store)] (Call (Name chr Load) [(ConstantInt 43 ())] []) ())] [] () ()) (FunctionDef test_abs ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Call (Name abs Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name a Store)] (Call (Name abs Load) [(UnaryOp USub (ConstantInt 500 ()))] []) ()) (Assign [(Name a Store)] (Call (Name abs Load) [(ConstantBool .false. ())] []) ()) (Assign [(Name a Store)] (Call (Name abs Load) [(ConstantBool .true. ())] []) ()) (AnnAssign (Name b Store) (Name f32 Load) () 1) (Assign [(Name b Store)] (Call (Name abs Load) [(ConstantFloat 3.450000 ())] []) ()) (Assign [(Name b Store)] (Call (Name abs Load) [(UnaryOp USub (ConstantFloat 5346.340000 ()))] []) ()) (Assign [(Name b Store)] (Call (Name abs Load) [(Call (Name complex Load) [(ConstantFloat 3.450000 ()) (ConstantFloat 5.600000 ())] [])] []) ())] [] () ()) (FunctionDef test_len ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Call (Name len Load) [(ConstantStr "" ())] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(ConstantStr "test" ())] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(ConstantStr "this is a test" ())] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Tuple [(Tuple [(ConstantStr "a" ()) (ConstantStr "b" ()) (ConstantFloat 3.400000 ())] Load) (Tuple [(ConstantStr "c" ()) (ConstantInt 3 ()) (ConstantFloat 5.600000 ())] Load)] Load)] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(List [(List [(UnaryOp USub (ConstantInt 4 ())) (UnaryOp USub (ConstantInt 5 ())) (UnaryOp USub (ConstantInt 6 ()))] Load) (List [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ())) (UnaryOp USub (ConstantInt 3 ()))] Load)] Load)] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())])] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Dict [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] [(ConstantStr "a" ()) (ConstantStr "b" ()) (ConstantStr "c" ())])] []) ())] [] () ()) (FunctionDef test_bool ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name bool Load) () 1) (Assign [(Name a Store)] (Call (Name bool Load) [(ConstantInt 0 ())] []) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(UnaryOp USub (ConstantInt 1 ()))] []) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(ConstantStr "" ())] []) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(Call (Name complex Load) [(ConstantInt 0 ()) (ConstantInt 0 ())] [])] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .false. ())]) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(ConstantStr "t" ())] []) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(ConstantFloat 2.300000 ())] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .true. ())]) ())] [] () ()) (FunctionDef test_str ([] [] [] [] [] [] []) [(AnnAssign (Name s Store) (Name str Load) () 1) (Assign [(Name s Store)] (Call (Name str Load) [] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(UnaryOp USub (ConstantInt 4 ()))] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantFloat 5.600000 ())] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantBool .true. ())] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantBool .false. ())] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantStr "5346" ())] []) ())] [] () ()) (FunctionDef test_callable ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name bool Load) () 1) (AnnAssign (Name b Store) (Name i32 Load) () 1) (Assign [(Name b Store)] (ConstantInt 2 ()) ()) (Assign [(Name a Store)] (Call (Name callable Load) [(Name test_len Load)] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .true. ())]) ()) (Assign [(Name a Store)] (Call (Name callable Load) [(Name b Load)] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .false. ())]) ()) (Assign [(Name a Store)] (Call (Name callable Load) [(ConstantStr "c" ())] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .false. ())]) ())] [] () ()) (FunctionDef test_int ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i64 Load) () 1) (Assign [(Name a Store)] (Call (Name int Load) [] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantFloat 4.560000 ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(UnaryOp USub (ConstantFloat 5.000010 ()))] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantBool .true. ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantBool .false. ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantStr "5346" ())] []) ())] [] () ()) (FunctionDef test_float ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name f64 Load) () 1) (Assign [(Name a Store)] (Call (Name float Load) [] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantFloat 4.560000 ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(UnaryOp USub (ConstantInt 1 ()))] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantBool .true. ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantBool .false. ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantStr "5346" ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantStr "423.534" ())] []) ())] [] () ()) (FunctionDef test_divmod ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 9 ()) (ConstantInt 3 ())] []) ()) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 9 ()) (UnaryOp USub (ConstantInt 3 ()))] []) ()) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 3 ()) (ConstantInt 3 ())] []) ()) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 4 ()) (ConstantInt 5 ())] []) ()) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 0 ()) (ConstantInt 5 ())] []) ())] [] () ())] []) +(Module [(FunctionDef test_boz ([] [] [] [] [] [] []) [(AnnAssign (Name b Store) (Name str Load) () 1) (Assign [(Name b Store)] (Call (Name bin Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name b Store)] (Call (Name bin Load) [(ConstantInt 64 ())] []) ()) (Assign [(Name b Store)] (Call (Name bin Load) [(UnaryOp USub (ConstantInt 534 ()))] []) ()) (Assign [(Name b Store)] (Call (Name oct Load) [(ConstantInt 8 ())] []) ()) (Assign [(Name b Store)] (Call (Name oct Load) [(ConstantInt 56 ())] []) ()) (Assign [(Name b Store)] (Call (Name oct Load) [(UnaryOp USub (ConstantInt 534 ()))] []) ()) (Assign [(Name b Store)] (Call (Name hex Load) [(ConstantInt 42 ())] []) ()) (Assign [(Name b Store)] (Call (Name hex Load) [(ConstantInt 12648430 ())] []) ()) (Assign [(Name b Store)] (Call (Name hex Load) [(UnaryOp USub (ConstantInt 534 ()))] []) ())] [] () ()) (FunctionDef test_ord_chr ([] [] [] [] [] [] []) [(AnnAssign (Name s Store) (Name str Load) () 1) (AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Call (Name ord Load) [(ConstantStr "5" ())] []) ()) (Assign [(Name s Store)] (Call (Name chr Load) [(ConstantInt 43 ())] []) ())] [] () ()) (FunctionDef test_abs ([] [] [] [] [] [] []) [(AnnAssign (Name b Store) (Name f32 Load) () 1) (Assign [(Name b Store)] (Call (Name abs Load) [(ConstantFloat 3.450000 ())] []) ()) (Assign [(Name b Store)] (Call (Name abs Load) [(UnaryOp USub (ConstantFloat 5346.340000 ()))] []) ())] [] () ()) (FunctionDef test_len ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Call (Name len Load) [(ConstantStr "" ())] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(ConstantStr "test" ())] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(ConstantStr "this is a test" ())] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Tuple [(Tuple [(ConstantStr "a" ()) (ConstantStr "b" ()) (ConstantFloat 3.400000 ())] Load) (Tuple [(ConstantStr "c" ()) (ConstantInt 3 ()) (ConstantFloat 5.600000 ())] Load)] Load)] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load)] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(List [(List [(UnaryOp USub (ConstantInt 4 ())) (UnaryOp USub (ConstantInt 5 ())) (UnaryOp USub (ConstantInt 6 ()))] Load) (List [(UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 2 ())) (UnaryOp USub (ConstantInt 3 ()))] Load)] Load)] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())])] []) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Dict [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] [(ConstantStr "a" ()) (ConstantStr "b" ()) (ConstantStr "c" ())])] []) ())] [] () ()) (FunctionDef test_bool ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name bool Load) () 1) (Assign [(Name a Store)] (Call (Name bool Load) [(ConstantInt 0 ())] []) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(UnaryOp USub (ConstantInt 1 ()))] []) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(ConstantStr "" ())] []) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(Call (Name complex Load) [(ConstantInt 0 ()) (ConstantInt 0 ())] [])] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .false. ())]) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(ConstantStr "t" ())] []) ()) (Assign [(Name a Store)] (Call (Name bool Load) [(ConstantFloat 2.300000 ())] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .true. ())]) ())] [] () ()) (FunctionDef test_str ([] [] [] [] [] [] []) [(AnnAssign (Name s Store) (Name str Load) () 1) (Assign [(Name s Store)] (Call (Name str Load) [] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(UnaryOp USub (ConstantInt 4 ()))] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantFloat 5.600000 ())] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantBool .true. ())] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantBool .false. ())] []) ()) (Assign [(Name s Store)] (Call (Name str Load) [(ConstantStr "5346" ())] []) ())] [] () ()) (FunctionDef test_callable ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name bool Load) () 1) (AnnAssign (Name b Store) (Name i32 Load) () 1) (Assign [(Name b Store)] (ConstantInt 2 ()) ()) (Assign [(Name a Store)] (Call (Name callable Load) [(Name test_len Load)] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .true. ())]) ()) (Assign [(Name a Store)] (Call (Name callable Load) [(Name b Load)] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .false. ())]) ()) (Assign [(Name a Store)] (Call (Name callable Load) [(ConstantStr "c" ())] []) ()) (Assert (Compare (Name a Load) Eq [(ConstantBool .false. ())]) ())] [] () ()) (FunctionDef test_int ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i64 Load) () 1) (Assign [(Name a Store)] (Call (Name int Load) [] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantFloat 4.560000 ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(UnaryOp USub (ConstantFloat 5.000010 ()))] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantBool .true. ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantBool .false. ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantStr "5346" ())] []) ())] [] () ()) (FunctionDef test_float ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name f64 Load) () 1) (Assign [(Name a Store)] (Call (Name float Load) [] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantFloat 4.560000 ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(UnaryOp USub (ConstantInt 1 ()))] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantBool .true. ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantBool .false. ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantStr "5346" ())] []) ()) (Assign [(Name a Store)] (Call (Name float Load) [(ConstantStr "423.534" ())] []) ())] [] () ()) (FunctionDef test_divmod ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 9 ()) (ConstantInt 3 ())] []) ()) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 9 ()) (UnaryOp USub (ConstantInt 3 ()))] []) ()) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 3 ()) (ConstantInt 3 ())] []) ()) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 4 ()) (ConstantInt 5 ())] []) ()) (Assign [(Name a Store)] (Call (Name divmod Load) [(ConstantInt 0 ()) (ConstantInt 5 ())] []) ())] [] () ())] []) diff --git a/tests/tests.toml b/tests/tests.toml index b30c5a37c1..189d0fbbd2 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -160,3 +160,11 @@ asr = true filename = "global_scope1.py" ast = true asr = true + +[[test]] +filename = "../integration_tests/test_builtin.py" +asr = true + +[[test]] +filename = "../integration_tests/test_builtin_abs.py" +asr = true