diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8fdfbcd48f..6a01adec30 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -33,12 +33,12 @@ jobs: - name: Install Windows Conda Packages if: contains(matrix.os, 'windows') shell: bash -l {0} - run: conda install m2-bison=3.0.4 ninja + run: conda install m2-bison=3.0.4 ninja rapidjson - 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 rapidjson - name: Conda info shell: bash -l {0} diff --git a/.gitignore b/.gitignore index cdaecbbc30..396963781e 100644 --- a/.gitignore +++ b/.gitignore @@ -56,6 +56,7 @@ lpython/asr/asr.py src/lpython/ast.h src/lpython/asr.h src/libasr/asr.h +src/libasr/wasm_visitor.h src/libasr/config.h share/jupyter/kernels/fortran/kernel.json src/runtime/*.o.empty.c @@ -63,6 +64,9 @@ python_ast.py python_ast.h ser.txt integration_tests/py_* +integration_tests/b1/* +integration_tests/b2/* +integration_tests/b3/* ### https://raw.github.com/github/gitignore/218a941be92679ce67d0484547e3e142b2f5f6f0/Global/macOS.gitignore @@ -156,8 +160,41 @@ build.ninja .ninja_log /compile_commands.json -##Parser +##Parser src/lpython/parser/parser.output src/lpython/parser/parser.tab.cc src/lpython/parser/parser.tab.hh +*.py[0-9A-Za-z]* + +##Generated files in integration_tests +integration_tests/test_c_interop_01.c +integration_tests/test_c_interop_01 +integration_tests/test_c_interop_03 +integration_tests/test_c_interop_03.c +integration_tests/test_c_interop_04 +integration_tests/test_c_interop_04.c +integration_tests/test_c_interop_05 +integration_tests/test_c_interop_05.c +integration_tests/bindc_01 +integration_tests/bindc_01.c +integration_tests/bindc_02 +integration_tests/bindc_02.c +integration_tests/bindc_03 +integration_tests/bindc_04 +integration_tests/structs_01 +integration_tests/structs_01.c +integration_tests/structs_02 +integration_tests/structs_02.c +integration_tests/structs_03 +integration_tests/structs_03.c +integration_tests/structs_05 +integration_tests/structs_05.c +integration_tests/expr_08 +integration_tests/expr_08.c +integration_tests/array_01_decl +integration_tests/array_01_decl.c +integration_tests/array_02_decl +integration_tests/array_02_decl.c +integration_tests/expr_12 +integration_tests/expr_12.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 1aed07cbac..b498c8ac79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,10 +167,12 @@ if (WITH_XEUS) PATTERN "*.in" EXCLUDE) endif() -# JSON +# JSON OR LSP (`conda install rapidjson`) set(WITH_JSON no CACHE BOOL "Build with JSON support") -if (WITH_JSON) +set(WITH_LSP no CACHE BOOL "Build with LSP support") +if (WITH_JSON OR WITH_LSP) find_package(RapidJSON REQUIRED) + set(HAVE_LFORTRAN_RAPIDJSON yes) endif() set(HAVE_LFORTRAN_DEMANGLE yes @@ -262,6 +264,7 @@ message("HAVE_LFORTRAN_DEMANGLE: ${HAVE_LFORTRAN_DEMANGLE}") message("WITH_LLVM: ${WITH_LLVM}") message("WITH_XEUS: ${WITH_XEUS}") message("WITH_JSON: ${WITH_JSON}") +message("WITH_LSP: ${WITH_LSP}") message("WITH_FMT: ${WITH_FMT}") message("WITH_LFORTRAN_BINARY_MODFILES: ${WITH_LFORTRAN_BINARY_MODFILES}") message("WITH_RUNTIME_LIBRARY: ${WITH_RUNTIME_LIBRARY}") diff --git a/README.md b/README.md index fbee2486cc..949dc190c1 100644 --- a/README.md +++ b/README.md @@ -73,12 +73,22 @@ ctest ./run_tests.py ``` -Also, run the integration tests: +Run integration tests: ```bash -./integration_tests/run_tests.py +cd integration_tests +./run_tests.sh ``` +### Speed up Integration Test on Macs + +Integration tests run slowly because Apple checks the hash of each +executable online before running. You can turn off that feature +in the Privacy tab of the Security and Privacy item of System +Preferences, Developer Tools, Terminal.app, "allow the apps below +to run software locally that does not meet the system's security +policy." + ## Examples You can run the following examples by hand in a terminal: @@ -90,6 +100,7 @@ You can run the following examples by hand in a terminal: ./src/bin/lpython --show-asr examples/expr2.py ./src/bin/lpython --show-cpp examples/expr2.py ./src/bin/lpython --show-llvm examples/expr2.py +./src/bin/lpython --show-c examples/expr2.py ``` ## Contributing diff --git a/build0.sh b/build0.sh index 5ab42db79a..6040e11f03 100755 --- a/build0.sh +++ b/build0.sh @@ -12,6 +12,8 @@ python grammar/asdl_py.py python grammar/asdl_cpp.py grammar/Python.asdl src/lpython/python_ast.h # Generate a Fortran ASR from ASR.asdl (C++) python grammar/asdl_cpp.py src/libasr/ASR.asdl src/libasr/asr.h +# Generate a wasm_visitor.h from src/libasr/wasm_instructions.txt (C++) +python src/libasr/wasm_instructions_visitor.py # Generate the tokenizer and parser (cd src/lpython/parser && re2c -W -b tokenizer.re -o tokenizer.cpp) diff --git a/build1.sh b/build1.sh index 7dd7b8325d..376783d79b 100755 --- a/build1.sh +++ b/build1.sh @@ -8,6 +8,7 @@ cmake \ -DWITH_LLVM=yes \ -DLPYTHON_BUILD_ALL=yes \ -DWITH_STACKTRACE=yes \ + -DWITH_LSP=no \ -DWITH_LFORTRAN_BINARY_MODFILES=no \ -DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH_LPYTHON;$CONDA_PREFIX" \ -DCMAKE_INSTALL_PREFIX=`pwd`/inst \ diff --git a/ci/build.xsh b/ci/build.xsh index 5f8f6469bb..86d9f4223f 100755 --- a/ci/build.xsh +++ b/ci/build.xsh @@ -32,6 +32,8 @@ python grammar/asdl_cpp.py src/libasr/ASR.asdl src/libasr/asr.h python grammar/asdl_cpp.py grammar/Python.asdl src/lpython/python_ast.h # Generate a Python AST from Python.asdl (Python) python grammar/asdl_py.py +# Generate a wasm_visitor.h from src/libasr/wasm_instructions.txt (C++) +python src/libasr/wasm_instructions_visitor.py # Generate the tokenizer and parser pushd src/lpython/parser && re2c -W -b tokenizer.re -o tokenizer.cpp && popd @@ -49,11 +51,11 @@ cd test-bld # compiled in Release mode and we get link failures if we mix and match build # modes: BUILD_TYPE = "Release" -cmake -G $LFORTRAN_CMAKE_GENERATOR -DCMAKE_VERBOSE_MAKEFILE=ON -DWITH_LLVM=yes -DWITH_XEUS=yes -DCMAKE_PREFIX_PATH=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DWITH_LFORTRAN_BINARY_MODFILES=no -DCMAKE_BUILD_TYPE=@(BUILD_TYPE) .. -cmake --build . --target install +cmake -G $LFORTRAN_CMAKE_GENERATOR -DCMAKE_VERBOSE_MAKEFILE=ON -DWITH_LLVM=yes -DWITH_LSP=yes -DWITH_XEUS=yes -DCMAKE_PREFIX_PATH=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DWITH_LFORTRAN_BINARY_MODFILES=no -DCMAKE_BUILD_TYPE=@(BUILD_TYPE) .. +cmake --build . --target install -j16 ./src/lpython/tests/test_lpython #./src/bin/lpython < ../src/bin/example_input.txt -ctest --output-on-failure +ctest --output-on-failure -j16 cpack -V cd ../.. diff --git a/ci/test.xsh b/ci/test.xsh index 790318a3f7..7648396076 100644 --- a/ci/test.xsh +++ b/ci/test.xsh @@ -17,4 +17,5 @@ src/bin/lpython --show-cpp tests/doconcurrentloop_01.py if $WIN != "1": python run_tests.py - python integration_tests/run_tests.py + cd integration_tests + ./run_tests.sh -j16 diff --git a/grammar/Python.asdl b/grammar/Python.asdl index b0720ded01..a5ca1c672e 100644 --- a/grammar/Python.asdl +++ b/grammar/Python.asdl @@ -83,6 +83,9 @@ module LPython | ConstantBool(bool value, string? kind) | ConstantFloat(float value, string? kind) | ConstantComplex(float re, float im, string? kind) + | ConstantEllipsis(string? kind) + | ConstantNone(string? kind) + | ConstantBytes(string value, string? kind) -- the following expression can appear in assignment context | Attribute(expr value, identifier attr, expr_context ctx) diff --git a/grammar/asdl_cpp.py b/grammar/asdl_cpp.py index 5ca9175d67..fb2eae6d18 100644 --- a/grammar/asdl_cpp.py +++ b/grammar/asdl_cpp.py @@ -432,7 +432,7 @@ def visitModule(self, mod): self.emit( "void inc_lindent() {", 1) self.emit( "indent_level++;", 2) self.emit( 'indtd += "| ";', 2) - self.emit( "}", 1) + self.emit( "}", 1) self.emit( "void dec_indent() {", 1) self.emit( "indent_level--;", 2) self.emit( "LFORTRAN_ASSERT(indent_level >= 0);", 2) @@ -535,9 +535,9 @@ def visitField(self, field, cons, last): self.emit("self().visit_%s(*x.m_%s[i]);" % (field.type, field.name), level+1) else: self.emit("self().visit_%s(x.m_%s[i]);" % (field.type, field.name), level+1) - self.emit( 'dec_indent();', level+1) + self.emit( 'dec_indent();', level+1) self.emit("}", level) - elif field.opt: + elif field.opt: self.emit('s.append("\\n" + indtd + "%s" + "%s=");' % (arr, field.name), 2) if last: self.emit('last = true;', 2) @@ -562,7 +562,7 @@ def visitField(self, field, cons, last): self.emit('s.append("\\n" + indtd + "%s" + "%s=");' % (arr, field.name), level) self.emit("for (size_t i=0; im_" + field.name, ) return arguments +class ExprBaseReplacerVisitor(ASDLVisitor): + + def __init__(self, stream, data): + self.replace_expr = [] + self.is_expr = False + self.is_product = False + super(ExprBaseReplacerVisitor, self).__init__(stream, data) + + def visitModule(self, mod): + self.emit("/" + "*"*78 + "/") + self.emit("// Expression Replacer Base class") + self.emit("") + self.emit("template ") + self.emit("class BaseExprReplacer {") + self.emit("public:") + self.emit(" Derived& self() { return static_cast(*this); }") + self.emit("") + self.emit(" ASR::expr_t** current_expr;") + self.emit(" ASR::expr_t** current_expr_copy;") + self.emit("") + self.emit(" BaseExprReplacer() : current_expr(nullptr) {}") + self.emit("") + + self.replace_expr.append((" void replace_expr(ASR::expr_t* x) {", 0)) + self.replace_expr.append((" if( !x ) {", 1)) + self.replace_expr.append((" return ;", 2)) + self.replace_expr.append((" }", 1)) + self.replace_expr.append(("", 0)) + self.replace_expr.append((" switch(x->type) {", 1)) + + super(ExprBaseReplacerVisitor, self).visitModule(mod) + + self.replace_expr.append((" default: {", 2)) + self.replace_expr.append((' LFORTRAN_ASSERT_MSG(false, "Duplication of " + std::to_string(x->type) + " expression is not supported yet.");', 3)) + self.replace_expr.append((" }", 2)) + self.replace_expr.append((" }", 1)) + self.replace_expr.append(("", 0)) + self.replace_expr.append((" }", 0)) + for line, level in self.replace_expr: + self.emit(line, level=level) + self.emit("") + self.emit("};") + + def visitType(self, tp): + if not (isinstance(tp.value, asdl.Sum) and + is_simple_sum(tp.value)): + super(ExprBaseReplacerVisitor, self).visitType(tp, tp.name) + + def visitSum(self, sum, *args): + self.is_expr = args[0] == 'expr' + if self.is_expr: + for tp in sum.types: + self.visit(tp, *args) + + def visitProduct(self, prod, name): + pass + + def visitConstructor(self, cons, _): + self.make_visitor(cons.name, cons.fields) + + def make_visitor(self, name, fields): + self.emit("") + self.emit("void replace_%s(%s_t* x) {" % (name, name), 1) + self.used = False + for field in fields: + self.visitField(field) + if not self.used: + self.emit("if (x) { }", 2) + + if self.is_expr: + self.replace_expr.append((" case ASR::exprType::%s: {" % name, 2)) + self.replace_expr.append((" self().replace_%s(down_cast(x));" % (name, name), 3)) + self.replace_expr.append((" break;", 3)) + self.replace_expr.append((" }", 2)) + self.emit("}", 1) + self.emit("") + + def visitField(self, field): + arguments = None + if field.type == "expr" or field.type == "symbol" or field.type == "call_arg": + level = 2 + if field.seq: + self.used = True + self.emit("for (size_t i = 0; i < x->n_%s; i++) {" % field.name, level) + if field.type == "call_arg": + self.emit(" current_expr_copy = current_expr;", level) + self.emit(" current_expr = &(x->m_%s[i].m_value);" % (field.name), level) + self.emit(" self().replace_expr(x->m_%s[i].m_value);"%(field.name), level) + self.emit(" current_expr = current_expr_copy;", level) + self.emit("}", level) + else: + if field.type != "symbol": + self.used = True + self.emit("current_expr_copy = current_expr;", level) + self.emit("current_expr = &(x->m_%s);" % (field.name), level) + self.emit("self().replace_%s(x->m_%s);" % (field.type, field.name), level) + self.emit("current_expr = current_expr_copy;", level) + +class StmtBaseReplacerVisitor(ASDLVisitor): + + def __init__(self, stream, data): + self.replace_stmt = [] + self.is_stmt = False + self.is_product = False + super(StmtBaseReplacerVisitor, self).__init__(stream, data) + def visitModule(self, mod): + self.emit("/" + "*"*78 + "/") + self.emit("// Statement Replacer Base class") + self.emit("") + self.emit("template ") + self.emit("class BaseStmtReplacer {") + self.emit("public:") + self.emit(" Derived& self() { return static_cast(*this); }") + self.emit("") + self.emit(" ASR::stmt_t** current_stmt;") + self.emit(" ASR::stmt_t** current_stmt_copy;") + self.emit(" bool has_replacement_happened;") + self.emit("") + self.emit(" BaseStmtReplacer() : current_stmt(nullptr), has_replacement_happened(false) {}") + self.emit("") + + self.replace_stmt.append((" void replace_stmt(ASR::stmt_t* x) {", 0)) + self.replace_stmt.append((" if( !x ) {", 1)) + self.replace_stmt.append((" return ;", 2)) + self.replace_stmt.append((" }", 1)) + self.replace_stmt.append(("", 0)) + self.replace_stmt.append((" switch(x->type) {", 1)) + + super(StmtBaseReplacerVisitor, self).visitModule(mod) + + self.replace_stmt.append((" default: {", 2)) + self.replace_stmt.append((' LFORTRAN_ASSERT_MSG(false, "Replacement of " + std::to_string(x->type) + " statement is not supported yet.");', 3)) + self.replace_stmt.append((" }", 2)) + self.replace_stmt.append((" }", 1)) + self.replace_stmt.append(("", 0)) + self.replace_stmt.append((" }", 0)) + for line, level in self.replace_stmt: + self.emit(line, level=level) + self.emit("") + self.emit("};") + + def visitType(self, tp): + if not (isinstance(tp.value, asdl.Sum) and + is_simple_sum(tp.value)): + super(StmtBaseReplacerVisitor, self).visitType(tp, tp.name) + + def visitSum(self, sum, *args): + self.is_stmt = args[0] == 'stmt' + if self.is_stmt: + for tp in sum.types: + self.visit(tp, *args) + + def visitProduct(self, prod, name): + pass + + def visitConstructor(self, cons, _): + self.make_visitor(cons.name, cons.fields) + + def make_visitor(self, name, fields): + self.emit("") + self.emit("void replace_%s(%s_t* x) {" % (name, name), 1) + self.used = False + for field in fields: + self.visitField(field) + if not self.used: + self.emit("if (x) { }", 2) + + if self.is_stmt: + self.replace_stmt.append((" case ASR::stmtType::%s: {" % name, 2)) + self.replace_stmt.append((" self().replace_%s(down_cast(x));" % (name, name), 3)) + self.replace_stmt.append((" break;", 3)) + self.replace_stmt.append((" }", 2)) + self.emit("}", 1) + self.emit("") + + def visitField(self, field): + arguments = None + if field.type == "stmt": + level = 2 + if field.seq: + self.used = True + self.emit("for (size_t i = 0; i < x->n_%s; i++) {" % field.name, level) + self.emit(" current_stmt_copy = current_stmt;", level) + self.emit(" current_stmt = &(x->m_%s[i]);" % (field.name), level) + self.emit(" self().replace_stmt(x->m_%s[i]);"%(field.name), level) + self.emit(" current_stmt = current_stmt_copy;", level) + self.emit("}", level) class PickleVisitorVisitor(ASDLVisitor): @@ -1081,7 +1268,7 @@ def visitField(self, field, cons): else: self.emit('s.append(std::to_string(x.m_%s));' % field.name, 2) elif field.type == "float" and not field.seq and not field.opt: - self.emit('s.append(std::to_string(x.m_%s));' % field.name, 2) + self.emit('s.append(double_to_scientific(x.m_%s));' % field.name, 2) elif field.type == "bool" and not field.seq and not field.opt: self.emit("if (x.m_%s) {" % field.name, 2) self.emit( 's.append(".true.");', 3) @@ -1576,6 +1763,142 @@ def visitConstructor(self, cons, _): self.emit( 'return %s::make_%s_t(%s);' % (subs["MOD"], name, ", ".join(args)), 2) self.emit("}", 1) +class ExprTypeVisitor(ASDLVisitor): + + def __init__(self, stream, data): + self.replace_expr = [] + self.is_expr = False + self.is_product = False + super(ExprTypeVisitor, self).__init__(stream, data) + + def emit(self, line, level=0, new_line=True): + indent = " "*level + self.stream.write(indent + line) + if new_line: + self.stream.write("\n") + + def visitModule(self, mod): + self.emit("/" + "*"*78 + "/") + self.emit("// Expression Type (`expr_type`) visitor") + self.emit("""\ +static inline ASR::ttype_t* expr_type0(const ASR::expr_t *f) +{ + LFORTRAN_ASSERT(f != nullptr); + switch (f->type) {""") + + super(ExprTypeVisitor, self).visitModule(mod) + + self.emit(""" default : throw LFortranException("Not implemented"); + } +} +""") + + def visitType(self, tp): + if not (isinstance(tp.value, asdl.Sum) and + is_simple_sum(tp.value)): + super(ExprTypeVisitor, self).visitType(tp, tp.name) + + def visitSum(self, sum, *args): + self.is_expr = args[0] == 'expr' + if self.is_expr: + for tp in sum.types: + self.visit(tp, *args) + + def visitProduct(self, prod, name): + pass + + def visitConstructor(self, cons, _): + self.make_visitor(cons.name, cons.fields) + + def make_visitor(self, name, fields): + if name == "Var": + self.emit("""case ASR::exprType::%s: { + ASR::symbol_t *s = ((ASR::%s_t*)f)->m_v; + if (s->type == ASR::symbolType::ExternalSymbol) { + ASR::ExternalSymbol_t *e = ASR::down_cast(s); + LFORTRAN_ASSERT(!ASR::is_a(*e->m_external)); + s = e->m_external; + } + return ASR::down_cast(s)->m_type; + }""" \ + % (name, name), 2, new_line=False) + else: + self.emit("case ASR::exprType::%s: { return ((ASR::%s_t*)f)->m_type; }"\ + % (name, name), 2, new_line=False) + self.emit("") + + def visitField(self, field): + pass + +class ExprValueVisitor(ASDLVisitor): + + def __init__(self, stream, data): + self.replace_expr = [] + self.is_expr = False + self.is_product = False + super(ExprValueVisitor, self).__init__(stream, data) + + def emit(self, line, level=0, new_line=True): + indent = " "*level + self.stream.write(indent + line) + if new_line: + self.stream.write("\n") + + def visitModule(self, mod): + self.emit("/" + "*"*78 + "/") + self.emit("// Expression Value (`expr_value`) visitor") + self.emit("""\ +static inline ASR::expr_t* expr_value0(ASR::expr_t *f) +{ + LFORTRAN_ASSERT(f != nullptr); + switch (f->type) {""") + + super(ExprValueVisitor, self).visitModule(mod) + + self.emit(""" default : throw LFortranException("Not implemented"); + } +} +""") + + def visitType(self, tp): + if not (isinstance(tp.value, asdl.Sum) and + is_simple_sum(tp.value)): + super(ExprValueVisitor, self).visitType(tp, tp.name) + + def visitSum(self, sum, *args): + self.is_expr = args[0] == 'expr' + if self.is_expr: + for tp in sum.types: + self.visit(tp, *args) + + def visitProduct(self, prod, name): + pass + + def visitConstructor(self, cons, _): + self.make_visitor(cons.name, cons.fields) + + def make_visitor(self, name, fields): + if name == "Var": + self.emit("""case ASR::exprType::%s: { + ASR::symbol_t *s = ((ASR::%s_t*)f)->m_v; + if (s->type == ASR::symbolType::ExternalSymbol) { + ASR::ExternalSymbol_t *e = ASR::down_cast(s); + LFORTRAN_ASSERT(!ASR::is_a(*e->m_external)); + s = e->m_external; + } + return ASR::down_cast(s)->m_value; + }""" \ + % (name, name), 2, new_line=False) + elif name.endswith("Constant") or name == "IntegerBOZ": + self.emit("case ASR::exprType::%s: { return f; }"\ + % (name), 2, new_line=False) + else: + self.emit("case ASR::exprType::%s: { return ((ASR::%s_t*)f)->m_value; }"\ + % (name, name), 2, new_line=False) + self.emit("") + + def visitField(self, field): + pass class ASDLData(object): @@ -1732,6 +2055,14 @@ def main(argv): if is_asr: ExprStmtDuplicatorVisitor(fp, data).visit(mod) fp.write("\n\n") + ExprBaseReplacerVisitor(fp, data).visit(mod) + fp.write("\n\n") + StmtBaseReplacerVisitor(fp, data).visit(mod) + fp.write("\n\n") + ExprTypeVisitor(fp, data).visit(mod) + fp.write("\n\n") + ExprValueVisitor(fp, data).visit(mod) + fp.write("\n\n") fp.write(FOOT % subs) finally: fp.close() diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt new file mode 100644 index 0000000000..eaeacce79f --- /dev/null +++ b/integration_tests/CMakeLists.txt @@ -0,0 +1,199 @@ +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) + +project(lpython_tests C) + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug + CACHE STRING "Build type (Debug, Release)" FORCE) +endif () +if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR + CMAKE_BUILD_TYPE STREQUAL "Release")) + message("${CMAKE_BUILD_TYPE}") + message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of: Debug, Release (current value: '${CMAKE_BUILD_TYPE}')") +endif () + +set(KIND no CACHE STRING "Type of Test") + +find_path(LPYTHON_RTLIB_DIR lfortran_intrinsics.h + ${CMAKE_SOURCE_DIR}/../src/runtime/impure) +find_library(LPYTHON_RTLIB_LIBRARY lpython_runtime_static + ${CMAKE_SOURCE_DIR}/../src/runtime/) +add_library(lpython_rtlib INTERFACE IMPORTED) +set_property(TARGET lpython_rtlib PROPERTY INTERFACE_INCLUDE_DIRECTORIES + ${LPYTHON_RTLIB_DIR}) +set_property(TARGET lpython_rtlib PROPERTY INTERFACE_LINK_LIBRARIES + ${LPYTHON_RTLIB_LIBRARY}) +target_link_libraries(lpython_rtlib INTERFACE m) + +enable_testing() + +message("\n") +message("Configuration results") +message("---------------------") +message("C compiler : ${CMAKE_C_COMPILER}") +message("Build type: ${CMAKE_BUILD_TYPE}") +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + message("C compiler flags : ${CMAKE_C_FLAGS_DEBUG}") +else () + message("C compiler flags : ${CMAKE_C_FLAGS_RELEASE}") +endif () +message("Installation prefix: ${CMAKE_INSTALL_PREFIX}") +message("KIND: ${KIND}") +message("LPYTHON_RTLIB_DIR: ${LPYTHON_RTLIB_DIR}") +message("LPYTHON_RTLIB_LIBRARY: ${LPYTHON_RTLIB_LIBRARY}") + + + +macro(RUN) + set(options FAIL) + set(oneValueArgs NAME) + set(multiValueArgs LABELS EXTRAFILES) + cmake_parse_arguments(RUN "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN} ) + set(name ${RUN_NAME}) + if (NOT name) + message(FATAL_ERROR "Must specify the NAME argument") + endif() + + if (${KIND} IN_LIST RUN_LABELS) + if (KIND STREQUAL "llvm") + add_custom_command( + OUTPUT ${name}.o + COMMAND lpython -c ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py -o ${name}.o + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py + VERBATIM) + add_executable(${name} ${name}.o ${RUN_EXTRAFILES}) + set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C) + target_link_libraries(${name} lpython_rtlib) + add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name}) + if (RUN_LABELS) + set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}") + endif() + if (${RUN_FAIL}) + set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE) + endif() + elseif(KIND STREQUAL "c") + add_custom_command( + OUTPUT ${name}.c + COMMAND lpython --show-c ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py > ${name}.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py + VERBATIM) + add_executable(${name} ${name}.c ${RUN_EXTRAFILES}) + set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C) + target_link_libraries(${name} lpython_rtlib) + add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name}) + if (RUN_LABELS) + set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}") + endif() + if (${RUN_FAIL}) + set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE) + endif() + elseif(KIND STREQUAL "cpython") + # CPython test + if (RUN_EXTRAFILES) + set(PY_MOD "${name}_mod") + add_library(${PY_MOD} SHARED ${RUN_EXTRAFILES}) + set_target_properties(${PY_MOD} PROPERTIES LINKER_LANGUAGE C) + else() + set(PY_MOD "") + endif() + + add_test(${name} python ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py) + set_tests_properties(${name} PROPERTIES + ENVIRONMENT "PYTHONPATH=${CMAKE_SOURCE_DIR}/../src/runtime/ltypes;LPYTHON_PY_MOD_NAME=${PY_MOD};LPYTHON_PY_MOD_PATH=${CMAKE_CURRENT_BINARY_DIR}") + if (RUN_LABELS) + set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}") + endif() + if (${RUN_FAIL}) + set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE) + endif() + endif() + endif() +endmacro(RUN) + + +# Test zero and non-zero exit code and assert statements +RUN(NAME array_01_decl LABELS cpython llvm c) +RUN(NAME array_02_decl LABELS cpython llvm c) +RUN(NAME bindc_01 LABELS llvm c) +RUN(NAME bindc_02 LABELS llvm c) +RUN(NAME bindc_04 LABELS llvm) +RUN(NAME exit_01 LABELS cpython llvm c) +RUN(NAME exit_02 FAIL LABELS cpython llvm c) +RUN(NAME exit_01b LABELS cpython llvm c) +RUN(NAME exit_02b FAIL LABELS cpython llvm c) +RUN(NAME exit_02c FAIL LABELS cpython llvm c) + +# Test all three backends +RUN(NAME print_01 LABELS cpython llvm c) + +# CPython and LLVM +RUN(NAME expr_01 LABELS cpython llvm c) +RUN(NAME expr_02 LABELS cpython llvm c) +RUN(NAME expr_03 LABELS cpython llvm c) +RUN(NAME expr_04 LABELS cpython llvm c) +RUN(NAME expr_05 LABELS cpython llvm) +RUN(NAME expr_06 LABELS cpython llvm) +RUN(NAME expr_07 LABELS cpython llvm) +RUN(NAME expr_08 LABELS llvm c) +RUN(NAME expr_09 LABELS cpython llvm) +RUN(NAME expr_10 LABELS cpython llvm) +RUN(NAME expr_11 LABELS cpython llvm c) +RUN(NAME expr_12 LABELS llvm c) +RUN(NAME test_types_01 LABELS cpython llvm) +RUN(NAME test_str_01 LABELS cpython llvm) +RUN(NAME test_str_02 LABELS cpython llvm) +RUN(NAME test_str_03 LABELS cpython llvm c) +RUN(NAME test_list_01 LABELS cpython llvm) +RUN(NAME modules_01 LABELS cpython llvm) +RUN(NAME test_math LABELS cpython llvm) +RUN(NAME test_numpy_01 LABELS cpython llvm) +RUN(NAME test_numpy_02 LABELS cpython llvm) +RUN(NAME test_random LABELS cpython llvm) +RUN(NAME test_os LABELS cpython llvm) +RUN(NAME test_builtin LABELS cpython llvm) +RUN(NAME test_builtin_abs LABELS cpython llvm) +RUN(NAME test_builtin_bool LABELS cpython llvm) +RUN(NAME test_builtin_pow LABELS cpython llvm) +RUN(NAME test_builtin_int LABELS cpython llvm) +RUN(NAME test_builtin_len LABELS cpython llvm) +RUN(NAME test_builtin_str LABELS cpython llvm) +RUN(NAME test_builtin_float LABELS cpython llvm) +RUN(NAME test_builtin_str_02 LABELS cpython llvm) +RUN(NAME test_builtin_round LABELS cpython llvm) +RUN(NAME test_math1 LABELS cpython llvm) +RUN(NAME test_math_02 LABELS cpython llvm) +RUN(NAME test_c_interop_01 LABELS cpython llvm c) +RUN(NAME test_c_interop_02 LABELS cpython llvm c + EXTRAFILES test_c_interop_02b.c) +RUN(NAME test_c_interop_03 LABELS cpython llvm c + EXTRAFILES test_c_interop_03b.c) +RUN(NAME test_c_interop_04 LABELS cpython llvm c + EXTRAFILES test_c_interop_04b.c) +RUN(NAME test_c_interop_05 LABELS llvm c + EXTRAFILES test_c_interop_05b.c) +RUN(NAME bindc_03 LABELS llvm + EXTRAFILES bindc_03b.c) +RUN(NAME test_generics_01 LABELS cpython llvm) +RUN(NAME test_cmath LABELS cpython llvm) +RUN(NAME test_complex LABELS cpython llvm) +RUN(NAME test_max_min LABELS cpython llvm) +RUN(NAME test_integer_bitnot LABELS cpython llvm) +RUN(NAME test_unary_minus LABELS cpython llvm) +RUN(NAME test_unary_plus LABELS cpython llvm) +RUN(NAME test_bool_binop LABELS cpython llvm) +RUN(NAME test_issue_518 LABELS cpython llvm) +RUN(NAME structs_01 LABELS cpython llvm c) +RUN(NAME structs_02 LABELS llvm c) +RUN(NAME structs_03 LABELS llvm c) +RUN(NAME structs_04 LABELS cpython llvm c) +RUN(NAME structs_05 LABELS llvm c) +RUN(NAME test_str_to_int LABELS cpython llvm) +RUN(NAME test_platform LABELS cpython llvm) +RUN(NAME test_vars_01 LABELS cpython llvm) +RUN(NAME test_version LABELS cpython llvm) +RUN(NAME vec_01 LABELS cpython llvm) +RUN(NAME test_str_comparison LABELS cpython llvm) + +# Just CPython +RUN(NAME test_builtin_bin LABELS cpython) diff --git a/integration_tests/array_01_decl.py b/integration_tests/array_01_decl.py new file mode 100644 index 0000000000..66838dd311 --- /dev/null +++ b/integration_tests/array_01_decl.py @@ -0,0 +1,32 @@ +from ltypes import i32, i64, f32, f64, c32, c64 +from numpy import empty + +def accept_i32_array(xi32: i32[:]) -> i32: + xi32[0] = 32 + return xi32[0] + +def accept_i64_array(xi64: i64[:]) -> i64: + xi64[0] = 64 + return xi64[0] + +def accept_f32_array(xf32: f32[:]) -> f32: + xf32[0] = 32.0 + return xf32[0] + +def accept_f64_array(xf64: f64[:]) -> f64: + xf64[0] = 64.0 + return xf64[0] + +def declare_arrays(): + ai32: i32[3] = empty(3) + ai64: i64[10] = empty(10) + af32: f32[3] = empty(3) + af64: f64[10] = empty(10) + ac32: c32[3] = empty(3) + ac64: c64[10] = empty(10) + print(accept_i32_array(ai32)) + print(accept_i64_array(ai64)) + print(accept_f32_array(af32)) + print(accept_f64_array(af64)) + +declare_arrays() diff --git a/integration_tests/array_02_decl.py b/integration_tests/array_02_decl.py new file mode 100644 index 0000000000..5969ba8a85 --- /dev/null +++ b/integration_tests/array_02_decl.py @@ -0,0 +1,29 @@ +from ltypes import i32, i64, f32, f64, c32, c64 +from numpy import empty + +def accept_multidim_i32_array(xi32: i32[:, :]) -> i32: + return xi32[0, 0] + +def accept_multidim_i64_array(xi64: i64[:, :, :]) -> i64: + return xi64[9, 9, 9] + +def accept_multidim_f32_array(xf32: f32[:]) -> f32: + return xf32[0] + +def accept_multidim_f64_array(xf64: f64[:, :]) -> f64: + return xf64[0, 1] + +def declare_arrays(): + ai32: i32[3, 3] = empty([3, 3]) + ai64: i64[10, 10, 10] = empty([10, 10, 10]) + af32: f32[3] = empty(3) + af64: f64[10, 4] = empty([10, 4]) + ac32: c32[3, 5, 99] = empty([3, 5, 99]) + ac64: c64[10, 13, 11, 16] = empty([10, 13, 11, 16]) + print(accept_multidim_i32_array(ai32)) + print(accept_multidim_i64_array(ai64)) + print(accept_multidim_f32_array(af32)) + print(accept_multidim_f64_array(af64)) + + +declare_arrays() diff --git a/integration_tests/bindc_01.py b/integration_tests/bindc_01.py new file mode 100644 index 0000000000..252e3cb0cf --- /dev/null +++ b/integration_tests/bindc_01.py @@ -0,0 +1,6 @@ +from ltypes import c_p_pointer, CPtr, i16 + +queries: CPtr +x: Pointer[i16] +c_p_pointer(queries, x) +print(queries, x) diff --git a/integration_tests/bindc_02.py b/integration_tests/bindc_02.py new file mode 100644 index 0000000000..6e1f4ac34a --- /dev/null +++ b/integration_tests/bindc_02.py @@ -0,0 +1,24 @@ +from ltypes import c_p_pointer, CPtr, pointer, i16, Pointer + +queries: CPtr +x: Pointer[i16[:]] +c_p_pointer(queries, x) +print(queries, x) + +def f(): + yq: CPtr + yptr1: Pointer[i16[:]] + y: i16[2] + y[0] = 1 + y[1] = 2 + yptr1 = pointer(y) + print(pointer(y), yptr1) + print(yptr1[0], yptr1[1]) + assert yptr1[0] == 1 + assert yptr1[1] == 2 + + c_p_pointer(yq, yptr1) + + print(yq, yptr1) + +f() diff --git a/integration_tests/bindc_03.py b/integration_tests/bindc_03.py new file mode 100644 index 0000000000..21009607ed --- /dev/null +++ b/integration_tests/bindc_03.py @@ -0,0 +1,33 @@ +from ltypes import c_p_pointer, CPtr, pointer, i16, i32, Pointer, ccall, p_c_pointer + +@ccall +def g(a: CPtr, value: i32) -> None: + pass + +@ccall +def get_array(size: i32) -> CPtr: + pass + +@ccallable +def f(q_void: CPtr) -> None: + i: i32 + el: i32 + q: Pointer[i32[:]] + c_p_pointer(q_void, q) + for i in range(10): + q2: CPtr + p_c_pointer(pointer(q[i]), q2) + g(q2, i * i) + # TODO: Use q[i] directly in the assert. + el = q[i] + print(el) + assert el == i * i + +def run(): + a: CPtr + size: i32 + size = 10 + a = get_array(size) + f(a) + +run() diff --git a/integration_tests/bindc_03b.c b/integration_tests/bindc_03b.c new file mode 100644 index 0000000000..ef987ff8da --- /dev/null +++ b/integration_tests/bindc_03b.c @@ -0,0 +1,10 @@ +#include "bindc_03b.h" +#include + +void g(int32_t* x, int32_t value) { + *x = value; +} + +void* get_array(int32_t size) { + return malloc(size * sizeof(int32_t)); +} diff --git a/integration_tests/bindc_03b.h b/integration_tests/bindc_03b.h new file mode 100644 index 0000000000..7ff7ce1558 --- /dev/null +++ b/integration_tests/bindc_03b.h @@ -0,0 +1,10 @@ +#ifndef BINDC_03B +#define BINDC_03B + +#include + +void g(int32_t* x, int32_t value); + +void* get_array(int32_t size); + +#endif // BINDC_03B diff --git a/integration_tests/bindc_04.py b/integration_tests/bindc_04.py new file mode 100644 index 0000000000..8bf06b3a20 --- /dev/null +++ b/integration_tests/bindc_04.py @@ -0,0 +1,21 @@ +from ltypes import pointer, i16, Pointer + +# Testing Global Pointers +x: Pointer[i16[:]] + +def f(): + yptr1: Pointer[i16[:]] + y: i16[2] + y[0] = 1 + y[1] = 2 + yptr1 = pointer(y) + assert yptr1[0] == 1 + assert yptr1[1] == 2 + x = pointer(y) + +def check(): + f() + assert x[0] == 1 + assert x[1] == 2 + +check() diff --git a/integration_tests/exit_01b.py b/integration_tests/exit_01b.py new file mode 100644 index 0000000000..4f28a46040 --- /dev/null +++ b/integration_tests/exit_01b.py @@ -0,0 +1,7 @@ +def main0(): + print("Before") + assert True + assert True, "OK!" + print("After") + +main0() diff --git a/integration_tests/exit_02.py b/integration_tests/exit_02.py new file mode 100644 index 0000000000..cee5fe86b1 --- /dev/null +++ b/integration_tests/exit_02.py @@ -0,0 +1,8 @@ +from sys import exit + +def main0(): + print("Before") + exit(1) + print("After") + +main0() diff --git a/integration_tests/exit_02b.py b/integration_tests/exit_02b.py new file mode 100644 index 0000000000..140d6353e5 --- /dev/null +++ b/integration_tests/exit_02b.py @@ -0,0 +1,6 @@ +def main0(): + print("Before") + assert False + print("After") + +main0() diff --git a/integration_tests/exit_02c.py b/integration_tests/exit_02c.py new file mode 100644 index 0000000000..9fa4fc8fbf --- /dev/null +++ b/integration_tests/exit_02c.py @@ -0,0 +1,6 @@ +def main0(): + print("Before") + assert False, "Custom message" + print("After") + +main0() diff --git a/integration_tests/expr_05.py b/integration_tests/expr_05.py index 8f75d865a0..0ce592db06 100644 --- a/integration_tests/expr_05.py +++ b/integration_tests/expr_05.py @@ -23,6 +23,9 @@ def main0(): a = 123282374 b = 32771 assert test_mod(a, b) == 30643 + a = -5345 + b = -534 + assert a % b == -5 a = -123282374 b = 32771 assert test_mod(a, b) == 2128 diff --git a/integration_tests/expr_06.py b/integration_tests/expr_06.py new file mode 100644 index 0000000000..e226b04efb --- /dev/null +++ b/integration_tests/expr_06.py @@ -0,0 +1,17 @@ +from ltypes import i32, f32 +from numpy import empty + +def main0(): + x: i32 = 25 + y: i32 = (2 + 3) * 5 + z: f32 = (2.0 + 3) * 5.0 + xa: i32[3] = empty(3) + assert x == 25 + assert y == 25 + assert z == 25.0 + +main0() + +# Not implemented yet in LPython: +#if __name__ == "__main__": +# main() diff --git a/integration_tests/expr_07.py b/integration_tests/expr_07.py new file mode 100644 index 0000000000..e02b041fc3 --- /dev/null +++ b/integration_tests/expr_07.py @@ -0,0 +1,17 @@ +from ltypes import i32 + +def g(x: i32): + print(x) + +x: i32 = 7 + +def f(): + a: i32 = 5 + x: i32 = 3 + x = 5 + b: i32 = x + 1 + assert b == 6 + print(a, b) + g(a*b + 3) + +f() diff --git a/integration_tests/expr_08.py b/integration_tests/expr_08.py new file mode 100644 index 0000000000..8bf06b3a20 --- /dev/null +++ b/integration_tests/expr_08.py @@ -0,0 +1,21 @@ +from ltypes import pointer, i16, Pointer + +# Testing Global Pointers +x: Pointer[i16[:]] + +def f(): + yptr1: Pointer[i16[:]] + y: i16[2] + y[0] = 1 + y[1] = 2 + yptr1 = pointer(y) + assert yptr1[0] == 1 + assert yptr1[1] == 2 + x = pointer(y) + +def check(): + f() + assert x[0] == 1 + assert x[1] == 2 + +check() diff --git a/integration_tests/expr_09.py b/integration_tests/expr_09.py new file mode 100644 index 0000000000..e79bd3010a --- /dev/null +++ b/integration_tests/expr_09.py @@ -0,0 +1,11 @@ +from ltypes import i32 + +def main0(): + i1: i32 = 10 + i2: i32 = 4 + i1 = 3 + i2 = 5 + print(-i1 ^ -i2) + assert -i1 ^ -i2 == 6 + +main0() diff --git a/integration_tests/expr_10.py b/integration_tests/expr_10.py new file mode 100644 index 0000000000..24da1000ee --- /dev/null +++ b/integration_tests/expr_10.py @@ -0,0 +1,16 @@ +from ltypes import i32 + +def g() -> i32: + return 5 + +def gsubrout(x: i32): + print(x) + +def test_fn1(): + i: i32 = g() + j: i32 + j = g() + g() + gsubrout(i) + +test_fn1() diff --git a/integration_tests/expr_11.py b/integration_tests/expr_11.py new file mode 100644 index 0000000000..b72fd1b982 --- /dev/null +++ b/integration_tests/expr_11.py @@ -0,0 +1,11 @@ +from ltypes import i32 + +def f(): + i: i32 + i = 3 + b: bool + b = bool(i) + assert b + print(b) + +f() diff --git a/integration_tests/expr_12.py b/integration_tests/expr_12.py new file mode 100644 index 0000000000..d860b310f1 --- /dev/null +++ b/integration_tests/expr_12.py @@ -0,0 +1,19 @@ +from ltypes import pointer, i16, Pointer + +def g(x: Pointer[i16[:]], y: i16[:]): + y[0] = 1 + y[1] = 2 + x = pointer(y) + print(x[0], x[1]) + +def check(ptr: Pointer[i16[:]]): + assert ptr[0] == 1 + assert ptr[1] == 2 + +def f(): + yptr1: Pointer[i16[:]] + y: i16[2] + g(yptr1, y) + check(yptr1) + +f() diff --git a/integration_tests/func_inline_01.py b/integration_tests/func_inline_01.py new file mode 100644 index 0000000000..e1a2b473a6 --- /dev/null +++ b/integration_tests/func_inline_01.py @@ -0,0 +1,16 @@ +from ltypes import i64 + +def fib(n: i64) -> i64: + if n < 2: + return n + return fib(n - 1) + fib(n - 2) + +def main(): + ans: i64 + x: i64 + x = 40 + ans = fib(x) + print(ans) + assert ans == 102334155 + +main() diff --git a/integration_tests/print_01.py b/integration_tests/print_01.py new file mode 100644 index 0000000000..22454c12de --- /dev/null +++ b/integration_tests/print_01.py @@ -0,0 +1,15 @@ +def f(): + print("Hello World!") + x: str + y: str + x = "," + y = "!!" + print("a", "b", sep=x) + x = "-+-+-" + print("a", "b", "c", sep=x) + print("d", "e", "f", sep = "=", end ="+\n") + print("x", "y", "z", end = y, sep = "*\n") + print("1", "2", sep =":") + print("LCompilers","LPython") + +f() diff --git a/integration_tests/run_tests.py b/integration_tests/run_tests.py deleted file mode 100755 index 36dfca68d7..0000000000 --- a/integration_tests/run_tests.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python - -import os -import sys - -# LPython and CPython tests -tests = [ - "exit_01.py", - "expr_01.py", - "expr_02.py", - "expr_03.py", - "expr_04.py", - "expr_05.py", - "test_types_01.py", - "test_str_01.py", - "test_str_02.py", - "test_list_01.py", - "modules_01.py", - #"modules_02.py", - "test_math.py", - "test_numpy_01.py", - "test_numpy_02.py", - "test_random.py", - "test_os.py", - "test_builtin.py", - "test_builtin_abs.py", - "test_builtin_bool.py", - "test_builtin_pow.py", - "test_builtin_int.py", - "test_builtin_len.py", - "test_builtin_float.py", - "test_builtin_str_02.py", - "test_builtin_round.py", - # "test_builtin_hex.py", - # "test_builtin_oct.py", - # "test_builtin_str.py", - "test_math1.py", - "test_math_02.py", - "test_c_interop_01.py", - "test_generics_01.py", - "test_cmath.py", - "test_complex.py", - "test_max_min.py" - -] - -# CPython tests only -test_cpython = [ - "test_builtin_bin.py", -] - -CUR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__))) - -def main(): - if not os.path.exists(os.path.join(CUR_DIR, 'tmp')): - os.makedirs(os.path.join(CUR_DIR, 'tmp')) - _print_msg("Compiling LPython tests...", 30) - for pyfile in tests: - basename = os.path.splitext(pyfile)[0] - cmd = os.path.join("..", "src", "bin", "lpython") + " %s -o tmp/%s" % (pyfile, basename) - msg = "Running: %s" % cmd - _print_msg(msg, 33) - os.chdir("integration_tests") - r = os.system(cmd) - os.chdir("..") - if r != 0: - msg = "Command '%s' failed." % cmd - _print_msg(msg, 31) - sys.exit(1) - - _print_msg("Running LPython and CPython tests...", 30) - python_path="src/runtime/ltypes" - for pyfile in tests: - basename = os.path.splitext(pyfile)[0] - cmd = "integration_tests/tmp/%s" % (basename) - msg = "Running: %s" % cmd - _print_msg(msg, 33) - r = os.system(cmd) - if r != 0: - msg = "Command '%s' failed." % cmd - _print_msg(msg, 31) - sys.exit(1) - cmd = "PYTHONPATH=%s python integration_tests/%s" % (python_path, - pyfile) - msg = "Running: %s" % cmd - _print_msg(msg, 33) - r = os.system(cmd) - if r != 0: - msg = "Command '%s' failed." % cmd - _print_msg(msg, 31) - sys.exit(1) - - _print_msg("Running CPython tests...", 30) - for pyfile in test_cpython: - cmd = "PYTHONPATH=%s python integration_tests/%s" % (python_path, - pyfile) - msg = "Running: %s" % cmd - _print_msg(msg, 33) - r = os.system(cmd) - if r != 0: - msg = "Command '%s' failed." % cmd - _print_msg(msg, 31) - sys.exit(1) - _print_msg("ALL TESTS PASSED", 32) - - -def _color(value): - return "\033[" + str(int(value)) + "m" - -def _print_msg(string, color_int): - print("%s%s%s" % (_color(color_int) + _color(1), string, _color(39) + _color(0))) - -if __name__ == "__main__": - main() diff --git a/integration_tests/run_tests.sh b/integration_tests/run_tests.sh new file mode 100755 index 0000000000..a5ce362ce0 --- /dev/null +++ b/integration_tests/run_tests.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -ex + +rm -rf b1 b2 b3 + +# Append "-j4" or "-j" to run in parallel +jn=$1 + +export PATH="$(pwd)/../src/bin:$PATH" + +mkdir b1 +cd b1 +cmake -DKIND=cpython .. +make $jn +ctest $jn --output-on-failure +cd .. + + +mkdir b2 +cd b2 +cmake -DKIND=llvm .. +make $jn +ctest $jn --output-on-failure +cd .. + +mkdir b3 +cd b3 + +cmake -DKIND=c .. +make $jn +ctest $jn --output-on-failure diff --git a/integration_tests/structs_01.py b/integration_tests/structs_01.py new file mode 100644 index 0000000000..8b63861e0a --- /dev/null +++ b/integration_tests/structs_01.py @@ -0,0 +1,32 @@ +from ltypes import i32, f32, dataclass + +@dataclass +class A: + y: f32 + x: i32 + +def f(a: A): + print(a.x) + print(a.y) + +def change_struct(a: A): + a.x = a.x + 1 + a.y = a.y + 1 + +def g(): + x: A + x = A(3.25, 3) + f(x) + assert x.x == 3 + assert x.y == 3.25 + + x.x = 5 + x.y = 5.5 + f(x) + assert x.x == 5 + assert x.y == 5.5 + change_struct(x) + assert x.x == 6 + assert x.y == 6.5 + +g() diff --git a/integration_tests/structs_02.py b/integration_tests/structs_02.py new file mode 100644 index 0000000000..5dbb4e995a --- /dev/null +++ b/integration_tests/structs_02.py @@ -0,0 +1,28 @@ +from ltypes import i32, f32, dataclass, CPtr, Pointer, c_p_pointer, pointer + +@dataclass +class A: + x: i32 + y: f32 + +@ccallable +def f(a: CPtr) -> None: + x: i32 + y: f32 + a1: A + a2: Pointer[A] + a1 = A(3, 3.25) + a2 = pointer(a1) + print(a2, pointer(a1)) + x = a2.x + y = a2.y + assert x == 3 + assert y == 3.25 + c_p_pointer(a, a2) + print(a, a2, pointer(a1)) + +def g(): + b: CPtr + f(b) + +g() diff --git a/integration_tests/structs_03.py b/integration_tests/structs_03.py new file mode 100644 index 0000000000..8b8182114f --- /dev/null +++ b/integration_tests/structs_03.py @@ -0,0 +1,21 @@ +from ltypes import i32, f32, dataclass, Pointer, pointer + +@dataclass +class A: + x: i32 + y: f32 + +def f(pa: Pointer[A]): + print(pa.x) + print(pa.y) + +def g(): + x: A = A(3, 3.25) + xp: Pointer[A] = pointer(x) + assert xp.x == 3 + assert xp.y == 3.25 + xp.x = 5 + xp.y = 5.5 + f(xp) + +g() diff --git a/integration_tests/structs_04.py b/integration_tests/structs_04.py new file mode 100644 index 0000000000..9a0036adc8 --- /dev/null +++ b/integration_tests/structs_04.py @@ -0,0 +1,33 @@ +from ltypes import i32, f32, dataclass + +@dataclass +class A: + y: f32 + x: i32 + +@dataclass +class B: + a: A + z: i32 + +def f(b: B): + print(b.z, b.a.x, b.a.y) + assert b.z == 1 + assert b.a.x == 2 + assert b.a.y == 3.0 + +def g(): + a1: A = A(1.0, 1.0) + a2: A = A(2.0, 2.0) + b: B = B(a1, 1) + b.a = a2 + b.z = 1 + b.a.x = 2 + b.a.y = 3.0 + assert a1.x == 1 + assert a1.y == 1.0 + assert a2.x == 2 + assert a2.y == 3.0 + f(b) + +g() diff --git a/integration_tests/structs_05.py b/integration_tests/structs_05.py new file mode 100644 index 0000000000..e5ec3d4dfe --- /dev/null +++ b/integration_tests/structs_05.py @@ -0,0 +1,36 @@ +from ltypes import i32, f64, dataclass + +@dataclass +class A: + y: f64 + x: i32 + +def verify(s: A[:], x1: i32, y1: f64, x2: i32, y2: f64): + eps: f64 = 1e-12 + print(s[0].x, s[0].y) + assert s[0].x == x1 + assert abs(s[0].y - y1) < eps + print(s[1].x, s[1].y) + assert s[1].x == x2 + assert abs(s[1].y - y2) < eps + +def update_1(s: A): + s.x = 2 + s.y = 1.2 + +def update_2(s: A[:]): + s[1].x = 3 + s[1].y = 2.3 + +def g(): + # TODO: Replace y: A[2] with y: A[2] = [None, None] + # TODO: And enable cpython in integration_tests. + y: A[2] + y[0] = A(1.1, 1) + y[1] = A(2.2, 2) + verify(y, 1, 1.1, 2, 2.2) + update_1(y[0]) + update_2(y) + verify(y, 2, 1.2, 3, 2.3) + +g() diff --git a/integration_tests/test_bool_binop.py b/integration_tests/test_bool_binop.py new file mode 100644 index 0000000000..74e409a4ae --- /dev/null +++ b/integration_tests/test_bool_binop.py @@ -0,0 +1,29 @@ +from ltypes import i32, f64 + +def f(): + i: i32 + i = True + True + assert i == 2 + + i = True - False + assert i == 1 + + i = False * True + assert i == 0 + + i = True // True + assert i == 1 + + i = False // True + assert i == 0 + + i = True ** True + assert i == 1 + + f: f64 + b1: bool = False + b2: bool = True + f = b1/b2 + assert f == 0.0 + +f() diff --git a/integration_tests/test_builtin_bool.py b/integration_tests/test_builtin_bool.py index f34e1ec773..cebb20a995 100644 --- a/integration_tests/test_builtin_bool.py +++ b/integration_tests/test_builtin_bool.py @@ -33,6 +33,9 @@ def test_bool(): f2 = -235.6 assert bool(f2) + f2 = 0.0000534 + assert bool(f2) + s: str s = "" assert not bool(s) diff --git a/integration_tests/test_builtin_float.py b/integration_tests/test_builtin_float.py index 7fb2eb9f1b..2481f95f3c 100644 --- a/integration_tests/test_builtin_float.py +++ b/integration_tests/test_builtin_float.py @@ -1,4 +1,4 @@ -from ltypes import i32 +from ltypes import i32, f64 def test_float(): i: i32 @@ -12,6 +12,12 @@ def test_float(): assert float(-4235) == -4235.0 assert float(True) == 1.0 assert float(False) == 0.0 - + b: bool + b = True + f: f64 + f = float(b) + assert f == 1.0 + b = False + assert b == 0.0 test_float() diff --git a/integration_tests/test_builtin_str.py b/integration_tests/test_builtin_str.py index 8ee48f51c9..940b8daa98 100644 --- a/integration_tests/test_builtin_str.py +++ b/integration_tests/test_builtin_str.py @@ -6,5 +6,21 @@ def test_str_int(): assert s == "-567" assert str(4) == "4" assert str(-5) == "-5" + assert str() == "" + assert str("1234") == "1234" + assert str(False) == "False" + assert str(True) == "True" + +def str_conv_for_variables(): + x: i32 + x = 123 + assert "123" == str(x) + x = 12345 + assert "12345" == str(x) + x = -12 + assert "-12" == str(x) + x = -121212 + assert "-121212" == str(x) test_str_int() +str_conv_for_variables() diff --git a/integration_tests/test_c_interop_01.py b/integration_tests/test_c_interop_01.py index 6582f58a40..4a79213b07 100644 --- a/integration_tests/test_c_interop_01.py +++ b/integration_tests/test_c_interop_01.py @@ -14,23 +14,23 @@ def _lfortran_bgt32(i: i32, j: i32) -> i32: pass @ccall -def _lfortran_bgt64(i: i64, j: i64) -> i64: +def _lfortran_bgt64(i: i64, j: i64) -> i32: pass -@ccall -def _lfortran_random_number(n: i64, v: f64[:]): - pass +#@ccall +#def _lfortran_random_number(n: i64, v: f64[:]): +# pass def test_c_callbacks(): pi: f64 = 3.141592653589793238462643383279502884197 assert abs(_lfortran_dsin(pi) - 0) < 1e-12 assert abs(_lfortran_dsin(pi/2) - 1) < 1e-12 - #assert abs(_lfortran_ssin(pi) - 0) < 1e-6 - #assert abs(_lfortran_ssin(pi/2) - 1) < 1e-6 + assert abs(_lfortran_ssin(pi) - 0) < 1e-6 + assert abs(_lfortran_ssin(pi/2) - 1) < 1e-6 assert _lfortran_bgt32(3, 4) == 0 assert _lfortran_bgt32(4, 3) == 1 - #assert _lfortran_bgt64(3, 4) == 0 - #assert _lfortran_bgt64(4, 3) == 1 + assert _lfortran_bgt64(3, 4) == 0 + assert _lfortran_bgt64(4, 3) == 1 test_c_callbacks() diff --git a/integration_tests/test_c_interop_02.py b/integration_tests/test_c_interop_02.py new file mode 100644 index 0000000000..c2e5ed4bba --- /dev/null +++ b/integration_tests/test_c_interop_02.py @@ -0,0 +1,65 @@ +from ltypes import ccall, f32, f64, i8, i16, i32, i64 + +@ccall +def f_f64_f64(x: f64) -> f64: + pass + +@ccall +def f_f32_f32(x: f32) -> f32: + pass + +@ccall +def f_i64_i64(x: i64) -> i64: + pass + +@ccall +def f_i32_i32(x: i32) -> i32: + pass + +@ccall +def f_i16_i16(x: i16) -> i16: + pass + +@ccall +def f_i8_i8(x: i8) -> i8: + pass + +@ccall +def f_str_i32(x: str) -> i32: + pass + +def test_c_callbacks(): + xf64: f64 + xf64 = 3.3 + assert abs(f_f64_f64(xf64) - (xf64+1)) < 1e-12 + + xf32: f32 + xf32 = 3.3 + assert abs(f_f32_f32(xf32) - (xf32+1)) < 1e-6 + + xi64: i64 + xi64 = 3 + assert f_i64_i64(xi64) == 4 + + xi32: i32 + xi32 = 3 + assert f_i32_i32(xi32) == 4 + + xi16: i16 + xi16 = 3 + assert f_i16_i16(xi16) == 4 + + xi8: i8 + xi8 = 3 + assert f_i8_i8(xi8) == 4 + + assert f_str_i32("Hello World!") == 12 + assert f_str_i32("abc") == 3 + assert f_str_i32("a") == 1 + assert f_str_i32("") == 0 + x: str = "Hello World!" + assert f_str_i32(x) == 12 + x = "abc" + assert f_str_i32(x) == 3 + +test_c_callbacks() diff --git a/integration_tests/test_c_interop_02b.c b/integration_tests/test_c_interop_02b.c new file mode 100644 index 0000000000..2dfde29304 --- /dev/null +++ b/integration_tests/test_c_interop_02b.c @@ -0,0 +1,31 @@ +#include + +#include "test_c_interop_02b.h" + +double f_f64_f64(double x) { + return x+1; +} + +float f_f32_f32(float x) { + return x+1; +} + +int64_t f_i64_i64(int64_t x) { + return x+1; +} + +int32_t f_i32_i32(int32_t x) { + return x+1; +} + +int16_t f_i16_i16(int16_t x) { + return x+1; +} + +int8_t f_i8_i8(int8_t x) { + return x+1; +} + +int32_t f_str_i32(char *x) { + return strlen(x); +} diff --git a/integration_tests/test_c_interop_02b.h b/integration_tests/test_c_interop_02b.h new file mode 100644 index 0000000000..331f8a9103 --- /dev/null +++ b/integration_tests/test_c_interop_02b.h @@ -0,0 +1,16 @@ +#ifndef TEST_C_INTEROP_02B +#define TEST_C_INTEROP_02B + +#include + + +double f_f64_f64(double x); +float f_f32_f32(float x); +int64_t f_i64_i64(int64_t x); +int32_t f_i32_i32(int32_t x); +int16_t f_i16_i16(int16_t x); +int8_t f_i8_i8 (int8_t x); +int32_t f_str_i32(char *x); + + +#endif // TEST_C_INTEROP_02B diff --git a/integration_tests/test_c_interop_03.py b/integration_tests/test_c_interop_03.py new file mode 100644 index 0000000000..3243524a57 --- /dev/null +++ b/integration_tests/test_c_interop_03.py @@ -0,0 +1,55 @@ +from ltypes import (ccall, f32, f64, i32, i64, CPtr, pointer, Pointer, + p_c_pointer, empty_c_void_p) + +@ccall +def f_pi32_i32(x: CPtr) -> i32: + pass + +@ccall +def f_pi64_i32(x: CPtr) -> i64: + pass + +@ccall +def f_pf32_i32(x: CPtr) -> f32: + pass + +@ccall +def f_pf64_i32(x: CPtr) -> f64: + pass + +@ccall +def f_pvoid_pvoid(x: CPtr) -> CPtr: + pass + +def test_c_callbacks(): + xi32: i32 + xi32 = 3 + p: CPtr + p = empty_c_void_p() + p_c_pointer(pointer(xi32, i32), p) + print(pointer(xi32, i32), p) + assert f_pi32_i32(p) == 4 + assert f_pi32_i32(f_pvoid_pvoid(p)) == 4 + + xi64: i64 + xi64 = 3 + p_c_pointer(pointer(xi64, i64), p) + print(pointer(xi64, i64), p) + assert f_pi64_i32(p) == 4 + assert f_pi64_i32(f_pvoid_pvoid(p)) == 4 + + xf32: f32 + xf32 = 3.3 + p_c_pointer(pointer(xf32, f32), p) + print(pointer(xf32, f32), p) + assert abs(f_pf32_i32(p)-4.3) < 1e-6 + assert abs(f_pf32_i32(f_pvoid_pvoid(p))-4.3) < 1e-6 + + xf64: f64 + xf64 = 3.3 + p_c_pointer(pointer(xf64, f64), p) + print(pointer(xf64, f64), p) + assert abs(f_pf64_i32(p)-4.3) < 1e-12 + assert abs(f_pf64_i32(f_pvoid_pvoid(p))-4.3) < 1e-12 + +test_c_callbacks() diff --git a/integration_tests/test_c_interop_03b.c b/integration_tests/test_c_interop_03b.c new file mode 100644 index 0000000000..6cdbc489cf --- /dev/null +++ b/integration_tests/test_c_interop_03b.c @@ -0,0 +1,21 @@ +#include "test_c_interop_03b.h" + +int32_t f_pi32_i32(int32_t *x) { + return *x+1; +} + +int64_t f_pi64_i32(int64_t *x) { + return *x+1; +} + +float f_pf32_i32(float *x) { + return *x+1; +} + +double f_pf64_i32(double *x) { + return *x+1; +} + +void* f_pvoid_pvoid(void *x) { + return x; +} diff --git a/integration_tests/test_c_interop_03b.h b/integration_tests/test_c_interop_03b.h new file mode 100644 index 0000000000..1f070d5e1b --- /dev/null +++ b/integration_tests/test_c_interop_03b.h @@ -0,0 +1,14 @@ +#ifndef TEST_C_INTEROP_03B +#define TEST_C_INTEROP_03B + +#include + + +int32_t f_pi32_i32(int32_t *x); +int64_t f_pi64_i32(int64_t *x); +float f_pf32_i32(float *x); +double f_pf64_i32(double *x); +void* f_pvoid_pvoid(void *x); + + +#endif // TEST_C_INTEROP_03B diff --git a/integration_tests/test_c_interop_04.py b/integration_tests/test_c_interop_04.py new file mode 100644 index 0000000000..483e4266c8 --- /dev/null +++ b/integration_tests/test_c_interop_04.py @@ -0,0 +1,26 @@ +from ltypes import (ccall, f32, f64, i32, i64, CPtr, pointer, Pointer, + p_c_pointer, empty_c_void_p) +from numpy import empty, int32 + +@ccall +def sum_pi32_i32(x: CPtr) -> i32: + pass + +def test_c_callbacks(): + xi32: i32[4] + xi32 = empty(4, dtype=int32) + sumi32: i32 + xi32[0] = 3 + xi32[1] = 4 + xi32[2] = 5 + xi32[3] = 6 + print(xi32[0], xi32[1], xi32[2], xi32[3]) + p: CPtr + p = empty_c_void_p() + p_c_pointer(pointer(xi32), p) + print(pointer(xi32), p) + sumi32 = sum_pi32_i32(p) + print(sumi32) + assert sumi32 == 18 + +test_c_callbacks() diff --git a/integration_tests/test_c_interop_04b.c b/integration_tests/test_c_interop_04b.c new file mode 100644 index 0000000000..a814ff85dc --- /dev/null +++ b/integration_tests/test_c_interop_04b.c @@ -0,0 +1,5 @@ +#include "test_c_interop_04b.h" + +int32_t sum_pi32_i32(int32_t *x) { + return x[0] + x[1] + x[2] + x[3]; +} diff --git a/integration_tests/test_c_interop_04b.h b/integration_tests/test_c_interop_04b.h new file mode 100644 index 0000000000..df1818c21b --- /dev/null +++ b/integration_tests/test_c_interop_04b.h @@ -0,0 +1,10 @@ +#ifndef TEST_C_INTEROP_04B +#define TEST_C_INTEROP_04B + +#include + + +int32_t sum_pi32_i32(int32_t *x); + + +#endif // TEST_C_INTEROP_04B diff --git a/integration_tests/test_c_interop_05.py b/integration_tests/test_c_interop_05.py new file mode 100644 index 0000000000..116779d8db --- /dev/null +++ b/integration_tests/test_c_interop_05.py @@ -0,0 +1,72 @@ +from ltypes import ccall, f32, f64, i32, i64, CPtr, pointer, Pointer, p_c_pointer + +@ccall +def f_i32_i32(x: i32) -> i32: + pass + +@ccall +def f_pi32_i32(x: CPtr) -> i32: + pass + +@ccall +def f_pstruct_i32(x: CPtr) -> i32: + pass + +@ccall +def f_enum_i32(x: i32) -> i32: + pass + +@ccall +def driver1() -> i32: + pass + +@ccall +def driver2() -> i32: + pass + +@ccall +def driver3() -> i32: + pass + +@ccall +def driver4() -> i32: + pass + +@ccall +def driver5() -> i32: + pass + +@ccallback +def callback1() -> i32: + xi32: i32 + xi32 = 3 + p: CPtr + p_c_pointer(pointer(xi32), p) + return f_pi32_i32(p) + +@ccallback +def callback2(x: i32) -> i32: + return f_i32_i32(x) + +@ccallback +def callback3(p: CPtr) -> i32: + return f_pi32_i32(p) + +@ccallback +def callback4(p: CPtr) -> i32: + return f_pstruct_i32(p) + +@ccallback +def callback5(x: i32) -> i32: + return f_enum_i32(x) + + +def test_c_callbacks(): + assert driver1() == 4 + assert driver2() == 4 + assert driver3() == 4 + assert driver4() == 4 + assert driver5() == 4 + + +test_c_callbacks() diff --git a/integration_tests/test_c_interop_05b.c b/integration_tests/test_c_interop_05b.c new file mode 100644 index 0000000000..6b45bf4dd3 --- /dev/null +++ b/integration_tests/test_c_interop_05b.c @@ -0,0 +1,45 @@ +#include "test_c_interop_05b.h" + +int32_t f_i32_i32(int32_t x) { + return x+1; +} + +int32_t f_pi32_i32(int32_t *x) { + return *x+1; +} + +int32_t f_pstruct_i32(struct Data *x) { + return x->a+1; +} + +int32_t f_enum_i32(enum MyEnum x) { + return (int32_t)x + 2; +} + +int32_t driver1() { + return callback1(); +} + +int32_t driver2() { + int32_t x; + x = 3; + return callback2(x); +} + +int32_t driver3() { + int32_t x; + x = 3; + return callback3(&x); +} + +int32_t driver4() { + struct Data x; + x.a = 3; + return callback4(&x); +} + +int32_t driver5() { + enum MyEnum x; + x = M_c; + return callback5(x); +} diff --git a/integration_tests/test_c_interop_05b.h b/integration_tests/test_c_interop_05b.h new file mode 100644 index 0000000000..e7676c0e3b --- /dev/null +++ b/integration_tests/test_c_interop_05b.h @@ -0,0 +1,38 @@ +#ifndef TEST_C_INTEROP_05B +#define TEST_C_INTEROP_05B + +#include + +struct Data { + int64_t x, *p; + double y, *z; + int32_t a; + char name[25]; +}; + +enum MyEnum { + M_a = 0, + M_b = 1, + M_c = 2, + M_d = 3, +}; + +int32_t f_i32_i32(int32_t x); +int32_t f_pi32_i32(int32_t *x); +int32_t f_pstruct_i32(struct Data *x); +int32_t f_enum_i32(enum MyEnum x); + +int32_t callback1(); +int32_t callback2(int32_t x); +int32_t callback3(int32_t *x); +int32_t callback4(struct Data *x); +int32_t callback5(enum MyEnum x); + +int32_t driver1(); +int32_t driver2(); +int32_t driver3(); +int32_t driver4(); +int32_t driver5(); + + +#endif // TEST_C_INTEROP_05B diff --git a/integration_tests/test_complex.py b/integration_tests/test_complex.py index 097224a61e..5c4984abd9 100644 --- a/integration_tests/test_complex.py +++ b/integration_tests/test_complex.py @@ -97,11 +97,46 @@ def test_complex_binop_64(): #z = x / y z = x ** y +def test_complex_unary_minus(): + c: c32 + c = complex(3, 4.5) + _c: c32 + _c = -c + assert abs(_c.real - (-3.0)) < 1e-12 + assert abs(_c.imag - (-4.5)) < 1e-12 + _c = complex(5, -78) + _c = -_c + assert abs(_c.real - (-5.0)) < 1e-12 + assert abs(_c.imag - 78.0) < 1e-12 + c2: c64 + c2 = complex(-4.5, -7.8) + c2 = -c2 + assert abs(c2.real - 4.5) < 1e-12 + assert abs(c2.imag - 7.8) < 1e-12 + c2 = 3+4j + c2 = -c2 + assert abs(c2.real - (-3.0)) < 1e-12 + assert abs(c2.imag - (-4.0)) < 1e-12 + +def test_complex_not(): + c: c32 + c = complex(4, 5) + b: bool + b = not c + assert not b + + c2: c64 + c2 = complex(0, 0) + b = not c2 + assert b + def check(): test_real_imag() test_complex() test_complex_abs() test_complex_binop_32() test_complex_binop_64() + test_complex_unary_minus() + test_complex_not() check() diff --git a/integration_tests/test_integer_bitnot.py b/integration_tests/test_integer_bitnot.py new file mode 100644 index 0000000000..2c12e8ecf4 --- /dev/null +++ b/integration_tests/test_integer_bitnot.py @@ -0,0 +1,13 @@ +from ltypes import i32 + +def f(): + i: i32 + i = 5 + res: i32 + res = ~i + assert res == -6 + + i = -235346 + assert ~i == 235345 + +f() diff --git a/integration_tests/test_issue_518.py b/integration_tests/test_issue_518.py new file mode 100644 index 0000000000..9fea6d3f71 --- /dev/null +++ b/integration_tests/test_issue_518.py @@ -0,0 +1,22 @@ +from ltypes import i64 + +def fib(n: i64) -> i64: + if n < 2: + return n + else: + return fib(n - 1) + fib(n - 2) + +def main0(): + ans: i64 + ans = fib(15) + assert ans == 610 + +def main(): + # test of issue-529 + ans: i64 + ans = fib(10) + assert ans == 55 + + +main0() +main() diff --git a/integration_tests/test_math.py b/integration_tests/test_math.py index 28a13f91a6..513b29c658 100644 --- a/integration_tests/test_math.py +++ b/integration_tests/test_math.py @@ -6,7 +6,7 @@ eps = 1e-12 def test_factorial_1(): - i: i32 + i: i64 i = factorial(10) assert i == 3628800 @@ -36,11 +36,11 @@ def test_degrees(): # Check for integer i = degrees(32) assert abs(i - 1833.4649444186343) < eps - + # Check for float i = degrees(32.2) assert abs(i - 1844.924100321251) < eps - + def test_radians(): i: f64 @@ -60,10 +60,19 @@ def test_exp(): def test_pow(): - i: f64 - i = pow(2.4, 4.3) - assert abs(i - 43.14280115650323) < eps - + eps: f64 + eps = 1e-12 + x: f64 + x = 2.4 + y: f64 + y = 4.3 + assert abs(pow(x, y) - 43.14280115650323) < eps + + a: i64 + a = 2 + b: i64 + b = 4 + assert abs(pow(a, b) - 16) < eps def test_ldexp(): i: f64 @@ -72,14 +81,18 @@ def test_ldexp(): def test_fabs(): - i: f64 - j: f64 + eps: f64 eps = 1e-12 - i = fabs(10.3) - j = fabs(-10.3) - assert abs(i - j) < eps - + i: f64 + j: f64 + i = -10.5 + j = -7.0 + assert fabs(i + fabs(j)) == 3.5 + assert abs(fabs(10) - fabs(-10)) < eps + assert abs(fabs(10.3) - fabs(-10.3)) < eps + assert fabs(0.5) == 0.5 + assert fabs(-5) == 5.0 def test_gcd(): i: i32 diff --git a/integration_tests/test_numpy_02.py b/integration_tests/test_numpy_02.py index c580eb47bc..ce5940f99c 100644 --- a/integration_tests/test_numpy_02.py +++ b/integration_tests/test_numpy_02.py @@ -52,7 +52,9 @@ def sqrt(n: i64) -> f64: @overload def sqrt(f: f32) -> f32: - return f**(1/2) + half: f32 + half = 1/2 + return f**half @overload def sqrt(f: f64) -> f64: @@ -78,7 +80,9 @@ def exp(n: i64) -> f64: @overload def exp(f: f32) -> f32: - return e**f + ef32: f32 + ef32 = e + return ef32**f @overload def exp(f: f64) -> f64: @@ -144,16 +148,20 @@ def sign(x: i32) -> i32: @overload def sign(x: i64) -> i64: + result: i64 if x == 0: - return 0 + result = 0 elif x > 0: - return 1 - - return -1 + result = 1 + else: + result = -1 + return result @overload def sign(x: f32) -> f32: - return x/fabs(x) + fabsf32: f32 + fabsf32 = fabs(x) + return x/fabsf32 @overload def sign(x: f64) -> f64: @@ -206,11 +214,15 @@ def imag(x: i32) -> i32: @overload def imag(x: i64) -> i64: - return 0 + result: i64 + result = 0 + return result @overload def imag(f: f32) -> f32: - return 0.0 + result: f32 + result = 0.0 + return result @overload def imag(f: f64) -> f64: diff --git a/integration_tests/test_os.py b/integration_tests/test_os.py index 664d5fea0a..2706e6ba88 100644 --- a/integration_tests/test_os.py +++ b/integration_tests/test_os.py @@ -3,7 +3,7 @@ def test(): path: str - path = "integration_tests/test_os.py" + path = "../test_os.py" fd: i64 n: i64 fd = open(path, O_RDONLY) diff --git a/integration_tests/test_platform.py b/integration_tests/test_platform.py new file mode 100644 index 0000000000..1d2730773b --- /dev/null +++ b/integration_tests/test_platform.py @@ -0,0 +1,9 @@ +from platform import python_implementation + +def test_platform1(): + s: str + s = python_implementation() + print("Python Implementation:", s) + assert s == "CPython" or s == "LPython" + +test_platform1() diff --git a/integration_tests/test_str_01.py b/integration_tests/test_str_01.py index aeb8a67438..014b798fca 100644 --- a/integration_tests/test_str_01.py +++ b/integration_tests/test_str_01.py @@ -45,11 +45,16 @@ def test_str_repeat(): assert 3*a*3 == "XyzXyzXyzXyzXyzXyzXyzXyzXyz" assert a*-1 == "" +def test_constant_str_subscript(): + assert "abc"[2] == "c" + assert "abc"[:2] == "ab" + def check(): f() test_str_concat() test_str_index() test_str_slice() test_str_repeat() + test_constant_str_subscript() check() diff --git a/integration_tests/test_str_03.py b/integration_tests/test_str_03.py new file mode 100644 index 0000000000..d9b140d9e2 --- /dev/null +++ b/integration_tests/test_str_03.py @@ -0,0 +1,14 @@ +def test_new_line(): + print("abc\n") + print("\ndef") + print("x\nyz") + +def test_int(): + i: i8 = 1 + j: i16 = 2 + k: i32 = 3 + l: i64 = 4 + print("abc:", i, j, k, l) + +test_new_line() +test_int() diff --git a/integration_tests/test_str_comparison.py b/integration_tests/test_str_comparison.py new file mode 100644 index 0000000000..4ac40aaa78 --- /dev/null +++ b/integration_tests/test_str_comparison.py @@ -0,0 +1,36 @@ +def f(): + s1: str = "abcd" + s2: str = "abcd" + assert s1 == s2 + assert s1 <= s2 + assert s1 >= s2 + s1 = "abcde" + assert s1 >= s2 + assert s1 > s2 + s1 = "abc" + assert s1 < s2 + assert s1 <= s2 + s1 = "Abcd" + s2 = "abcd" + assert s1 < s2 + s1 = "orange" + s2 = "apple" + assert s1 >= s2 + assert s1 > s2 + s1 = "albatross" + s2 = "albany" + assert s1 >= s2 + assert s1 > s2 + assert s1 != s2 + s1 = "maple" + s2 = "morning" + assert s1 <= s2 + assert s1 < s2 + assert s1 != s2 + s1 = "Zebra" + s2 = "ant" + assert s1 <= s2 + assert s1 < s2 + assert s1 != s2 + +f() diff --git a/integration_tests/test_str_to_int.py b/integration_tests/test_str_to_int.py new file mode 100644 index 0000000000..81bd75c34d --- /dev/null +++ b/integration_tests/test_str_to_int.py @@ -0,0 +1,10 @@ +from ltypes import i32 + +def f(): + i: i32 + i = int("314") + assert i == 314 + i = int("-314") + assert i == -314 + +f() \ No newline at end of file diff --git a/integration_tests/test_types_01.py b/integration_tests/test_types_01.py index 23494268d3..064f098e76 100644 --- a/integration_tests/test_types_01.py +++ b/integration_tests/test_types_01.py @@ -20,12 +20,27 @@ def test_i64(): i = 5 assert i == 5 +def test_i8_to_i64(): + i1: i8 + i1 = -5 + i2: i64 + i2 = i1 + assert i2 == -5 + +def test_i64_to_i8(): + i1: i64 + i1 = 6 + i2: i8 + i2 = i1 + assert i2 == 6 def check(): test_i8() test_i16() test_i32() test_i64() + test_i8_to_i64() + test_i64_to_i8() check() diff --git a/integration_tests/test_unary_minus.py b/integration_tests/test_unary_minus.py new file mode 100644 index 0000000000..02de00715f --- /dev/null +++ b/integration_tests/test_unary_minus.py @@ -0,0 +1,15 @@ +from ltypes import i32, f64 + +def f(): + eps: f64 + eps = 1e-12 + + i: i32 + i = -67 + assert -i == 67 + + f: f64 + f = -67.6457 + assert abs(-f - 67.6457) < eps + +f() diff --git a/integration_tests/test_unary_plus.py b/integration_tests/test_unary_plus.py new file mode 100644 index 0000000000..c8019dd260 --- /dev/null +++ b/integration_tests/test_unary_plus.py @@ -0,0 +1,26 @@ +from ltypes import i32, f64, c32 + +def f(): + eps: f64 + eps = 1e-12 + + i: i32 + i = -67 + assert +i == -67 + + f: f64 + f = -67.6457 + assert abs(+f + 67.6457) < eps + + c: c32 + c = 4-5j + c = +c + assert abs(c.real - 4.000000) < eps + assert abs(c.imag - (-5.000000)) < eps + + assert +True == 1 + b: bool + b = False + assert -b == 0 + +f() diff --git a/integration_tests/test_vars_01.py b/integration_tests/test_vars_01.py new file mode 100644 index 0000000000..b7c357ccb1 --- /dev/null +++ b/integration_tests/test_vars_01.py @@ -0,0 +1,8 @@ +from test_vars_01b import test_name_other_module + +def test_name(): + print(__name__) + assert __name__ == "__main__" + +test_name() +test_name_other_module() diff --git a/integration_tests/test_vars_01b.py b/integration_tests/test_vars_01b.py new file mode 100644 index 0000000000..ba062cf214 --- /dev/null +++ b/integration_tests/test_vars_01b.py @@ -0,0 +1,3 @@ +def test_name_other_module(): + print(__name__) + assert __name__ != "__main__" diff --git a/integration_tests/test_version.py b/integration_tests/test_version.py new file mode 100644 index 0000000000..eb93d9cdf9 --- /dev/null +++ b/integration_tests/test_version.py @@ -0,0 +1,6 @@ +from platform import python_version + +def test_lpython_version(): + print(python_version()) + +test_lpython_version() \ No newline at end of file diff --git a/integration_tests/vec_01.py b/integration_tests/vec_01.py new file mode 100644 index 0000000000..4bbcb87522 --- /dev/null +++ b/integration_tests/vec_01.py @@ -0,0 +1,18 @@ +from ltypes import f64 +from numpy import empty + +def loop_vec(): + a: f64[9216] = empty(9216) + b: f64[9216] = empty(9216) + i: i32 + + for i in range(9216): + b[i] = 5.0 + + for i in range(9216): + a[i] = b[i] + + for i in range(9216): + assert a[i] == 5.0 + +loop_vec() diff --git a/run_tests.py b/run_tests.py index 53d4a5ea38..5f657433ef 100755 --- a/run_tests.py +++ b/run_tests.py @@ -49,11 +49,14 @@ def main(): mod_to_asr = test.get("mod_to_asr", False) llvm = test.get("llvm", False) cpp = test.get("cpp", False) + c = test.get("c", False) obj = test.get("obj", False) x86 = test.get("x86", False) bin_ = test.get("bin", False) pass_ = test.get("pass", None) - if pass_ and pass_ not in ["do_loops", "global_stmts"]: + pass_with_llvm = test.get("pass_with_llvm", None) + if pass_ and pass_ not in ["do_loops", "global_stmts", + "loop_vectorise", "inline_function_calls"]: raise Exception("Unknown pass: %s" % pass_) print(color(style.bold)+"TEST:"+color(style.reset), filename) @@ -72,6 +75,15 @@ def main(): run_test("asr", "lpython --show-asr --no-color {infile} -o {outfile}", filename, update_reference, extra_args) + if pass_ is not None: + cmd = "lpython --pass=" + pass_ + " --show-asr --no-color {infile} -o {outfile}" + run_test("pass_{}".format(pass_), cmd, + filename, update_reference, extra_args) + if pass_with_llvm: + cmd = "lpython --pass=" + pass_ + " --show-llvm --no-color {infile} -o {outfile}" + run_test("pass_llvm_{}".format(pass_), cmd, + filename, update_reference, extra_args) + if llvm: if no_llvm: print(" * llvm SKIPPED as requested") @@ -83,6 +95,10 @@ def main(): run_test("cpp", "lpython --no-color --show-cpp {infile}", filename, update_reference, extra_args) + if c: + run_test("c", "lpython --no-color --show-c {infile}", + filename, update_reference, extra_args) + if tokens: run_test("tokens", "lpython --no-color --show-tokens {infile} -o {outfile}", filename, update_reference, extra_args) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index 4a12b71d01..baf6d0b01c 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -11,20 +11,12 @@ #include #include #include +#include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include @@ -35,6 +27,10 @@ #include #include +#ifdef HAVE_LFORTRAN_RAPIDJSON + #include +#endif + #include #include @@ -48,12 +44,6 @@ enum Backend { llvm, cpp, x86 }; -enum ASRPass { - do_loops, global_stmts, implied_do_loops, array_op, - arr_slice, print_arr, class_constructor, unused_functions, - inline_function_calls -}; - std::string remove_extension(const std::string& filename) { size_t lastdot = filename.find_last_of("."); if (lastdot == std::string::npos) return filename; @@ -145,6 +135,7 @@ int emit_ast(const std::string &infile, } int emit_asr(const std::string &infile, + LCompilers::PassManager& pass_manager, const std::string &runtime_library_dir, bool with_intrinsic_modules, CompilerOptions &compiler_options) { @@ -165,13 +156,14 @@ int emit_asr(const std::string &infile, diagnostics.diagnostics.clear(); LFortran::Result r = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, true, - compiler_options.symtab_only); + compiler_options.disable_main, compiler_options.symtab_only, infile); std::cerr << diagnostics.render(input, lm, compiler_options); if (!r.ok) { LFORTRAN_ASSERT(diagnostics.has_error()) return 2; } LFortran::ASR::TranslationUnit_t* asr = r.result; + pass_manager.apply_passes(al, asr, "f", true); if (compiler_options.tree) { std::cout << LFortran::pickle_tree(*asr, compiler_options.use_colors, @@ -204,7 +196,7 @@ int emit_cpp(const std::string &infile, diagnostics.diagnostics.clear(); LFortran::Result r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, true, - compiler_options.symtab_only); + compiler_options.disable_main, compiler_options.symtab_only, infile); std::cerr << diagnostics.render(input, lm, compiler_options); if (!r1.ok) { LFORTRAN_ASSERT(diagnostics.has_error()) @@ -213,7 +205,49 @@ int emit_cpp(const std::string &infile, LFortran::ASR::TranslationUnit_t* asr = r1.result; diagnostics.diagnostics.clear(); - auto res = LFortran::asr_to_cpp(al, *asr, diagnostics); + auto res = LFortran::asr_to_cpp(al, *asr, diagnostics, + compiler_options.platform, 0); + std::cerr << diagnostics.render(input, lm, compiler_options); + if (!res.ok) { + LFORTRAN_ASSERT(diagnostics.has_error()) + return 3; + } + std::cout << res.result; + return 0; +} + +int emit_c(const std::string &infile, + const std::string &runtime_library_dir, + CompilerOptions &compiler_options) +{ + Allocator al(4*1024); + LFortran::diag::Diagnostics diagnostics; + LFortran::LocationManager lm; + lm.in_filename = infile; + std::string input = LFortran::read_file(infile); + lm.init_simple(input); + LFortran::Result r = parse_python_file( + al, runtime_library_dir, infile, diagnostics, compiler_options.new_parser); + std::cerr << diagnostics.render(input, lm, compiler_options); + if (!r.ok) { + return 1; + } + LFortran::LPython::AST::ast_t* ast = r.result; + + diagnostics.diagnostics.clear(); + LFortran::Result + r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, true, + compiler_options.disable_main, compiler_options.symtab_only, infile); + std::cerr << diagnostics.render(input, lm, compiler_options); + if (!r1.ok) { + LFORTRAN_ASSERT(diagnostics.has_error()) + return 2; + } + LFortran::ASR::TranslationUnit_t* asr = r1.result; + + diagnostics.diagnostics.clear(); + auto res = LFortran::asr_to_c(al, *asr, diagnostics, + compiler_options.platform, 0); std::cerr << diagnostics.render(input, lm, compiler_options); if (!res.ok) { LFORTRAN_ASSERT(diagnostics.has_error()) @@ -227,6 +261,7 @@ int emit_cpp(const std::string &infile, int emit_llvm(const std::string &infile, const std::string &runtime_library_dir, + LCompilers::PassManager& pass_manager, CompilerOptions &compiler_options) { Allocator al(4*1024); @@ -247,7 +282,7 @@ int emit_llvm(const std::string &infile, diagnostics.diagnostics.clear(); LFortran::Result r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, true, - compiler_options.symtab_only); + compiler_options.disable_main, compiler_options.symtab_only, infile); std::cerr << diagnostics.render(input, lm, compiler_options); if (!r1.ok) { LFORTRAN_ASSERT(diagnostics.has_error()) @@ -259,7 +294,7 @@ int emit_llvm(const std::string &infile, // ASR -> LLVM LFortran::PythonCompiler fe(compiler_options); LFortran::Result> - res = fe.get_llvm3(*asr, diagnostics); + res = fe.get_llvm3(*asr, pass_manager, diagnostics); std::cerr << diagnostics.render(input, lm, compiler_options); if (!res.ok) { LFORTRAN_ASSERT(diagnostics.has_error()) @@ -281,6 +316,7 @@ int compile_python_to_object_file( const std::string &infile, const std::string &outfile, const std::string &runtime_library_dir, + LCompilers::PassManager& pass_manager, CompilerOptions &compiler_options, bool time_report) { @@ -311,7 +347,7 @@ int compile_python_to_object_file( auto ast_to_asr_start = std::chrono::high_resolution_clock::now(); LFortran::Result r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, true, - compiler_options.symtab_only); + compiler_options.disable_main, compiler_options.symtab_only, infile); auto ast_to_asr_end = std::chrono::high_resolution_clock::now(); times.push_back(std::make_pair("AST to ASR", std::chrono::duration(ast_to_asr_end - ast_to_asr_start).count())); std::cerr << diagnostics.render(input, lm, compiler_options); @@ -329,7 +365,7 @@ int compile_python_to_object_file( std::unique_ptr m; auto asr_to_llvm_start = std::chrono::high_resolution_clock::now(); LFortran::Result> - res = fe.get_llvm3(*asr, diagnostics); + res = fe.get_llvm3(*asr, pass_manager, diagnostics); auto asr_to_llvm_end = std::chrono::high_resolution_clock::now(); times.push_back(std::make_pair("ASR to LLVM", std::chrono::duration(asr_to_llvm_end - asr_to_llvm_start).count())); std::cerr << diagnostics.render(input, lm, compiler_options); @@ -349,6 +385,11 @@ int compile_python_to_object_file( #endif +void do_print_rtlib_header_dir() { + std::string rtlib_header_dir = LFortran::get_runtime_library_header_dir(); + std::cout << rtlib_header_dir << std::endl; +} + // infile is an object file // outfile will become the executable @@ -542,6 +583,7 @@ int main(int argc, char *argv[]) bool show_ast = false; bool show_asr = false; bool show_cpp = false; + bool show_c = false; bool with_intrinsic_modules = false; std::string arg_pass; bool arg_no_color = false; @@ -552,6 +594,7 @@ int main(int argc, char *argv[]) std::string arg_backend = "llvm"; std::string arg_kernel_f; bool print_targets = false; + bool print_rtlib_header_dir = false; std::string arg_fmt_file; // int arg_fmt_indent = 4; @@ -566,7 +609,10 @@ int main(int argc, char *argv[]) std::string arg_pywrap_file; std::string arg_pywrap_array_order="f"; + std::string arg_lsp_filename; + CompilerOptions compiler_options; + LCompilers::PassManager lpython_pass_manager; CLI::App app{"LPython: modern interactive LLVM-based Python compiler"}; // Standard options compatible with gfortran, gcc or clang @@ -595,6 +641,7 @@ int main(int argc, char *argv[]) app.add_flag("--show-asr", show_asr, "Show ASR for the given python file and exit"); app.add_flag("--show-llvm", show_llvm, "Show LLVM IR for the given file and exit"); app.add_flag("--show-cpp", show_cpp, "Show C++ translation source for the given python file and exit"); + app.add_flag("--show-c", show_c, "Show C translation source for the given python file and exit"); app.add_flag("--show-asm", show_asm, "Show assembly for the given file and exit"); app.add_flag("--show-stacktrace", compiler_options.show_stacktrace, "Show internal stacktrace on compiler errors"); app.add_flag("--with-intrinsic-mods", with_intrinsic_modules, "Show intrinsic modules in ASR"); @@ -602,6 +649,7 @@ int main(int argc, char *argv[]) app.add_flag("--indent", compiler_options.indent, "Indented print ASR/AST"); app.add_flag("--tree", compiler_options.tree, "Tree structure print ASR/AST"); app.add_option("--pass", arg_pass, "Apply the ASR pass and show ASR (implies --show-asr)"); + app.add_flag("--disable-main", compiler_options.disable_main, "Do not generate any code for the `main` function"); app.add_flag("--symtab-only", compiler_options.symtab_only, "Only create symbol tables in ASR (skip executable stmt)"); app.add_flag("--time-report", time_report, "Show compilation time report"); app.add_flag("--static", static_link, "Create a static executable"); @@ -612,6 +660,11 @@ int main(int argc, char *argv[]) app.add_flag("--fast", compiler_options.fast, "Best performance (disable strict standard compliance)"); app.add_option("--target", compiler_options.target, "Generate code for the given target")->capture_default_str(); app.add_flag("--print-targets", print_targets, "Print the registered targets"); + app.add_flag("--get-rtlib-header-dir", print_rtlib_header_dir, "Print the path to the runtime library header file"); + + if( compiler_options.fast ) { + lpython_pass_manager.use_optimization_passes(); + } /* * Subcommands: @@ -641,6 +694,10 @@ int main(int argc, char *argv[]) pywrap.add_option("--array-order", arg_pywrap_array_order, "Select array order (c, f)")->capture_default_str(); + // Language Server Protocol + CLI::App &lsp = *app.add_subcommand("lsp", "Language Server Protocol"); + lsp.add_option("filename", arg_lsp_filename, "Path to a filename")->required(); + app.get_formatter()->column_width(25); app.require_subcommand(0, 1); @@ -674,6 +731,11 @@ int main(int argc, char *argv[]) #endif } + if (print_rtlib_header_dir) { + do_print_rtlib_header_dir(); + return 0; + } + compiler_options.use_colors = !arg_no_color; // if (fmt) { @@ -702,6 +764,15 @@ int main(int argc, char *argv[]) return 1; } + if (lsp) { + #ifdef HAVE_LFORTRAN_RAPIDJSON + LPythonServer().run(arg_lsp_filename); + return 0; + #else + std::cerr << "Compiler was not built with LSP support (-DWITH_LSP), please build it again.\n"; + #endif + } + if (arg_backend == "llvm") { backend = Backend::llvm; } else if (arg_backend == "cpp") { @@ -748,32 +819,7 @@ int main(int argc, char *argv[]) // return emit_c_preprocessor(arg_file, compiler_options); // } - std::vector passes; - if (arg_pass != "") { - if (arg_pass == "do_loops") { - passes.push_back(ASRPass::do_loops); - } else if (arg_pass == "global_stmts") { - passes.push_back(ASRPass::global_stmts); - } else if (arg_pass == "implied_do_loops") { - passes.push_back(ASRPass::implied_do_loops); - } else if (arg_pass == "array_op") { - passes.push_back(ASRPass::array_op); - } else if (arg_pass == "inline_function_calls") { - passes.push_back(ASRPass::inline_function_calls); - } else if (arg_pass == "class_constructor") { - passes.push_back(ASRPass::class_constructor); - } else if (arg_pass == "print_arr") { - passes.push_back(ASRPass::print_arr); - } else if (arg_pass == "arr_slice") { - passes.push_back(ASRPass::arr_slice); - } else if (arg_pass == "unused_functions") { - passes.push_back(ASRPass::unused_functions); - } else { - std::cerr << "Pass must be one of: do_loops, global_stmts, implied_do_loops, array_op, class_constructor, print_arr, arr_slice, unused_functions" << std::endl; - return 1; - } - show_asr = true; - } + lpython_pass_manager.parse_pass_arg(arg_pass); if (show_tokens) { return emit_tokens(arg_file, true, compiler_options); } @@ -781,15 +827,19 @@ int main(int argc, char *argv[]) return emit_ast(arg_file, runtime_library_dir, compiler_options); } if (show_asr) { - return emit_asr(arg_file, runtime_library_dir, + return emit_asr(arg_file, lpython_pass_manager, runtime_library_dir, with_intrinsic_modules, compiler_options); } if (show_cpp) { return emit_cpp(arg_file, runtime_library_dir, compiler_options); } + if (show_c) { + return emit_c(arg_file, runtime_library_dir, compiler_options); + } + lpython_pass_manager.use_default_passes(); if (show_llvm) { #ifdef HAVE_LFORTRAN_LLVM - return emit_llvm(arg_file, runtime_library_dir, compiler_options); + return emit_llvm(arg_file, runtime_library_dir, lpython_pass_manager, compiler_options); #else std::cerr << "The --show-llvm option requires the LLVM backend to be enabled. Recompile with `WITH_LLVM=yes`." << std::endl; return 1; @@ -814,7 +864,7 @@ int main(int argc, char *argv[]) if (arg_c) { if (backend == Backend::llvm) { #ifdef HAVE_LFORTRAN_LLVM - return compile_python_to_object_file(arg_file, outfile, runtime_library_dir, compiler_options, time_report); + return compile_python_to_object_file(arg_file, outfile, runtime_library_dir, lpython_pass_manager, compiler_options, time_report); #else std::cerr << "The -c option requires the LLVM backend to be enabled. Recompile with `WITH_LLVM=yes`." << std::endl; return 1; @@ -830,7 +880,7 @@ int main(int argc, char *argv[]) int err; if (backend == Backend::llvm) { #ifdef HAVE_LFORTRAN_LLVM - err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir, compiler_options, time_report); + err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir, lpython_pass_manager, compiler_options, time_report); #else std::cerr << "Compiling Python files to object files requires the LLVM backend to be enabled. Recompile with `WITH_LLVM=yes`." << std::endl; return 1; diff --git a/src/libasr/ASR.asdl b/src/libasr/ASR.asdl index cb1d693d84..1ba7d15234 100644 --- a/src/libasr/ASR.asdl +++ b/src/libasr/ASR.asdl @@ -154,7 +154,7 @@ abi -- External ABI stmt - = Allocate(alloc_arg* args, expr? stat, expr? errmsg) + = Allocate(alloc_arg* args, expr? stat, expr? errmsg, expr? source) | Assign(int label, identifier variable) | Assignment(expr target, expr value, stmt? overloaded) | Associate(expr target, expr value) @@ -177,7 +177,7 @@ stmt | GoToTarget(int id) | If(expr test, stmt* body, stmt* orelse) | IfArithmetic(expr test, int lt_label, int eq_label, int gt_label) - | Print(expr? fmt, expr* values) + | Print(expr? fmt, expr* values, expr? separator, expr? end) | FileOpen(int label, expr? newunit, expr? filename, expr? status) | FileClose(int label, expr? unit, expr? iostat, expr? iomsg, expr? err, expr? status) | FileRead(int label, expr? unit, expr? fmt, expr? iomsg, expr? iostat, expr? id, expr* values) @@ -190,7 +190,7 @@ stmt expr? read, expr? write, expr? readwrite, expr? delim, expr? pad, expr? flen, expr? blocksize, expr? convert, expr? carriagecontrol, expr? iolength) - | FileWrite(int label, expr? unit, expr? fmt, expr? iomsg, expr? iostat, expr? id, expr* values) + | FileWrite(int label, expr? unit, expr? fmt, expr? iomsg, expr? iostat, expr? id, expr* values, expr? separator, expr? end) | Return() | Select(expr test, case_stmt* body, stmt* default) | Stop(expr? code) @@ -200,35 +200,45 @@ stmt | WhileLoop(expr test, stmt* body) | Nullify(symbol* vars) | Flush(int label, expr unit, expr? err, expr? iomsg, expr? iostat) - | ListAppend(symbol a, expr ele) + | ListAppend(expr a, expr ele) | AssociateBlockCall(symbol m) - | BlockCall(symbol m) - | SetInsert(symbol a, expr ele) - | SetRemove(symbol a, expr ele) - | ListInsert(symbol a, expr pos, expr ele) - | ListRemove(symbol a, expr ele) - | DictInsert(symbol a, expr key, expr value) + | CPtrToPointer(expr cptr, expr ptr, expr? shape) + | BlockCall(int label, symbol m) + | SetInsert(expr a, expr ele) + | SetRemove(expr a, expr ele) + | ListInsert(expr a, expr pos, expr ele) + | ListRemove(expr a, expr ele) + | DictInsert(expr a, expr key, expr value) expr - = BoolOp(expr left, boolop op, expr right, ttype type, expr? value) - | BinOp(expr left, binop op, expr right, ttype type, expr? value, expr? overloaded) - | UnaryOp(unaryop op, expr operand, ttype type, expr? value) + = IfExp(expr test, expr body, expr orelse, ttype type, expr? value) -- Such as: (x, y+z), (3.0, 2.0) generally not known at compile time | ComplexConstructor(expr re, expr im, ttype type, expr? value) | NamedExpr(expr target, expr value, ttype type) - | Compare(expr left, cmpop op, expr right, ttype type, expr? value, expr? overloaded) - | IfExp(expr test, expr body, expr orelse, ttype type) | FunctionCall(symbol name, symbol? original_name, call_arg* args, ttype type, expr? value, expr? dt) - | DerivedTypeConstructor(symbol dt_sym, expr* args, ttype type) + | DerivedTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value) | ImpliedDoLoop(expr* values, expr var, expr start, expr end, expr? increment, ttype type, expr? value) | IntegerConstant(int n, ttype type) | IntegerBOZ(int v, integerboz intboz_type, ttype? type) + | IntegerBitNot(expr arg, ttype type, expr? value) + | IntegerUnaryMinus(expr arg, ttype type, expr? value) + | IntegerCompare(expr left, cmpop op, expr right, ttype type, expr? value) + | IntegerBinOp(expr left, binop op, expr right, ttype type, expr? value) | RealConstant(float r, ttype type) + | RealUnaryMinus(expr arg, ttype type, expr? value) + | RealCompare(expr left, cmpop op, expr right, ttype type, expr? value) + | RealBinOp(expr left, binop op, expr right, ttype type, expr? value) | ComplexConstant(float re, float im, ttype type) + | ComplexUnaryMinus(expr arg, ttype type, expr? value) + | ComplexCompare(expr left, cmpop op, expr right, ttype type, expr? value) + | ComplexBinOp(expr left, binop op, expr right, ttype type, expr? value) | LogicalConstant(bool value, ttype type) + | LogicalNot(expr arg, ttype type, expr? value) + | LogicalCompare(expr left, cmpop op, expr right, ttype type, expr? value) + | LogicalBinOp(expr left, logicalbinop op, expr right, ttype type, expr? value) | ListConstant(expr* args, ttype type) | ListLen(expr arg, ttype type, expr? value) @@ -248,25 +258,37 @@ expr | StringLen(expr arg, ttype type, expr? value) | StringItem(expr arg, expr idx, ttype type, expr? value) | StringSection(expr arg, expr start, expr end, expr step, ttype type, expr? value) + | StringCompare(expr left, cmpop op, expr right, ttype type, expr? value) | DictConstant(expr* keys, expr* values, ttype type) | DictLen(expr arg, ttype type, expr? value) | Var(symbol v) - | ArrayRef(symbol v, array_index* args, ttype type, expr? value) + | ArrayItem(expr v, array_index* args, ttype type, expr? value) + | ArraySection(expr v, array_index* args, ttype type, expr? value) | ArraySize(expr v, expr? dim, ttype type, expr? value) - | ArrayBound(expr v, expr? dim ttype type, arraybound bound, + | ArrayBound(expr v, expr? dim, ttype type, arraybound bound, expr? value) + | ArrayTranspose(expr matrix, ttype type, expr? value) + | ArrayMatMul(expr matrix_a, expr matrix_b, ttype type, expr? value) + | ArrayPack(expr array, expr mask, expr? vector, ttype type, expr? value) + | BitCast(expr source, expr mold, expr? size, ttype type, expr? value) | DerivedRef(expr v, symbol m, ttype type, expr? value) + | OverloadedCompare(expr left, cmpop op, expr right, ttype type, expr? value, expr overloaded) + | OverloadedBinOp(expr left, binop op, expr right, ttype type, expr? value, expr overloaded) | Cast(expr arg, cast_kind kind, ttype type, expr? value) | ComplexRe(expr arg, ttype type, expr? value) | ComplexIm(expr arg, ttype type, expr? value) - | DictItem(symbol a, expr key, expr? default, ttype type) - | ListItem(symbol a, expr pos, ttype type, expr? value) - | TupleItem(symbol a, expr pos, ttype type, expr? value) + | DictItem(expr a, expr key, expr? default, ttype type, expr? value) + | CLoc(expr arg, ttype type, expr? value) + | PointerToCPtr(expr arg, ttype type, expr? value) + | GetPointer(expr arg, ttype type, expr? value) + | ListItem(expr a, expr pos, ttype type, expr? value) + | TupleItem(expr a, expr pos, ttype type, expr? value) | ListSection(expr a, array_index section, ttype type, expr? value) - | ListPop(symbol a, expr? index, ttype type, expr? value) - | DictPop(symbol a, expr key, ttype type, expr? value) - | SetPop(symbol a, ttype type, expr? value) + | ListPop(expr a, expr? index, ttype type, expr? value) + | DictPop(expr a, expr key, ttype type, expr? value) + | SetPop(expr a, ttype type, expr? value) + -- `len` in Character: -- >=0 ... the length of the string, known at compile time @@ -300,12 +322,11 @@ ttype | Class(symbol class_type, dimension* dims) | Dict(ttype key_type, ttype value_type) | Pointer(ttype type) + | CPtr() -boolop = And | Or | Xor | NEqv | Eqv - -binop = Add | Sub | Mul | Div | Pow +binop = Add | Sub | Mul | Div | Pow | BitAnd | BitOr | BitXor | BitLShift | BitRShift -unaryop = Invert | Not | UAdd | USub +logicalbinop = And | Or | Xor | NEqv | Eqv cmpop = Eq | NotEq | Lt | LtE | Gt | GtE @@ -316,11 +337,15 @@ arraybound = LBound | UBound cast_kind = RealToInteger | IntegerToReal + | LogicalToReal | RealToReal | IntegerToInteger | RealToComplex | IntegerToComplex | IntegerToLogical + | RealToLogical + | CharacterToLogical + | ComplexToLogical | ComplexToComplex | ComplexToReal | LogicalToInteger diff --git a/src/libasr/CMakeLists.txt b/src/libasr/CMakeLists.txt index 96334a860f..7b955535e9 100644 --- a/src/libasr/CMakeLists.txt +++ b/src/libasr/CMakeLists.txt @@ -16,11 +16,14 @@ configure_file(config.h.in config.h) set(SRC codegen/asr_to_cpp.cpp + codegen/asr_to_c.cpp codegen/asr_to_py.cpp codegen/x86_assembler.cpp codegen/asr_to_x86.cpp codegen/asr_to_wasm.cpp - + codegen/wasm_to_wat.cpp + codegen/wasm_utils.cpp + pass/param_to_const.cpp pass/do_loops.cpp pass/for_all.cpp @@ -37,6 +40,7 @@ set(SRC pass/flip_sign.cpp pass/div_to_mul.cpp pass/fma.cpp + pass/loop_vectorise.cpp pass/sign_from_value.cpp pass/inline_function_calls.cpp pass/loop_unroll.cpp @@ -72,6 +76,14 @@ if (WITH_LLVM) COMPILE_FLAGS -Wno-deprecated-declarations) endif() endif() + +if (WITH_LSP) + set (SRC ${SRC} + lsp/JSONRPC2Connection.cpp + lsp/LPythonServer.cpp + ) +endif() + add_library(asr ${SRC}) target_include_directories(asr BEFORE PUBLIC ${libasr_SOURCE_DIR}/..) target_include_directories(asr BEFORE PUBLIC ${libasr_BINARY_DIR}/..) diff --git a/src/libasr/asr_scopes.h b/src/libasr/asr_scopes.h index e928b8928b..8323872212 100644 --- a/src/libasr/asr_scopes.h +++ b/src/libasr/asr_scopes.h @@ -47,7 +47,7 @@ struct SymbolTable { return scope[name]; } - const std::map& get_scope() { + const std::map& get_scope() const { return scope; } diff --git a/src/libasr/asr_utils.cpp b/src/libasr/asr_utils.cpp index 0f4be3cf2f..6771d9f366 100644 --- a/src/libasr/asr_utils.cpp +++ b/src/libasr/asr_utils.cpp @@ -179,6 +179,7 @@ void set_intrinsic(ASR::symbol_t* sym) { switch( sym->type ) { case ASR::symbolType::Module: { ASR::Module_t* module_sym = ASR::down_cast(sym); + module_sym->m_intrinsic = true; for( auto& itr: module_sym->m_symtab->get_scope() ) { set_intrinsic(itr.second); } @@ -241,9 +242,10 @@ ASR::asr_t* getDerivedRef_t(Allocator& al, const Location& loc, ASR::ttype_t* member_type = member_variable->m_type; switch( member_type->type ) { case ASR::ttypeType::Derived: { - ASR::Derived_t* der = (ASR::Derived_t*)(&(member_type->base)); - ASR::DerivedType_t* der_type = (ASR::DerivedType_t*)(&(der->m_derived_type->base)); - if( der_type->m_symtab->counter != current_scope->counter ) { + ASR::Derived_t* der = ASR::down_cast(member_type); + std::string der_type_name = ASRUtils::symbol_name(der->m_derived_type); + ASR::symbol_t* der_type_sym = current_scope->resolve_symbol(der_type_name); + if( der_type_sym == nullptr ) { ASR::symbol_t* der_ext; char* module_name = (char*)"~nullptr"; ASR::symbol_t* m_external = der->m_derived_type; @@ -255,13 +257,13 @@ ASR::asr_t* getDerivedRef_t(Allocator& al, const Location& loc, Str mangled_name; mangled_name.from_str(al, "1_" + std::string(module_name) + "_" + - std::string(der_type->m_name)); + std::string(der_type_name)); char* mangled_name_char = mangled_name.c_str(al); if( current_scope->get_symbol(mangled_name.str()) == nullptr ) { bool make_new_ext_sym = true; ASR::symbol_t* der_tmp = nullptr; - if( current_scope->get_symbol(std::string(der_type->m_name)) != nullptr ) { - der_tmp = current_scope->get_symbol(std::string(der_type->m_name)); + if( current_scope->get_symbol(std::string(der_type_name)) != nullptr ) { + der_tmp = current_scope->get_symbol(std::string(der_type_name)); if( der_tmp->type == ASR::symbolType::ExternalSymbol ) { ASR::ExternalSymbol_t* der_ext_tmp = (ASR::ExternalSymbol_t*)(&(der_tmp->base)); if( der_ext_tmp->m_external == m_external ) { @@ -273,7 +275,7 @@ ASR::asr_t* getDerivedRef_t(Allocator& al, const Location& loc, } if( make_new_ext_sym ) { der_ext = (ASR::symbol_t*)ASR::make_ExternalSymbol_t(al, loc, current_scope, mangled_name_char, m_external, - module_name, nullptr, 0, der_type->m_name, ASR::accessType::Public); + module_name, nullptr, 0, s2c(al, der_type_name), ASR::accessType::Public); current_scope->add_symbol(mangled_name.str(), der_ext); } else { LFORTRAN_ASSERT(der_tmp != nullptr); @@ -283,7 +285,10 @@ ASR::asr_t* getDerivedRef_t(Allocator& al, const Location& loc, der_ext = current_scope->get_symbol(mangled_name.str()); } ASR::asr_t* der_new = ASR::make_Derived_t(al, loc, der_ext, der->m_dims, der->n_dims); - member_type = (ASR::ttype_t*)(der_new); + member_type = ASRUtils::TYPE(der_new); + } else if(ASR::is_a(*der_type_sym)) { + member_type = ASRUtils::TYPE(ASR::make_Derived_t(al, loc, der_type_sym, + der->m_dims, der->n_dims)); } break; } @@ -302,7 +307,7 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right, ASR::ttype_t *right_type = LFortran::ASRUtils::expr_type(right); bool found = false; if( is_op_overloaded(op, intrinsic_op_name, curr_scope) ) { - ASR::symbol_t* sym = curr_scope->get_symbol(intrinsic_op_name); + ASR::symbol_t* sym = curr_scope->resolve_symbol(intrinsic_op_name); ASR::symbol_t* orig_sym = ASRUtils::symbol_get_past_external(sym); ASR::CustomOperator_t* gen_proc = ASR::down_cast(orig_sym); for( size_t i = 0; i < gen_proc->n_procs && !found; i++ ) { @@ -310,6 +315,7 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right, switch(proc->type) { case ASR::symbolType::Function: { ASR::Function_t* func = ASR::down_cast(proc); + std::string matched_func_name = ""; if( func->n_args == 2 ) { ASR::ttype_t* left_arg_type = ASRUtils::expr_type(func->m_args[0]); ASR::ttype_t* right_arg_type = ASRUtils::expr_type(func->m_args[1]); @@ -323,7 +329,18 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right, a_args.push_back(al, left_call_arg); right_call_arg.loc = right->base.loc, right_call_arg.m_value = right; a_args.push_back(al, right_call_arg); - asr = ASR::make_FunctionCall_t(al, loc, curr_scope->get_symbol(std::string(func->m_name)), orig_sym, + std::string func_name = to_lower(func->m_name); + if( curr_scope->resolve_symbol(func_name) ) { + matched_func_name = func_name; + } else { + std::string mangled_name = func_name + "@" + intrinsic_op_name; + matched_func_name = mangled_name; + } + ASR::symbol_t* a_name = curr_scope->resolve_symbol(matched_func_name); + if( a_name == nullptr ) { + err("Unable to resolve matched function for operator overloading, " + matched_func_name, loc); + } + asr = ASR::make_FunctionCall_t(al, loc, a_name, sym, a_args.p, 2, ASRUtils::expr_type(func->m_return_var), nullptr, nullptr); @@ -375,6 +392,9 @@ bool is_op_overloaded(ASR::binopType op, std::string& intrinsic_op_name, } break; } + default: { + throw LFortranException("Binary operator '" + ASRUtils::binop_to_str_python(op) + "' not supported yet"); + } } if( result && curr_scope->get_symbol(intrinsic_op_name) == nullptr ) { result = false; @@ -416,24 +436,13 @@ bool use_overloaded_assignment(ASR::expr_t* target, ASR::expr_t* value, } else { std::string mangled_name = subrout_name + "@~assign"; matched_subrout_name = mangled_name; - ASR::symbol_t* imported_subrout = nullptr; - if( sym->type == ASR::symbolType::ExternalSymbol && - curr_scope->resolve_symbol(mangled_name) == nullptr) { - ASR::ExternalSymbol_t* ext_sym = ASR::down_cast(sym); - imported_subrout = ASR::down_cast( - ASR::make_ExternalSymbol_t(al, - loc, curr_scope, - s2c(al, mangled_name), proc, - ext_sym->m_module_name, nullptr, 0, - subrout->m_name, ASR::accessType::Private)); - curr_scope->add_symbol(mangled_name, imported_subrout); - } } - if( curr_scope->resolve_symbol(matched_subrout_name) == nullptr ) { - err("Unable to resolve matched subroutine for assignment overloading, " + std::string(matched_subrout_name), loc); + ASR::symbol_t *a_name = curr_scope->resolve_symbol(matched_subrout_name); + if( a_name == nullptr ) { + err("Unable to resolve matched subroutine for assignment overloading, " + matched_subrout_name, loc); } - asr = ASR::make_SubroutineCall_t(al, loc, curr_scope->resolve_symbol(matched_subrout_name), orig_sym, - a_args.p, 2, nullptr); + asr = ASR::make_SubroutineCall_t(al, loc, a_name, sym, + a_args.p, 2, nullptr); } } } @@ -458,6 +467,7 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right, switch(proc->type) { case ASR::symbolType::Function: { ASR::Function_t* func = ASR::down_cast(proc); + std::string matched_func_name = ""; if( func->n_args == 2 ) { ASR::ttype_t* left_arg_type = ASRUtils::expr_type(func->m_args[0]); ASR::ttype_t* right_arg_type = ASRUtils::expr_type(func->m_args[1]); @@ -471,7 +481,18 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right, a_args.push_back(al, left_call_arg); right_call_arg.loc = right->base.loc, right_call_arg.m_value = right; a_args.push_back(al, right_call_arg); - asr = ASR::make_FunctionCall_t(al, loc, curr_scope->resolve_symbol(std::string(func->m_name)), orig_sym, + std::string func_name = to_lower(func->m_name); + if( curr_scope->resolve_symbol(func_name) ) { + matched_func_name = func_name; + } else { + std::string mangled_name = func_name + "@" + intrinsic_op_name; + matched_func_name = mangled_name; + } + ASR::symbol_t* a_name = curr_scope->resolve_symbol(matched_func_name); + if( a_name == nullptr ) { + err("Unable to resolve matched function for operator overloading, " + matched_func_name, loc); + } + asr = ASR::make_FunctionCall_t(al, loc, a_name, sym, a_args.p, 2, ASRUtils::expr_type(func->m_return_var), nullptr, nullptr); @@ -536,13 +557,26 @@ bool is_op_overloaded(ASR::cmpopType op, std::string& intrinsic_op_name, return result; } +bool is_parent(ASR::DerivedType_t* a, ASR::DerivedType_t* b) { + ASR::symbol_t* current_parent = b->m_parent; + while( current_parent ) { + if( current_parent == (ASR::symbol_t*) a ) { + return true; + } + LFORTRAN_ASSERT(ASR::is_a(*current_parent)); + current_parent = ASR::down_cast(current_parent)->m_parent; + } + return false; +} + +bool is_derived_type_similar(ASR::DerivedType_t* a, ASR::DerivedType_t* b) { + return a == b || is_parent(a, b) || is_parent(b, a); +} + bool types_equal(const ASR::ttype_t &a, const ASR::ttype_t &b) { // TODO: If anyone of the input or argument is derived type then // add support for checking member wise types and do not compare // directly. From stdlib_string len(pattern) error. - if (b.type == ASR::ttypeType::Derived || b.type == ASR::ttypeType::Class) { - return true; - } if (a.type == b.type) { // TODO: check dims // TODO: check all types @@ -597,8 +631,74 @@ bool types_equal(const ASR::ttype_t &a, const ASR::ttype_t &b) { } break; } + case (ASR::ttypeType::Derived) : { + ASR::Derived_t *a2 = ASR::down_cast(&a); + ASR::Derived_t *b2 = ASR::down_cast(&b); + ASR::DerivedType_t *a2_type = ASR::down_cast( + ASRUtils::symbol_get_past_external( + a2->m_derived_type)); + ASR::DerivedType_t *b2_type = ASR::down_cast( + ASRUtils::symbol_get_past_external( + b2->m_derived_type)); + return a2_type == b2_type; + } + case (ASR::ttypeType::Class) : { + ASR::Class_t *a2 = ASR::down_cast(&a); + ASR::Class_t *b2 = ASR::down_cast(&b); + ASR::symbol_t* a2_typesym = ASRUtils::symbol_get_past_external(a2->m_class_type); + ASR::symbol_t* b2_typesym = ASRUtils::symbol_get_past_external(b2->m_class_type); + if( a2_typesym->type != b2_typesym->type ) { + return false; + } + if( a2_typesym->type == ASR::symbolType::ClassType ) { + ASR::ClassType_t *a2_type = ASR::down_cast(a2_typesym); + ASR::ClassType_t *b2_type = ASR::down_cast(b2_typesym); + return a2_type == b2_type; + } else if( a2_typesym->type == ASR::symbolType::DerivedType ) { + ASR::DerivedType_t *a2_type = ASR::down_cast(a2_typesym); + ASR::DerivedType_t *b2_type = ASR::down_cast(b2_typesym); + return is_derived_type_similar(a2_type, b2_type); + } + return false; + } default : return false; } + } else if( a.type == ASR::ttypeType::Derived && + b.type == ASR::ttypeType::Class ) { + ASR::Derived_t *a2 = ASR::down_cast(&a); + ASR::Class_t *b2 = ASR::down_cast(&b); + ASR::symbol_t* a2_typesym = ASRUtils::symbol_get_past_external(a2->m_derived_type); + ASR::symbol_t* b2_typesym = ASRUtils::symbol_get_past_external(b2->m_class_type); + if( a2_typesym->type != b2_typesym->type ) { + return false; + } + if( a2_typesym->type == ASR::symbolType::ClassType ) { + ASR::ClassType_t *a2_type = ASR::down_cast(a2_typesym); + ASR::ClassType_t *b2_type = ASR::down_cast(b2_typesym); + return a2_type == b2_type; + } else if( a2_typesym->type == ASR::symbolType::DerivedType ) { + ASR::DerivedType_t *a2_type = ASR::down_cast(a2_typesym); + ASR::DerivedType_t *b2_type = ASR::down_cast(b2_typesym); + return is_derived_type_similar(a2_type, b2_type); + } + } else if( a.type == ASR::ttypeType::Class && + b.type == ASR::ttypeType::Derived ) { + ASR::Class_t *a2 = ASR::down_cast(&a); + ASR::Derived_t *b2 = ASR::down_cast(&b); + ASR::symbol_t* a2_typesym = ASRUtils::symbol_get_past_external(a2->m_class_type); + ASR::symbol_t* b2_typesym = ASRUtils::symbol_get_past_external(b2->m_derived_type); + if( a2_typesym->type != b2_typesym->type ) { + return false; + } + if( a2_typesym->type == ASR::symbolType::ClassType ) { + ASR::ClassType_t *a2_type = ASR::down_cast(a2_typesym); + ASR::ClassType_t *b2_type = ASR::down_cast(b2_typesym); + return a2_type == b2_type; + } else if( a2_typesym->type == ASR::symbolType::DerivedType ) { + ASR::DerivedType_t *a2_type = ASR::down_cast(a2_typesym); + ASR::DerivedType_t *b2_type = ASR::down_cast(b2_typesym); + return is_derived_type_similar(a2_type, b2_type); + } } return false; } @@ -651,7 +751,8 @@ bool select_func_subrout(const ASR::symbol_t* proc, const Vec& int select_generic_procedure(const Vec& args, const ASR::GenericProcedure_t &p, Location loc, - const std::function err) { + const std::function err, + bool raise_error) { for (size_t i=0; i < p.n_procs; i++) { if( ASR::is_a(*p.m_procs[i]) ) { ASR::ClassProcedure_t *clss_fn @@ -666,7 +767,9 @@ int select_generic_procedure(const Vec& args, } } } - err("Arguments do not match for any generic procedure", loc); + if( raise_error ) { + err("Arguments do not match for any generic procedure, " + std::string(p.m_name), loc); + } return -1; } @@ -780,6 +883,9 @@ ASR::asr_t* make_Cast_t_value(Allocator &al, const Location &a_loc, return ASR::make_Cast_t(al, a_loc, a_arg, a_kind, a_type, value); } +//Initialize pointer to zero so that it can be initialized in first call to get_instance +ASRUtils::LabelGenerator* ASRUtils::LabelGenerator::label_generator = nullptr; + } // namespace ASRUtils diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index a097051edb..b6fcdc89a3 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -39,7 +40,7 @@ static inline ASR::ttype_t* TYPE(const ASR::asr_t *f) static inline ASR::symbol_t *symbol_get_past_external(ASR::symbol_t *f) { - if (f->type == ASR::symbolType::ExternalSymbol) { + if (f && f->type == ASR::symbolType::ExternalSymbol) { ASR::ExternalSymbol_t *e = ASR::down_cast(f); LFORTRAN_ASSERT(!ASR::is_a(*e->m_external)); return e->m_external; @@ -91,56 +92,21 @@ static inline ASR::Subroutine_t* EXPR2SUB(const ASR::expr_t *f) static inline ASR::ttype_t* expr_type(const ASR::expr_t *f) { - LFORTRAN_ASSERT(f != nullptr); - switch (f->type) { - case ASR::exprType::BoolOp: { return ((ASR::BoolOp_t*)f)->m_type; } - case ASR::exprType::BinOp: { return ((ASR::BinOp_t*)f)->m_type; } - case ASR::exprType::UnaryOp: { return ((ASR::UnaryOp_t*)f)->m_type; } - case ASR::exprType::ComplexConstructor: { return ((ASR::ComplexConstructor_t*)f)->m_type; } - case ASR::exprType::NamedExpr: { return ((ASR::NamedExpr_t*)f)->m_type; } - case ASR::exprType::Compare: { return ((ASR::Compare_t*)f)->m_type; } - case ASR::exprType::IfExp: { return ((ASR::IfExp_t*)f)->m_type; } - case ASR::exprType::FunctionCall: { return ((ASR::FunctionCall_t*)f)->m_type; } - case ASR::exprType::DerivedTypeConstructor: { return ((ASR::DerivedTypeConstructor_t*)f)->m_type; } - case ASR::exprType::ArrayConstant: { return ((ASR::ArrayConstant_t*)f)->m_type; } - case ASR::exprType::ImpliedDoLoop: { return ((ASR::ImpliedDoLoop_t*)f)->m_type; } - case ASR::exprType::IntegerConstant: { return ((ASR::IntegerConstant_t*)f)->m_type; } - case ASR::exprType::RealConstant: { return ((ASR::RealConstant_t*)f)->m_type; } - case ASR::exprType::ComplexConstant: { return ((ASR::ComplexConstant_t*)f)->m_type; } - case ASR::exprType::SetConstant: { return ((ASR::SetConstant_t*)f)->m_type; } - case ASR::exprType::SetLen: { return ((ASR::SetLen_t*)f)->m_type; } - case ASR::exprType::ListConstant: { return ((ASR::ListConstant_t*)f)->m_type; } - case ASR::exprType::ListConcat: { return ((ASR::ListConcat_t*)f)->m_type; } - case ASR::exprType::ListLen: { return ((ASR::ListLen_t*)f)->m_type; } - case ASR::exprType::TupleConstant: { return ((ASR::TupleConstant_t*)f)->m_type; } - case ASR::exprType::TupleLen: { return ((ASR::TupleLen_t*)f)->m_type; } - case ASR::exprType::LogicalConstant: { return ((ASR::LogicalConstant_t*)f)->m_type; } - case ASR::exprType::StringConstant: { return ((ASR::StringConstant_t*)f)->m_type; } - case ASR::exprType::StringConcat: { return ((ASR::StringConcat_t*)f)->m_type; } - case ASR::exprType::StringRepeat: { return ((ASR::StringRepeat_t*)f)->m_type; } - case ASR::exprType::StringLen: { return ((ASR::StringLen_t*)f)->m_type; } - case ASR::exprType::StringItem: { return ((ASR::StringItem_t*)f)->m_type; } - case ASR::exprType::StringSection: { return ((ASR::StringSection_t*)f)->m_type; } - case ASR::exprType::DictConstant: { return ((ASR::DictConstant_t*)f)->m_type; } - case ASR::exprType::DictLen: { return ((ASR::DictLen_t*)f)->m_type; } - case ASR::exprType::IntegerBOZ: { return ((ASR::IntegerBOZ_t*)f)->m_type; } - case ASR::exprType::Var: { return EXPR2VAR(f)->m_type; } - case ASR::exprType::ArrayRef: { return ((ASR::ArrayRef_t*)f)->m_type; } - case ASR::exprType::ArraySize: { return ((ASR::ArraySize_t*)f)->m_type; } - case ASR::exprType::ArrayBound: { return ((ASR::ArrayBound_t*)f)->m_type; } - case ASR::exprType::DerivedRef: { return ((ASR::DerivedRef_t*)f)->m_type; } - case ASR::exprType::Cast: { return ((ASR::Cast_t*)f)->m_type; } - case ASR::exprType::ComplexRe: { return ((ASR::ComplexRe_t*)f)->m_type; } - case ASR::exprType::ComplexIm: { return ((ASR::ComplexIm_t*)f)->m_type; } - case ASR::exprType::DictItem: { return ((ASR::DictItem_t*)f)->m_type; } - case ASR::exprType::ListItem: { return ((ASR::ListItem_t*)f)->m_type; } - case ASR::exprType::TupleItem: { return ((ASR::TupleItem_t*)f)->m_type; } - case ASR::exprType::ListSection: { return ((ASR::ListSection_t*)f)->m_type; } - case ASR::exprType::ListPop: { return ((ASR::ListPop_t*)f)->m_type; } - case ASR::exprType::DictPop: { return ((ASR::DictPop_t*)f)->m_type; } - case ASR::exprType::SetPop: { return ((ASR::SetPop_t*)f)->m_type; } - default : throw LFortranException("Not implemented"); + return ASR::expr_type0(f); +} + +static inline ASR::ttype_t* symbol_type(const ASR::symbol_t *f) +{ + switch( f->type ) { + case ASR::symbolType::Variable: { + return ASR::down_cast(f)->m_type; + } + default: { + throw LFortranException("Cannot return type of, " + + std::to_string(f->type) + " symbol."); + } } + return nullptr; } static inline std::string type_to_str(const ASR::ttype_t *t) @@ -173,80 +139,17 @@ static inline std::string type_to_str(const ASR::ttype_t *t) case ASR::ttypeType::List: { return "list"; } - default : throw LFortranException("Not implemented"); - } -} - -static inline std::string type_to_str_python(const ASR::ttype_t *t) -{ - switch (t->type) { - case ASR::ttypeType::Integer: { - ASR::Integer_t *i = (ASR::Integer_t*)t; - switch (i->m_kind) { - case 1: { return "i8"; } - case 2: { return "i16"; } - case 4: { return "i32"; } - case 8: { return "i64"; } - default: { throw LFortranException("Integer kind not supported"); } - } - } - case ASR::ttypeType::Real: { - ASR::Real_t *r = (ASR::Real_t*)t; - switch (r->m_kind) { - case 4: { return "f32"; } - case 8: { return "f64"; } - default: { throw LFortranException("Float kind not supported"); } - } - } - case ASR::ttypeType::Complex: { - ASR::Complex_t *c = (ASR::Complex_t*)t; - switch (c->m_kind) { - case 4: { return "c32"; } - case 8: { return "c64"; } - default: { throw LFortranException("Complex kind not supported"); } - } - } - case ASR::ttypeType::Logical: { - return "bool"; - } - case ASR::ttypeType::Character: { - return "str"; - } - case ASR::ttypeType::Tuple: { - ASR::Tuple_t *tup = ASR::down_cast(t); - std::string result = "tuple["; - for (size_t i=0; in_type; i++) { - result += type_to_str_python(tup->m_type[i]); - if (i+1 != tup->n_type) { - result += ", "; - } - } - result += "]"; - return result; - } - case ASR::ttypeType::Set: { - ASR::Set_t *s = (ASR::Set_t *)t; - return "set[" + type_to_str_python(s->m_type) + "]"; + case ASR::ttypeType::Derived: { + return "derived type"; } - case ASR::ttypeType::Dict: { - ASR::Dict_t *d = (ASR::Dict_t *)t; - return "dict[" + type_to_str_python(d->m_key_type) + ", " + type_to_str_python(d->m_value_type) + "]"; + case ASR::ttypeType::CPtr: { + return "type(c_ptr)"; } - case ASR::ttypeType::List: { - ASR::List_t *l = (ASR::List_t *)t; - return "list[" + type_to_str_python(l->m_type) + "]"; + case ASR::ttypeType::Pointer: { + return type_to_str(ASRUtils::type_get_past_pointer( + const_cast(t))) + " pointer"; } - default : throw LFortranException("Not implemented"); - } -} - -static inline std::string unop_to_str(const ASR::unaryopType t) { - switch (t) { - case (ASR::unaryopType::Not): { return "!"; } - case (ASR::unaryopType::USub): { return "-"; } - case (ASR::unaryopType::UAdd): { return "+"; } - case (ASR::unaryopType::Invert): {return "~"; } - default : throw LFortranException("Not implemented"); + default : throw LFortranException("Not implemented " + std::to_string(t->type) + "."); } } @@ -272,64 +175,19 @@ static inline std::string cmpop_to_str(const ASR::cmpopType t) { } } -static inline std::string boolop_to_str(const ASR::boolopType t) { +static inline std::string logicalbinop_to_str_python(const ASR::logicalbinopType t) { switch (t) { - case (ASR::boolopType::And): { return " && "; } - case (ASR::boolopType::Or): { return " || "; } - case (ASR::boolopType::Eqv): { return " == "; } - case (ASR::boolopType::NEqv): { return " != "; } + case (ASR::logicalbinopType::And): { return " && "; } + case (ASR::logicalbinopType::Or): { return " || "; } + case (ASR::logicalbinopType::Eqv): { return " == "; } + case (ASR::logicalbinopType::NEqv): { return " != "; } default : throw LFortranException("Cannot represent the boolean operator as a string"); } } static inline ASR::expr_t* expr_value(ASR::expr_t *f) { - switch (f->type) { - case ASR::exprType::BoolOp: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::BinOp: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::UnaryOp: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ComplexConstructor: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::Compare: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::FunctionCall: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ArrayRef: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ArraySize: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ArrayBound: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::DerivedRef: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::Cast: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::Var: { return EXPR2VAR(f)->m_value; } - case ASR::exprType::ImpliedDoLoop: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::StringLen: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::StringItem: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::StringSection: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::DictLen: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ListLen: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::TupleLen: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::SetLen: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::StringConcat: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::StringRepeat: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ComplexRe: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ComplexIm: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ListItem: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::TupleItem: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ListSection: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::ListPop: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::DictPop: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::SetPop: { return ASR::down_cast(f)->m_value; } - case ASR::exprType::DictItem: // Drop through - case ASR::exprType::ArrayConstant: // Drop through - case ASR::exprType::IntegerConstant: // Drop through - case ASR::exprType::RealConstant: // Drop through - case ASR::exprType::ComplexConstant: // Drop through - case ASR::exprType::LogicalConstant: // Drop through - case ASR::exprType::TupleConstant: // Drop through - case ASR::exprType::DictConstant: // Drop through - case ASR::exprType::SetConstant: // Drop through - case ASR::exprType::ListConstant: // Drop through - case ASR::exprType::StringConstant:{ // For all Constants - return f; - } - default : throw LFortranException("Not implemented"); - } + return ASR::expr_value0(f); } static inline char *symbol_name(const ASR::symbol_t *f) @@ -493,7 +351,8 @@ static inline ASR::Module_t *get_sym_module0(const ASR::symbol_t *sym) { } // Returns true if the Function is intrinsic, otherwise false -static inline bool is_intrinsic_function(const ASR::Function_t *fn) { +template +static inline bool is_intrinsic_procedure(const T *fn) { ASR::symbol_t *sym = (ASR::symbol_t*)fn; ASR::Module_t *m = get_sym_module0(sym); if (m != nullptr) { @@ -502,9 +361,21 @@ static inline bool is_intrinsic_function(const ASR::Function_t *fn) { return false; } +static inline bool is_intrinsic_symbol(const ASR::symbol_t *fn) { + const ASR::symbol_t *sym = fn; + ASR::Module_t *m = get_sym_module0(sym); + if (m != nullptr) { + if (m->m_intrinsic) { + return true; + } + if (startswith(m->m_name, "lfortran_intrinsic")) return true; + } + return false; +} + // Returns true if the Function is intrinsic, otherwise false // This version uses the `intrinsic` member of `Module`, so it -// should be used instead of is_intrinsic_function +// should be used instead of is_intrinsic_procedure static inline bool is_intrinsic_function2(const ASR::Function_t *fn) { ASR::symbol_t *sym = (ASR::symbol_t*)fn; ASR::Module_t *m = get_sym_module0(sym); @@ -714,6 +585,11 @@ static inline bool extract_value(ASR::expr_t* value_expr, T& value) { } switch( value_expr->type ) { + case ASR::exprType::IntegerConstant: { + ASR::IntegerConstant_t* const_int = ASR::down_cast(value_expr); + value = (T) const_int->m_n; + break; + } case ASR::exprType::RealConstant: { ASR::RealConstant_t* const_real = ASR::down_cast(value_expr); value = (T) const_real->m_r; @@ -725,6 +601,122 @@ static inline bool extract_value(ASR::expr_t* value_expr, T& value) { return true; } +static inline std::string type_python_1dim_helper(const std::string & res, + const ASR::dimension_t* e ) +{ + if( !e->m_end && !e->m_start ) { + return res + "[:]"; + } + + if( ASRUtils::expr_value(e->m_end) ) { + int64_t end_dim = -1; + ASRUtils::extract_value(ASRUtils::expr_value(e->m_end), end_dim); + return res + "[" + std::to_string(end_dim + 1) + "]"; + } + + return res; +} + +static inline std::string type_to_str_python(const ASR::ttype_t *t, + bool for_error_message=true) +{ + switch (t->type) { + case ASR::ttypeType::Integer: { + ASR::Integer_t *i = (ASR::Integer_t*)t; + std::string res = ""; + switch (i->m_kind) { + case 1: { res = "i8"; break; } + case 2: { res = "i16"; break; } + case 4: { res = "i32"; break; } + case 8: { res = "i64"; break; } + default: { throw LFortranException("Integer kind not supported"); } + } + if (i->n_dims == 1 && for_error_message) { + res = type_python_1dim_helper(res, i->m_dims); + } + return res; + } + case ASR::ttypeType::Real: { + ASR::Real_t *r = (ASR::Real_t*)t; + std::string res = ""; + switch (r->m_kind) { + case 4: { res = "f32"; break; } + case 8: { res = "f64"; break; } + default: { throw LFortranException("Float kind not supported"); } + } + if (r->n_dims == 1 && for_error_message) { + res = type_python_1dim_helper(res, r->m_dims); + } + return res; + } + case ASR::ttypeType::Complex: { + ASR::Complex_t *c = (ASR::Complex_t*)t; + switch (c->m_kind) { + case 4: { return "c32"; } + case 8: { return "c64"; } + default: { throw LFortranException("Complex kind not supported"); } + } + } + case ASR::ttypeType::Logical: { + return "bool"; + } + case ASR::ttypeType::Character: { + return "str"; + } + case ASR::ttypeType::Tuple: { + ASR::Tuple_t *tup = ASR::down_cast(t); + std::string result = "tuple["; + for (size_t i=0; in_type; i++) { + result += type_to_str_python(tup->m_type[i]); + if (i+1 != tup->n_type) { + result += ", "; + } + } + result += "]"; + return result; + } + case ASR::ttypeType::Set: { + ASR::Set_t *s = (ASR::Set_t *)t; + return "set[" + type_to_str_python(s->m_type) + "]"; + } + case ASR::ttypeType::Dict: { + ASR::Dict_t *d = (ASR::Dict_t *)t; + return "dict[" + type_to_str_python(d->m_key_type) + ", " + type_to_str_python(d->m_value_type) + "]"; + } + case ASR::ttypeType::List: { + ASR::List_t *l = (ASR::List_t *)t; + return "list[" + type_to_str_python(l->m_type) + "]"; + } + case ASR::ttypeType::CPtr: { + return "CPtr"; + } + case ASR::ttypeType::Derived: { + ASR::Derived_t* d = ASR::down_cast(t); + return symbol_name(d->m_derived_type); + } + case ASR::ttypeType::Pointer: { + ASR::Pointer_t* p = ASR::down_cast(t); + return "Pointer[" + type_to_str_python(p->m_type) + "]"; + } + default : throw LFortranException("Not implemented " + std::to_string(t->type)); + } +} + +static inline std::string binop_to_str_python(const ASR::binopType t) { + switch (t) { + case (ASR::binopType::Add): { return " + "; } + case (ASR::binopType::Sub): { return " - "; } + case (ASR::binopType::Mul): { return "*"; } + case (ASR::binopType::Div): { return "/"; } + case (ASR::binopType::BitAnd): { return "&"; } + case (ASR::binopType::BitOr): { return "|"; } + case (ASR::binopType::BitXor): { return "^"; } + case (ASR::binopType::BitLShift): { return "<<"; } + case (ASR::binopType::BitRShift): { return ">>"; } + default : throw LFortranException("Cannot represent the binary operator as a string"); + } +} + // Returns a list of values static inline Vec get_arg_values(Allocator &al, const Vec& args) { Vec values; @@ -901,61 +893,156 @@ static inline bool is_logical(ASR::ttype_t &x) { return ASR::is_a(*type_get_past_pointer(&x)); } -inline bool is_array(ASR::ttype_t *x) { +static inline int get_body_size(ASR::symbol_t* s) { + int n_body = 0; + switch (s->type) { + case ASR::symbolType::Function: { + ASR::Function_t* f = ASR::down_cast(s); + n_body = f->n_body; + break; + } + case ASR::symbolType::Subroutine: { + ASR::Subroutine_t* sub = ASR::down_cast(s); + n_body = sub->n_body; + break; + } + case ASR::symbolType::Program: { + ASR::Program_t* p = ASR::down_cast(s); + n_body = p->n_body; + break; + } + default: { + n_body = -1; + } + } + return n_body; +} + +inline int extract_dimensions_from_ttype(ASR::ttype_t *x, + ASR::dimension_t*& m_dims) { int n_dims = 0; switch (x->type) { case ASR::ttypeType::Integer: { - n_dims = ASR::down_cast(x)->n_dims; + ASR::Integer_t* Integer_type = ASR::down_cast(x); + n_dims = Integer_type->n_dims; + m_dims = Integer_type->m_dims; break; } case ASR::ttypeType::Real: { - n_dims = ASR::down_cast(x)->n_dims; + ASR::Real_t* Real_type = ASR::down_cast(x); + n_dims = Real_type->n_dims; + m_dims = Real_type->m_dims; break; } case ASR::ttypeType::Complex: { - n_dims = ASR::down_cast(x)->n_dims; + ASR::Complex_t* Complex_type = ASR::down_cast(x); + n_dims = Complex_type->n_dims; + m_dims = Complex_type->m_dims; break; } case ASR::ttypeType::Character: { - n_dims = ASR::down_cast(x)->n_dims; + ASR::Character_t* Character_type = ASR::down_cast(x); + n_dims = Character_type->n_dims; + m_dims = Character_type->m_dims; break; } case ASR::ttypeType::Logical: { - n_dims = ASR::down_cast(x)->n_dims; + ASR::Logical_t* Logical_type = ASR::down_cast(x); + n_dims = Logical_type->n_dims; + m_dims = Logical_type->m_dims; break; } case ASR::ttypeType::Derived: { - n_dims = ASR::down_cast(x)->n_dims; + ASR::Derived_t* Derived_type = ASR::down_cast(x); + n_dims = Derived_type->n_dims; + m_dims = Derived_type->m_dims; break; } case ASR::ttypeType::Class: { - n_dims = ASR::down_cast(x)->n_dims; + ASR::Class_t* Class_type = ASR::down_cast(x); + n_dims = Class_type->n_dims; + m_dims = Class_type->m_dims; break; } case ASR::ttypeType::Pointer: { - return is_array(ASR::down_cast(x)->m_type); + n_dims = extract_dimensions_from_ttype(ASR::down_cast(x)->m_type, m_dims); break; } case ASR::ttypeType::List: { n_dims = 0; + m_dims = nullptr; break; } - case ASR::ttypeType::Set: { - n_dims = 0; - break; - } - case ASR::ttypeType::Dict: { - n_dims = 0; - break; - } - case ASR::ttypeType::Tuple: { + case ASR::ttypeType::CPtr: { n_dims = 0; + m_dims = nullptr; break; } default: throw LFortranException("Not implemented."); } - return n_dims > 0; + return n_dims; +} + +inline bool is_array(ASR::ttype_t *x) { + ASR::dimension_t* dims = nullptr; + return extract_dimensions_from_ttype(x, dims) > 0; +} + +static inline ASR::ttype_t* duplicate_type(Allocator& al, const ASR::ttype_t* t, + Vec* dims = nullptr) { + switch (t->type) { + case ASR::ttypeType::Integer: { + ASR::Integer_t* tnew = ASR::down_cast(t); + ASR::dimension_t* dimsp = dims ? dims->p : tnew->m_dims; + size_t dimsn = dims ? dims->n : tnew->n_dims; + return ASRUtils::TYPE(ASR::make_Integer_t(al, t->base.loc, + tnew->m_kind, dimsp, dimsn)); + } + case ASR::ttypeType::Real: { + ASR::Real_t* tnew = ASR::down_cast(t); + ASR::dimension_t* dimsp = dims ? dims->p : tnew->m_dims; + size_t dimsn = dims ? dims->n : tnew->n_dims; + return ASRUtils::TYPE(ASR::make_Real_t(al, t->base.loc, + tnew->m_kind, dimsp, dimsn)); + } + case ASR::ttypeType::Complex: { + ASR::Complex_t* tnew = ASR::down_cast(t); + ASR::dimension_t* dimsp = dims ? dims->p : tnew->m_dims; + size_t dimsn = dims ? dims->n : tnew->n_dims; + return ASRUtils::TYPE(ASR::make_Complex_t(al, t->base.loc, + tnew->m_kind, dimsp, dimsn)); + } + case ASR::ttypeType::Logical: { + ASR::Logical_t* tnew = ASR::down_cast(t); + ASR::dimension_t* dimsp = dims ? dims->p : tnew->m_dims; + size_t dimsn = dims ? dims->n : tnew->n_dims; + return ASRUtils::TYPE(ASR::make_Logical_t(al, t->base.loc, + tnew->m_kind, dimsp, dimsn)); + } + case ASR::ttypeType::Character: { + ASR::Character_t* tnew = ASR::down_cast(t); + ASR::dimension_t* dimsp = dims ? dims->p : tnew->m_dims; + size_t dimsn = dims ? dims->n : tnew->n_dims; + return ASRUtils::TYPE(ASR::make_Character_t(al, t->base.loc, + tnew->m_kind, tnew->m_len, tnew->m_len_expr, + dimsp, dimsn)); + } + case ASR::ttypeType::Derived: { + ASR::Derived_t* tnew = ASR::down_cast(t); + ASR::dimension_t* dimsp = dims ? dims->p : tnew->m_dims; + size_t dimsn = dims ? dims->n : tnew->n_dims; + return ASRUtils::TYPE(ASR::make_Derived_t(al, t->base.loc, + tnew->m_derived_type, dimsp, dimsn)); + } + case ASR::ttypeType::Pointer: { + ASR::Pointer_t* ptr = ASR::down_cast(t); + ASR::ttype_t* dup_type = duplicate_type(al, ptr->m_type, dims); + return ASRUtils::TYPE(ASR::make_Pointer_t(al, ptr->base.base.loc, + dup_type)); + } + default : throw LFortranException("Not implemented " + std::to_string(t->type)); + } } inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) { @@ -973,157 +1060,168 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) { return res; } - inline int extract_kind_str(char* m_n, char *&kind_str) { - char *p = m_n; - while (*p != '\0') { - if (*p == '_') { - p++; - std::string kind = std::string(p); - int ikind = std::atoi(p); - if (ikind == 0) { - // Not an integer, return a string - kind_str = p; - return 0; - } else { - return ikind; - } - } - if (*p == 'd' || *p == 'D') { - // Double precision - return 8; - } - p++; - } - return 4; +inline int extract_kind_str(char* m_n, char *&kind_str) { + char *p = m_n; + while (*p != '\0') { + if (*p == '_') { + p++; + std::string kind = std::string(p); + int ikind = std::atoi(p); + if (ikind == 0) { + // Not an integer, return a string + kind_str = p; + return 0; + } else { + return ikind; } + } + if (*p == 'd' || *p == 'D') { + // Double precision + return 8; + } + p++; + } + return 4; +} - template - inline int extract_kind(ASR::expr_t* kind_expr, const Location& loc) { - int a_kind = 4; - switch( kind_expr->type ) { - case ASR::exprType::IntegerConstant: { - a_kind = ASR::down_cast - (kind_expr)->m_n; - break; - } - case ASR::exprType::Var: { - ASR::Var_t* kind_var = - ASR::down_cast(kind_expr); - ASR::Variable_t* kind_variable = - ASR::down_cast( - symbol_get_past_external(kind_var->m_v)); - if( kind_variable->m_storage == ASR::storage_typeType::Parameter ) { - if( kind_variable->m_type->type == ASR::ttypeType::Integer ) { - LFORTRAN_ASSERT( kind_variable->m_value != nullptr ); - a_kind = ASR::down_cast(kind_variable->m_value)->m_n; - } else { - std::string msg = "Integer variable required. " + std::string(kind_variable->m_name) + - " is not an Integer variable."; - throw SemanticError(msg, loc); - } - } else { - std::string msg = "Parameter " + std::string(kind_variable->m_name) + - " is a variable, which does not reduce to a constant expression"; - throw SemanticError(msg, loc); - } - break; - } - default: { - throw SemanticError(R"""(Only Integer literals or expressions which reduce to constant Integer are accepted as kind parameters.)""", - loc); - } +template +inline int extract_kind(ASR::expr_t* kind_expr, const Location& loc) { + int a_kind = 4; + switch( kind_expr->type ) { + case ASR::exprType::IntegerConstant: { + a_kind = ASR::down_cast + (kind_expr)->m_n; + break; + } + case ASR::exprType::Var: { + ASR::Var_t* kind_var = + ASR::down_cast(kind_expr); + ASR::Variable_t* kind_variable = + ASR::down_cast( + symbol_get_past_external(kind_var->m_v)); + if( kind_variable->m_storage == ASR::storage_typeType::Parameter ) { + if( kind_variable->m_type->type == ASR::ttypeType::Integer ) { + LFORTRAN_ASSERT( kind_variable->m_value != nullptr ); + a_kind = ASR::down_cast(kind_variable->m_value)->m_n; + } else { + std::string msg = "Integer variable required. " + std::string(kind_variable->m_name) + + " is not an Integer variable."; + throw SemanticError(msg, loc); } - return a_kind; + } else { + std::string msg = "Parameter " + std::string(kind_variable->m_name) + + " is a variable, which does not reduce to a constant expression"; + throw SemanticError(msg, loc); } + break; + } + default: { + throw SemanticError(R"""(Only Integer literals or expressions which reduce to constant Integer are accepted as kind parameters.)""", + loc); + } + } + return a_kind; +} - template - inline int extract_len(ASR::expr_t* len_expr, const Location& loc) { - int a_len = -10; - switch( len_expr->type ) { - case ASR::exprType::IntegerConstant: { - a_len = ASR::down_cast - (len_expr)->m_n; - break; - } - case ASR::exprType::Var: { - ASR::Var_t* len_var = - ASR::down_cast(len_expr); - ASR::Variable_t* len_variable = - ASR::down_cast( - symbol_get_past_external(len_var->m_v)); - if( len_variable->m_storage == ASR::storage_typeType::Parameter ) { - if( len_variable->m_type->type == ASR::ttypeType::Integer ) { - LFORTRAN_ASSERT( len_variable->m_value != nullptr ); - a_len = ASR::down_cast(len_variable->m_value)->m_n; - } else { - std::string msg = "Integer variable required. " + std::string(len_variable->m_name) + - " is not an Integer variable."; - throw SemanticError(msg, loc); - } - } else { - // An expression is beind used for `len` that cannot be evaluated - a_len = -3; - } - break; - } - case ASR::exprType::FunctionCall: { - a_len = -3; - break; - } - case ASR::exprType::BinOp: { - a_len = -3; - break; - } - default: { - throw SemanticError("Only Integers or variables implemented so far for `len` expressions", - loc); - } +template +inline int extract_len(ASR::expr_t* len_expr, const Location& loc) { + int a_len = -10; + switch( len_expr->type ) { + case ASR::exprType::IntegerConstant: { + a_len = ASR::down_cast + (len_expr)->m_n; + break; + } + case ASR::exprType::Var: { + ASR::Var_t* len_var = + ASR::down_cast(len_expr); + ASR::Variable_t* len_variable = + ASR::down_cast( + symbol_get_past_external(len_var->m_v)); + if( len_variable->m_storage == ASR::storage_typeType::Parameter ) { + if( len_variable->m_type->type == ASR::ttypeType::Integer ) { + LFORTRAN_ASSERT( len_variable->m_value != nullptr ); + a_len = ASR::down_cast(len_variable->m_value)->m_n; + } else { + std::string msg = "Integer variable required. " + std::string(len_variable->m_name) + + " is not an Integer variable."; + throw SemanticError(msg, loc); } - LFORTRAN_ASSERT(a_len != -10) - return a_len; + } else { + // An expression is beind used for `len` that cannot be evaluated + a_len = -3; } + break; + } + case ASR::exprType::FunctionCall: { + a_len = -3; + break; + } + case ASR::exprType::IntegerBinOp: { + a_len = -3; + break; + } + default: { + throw SemanticError("Only Integers or variables implemented so far for `len` expressions", + loc); + } + } + LFORTRAN_ASSERT(a_len != -10) + return a_len; +} - inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y) { - if (ASR::is_a(*x) && ASR::is_a(*y)) { - x = ASR::down_cast(x)->m_type; - y = ASR::down_cast(y)->m_type; - return check_equal_type(x, y); - } else if (ASR::is_a(*x) && ASR::is_a(*y)) { - x = ASR::down_cast(x)->m_type; - y = ASR::down_cast(y)->m_type; - return check_equal_type(x, y); - } else if (ASR::is_a(*x) && ASR::is_a(*y)) { - ASR::ttype_t *x_key_type = ASR::down_cast(x)->m_key_type; - ASR::ttype_t *y_key_type = ASR::down_cast(y)->m_key_type; - ASR::ttype_t *x_value_type = ASR::down_cast(x)->m_value_type; - ASR::ttype_t *y_value_type = ASR::down_cast(y)->m_value_type; - return (check_equal_type(x_key_type, y_key_type) && - check_equal_type(x_value_type, y_value_type)); - } else if (ASR::is_a(*x) && ASR::is_a(*y)) { - ASR::Tuple_t *a = ASR::down_cast(x); - ASR::Tuple_t *b = ASR::down_cast(y); - if(a->n_type != b->n_type) { - return false; - } - bool result = true; - for (size_t i=0; in_type; i++) { - result = result && check_equal_type(a->m_type[i], b->m_type[i]); - if (!result) { - return false; - } - } - return result; - } - if( x->type == y->type ) { - return true; - } - - return ASRUtils::is_same_type_pointer(x, y); +inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y) { + if( ASR::is_a(*x) || + ASR::is_a(*y) ) { + x = ASRUtils::type_get_past_pointer(x); + y = ASRUtils::type_get_past_pointer(y); + return check_equal_type(x, y); + } else if (ASR::is_a(*x) && ASR::is_a(*y)) { + x = ASR::down_cast(x)->m_type; + y = ASR::down_cast(y)->m_type; + return check_equal_type(x, y); + } else if (ASR::is_a(*x) && ASR::is_a(*y)) { + x = ASR::down_cast(x)->m_type; + y = ASR::down_cast(y)->m_type; + return check_equal_type(x, y); + } else if (ASR::is_a(*x) && ASR::is_a(*y)) { + ASR::ttype_t *x_key_type = ASR::down_cast(x)->m_key_type; + ASR::ttype_t *y_key_type = ASR::down_cast(y)->m_key_type; + ASR::ttype_t *x_value_type = ASR::down_cast(x)->m_value_type; + ASR::ttype_t *y_value_type = ASR::down_cast(y)->m_value_type; + return (check_equal_type(x_key_type, y_key_type) && + check_equal_type(x_value_type, y_value_type)); + } else if (ASR::is_a(*x) && ASR::is_a(*y)) { + ASR::Tuple_t *a = ASR::down_cast(x); + ASR::Tuple_t *b = ASR::down_cast(y); + if(a->n_type != b->n_type) { + return false; + } + bool result = true; + for (size_t i=0; in_type; i++) { + result = result && check_equal_type(a->m_type[i], b->m_type[i]); + if (!result) { + return false; } + } + return result; + } + + int64_t x_kind = ASRUtils::extract_kind_from_ttype_t(x); + int64_t y_kind = ASRUtils::extract_kind_from_ttype_t(y); + + if( x->type == y->type && + x_kind == y_kind ) { + return true; + } + + return false; +} int select_generic_procedure(const Vec &args, const ASR::GenericProcedure_t &p, Location loc, - const std::function err); + const std::function err, + bool raise_error=true); ASR::asr_t* symbol_resolve_external_generic_procedure_without_eval( const Location &loc, @@ -1131,9 +1229,178 @@ ASR::asr_t* symbol_resolve_external_generic_procedure_without_eval( SymbolTable* current_scope, Allocator& al, const std::function err); -// Creates an Cast node and automatically computes the `value` if it can be computed at compile time +class ReplaceArgVisitor: public ASR::BaseExprReplacer { + + private: + + Allocator& al; + + SymbolTable* current_scope; + + ASR::Function_t* orig_func; + + Vec& orig_args; + + public: + + ReplaceArgVisitor(Allocator& al_, SymbolTable* current_scope_, + ASR::Function_t* orig_func_, Vec& orig_args_) : + al(al_), current_scope(current_scope_), orig_func(orig_func_), + orig_args(orig_args_) + {} + + void replace_FunctionCall(ASR::FunctionCall_t* x) { + ASR::symbol_t *new_es = x->m_name; + // Import a function as external only if necessary + ASR::Function_t *f = nullptr; + ASR::symbol_t* f_sym = nullptr; + if (ASR::is_a(*x->m_name)) { + f = ASR::down_cast(x->m_name); + } else if( ASR::is_a(*x->m_name) ) { + f_sym = ASRUtils::symbol_get_past_external(x->m_name); + if( ASR::is_a(*f_sym) ) { + f = ASR::down_cast(f_sym); + } + } + ASR::Module_t *m = ASR::down_cast2(f->m_symtab->parent->asr_owner); + char *modname = m->m_name; + ASR::symbol_t *maybe_f = current_scope->resolve_symbol(std::string(f->m_name)); + ASR::symbol_t* maybe_f_actual = nullptr; + std::string maybe_modname = ""; + if( maybe_f && ASR::is_a(*maybe_f) ) { + maybe_modname = ASR::down_cast(maybe_f)->m_module_name; + maybe_f_actual = ASRUtils::symbol_get_past_external(maybe_f); + } + // If the Function to be imported is already present + // then do not import. + if( maybe_modname == std::string(modname) && + f_sym == maybe_f_actual ) { + new_es = maybe_f; + } else { + // Import while assigning a new name to avoid conflicts + // For example, if someone is using `len` from a user + // define module then `get_unique_name` will avoid conflict + std::string unique_name = current_scope->get_unique_name(f->m_name); + Str s; s.from_str_view(unique_name); + char *unique_name_c = s.c_str(al); + LFORTRAN_ASSERT(current_scope->get_symbol(unique_name) == nullptr); + new_es = ASR::down_cast(ASR::make_ExternalSymbol_t( + al, f->base.base.loc, + /* a_symtab */ current_scope, + /* a_name */ unique_name_c, + (ASR::symbol_t*)f, + modname, nullptr, 0, + f->m_name, + ASR::accessType::Private + )); + current_scope->add_symbol(unique_name, new_es); + } + // The following substitutes args from the current scope + for (size_t i = 0; i < x->n_args; i++) { + current_expr_copy = current_expr; + current_expr = &(x->m_args[i].m_value); + replace_expr(x->m_args[i].m_value); + current_expr = current_expr_copy; + } + x->m_name = new_es; + } + + void replace_Var(ASR::Var_t* x) { + size_t arg_idx = 0; + bool idx_found = false; + std::string arg_name = ASRUtils::symbol_name(x->m_v); + // Finds the index of the argument to be used for substitution + // Basically if we are calling maybe(string, ret_type=character(len=len(s))) + // where string is a variable in current scope and s is one of the arguments + // accepted by maybe i.e., maybe has a signature maybe(s). Then, we will + // replace s with string. So, the call would become, + // maybe(string, ret_type=character(len=len(string))) + for( size_t j = 0; j < orig_func->n_args && !idx_found; j++ ) { + if( ASR::is_a(*(orig_func->m_args[j])) ) { + std::string arg_name_2 = std::string(ASRUtils::symbol_name( + ASR::down_cast(orig_func->m_args[j])->m_v)); + arg_idx = j; + idx_found = arg_name_2 == arg_name; + } + } + if( idx_found ) { + LFORTRAN_ASSERT(current_expr); + *current_expr = orig_args[arg_idx].m_value; + } + } + +}; + +class ReplaceReturnWithGotoVisitor: public ASR::BaseStmtReplacer { + + private: + + Allocator& al; + + uint64_t goto_label; + + public: + + ReplaceReturnWithGotoVisitor(Allocator& al_, uint64_t goto_label_) : + al(al_), goto_label(goto_label_) + {} + + void set_goto_label(uint64_t label) { + goto_label = label; + } + + void replace_Return(ASR::Return_t* x) { + *current_stmt = ASRUtils::STMT(ASR::make_GoTo_t(al, x->base.base.loc, goto_label)); + has_replacement_happened = true; + } + +}; + +// Singleton LabelGenerator so that it generates +// unique labels for different statements, from +// whereever it is called (be it ASR passes, be it +// AST to ASR transition, etc). +class LabelGenerator { + private: + + static LabelGenerator *label_generator; + uint64_t unique_label; + std::map node2label; + + // Private constructor so that more than + // one object cannot be created by calling the + // constructor. + LabelGenerator() { + unique_label = 0; + } + + public: + + static LabelGenerator *get_instance() { + if (!label_generator) { + label_generator = new LabelGenerator; + } + return label_generator; + } + + int get_unique_label() { + unique_label += 1; + return unique_label; + } + + void add_node_with_unique_label(ASR::asr_t* node, uint64_t label) { + LFORTRAN_ASSERT( node2label.find(node) == node2label.end() ); + node2label[node] = label; + } + + bool verify(ASR::asr_t* node) { + return node2label.find(node) != node2label.end(); + } +}; + ASR::asr_t* make_Cast_t_value(Allocator &al, const Location &a_loc, - ASR::expr_t* a_arg, ASR::cast_kindType a_kind, ASR::ttype_t* a_type); + ASR::expr_t* a_arg, ASR::cast_kindType a_kind, ASR::ttype_t* a_type); + } // namespace ASRUtils diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index 92dfb67cf1..6ca25d4fe9 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -358,15 +358,23 @@ class VerifyVisitor : public BaseWalkVisitor "Var::m_v `" + std::string(ASRUtils::symbol_name(x.m_v)) + "` cannot point outside of its symbol table"); } - void visit_ArrayRef(const ArrayRef_t &x) { - require(symtab_in_scope(current_symtab, x.m_v), - "ArrayRef::m_v cannot point outside of its symbol table"); + template + void visit_ArrayItemSection(const T &x) { + visit_expr(*x.m_v); for (size_t i=0; i +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +namespace LFortran { + +std::string format_type_c(const std::string &dims, const std::string &type, + const std::string &name, bool use_ref, bool /*dummy*/) +{ + std::string fmt; + std::string ref = ""; + if (use_ref) ref = "*"; + if( dims == "*" ) { + fmt = type + " " + dims + ref + name; + } else { + fmt = type + " " + ref + name + dims; + } + return fmt; +} + +class ASRToCVisitor : public BaseCCPPVisitor +{ +public: + + std::string array_types_decls; + std::map> eltypedims2arraytype; + + ASRToCVisitor(diag::Diagnostics &diag, Platform &platform, + int64_t default_lower_bound) + : BaseCCPPVisitor(diag, platform, false, false, true, default_lower_bound), + array_types_decls(std::string("\nstruct dimension_descriptor\n" + "{\n int32_t lower_bound, upper_bound;\n};\n")) { + } + + std::string convert_dims_c(size_t n_dims, ASR::dimension_t *m_dims, + bool convert_to_1d=false) + { + std::string dims; + size_t size = 1; + for (size_t i=0; idata = " + std::string(v_m_name) + "_data;\n"; + for (int i = 0; i < n_dims; i++) { + if( m_dims[i].m_start ) { + this->visit_expr(*m_dims[i].m_start); + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].lower_bound = " + src + ";\n"; + } else { + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].lower_bound = 0" + ";\n"; + } + if( m_dims[i].m_end ) { + this->visit_expr(*m_dims[i].m_end); + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].upper_bound = " + src + ";\n"; + } else { + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].upper_bound = -1" + ";\n"; + } + } + sub.pop_back(); + sub.pop_back(); + } + } else { + sub = format_type_c("", type_name, v_m_name, use_ref, dummy); + } + } + + std::string convert_variable_decl(const ASR::Variable_t &v, + bool pre_initialise_derived_type=true, + bool use_static=true) + { + std::string sub; + bool use_ref = (v.m_intent == LFortran::ASRUtils::intent_out || + v.m_intent == LFortran::ASRUtils::intent_inout); + bool is_array = ASRUtils::is_array(v.m_type); + bool dummy = LFortran::ASRUtils::is_arg_dummy(v.m_intent); + if (ASRUtils::is_pointer(v.m_type)) { + ASR::ttype_t *t2 = ASR::down_cast(v.m_type)->m_type; + if (ASRUtils::is_integer(*t2)) { + ASR::Integer_t *t = ASR::down_cast(t2); + std::string type_name = "int" + std::to_string(t->m_kind * 8) + "_t"; + if( !ASRUtils::is_array(v.m_type) ) { + type_name.append(" *"); + } + if( is_array ) { + std::string dims = convert_dims_c(t->n_dims, t->m_dims, true); + std::string encoded_type_name = "i" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout, true); + } else { + std::string dims = convert_dims_c(t->n_dims, t->m_dims); + sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + } + } else if(ASR::is_a(*t2)) { + ASR::Derived_t *t = ASR::down_cast(t2); + std::string der_type_name = ASRUtils::symbol_name(t->m_derived_type); + std::string dims = convert_dims_c(t->n_dims, t->m_dims); + sub = format_type_c(dims, "struct " + der_type_name + "*", + v.m_name, use_ref, dummy); + } else { + diag.codegen_error_label("Type number '" + + std::to_string(v.m_type->type) + + "' not supported", {v.base.base.loc}, ""); + throw Abort(); + } + } else { + std::string dims; + use_ref = use_ref && !is_array; + if (ASRUtils::is_integer(*v.m_type)) { + headers.insert("inttypes"); + ASR::Integer_t *t = ASR::down_cast(v.m_type); + std::string type_name = "int" + std::to_string(t->m_kind * 8) + "_t"; + if( is_array ) { + dims = convert_dims_c(t->n_dims, t->m_dims, true); + std::string encoded_type_name = "i" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout); + } else { + dims = convert_dims_c(t->n_dims, t->m_dims); + sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + } + } else if (ASRUtils::is_real(*v.m_type)) { + ASR::Real_t *t = ASR::down_cast(v.m_type); + std::string type_name = "float"; + if (t->m_kind == 8) type_name = "double"; + if( is_array ) { + dims = convert_dims_c(t->n_dims, t->m_dims, true); + std::string encoded_type_name = "f" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout); + } else { + dims = convert_dims_c(t->n_dims, t->m_dims); + sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + } + } else if (ASRUtils::is_complex(*v.m_type)) { + headers.insert("complex"); + ASR::Complex_t *t = ASR::down_cast(v.m_type); + std::string type_name = "float complex"; + if (t->m_kind == 8) type_name = "double complex"; + if( is_array ) { + dims = convert_dims_c(t->n_dims, t->m_dims, true); + std::string encoded_type_name = "c" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout); + } else { + dims = convert_dims_c(t->n_dims, t->m_dims); + sub = format_type_c(dims, type_name, v.m_name, use_ref, dummy); + } + } else if (ASRUtils::is_logical(*v.m_type)) { + ASR::Logical_t *t = ASR::down_cast(v.m_type); + dims = convert_dims_c(t->n_dims, t->m_dims); + sub = format_type_c(dims, "bool", v.m_name, use_ref, dummy); + } else if (ASRUtils::is_character(*v.m_type)) { + ASR::Character_t *t = ASR::down_cast(v.m_type); + std::string dims = convert_dims_c(t->n_dims, t->m_dims); + sub = format_type_c(dims, "char *", v.m_name, use_ref, dummy); + } else if (ASR::is_a(*v.m_type)) { + std::string indent(indentation_level*indentation_spaces, ' '); + ASR::Derived_t *t = ASR::down_cast(v.m_type); + std::string der_type_name = ASRUtils::symbol_name(t->m_derived_type); + if( is_array ) { + dims = convert_dims_c(t->n_dims, t->m_dims, true); + std::string encoded_type_name = "x" + der_type_name; + std::string type_name = std::string("struct ") + der_type_name; + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout); + } else if( v.m_intent == ASRUtils::intent_local && pre_initialise_derived_type) { + dims = convert_dims_c(t->n_dims, t->m_dims); + std::string value_var_name = v.m_parent_symtab->get_unique_name(std::string(v.m_name) + "_value"); + sub = format_type_c(dims, "struct " + der_type_name, + value_var_name, use_ref, dummy); + if (v.m_symbolic_value) { + this->visit_expr(*v.m_symbolic_value); + std::string init = src; + sub += "=" + init; + } + sub += ";\n"; + sub += indent + format_type_c("", "struct " + der_type_name + "*", v.m_name, use_ref, dummy); + if( t->n_dims != 0 ) { + sub += " = " + value_var_name; + } else { + sub += " = &" + value_var_name; + } + return sub; + } else { + dims = convert_dims_c(t->n_dims, t->m_dims); + if( v.m_intent == ASRUtils::intent_in || + v.m_intent == ASRUtils::intent_inout ) { + use_ref = false; + dims = ""; + } + sub = format_type_c(dims, "struct " + der_type_name + "*", + v.m_name, use_ref, dummy); + } + } else if (ASR::is_a(*v.m_type)) { + sub = format_type_c("", "void*", v.m_name, false, false); + } else { + diag.codegen_error_label("Type number '" + + std::to_string(v.m_type->type) + + "' not supported", {v.base.base.loc}, ""); + throw Abort(); + } + if (dims.size() == 0 && v.m_storage == ASR::storage_typeType::Save && use_static) { + sub = "static " + sub; + } + if (dims.size() == 0 && v.m_symbolic_value) { + this->visit_expr(*v.m_symbolic_value); + std::string init = src; + sub += "=" + init; + } + } + return sub; + } + + + void visit_TranslationUnit(const ASR::TranslationUnit_t &x) { + global_scope = x.m_global_scope; + // All loose statements must be converted to a function, so the items + // must be empty: + LFORTRAN_ASSERT(x.n_items == 0); + std::string unit_src = ""; + indentation_level = 0; + indentation_spaces = 4; + + std::string head = +R"( +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + +)"; + + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second)) { + array_types_decls += "struct " + item.first + ";\n\n"; + } + } + + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Variable_t *v = ASR::down_cast(item.second); + unit_src += convert_variable_decl(*v) + ";\n"; + } + } + + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second)) { + visit_symbol(*item.second); + array_types_decls += src; + } + } + + // Pre-declare all functions first, then generate code + // Otherwise some function might not be found. + unit_src += "// Forward declarations\n"; + unit_src += declare_all_functions(*x.m_global_scope); + // Now pre-declare all functions from modules and programs + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Module_t *m = ASR::down_cast(item.second); + unit_src += declare_all_functions(*m->m_symtab); + } else if (ASR::is_a(*item.second)) { + ASR::Program_t *p = ASR::down_cast(item.second); + unit_src += declare_all_functions(*p->m_symtab); + } + } + unit_src += "\n"; + unit_src += "// Implementations\n"; + + { + // Process intrinsic modules in the right order + std::vector build_order + = LFortran::ASRUtils::determine_module_dependencies(x); + for (auto &item : build_order) { + LFORTRAN_ASSERT(x.m_global_scope->get_scope().find(item) + != x.m_global_scope->get_scope().end()); + if (startswith(item, "lfortran_intrinsic")) { + ASR::symbol_t *mod = x.m_global_scope->get_symbol(item); + if( ASRUtils::get_body_size(mod) != 0 ) { + visit_symbol(*mod); + unit_src += src; + } + } + } + } + + // Process procedures first: + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second) + || ASR::is_a(*item.second)) { + if( ASRUtils::get_body_size(item.second) != 0 ) { + visit_symbol(*item.second); + unit_src += src; + } + } + } + + // Then do all the modules in the right order + std::vector build_order + = LFortran::ASRUtils::determine_module_dependencies(x); + for (auto &item : build_order) { + LFORTRAN_ASSERT(x.m_global_scope->get_scope().find(item) + != x.m_global_scope->get_scope().end()); + if (!startswith(item, "lfortran_intrinsic")) { + ASR::symbol_t *mod = x.m_global_scope->get_symbol(item); + visit_symbol(*mod); + unit_src += src; + } + } + + // Then the main program: + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second)) { + visit_symbol(*item.second); + unit_src += src; + } + } + std::string to_include = ""; + for (auto s: headers) { + to_include += "#include <" + s + ".h>\n"; + } + src = to_include + head + array_types_decls + unit_src; + } + + void visit_Program(const ASR::Program_t &x) { + // Generate code for nested subroutines and functions first: + std::string contains; + for (auto &item : x.m_symtab->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Subroutine_t *s = ASR::down_cast(item.second); + visit_Subroutine(*s); + contains += src; + } + if (ASR::is_a(*item.second)) { + ASR::Function_t *s = ASR::down_cast(item.second); + visit_Function(*s); + contains += src; + } + } + + // Generate code for the main program + indentation_level += 1; + std::string indent1(indentation_level*indentation_spaces, ' '); + std::string decl; + for (auto &item : x.m_symtab->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Variable_t *v = ASR::down_cast(item.second); + decl += indent1; + decl += convert_variable_decl(*v) + ";\n"; + } + } + + std::string body; + for (size_t i=0; ivisit_stmt(*x.m_body[i]); + body += src; + } + src = contains + + "int main(int argc, char* argv[])\n{\n" + + decl + body + + indent1 + "return 0;\n}\n"; + indentation_level -= 2; + } + + void visit_DerivedType(const ASR::DerivedType_t& x) { + std::string indent(indentation_level*indentation_spaces, ' '); + indentation_level += 1; + std::string open_struct = indent + "struct " + std::string(x.m_name) + " {\n"; + std::string body = ""; + indent.push_back(' '); + for( size_t i = 0; i < x.n_members; i++ ) { + ASR::symbol_t* member = x.m_symtab->get_symbol(x.m_members[i]); + LFORTRAN_ASSERT(ASR::is_a(*member)); + body += indent + convert_variable_decl(*ASR::down_cast(member), false) + ";\n"; + } + indentation_level -= 1; + std::string end_struct = "};\n\n"; + array_types_decls += open_struct + body + end_struct; + } + + void visit_LogicalConstant(const ASR::LogicalConstant_t &x) { + if (x.m_value == true) { + src = "true"; + } else { + src = "false"; + } + last_expr_precedence = 2; + } + + void visit_Assert(const ASR::Assert_t &x) { + std::string indent(indentation_level*indentation_spaces, ' '); + std::string out = indent; + if (x.m_msg) { + out += "ASSERT_MSG("; + visit_expr(*x.m_test); + out += src + ", "; + visit_expr(*x.m_msg); + out += src + ");\n"; + } else { + out += "ASSERT("; + visit_expr(*x.m_test); + out += src + ");\n"; + } + src = out; + } + + std::string get_print_type(ASR::ttype_t *t, bool deref_ptr) { + switch (t->type) { + case ASR::ttypeType::Integer: { + ASR::Integer_t *i = (ASR::Integer_t*)t; + switch (i->m_kind) { + case 1: { return "%d"; } + case 2: { return "%d"; } + case 4: { return "%d"; } + case 8: { + if (platform == Platform::Linux) { + return "%li"; + } else { + return "%lli"; + } + } + default: { throw LFortranException("Integer kind not supported"); } + } + } + case ASR::ttypeType::Real: { + ASR::Real_t *r = (ASR::Real_t*)t; + switch (r->m_kind) { + case 4: { return "%f"; } + case 8: { return "%lf"; } + default: { throw LFortranException("Float kind not supported"); } + } + } + case ASR::ttypeType::Logical: { + return "%d"; + } + case ASR::ttypeType::Character: { + return "%s"; + } + case ASR::ttypeType::CPtr: { + return "%p"; + } + case ASR::ttypeType::Pointer: { + if( !deref_ptr ) { + return "%p"; + } else { + ASR::Pointer_t* type_ptr = ASR::down_cast(t); + return get_print_type(type_ptr->m_type, false); + } + } + default : throw LFortranException("Not implemented"); + } + } + + void visit_Print(const ASR::Print_t &x) { + std::string indent(indentation_level*indentation_spaces, ' '); + std::string out = indent + "printf(\""; + std::vector v; + std::string separator; + if (x.m_separator) { + this->visit_expr(*x.m_separator); + separator = src; + } else { + separator = "\" \""; + } + for (size_t i=0; ivisit_expr(*x.m_values[i]); + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_values[i])) ) { + src += "->data"; + } + ASR::ttype_t* value_type = ASRUtils::expr_type(x.m_values[i]); + out += get_print_type(value_type, ASR::is_a(*x.m_values[i])); + v.push_back(src); + if (i+1!=x.n_values) { + out += "\%s"; + v.push_back(separator); + } + } + out += "\\n\""; + if (!v.empty()) { + for (auto s: v) { + out += ", " + s; + } + } + out += ");\n"; + src = out; + } + + void visit_ArrayItem(const ASR::ArrayItem_t &x) { + this->visit_expr(*x.m_v); + std::string array = src; + std::string out = array; + ASR::dimension_t* m_dims; + ASRUtils::extract_dimensions_from_ttype(ASRUtils::expr_type(x.m_v), m_dims); + out += "->data["; + std::string index = ""; + for (size_t i=0; ivisit_expr(*x.m_args[i].m_right); + } else { + src = "/* FIXME right index */"; + } + + current_index += "(" + src + " - " + array + "->dims[" + + std::to_string(i) + "].lower_bound)"; + for( size_t j = 0; j < i; j++ ) { + std::string lb = array + "->dims[" + std::to_string(j) + "].lower_bound"; + std::string ub = array + "->dims[" + std::to_string(j) + "].upper_bound"; + current_index += " * (" + ub + " - " + lb + " + 1)"; + } + index += current_index; + if (i < x.n_args - 1) { + index += " + "; + } + } + out += index + "]"; + last_expr_precedence = 2; + src = out; + } + +}; + +Result asr_to_c(Allocator &al, ASR::TranslationUnit_t &asr, + diag::Diagnostics &diagnostics, Platform &platform, + int64_t default_lower_bound) +{ + pass_unused_functions(al, asr, true); + pass_replace_class_constructor(al, asr); + ASRToCVisitor v(diagnostics, platform, default_lower_bound); + try { + v.visit_asr((ASR::asr_t &)asr); + } catch (const CodeGenError &e) { + diagnostics.diagnostics.push_back(e.d); + return Error(); + } catch (const Abort &) { + return Error(); + } + return v.src; +} + +} // namespace LFortran diff --git a/src/libasr/codegen/asr_to_c.h b/src/libasr/codegen/asr_to_c.h new file mode 100644 index 0000000000..0b1d893ff4 --- /dev/null +++ b/src/libasr/codegen/asr_to_c.h @@ -0,0 +1,15 @@ +#ifndef LFORTRAN_ASR_TO_C_H +#define LFORTRAN_ASR_TO_C_H + +#include +#include + +namespace LFortran { + + Result asr_to_c(Allocator &al, ASR::TranslationUnit_t &asr, + diag::Diagnostics &diagnostics, Platform &platform, + int64_t default_lower_bound); + +} // namespace LFortran + +#endif // LFORTRAN_ASR_TO_C_H diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h new file mode 100644 index 0000000000..cca83c4519 --- /dev/null +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -0,0 +1,1220 @@ +#ifndef LFORTRAN_ASR_TO_C_CPP_H +#define LFORTRAN_ASR_TO_C_CPP_H + +/* + * Common code to be used in both of: + * + * * asr_to_cpp.cpp + * * asr_to_c.cpp + * + * In particular, a common base class visitor with visitors that are identical + * for both C and C++ code generation. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +namespace LFortran { + +namespace { + + // Local exception that is only used in this file to exit the visitor + // pattern and caught later (not propagated outside) + class CodeGenError + { + public: + diag::Diagnostic d; + public: + CodeGenError(const std::string &msg) + : d{diag::Diagnostic(msg, diag::Level::Error, diag::Stage::CodeGen)} + { } + + CodeGenError(const std::string &msg, const Location &loc) + : d{diag::Diagnostic(msg, diag::Level::Error, diag::Stage::CodeGen, { + diag::Label("", {loc}) + })} + { } + }; + + class Abort {}; + +} + +// Platform dependent fast unique hash: +static uint64_t get_hash(ASR::asr_t *node) +{ + return (uint64_t)node; +} + +struct SymbolInfo +{ + bool needs_declaration = true; + bool intrinsic_function = false; +}; + +template +class BaseCCPPVisitor : public ASR::BaseVisitor +{ +private: + Derived& self() { return static_cast(*this); } +public: + diag::Diagnostics &diag; + Platform platform; + std::string src; + int indentation_level; + int indentation_spaces; + // The precedence of the last expression, using the table: + // https://en.cppreference.com/w/cpp/language/operator_precedence + int last_expr_precedence; + bool intrinsic_module = false; + const ASR::Function_t *current_function = nullptr; + std::map sym_info; + + // Output configuration: + // Use std::string or char* + bool gen_stdstring; + // Use std::complex or float/double complex + bool gen_stdcomplex; + bool is_c; + std::set headers; + + SymbolTable* global_scope; + int64_t lower_bound; + + std::string template_for_Kokkos; + size_t template_number; + std::string from_std_vector_helper; + + BaseCCPPVisitor(diag::Diagnostics &diag, Platform &platform, + bool gen_stdstring, bool gen_stdcomplex, bool is_c, + int64_t default_lower_bound) : diag{diag}, + platform{platform}, + gen_stdstring{gen_stdstring}, gen_stdcomplex{gen_stdcomplex}, + is_c{is_c}, global_scope{nullptr}, lower_bound{default_lower_bound}, + template_number{0} {} + + void visit_TranslationUnit(const ASR::TranslationUnit_t &x) { + global_scope = x.m_global_scope; + // All loose statements must be converted to a function, so the items + // must be empty: + LFORTRAN_ASSERT(x.n_items == 0); + std::string unit_src = ""; + indentation_level = 0; + indentation_spaces = 4; + + std::string headers = +R"(#include +#include +#include +#include +)"; + unit_src += headers; + + { + // Process intrinsic modules in the right order + std::vector build_order + = LFortran::ASRUtils::determine_module_dependencies(x); + for (auto &item : build_order) { + LFORTRAN_ASSERT(x.m_global_scope->get_scope().find(item) + != x.m_global_scope->get_scope().end()); + if (startswith(item, "lfortran_intrinsic")) { + ASR::symbol_t *mod = x.m_global_scope->get_symbol(item); + self().visit_symbol(*mod); + unit_src += src; + } + } + } + + // Process procedures first: + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second) + || ASR::is_a(*item.second)) { + self().visit_symbol(*item.second); + unit_src += src; + } + } + + // Then do all the modules in the right order + std::vector build_order + = LFortran::ASRUtils::determine_module_dependencies(x); + for (auto &item : build_order) { + LFORTRAN_ASSERT(x.m_global_scope->get_scope().find(item) + != x.m_global_scope->get_scope().end()); + if (!startswith(item, "lfortran_intrinsic")) { + ASR::symbol_t *mod = x.m_global_scope->get_symbol(item); + self().visit_symbol(*mod); + unit_src += src; + } + } + + // Then the main program: + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second)) { + self().visit_symbol(*item.second); + unit_src += src; + } + } + + src = unit_src; + } + + void visit_Module(const ASR::Module_t &x) { + if (startswith(x.m_name, "lfortran_intrinsic_")) { + intrinsic_module = true; + } else { + intrinsic_module = false; + } + + std::string contains; + + // Generate the bodies of subroutines + for (auto &item : x.m_symtab->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Subroutine_t *s = ASR::down_cast(item.second); + self().visit_Subroutine(*s); + contains += src; + } + if (ASR::is_a(*item.second)) { + ASR::Function_t *s = ASR::down_cast(item.second); + self().visit_Function(*s); + contains += src; + } + } + src = contains; + intrinsic_module = false; + } + + void visit_Program(const ASR::Program_t &x) { + // Generate code for nested subroutines and functions first: + std::string contains; + for (auto &item : x.m_symtab->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Subroutine_t *s = ASR::down_cast(item.second); + visit_Subroutine(*s); + contains += src; + } + if (ASR::is_a(*item.second)) { + ASR::Function_t *s = ASR::down_cast(item.second); + visit_Function(*s); + contains += src; + } + } + + // Generate code for the main program + indentation_level += 1; + std::string indent1(indentation_level*indentation_spaces, ' '); + indentation_level += 1; + std::string indent(indentation_level*indentation_spaces, ' '); + std::string decl; + for (auto &item : x.m_symtab->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Variable_t *v = ASR::down_cast(item.second); + decl += self().convert_variable_decl(*v) + ";\n"; + } + } + + std::string body; + for (size_t i=0; im_intent)); + if( is_c ) { + func += self().convert_variable_decl(*arg, false); + } else { + func += self().convert_variable_decl(*arg, false, true); + } + if (i < x.n_args-1) func += ", "; + } + func += ")"; + if( is_c || template_for_Kokkos.empty() ) { + return func; + } + + template_for_Kokkos.pop_back(); + template_for_Kokkos.pop_back(); + return "\ntemplate <" + template_for_Kokkos + ">\n" + func; + } + + // Returns the declaration, no semi colon at the end + std::string get_function_declaration(const ASR::Function_t &x) { + template_for_Kokkos.clear(); + template_number = 0; + std::string sub; + ASR::Variable_t *return_var = LFortran::ASRUtils::EXPR2VAR(x.m_return_var); + if (ASRUtils::is_integer(*return_var->m_type)) { + int kind = ASR::down_cast(return_var->m_type)->m_kind; + switch (kind) { + case (1) : sub = "int8_t "; break; + case (2) : sub = "int16_t "; break; + case (4) : sub = "int32_t "; break; + case (8) : sub = "int64_t "; break; + } + } else if (ASRUtils::is_real(*return_var->m_type)) { + bool is_float = ASR::down_cast(return_var->m_type)->m_kind == 4; + if (is_float) { + sub = "float "; + } else { + sub = "double "; + } + } else if (ASRUtils::is_logical(*return_var->m_type)) { + sub = "bool "; + } else if (ASRUtils::is_character(*return_var->m_type)) { + if (gen_stdstring) { + sub = "std::string "; + } else { + sub = "char* "; + } + } else if (ASRUtils::is_complex(*return_var->m_type)) { + bool is_float = ASR::down_cast(return_var->m_type)->m_kind == 4; + if (is_float) { + if (gen_stdcomplex) { + sub = "std::complex "; + } else { + sub = "float complex "; + } + } else { + if (gen_stdcomplex) { + sub = "std::complex "; + } else { + sub = "double complex "; + } + } + } else if (ASR::is_a(*return_var->m_type)) { + sub = "void* "; + } else { + throw CodeGenError("Return type not supported in function '" + + std::string(x.m_name) + + + "'", return_var->base.base.loc); + } + std::string sym_name = x.m_name; + if (sym_name == "main") { + sym_name = "_xx_lcompilers_changed_main_xx"; + } + std::string func = sub + sym_name + "("; + for (size_t i=0; im_intent)); + if( is_c ) { + func += self().convert_variable_decl(*arg, false); + } else { + func += self().convert_variable_decl(*arg, false, true); + } + if (i < x.n_args-1) func += ", "; + } + func += ")"; + if( is_c || template_for_Kokkos.empty() ) { + return func; + } + + template_for_Kokkos.pop_back(); + template_for_Kokkos.pop_back(); + return "\ntemplate <" + template_for_Kokkos + ">\n" + func; + } + + std::string declare_all_functions(const SymbolTable &scope) { + std::string code; + for (auto &item : scope.get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Subroutine_t *s = ASR::down_cast(item.second); + code += get_subroutine_declaration(*s) + ";\n"; + } + if (ASR::is_a(*item.second)) { + ASR::Function_t *s = ASR::down_cast(item.second); + code += get_function_declaration(*s) + ";\n"; + } + } + return code; + } + + void visit_Subroutine(const ASR::Subroutine_t &x) { + indentation_level += 1; + std::string sub = get_subroutine_declaration(x); + if (x.m_abi == ASR::abiType::BindC + && x.m_deftype == ASR::deftypeType::Interface) { + sub += ";\n"; + } else { + sub += "\n"; + for (auto &item : x.m_symtab->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Variable_t *v = ASR::down_cast(item.second); + if (v->m_intent == LFortran::ASRUtils::intent_local) { + SymbolInfo s; + s.needs_declaration = true; + sym_info[get_hash((ASR::asr_t*)v)] = s; + } + } + } + + std::string body; + for (size_t i=0; iget_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Variable_t *v = ASR::down_cast(item.second); + if (v->m_intent == LFortran::ASRUtils::intent_local) { + if (sym_info[get_hash((ASR::asr_t*) v)].needs_declaration) { + std::string indent(indentation_level*indentation_spaces, ' '); + decl += indent; + decl += self().convert_variable_decl(*v) + ";\n"; + } + } + } + } + + sub += "{\n" + decl + body + "}\n"; + } + sub += "\n"; + src = sub; + indentation_level -= 1; + } + + void visit_Function(const ASR::Function_t &x) { + if (std::string(x.m_name) == "size" && intrinsic_module ) { + // Intrinsic function `size` + SymbolInfo s; + s.intrinsic_function = true; + sym_info[get_hash((ASR::asr_t*)&x)] = s; + src = ""; + return; + } else if (( + std::string(x.m_name) == "int" || + std::string(x.m_name) == "char" || + std::string(x.m_name) == "present" || + std::string(x.m_name) == "len" || + std::string(x.m_name) == "not" + ) && intrinsic_module) { + // Intrinsic function `int` + SymbolInfo s; + s.intrinsic_function = true; + sym_info[get_hash((ASR::asr_t*)&x)] = s; + src = ""; + return; + } else { + SymbolInfo s; + s.intrinsic_function = false; + sym_info[get_hash((ASR::asr_t*)&x)] = s; + } + std::string sub = get_function_declaration(x); + if (x.m_abi == ASR::abiType::BindC + && x.m_deftype == ASR::deftypeType::Interface) { + sub += ";\n"; + } else { + sub += "\n"; + + indentation_level += 1; + std::string indent(indentation_level*indentation_spaces, ' '); + std::string decl; + for (auto &item : x.m_symtab->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Variable_t *v = ASR::down_cast(item.second); + if (v->m_intent == LFortran::ASRUtils::intent_local || v->m_intent == LFortran::ASRUtils::intent_return_var) { + decl += indent + self().convert_variable_decl(*v) + ";\n"; + } + } + } + + current_function = &x; + std::string body; + + for (size_t i=0; i 0 && ASR::is_a(*x.m_body[x.n_body-1])) { + visited_return = true; + } + + if(!visited_return) { + body += indent + "return " + + LFortran::ASRUtils::EXPR2VAR(x.m_return_var)->m_name + + ";\n"; + } + + if (decl.size() > 0 || body.size() > 0) { + sub += "{\n" + decl + body + "}\n"; + } else { + sub[sub.size()-1] = ';'; + sub += "\n"; + } + indentation_level -= 1; + } + sub += "\n"; + src = sub; + } + + void visit_FunctionCall(const ASR::FunctionCall_t &x) { + ASR::Function_t *fn = ASR::down_cast( + LFortran::ASRUtils::symbol_get_past_external(x.m_name)); + std::string fn_name = fn->m_name; + if (sym_info[get_hash((ASR::asr_t*)fn)].intrinsic_function) { + if (fn_name == "size") { + LFORTRAN_ASSERT(x.n_args > 0); + self().visit_expr(*x.m_args[0].m_value); + std::string var_name = src; + std::string args; + if (x.n_args == 1) { + args = "0"; + } else { + for (size_t i=1; i 0); + self().visit_expr(*x.m_args[0].m_value); + src = "(int)" + src; + } else if (fn_name == "not") { + LFORTRAN_ASSERT(x.n_args > 0); + self().visit_expr(*x.m_args[0].m_value); + src = "!(" + src + ")"; + } else { + throw CodeGenError("Intrinsic function '" + fn_name + + "' not implemented"); + } + } else { + std::string args; + for (size_t i=0; idata->extent(" + args + ")"; + } + + void visit_Assignment(const ASR::Assignment_t &x) { + std::string target; + if (ASR::is_a(*x.m_target)) { + visit_Var(*ASR::down_cast(x.m_target)); + target = src; + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_target)) && !is_c ) { + target += "->data"; + } + } else if (ASR::is_a(*x.m_target)) { + self().visit_ArrayItem(*ASR::down_cast(x.m_target)); + target = src; + } else if (ASR::is_a(*x.m_target)) { + visit_DerivedRef(*ASR::down_cast(x.m_target)); + target = src; + } else { + LFORTRAN_ASSERT(false) + } + from_std_vector_helper.clear(); + self().visit_expr(*x.m_value); + std::string value = src; + std::string indent(indentation_level*indentation_spaces, ' '); + if( !from_std_vector_helper.empty() ) { + src = from_std_vector_helper; + } else { + src.clear(); + } + src += indent + target + " = " + value + ";\n"; + from_std_vector_helper.clear(); + } + + void visit_IntegerConstant(const ASR::IntegerConstant_t &x) { + src = std::to_string(x.m_n); + last_expr_precedence = 2; + } + + void visit_RealConstant(const ASR::RealConstant_t &x) { + src = double_to_scientific(x.m_r); + last_expr_precedence = 2; + } + + + void visit_StringConstant(const ASR::StringConstant_t &x) { + src = "\""; + std::string s = x.m_s; + for (size_t idx=0; idx < s.size(); idx++) { + if (s[idx] == '\n') { + src += "\\n"; + } else if (s[idx] == '\\') { + src += "\\\\"; + } else if (s[idx] == '\"') { + src += "\\\""; + } else { + src += s[idx]; + } + } + src += "\""; + last_expr_precedence = 2; + } + + void visit_LogicalConstant(const ASR::LogicalConstant_t &x) { + if (x.m_value == true) { + src = "true"; + } else { + src = "false"; + } + last_expr_precedence = 2; + } + + void visit_Var(const ASR::Var_t &x) { + const ASR::symbol_t *s = ASRUtils::symbol_get_past_external(x.m_v); + ASR::Variable_t* sv = ASR::down_cast(s); + if( (sv->m_intent == ASRUtils::intent_in || + sv->m_intent == ASRUtils::intent_inout) && + is_c && ASRUtils::is_array(sv->m_type) && + ASRUtils::is_pointer(sv->m_type)) { + src = "(*" + std::string(ASR::down_cast(s)->m_name) + ")"; + } else { + src = std::string(ASR::down_cast(s)->m_name); + } + last_expr_precedence = 2; + } + + void visit_DerivedRef(const ASR::DerivedRef_t& x) { + std::string der_expr, member; + this->visit_expr(*x.m_v); + der_expr = std::move(src); + member = ASRUtils::symbol_name(x.m_m); + if( ASR::is_a(*x.m_v) ) { + src = der_expr + "." + member; + } else { + src = der_expr + "->" + member; + } + } + + void visit_Cast(const ASR::Cast_t &x) { + self().visit_expr(*x.m_arg); + switch (x.m_kind) { + case (ASR::cast_kindType::IntegerToReal) : { + src = "(float)(" + src + ")"; + break; + } + case (ASR::cast_kindType::RealToInteger) : { + src = "(int)(" + src + ")"; + break; + } + case (ASR::cast_kindType::RealToReal) : { + // In C++, we do not need to cast float to float explicitly: + // src = src; + break; + } + case (ASR::cast_kindType::IntegerToInteger) : { + // In C++, we do not need to cast int <-> long long explicitly: + // src = src; + break; + } + case (ASR::cast_kindType::ComplexToComplex) : { + break; + } + case (ASR::cast_kindType::IntegerToComplex) : { + if (is_c) { + headers.insert("complex"); + src = "CMPLX(" + src + ", 0)"; + } else { + src = "std::complex(" + src + ")"; + } + break; + } + case (ASR::cast_kindType::ComplexToReal) : { + if (is_c) { + headers.insert("complex"); + src = "creal(" + src + ")"; + } else { + src = "std::real(" + src + ")"; + } + break; + } + case (ASR::cast_kindType::RealToComplex) : { + if (is_c) { + headers.insert("complex"); + src = "CMPLX(" + src + ", 0.0)"; + } else { + src = "std::complex(" + src + ")"; + } + break; + } + case (ASR::cast_kindType::LogicalToInteger) : { + src = "(int)(" + src + ")"; + break; + } + case (ASR::cast_kindType::IntegerToLogical) : { + src = "(bool)(" + src + ")"; + break; + } + default : throw CodeGenError("Cast kind " + std::to_string(x.m_kind) + " not implemented", + x.base.base.loc); + } + last_expr_precedence = 2; + } + + void visit_IntegerCompare(const ASR::IntegerCompare_t &x) { + handle_Compare(x); + } + + void visit_RealCompare(const ASR::RealCompare_t &x) { + handle_Compare(x); + } + + void visit_ComplexCompare(const ASR::ComplexCompare_t &x) { + handle_Compare(x); + } + + void visit_LogicalCompare(const ASR::LogicalCompare_t &x) { + handle_Compare(x); + } + + void visit_StringCompare(const ASR::StringCompare_t &x) { + handle_Compare(x); + } + + template + void handle_Compare(const T &x) { + self().visit_expr(*x.m_left); + std::string left = std::move(src); + int left_precedence = last_expr_precedence; + self().visit_expr(*x.m_right); + std::string right = std::move(src); + int right_precedence = last_expr_precedence; + switch (x.m_op) { + case (ASR::cmpopType::Eq) : { last_expr_precedence = 10; break; } + case (ASR::cmpopType::Gt) : { last_expr_precedence = 9; break; } + case (ASR::cmpopType::GtE) : { last_expr_precedence = 9; break; } + case (ASR::cmpopType::Lt) : { last_expr_precedence = 9; break; } + case (ASR::cmpopType::LtE) : { last_expr_precedence = 9; break; } + case (ASR::cmpopType::NotEq): { last_expr_precedence = 10; break; } + default : LFORTRAN_ASSERT(false); // should never happen + } + if (left_precedence <= last_expr_precedence) { + src += left; + } else { + src += "(" + left + ")"; + } + src += ASRUtils::cmpop_to_str(x.m_op); + if (right_precedence <= last_expr_precedence) { + src += right; + } else { + src += "(" + right + ")"; + } + } + + void visit_IntegerBitNot(const ASR::IntegerBitNot_t& x) { + self().visit_expr(*x.m_arg); + int expr_precedence = last_expr_precedence; + last_expr_precedence = 3; + if (expr_precedence <= last_expr_precedence) { + src = "~" + src; + } else { + src = "~(" + src + ")"; + } + } + + void visit_IntegerUnaryMinus(const ASR::IntegerUnaryMinus_t &x) { + handle_UnaryMinus(x); + } + + void visit_RealUnaryMinus(const ASR::RealUnaryMinus_t &x) { + handle_UnaryMinus(x); + } + + template + void handle_UnaryMinus(const T &x) { + self().visit_expr(*x.m_arg); + int expr_precedence = last_expr_precedence; + last_expr_precedence = 3; + if (expr_precedence <= last_expr_precedence) { + src = "-" + src; + } else { + src = "-(" + src + ")"; + } + } + + void visit_LogicalNot(const ASR::LogicalNot_t &x) { + self().visit_expr(*x.m_arg); + int expr_precedence = last_expr_precedence; + last_expr_precedence = 3; + if (expr_precedence <= last_expr_precedence) { + src = "!" + src; + } else { + src = "!(" + src + ")"; + } + } + + std::string get_c_type_from_ttype_t(ASR::ttype_t* t) { + int kind = ASRUtils::extract_kind_from_ttype_t(t); + std::string type_src = ""; + switch( t->type ) { + case ASR::ttypeType::Integer: { + type_src = "int" + std::to_string(kind * 8) + "_t"; + break; + } + case ASR::ttypeType::Pointer: { + ASR::Pointer_t* ptr_type = ASR::down_cast(t); + type_src = get_c_type_from_ttype_t(ptr_type->m_type) + "*"; + break; + } + case ASR::ttypeType::CPtr: { + type_src = "void*"; + break; + } + case ASR::ttypeType::Derived: { + ASR::Derived_t* der_type = ASR::down_cast(t); + type_src = std::string("struct ") + ASRUtils::symbol_name(der_type->m_derived_type); + break; + } + default: { + throw CodeGenError("Type " + ASRUtils::type_to_str_python(t) + " not supported yet."); + } + } + return type_src; + } + + void visit_GetPointer(const ASR::GetPointer_t& x) { + self().visit_expr(*x.m_arg); + std::string arg_src = std::move(src); + std::string addr_prefix = "&"; + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_arg)) || + ASR::is_a(*ASRUtils::expr_type(x.m_arg)) ) { + addr_prefix.clear(); + } + src = addr_prefix + arg_src; + } + + void visit_PointerToCPtr(const ASR::PointerToCPtr_t& x) { + self().visit_expr(*x.m_arg); + std::string arg_src = std::move(src); + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_arg)) ) { + arg_src += "->data"; + } + std::string type_src = get_c_type_from_ttype_t(x.m_type); + src = "(" + type_src + ") " + arg_src; + } + + void visit_CPtrToPointer(const ASR::CPtrToPointer_t& x) { + self().visit_expr(*x.m_cptr); + std::string source_src = std::move(src); + self().visit_expr(*x.m_ptr); + std::string dest_src = std::move(src); + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_ptr)) ) { + dest_src += "->data"; + } + std::string type_src = get_c_type_from_ttype_t(ASRUtils::expr_type(x.m_ptr)); + std::string indent(indentation_level*indentation_spaces, ' '); + src = indent + dest_src + " = (" + type_src + ") " + source_src + ";\n"; + } + + void visit_IntegerBinOp(const ASR::IntegerBinOp_t &x) { + handle_BinOp(x); + } + + void visit_RealBinOp(const ASR::RealBinOp_t &x) { + handle_BinOp(x); + } + + void visit_ComplexBinOp(const ASR::ComplexBinOp_t &x) { + handle_BinOp(x); + } + + template + void handle_BinOp(const T &x) { + self().visit_expr(*x.m_left); + std::string left = std::move(src); + int left_precedence = last_expr_precedence; + self().visit_expr(*x.m_right); + std::string right = std::move(src); + int right_precedence = last_expr_precedence; + switch (x.m_op) { + case (ASR::binopType::Add) : { last_expr_precedence = 6; break; } + case (ASR::binopType::Sub) : { last_expr_precedence = 6; break; } + case (ASR::binopType::Mul) : { last_expr_precedence = 5; break; } + case (ASR::binopType::Div) : { last_expr_precedence = 5; break; } + case (ASR::binopType::Pow) : { + src = "pow(" + left + ", " + right + ")"; + if (is_c) { + headers.insert("math"); + } else { + src = "std::" + src; + } + return; + } + default: throw CodeGenError("BinOp: operator not implemented yet"); + } + src = ""; + if (left_precedence == 3) { + src += "(" + left + ")"; + } else { + if (left_precedence <= last_expr_precedence) { + src += left; + } else { + src += "(" + left + ")"; + } + } + src += ASRUtils::binop_to_str_python(x.m_op); + if (right_precedence == 3) { + src += "(" + right + ")"; + } else if (x.m_op == ASR::binopType::Sub) { + if (right_precedence < last_expr_precedence) { + src += right; + } else { + src += "(" + right + ")"; + } + } else { + if (right_precedence <= last_expr_precedence) { + src += right; + } else { + src += "(" + right + ")"; + } + } + } + + void visit_LogicalBinOp(const ASR::LogicalBinOp_t &x) { + self().visit_expr(*x.m_left); + std::string left = std::move(src); + int left_precedence = last_expr_precedence; + self().visit_expr(*x.m_right); + std::string right = std::move(src); + int right_precedence = last_expr_precedence; + switch (x.m_op) { + case (ASR::logicalbinopType::And): { + last_expr_precedence = 14; + break; + } + case (ASR::logicalbinopType::Or): { + last_expr_precedence = 15; + break; + } + case (ASR::logicalbinopType::NEqv): { + last_expr_precedence = 10; + break; + } + case (ASR::logicalbinopType::Eqv): { + last_expr_precedence = 10; + break; + } + default : throw CodeGenError("Unhandled switch case"); + } + + if (left_precedence <= last_expr_precedence) { + src += left; + } else { + src += "(" + left + ")"; + } + src += ASRUtils::logicalbinop_to_str_python(x.m_op); + if (right_precedence <= last_expr_precedence) { + src += right; + } else { + src += "(" + right + ")"; + } + } + + void visit_Allocate(const ASR::Allocate_t &x) { + std::string indent(indentation_level*indentation_spaces, ' '); + std::string out = indent + "// FIXME: allocate("; + for (size_t i=0; im_return_var)->m_name + + ";\n"; + } else { + src = indent + "return;\n"; + } + } + + void visit_GoToTarget(const ASR::GoToTarget_t & /* x */) { + // Ignore for now + src = ""; + } + + void visit_Stop(const ASR::Stop_t &x) { + if (x.m_code) { + self().visit_expr(*x.m_code); + } else { + src = "0"; + } + std::string indent(indentation_level*indentation_spaces, ' '); + src = indent + "exit(" + src + ");\n"; + } + + void visit_ErrorStop(const ASR::ErrorStop_t & /* x */) { + std::string indent(indentation_level*indentation_spaces, ' '); + if (is_c) { + src = indent + "fprintf(stderr, \"ERROR STOP\");\n"; + } else { + src = indent + "std::cerr << \"ERROR STOP\" << std::endl;\n"; + } + src += indent + "exit(1);\n"; + } + + void visit_ImpliedDoLoop(const ASR::ImpliedDoLoop_t &/*x*/) { + std::string indent(indentation_level*indentation_spaces, ' '); + std::string out = indent + " /* FIXME: implied do loop */ "; + src = out; + last_expr_precedence = 2; + } + + void visit_DoLoop(const ASR::DoLoop_t &x) { + std::string indent(indentation_level*indentation_spaces, ' '); + std::string out = indent + "for ("; + ASR::Variable_t *loop_var = LFortran::ASRUtils::EXPR2VAR(x.m_head.m_v); + std::string lvname=loop_var->m_name; + ASR::expr_t *a=x.m_head.m_start; + ASR::expr_t *b=x.m_head.m_end; + ASR::expr_t *c=x.m_head.m_increment; + LFORTRAN_ASSERT(a); + LFORTRAN_ASSERT(b); + int increment; + if (!c) { + increment = 1; + } else { + if (c->type == ASR::exprType::IntegerConstant) { + increment = ASR::down_cast(c)->m_n; + } else if (c->type == ASR::exprType::IntegerUnaryMinus) { + ASR::IntegerUnaryMinus_t *ium = ASR::down_cast(c); + increment = - ASR::down_cast(ium->m_arg)->m_n; + } else { + throw CodeGenError("Do loop increment type not supported"); + } + } + std::string cmp_op; + if (increment > 0) { + cmp_op = "<="; + } else { + cmp_op = ">="; + } + + out += lvname + "="; + self().visit_expr(*a); + out += src + "; " + lvname + cmp_op; + self().visit_expr(*b); + out += src + "; " + lvname; + if (increment == 1) { + out += "++"; + } else if (increment == -1) { + out += "--"; + } else { + out += "+=" + std::to_string(increment); + } + out += ") {\n"; + indentation_level += 1; + for (size_t i=0; i( + LFortran::ASRUtils::symbol_get_past_external(x.m_name)); + // TODO: use a mapping with a hash(s) instead: + std::string sym_name = s->m_name; + if (sym_name == "exit") { + sym_name = "_xx_lcompilers_changed_exit_xx"; + } + std::string out = indent + sym_name + "("; + for (size_t i=0; i(*x.m_args[i].m_value)) { + ASR::Variable_t *arg = LFortran::ASRUtils::EXPR2VAR(x.m_args[i].m_value); + std::string arg_name = arg->m_name; + if( ASRUtils::is_array(arg->m_type) && + ASRUtils::is_pointer(arg->m_type) ) { + out += "&" + arg_name; + } else { + out += arg_name; + } + } else { + self().visit_expr(*x.m_args[i].m_value); + if( ASR::is_a(*x.m_args[i].m_value) && + ASR::is_a(*ASRUtils::expr_type(x.m_args[i].m_value)) ) { + out += "&" + src; + } else { + out += src; + } + } + if (i < x.n_args-1) out += ", "; + } + out += ");\n"; + src = out; + } + +}; + +} // namespace LFortran + +#endif // LFORTRAN_ASR_TO_C_CPP_H diff --git a/src/libasr/codegen/asr_to_cpp.cpp b/src/libasr/codegen/asr_to_cpp.cpp index 6899b9c9c8..ba86db9e1a 100644 --- a/src/libasr/codegen/asr_to_cpp.cpp +++ b/src/libasr/codegen/asr_to_cpp.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -12,65 +13,9 @@ namespace LFortran { -namespace { - - // Local exception that is only used in this file to exit the visitor - // pattern and caught later (not propagated outside) - class CodeGenError - { - public: - diag::Diagnostic d; - public: - CodeGenError(const std::string &msg) - : d{diag::Diagnostic(msg, diag::Level::Error, diag::Stage::CodeGen)} - { } - }; - - class Abort {}; - -} - -// Platform dependent fast unique hash: -uint64_t get_hash(ASR::asr_t *node) -{ - return (uint64_t)node; -} - -struct SymbolInfo -{ - bool needs_declaration = true; - bool intrinsic_function = false; -}; - -std::string convert_dims(size_t n_dims, ASR::dimension_t *m_dims) -{ - std::string dims; - for (size_t i=0; i(*start) && ASR::is_a(*end)) { - ASR::IntegerConstant_t *s = ASR::down_cast(start); - ASR::IntegerConstant_t *e = ASR::down_cast(end); - if (s->m_n == 1) { - dims += "[" + std::to_string(e->m_n) + "]"; - } else { - throw CodeGenError("Lower dimension must be 1 for now"); - } - } else { - dims += "[ /* FIXME symbolic dimensions */ ]"; - } - } else { - throw CodeGenError("Dimension type not supported"); - } - } - return dims; -} - std::string format_type(const std::string &dims, const std::string &type, - const std::string &name, bool use_ref, bool dummy) + const std::string &name, bool use_ref, bool dummy, bool use_kokko=true, + std::string kokko_ref="&", bool use_name=false, size_t size=0) { std::string fmt; if (dims.size() == 0) { @@ -81,42 +26,210 @@ std::string format_type(const std::string &dims, const std::string &type, if (dummy) { std::string c; if (!use_ref) c = "const "; - fmt = "const Kokkos::View<" + c + type + dims + "> &" + name; + if( use_kokko ) { + fmt = "const Kokkos::View<" + c + type + dims + "> &" + name; + } else { + fmt = c + type + dims + " " + name; + } } else { - fmt = "Kokkos::View<" + type + dims + "> " + name - + "(\"" + name + "\")"; + if( use_kokko ) { + fmt = "Kokkos::View<" + type + dims + ">" + kokko_ref + " " + name; + if( use_name ) { + fmt += "(\"" + name + "\""; + if( size > 0 ) { + fmt += ", " + std::to_string(size); + } + fmt += ")"; + } + } else { + fmt = type + dims + " " + name; + } } } return fmt; } -class ASRToCPPVisitor : public ASR::BaseVisitor +std::string remove_characters(std::string s, char c) +{ + s.erase(remove(s.begin(), s.end(), c), s.end()); + return s; +} + +class ASRToCPPVisitor : public BaseCCPPVisitor { public: - diag::Diagnostics &diag; - std::map sym_info; - std::string src; - int indentation_level; - int indentation_spaces; - // The precedence of the last expression, using the table: - // https://en.cppreference.com/w/cpp/language/operator_precedence - int last_expr_precedence; - bool intrinsic_module = false; - const ASR::Function_t *current_function = nullptr; - ASRToCPPVisitor(diag::Diagnostics &diag) : diag{diag} {} + std::string array_types_decls; + std::map>> eltypedims2arraytype; + + ASRToCPPVisitor(diag::Diagnostics &diag, Platform &platform, + int64_t default_lower_bound) + : BaseCCPPVisitor(diag, platform, true, true, false, + default_lower_bound), + array_types_decls(std::string("\nstruct dimension_descriptor\n" + "{\n int32_t lower_bound, upper_bound;\n};\n")) {} + + std::string convert_dims(size_t n_dims, ASR::dimension_t *m_dims, size_t& size) + { + std::string dims; + size = 1; + for (size_t i=0; ivisit_expr(*m_dims[i].m_start); + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].lower_bound = " + src + ";\n"; + } else { + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].lower_bound = 0" + ";\n"; + } + if( m_dims[i].m_end ) { + this->visit_expr(*m_dims[i].m_end); + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].upper_bound = " + src + ";\n"; + } else { + sub += indent + std::string(v_m_name) + + "->dims[" + std::to_string(i) + "].upper_bound = -1" + ";\n"; + } + } + sub.pop_back(); + sub.pop_back(); + } + } else { + sub = format_type("", type_name, v_m_name, use_ref, dummy, false); + } + } + + std::string generate_templates_for_arrays(std::string v_name) { + std::string typename_T = "T" + std::to_string(template_number); + template_for_Kokkos += "typename " + typename_T + ", "; + template_number += 1; + return typename_T + "* " + v_name; + } - std::string convert_variable_decl(const ASR::Variable_t &v) + std::string convert_variable_decl(const ASR::Variable_t &v, bool use_static=true, + bool use_templates_for_arrays=false) { std::string sub; - bool use_ref = (v.m_intent == LFortran::ASRUtils::intent_out || v.m_intent == LFortran::ASRUtils::intent_inout); + bool use_ref = (v.m_intent == LFortran::ASRUtils::intent_out || + + v.m_intent == LFortran::ASRUtils::intent_inout); + bool is_array = ASRUtils::is_array(v.m_type); bool dummy = LFortran::ASRUtils::is_arg_dummy(v.m_intent); if (ASRUtils::is_pointer(v.m_type)) { ASR::ttype_t *t2 = ASR::down_cast(v.m_type)->m_type; if (ASRUtils::is_integer(*t2)) { ASR::Integer_t *t = ASR::down_cast(t2); - std::string dims = convert_dims(t->n_dims, t->m_dims); - sub = format_type(dims, "int *", v.m_name, use_ref, dummy); + size_t size; + std::string dims = convert_dims(t->n_dims, t->m_dims, size); + std::string type_name = "int" + std::to_string(t->m_kind * 8) + "_t"; + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "i" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out, true); + } + } else { + sub = format_type(dims, "int *", v.m_name, use_ref, dummy); + } } else { diag.codegen_error_label("Type number '" + std::to_string(v.m_type->type) @@ -124,45 +237,101 @@ class ASRToCPPVisitor : public ASR::BaseVisitor throw Abort(); } } else { + std::string dims; + use_ref = use_ref && !is_array; if (ASRUtils::is_integer(*v.m_type)) { ASR::Integer_t *t = ASR::down_cast(v.m_type); - std::string dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); std::string type_name = "int"; if (t->m_kind == 8) type_name = "long long"; - sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "i" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out); + } + } else { + sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_real(*v.m_type)) { ASR::Real_t *t = ASR::down_cast(v.m_type); - std::string dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); std::string type_name = "float"; if (t->m_kind == 8) type_name = "double"; - sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "f" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out); + } + } else { + sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_complex(*v.m_type)) { ASR::Complex_t *t = ASR::down_cast(v.m_type); - std::string dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); std::string type_name = "std::complex"; if (t->m_kind == 8) type_name = "std::complex"; - sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "c" + std::to_string(t->m_kind * 8); + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out); + } + } else { + sub = format_type(dims, type_name, v.m_name, use_ref, dummy); + } } else if (ASRUtils::is_logical(*v.m_type)) { ASR::Logical_t *t = ASR::down_cast(v.m_type); - std::string dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); sub = format_type(dims, "bool", v.m_name, use_ref, dummy); } else if (ASRUtils::is_character(*v.m_type)) { ASR::Character_t *t = ASR::down_cast(v.m_type); - std::string dims = convert_dims(t->n_dims, t->m_dims); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); sub = format_type(dims, "std::string", v.m_name, use_ref, dummy); - if (v.m_symbolic_value) { - this->visit_expr(*v.m_symbolic_value); - std::string init = src; - sub += "=" + init; - } } else if (ASR::is_a(*v.m_type)) { ASR::Derived_t *t = ASR::down_cast(v.m_type); - std::string dims = convert_dims(t->n_dims, t->m_dims); - sub = format_type(dims, "struct", v.m_name, use_ref, dummy); - if (v.m_symbolic_value) { - this->visit_expr(*v.m_symbolic_value); - std::string init = src; - sub += "=" + init; + std::string der_type_name = ASRUtils::symbol_name(t->m_derived_type); + size_t size; + dims = convert_dims(t->n_dims, t->m_dims, size); + if( is_array ) { + if( use_templates_for_arrays ) { + sub += generate_templates_for_arrays(std::string(v.m_name)); + } else { + std::string encoded_type_name = "x" + der_type_name; + std::string type_name = std::string("struct ") + der_type_name; + generate_array_decl(sub, std::string(v.m_name), type_name, dims, + encoded_type_name, t->m_dims, t->n_dims, size, + use_ref, dummy, + v.m_intent != ASRUtils::intent_in && + v.m_intent != ASRUtils::intent_inout && + v.m_intent != ASRUtils::intent_out); + } + } else { + sub = format_type(dims, "struct", v.m_name, use_ref, dummy); } } else { diag.codegen_error_label("Type number '" @@ -170,12 +339,21 @@ class ASRToCPPVisitor : public ASR::BaseVisitor + "' not supported", {v.base.base.loc}, ""); throw Abort(); } + if (dims.size() == 0 && v.m_storage == ASR::storage_typeType::Save && use_static) { + sub = "static " + sub; + } + if (dims.size() == 0 && v.m_symbolic_value) { + this->visit_expr(*v.m_symbolic_value); + std::string init = src; + sub += "=" + init; + } } return sub; } void visit_TranslationUnit(const ASR::TranslationUnit_t &x) { + global_scope = x.m_global_scope; // All loose statements must be converted to a function, so the items // must be empty: LFORTRAN_ASSERT(x.n_items == 0); @@ -204,11 +382,26 @@ Kokkos::View from_std_vector(const std::vector &v) } )"; - unit_src += headers; - // TODO: We need to pre-declare all functions first, then generate code + // Pre-declare all functions first, then generate code // Otherwise some function might not be found. + unit_src += "// Forward declarations\n"; + unit_src += declare_all_functions(*x.m_global_scope); + // Now pre-declare all functions from modules and programs + for (auto &item : x.m_global_scope->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Module_t *m = ASR::down_cast(item.second); + unit_src += declare_all_functions(*m->m_symtab); + } else if (ASR::is_a(*item.second)) { + ASR::Program_t *p = ASR::down_cast(item.second); + unit_src += "namespace {\n" + + declare_all_functions(*p->m_symtab) + + "}\n"; + } + } + unit_src += "\n"; + unit_src += "// Implementations\n"; { // Process intrinsic modules in the right order @@ -255,31 +448,7 @@ Kokkos::View from_std_vector(const std::vector &v) } } - src = unit_src; - } - - void visit_Module(const ASR::Module_t &x) { - if (startswith(x.m_name, "lfortran_intrinsic_")) { - intrinsic_module = true; - } else { - intrinsic_module = false; - } - // Generate code for nested subroutines and functions first: - std::string contains; - for (auto &item : x.m_symtab->get_scope()) { - if (ASR::is_a(*item.second)) { - ASR::Subroutine_t *s = ASR::down_cast(item.second); - visit_Subroutine(*s); - contains += src; - } - if (ASR::is_a(*item.second)) { - ASR::Function_t *s = ASR::down_cast(item.second); - visit_Function(*s); - contains += src; - } - } - src = contains; - intrinsic_module = false; + src = headers + array_types_decls + unit_src; } void visit_Program(const ASR::Program_t &x) { @@ -301,13 +470,11 @@ Kokkos::View from_std_vector(const std::vector &v) // Generate code for the main program indentation_level += 1; std::string indent1(indentation_level*indentation_spaces, ' '); - indentation_level += 1; - std::string indent(indentation_level*indentation_spaces, ' '); std::string decl; for (auto &item : x.m_symtab->get_scope()) { if (ASR::is_a(*item.second)) { ASR::Variable_t *v = ASR::down_cast(item.second); - decl += indent; + decl += indent1; decl += convert_variable_decl(*v) + ";\n"; } } @@ -332,258 +499,6 @@ Kokkos::View from_std_vector(const std::vector &v) indentation_level -= 2; } - void visit_Subroutine(const ASR::Subroutine_t &x) { - indentation_level += 1; - std::string sub = "void " + std::string(x.m_name) + "("; - for (size_t i=0; im_intent)); - sub += convert_variable_decl(*arg); - if (i < x.n_args-1) sub += ", "; - } - sub += ")\n"; - - for (auto &item : x.m_symtab->get_scope()) { - if (ASR::is_a(*item.second)) { - ASR::Variable_t *v = ASR::down_cast(item.second); - if (v->m_intent == LFortran::ASRUtils::intent_local) { - SymbolInfo s; - s.needs_declaration = true; - sym_info[get_hash((ASR::asr_t*)v)] = s; - } - } - } - - std::string body; - for (size_t i=0; ivisit_stmt(*x.m_body[i]); - body += src; - } - - std::string decl; - for (auto &item : x.m_symtab->get_scope()) { - if (ASR::is_a(*item.second)) { - ASR::Variable_t *v = ASR::down_cast(item.second); - if (v->m_intent == LFortran::ASRUtils::intent_local) { - if (sym_info[get_hash((ASR::asr_t*) v)].needs_declaration) { - std::string indent(indentation_level*indentation_spaces, ' '); - decl += indent; - decl += convert_variable_decl(*v) + ";\n"; - } - } - } - } - - sub += "{\n" + decl + body + "}\n\n"; - src = sub; - indentation_level -= 1; - } - - void visit_Function(const ASR::Function_t &x) { - if (std::string(x.m_name) == "size" && intrinsic_module ) { - // Intrinsic function `size` - SymbolInfo s; - s.intrinsic_function = true; - sym_info[get_hash((ASR::asr_t*)&x)] = s; - src = ""; - return; - } else if (( - std::string(x.m_name) == "int" || - std::string(x.m_name) == "char" || - std::string(x.m_name) == "present" || - std::string(x.m_name) == "len" || - std::string(x.m_name) == "not" - ) && intrinsic_module) { - // Intrinsic function `int` - SymbolInfo s; - s.intrinsic_function = true; - sym_info[get_hash((ASR::asr_t*)&x)] = s; - src = ""; - return; - } else { - SymbolInfo s; - s.intrinsic_function = false; - sym_info[get_hash((ASR::asr_t*)&x)] = s; - } - std::string sub; - ASR::Variable_t *return_var = LFortran::ASRUtils::EXPR2VAR(x.m_return_var); - if (ASRUtils::is_integer(*return_var->m_type)) { - bool is_int = ASR::down_cast(return_var->m_type)->m_kind == 4; - if (is_int) { - sub = "int "; - } else { - sub = "long long "; - } - } else if (ASRUtils::is_real(*return_var->m_type)) { - bool is_float = ASR::down_cast(return_var->m_type)->m_kind == 4; - if (is_float) { - sub = "float "; - } else { - sub = "double "; - } - } else if (ASRUtils::is_logical(*return_var->m_type)) { - sub = "bool "; - } else if (ASRUtils::is_character(*return_var->m_type)) { - sub = "std::string "; - } else if (ASRUtils::is_complex(*return_var->m_type)) { - bool is_float = ASR::down_cast(return_var->m_type)->m_kind == 4; - if (is_float) { - sub = "std::complex "; - } else { - sub = "std::complex "; - } - } else { - throw CodeGenError("Return type not supported"); - } - sub = sub + std::string(x.m_name) + "("; - for (size_t i=0; im_intent)); - sub += convert_variable_decl(*arg); - if (i < x.n_args-1) sub += ", "; - } - sub += ")"; - if (x.m_abi == ASR::abiType::BindC) { - sub += ";\n"; - } else { - sub += "\n"; - - indentation_level += 1; - std::string indent(indentation_level*indentation_spaces, ' '); - std::string decl; - for (auto &item : x.m_symtab->get_scope()) { - if (ASR::is_a(*item.second)) { - ASR::Variable_t *v = ASR::down_cast(item.second); - if (v->m_intent == LFortran::ASRUtils::intent_local || v->m_intent == LFortran::ASRUtils::intent_return_var) { - decl += indent + convert_variable_decl(*v) + ";\n"; - } - } - } - - current_function = &x; - std::string body; - - for (size_t i=0; ivisit_stmt(*x.m_body[i]); - body += src; - } - current_function = nullptr; - bool visited_return = false; - - if (x.n_body > 0 && ASR::is_a(*x.m_body[x.n_body-1])) { - visited_return = true; - } - - if(!visited_return) { - body += indent + "return " - + LFortran::ASRUtils::EXPR2VAR(x.m_return_var)->m_name - + ";\n"; - } - - if (decl.size() > 0 || body.size() > 0) { - sub += "{\n" + decl + body + "}\n"; - } else { - sub[sub.size()-1] = ';'; - sub += "\n"; - } - indentation_level -= 1; - } - sub += "\n"; - src = sub; - } - - void visit_FunctionCall(const ASR::FunctionCall_t &x) { - ASR::Function_t *fn = ASR::down_cast( - LFortran::ASRUtils::symbol_get_past_external(x.m_name)); - std::string fn_name = fn->m_name; - if (sym_info[get_hash((ASR::asr_t*)fn)].intrinsic_function) { - if (fn_name == "size") { - LFORTRAN_ASSERT(x.n_args > 0); - visit_expr(*x.m_args[0].m_value); - std::string var_name = src; - std::string args; - if (x.n_args == 1) { - args = "0"; - } else { - for (size_t i=1; i 0); - visit_expr(*x.m_args[0].m_value); - src = "(int)" + src; - } else if (fn_name == "not") { - LFORTRAN_ASSERT(x.n_args > 0); - visit_expr(*x.m_args[0].m_value); - src = "!(" + src + ")"; - } else if (fn_name == "len") { - LFORTRAN_ASSERT(x.n_args > 0); - visit_expr(*x.m_args[0].m_value); - src = "(" + src + ").size()"; - } else { - throw CodeGenError("Intrinsic function '" + fn_name - + "' not implemented"); - } - } else { - std::string args; - for (size_t i=0; i(*x.m_target)) { - target = LFortran::ASRUtils::EXPR2VAR(x.m_target)->m_name; - } else if (ASR::is_a(*x.m_target)) { - visit_ArrayRef(*ASR::down_cast(x.m_target)); - target = src; - } else { - LFORTRAN_ASSERT(false) - } - this->visit_expr(*x.m_value); - std::string value = src; - std::string indent(indentation_level*indentation_spaces, ' '); - src = indent + target + " = " + value + ";\n"; - } - - void visit_IntegerConstant(const ASR::IntegerConstant_t &x) { - src = std::to_string(x.m_n); - last_expr_precedence = 2; - } - - void visit_RealConstant(const ASR::RealConstant_t &x) { - src = std::to_string(x.m_r); - last_expr_precedence = 2; - } - void visit_ComplexConstructor(const ASR::ComplexConstructor_t &x) { this->visit_expr(*x.m_re); std::string re = src; @@ -596,11 +511,6 @@ Kokkos::View from_std_vector(const std::vector &v) last_expr_precedence = 2; } - void visit_StringConstant(const ASR::StringConstant_t &x) { - src = "\"" + std::string(x.m_s) + "\""; - last_expr_precedence = 2; - } - void visit_ComplexConstant(const ASR::ComplexConstant_t &x) { std::string re = std::to_string(x.m_re); std::string im = std::to_string(x.m_im); @@ -633,30 +543,6 @@ Kokkos::View from_std_vector(const std::vector &v) last_expr_precedence = 2; } - void visit_Var(const ASR::Var_t &x) { - const ASR::symbol_t *s = ASRUtils::symbol_get_past_external(x.m_v); - src = ASR::down_cast(s)->m_name; - last_expr_precedence = 2; - } - - void visit_ArrayRef(const ASR::ArrayRef_t &x) { - const ASR::symbol_t *s = ASRUtils::symbol_get_past_external(x.m_v); - std::string out = ASR::down_cast(s)->m_name; - out += "["; - for (size_t i=0; i from_std_vector(const std::vector &v) last_expr_precedence = 2; } - void visit_Cast(const ASR::Cast_t &x) { - visit_expr(*x.m_arg); - switch (x.m_kind) { - case (ASR::cast_kindType::IntegerToReal) : { - src = "(float)(" + src + ")"; - break; - } - case (ASR::cast_kindType::RealToInteger) : { - src = "(int)(" + src + ")"; - break; - } - case (ASR::cast_kindType::RealToReal) : { - // In C++, we do not need to cast float to float explicitly: - // src = src; - break; - } - case (ASR::cast_kindType::IntegerToInteger) : { - // In C++, we do not need to cast int <-> long long explicitly: - // src = src; - break; - } - case (ASR::cast_kindType::ComplexToComplex) : { - break; - } - case (ASR::cast_kindType::IntegerToComplex) : { - src = "std::complex(" + src + ")"; - break; - } - case (ASR::cast_kindType::ComplexToReal) : { - src = "std::real(" + src + ")"; - break; - } - case (ASR::cast_kindType::LogicalToInteger) : { - src = "(int)(" + src + ")"; - break; - } - default : throw CodeGenError("Cast kind " + std::to_string(x.m_kind) + " not implemented"); - } - last_expr_precedence = 2; - } - - void visit_Compare(const ASR::Compare_t &x) { - this->visit_expr(*x.m_left); - std::string left = std::move(src); - int left_precedence = last_expr_precedence; - this->visit_expr(*x.m_right); - std::string right = std::move(src); - int right_precedence = last_expr_precedence; - switch (x.m_op) { - case (ASR::cmpopType::Eq) : { last_expr_precedence = 10; break; } - case (ASR::cmpopType::Gt) : { last_expr_precedence = 9; break; } - case (ASR::cmpopType::GtE) : { last_expr_precedence = 9; break; } - case (ASR::cmpopType::Lt) : { last_expr_precedence = 9; break; } - case (ASR::cmpopType::LtE) : { last_expr_precedence = 9; break; } - case (ASR::cmpopType::NotEq): { last_expr_precedence = 10; break; } - default : LFORTRAN_ASSERT(false); // should never happen - } - if (left_precedence <= last_expr_precedence) { - src += left; - } else { - src += "(" + left + ")"; - } - src += ASRUtils::cmpop_to_str(x.m_op); - if (right_precedence <= last_expr_precedence) { - src += right; - } else { - src += "(" + right + ")"; - } - } - - void visit_UnaryOp(const ASR::UnaryOp_t &x) { - this->visit_expr(*x.m_operand); - int expr_precedence = last_expr_precedence; - if (x.m_type->type == ASR::ttypeType::Integer) { - if (x.m_op == ASR::unaryopType::UAdd) { - // src = src; - // Skip unary plus, keep the previous precedence - } else if (x.m_op == ASR::unaryopType::USub) { - last_expr_precedence = 3; - if (expr_precedence <= last_expr_precedence) { - src = "-" + src; - } else { - src = "-(" + src + ")"; - } - } else if (x.m_op == ASR::unaryopType::Invert) { - last_expr_precedence = 3; - if (expr_precedence <= last_expr_precedence) { - src = "~" + src; - } else { - src = "~(" + src + ")"; - } - - } else if (x.m_op == ASR::unaryopType::Not) { - last_expr_precedence = 3; - if (expr_precedence <= last_expr_precedence) { - src = "!" + src; - } else { - src = "!(" + src + ")"; - } - } else { - throw CodeGenError("Unary type not implemented yet for Integer"); - } - return; - } else if (x.m_type->type == ASR::ttypeType::Real) { - if (x.m_op == ASR::unaryopType::UAdd) { - // src = src; - // Skip unary plus, keep the previous precedence - } else if (x.m_op == ASR::unaryopType::USub) { - last_expr_precedence = 3; - if (expr_precedence <= last_expr_precedence) { - src = "-" + src; - } else { - src = "-(" + src + ")"; - } - } else if (x.m_op == ASR::unaryopType::Not) { - last_expr_precedence = 3; - if (expr_precedence <= last_expr_precedence) { - src = "!" + src; - } else { - src = "!(" + src + ")"; - } - } else { - throw CodeGenError("Unary type not implemented yet for Real"); - } - return; - } else if (x.m_type->type == ASR::ttypeType::Logical) { - if (x.m_op == ASR::unaryopType::Not) { - last_expr_precedence = 3; - if (expr_precedence <= last_expr_precedence) { - src = "!" + src; - } else { - src = "!(" + src + ")"; - } - return; - } else { - throw CodeGenError("Unary type not implemented yet for Logical"); - } - } else { - throw CodeGenError("UnaryOp: type not supported yet"); - } - } - - void visit_BinOp(const ASR::BinOp_t &x) { - this->visit_expr(*x.m_left); - std::string left = std::move(src); - int left_precedence = last_expr_precedence; - this->visit_expr(*x.m_right); - std::string right = std::move(src); - int right_precedence = last_expr_precedence; - switch (x.m_op) { - case (ASR::binopType::Add) : { last_expr_precedence = 6; break; } - case (ASR::binopType::Sub) : { last_expr_precedence = 6; break; } - case (ASR::binopType::Mul) : { last_expr_precedence = 5; break; } - case (ASR::binopType::Div) : { last_expr_precedence = 5; break; } - case (ASR::binopType::Pow) : { - src = "std::pow(" + left + ", " + right + ")"; - return; - } - default: throw CodeGenError("BinOp: operator not implemented yet"); - } - src = ""; - if (left_precedence == 3) { - src += "(" + left + ")"; - } else { - if (left_precedence <= last_expr_precedence) { - src += left; - } else { - src += "(" + left + ")"; - } - } - src += ASRUtils::binop_to_str(x.m_op); - if (right_precedence == 3) { - src += "(" + right + ")"; - } else if (x.m_op == ASR::binopType::Sub) { - if (right_precedence < last_expr_precedence) { - src += right; - } else { - src += "(" + right + ")"; - } - } else { - if (right_precedence <= last_expr_precedence) { - src += right; - } else { - src += "(" + right + ")"; - } - } - } - void visit_StringConcat(const ASR::StringConcat_t &x) { this->visit_expr(*x.m_left); std::string left = std::move(src); @@ -882,47 +580,9 @@ Kokkos::View from_std_vector(const std::vector &v) } } - void visit_BoolOp(const ASR::BoolOp_t &x) { - this->visit_expr(*x.m_left); - std::string left = std::move(src); - int left_precedence = last_expr_precedence; - this->visit_expr(*x.m_right); - std::string right = std::move(src); - int right_precedence = last_expr_precedence; - switch (x.m_op) { - case (ASR::boolopType::And): { - last_expr_precedence = 14; - break; - } - case (ASR::boolopType::Or): { - last_expr_precedence = 15; - break; - } - case (ASR::boolopType::NEqv): { - last_expr_precedence = 10; - break; - } - case (ASR::boolopType::Eqv): { - last_expr_precedence = 10; - break; - } - default : throw CodeGenError("Unhandled switch case"); - } - - if (left_precedence <= last_expr_precedence) { - src += left; - } else { - src += "(" + left + ")"; - } - src += ASRUtils::boolop_to_str(x.m_op); - if (right_precedence <= last_expr_precedence) { - src += right; - } else { - src += "(" + right + ")"; - } - } - void visit_ArrayConstant(const ASR::ArrayConstant_t &x) { + std::string indent(indentation_level * indentation_spaces, ' '); + from_std_vector_helper = indent + "Kokkos::View r;\n"; std::string out = "from_std_vector({"; for (size_t i=0; ivisit_expr(*x.m_args[i]); @@ -930,77 +590,31 @@ Kokkos::View from_std_vector(const std::vector &v) if (i < x.n_args-1) out += ", "; } out += "})"; - src = out; + from_std_vector_helper += indent + "r = " + out + ";\n"; + src = "&r"; last_expr_precedence = 2; } void visit_Print(const ASR::Print_t &x) { std::string indent(indentation_level*indentation_spaces, ' '); - std::string out = indent + "std::cout "; + std::string out = indent + "std::cout ", sep; + if (x.m_separator) { + this->visit_expr(*x.m_separator); + sep = src; + } else { + sep = "\" \""; + } for (size_t i=0; ivisit_expr(*x.m_values[i]); out += "<< " + src + " "; + if (i+1 != x.n_values) { + out += "<< " + sep + " "; + } } out += "<< std::endl;\n"; src = out; } - void visit_Allocate(const ASR::Allocate_t &x) { - std::string indent(indentation_level*indentation_spaces, ' '); - std::string out = indent + "// FIXME: allocate("; - for (size_t i=0; i from_std_vector(const std::vector &v) src = out; } - void visit_WhileLoop(const ASR::WhileLoop_t &x) { - std::string indent(indentation_level*indentation_spaces, ' '); - std::string out = indent + "while ("; - visit_expr(*x.m_test); - out += src + ") {\n"; - indentation_level += 1; - for (size_t i=0; ivisit_stmt(*x.m_body[i]); - out += src; - } - out += indent + "}\n"; - indentation_level -= 1; - src = out; - } - - void visit_Exit(const ASR::Exit_t & /* x */) { - std::string indent(indentation_level*indentation_spaces, ' '); - src = indent + "break;\n"; - } - - void visit_Cycle(const ASR::Cycle_t & /* x */) { - std::string indent(indentation_level*indentation_spaces, ' '); - src = indent + "continue;\n"; - } - - void visit_Return(const ASR::Return_t & /* x */) { - std::string indent(indentation_level*indentation_spaces, ' '); - if (current_function) { - src = indent + "return " - + LFortran::ASRUtils::EXPR2VAR(current_function->m_return_var)->m_name - + ";\n"; - } else { - src = indent + "return;\n"; - } - } - - void visit_GoToTarget(const ASR::GoToTarget_t & /* x */) { - // Ignore for now - src = ""; - } - - void visit_Stop(const ASR::Stop_t & /* x */) { - std::string indent(indentation_level*indentation_spaces, ' '); - src = indent + "exit(0);\n"; - } - - void visit_ImpliedDoLoop(const ASR::ImpliedDoLoop_t &/*x*/) { - std::string indent(indentation_level*indentation_spaces, ' '); - std::string out = indent + " /* FIXME: implied do loop */ "; - src = out; - last_expr_precedence = 2; - } - - void visit_DoLoop(const ASR::DoLoop_t &x) { - std::string indent(indentation_level*indentation_spaces, ' '); - std::string out = indent + "for ("; - ASR::Variable_t *loop_var = LFortran::ASRUtils::EXPR2VAR(x.m_head.m_v); - std::string lvname=loop_var->m_name; - ASR::expr_t *a=x.m_head.m_start; - ASR::expr_t *b=x.m_head.m_end; - ASR::expr_t *c=x.m_head.m_increment; - LFORTRAN_ASSERT(a); - LFORTRAN_ASSERT(b); - int increment; - if (!c) { - increment = 1; - } else { - if (c->type == ASR::exprType::IntegerConstant) { - increment = ASR::down_cast(c)->m_n; - } else if (c->type == ASR::exprType::UnaryOp) { - ASR::UnaryOp_t *u = ASR::down_cast(c); - LFORTRAN_ASSERT(u->m_op == ASR::unaryopType::USub); - LFORTRAN_ASSERT(u->m_operand->type == ASR::exprType::IntegerConstant); - increment = - ASR::down_cast(u->m_operand)->m_n; - } else { - throw CodeGenError("Do loop increment type not supported"); - } - } - std::string cmp_op; - if (increment > 0) { - cmp_op = "<="; - } else { - cmp_op = ">="; - } - - out += lvname + "="; - visit_expr(*a); - out += src + "; " + lvname + cmp_op; - visit_expr(*b); - out += src + "; " + lvname; - if (increment == 1) { - out += "++"; - } else if (increment == -1) { - out += "--"; - } else { - out += "+=" + std::to_string(increment); - } - out += ") {\n"; - indentation_level += 1; - for (size_t i=0; ivisit_stmt(*x.m_body[i]); - out += src; - } - out += indent + "}\n"; - indentation_level -= 1; - src = out; - } - void visit_DoConcurrentLoop(const ASR::DoConcurrentLoop_t &x) { std::string indent(indentation_level*indentation_spaces, ' '); std::string out = indent + "Kokkos::parallel_for("; @@ -1153,78 +659,40 @@ Kokkos::View from_std_vector(const std::vector &v) src = out; } - void visit_ErrorStop(const ASR::ErrorStop_t & /* x */) { - std::string indent(indentation_level*indentation_spaces, ' '); - src = indent + "std::cerr << \"ERROR STOP\" << std::endl;\n"; - src += indent + "exit(1);\n"; - } - - void visit_If(const ASR::If_t &x) { - std::string indent(indentation_level*indentation_spaces, ' '); - std::string out = indent + "if ("; - visit_expr(*x.m_test); - out += src + ") {\n"; - indentation_level += 1; - for (size_t i=0; ivisit_stmt(*x.m_body[i]); - out += src; - } - out += indent + "}"; - if (x.n_orelse == 0) { - out += "\n"; - } else { - out += " else {\n"; - for (size_t i=0; ivisit_stmt(*x.m_orelse[i]); - out += src; - } - out += indent + "}\n"; - } - indentation_level -= 1; - src = out; - } - - void visit_IfExp(const ASR::IfExp_t &x) { - // IfExp is like a ternary operator in c++ - // test ? body : orelse; - std::string out = "("; - visit_expr(*x.m_test); - out += src + ") ? ("; - visit_expr(*x.m_body); - out += src + ") : ("; - visit_expr(*x.m_orelse); - out += src + ")"; - src = out; - last_expr_precedence = 16; - } - - void visit_SubroutineCall(const ASR::SubroutineCall_t &x) { - std::string indent(indentation_level*indentation_spaces, ' '); - ASR::Subroutine_t *s = ASR::down_cast( - LFortran::ASRUtils::symbol_get_past_external(x.m_name)); - std::string out = indent + s->m_name + "("; + void visit_ArrayItem(const ASR::ArrayItem_t &x) { + this->visit_expr(*x.m_v); + std::string array = src; + std::string out = array; + ASR::dimension_t* m_dims; + ASRUtils::extract_dimensions_from_ttype(ASRUtils::expr_type(x.m_v), m_dims); + out += "->data->operator[]("; + std::string index = ""; for (size_t i=0; i(*x.m_args[i].m_value)) { - ASR::Variable_t *arg = LFortran::ASRUtils::EXPR2VAR(x.m_args[i].m_value); - std::string arg_name = arg->m_name; - out += arg_name; + std::string current_index = ""; + if (x.m_args[i].m_right) { + this->visit_expr(*x.m_args[i].m_right); } else { - this->visit_expr(*x.m_args[i].m_value); - out += src; + src = "/* FIXME right index */"; + } + out += src; + out += " - " + array + "->dims[" + std::to_string(i) + "].lower_bound"; + if (i < x.n_args - 1) { + out += ", "; } - if (i < x.n_args-1) out += ", "; } - out += ");\n"; + out += ")"; + last_expr_precedence = 2; src = out; } }; Result asr_to_cpp(Allocator &al, ASR::TranslationUnit_t &asr, - diag::Diagnostics &diagnostics) + diag::Diagnostics &diagnostics, Platform &platform, + int64_t default_lower_bound) { - pass_unused_functions(al, asr); - ASRToCPPVisitor v(diagnostics); + pass_unused_functions(al, asr, true); + ASRToCPPVisitor v(diagnostics, platform, default_lower_bound); try { v.visit_asr((ASR::asr_t &)asr); } catch (const CodeGenError &e) { diff --git a/src/libasr/codegen/asr_to_cpp.h b/src/libasr/codegen/asr_to_cpp.h index 0d58e7c1f7..b9c289e4d2 100644 --- a/src/libasr/codegen/asr_to_cpp.h +++ b/src/libasr/codegen/asr_to_cpp.h @@ -2,11 +2,12 @@ #define LFORTRAN_ASR_TO_CPP_H #include +#include namespace LFortran { Result asr_to_cpp(Allocator &al, ASR::TranslationUnit_t &asr, - diag::Diagnostics &diagnostics); + diag::Diagnostics &diagnostics, Platform &platform, int64_t default_lower_bound); } // namespace LFortran diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 4060b59821..c38e57ed40 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -41,25 +41,8 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include @@ -269,6 +252,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor std::unique_ptr llvm_utils; std::unique_ptr arr_descr; + uint64_t ptr_loads; + ASRToLLVMVisitor(Allocator &al, llvm::LLVMContext &context, Platform platform, diag::Diagnostics &diagnostics) : diag{diagnostics}, @@ -281,7 +266,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor arr_descr(LLVMArrUtils::Descriptor::get_descriptor(context, builder.get(), llvm_utils.get(), - LLVMArrUtils::DESCR_TYPE::_SimpleCMODescriptor)) + LLVMArrUtils::DESCR_TYPE::_SimpleCMODescriptor)), + ptr_loads(2) { } @@ -517,6 +503,46 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return nullptr; } + llvm::Type* getMemberType(ASR::ttype_t* mem_type, ASR::Variable_t* member) { + llvm::Type* llvm_mem_type = nullptr; + switch( mem_type->type ) { + case ASR::ttypeType::Integer: { + int a_kind = down_cast(mem_type)->m_kind; + llvm_mem_type = getIntType(a_kind); + break; + } + case ASR::ttypeType::Real: { + int a_kind = down_cast(mem_type)->m_kind; + llvm_mem_type = getFPType(a_kind); + break; + } + case ASR::ttypeType::Derived: { + llvm_mem_type = getDerivedType(mem_type); + break; + } + case ASR::ttypeType::Pointer: { + ASR::Pointer_t* ptr_type = ASR::down_cast(mem_type); + llvm_mem_type = getMemberType(ptr_type->m_type, member)->getPointerTo(); + break; + } + case ASR::ttypeType::Complex: { + int a_kind = down_cast(mem_type)->m_kind; + llvm_mem_type = getComplexType(a_kind); + break; + } + case ASR::ttypeType::Character: { + llvm_mem_type = character_type; + break; + } + default: + throw CodeGenError("Cannot identify the type of member, '" + + std::string(member->m_name) + + "' in derived type, '" + der_type_name + "'.", + member->base.base.loc); + } + return llvm_mem_type; + } + llvm::Type* getDerivedType(ASR::DerivedType_t* der_type, bool is_pointer=false) { std::string der_type_name = std::string(der_type->m_name); llvm::StructType* der_type_llvm; @@ -536,38 +562,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor const std::map& scope = der_type->m_symtab->get_scope(); for( auto itr = scope.begin(); itr != scope.end(); itr++ ) { ASR::Variable_t* member = (ASR::Variable_t*)(&(itr->second->base)); - llvm::Type* mem_type = nullptr; - switch( member->m_type->type ) { - case ASR::ttypeType::Integer: { - int a_kind = down_cast(member->m_type)->m_kind; - mem_type = getIntType(a_kind); - break; - } - case ASR::ttypeType::Real: { - int a_kind = down_cast(member->m_type)->m_kind; - mem_type = getFPType(a_kind); - break; - } - case ASR::ttypeType::Derived: { - mem_type = getDerivedType(member->m_type); - break; - } - case ASR::ttypeType::Complex: { - int a_kind = down_cast(member->m_type)->m_kind; - mem_type = getComplexType(a_kind); - break; - } - case ASR::ttypeType::Character: { - mem_type = character_type; - break; - } - default: - throw CodeGenError("Cannot identify the type of member, '" + - std::string(member->m_name) + - "' in derived type, '" + der_type_name + "'.", - member->base.base.loc); - } - member_types.push_back(mem_type); + llvm::Type* llvm_mem_type = getMemberType(member->m_type, member); + member_types.push_back(llvm_mem_type); name2memidx[der_type_name][std::string(member->m_name)] = member_idx; member_idx++; } @@ -742,6 +738,29 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return CreateLoad(presult); } + llvm::Value* lfortran_str_cmp(llvm::Value* left_arg, llvm::Value* right_arg, + std::string runtime_func_name) + { + llvm::Function *fn = module->getFunction(runtime_func_name); + if(!fn) { + llvm::FunctionType *function_type = llvm::FunctionType::get( + llvm::Type::getInt1Ty(context), { + character_type->getPointerTo(), + character_type->getPointerTo() + }, false); + fn = llvm::Function::Create(function_type, + llvm::Function::ExternalLinkage, runtime_func_name, *module); + } + llvm::AllocaInst *pleft_arg = builder->CreateAlloca(character_type, + nullptr); + builder->CreateStore(left_arg, pleft_arg); + llvm::AllocaInst *pright_arg = builder->CreateAlloca(character_type, + nullptr); + builder->CreateStore(right_arg, pright_arg); + std::vector args = {pleft_arg, pright_arg}; + return builder->CreateCall(fn, args); + } + llvm::Value* lfortran_strrepeat(llvm::Value* left_arg, llvm::Value* right_arg) { std::string runtime_func_name = "_lfortran_strrepeat"; @@ -1104,7 +1123,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListAppend(const ASR::ListAppend_t& x) { - ASR::Variable_t *l = ASR::down_cast(x.m_a); + ASR::Variable_t *l = EXPR2VAR(x.m_a); uint32_t v_h = get_hash((ASR::asr_t*)l); LFORTRAN_ASSERT(llvm_symtab.find(v_h) != llvm_symtab.end()); llvm::Value *plist = llvm_symtab[v_h]; @@ -1129,7 +1148,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListItem(const ASR::ListItem_t& x) { - ASR::Variable_t *l = ASR::down_cast(x.m_a); + ASR::Variable_t *l = EXPR2VAR(x.m_a); uint32_t v_h = get_hash((ASR::asr_t*)l); LFORTRAN_ASSERT(llvm_symtab.find(v_h) != llvm_symtab.end()); llvm::Value *plist = llvm_symtab[v_h]; @@ -1144,57 +1163,121 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *plist2 = CreateLoad(plist); tmp = lcompilers_list_item_i32(plist2, pos); } else { - throw CodeGenError("Integer kind not supported yet in ListAppend", x.base.base.loc); + throw CodeGenError("Integer kind not supported as index in ListItem", x.base.base.loc); } } else { - throw CodeGenError("List type not supported yet in ListAppend", x.base.base.loc); + throw CodeGenError("List type not supported yet in ListItem", x.base.base.loc); } } - void visit_ArrayRef(const ASR::ArrayRef_t& x) { + void visit_ArrayItem(const ASR::ArrayItem_t& x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; } - ASR::Variable_t *v = ASR::down_cast(x.m_v); - uint32_t v_h = get_hash((ASR::asr_t*)v); - LFORTRAN_ASSERT(llvm_symtab.find(v_h) != llvm_symtab.end()); - llvm::Value* array = llvm_symtab[v_h]; - std::vector indices; - for( size_t r = 0; r < x.n_args; r++ ) { - ASR::array_index_t curr_idx = x.m_args[r]; - this->visit_expr_wrapper(curr_idx.m_right, true); - indices.push_back(tmp); - } - tmp = arr_descr->get_single_element(array, indices, x.n_args); - } - - void visit_StringItem(const ASR::StringItem_t& x) { - if (x.m_value) { - this->visit_expr_wrapper(x.m_value, true); - return; + llvm::Value* array = nullptr; + if( ASR::is_a(*x.m_v) ) { + ASR::Variable_t *v = ASRUtils::EXPR2VAR(x.m_v); + if( ASR::is_a(*v->m_type) ) { + ASR::Derived_t* der_type = ASR::down_cast(v->m_type); + der_type_name = ASRUtils::symbol_name(ASRUtils::symbol_get_past_external(der_type->m_derived_type)); + } + uint32_t v_h = get_hash((ASR::asr_t*)v); + LFORTRAN_ASSERT(llvm_symtab.find(v_h) != llvm_symtab.end()); + array = llvm_symtab[v_h]; + } else { + int64_t ptr_loads_copy = ptr_loads; + ptr_loads = 0; + this->visit_expr(*x.m_v); + if( ASR::is_a(*ASRUtils::expr_type(x.m_v)) ) { + ASR::Derived_t* der_type = ASR::down_cast(ASRUtils::expr_type(x.m_v)); + der_type_name = ASRUtils::symbol_name(ASRUtils::symbol_get_past_external(der_type->m_derived_type)); + } + ptr_loads = ptr_loads_copy; + array = tmp; + } + ASR::dimension_t* m_dims; + int n_dims = ASRUtils::extract_dimensions_from_ttype( + ASRUtils::expr_type(x.m_v), m_dims); + if (is_a(*x.m_type) && n_dims == 0) { + // String indexing: + if (x.n_args != 1) { + throw CodeGenError("Only string(a) supported for now.", x.base.base.loc); + } + LFORTRAN_ASSERT(ASR::is_a(*x.m_args[0].m_right)); + this->visit_expr_wrapper(x.m_args[0].m_right, true); + llvm::Value *idx = tmp; + idx = builder->CreateSub(idx, llvm::ConstantInt::get(context, llvm::APInt(32, 1))); + //std::vector idx_vec = {llvm::ConstantInt::get(context, llvm::APInt(32, 0)), idx}; + std::vector idx_vec = {idx}; + llvm::Value *str = CreateLoad(array); + llvm::Value *p = CreateGEP(str, idx_vec); + // TODO: Currently the string starts at the right location, but goes to the end of the original string. + // We have to allocate a new string, copy it and add null termination. + + tmp = builder->CreateAlloca(character_type, nullptr); + builder->CreateStore(p, tmp); + + //tmp = p; + } else { + // Array indexing: + std::vector indices; + for( size_t r = 0; r < x.n_args; r++ ) { + ASR::array_index_t curr_idx = x.m_args[r]; + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = 2; + this->visit_expr_wrapper(curr_idx.m_right, true); + ptr_loads = ptr_loads_copy; + indices.push_back(tmp); + } + if (ASRUtils::expr_type(x.m_v)->type == ASR::ttypeType::Pointer) { + array = builder->CreateLoad(array); + } + tmp = arr_descr->get_single_element(array, indices, x.n_args); } - this->visit_expr_wrapper(x.m_idx, true); - llvm::Value *idx = tmp; - this->visit_expr_wrapper(x.m_arg, true); - llvm::Value *str = tmp; - tmp = lfortran_str_copy(str, idx, idx); } - void visit_StringSection(const ASR::StringSection_t& x) { + void visit_ArraySection(const ASR::ArraySection_t& x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; } - this->visit_expr_wrapper(x.m_arg, true); - llvm::Value *str = tmp; - this->visit_expr_wrapper(x.m_start, true); - llvm::Value *left = tmp; - this->visit_expr_wrapper(x.m_end, true); - llvm::Value *right = tmp; - tmp = lfortran_str_copy(str, left, right); + int64_t ptr_loads_copy = ptr_loads; + ptr_loads = 0; + this->visit_expr(*x.m_v); + ptr_loads = ptr_loads_copy; + llvm::Value* array = tmp; + ASR::dimension_t* m_dims; + int n_dims = ASRUtils::extract_dimensions_from_ttype( + ASRUtils::expr_type(x.m_v), m_dims); + LFORTRAN_ASSERT(ASR::is_a(*ASRUtils::expr_type(x.m_v)) && + n_dims == 0); + // String indexing: + if (x.n_args == 1) { + throw CodeGenError("Only string(a:b) supported for now.", x.base.base.loc); + } + + LFORTRAN_ASSERT(x.m_args[0].m_left) + LFORTRAN_ASSERT(x.m_args[0].m_right) + //throw CodeGenError("Only string(a:b) for a,b variables for now.", x.base.base.loc); + // Use the "right" index for now + this->visit_expr_wrapper(x.m_args[0].m_right, true); + llvm::Value *idx2 = tmp; + this->visit_expr_wrapper(x.m_args[0].m_left, true); + llvm::Value *idx1 = tmp; + // idx = builder->CreateSub(idx, llvm::ConstantInt::get(context, llvm::APInt(32, 1))); + //std::vector idx_vec = {llvm::ConstantInt::get(context, llvm::APInt(32, 0)), idx}; + // std::vector idx_vec = {idx}; + llvm::Value *str = CreateLoad(array); + // llvm::Value *p = CreateGEP(str, idx_vec); + // TODO: Currently the string starts at the right location, but goes to the end of the original string. + // We have to allocate a new string, copy it and add null termination. + llvm::Value *p = lfortran_str_copy(str, idx1, idx2); + + tmp = builder->CreateAlloca(character_type, nullptr); + builder->CreateStore(p, tmp); } void visit_DerivedRef(const ASR::DerivedRef_t& x) { @@ -1203,7 +1286,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return; } der_type_name = ""; + ASR::ttype_t* x_m_v_type = ASRUtils::expr_type(x.m_v); + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = ptr_loads_copy - ASR::is_a(*x_m_v_type); this->visit_expr(*x.m_v); + ptr_loads = ptr_loads_copy; ASR::Variable_t* member = down_cast(symbol_get_past_external(x.m_m)); std::string member_name = std::string(member->m_name); LFORTRAN_ASSERT(der_type_name.size() != 0); @@ -1219,9 +1306,17 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor std::vector idx_vec = { llvm::ConstantInt::get(context, llvm::APInt(32, 0)), llvm::ConstantInt::get(context, llvm::APInt(32, member_idx))}; + if( ASR::is_a(*x.m_v) && + is_nested_pointer(tmp) ) { + tmp = builder->CreateLoad(tmp); + } llvm::Value* tmp1 = CreateGEP(tmp, idx_vec); - if( member->m_type->type == ASR::ttypeType::Derived ) { - ASR::Derived_t* der = (ASR::Derived_t*)(&(member->m_type->base)); + ASR::ttype_t* member_type = member->m_type; + if( ASR::is_a(*member_type) ) { + member_type = ASR::down_cast(member_type)->m_type; + } + if( member_type->type == ASR::ttypeType::Derived ) { + ASR::Derived_t* der = (ASR::Derived_t*)(&(member_type->base)); ASR::DerivedType_t* der_type = (ASR::DerivedType_t*)(&(der->m_derived_type->base)); der_type_name = std::string(der_type->m_name); uint32_t h = get_hash((ASR::asr_t*)member); @@ -1305,6 +1400,43 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } llvm_symtab[h] = ptr; + } else if( x.m_type->type == ASR::ttypeType::CPtr ) { + llvm::Type* void_ptr = llvm::Type::getVoidTy(context)->getPointerTo(); + llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, + void_ptr); + if (!external) { + if (init_value) { + module->getNamedGlobal(x.m_name)->setInitializer( + init_value); + } else { + module->getNamedGlobal(x.m_name)->setInitializer( + llvm::ConstantPointerNull::get( + static_cast(void_ptr)) + ); + } + } + llvm_symtab[h] = ptr; + } else if(x.m_type->type == ASR::ttypeType::Pointer) { + ASR::dimension_t* m_dims = nullptr; + int n_dims = -1, a_kind = -1; + bool is_array_type = false, is_malloc_array_type = false; + llvm::Type* x_ptr = get_type_from_ttype_t(x.m_type, x.m_storage, is_array_type, + is_malloc_array_type, m_dims, n_dims, + a_kind); + llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name, + x_ptr); + if (!external) { + if (init_value) { + module->getNamedGlobal(x.m_name)->setInitializer( + init_value); + } else { + module->getNamedGlobal(x.m_name)->setInitializer( + llvm::ConstantPointerNull::get( + static_cast(x_ptr)) + ); + } + } + llvm_symtab[h] = ptr; } else { throw CodeGenError("Variable type not supported", x.base.base.loc); } @@ -1413,6 +1545,150 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return false; } + llvm::Type* get_type_from_ttype_t(ASR::ttype_t* asr_type, + ASR::storage_typeType m_storage, + bool& is_array_type, bool& is_malloc_array_type, + ASR::dimension_t*& m_dims, int& n_dims, + int& a_kind) { + llvm::Type* llvm_type = nullptr; + switch (asr_type->type) { + case (ASR::ttypeType::Integer) : { + ASR::Integer_t* v_type = down_cast(asr_type); + m_dims = v_type->m_dims; + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + is_malloc_array_type = true; + llvm_type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type); + } else { + llvm_type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type); + } + } else { + llvm_type = getIntType(a_kind); + } + break; + } + case (ASR::ttypeType::Real) : { + ASR::Real_t* v_type = down_cast(asr_type); + m_dims = v_type->m_dims; + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + is_malloc_array_type = true; + llvm_type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type); + } else { + llvm_type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type); + } + } else { + llvm_type = getFPType(a_kind); + } + break; + } + case (ASR::ttypeType::Complex) : { + ASR::Complex_t* v_type = down_cast(asr_type); + m_dims = v_type->m_dims; + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + is_malloc_array_type = true; + llvm_type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type); + } else { + llvm_type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type); + } + } else { + llvm_type = getComplexType(a_kind); + } + break; + } + case (ASR::ttypeType::Character) : { + ASR::Character_t* v_type = down_cast(asr_type); + m_dims = v_type->m_dims; + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + is_malloc_array_type = true; + llvm_type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type); + } else { + llvm_type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type); + } + } else { + llvm_type = character_type; + } + break; + } + case (ASR::ttypeType::Logical) : { + ASR::Logical_t* v_type = down_cast(asr_type); + m_dims = v_type->m_dims; + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + is_malloc_array_type = true; + llvm_type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type); + } else { + llvm_type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type); + } + } else { + llvm_type = llvm::Type::getInt1Ty(context); + } + break; + } + case (ASR::ttypeType::Derived) : { + ASR::Derived_t* v_type = down_cast(asr_type); + m_dims = v_type->m_dims; + n_dims = v_type->n_dims; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + is_malloc_array_type = true; + llvm_type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type); + } else { + llvm_type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type); + } + } else { + llvm_type = getDerivedType(asr_type, false); + } + break; + } + case (ASR::ttypeType::Pointer) : { + ASR::ttype_t *t2 = ASR::down_cast(asr_type)->m_type; + llvm_type = get_type_from_ttype_t(t2, m_storage, is_array_type, + is_malloc_array_type, m_dims, n_dims, a_kind); + llvm_type = llvm_type->getPointerTo(); + break; + } + case (ASR::ttypeType::List) : { + //ASR::List_t* v_type = down_cast(v->m_type); + //ASR::ttype_t *el_type = v_type->m_type; + llvm_type = list_type; + break; + } + case (ASR::ttypeType::CPtr) : { + llvm_type = llvm::Type::getVoidTy(context)->getPointerTo(); + break; + } + default : + throw CodeGenError("Support for type " + ASRUtils::type_to_str(asr_type) + + " not yet implemented."); + } + return llvm_type; + } + template void declare_vars(const T &x) { llvm::Value *target_var; @@ -1421,7 +1697,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::Variable_t *v = down_cast(item.second); uint32_t h = get_hash((ASR::asr_t*)v); llvm::Type *type; - ASR::ttype_t* m_type_; int n_dims = 0, a_kind = 4; ASR::dimension_t* m_dims = nullptr; bool is_array_type = false; @@ -1429,169 +1704,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (v->m_intent == intent_local || v->m_intent == intent_return_var || !v->m_intent) { - switch (v->m_type->type) { - case (ASR::ttypeType::Integer) : { - ASR::Integer_t* v_type = down_cast(v->m_type); - m_type_ = v->m_type; - m_dims = v_type->m_dims; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - is_malloc_array_type = true; - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type); - } - } else { - type = getIntType(a_kind); - } - break; - } - case (ASR::ttypeType::Real) : { - ASR::Real_t* v_type = down_cast(v->m_type); - m_type_ = v->m_type; - m_dims = v_type->m_dims; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - is_malloc_array_type = true; - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type); - } - } else { - type = getFPType(a_kind); - } - break; - } - case (ASR::ttypeType::Complex) : { - ASR::Complex_t* v_type = down_cast(v->m_type); - m_type_ = v->m_type; - m_dims = v_type->m_dims; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - is_malloc_array_type = true; - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type); - } - } else { - type = getComplexType(a_kind); - } - break; - } - case (ASR::ttypeType::Character) : { - ASR::Character_t* v_type = down_cast(v->m_type); - m_type_ = v->m_type; - m_dims = v_type->m_dims; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - is_malloc_array_type = true; - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type); - } - } else { - type = character_type; - } - break; - } - case (ASR::ttypeType::Logical) : { - ASR::Logical_t* v_type = down_cast(v->m_type); - m_type_ = v->m_type; - m_dims = v_type->m_dims; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - is_malloc_array_type = true; - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type); - } - } else { - type = llvm::Type::getInt1Ty(context); - } - break; - } - case (ASR::ttypeType::Derived) : { - ASR::Derived_t* v_type = down_cast(v->m_type); - m_type_ = v->m_type; - m_dims = v_type->m_dims; - n_dims = v_type->n_dims; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - is_malloc_array_type = true; - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type); - } - } else { - type = getDerivedType(m_type_, false); - } - break; - } - case (ASR::ttypeType::Pointer) : { - ASR::ttype_t *t2 = ASR::down_cast(v->m_type)->m_type; - switch (t2->type) { - case (ASR::ttypeType::Integer) : { - a_kind = down_cast(t2)->m_kind; - type = getIntType(a_kind, true); - break; - } - case (ASR::ttypeType::Real) : { - a_kind = down_cast(t2)->m_kind; - type = getFPType(a_kind, true); - break; - } - case (ASR::ttypeType::Complex) : { - a_kind = down_cast(t2)->m_kind; - type = getComplexType(a_kind, true); - break; - } - case (ASR::ttypeType::Character) : { - type = character_type; - break; - } - case (ASR::ttypeType::Derived) : { - throw CodeGenError("Pointers for Derived type not implemented yet in conversion", v->base.base.loc); - } - case (ASR::ttypeType::Logical) : { - type = llvm::Type::getInt1Ty(context); - break; - } - default : - throw CodeGenError("Type not implemented", v->base.base.loc); - } - break; - } - case (ASR::ttypeType::List) : { - //ASR::List_t* v_type = down_cast(v->m_type); - //ASR::ttype_t *el_type = v_type->m_type; - type = list_type; - break; - } - default : - throw CodeGenError("Type not implemented", v->base.base.loc); - } + type = get_type_from_ttype_t(v->m_type, v->m_storage, is_array_type, + is_malloc_array_type, m_dims, n_dims, + a_kind); /* * The following if block is used for converting any * general array descriptor to a pointer type which @@ -1634,18 +1749,23 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } llvm::AllocaInst *ptr = builder->CreateAlloca(type, nullptr, v->m_name); llvm_symtab[h] = ptr; - if( is_malloc_array_type ) { + if( is_malloc_array_type && + v->m_type->type != ASR::ttypeType::Pointer ) { arr_descr->fill_dimension_descriptor(ptr, n_dims); } - if( is_array_type && !is_malloc_array_type ) { + if( is_array_type && !is_malloc_array_type && + v->m_type->type != ASR::ttypeType::Pointer ) { fill_array_details(ptr, m_dims, n_dims); } - if( is_array_type && is_malloc_array_type ) { + if( is_array_type && is_malloc_array_type && + v->m_type->type != ASR::ttypeType::Pointer) { // Set allocatable arrays as unallocated arr_descr->set_is_allocated_flag(ptr, 0); } - if( v->m_symbolic_value != nullptr ) { + if( v->m_symbolic_value != nullptr && + !ASR::is_a(*v->m_type)) { target_var = ptr; + tmp = nullptr; this->visit_expr_wrapper(v->m_symbolic_value, true); llvm::Value *init_value = tmp; if (ASR::is_a(*v->m_symbolic_value)) { @@ -1700,201 +1820,205 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } - template - std::vector convert_args(const T &x) { - std::vector args; - for (size_t i=0; i(*symbol_get_past_external( - ASR::down_cast(x.m_args[i])->m_v))) { - ASR::Variable_t *arg = EXPR2VAR(x.m_args[i]); - LFORTRAN_ASSERT(is_arg_dummy(arg->m_intent)); - // We pass all arguments as pointers for now, - // except bind(C) value arguments that are passed by value - llvm::Type *type; - ASR::ttype_t* m_type_; - int n_dims = 0, a_kind = 4; - bool is_array_type = false; - ASR::Variable_t* v = arg; - switch (arg->m_type->type) { - case (ASR::ttypeType::Integer) : { - ASR::Integer_t* v_type = down_cast(arg->m_type); - m_type_ = arg->m_type; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - if (x.m_abi == ASR::abiType::BindC) { - // Bind(C) arrays are represened as a pointer - type = getIntType(a_kind, true); - } else { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type, true); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type, true); - } - } + llvm::Type* get_arg_type_from_ttype_t(ASR::ttype_t* asr_type, + ASR::abiType m_abi, ASR::abiType arg_m_abi, + ASR::storage_typeType m_storage, + bool arg_m_value_attr, + int& n_dims, int& a_kind, bool& is_array_type) { + llvm::Type* type = nullptr; + switch (asr_type->type) { + case (ASR::ttypeType::Integer) : { + ASR::Integer_t* v_type = down_cast(asr_type); + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + if (m_abi == ASR::abiType::BindC) { + // Bind(C) arrays are represened as a pointer + type = getIntType(a_kind, true); + } else { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type, true); } else { - if (arg->m_abi == ASR::abiType::BindC - && arg->m_value_attr) { - type = getIntType(a_kind, false); - } else { - type = getIntType(a_kind, true); - } + type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type, true); } - break; } - case (ASR::ttypeType::Pointer) : { - ASR::ttype_t *t2 = ASRUtils::type_get_past_pointer(arg->m_type); - switch (t2->type) { - case (ASR::ttypeType::Integer) : { - ASR::Integer_t* v_type = down_cast(t2); - m_type_ = arg->m_type; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - type = getIntType(a_kind, true); - break; - } - default: - throw CodeGenError("Type not implemented"); + } else { + if (arg_m_abi == ASR::abiType::BindC + && arg_m_value_attr) { + type = getIntType(a_kind, false); + } else { + type = getIntType(a_kind, true); + } + } + break; + } + case (ASR::ttypeType::Pointer) : { + ASR::ttype_t *t2 = ASRUtils::type_get_past_pointer(asr_type); + type = get_arg_type_from_ttype_t(t2, m_abi, arg_m_abi, + m_storage, arg_m_value_attr, n_dims, a_kind, + is_array_type); + type = type->getPointerTo(); + break; + } + case (ASR::ttypeType::Real) : { + ASR::Real_t* v_type = down_cast(asr_type); + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + if (m_abi == ASR::abiType::BindC) { + // Bind(C) arrays are represened as a pointer + type = getFPType(a_kind, true); + } else { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type, true); + } else { + type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type, true); } - break; } - case (ASR::ttypeType::Real) : { - ASR::Real_t* v_type = down_cast(arg->m_type); - m_type_ = arg->m_type; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - if (x.m_abi == ASR::abiType::BindC) { - // Bind(C) arrays are represened as a pointer - type = getFPType(a_kind, true); + } else { + if (arg_m_abi == ASR::abiType::BindC + && arg_m_value_attr) { + type = getFPType(a_kind, false); + } else { + type = getFPType(a_kind, true); + } + } + break; + } + case (ASR::ttypeType::Complex) : { + ASR::Complex_t* v_type = down_cast(asr_type); + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type, true); + } else { + type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type, true); + } + } else { + if (arg_m_abi == ASR::abiType::BindC + && arg_m_value_attr) { + if (a_kind == 4) { + if (platform == Platform::Windows) { + // type_fx2 is i64 + llvm::Type* type_fx2 = llvm::Type::getInt64Ty(context); + type = type_fx2; + } else if (platform == Platform::macOS_ARM) { + // type_fx2 is [2 x float] + llvm::Type* type_fx2 = llvm::ArrayType::get(llvm::Type::getFloatTy(context), 2); + type = type_fx2; } else { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type, true); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type, true); - } + // type_fx2 is <2 x float> + llvm::Type* type_fx2 = FIXED_VECTOR_TYPE::get(llvm::Type::getFloatTy(context), 2); + type = type_fx2; } } else { - if (arg->m_abi == ASR::abiType::BindC - && arg->m_value_attr) { - type = getFPType(a_kind, false); + LFORTRAN_ASSERT(a_kind == 8) + if (platform == Platform::Windows) { + // 128 bit aggregate type is passed by reference + type = getComplexType(a_kind, true); } else { - type = getFPType(a_kind, true); + // Pass by value + type = getComplexType(a_kind, false); } } - break; + } else { + type = getComplexType(a_kind, true); } - case (ASR::ttypeType::Complex) : { - ASR::Complex_t* v_type = down_cast(arg->m_type); - m_type_ = arg->m_type; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type, true); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type, true); - } - } else { - if (arg->m_abi == ASR::abiType::BindC - && arg->m_value_attr) { - if (a_kind == 4) { - if (platform == Platform::Windows) { - // type_fx2 is i64 - llvm::Type* type_fx2 = llvm::Type::getInt64Ty(context); - type = type_fx2; - } else if (platform == Platform::macOS_ARM) { - // type_fx2 is [2 x float] - llvm::Type* type_fx2 = llvm::ArrayType::get(llvm::Type::getFloatTy(context), 2); - type = type_fx2; - } else { - // type_fx2 is <2 x float> - llvm::Type* type_fx2 = FIXED_VECTOR_TYPE::get(llvm::Type::getFloatTy(context), 2); - type = type_fx2; - } - } else { - LFORTRAN_ASSERT(a_kind == 8) - if (platform == Platform::Windows) { - // 128 bit aggregate type is passed by reference - type = getComplexType(a_kind, true); - } else { - // Pass by value - type = getComplexType(a_kind, false); - } - } - } else { - type = getComplexType(a_kind, true); - } - } - break; - } - case (ASR::ttypeType::Character) : - if (arg->m_abi == ASR::abiType::BindC) { - type = character_type; - } else { - type = character_type->getPointerTo(); - } - break; - case (ASR::ttypeType::Logical) : { - ASR::Logical_t* v_type = down_cast(arg->m_type); - m_type_ = arg->m_type; - n_dims = v_type->n_dims; - a_kind = v_type->m_kind; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type, true); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type, true); - } - } else { - type = llvm::Type::getInt1PtrTy(context); - } - break; + } + break; + } + case (ASR::ttypeType::Character) : + if (arg_m_abi == ASR::abiType::BindC) { + type = character_type; + } else { + type = character_type->getPointerTo(); + } + break; + case (ASR::ttypeType::Logical) : { + ASR::Logical_t* v_type = down_cast(asr_type); + n_dims = v_type->n_dims; + a_kind = v_type->m_kind; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type, true); + } else { + type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type, true); } - case (ASR::ttypeType::Derived) : { - ASR::Derived_t* v_type = down_cast(arg->m_type); - m_type_ = arg->m_type; - n_dims = v_type->n_dims; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type, true); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type, true); - } - } else { - type = getDerivedType(arg->m_type, true); - } - break; + } else { + type = llvm::Type::getInt1PtrTy(context); + } + break; + } + case (ASR::ttypeType::Derived) : { + ASR::Derived_t* v_type = down_cast(asr_type); + n_dims = v_type->n_dims; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type, true); + } else { + type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type, true); } - case (ASR::ttypeType::Class) : { - ASR::Class_t* v_type = down_cast(arg->m_type); - m_type_ = arg->m_type; - n_dims = v_type->n_dims; - if( n_dims > 0 ) { - is_array_type = true; - llvm::Type* el_type = get_el_type(m_type_, a_kind); - if( v->m_storage == ASR::storage_typeType::Allocatable ) { - type = arr_descr->get_malloc_array_type(m_type_, a_kind, n_dims, el_type, true); - } else { - type = arr_descr->get_array_type(m_type_, a_kind, n_dims, el_type, true); - } - } else { - type = getClassType(arg->m_type, true); - } - break; + } else { + type = getDerivedType(asr_type, true); + } + break; + } + case (ASR::ttypeType::Class) : { + ASR::Class_t* v_type = down_cast(asr_type); + n_dims = v_type->n_dims; + if( n_dims > 0 ) { + is_array_type = true; + llvm::Type* el_type = get_el_type(asr_type, a_kind); + if( m_storage == ASR::storage_typeType::Allocatable ) { + type = arr_descr->get_malloc_array_type(asr_type, a_kind, n_dims, el_type, true); + } else { + type = arr_descr->get_array_type(asr_type, a_kind, n_dims, el_type, true); } - default : - LFORTRAN_ASSERT(false); + } else { + type = getClassType(asr_type, true); + } + break; + } + case (ASR::ttypeType::CPtr) : { + type = llvm::Type::getVoidTy(context)->getPointerTo(); + break; + } + default : + LFORTRAN_ASSERT(false); + } + return type; + } + + template + std::vector convert_args(const T &x) { + std::vector args; + for (size_t i=0; i(*symbol_get_past_external( + ASR::down_cast(x.m_args[i])->m_v))) { + ASR::Variable_t *arg = EXPR2VAR(x.m_args[i]); + LFORTRAN_ASSERT(is_arg_dummy(arg->m_intent)); + // We pass all arguments as pointers for now, + // except bind(C) value arguments that are passed by value + llvm::Type *type; + int n_dims = 0, a_kind = 4; + bool is_array_type = false; + type = get_arg_type_from_ttype_t(arg->m_type, x.m_abi, + arg->m_abi, arg->m_storage, arg->m_value_attr, + n_dims, a_kind, is_array_type); + if( arg->m_intent == ASRUtils::intent_out && + ASR::is_a(*arg->m_type) ) { + type = type->getPointerTo(); } std::uint32_t m_h; std::string m_name = std::string(x.m_name); @@ -1905,7 +2029,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::Subroutine_t* _sub = (ASR::Subroutine_t*)(&(x.base)); m_h = get_hash((ASR::asr_t*)_sub); } - if( is_array_type ) { + if( is_array_type && arg->m_type->type != ASR::ttypeType::Pointer ) { if( x.m_abi == ASR::abiType::Source ) { llvm::Type* orig_type = static_cast(type)->getElementType(); type = arr_descr->get_argument_type(orig_type, m_h, arg->m_name, arr_arg_type_cache); @@ -2100,18 +2224,23 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor void visit_Function(const ASR::Function_t &x) { instantiate_function(x); + if (x.m_deftype == ASR::deftypeType::Interface) { + // Interface does not have an implementation and it is already + // declared, so there is nothing to do here + return; + } visit_procedures(x); generate_function(x); parent_function = nullptr; } void visit_Subroutine(const ASR::Subroutine_t &x) { - if (x.m_abi != ASR::abiType::Source && - x.m_abi != ASR::abiType::Interactive && - x.m_abi != ASR::abiType::Intrinsic) { - return; - } instantiate_subroutine(x); + if (x.m_deftype == ASR::deftypeType::Interface) { + // Interface does not have an implementation and it is already + // declared, so there is nothing to do here + return; + } visit_procedures(x); generate_subroutine(x); parent_subroutine = nullptr; @@ -2120,6 +2249,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor void instantiate_subroutine(const ASR::Subroutine_t &x){ uint32_t h = get_hash((ASR::asr_t*)&x); llvm::Function *F = nullptr; + std::string sym_name = x.m_name; + if (sym_name == "main") { + sym_name = "_xx_lcompilers_changed_main_xx"; + } if (llvm_symtab_fn.find(h) != llvm_symtab_fn.end()) { /* throw CodeGenError("Subroutine code already generated for '" @@ -2133,10 +2266,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (x.m_bindc_name) { fn_name = x.m_bindc_name; } else { - fn_name = x.m_name; + fn_name = sym_name; } } else { - fn_name = mangle_prefix + x.m_name; + fn_name = mangle_prefix + sym_name; } if (llvm_symtab_fn_names.find(fn_name) == llvm_symtab_fn_names.end()) { llvm_symtab_fn_names[fn_name] = h; @@ -2193,6 +2326,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor void instantiate_function(const ASR::Function_t &x){ uint32_t h = get_hash((ASR::asr_t*)&x); llvm::Function *F = nullptr; + std::string sym_name = x.m_name; + if (sym_name == "main") { + sym_name = "_xx_lcompilers_changed_main_xx"; + } if (llvm_symtab_fn.find(h) != llvm_symtab_fn.end()) { /* throw CodeGenError("Function code already generated for '" @@ -2206,10 +2343,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (x.m_bindc_name) { fn_name = x.m_bindc_name; } else { - fn_name = x.m_name; + fn_name = sym_name; } } else { - fn_name = mangle_prefix + x.m_name; + fn_name = mangle_prefix + sym_name; } if (llvm_symtab_fn_names.find(fn_name) == llvm_symtab_fn_names.end()) { llvm_symtab_fn_names[fn_name] = h; @@ -2296,6 +2433,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor case (ASR::ttypeType::Logical) : return_type = llvm::Type::getInt1Ty(context); break; + case (ASR::ttypeType::CPtr) : + return_type = llvm::Type::getVoidTy(context)->getPointerTo(); + break; case (ASR::ttypeType::Derived) : throw CodeGenError("Derived return type not implemented yet"); break; @@ -2506,6 +2646,146 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } + bool is_nested_pointer(llvm::Value* val) { + // TODO: Remove this in future + // Related issue, https://github.com/lcompilers/lpython/pull/707#issuecomment-1169773106. + return val->getType()->isPointerTy() && + val->getType()->getContainedType(0)->isPointerTy(); + } + + void visit_CLoc(const ASR::CLoc_t& x) { + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = 0; + this->visit_expr(*x.m_arg); + ptr_loads = ptr_loads_copy; + if( is_nested_pointer(tmp) ) { + tmp = builder->CreateLoad(tmp); + } + if( arr_descr->is_array(tmp) ) { + tmp = builder->CreateLoad(arr_descr->get_pointer_to_data(tmp)); + } + tmp = builder->CreateBitCast(tmp, + llvm::Type::getVoidTy(context)->getPointerTo()); + } + + + llvm::Value* GetPointerCPtrUtil(llvm::Value* llvm_tmp) { + if( is_nested_pointer(llvm_tmp) ) { + llvm_tmp = builder->CreateLoad(llvm_tmp); + } + if( arr_descr->is_array(llvm_tmp) ) { + llvm_tmp = builder->CreateLoad(arr_descr->get_pointer_to_data(llvm_tmp)); + } + + // // TODO: refactor this into a function, it is being used a few times + // llvm::Type *target_type = llvm_tmp->getType(); + // // Create alloca to get a pointer, but do it + // // at the beginning of the function to avoid + // // using alloca inside a loop, which would + // // run out of stack + // llvm::BasicBlock &entry_block = builder->GetInsertBlock()->getParent()->getEntryBlock(); + // llvm::IRBuilder<> builder0(context); + // builder0.SetInsertPoint(&entry_block, entry_block.getFirstInsertionPt()); + // llvm::AllocaInst *target = builder0.CreateAlloca( + // target_type, nullptr, "call_arg_value_ptr"); + // builder->CreateStore(llvm_tmp, target); + // llvm_tmp = target; + return llvm_tmp; + } + + void visit_GetPointer(const ASR::GetPointer_t& x) { + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = 0; + this->visit_expr(*x.m_arg); + ptr_loads = ptr_loads_copy; + tmp = GetPointerCPtrUtil(tmp); + } + + void visit_PointerToCPtr(const ASR::PointerToCPtr_t& x) { + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = 0; + this->visit_expr(*x.m_arg); + ptr_loads = ptr_loads_copy; + if( !ASR::is_a(*x.m_arg) ) { + tmp = GetPointerCPtrUtil(tmp); + } + tmp = builder->CreateBitCast(tmp, + llvm::Type::getVoidTy(context)->getPointerTo()); + } + + + void visit_CPtrToPointer(const ASR::CPtrToPointer_t& x) { + ASR::expr_t *cptr = x.m_cptr, *fptr = x.m_ptr, *shape = x.m_shape; + int reduce_loads = 0; + if( ASR::is_a(*cptr) ) { + ASR::Variable_t* cptr_var = ASRUtils::EXPR2VAR(cptr); + reduce_loads = cptr_var->m_intent == ASRUtils::intent_in; + } + if( ASRUtils::is_array(ASRUtils::expr_type(fptr)) ) { + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = 1 - reduce_loads; + this->visit_expr(*cptr); + llvm::Value* llvm_cptr = tmp; + ptr_loads = 0; + this->visit_expr(*fptr); + llvm::Value* llvm_fptr = tmp; + ptr_loads = ptr_loads_copy; + llvm::Value* llvm_shape = nullptr; + if( shape ) { + this->visit_expr(*shape); + llvm_shape = tmp; + } + llvm::Type* llvm_fptr_type = llvm_fptr->getType(); + llvm_fptr_type = static_cast(llvm_fptr_type)->getElementType(); + llvm_fptr_type = static_cast(llvm_fptr_type)->getElementType(); + llvm::Value* fptr_array = builder->CreateAlloca(llvm_fptr_type); + ASR::dimension_t* fptr_dims; + int fptr_rank = ASRUtils::extract_dimensions_from_ttype( + ASRUtils::expr_type(fptr), + fptr_dims); + llvm::Value* llvm_rank = llvm::ConstantInt::get(context, llvm::APInt(32, fptr_rank)); + llvm::Value* dim_des = builder->CreateAlloca(arr_descr->get_dimension_descriptor_type(), llvm_rank); + builder->CreateStore(dim_des, arr_descr->get_pointer_to_dimension_descriptor_array(fptr_array, false)); + arr_descr->set_rank(fptr_array, llvm_rank); + builder->CreateStore(fptr_array, llvm_fptr); + llvm_fptr = fptr_array; + llvm::Value* fptr_data = arr_descr->get_pointer_to_data(llvm_fptr); + llvm::Value* fptr_des = arr_descr->get_pointer_to_dimension_descriptor_array(llvm_fptr); + llvm::Value* shape_data = llvm_shape; + if( llvm_shape && arr_descr->is_array(llvm_shape) ) { + shape_data = builder->CreateLoad(arr_descr->get_pointer_to_data(llvm_shape)); + } + llvm_cptr = builder->CreateBitCast(llvm_cptr, + static_cast(fptr_data->getType())->getElementType()); + builder->CreateStore(llvm_cptr, fptr_data); + for( int i = 0; i < fptr_rank; i++ ) { + llvm::Value* curr_dim = llvm::ConstantInt::get(context, llvm::APInt(32, i)); + llvm::Value* desi = arr_descr->get_pointer_to_dimension_descriptor(fptr_des, curr_dim); + llvm::Value* desi_lb = arr_descr->get_lower_bound(desi, false); + llvm::Value* desi_ub = arr_descr->get_upper_bound(desi, false); + llvm::Value* desi_size = arr_descr->get_dimension_size(fptr_des, curr_dim, false); + llvm::Value* i32_one = llvm::ConstantInt::get(context, llvm::APInt(32, 1)); + llvm::Value* new_lb = i32_one; + llvm::Value* new_ub = shape_data ? builder->CreateLoad(llvm_utils->create_ptr_gep(shape_data, i)) : i32_one; + builder->CreateStore(new_lb, desi_lb); + builder->CreateStore(new_ub, desi_ub); + builder->CreateStore(builder->CreateAdd(builder->CreateSub(new_ub, new_lb), i32_one), desi_size); + } + } else { + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = 1 - reduce_loads; + this->visit_expr(*cptr); + llvm::Value* llvm_cptr = tmp; + ptr_loads = 0; + this->visit_expr(*fptr); + llvm::Value* llvm_fptr = tmp; + ptr_loads = ptr_loads_copy; + llvm_cptr = builder->CreateBitCast(llvm_cptr, + static_cast(llvm_fptr->getType())->getElementType()); + builder->CreateStore(llvm_cptr, llvm_fptr); + } + } + void visit_Associate(const ASR::Associate_t& x) { ASR::Variable_t *asr_target = EXPR2VAR(x.m_target); ASR::Variable_t *asr_value = EXPR2VAR(x.m_value); @@ -2519,17 +2799,46 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_stmt(*x.m_overloaded); return ; } + + // TODO: Remove this check after supporting ListConstant + if( ASR::is_a(*ASRUtils::expr_type(x.m_value)) ) { + return ; + } + + if( ASR::is_a(*ASRUtils::expr_type(x.m_target)) && + ASR::is_a(*x.m_value) ) { + ASR::Variable_t *asr_target = EXPR2VAR(x.m_target); + ASR::GetPointer_t* get_ptr = ASR::down_cast(x.m_value); + ASR::Variable_t *asr_value = EXPR2VAR(get_ptr->m_arg); + uint32_t value_h = get_hash((ASR::asr_t*)asr_value); + uint32_t target_h = get_hash((ASR::asr_t*)asr_target); + builder->CreateStore(llvm_symtab[value_h], llvm_symtab[target_h]); + return ; + } llvm::Value *target, *value; uint32_t h; bool lhs_is_string_arrayref = false; - if( x.m_target->type == ASR::exprType::ArrayRef || + if( x.m_target->type == ASR::exprType::ArrayItem || + x.m_target->type == ASR::exprType::ArraySection || x.m_target->type == ASR::exprType::DerivedRef ) { this->visit_expr(*x.m_target); target = tmp; - if (is_a(*x.m_target)) { - ASR::ArrayRef_t *asr_target0 = ASR::down_cast(x.m_target); - if (is_a(*asr_target0->m_v)) { - ASR::Variable_t *asr_target = ASR::down_cast(asr_target0->m_v); + if (is_a(*x.m_target)) { + ASR::ArrayItem_t *asr_target0 = ASR::down_cast(x.m_target); + if (is_a(*asr_target0->m_v)) { + ASR::Variable_t *asr_target = ASRUtils::EXPR2VAR(asr_target0->m_v); + if ( is_a(*asr_target->m_type) ) { + ASR::Character_t *t = ASR::down_cast(asr_target->m_type); + if (t->n_dims == 0) { + target = CreateLoad(target); + lhs_is_string_arrayref = true; + } + } + } + } else if (is_a(*x.m_target)) { + ASR::ArraySection_t *asr_target0 = ASR::down_cast(x.m_target); + if (is_a(*asr_target0->m_v)) { + ASR::Variable_t *asr_target = ASRUtils::EXPR2VAR(asr_target0->m_v); if ( is_a(*asr_target->m_type) ) { ASR::Character_t *t = ASR::down_cast(asr_target->m_type); if (t->n_dims == 0) { @@ -2600,6 +2909,13 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_BlockCall(const ASR::BlockCall_t& x) { + if( x.m_label != -1 ) { + if( llvm_goto_targets.find(x.m_label) == llvm_goto_targets.end() ) { + llvm::BasicBlock *new_target = llvm::BasicBlock::Create(context, "goto_target"); + llvm_goto_targets[x.m_label] = new_target; + } + start_new_block(llvm_goto_targets[x.m_label]); + } LFORTRAN_ASSERT(ASR::is_a(*x.m_m)); ASR::Block_t* block = ASR::down_cast(x.m_m); declare_vars(*block); @@ -2610,7 +2926,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor inline void visit_expr_wrapper(const ASR::expr_t* x, bool load_ref=false) { this->visit_expr(*x); - if( x->type == ASR::exprType::ArrayRef || + if( x->type == ASR::exprType::ArrayItem || + x->type == ASR::exprType::ArraySection || x->type == ASR::exprType::DerivedRef ) { if( load_ref ) { tmp = CreateLoad(tmp); @@ -2618,11 +2935,48 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } - void visit_Compare(const ASR::Compare_t &x) { - if( x.m_overloaded ) { - this->visit_expr(*x.m_overloaded); - return ; + void visit_IntegerCompare(const ASR::IntegerCompare_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; } + this->visit_expr_wrapper(x.m_left, true); + llvm::Value *left = tmp; + this->visit_expr_wrapper(x.m_right, true); + llvm::Value *right = tmp; + switch (x.m_op) { + case (ASR::cmpopType::Eq) : { + tmp = builder->CreateICmpEQ(left, right); + break; + } + case (ASR::cmpopType::Gt) : { + tmp = builder->CreateICmpSGT(left, right); + break; + } + case (ASR::cmpopType::GtE) : { + tmp = builder->CreateICmpSGE(left, right); + break; + } + case (ASR::cmpopType::Lt) : { + tmp = builder->CreateICmpSLT(left, right); + break; + } + case (ASR::cmpopType::LtE) : { + tmp = builder->CreateICmpSLE(left, right); + break; + } + case (ASR::cmpopType::NotEq) : { + tmp = builder->CreateICmpNE(left, right); + break; + } + default : { + throw CodeGenError("Comparison operator not implemented", + x.base.base.loc); + } + } + } + + void visit_RealCompare(const ASR::RealCompare_t &x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; @@ -2631,167 +2985,162 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *left = tmp; this->visit_expr_wrapper(x.m_right, true); llvm::Value *right = tmp; - LFORTRAN_ASSERT(expr_type(x.m_left)->type == expr_type(x.m_right)->type); - ASR::ttypeType optype = expr_type(x.m_left)->type; - if (optype == ASR::ttypeType::Integer) { - switch (x.m_op) { - case (ASR::cmpopType::Eq) : { - tmp = builder->CreateICmpEQ(left, right); - break; - } - case (ASR::cmpopType::Gt) : { - tmp = builder->CreateICmpSGT(left, right); - break; - } - case (ASR::cmpopType::GtE) : { - tmp = builder->CreateICmpSGE(left, right); - break; - } - case (ASR::cmpopType::Lt) : { - tmp = builder->CreateICmpSLT(left, right); - break; - } - case (ASR::cmpopType::LtE) : { - tmp = builder->CreateICmpSLE(left, right); - break; - } - case (ASR::cmpopType::NotEq) : { - tmp = builder->CreateICmpNE(left, right); - break; - } - default : { - throw CodeGenError("Comparison operator not implemented", - x.base.base.loc); - } + switch (x.m_op) { + case (ASR::cmpopType::Eq) : { + tmp = builder->CreateFCmpUEQ(left, right); + break; } - } else if (optype == ASR::ttypeType::Real) { - switch (x.m_op) { - case (ASR::cmpopType::Eq) : { - tmp = builder->CreateFCmpUEQ(left, right); - break; - } - case (ASR::cmpopType::Gt) : { - tmp = builder->CreateFCmpUGT(left, right); - break; - } - case (ASR::cmpopType::GtE) : { - tmp = builder->CreateFCmpUGE(left, right); - break; - } - case (ASR::cmpopType::Lt) : { - tmp = builder->CreateFCmpULT(left, right); - break; - } - case (ASR::cmpopType::LtE) : { - tmp = builder->CreateFCmpULE(left, right); - break; - } - case (ASR::cmpopType::NotEq) : { - tmp = builder->CreateFCmpUNE(left, right); - break; - } - default : { - throw CodeGenError("Comparison operator not implemented", - x.base.base.loc); - } + case (ASR::cmpopType::Gt) : { + tmp = builder->CreateFCmpUGT(left, right); + break; } - } else if (optype == ASR::ttypeType::Complex) { - llvm::Value* real_left = complex_re(left, left->getType()); - llvm::Value* real_right = complex_re(right, right->getType()); - llvm::Value* img_left = complex_im(left, left->getType()); - llvm::Value* img_right = complex_im(right, right->getType()); - llvm::Value *real_res, *img_res; - switch (x.m_op) { - case (ASR::cmpopType::Eq) : { - real_res = builder->CreateFCmpUEQ(real_left, real_right); - img_res = builder->CreateFCmpUEQ(img_left, img_right); - break; - } - case (ASR::cmpopType::NotEq) : { - real_res = builder->CreateFCmpUNE(real_left, real_right); - img_res = builder->CreateFCmpUNE(img_left, img_right); - break; - } - default : { - throw CodeGenError("Comparison operator not implemented", - x.base.base.loc); - } + case (ASR::cmpopType::GtE) : { + tmp = builder->CreateFCmpUGE(left, right); + break; } - tmp = builder->CreateAnd(real_res, img_res); - } else if (optype == ASR::ttypeType::Character) { - // TODO: For now we only compare the first character of the strings - left = CreateLoad(left); - right = CreateLoad(right); - switch (x.m_op) { - case (ASR::cmpopType::Eq) : { - tmp = builder->CreateICmpEQ(left, right); - break; - } - case (ASR::cmpopType::NotEq) : { - tmp = builder->CreateICmpNE(left, right); - break; - } - case (ASR::cmpopType::Gt) : { - tmp = builder->CreateICmpUGT(left, right); - break; - } - case (ASR::cmpopType::GtE) : { - tmp = builder->CreateICmpUGE(left, right); - break; - } - case (ASR::cmpopType::Lt) : { - tmp = builder->CreateICmpULT(left, right); - break; - } - case (ASR::cmpopType::LtE) : { - tmp = builder->CreateICmpULE(left, right); - break; - } - default : { - throw CodeGenError("Comparison operator not implemented.", - x.base.base.loc); - } + case (ASR::cmpopType::Lt) : { + tmp = builder->CreateFCmpULT(left, right); + break; } - } else if (optype == ASR::ttypeType::Logical) { - // i1 -> i32 - left = builder->CreateZExt(left, llvm::Type::getInt32Ty(context)); - right = builder->CreateZExt(right, llvm::Type::getInt32Ty(context)); - switch (x.m_op) { - case (ASR::cmpopType::Eq) : { - tmp = builder->CreateICmpEQ(left, right); - break; - } - case (ASR::cmpopType::NotEq) : { - tmp = builder->CreateICmpNE(left, right); - break; - } - case (ASR::cmpopType::Gt) : { - tmp = builder->CreateICmpUGT(left, right); - break; - } - case (ASR::cmpopType::GtE) : { - tmp = builder->CreateICmpUGE(left, right); - break; - } - case (ASR::cmpopType::Lt) : { - tmp = builder->CreateICmpULT(left, right); - break; - } - case (ASR::cmpopType::LtE) : { - tmp = builder->CreateICmpULE(left, right); - break; - } - default : { - throw CodeGenError("Comparison operator not implemented.", - x.base.base.loc); - } + case (ASR::cmpopType::LtE) : { + tmp = builder->CreateFCmpULE(left, right); + break; + } + case (ASR::cmpopType::NotEq) : { + tmp = builder->CreateFCmpUNE(left, right); + break; + } + default : { + throw CodeGenError("Comparison operator not implemented", + x.base.base.loc); + } + } + } + + void visit_ComplexCompare(const ASR::ComplexCompare_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_left, true); + llvm::Value *left = tmp; + this->visit_expr_wrapper(x.m_right, true); + llvm::Value *right = tmp; + llvm::Value* real_left = complex_re(left, left->getType()); + llvm::Value* real_right = complex_re(right, right->getType()); + llvm::Value* img_left = complex_im(left, left->getType()); + llvm::Value* img_right = complex_im(right, right->getType()); + llvm::Value *real_res, *img_res; + switch (x.m_op) { + case (ASR::cmpopType::Eq) : { + real_res = builder->CreateFCmpUEQ(real_left, real_right); + img_res = builder->CreateFCmpUEQ(img_left, img_right); + break; + } + case (ASR::cmpopType::NotEq) : { + real_res = builder->CreateFCmpUNE(real_left, real_right); + img_res = builder->CreateFCmpUNE(img_left, img_right); + break; + } + default : { + throw CodeGenError("Comparison operator not implemented", + x.base.base.loc); + } + } + tmp = builder->CreateAnd(real_res, img_res); + } + + void visit_StringCompare(const ASR::StringCompare_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_left, true); + llvm::Value *left = tmp; + this->visit_expr_wrapper(x.m_right, true); + llvm::Value *right = tmp; + std::string fn; + switch (x.m_op) { + case (ASR::cmpopType::Eq) : { + fn = "_lpython_str_compare_eq"; + break; + } + case (ASR::cmpopType::NotEq) : { + fn = "_lpython_str_compare_noteq"; + break; + } + case (ASR::cmpopType::Gt) : { + fn = "_lpython_str_compare_gt"; + break; + } + case (ASR::cmpopType::GtE) : { + fn = "_lpython_str_compare_gte"; + break; + } + case (ASR::cmpopType::Lt) : { + fn = "_lpython_str_compare_lt"; + break; + } + case (ASR::cmpopType::LtE) : { + fn = "_lpython_str_compare_lte"; + break; + } + default : { + throw CodeGenError("Comparison operator not implemented", + x.base.base.loc); + } + } + tmp = lfortran_str_cmp(left, right, fn); + } + + void visit_LogicalCompare(const ASR::LogicalCompare_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_left, true); + llvm::Value *left = tmp; + this->visit_expr_wrapper(x.m_right, true); + llvm::Value *right = tmp; + // i1 -> i32 + left = builder->CreateZExt(left, llvm::Type::getInt32Ty(context)); + right = builder->CreateZExt(right, llvm::Type::getInt32Ty(context)); + switch (x.m_op) { + case (ASR::cmpopType::Eq) : { + tmp = builder->CreateICmpEQ(left, right); + break; + } + case (ASR::cmpopType::NotEq) : { + tmp = builder->CreateICmpNE(left, right); + break; + } + case (ASR::cmpopType::Gt) : { + tmp = builder->CreateICmpUGT(left, right); + break; + } + case (ASR::cmpopType::GtE) : { + tmp = builder->CreateICmpUGE(left, right); + break; + } + case (ASR::cmpopType::Lt) : { + tmp = builder->CreateICmpULT(left, right); + break; + } + case (ASR::cmpopType::LtE) : { + tmp = builder->CreateICmpULE(left, right); + break; + } + default : { + throw CodeGenError("Comparison operator not implemented", + x.base.base.loc); } - } else { - throw CodeGenError("Only Integer, Real, Complex, Character, and Logical" - " types are supported for comparison.", x.base.base.loc); } } + void visit_OverloadedCompare(const ASR::OverloadedCompare_t &x) { + this->visit_expr(*x.m_overloaded); + } + void visit_If(const ASR::If_t &x) { this->visit_expr_wrapper(x.m_test, true); llvm::Value *cond=tmp; @@ -2878,7 +3227,102 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor start_new_block(target); } - void visit_BoolOp(const ASR::BoolOp_t &x) { + void visit_LogicalBinOp(const ASR::LogicalBinOp_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_left, true); + llvm::Value *left_val = tmp; + this->visit_expr_wrapper(x.m_right, true); + llvm::Value *right_val = tmp; + LFORTRAN_ASSERT(ASRUtils::is_logical(*x.m_type)) + switch (x.m_op) { + case ASR::logicalbinopType::And: { + tmp = builder->CreateAnd(left_val, right_val); + break; + }; + case ASR::logicalbinopType::Or: { + tmp = builder->CreateOr(left_val, right_val); + break; + }; + case ASR::logicalbinopType::Xor: { + tmp = builder->CreateXor(left_val, right_val); + break; + }; + case ASR::logicalbinopType::NEqv: { + tmp = builder->CreateXor(left_val, right_val); + break; + }; + case ASR::logicalbinopType::Eqv: { + tmp = builder->CreateXor(left_val, right_val); + tmp = builder->CreateNot(tmp); + }; + } + } + + void visit_StringRepeat(const ASR::StringRepeat_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_left, true); + llvm::Value *left_val = tmp; + this->visit_expr_wrapper(x.m_right, true); + llvm::Value *right_val = tmp; + tmp = lfortran_strrepeat(left_val, right_val); + } + + void visit_StringConcat(const ASR::StringConcat_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_left, true); + llvm::Value *left_val = tmp; + this->visit_expr_wrapper(x.m_right, true); + llvm::Value *right_val = tmp; + tmp = lfortran_strop(left_val, right_val, "_lfortran_strcat"); + } + + void visit_StringLen(const ASR::StringLen_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_arg, true); + llvm::AllocaInst *parg = builder->CreateAlloca(character_type, nullptr); + builder->CreateStore(tmp, parg); + tmp = lfortran_str_len(parg); + } + + void visit_StringItem(const ASR::StringItem_t& x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_idx, true); + llvm::Value *idx = tmp; + this->visit_expr_wrapper(x.m_arg, true); + llvm::Value *str = tmp; + tmp = lfortran_str_copy(str, idx, idx); + } + + void visit_StringSection(const ASR::StringSection_t& x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_arg, true); + llvm::Value *str = tmp; + this->visit_expr_wrapper(x.m_start, true); + llvm::Value *left = tmp; + this->visit_expr_wrapper(x.m_end, true); + llvm::Value *right = tmp; + tmp = lfortran_str_copy(str, left, right); + } + + void visit_IntegerBinOp(const ASR::IntegerBinOp_t &x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; @@ -2887,35 +3331,71 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *left_val = tmp; this->visit_expr_wrapper(x.m_right, true); llvm::Value *right_val = tmp; - if (x.m_type->type == ASR::ttypeType::Logical) { - switch (x.m_op) { - case ASR::boolopType::And: { - tmp = builder->CreateAnd(left_val, right_val); - break; - }; - case ASR::boolopType::Or: { - tmp = builder->CreateOr(left_val, right_val); - break; - }; - case ASR::boolopType::Xor: { - tmp = builder->CreateXor(left_val, right_val); - break; - }; - case ASR::boolopType::NEqv: { - tmp = builder->CreateXor(left_val, right_val); - break; - }; - case ASR::boolopType::Eqv: { - tmp = builder->CreateXor(left_val, right_val); - tmp = builder->CreateNot(tmp); - }; + LFORTRAN_ASSERT(ASRUtils::is_integer(*x.m_type)) + switch (x.m_op) { + case ASR::binopType::Add: { + tmp = builder->CreateAdd(left_val, right_val); + break; + }; + case ASR::binopType::Sub: { + tmp = builder->CreateSub(left_val, right_val); + break; + }; + case ASR::binopType::Mul: { + tmp = builder->CreateMul(left_val, right_val); + break; + }; + case ASR::binopType::Div: { + tmp = builder->CreateUDiv(left_val, right_val); + break; + }; + case ASR::binopType::Pow: { + llvm::Type *type; + int a_kind; + a_kind = down_cast(ASRUtils::type_get_past_pointer(x.m_type))->m_kind; + type = getFPType(a_kind); + llvm::Value *fleft = builder->CreateSIToFP(left_val, + type); + llvm::Value *fright = builder->CreateSIToFP(right_val, + type); + std::string func_name = a_kind == 4 ? "llvm.pow.f32" : "llvm.pow.f64"; + llvm::Function *fn_pow = module->getFunction(func_name); + if (!fn_pow) { + llvm::FunctionType *function_type = llvm::FunctionType::get( + type, { type, type}, false); + fn_pow = llvm::Function::Create(function_type, + llvm::Function::ExternalLinkage, func_name, + module.get()); + } + tmp = builder->CreateCall(fn_pow, {fleft, fright}); + type = getIntType(a_kind); + tmp = builder->CreateFPToSI(tmp, type); + break; + }; + case ASR::binopType::BitOr: { + tmp = builder->CreateOr(left_val, right_val); + break; + } + case ASR::binopType::BitAnd: { + tmp = builder->CreateAnd(left_val, right_val); + break; + } + case ASR::binopType::BitXor: { + tmp = builder->CreateXor(left_val, right_val); + break; + } + case ASR::binopType::BitLShift: { + tmp = builder->CreateShl(left_val, right_val); + break; + } + case ASR::binopType::BitRShift: { + tmp = builder->CreateAShr(left_val, right_val); + break; } - } else { - throw CodeGenError("Boolop: Only Logical types can be used with logical operators."); } } - void visit_StringRepeat(const ASR::StringRepeat_t &x) { + void visit_RealBinOp(const ASR::RealBinOp_t &x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; @@ -2924,10 +3404,49 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *left_val = tmp; this->visit_expr_wrapper(x.m_right, true); llvm::Value *right_val = tmp; - tmp = lfortran_strrepeat(left_val, right_val); + LFORTRAN_ASSERT(ASRUtils::is_real(*x.m_type)) + switch (x.m_op) { + case ASR::binopType::Add: { + tmp = builder->CreateFAdd(left_val, right_val); + break; + }; + case ASR::binopType::Sub: { + tmp = builder->CreateFSub(left_val, right_val); + break; + }; + case ASR::binopType::Mul: { + tmp = builder->CreateFMul(left_val, right_val); + break; + }; + case ASR::binopType::Div: { + tmp = builder->CreateFDiv(left_val, right_val); + break; + }; + case ASR::binopType::Pow: { + llvm::Type *type; + int a_kind; + a_kind = down_cast(ASRUtils::type_get_past_pointer(x.m_type))->m_kind; + type = getFPType(a_kind); + std::string func_name = a_kind == 4 ? "llvm.pow.f32" : "llvm.pow.f64"; + llvm::Function *fn_pow = module->getFunction(func_name); + if (!fn_pow) { + llvm::FunctionType *function_type = llvm::FunctionType::get( + type, { type, type }, false); + fn_pow = llvm::Function::Create(function_type, + llvm::Function::ExternalLinkage, func_name, + module.get()); + } + tmp = builder->CreateCall(fn_pow, {left_val, right_val}); + break; + }; + default: { + throw CodeGenError("Binary operator '" + ASRUtils::binop_to_str_python(x.m_op) + "' not supported", + x.base.base.loc); + } + } } - void visit_StringConcat(const ASR::StringConcat_t &x) { + void visit_ComplexBinOp(const ASR::ComplexBinOp_t &x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; @@ -2936,220 +3455,147 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *left_val = tmp; this->visit_expr_wrapper(x.m_right, true); llvm::Value *right_val = tmp; - tmp = lfortran_strop(left_val, right_val, "_lfortran_strcat"); + LFORTRAN_ASSERT(ASRUtils::is_complex(*x.m_type)); + llvm::Type *type; + int a_kind; + a_kind = down_cast(ASRUtils::type_get_past_pointer(x.m_type))->m_kind; + type = getComplexType(a_kind); + if( left_val->getType()->isPointerTy() ) { + left_val = CreateLoad(left_val); + } + if( right_val->getType()->isPointerTy() ) { + right_val = CreateLoad(right_val); + } + std::string fn_name; + switch (x.m_op) { + case ASR::binopType::Add: { + if (a_kind == 4) { + fn_name = "_lfortran_complex_add_32"; + } else { + fn_name = "_lfortran_complex_add_64"; + } + break; + }; + case ASR::binopType::Sub: { + if (a_kind == 4) { + fn_name = "_lfortran_complex_sub_32"; + } else { + fn_name = "_lfortran_complex_sub_64"; + } + break; + }; + case ASR::binopType::Mul: { + if (a_kind == 4) { + fn_name = "_lfortran_complex_mul_32"; + } else { + fn_name = "_lfortran_complex_mul_64"; + } + break; + }; + case ASR::binopType::Div: { + if (a_kind == 4) { + fn_name = "_lfortran_complex_div_32"; + } else { + fn_name = "_lfortran_complex_div_64"; + } + break; + }; + case ASR::binopType::Pow: { + if (a_kind == 4) { + fn_name = "_lfortran_complex_pow_32"; + } else { + fn_name = "_lfortran_complex_pow_64"; + } + break; + }; + default: { + throw CodeGenError("Binary operator '" + ASRUtils::binop_to_str_python(x.m_op) + "' not supported", + x.base.base.loc); + } + } + tmp = lfortran_complex_bin_op(left_val, right_val, fn_name, type); } - void visit_StringLen(const ASR::StringLen_t &x) { + void visit_OverloadedBinOp(const ASR::OverloadedBinOp_t &x) { + this->visit_expr(*x.m_overloaded); + } + + void visit_IntegerBitNot(const ASR::IntegerBitNot_t &x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; } this->visit_expr_wrapper(x.m_arg, true); - llvm::AllocaInst *parg = builder->CreateAlloca(character_type, nullptr); - builder->CreateStore(tmp, parg); - tmp = lfortran_str_len(parg); + tmp = builder->CreateNot(tmp); } - void visit_BinOp(const ASR::BinOp_t &x) { - if( x.m_overloaded ) { - this->visit_expr(*x.m_overloaded); - return ; + void visit_IntegerUnaryMinus(const ASR::IntegerUnaryMinus_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; } + this->visit_expr_wrapper(x.m_arg, true); + llvm::Value *zero = llvm::ConstantInt::get(context, + llvm::APInt(ASRUtils::extract_kind_from_ttype_t(ASRUtils::expr_type(x.m_arg)) * 8, 0)); + tmp = builder->CreateSub(zero, tmp); + } + + void visit_RealUnaryMinus(const ASR::RealUnaryMinus_t &x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; } - this->visit_expr_wrapper(x.m_left, true); - llvm::Value *left_val = tmp; - this->visit_expr_wrapper(x.m_right, true); - llvm::Value *right_val = tmp; - if (ASRUtils::is_integer(*x.m_type)) { - switch (x.m_op) { - case ASR::binopType::Add: { - tmp = builder->CreateAdd(left_val, right_val); - break; - }; - case ASR::binopType::Sub: { - tmp = builder->CreateSub(left_val, right_val); - break; - }; - case ASR::binopType::Mul: { - tmp = builder->CreateMul(left_val, right_val); - break; - }; - case ASR::binopType::Div: { - tmp = builder->CreateUDiv(left_val, right_val); - break; - }; - case ASR::binopType::Pow: { - llvm::Type *type; - int a_kind; - a_kind = down_cast(ASRUtils::type_get_past_pointer(x.m_type))->m_kind; - type = getFPType(a_kind); - llvm::Value *fleft = builder->CreateSIToFP(left_val, - type); - llvm::Value *fright = builder->CreateSIToFP(right_val, - type); - std::string func_name = a_kind == 4 ? "llvm.pow.f32" : "llvm.pow.f64"; - llvm::Function *fn_pow = module->getFunction(func_name); - if (!fn_pow) { - llvm::FunctionType *function_type = llvm::FunctionType::get( - type, { type, type}, false); - fn_pow = llvm::Function::Create(function_type, - llvm::Function::ExternalLinkage, func_name, - module.get()); - } - tmp = builder->CreateCall(fn_pow, {fleft, fright}); - type = getIntType(a_kind); - tmp = builder->CreateFPToSI(tmp, type); - break; - }; - } - } else if (ASRUtils::is_real(*x.m_type)) { - switch (x.m_op) { - case ASR::binopType::Add: { - tmp = builder->CreateFAdd(left_val, right_val); - break; - }; - case ASR::binopType::Sub: { - tmp = builder->CreateFSub(left_val, right_val); - break; - }; - case ASR::binopType::Mul: { - tmp = builder->CreateFMul(left_val, right_val); - break; - }; - case ASR::binopType::Div: { - tmp = builder->CreateFDiv(left_val, right_val); - break; - }; - case ASR::binopType::Pow: { - llvm::Type *type; - int a_kind; - a_kind = down_cast(ASRUtils::type_get_past_pointer(x.m_type))->m_kind; - type = getFPType(a_kind); - std::string func_name = a_kind == 4 ? "llvm.pow.f32" : "llvm.pow.f64"; - llvm::Function *fn_pow = module->getFunction(func_name); - if (!fn_pow) { - llvm::FunctionType *function_type = llvm::FunctionType::get( - type, { type, type }, false); - fn_pow = llvm::Function::Create(function_type, - llvm::Function::ExternalLinkage, func_name, - module.get()); - } - tmp = builder->CreateCall(fn_pow, {left_val, right_val}); - break; - }; - } - } else if (ASRUtils::is_complex(*x.m_type)) { - llvm::Type *type; - int a_kind; - a_kind = down_cast(ASRUtils::type_get_past_pointer(x.m_type))->m_kind; - type = getComplexType(a_kind); - if( left_val->getType()->isPointerTy() ) { - left_val = CreateLoad(left_val); - } - if( right_val->getType()->isPointerTy() ) { - right_val = CreateLoad(right_val); - } - std::string fn_name; - switch (x.m_op) { - case ASR::binopType::Add: { - if (a_kind == 4) { - fn_name = "_lfortran_complex_add_32"; - } else { - fn_name = "_lfortran_complex_add_64"; - } - break; - }; - case ASR::binopType::Sub: { - if (a_kind == 4) { - fn_name = "_lfortran_complex_sub_32"; - } else { - fn_name = "_lfortran_complex_sub_64"; - } - break; - }; - case ASR::binopType::Mul: { - if (a_kind == 4) { - fn_name = "_lfortran_complex_mul_32"; - } else { - fn_name = "_lfortran_complex_mul_64"; - } - break; - }; - case ASR::binopType::Div: { - if (a_kind == 4) { - fn_name = "_lfortran_complex_div_32"; - } else { - fn_name = "_lfortran_complex_div_64"; - } - break; - }; - case ASR::binopType::Pow: { - if (a_kind == 4) { - fn_name = "_lfortran_complex_pow_32"; - } else { - fn_name = "_lfortran_complex_pow_64"; - } - break; - }; - } - tmp = lfortran_complex_bin_op(left_val, right_val, fn_name, type); + this->visit_expr_wrapper(x.m_arg, true); + llvm::Value *zero; + int a_kind = down_cast(x.m_type)->m_kind; + if (a_kind == 4) { + zero = llvm::ConstantFP::get(context, + llvm::APFloat((float)0.0)); + } else if (a_kind == 8) { + zero = llvm::ConstantFP::get(context, + llvm::APFloat((double)0.0)); } else { - throw CodeGenError("Binop: Only Real, Integer and Complex types are allowed"); + throw CodeGenError("RealUnaryMinus: kind not supported yet"); } + + tmp = builder->CreateFSub(zero, tmp); } - void visit_UnaryOp(const ASR::UnaryOp_t &x) { + void visit_ComplexUnaryMinus(const ASR::ComplexUnaryMinus_t &x) { if (x.m_value) { this->visit_expr_wrapper(x.m_value, true); return; } - this->visit_expr_wrapper(x.m_operand, true); - if (x.m_type->type == ASR::ttypeType::Integer) { - if (x.m_op == ASR::unaryopType::UAdd) { - // tmp = tmp; - return; - } else if (x.m_op == ASR::unaryopType::USub) { - llvm::Value *zero = llvm::ConstantInt::get(context, - llvm::APInt(ASRUtils::extract_kind_from_ttype_t(ASRUtils::expr_type(x.m_operand)) * 8, 0)); - tmp = builder ->CreateSub(zero, tmp); - return; - } else { - throw CodeGenError("Unary type not implemented yet"); + this->visit_expr_wrapper(x.m_arg, true); + llvm::Value *c = tmp; + double re = 0.0; + double im = 0.0; + llvm::Value *re2, *im2; + llvm::Type *type; + int a_kind = down_cast(x.m_type)->m_kind; + std::string f_name; + switch (a_kind) { + case 4: { + re2 = llvm::ConstantFP::get(context, llvm::APFloat((float)re)); + im2 = llvm::ConstantFP::get(context, llvm::APFloat((float)im)); + type = complex_type_4; + f_name = "_lfortran_complex_sub_32"; + break; } - } else if (x.m_type->type == ASR::ttypeType::Real) { - if (x.m_op == ASR::unaryopType::UAdd) { - // tmp = tmp; - return; - } else if (x.m_op == ASR::unaryopType::USub) { - llvm::Value *zero; - int a_kind = down_cast(x.m_type)->m_kind; - if (a_kind == 4) { - zero = llvm::ConstantFP::get(context, - llvm::APFloat((float)0.0)); - } else if (a_kind == 8) { - zero = llvm::ConstantFP::get(context, - llvm::APFloat((double)0.0)); - } else { - throw CodeGenError("Unary type kind not implemented yet, only 4 and 8 is"); - } - tmp = builder ->CreateFSub(zero, tmp); - return; - } else { - throw CodeGenError("Unary type not implemented yet"); + case 8: { + re2 = llvm::ConstantFP::get(context, llvm::APFloat(re)); + im2 = llvm::ConstantFP::get(context, llvm::APFloat(im)); + type = complex_type_8; + f_name = "_lfortran_complex_sub_64"; + break; } - } else if (x.m_type->type == ASR::ttypeType::Logical) { - if (x.m_op == ASR::unaryopType::Not) { - tmp = builder ->CreateNot(tmp); - return; - } else { - throw CodeGenError("Unary type not implemented yet in Logical"); + default: { + throw CodeGenError("kind type is not supported"); } - } else { - throw CodeGenError("UnaryOp: type not supported yet"); } + tmp = complex_from_floats(re2, im2, type); + llvm::Value *zero_c = tmp; + tmp = lfortran_complex_bin_op(zero_c, c, f_name, type); } void visit_IntegerConstant(const ASR::IntegerConstant_t &x) { @@ -3336,6 +3782,15 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor tmp = llvm::ConstantInt::get(context, llvm::APInt(1, val)); } + void visit_LogicalNot(const ASR::LogicalNot_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } + this->visit_expr_wrapper(x.m_arg, true); + llvm::Value *arg = tmp; + tmp = builder->CreateNot(arg); + } void visit_StringConstant(const ASR::StringConstant_t &x) { tmp = builder->CreateGlobalStringPtr(x.m_s); @@ -3345,8 +3800,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor uint32_t x_h = get_hash((ASR::asr_t*)x); LFORTRAN_ASSERT(llvm_symtab.find(x_h) != llvm_symtab.end()); llvm::Value* x_v = llvm_symtab[x_h]; - tmp = CreateLoad(x_v); - tmp = CreateLoad(tmp); + uint64_t ptr_loads_copy = ptr_loads; + tmp = x_v; + while( ptr_loads_copy-- ) { + tmp = CreateLoad(tmp); + } } inline void fetch_val(ASR::Variable_t* x) { @@ -3375,10 +3833,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return; } } - tmp = CreateLoad(x_v); - if( arr_descr->is_array(x_v) ) { tmp = x_v; + } else { + tmp = x_v; + // Load only once since its a value + if( ptr_loads > 0 ) { + tmp = CreateLoad(tmp); + } } } @@ -3393,13 +3855,17 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor switch (t2->type) { case ASR::ttypeType::Integer: case ASR::ttypeType::Real: - case ASR::ttypeType::Complex: { + case ASR::ttypeType::Complex: + case ASR::ttypeType::Derived: { + if( t2->type == ASR::ttypeType::Derived ) { + ASR::Derived_t* d = ASR::down_cast(t2); + der_type_name = ASRUtils::symbol_name(d->m_derived_type); + } fetch_ptr(x); break; } case ASR::ttypeType::Character: - case ASR::ttypeType::Logical: - case ASR::ttypeType::Derived: { + case ASR::ttypeType::Logical: { break; } default: @@ -3454,6 +3920,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ComplexRe(const ASR::ComplexRe_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } this->visit_expr_wrapper(x.m_arg, true); ASR::ttype_t* curr_type = extract_ttype_t_from_expr(x.m_arg); int arg_kind = ASRUtils::extract_kind_from_ttype_t(curr_type); @@ -3483,6 +3953,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ComplexIm(const ASR::ComplexIm_t &x) { + if (x.m_value) { + this->visit_expr_wrapper(x.m_value, true); + return; + } ASR::ttype_t* curr_type = extract_ttype_t_from_expr(x.m_arg); int arg_kind = ASRUtils::extract_kind_from_ttype_t(curr_type); llvm::Function *fn = nullptr; @@ -3529,20 +4003,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor switch (x.m_kind) { case (ASR::cast_kindType::IntegerToReal) : { int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); - switch (a_kind) { - case 4 : { - tmp = builder->CreateSIToFP(tmp, llvm::Type::getFloatTy(context)); - break; - } - case 8 : { - tmp = builder->CreateSIToFP(tmp, llvm::Type::getDoubleTy(context)); - break; - } - default : { - throw CodeGenError(R"""(Only 32 and 64 bit real kinds are implemented)""", - x.base.base.loc); - } - } + tmp = builder->CreateSIToFP(tmp, getFPType(a_kind, false)); + break; + } + case (ASR::cast_kindType::LogicalToReal) : { + int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); + tmp = builder->CreateUIToFP(tmp, getFPType(a_kind, false)); break; } case (ASR::cast_kindType::RealToInteger) : { @@ -3599,28 +4065,66 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor break; } case (ASR::cast_kindType::IntegerToLogical) : { - tmp = builder->CreateICmpNE(tmp, builder->getInt32(0)); + ASR::ttype_t* curr_type = extract_ttype_t_from_expr(x.m_arg); + LFORTRAN_ASSERT(curr_type != nullptr) + int a_kind = ASRUtils::extract_kind_from_ttype_t(curr_type); + switch (a_kind) { + case 1: + tmp = builder->CreateICmpNE(tmp, builder->getInt8(0)); + break; + case 2: + tmp = builder->CreateICmpNE(tmp, builder->getInt16(0)); + break; + case 4: + tmp = builder->CreateICmpNE(tmp, builder->getInt32(0)); + break; + case 8: + tmp = builder->CreateICmpNE(tmp, builder->getInt64(0)); + break; + } break; } - case (ASR::cast_kindType::LogicalToInteger) : { - int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); - if (a_kind == 2) { - tmp = builder->CreateSExt(tmp, llvm::Type::getInt16Ty(context)); - llvm::Value *zero = llvm::ConstantInt::get(context, llvm::APInt(16, 0, true)); - tmp = builder ->CreateSub(zero, tmp); - } else if (a_kind == 4) { - tmp = builder->CreateSExt(tmp, llvm::Type::getInt32Ty(context)); - llvm::Value *zero = llvm::ConstantInt::get(context, llvm::APInt(32, 0, true)); - tmp = builder ->CreateSub(zero, tmp); - } else if (a_kind == 8) { - tmp = builder->CreateSExt(tmp, llvm::Type::getInt64Ty(context)); - llvm::Value *zero = llvm::ConstantInt::get(context, llvm::APInt(64, 0, true)); - tmp = builder ->CreateSub(zero, tmp); + case (ASR::cast_kindType::RealToLogical) : { + llvm::Value *zero; + ASR::ttype_t* curr_type = extract_ttype_t_from_expr(x.m_arg); + LFORTRAN_ASSERT(curr_type != nullptr) + int a_kind = ASRUtils::extract_kind_from_ttype_t(curr_type); + if (a_kind == 4) { + zero = llvm::ConstantFP::get(context, llvm::APFloat((float)0.0)); + } else { + zero = llvm::ConstantFP::get(context, llvm::APFloat(0.0)); + } + tmp = builder->CreateFCmpUNE(tmp, zero); + break; + } + case (ASR::cast_kindType::CharacterToLogical) : { + llvm::AllocaInst *parg = builder->CreateAlloca(character_type, nullptr); + builder->CreateStore(tmp, parg); + tmp = builder->CreateICmpNE(lfortran_str_len(parg), builder->getInt32(0)); + break; + } + case (ASR::cast_kindType::ComplexToLogical) : { + // !(c.real == 0.0 && c.imag == 0.0) + llvm::Value *zero; + ASR::ttype_t* curr_type = extract_ttype_t_from_expr(x.m_arg); + LFORTRAN_ASSERT(curr_type != nullptr) + int a_kind = ASRUtils::extract_kind_from_ttype_t(curr_type); + if (a_kind == 4) { + zero = llvm::ConstantFP::get(context, llvm::APFloat((float)0.0)); } else { - std::string msg = "Conversion from i1 to" + - std::to_string(a_kind) + " is not implemented yet."; - throw CodeGenError(msg); + zero = llvm::ConstantFP::get(context, llvm::APFloat(0.0)); } + llvm::Value *c_real = complex_re(tmp, tmp->getType()); + llvm::Value *real_check = builder->CreateFCmpUEQ(c_real, zero); + llvm::Value *c_imag = complex_im(tmp, tmp->getType()); + llvm::Value *imag_check = builder->CreateFCmpUEQ(c_imag, zero); + tmp = builder->CreateAnd(real_check, imag_check); + tmp = builder->CreateNot(tmp); + break; + } + case (ASR::cast_kindType::LogicalToInteger) : { + int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); + tmp = builder->CreateZExt(tmp, getIntType(a_kind)); break; } case (ASR::cast_kindType::RealToReal) : { @@ -3647,22 +4151,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if( arg_kind > 0 && dest_kind > 0 && arg_kind != dest_kind ) { - if( arg_kind == 4 && dest_kind == 8 ) { - tmp = builder->CreateSExt(tmp, llvm::Type::getInt64Ty(context)); - } else if( arg_kind == 8 && dest_kind == 4 ) { - tmp = builder->CreateTrunc(tmp, llvm::Type::getInt32Ty(context)); - } else if( arg_kind == 2 && dest_kind == 4 ) { - tmp = builder->CreateSExt(tmp, llvm::Type::getInt32Ty(context)); - } else if( arg_kind == 4 && dest_kind == 2 ) { - tmp = builder->CreateTrunc(tmp, llvm::Type::getInt16Ty(context)); - } else if( arg_kind == 1 && dest_kind == 4 ) { - tmp = builder->CreateSExt(tmp, llvm::Type::getInt32Ty(context)); - } else if( arg_kind == 4 && dest_kind == 1 ) { - tmp = builder->CreateTrunc(tmp, llvm::Type::getInt8Ty(context)); + if (dest_kind > arg_kind) { + tmp = builder->CreateSExt(tmp, getIntType(dest_kind)); } else { - std::string msg = "Conversion from " + std::to_string(arg_kind) + - " to " + std::to_string(dest_kind) + " not implemented yet."; - throw CodeGenError(msg); + tmp = builder->CreateTrunc(tmp, getIntType(dest_kind)); } } break; @@ -3774,13 +4266,58 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor void handle_print(const T &x) { std::vector args; std::vector fmt; + llvm::Value *sep = nullptr; + llvm::Value *end = nullptr; + if (x.m_separator) { + this->visit_expr_wrapper(x.m_separator, true); + sep = tmp; + } else { + sep = builder->CreateGlobalStringPtr(" "); + } + if (x.m_end) { + this->visit_expr_wrapper(x.m_end, true); + end = tmp; + } else { + end = builder->CreateGlobalStringPtr("\n"); + } for (size_t i=0; i(*x.m_values[i]) ) { + ASR::Variable_t* var = ASRUtils::EXPR2VAR(x.m_values[i]); + reduce_loads = var->m_intent == ASRUtils::intent_in; + if( ASR::is_a(*var->m_type) ) { + ptr_loads = 1; + } + } + if (i != 0) { + fmt.push_back("%s"); + args.push_back(sep); + } + ptr_loads = ptr_loads - reduce_loads; this->visit_expr_wrapper(x.m_values[i], true); + ptr_loads = ptr_loads_copy; ASR::expr_t *v = x.m_values[i]; ASR::ttype_t *t = expr_type(v); int a_kind = ASRUtils::extract_kind_from_ttype_t(t); - if (ASRUtils::is_integer(*t) || - ASR::is_a(*ASRUtils::type_get_past_pointer(t))) { + if( ASR::is_a(*t) && ASR::is_a(*v) ) { + if( ASRUtils::is_array(ASRUtils::type_get_past_pointer(t)) ) { + tmp = builder->CreateLoad(arr_descr->get_pointer_to_data(tmp)); + } + fmt.push_back("%lld"); + llvm::Value* d = builder->CreatePtrToInt(tmp, getIntType(8, false)); + args.push_back(d); + continue; + } + if (t->type == ASR::ttypeType::CPtr || + (t->type == ASR::ttypeType::Pointer && + (ASR::is_a(*v) || ASR::is_a(*v))) + ) { + fmt.push_back("%lld"); + llvm::Value* d = builder->CreatePtrToInt(tmp, getIntType(8, false)); + args.push_back(d); + } else if (ASRUtils::is_integer(*t)) { switch( a_kind ) { case 1 : { fmt.push_back("%d"); @@ -3833,6 +4370,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } else if (t->type == ASR::ttypeType::Character) { fmt.push_back("%s"); args.push_back(tmp); + } else if (ASRUtils::is_logical(*t)) { + llvm::Value *cmp = builder->CreateICmpEQ(tmp, builder->getInt1(0)); + llvm::Value *zero_str = builder->CreateGlobalStringPtr("False"); + llvm::Value *one_str = builder->CreateGlobalStringPtr("True"); + llvm::Value *str = builder->CreateSelect(cmp, zero_str, one_str); + printf(context, *module, *builder, {str}); } else if (ASRUtils::is_complex(*t)) { llvm::Type *type, *complex_type; switch( a_kind ) { @@ -3862,17 +4405,22 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor args.push_back(d); d = builder->CreateFPExt(complex_im(tmp, complex_type), type); args.push_back(d); + } else if (t->type == ASR::ttypeType::CPtr) { + fmt.push_back("%lld"); + llvm::Value* d = builder->CreatePtrToInt(tmp, getIntType(8, false)); + args.push_back(d); } else { throw LFortranException("Printing support is available only for integer, real," - " character, and complex types."); + " character, and complex types, got type " + + ASRUtils::type_to_str(t)); } } + fmt.push_back("%s"); + args.push_back(end); std::string fmt_str; for (size_t i=0; iCreateGlobalStringPtr(fmt_str); std::vector printf_args; printf_args.push_back(fmt_ptr); @@ -3907,11 +4455,13 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor template inline void set_func_subrout_params(T* func_subrout, ASR::abiType& x_abi, std::uint32_t& m_h, ASR::Variable_t*& orig_arg, - std::string& orig_arg_name, size_t arg_idx) { + std::string& orig_arg_name, ASR::intentType& arg_intent, + size_t arg_idx) { m_h = get_hash((ASR::asr_t*)func_subrout); orig_arg = EXPR2VAR(func_subrout->m_args[arg_idx]); orig_arg_name = orig_arg->m_name; x_abi = func_subrout->m_abi; + arg_intent = orig_arg->m_intent; } @@ -3927,6 +4477,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::Subroutine_t* sub = down_cast(func_subrout); x_abi = sub->m_abi; } + // TODO: Below if check is dead. Remove. if( x_abi == ASR::abiType::Intrinsic ) { if( name == "lbound" || name == "ubound" ) { ASR::Variable_t *arg = EXPR2VAR(x.m_args[0].m_value); @@ -3955,23 +4506,24 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor tmp = llvm_symtab[h]; func_subrout = symbol_get_past_external(x.m_name); x_abi = (ASR::abiType) 0; + ASR::intentType orig_arg_intent = ASR::intentType::Unspecified; std::uint32_t m_h; ASR::Variable_t *orig_arg = nullptr; std::string orig_arg_name = ""; if( func_subrout->type == ASR::symbolType::Function ) { ASR::Function_t* func = down_cast(func_subrout); - set_func_subrout_params(func, x_abi, m_h, orig_arg, orig_arg_name, i); + set_func_subrout_params(func, x_abi, m_h, orig_arg, orig_arg_name, orig_arg_intent, i); } else if( func_subrout->type == ASR::symbolType::Subroutine ) { ASR::Subroutine_t* sub = down_cast(func_subrout); - set_func_subrout_params(sub, x_abi, m_h, orig_arg, orig_arg_name, i); + set_func_subrout_params(sub, x_abi, m_h, orig_arg, orig_arg_name, orig_arg_intent, i); } else if( func_subrout->type == ASR::symbolType::ClassProcedure ) { ASR::ClassProcedure_t* clss_proc = ASR::down_cast(func_subrout); if( clss_proc->m_proc->type == ASR::symbolType::Subroutine ) { ASR::Subroutine_t* sub = down_cast(clss_proc->m_proc); - set_func_subrout_params(sub, x_abi, m_h, orig_arg, orig_arg_name, i); + set_func_subrout_params(sub, x_abi, m_h, orig_arg, orig_arg_name, orig_arg_intent, i); } else if( clss_proc->m_proc->type == ASR::symbolType::Function ) { ASR::Function_t* func = down_cast(clss_proc->m_proc); - set_func_subrout_params(func, x_abi, m_h, orig_arg, orig_arg_name, i); + set_func_subrout_params(func, x_abi, m_h, orig_arg, orig_arg_name, orig_arg_intent, i); } } else { LFORTRAN_ASSERT(false) @@ -4027,15 +4579,38 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor tmp = CreateLoad(tmp); } } + } else if (is_a(*arg_type)) { + if (arg->m_intent == intent_local) { + // Local variable of type + // CPtr is a void**, so we + // have to load it + tmp = CreateLoad(tmp); + } } else { - // Dereference the pointer argument - // to pass by value - // E.g.: - // i32* -> i32 - // {double,double}* -> {double,double} - tmp = CreateLoad(tmp); + if (!arg->m_value_attr) { + // Dereference the pointer argument (unless it is a CPtr) + // to pass by value + // E.g.: + // i32* -> i32 + // {double,double}* -> {double,double} + tmp = CreateLoad(tmp); + } } } + if (!orig_arg->m_value_attr && arg->m_value_attr) { + llvm::Type *target_type = tmp->getType(); + // Create alloca to get a pointer, but do it + // at the beginning of the function to avoid + // using alloca inside a loop, which would + // run out of stack + llvm::BasicBlock &entry_block = builder->GetInsertBlock()->getParent()->getEntryBlock(); + llvm::IRBuilder<> builder0(context); + builder0.SetInsertPoint(&entry_block, entry_block.getFirstInsertionPt()); + llvm::AllocaInst *target = builder0.CreateAlloca( + target_type, nullptr, "call_arg_value_ptr"); + builder->CreateStore(tmp, target); + tmp = target; + } } } } else { @@ -4117,8 +4692,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor break; case (ASR::ttypeType::Derived) : break; + case (ASR::ttypeType::CPtr) : + target_type = llvm::Type::getVoidTy(context)->getPointerTo(); + break; default : - throw CodeGenError("Type not implemented yet."); + throw CodeGenError("Type " + ASRUtils::type_to_str(arg_type) + " not implemented yet."); } switch(arg_type->type) { case ASR::ttypeType::Derived: { @@ -4291,6 +4869,35 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor pop_nested_stack(s); } + void handle_bitwise_args(const ASR::FunctionCall_t& x, llvm::Value*& arg1, + llvm::Value*& arg2) { + LFORTRAN_ASSERT(x.n_args == 2); + tmp = nullptr; + this->visit_expr_wrapper(x.m_args[0].m_value, true); + arg1 = tmp; + tmp = nullptr; + this->visit_expr_wrapper(x.m_args[1].m_value, true); + arg2 = tmp; + } + + void handle_bitwise_xor(const ASR::FunctionCall_t& x) { + llvm::Value *arg1 = nullptr, *arg2 = nullptr; + handle_bitwise_args(x, arg1, arg2); + tmp = builder->CreateXor(arg1, arg2); + } + + void handle_bitwise_and(const ASR::FunctionCall_t& x) { + llvm::Value *arg1 = nullptr, *arg2 = nullptr; + handle_bitwise_args(x, arg1, arg2); + tmp = builder->CreateAnd(arg1, arg2); + } + + void handle_bitwise_or(const ASR::FunctionCall_t& x) { + llvm::Value *arg1 = nullptr, *arg2 = nullptr; + handle_bitwise_args(x, arg1, arg2); + tmp = builder->CreateOr(arg1, arg2); + } + void visit_FunctionCall(const ASR::FunctionCall_t &x) { if( ASRUtils::is_intrinsic_optimization(x.m_name) ) { ASR::Function_t* routine = ASR::down_cast( @@ -4321,6 +4928,21 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if( s == nullptr ) { s = ASR::down_cast(symbol_get_past_external(x.m_name)); } + if( ASRUtils::is_intrinsic_function2(s) ) { + std::string symbol_name = ASRUtils::symbol_name(x.m_name); + if( startswith(symbol_name, "_bitwise_xor") ) { + handle_bitwise_xor(x); + return ; + } + if( startswith(symbol_name, "_bitwise_and") ) { + handle_bitwise_and(x); + return ; + } + if( startswith(symbol_name, "_bitwise_or") ) { + handle_bitwise_or(x); + return ; + } + } if (parent_function){ push_nested_stack(parent_function); } else if (parent_subroutine){ @@ -4439,7 +5061,13 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor visit_expr_wrapper(x.m_value, true); return ; } + int output_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = 2 - // Sync: instead of 2 - , should this be ptr_loads_copy - + (ASRUtils::expr_type(x.m_v)->type == + ASR::ttypeType::Pointer); visit_expr_wrapper(x.m_v); + ptr_loads = ptr_loads_copy; llvm::Value* llvm_arg = tmp; llvm::Value* dim_des_val = arr_descr->get_pointer_to_dimension_descriptor_array(llvm_arg); if( x.m_dim ) { @@ -4447,11 +5075,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor int kind = ASRUtils::extract_kind_from_ttype_t(ASRUtils::expr_type(x.m_dim)); tmp = builder->CreateSub(tmp, llvm::ConstantInt::get(context, llvm::APInt(kind * 8, 1))); tmp = arr_descr->get_dimension_size(dim_des_val, tmp); + tmp = builder->CreateSExt(tmp, getIntType(output_kind)); return ; } llvm::Value* rank = arr_descr->get_rank(llvm_arg); - llvm::Value* llvm_size = builder->CreateAlloca(getIntType(ASRUtils::extract_kind_from_ttype_t(x.m_type)), nullptr); - builder->CreateStore(llvm::ConstantInt::get(context, llvm::APInt(32, 1)), llvm_size); + llvm::Value* llvm_size = builder->CreateAlloca(getIntType(output_kind), nullptr); + builder->CreateStore(llvm::ConstantInt::get(context, llvm::APInt(output_kind * 8, 1)), llvm_size); llvm::BasicBlock *loophead = llvm::BasicBlock::Create(context, "loop.head"); llvm::BasicBlock *loopbody = llvm::BasicBlock::Create(context, "loop.body"); @@ -4471,6 +5100,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value* r_val = CreateLoad(r); llvm::Value* ret_val = CreateLoad(llvm_size); llvm::Value* dim_size = arr_descr->get_dimension_size(dim_des_val, r_val); + dim_size = builder->CreateSExt(dim_size, getIntType(output_kind)); ret_val = builder->CreateMul(ret_val, dim_size); builder->CreateStore(ret_val, llvm_size); r_val = builder->CreateAdd(r_val, llvm::ConstantInt::get(context, llvm::APInt(32, 1))); @@ -4484,7 +5114,27 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ArrayBound(const ASR::ArrayBound_t& x) { + ASR::expr_t* array_value = ASRUtils::expr_value(x.m_v); + if( array_value && ASR::is_a(*array_value) ) { + ASR::ArrayConstant_t* array_const = ASR::down_cast(array_value); + int kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); + size_t bound_value = 0; + if( x.m_bound == ASR::arrayboundType::LBound ) { + bound_value = 1; + } else if( x.m_bound == ASR::arrayboundType::UBound ) { + bound_value = array_const->n_args; + } else { + LFORTRAN_ASSERT(false); + } + tmp = llvm::ConstantInt::get(context, llvm::APInt(kind * 8, bound_value)); + return ; + } + uint64_t ptr_loads_copy = ptr_loads; + ptr_loads = 2 - // Sync: instead of 2 - , should this be ptr_loads_copy - + (ASRUtils::expr_type(x.m_v)->type == + ASR::ttypeType::Pointer); visit_expr_wrapper(x.m_v); + ptr_loads = ptr_loads_copy; llvm::Value* llvm_arg1 = tmp; llvm::Value* dim_des_val = arr_descr->get_pointer_to_dimension_descriptor_array(llvm_arg1); visit_expr_wrapper(x.m_dim, true); @@ -4507,41 +5157,15 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor Result> asr_to_llvm(ASR::TranslationUnit_t &asr, diag::Diagnostics &diagnostics, - llvm::LLVMContext &context, Allocator &al, Platform platform, - bool fast, const std::string &rl_path, const std::string &run_fn) + llvm::LLVMContext &context, Allocator &al, + LCompilers::PassManager& pass_manager, + Platform platform, const std::string &run_fn) { ASRToLLVMVisitor v(al, context, platform, diagnostics); - pass_wrap_global_stmts_into_function(al, asr, run_fn); + pass_manager.apply_passes(al, &asr, run_fn, false); // Uncomment for debugging the ASR after the transformation - // std::cout << pickle(asr) << std::endl; - pass_replace_class_constructor(al, asr); - pass_replace_implied_do_loops(al, asr, rl_path); - pass_replace_arr_slice(al, asr, rl_path); - pass_replace_array_op(al, asr, rl_path); - pass_replace_print_arr(al, asr, rl_path); - - if( fast ) { - pass_loop_unroll(al, asr, rl_path); - } - - pass_replace_do_loops(al, asr); - pass_replace_forall(al, asr); - - if( fast ) { - pass_dead_code_removal(al, asr, rl_path); - } - - pass_replace_select_case(al, asr); - pass_unused_functions(al, asr); - - if( fast ) { - pass_replace_flip_sign(al, asr, rl_path); - pass_replace_sign_from_value(al, asr, rl_path); - pass_replace_div_to_mul(al, asr, rl_path); - pass_replace_fma(al, asr, rl_path); - pass_inline_function_calls(al, asr, rl_path); - } + // std::cout << pickle(asr, true, true, true) << std::endl; v.nested_func_types = pass_find_nested_vars(asr, context, v.nested_globals, v.nested_call_out, v.nesting_map); diff --git a/src/libasr/codegen/asr_to_llvm.h b/src/libasr/codegen/asr_to_llvm.h index 90862a1445..52f370b452 100644 --- a/src/libasr/codegen/asr_to_llvm.h +++ b/src/libasr/codegen/asr_to_llvm.h @@ -3,13 +3,16 @@ #include #include +#include namespace LFortran { Result> asr_to_llvm(ASR::TranslationUnit_t &asr, diag::Diagnostics &diagnostics, - llvm::LLVMContext &context, Allocator &al, Platform platform, - bool fast, const std::string &rl_path, const std::string &run_fn); + llvm::LLVMContext &context, Allocator &al, + LCompilers::PassManager& pass_manager, + Platform platform, + const std::string &run_fn); } // namespace LFortran diff --git a/src/libasr/codegen/asr_to_wasm.cpp b/src/libasr/codegen/asr_to_wasm.cpp index 5cbbb974c8..94c7ad592c 100644 --- a/src/libasr/codegen/asr_to_wasm.cpp +++ b/src/libasr/codegen/asr_to_wasm.cpp @@ -17,6 +17,11 @@ namespace LFortran { namespace { + // This exception is used to abort the visitor pattern when an error occurs. + class CodeGenAbort + { + }; + // Local exception that is only used in this file to exit the visitor // pattern and caught later (not propagated outside) class CodeGenError { @@ -25,140 +30,285 @@ namespace { public: CodeGenError(const std::string &msg) - : d{diag::Diagnostic(msg, diag::Level::Error, diag::Stage::CodeGen)} {} + : d{diag::Diagnostic(msg, diag::Level::Error, diag::Stage::CodeGen)} + { } + + CodeGenError(const std::string &msg, const Location &loc) + : d{diag::Diagnostic(msg, diag::Level::Error, diag::Stage::CodeGen, { + diag::Label("", {loc}) + })} + { } }; } // namespace + +struct import_func{ + std::string name; + std::vector param_types, result_types; +}; + + class ASRToWASMVisitor : public ASR::BaseVisitor { public: Allocator &m_al; + diag::Diagnostics &diag; + ASR::Variable_t *return_var; + bool is_return_visited; - Vec m_preamble; Vec m_type_section; + Vec m_import_section; Vec m_func_section; Vec m_export_section; Vec m_code_section; + Vec m_data_section; uint32_t cur_func_idx; + uint32_t no_of_functions; + uint32_t no_of_imports; + uint32_t no_of_data_segments; + uint32_t last_str_len; + uint32_t avail_mem_loc; + std::map m_var_name_idx_map; std::map m_func_name_idx_map; public: - ASRToWASMVisitor(Allocator &al) : m_al{al} { + ASRToWASMVisitor(Allocator &al, diag::Diagnostics &diagnostics): m_al(al), diag(diagnostics) { cur_func_idx = 0; - m_preamble.reserve(m_al, 1024*128); - m_type_section.reserve(m_al, 1024*128); - m_func_section.reserve(m_al, 1024*128); - m_export_section.reserve(m_al, 1024*128); - m_code_section.reserve(m_al, 1024*128); + avail_mem_loc = 0; + no_of_functions = 0; + no_of_imports = 0; + no_of_data_segments = 0; + m_type_section.reserve(m_al, 1024 * 128); + m_import_section.reserve(m_al, 1024 * 128); + m_func_section.reserve(m_al, 1024 * 128); + m_export_section.reserve(m_al, 1024 * 128); + m_code_section.reserve(m_al, 1024 * 128); + m_data_section.reserve(m_al, 1024 * 128); } void visit_TranslationUnit(const ASR::TranslationUnit_t &x) { + uint32_t len_idx_type_section = wasm::emit_len_placeholder(m_type_section, m_al); + uint32_t len_idx_import_section = wasm::emit_len_placeholder(m_import_section, m_al); + uint32_t len_idx_func_section = wasm::emit_len_placeholder(m_func_section, m_al); + uint32_t len_idx_export_section = wasm::emit_len_placeholder(m_export_section, m_al); + uint32_t len_idx_code_section = wasm::emit_len_placeholder(m_code_section, m_al); + uint32_t len_idx_data_section = wasm::emit_len_placeholder(m_data_section, m_al); + // the main program: for (auto &item : x.m_global_scope->get_scope()) { if (ASR::is_a(*item.second)) { visit_symbol(*item.second); } } + + wasm::emit_u32_b32_idx(m_type_section, m_al, len_idx_type_section, cur_func_idx); // cur_func_idx indicates the total (imported + defined) no of functions + wasm::emit_u32_b32_idx(m_import_section, m_al, len_idx_import_section, no_of_imports); + wasm::emit_u32_b32_idx(m_func_section, m_al, len_idx_func_section, no_of_functions); + wasm::emit_u32_b32_idx(m_export_section, m_al, len_idx_export_section, no_of_functions); + wasm::emit_u32_b32_idx(m_code_section, m_al, len_idx_code_section, no_of_functions); + wasm::emit_u32_b32_idx(m_data_section, m_al, len_idx_data_section, no_of_data_segments); } + void emit_imports(){ + std::vector import_funcs = { + {"print_i32", { wasm::type::i32 }, {}}, + {"print_i64", { wasm::type::i64 }, {}}, + {"print_f32", { wasm::type::f32 }, {}}, + {"print_f64", { wasm::type::f64 }, {}}, + {"print_str", { wasm::type::i32, wasm::type::i32 }, {}}, + {"flush_buf", {}, {}} + }; + + for(auto import_func:import_funcs){ + wasm::emit_import_fn(m_import_section, m_al, "js", import_func.name, cur_func_idx); + // add their types to type section + wasm::emit_b8(m_type_section, m_al, 0x60); // type section + + wasm::emit_u32(m_type_section, m_al, import_func.param_types.size()); + for(auto ¶m_type:import_func.param_types){ + wasm::emit_b8(m_type_section, m_al, param_type); + } + + wasm::emit_u32(m_type_section, m_al, import_func.result_types.size()); + for(auto &result_type:import_func.result_types){ + wasm::emit_b8(m_type_section, m_al, result_type); + } + + m_func_name_idx_map[import_func.name] = cur_func_idx++; + no_of_imports++; + } + + wasm::emit_import_mem(m_import_section, m_al, "js", "memory", 10U /* min page limit */, 10U /* max page limit */); + no_of_imports++; + } + + void visit_Program(const ASR::Program_t &x) { - wasm::emit_header(m_preamble, m_al); // emit header and version - - uint32_t len_idx_type_section = wasm::emit_len_placeholder(m_type_section, m_al); - uint32_t len_idx_func_section = wasm::emit_len_placeholder(m_func_section, m_al); - uint32_t len_idx_export_section = wasm::emit_len_placeholder(m_export_section, m_al); - uint32_t len_idx_code_section = wasm::emit_len_placeholder(m_code_section, m_al); - + + emit_imports(); + + no_of_functions = 0; + for (auto &item : x.m_symtab->get_scope()) { if (ASR::is_a(*item.second)) { throw CodeGenError("Sub Routine not yet supported"); } if (ASR::is_a(*item.second)) { - ASR::Function_t *s = - ASR::down_cast(item.second); + ASR::Function_t *s = ASR::down_cast(item.second); visit_Function(*s); + no_of_functions++; } } - wasm::emit_u32_b32_idx(m_type_section, len_idx_type_section, cur_func_idx); - wasm::emit_u32_b32_idx(m_func_section, len_idx_func_section, cur_func_idx); - wasm::emit_u32_b32_idx(m_export_section, len_idx_export_section, cur_func_idx); - wasm::emit_u32_b32_idx(m_code_section, len_idx_code_section, cur_func_idx); + // Generate main program code + sprintf(x.m_name, "_lcompilers_main"); + m_var_name_idx_map.clear(); // clear all previous variable and their indices + wasm::emit_b8(m_type_section, m_al, 0x60); // new type declaration starts here + m_func_name_idx_map[x.m_name] = cur_func_idx; + + wasm::emit_u32(m_type_section, m_al, 0U); // emit parameter types length = 0 + wasm::emit_u32(m_type_section, m_al, 0U); // emit result types length = 0 + + /********************* Function Body Starts Here *********************/ + uint32_t len_idx_code_section_func_size = wasm::emit_len_placeholder(m_code_section, m_al); + + /********************* Local Vars Types List *********************/ + uint32_t len_idx_code_section_local_vars_list = wasm::emit_len_placeholder(m_code_section, m_al); + int local_vars_cnt = 0, cur_idx = 0; + for (auto &item : x.m_symtab->get_scope()) { + if (ASR::is_a(*item.second)) { + ASR::Variable_t *v = ASR::down_cast(item.second); + wasm::emit_u32(m_code_section, m_al, 1U); // count of local vars of this type + emit_var_type(m_code_section, v); // emit the type of this var + m_var_name_idx_map[v->m_name] = cur_idx++; + local_vars_cnt++; + } + } + // fixup length of local vars list + wasm::emit_u32_b32_idx(m_code_section, m_al, len_idx_code_section_local_vars_list, local_vars_cnt); + + for (size_t i = 0; i < x.n_body; i++) { + this->visit_stmt(*x.m_body[i]); + } + + wasm::emit_expr_end(m_code_section, m_al); + wasm::fixup_len(m_code_section, m_al, len_idx_code_section_func_size); + + wasm::emit_u32(m_func_section, m_al, cur_func_idx); + + wasm::emit_export_fn(m_export_section, m_al, x.m_name, cur_func_idx); + + cur_func_idx++; + no_of_functions++; + } + + void emit_var_type(Vec &code, ASR::Variable_t *v){ + if (ASRUtils::is_integer(*v->m_type)) { + // checking for array is currently omitted + ASR::Integer_t* v_int = ASR::down_cast(v->m_type); + if (v_int->m_kind == 4) { + wasm::emit_b8(code, m_al, wasm::type::i32); + } + else if (v_int->m_kind == 8) { + wasm::emit_b8(code, m_al, wasm::type::i64); + } + else{ + throw CodeGenError("Integers of kind 4 and 8 only supported"); + } + } else if (ASRUtils::is_real(*v->m_type)) { + // checking for array is currently omitted + ASR::Real_t* v_float = ASR::down_cast(v->m_type); + if (v_float->m_kind == 4) { + wasm::emit_b8(code, m_al, wasm::type::f32); + } + else if(v_float->m_kind == 8){ + wasm::emit_b8(code, m_al, wasm::type::f64); + } + else { + throw CodeGenError("Floating Points of kind 4 and 8 only supported"); + } + } else if (ASRUtils::is_logical(*v->m_type)) { + // checking for array is currently omitted + ASR::Logical_t* v_logical = ASR::down_cast(v->m_type); + if (v_logical->m_kind == 4) { + wasm::emit_b8(code, m_al, wasm::type::i32); + } + else if(v_logical->m_kind == 8){ + wasm::emit_b8(code, m_al, wasm::type::i64); + } + else { + throw CodeGenError("Logicals of kind 4 and 8 only supported"); + } + } else { + throw CodeGenError("Param, Result, Var Types other than integer, floating point and logical not yet supported"); + } } void visit_Function(const ASR::Function_t &x) { - wasm::emit_b8(m_type_section, m_al, 0x60); // type section - + m_var_name_idx_map.clear(); // clear all previous variable and their indices + + wasm::emit_b8(m_type_section, m_al, 0x60); // new type declaration starts here + + m_func_name_idx_map[x.m_name] = cur_func_idx; // add func to map early to support recursive func calls + + /********************* Parameter Types List *********************/ uint32_t len_idx_type_section_param_types_list = wasm::emit_len_placeholder(m_type_section, m_al); - int curIdx = 0; + int cur_idx = 0; for (size_t i = 0; i < x.n_args; i++) { ASR::Variable_t *arg = LFortran::ASRUtils::EXPR2VAR(x.m_args[i]); LFORTRAN_ASSERT(LFortran::ASRUtils::is_arg_dummy(arg->m_intent)); - if (arg->m_type->type == ASR::ttypeType::Integer) { - // checking for array is currently omitted - - wasm::emit_b8(m_type_section, m_al, 0x7F); // i32 - m_var_name_idx_map[arg->m_name] = curIdx++; - } else { - throw CodeGenError( - "Parameters other than integer not yet supported"); - } + emit_var_type(m_type_section, arg); + m_var_name_idx_map[arg->m_name] = cur_idx++; } - wasm::fixup_len(m_type_section, len_idx_type_section_param_types_list); + wasm::fixup_len(m_type_section, m_al, len_idx_type_section_param_types_list); + /********************* Result Types List *********************/ uint32_t len_idx_type_section_return_types_list = wasm::emit_len_placeholder(m_type_section, m_al); return_var = LFortran::ASRUtils::EXPR2VAR(x.m_return_var); - if (ASRUtils::is_integer(*return_var->m_type)) { - bool is_int = - ASR::down_cast(return_var->m_type)->m_kind == 4; - if (is_int) { - wasm::emit_b8(m_type_section, m_al, 0x7F); // i32 - } else { - wasm::emit_b8(m_type_section, m_al, 0x7E); // i64 - } - } else { - throw CodeGenError("Return type not supported"); - } - wasm::fixup_len(m_type_section, len_idx_type_section_return_types_list); + emit_var_type(m_type_section, return_var); + wasm::fixup_len(m_type_section, m_al, len_idx_type_section_return_types_list); + is_return_visited = false; // for every function initialize is_return_visited to false + /********************* Function Body Starts Here *********************/ uint32_t len_idx_code_section_func_size = wasm::emit_len_placeholder(m_code_section, m_al); + + /********************* Local Vars Types List *********************/ uint32_t len_idx_code_section_local_vars_list = wasm::emit_len_placeholder(m_code_section, m_al); int local_vars_cnt = 0; for (auto &item : x.m_symtab->get_scope()) { if (ASR::is_a(*item.second)) { - ASR::Variable_t *v = - ASR::down_cast(item.second); - if (v->m_intent == LFortran::ASRUtils::intent_local || - v->m_intent == LFortran::ASRUtils::intent_return_var) { - if (v->m_type->type == ASR::ttypeType::Integer) { - wasm::emit_u32(m_code_section, m_al, 1); // count of local vars of this type - wasm::emit_b8(m_code_section, m_al, 0x7F); // i32 - m_var_name_idx_map[v->m_name] = curIdx++; - local_vars_cnt++; - } else { - throw CodeGenError( - "Variables other than integer not yet supported"); - } + ASR::Variable_t *v = ASR::down_cast(item.second); + if (v->m_intent == LFortran::ASRUtils::intent_local || v->m_intent == LFortran::ASRUtils::intent_return_var) { + wasm::emit_u32(m_code_section, m_al, 1U); // count of local vars of this type + emit_var_type(m_code_section, v); // emit the type of this var + m_var_name_idx_map[v->m_name] = cur_idx++; + local_vars_cnt++; } } } // fixup length of local vars list - wasm::emit_u32_b32_idx(m_code_section, len_idx_code_section_local_vars_list, local_vars_cnt); + wasm::emit_u32_b32_idx(m_code_section, m_al, len_idx_code_section_local_vars_list, local_vars_cnt); for (size_t i = 0; i < x.n_body; i++) { this->visit_stmt(*x.m_body[i]); } + if(!is_return_visited){ + ASR::Return_t temp; + visit_Return(temp); + } + wasm::emit_expr_end(m_code_section, m_al); - wasm::fixup_len(m_code_section, len_idx_code_section_func_size); + wasm::fixup_len(m_code_section, m_al, len_idx_code_section_func_size); wasm::emit_u32(m_func_section, m_al, cur_func_idx); - + wasm::emit_export_fn(m_export_section, m_al, x.m_name, cur_func_idx); - m_func_name_idx_map[x.m_name] = cur_func_idx++; + + cur_func_idx++; } void visit_Assignment(const ASR::Assignment_t &x) { @@ -166,21 +316,24 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { // this->visit_expr(*x.m_target); if (ASR::is_a(*x.m_target)) { ASR::Variable_t *asr_target = LFortran::ASRUtils::EXPR2VAR(x.m_target); - + LFORTRAN_ASSERT(m_var_name_idx_map.find(asr_target->m_name) != m_var_name_idx_map.end()); wasm::emit_set_local(m_code_section, m_al, m_var_name_idx_map[asr_target->m_name]); - } else if (ASR::is_a(*x.m_target)) { + } else if (ASR::is_a(*x.m_target)) { throw CodeGenError("Assignment: Arrays not yet supported"); } else { LFORTRAN_ASSERT(false) } } - void visit_BinOp(const ASR::BinOp_t &x) { + void visit_IntegerBinOp(const ASR::IntegerBinOp_t &x) { + if (x.m_value) { + visit_expr(*x.m_value); + return; + } this->visit_expr(*x.m_left); - this->visit_expr(*x.m_right); - - if (ASRUtils::is_integer(*x.m_type)) { + ASR::Integer_t *i = ASR::down_cast(x.m_type); + if (i->m_kind == 4) { switch (x.m_op) { case ASR::binopType::Add: { wasm::emit_i32_add(m_code_section, m_al); @@ -195,15 +348,131 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { break; }; case ASR::binopType::Div: { - wasm::emit_i32_div(m_code_section, m_al); + wasm::emit_i32_div_s(m_code_section, m_al); + break; + }; + default: + throw CodeGenError("IntegerBinop: Pow Operation not yet implemented"); + } + } else if (i->m_kind == 8) { + switch (x.m_op) { + case ASR::binopType::Add: { + wasm::emit_i64_add(m_code_section, m_al); + break; + }; + case ASR::binopType::Sub: { + wasm::emit_i64_sub(m_code_section, m_al); + break; + }; + case ASR::binopType::Mul: { + wasm::emit_i64_mul(m_code_section, m_al); + break; + }; + case ASR::binopType::Div: { + wasm::emit_i64_div_s(m_code_section, m_al); + break; + }; + default: + throw CodeGenError("IntegerBinop: Pow Operation not yet implemented"); + } + } else { + throw CodeGenError("IntegerBinop: Integer kind not supported"); + } + } + + void visit_RealBinOp(const ASR::RealBinOp_t &x) { + if (x.m_value) { + visit_expr(*x.m_value); + return; + } + this->visit_expr(*x.m_left); + this->visit_expr(*x.m_right); + ASR::Real_t *f = ASR::down_cast(x.m_type); + if (f->m_kind == 4) { + switch (x.m_op) { + case ASR::binopType::Add: { + wasm::emit_f32_add(m_code_section, m_al); + break; + }; + case ASR::binopType::Sub: { + wasm::emit_f32_sub(m_code_section, m_al); + break; + }; + case ASR::binopType::Mul: { + wasm::emit_f32_mul(m_code_section, m_al); + break; + }; + case ASR::binopType::Div: { + wasm::emit_f32_div(m_code_section, m_al); break; }; default: - throw CodeGenError( - "Binop: Pow Operation not yet implemented"); + throw CodeGenError("RealBinop: Pow Operation not yet implemented"); + } + } else if (f->m_kind == 8) { + switch (x.m_op) { + case ASR::binopType::Add: { + wasm::emit_f64_add(m_code_section, m_al); + break; + }; + case ASR::binopType::Sub: { + wasm::emit_f64_sub(m_code_section, m_al); + break; + }; + case ASR::binopType::Mul: { + wasm::emit_f64_mul(m_code_section, m_al); + break; + }; + case ASR::binopType::Div: { + wasm::emit_f64_div(m_code_section, m_al); + break; + }; + default: + throw CodeGenError("RealBinop: Pow Operation not yet implemented"); } } else { - throw CodeGenError("Binop: Only Integer type implemented"); + throw CodeGenError("RealBinop: Real kind not supported"); + } + } + + void visit_IntegerUnaryMinus(const ASR::IntegerUnaryMinus_t &x) { + if (x.m_value) { + visit_expr(*x.m_value); + return; + } + ASR::Integer_t *i = ASR::down_cast(x.m_type); + // there seems no direct unary-minus inst in wasm, so subtracting from 0 + if(i->m_kind == 4){ + wasm::emit_i32_const(m_code_section, m_al, 0); + this->visit_expr(*x.m_arg); + wasm::emit_i32_sub(m_code_section, m_al); + } + else if(i->m_kind == 8){ + wasm::emit_i64_const(m_code_section, m_al, 0LL); + this->visit_expr(*x.m_arg); + wasm::emit_i64_sub(m_code_section, m_al); + } + else{ + throw CodeGenError("IntegerUnaryMinus: Only kind 4 and 8 supported"); + } + } + + void visit_RealUnaryMinus(const ASR::RealUnaryMinus_t &x) { + if (x.m_value) { + visit_expr(*x.m_value); + return; + } + ASR::Real_t *f = ASR::down_cast(x.m_type); + if(f->m_kind == 4){ + this->visit_expr(*x.m_arg); + wasm::emit_f32_neg(m_code_section, m_al); + } + else if(f->m_kind == 8){ + this->visit_expr(*x.m_arg); + wasm::emit_f64_neg(m_code_section, m_al); + } + else{ + throw CodeGenError("RealUnaryMinus: Only kind 4 and 8 supported"); } } @@ -212,18 +481,23 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { auto v = ASR::down_cast(s); switch (v->m_type->type) { case ASR::ttypeType::Integer: - // currently omitting check for 64 bit integers + case ASR::ttypeType::Logical: + case ASR::ttypeType::Real: { + LFORTRAN_ASSERT(m_var_name_idx_map.find(v->m_name) != m_var_name_idx_map.end()); wasm::emit_get_local(m_code_section, m_al, m_var_name_idx_map[v->m_name]); break; + } default: - throw CodeGenError("Variable type not supported"); + throw CodeGenError("Only Integer and Float Variable types currently supported"); } } void visit_Return(const ASR::Return_t & /* x */) { + LFORTRAN_ASSERT(m_var_name_idx_map.find(return_var->m_name) != m_var_name_idx_map.end()); wasm::emit_get_local(m_code_section, m_al, m_var_name_idx_map[return_var->m_name]); - wasm::emit_b8(m_code_section, m_al, 0x0F); + wasm::emit_b8(m_code_section, m_al, 0x0F); // return instruction + is_return_visited = true; } void visit_IntegerConstant(const ASR::IntegerConstant_t &x) { @@ -234,125 +508,271 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { wasm::emit_i32_const(m_code_section, m_al, val); break; } + case 8: { + wasm::emit_i64_const(m_code_section, m_al, val); + break; + } default: { - throw CodeGenError( - "Constant Integer: Only kind 4 currently supported"); + throw CodeGenError("Constant Integer: Only kind 4 and 8 supported"); } } } + void visit_RealConstant(const ASR::RealConstant_t &x) { + double val = x.m_r; + int a_kind = ((ASR::Real_t *)(&(x.m_type->base)))->m_kind; + switch (a_kind) { + case 4: { + wasm::emit_f32_const(m_code_section, m_al, val); + break; + } + case 8: { + wasm::emit_f64_const(m_code_section, m_al, val); + break; + } + default: { + throw CodeGenError("Constant Real: Only kind 4 and 8 supported"); + } + } + } + + void visit_LogicalConstant(const ASR::LogicalConstant_t &x) { + bool val = x.m_value; + int a_kind = ((ASR::Logical_t *)(&(x.m_type->base)))->m_kind; + switch (a_kind) { + case 4: { + wasm::emit_i32_const(m_code_section, m_al, val); + break; + } + case 8: { + wasm::emit_i64_const(m_code_section, m_al, val); + break; + } + default: { + throw CodeGenError("Constant Logical: Only kind 4 and 8 supported"); + } + } + } + + void visit_StringConstant(const ASR::StringConstant_t &x){ + // Todo: Add a check here if there is memory available to store the given string + wasm::emit_str_const(m_data_section, m_al, avail_mem_loc, x.m_s); + last_str_len = strlen(x.m_s); + avail_mem_loc += last_str_len; + no_of_data_segments++; + } + void visit_FunctionCall(const ASR::FunctionCall_t &x) { - ASR::Function_t *fn = ASR::down_cast( - LFortran::ASRUtils::symbol_get_past_external(x.m_name)); + ASR::Function_t *fn = ASR::down_cast(LFortran::ASRUtils::symbol_get_past_external(x.m_name)); for (size_t i = 0; i < x.n_args; i++) { visit_expr(*x.m_args[i].m_value); } + LFORTRAN_ASSERT(m_func_name_idx_map.find(fn->m_name) != m_func_name_idx_map.end()) wasm::emit_call(m_code_section, m_al, m_func_name_idx_map[fn->m_name]); } -}; -Result asr_to_wasm(ASR::TranslationUnit_t &asr, Allocator &al, - const std::string &filename, bool time_report) -{ - int time_pass_global = 0; - int time_pass_do_loops = 0; - int time_visit_asr = 0; - int time_verify = 0; - int time_save = 0; + template + void handle_print(const T &x){ + for (size_t i=0; ivisit_expr(*x.m_values[i]); + ASR::expr_t *v = x.m_values[i]; + ASR::ttype_t *t = ASRUtils::expr_type(v); + int a_kind = ASRUtils::extract_kind_from_ttype_t(t); + + if (ASRUtils::is_integer(*t)) { + switch( a_kind ) { + case 4 : { + // the value is already on stack. call JavaScript print_i32 + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["print_i32"]); + break; + } + case 8 : { + // the value is already on stack. call JavaScript print_i64 + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["print_i64"]); + break; + } + default: { + throw CodeGenError(R"""(Printing support is currently available only + for 32, and 64 bit integer kinds.)"""); + } + } + } else if (ASRUtils::is_real(*t)) { + switch( a_kind ) { + case 4 : { + // the value is already on stack. call JavaScript print_f32 + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["print_f32"]); + break; + } + case 8 : { + // the value is already on stack. call JavaScript print_f64 + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["print_f64"]); + break; + } + default: { + throw CodeGenError(R"""(Printing support is available only + for 32, and 64 bit real kinds.)"""); + } + } + } else if (t->type == ASR::ttypeType::Character) { + // push string location and its size on function stack + wasm::emit_i32_const(m_code_section, m_al, avail_mem_loc - last_str_len); + wasm::emit_i32_const(m_code_section, m_al, last_str_len); - ASRToWASMVisitor v(al); + // call JavaScript printStr + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["print_str"]); - { - auto t1 = std::chrono::high_resolution_clock::now(); - pass_wrap_global_stmts_into_function(al, asr, "f"); - auto t2 = std::chrono::high_resolution_clock::now(); - time_pass_global = - std::chrono::duration_cast(t2 - t1) - .count(); + } + } + + // call JavaScript Flush + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["flush_buf"]); } - { - auto t1 = std::chrono::high_resolution_clock::now(); - pass_replace_do_loops(al, asr); - auto t2 = std::chrono::high_resolution_clock::now(); - time_pass_do_loops = - std::chrono::duration_cast(t2 - t1) - .count(); + void visit_Print(const ASR::Print_t &x){ + if (x.m_fmt != nullptr) { + diag.codegen_warning_label("format string in `print` is not implemented yet and it is currently treated as '*'", + {x.m_fmt->base.loc}, "treated as '*'"); + } + handle_print(x); } - { - auto t1 = std::chrono::high_resolution_clock::now(); - try { - wasm::emit_u32(v.m_type_section, v.m_al, 1); - wasm::emit_u32(v.m_func_section, v.m_al, 3); - wasm::emit_u32(v.m_export_section, v.m_al, 7); - wasm::emit_u32(v.m_code_section, v.m_al, 10); - - uint32_t len_idx_type_section = wasm::emit_len_placeholder(v.m_type_section, v.m_al); - uint32_t len_idx_func_section = wasm::emit_len_placeholder(v.m_func_section, v.m_al); - uint32_t len_idx_export_section = wasm::emit_len_placeholder(v.m_export_section, v.m_al); - uint32_t len_idx_code_section = wasm::emit_len_placeholder(v.m_code_section, v.m_al); - - v.visit_asr((ASR::asr_t &)asr); - - wasm::fixup_len(v.m_type_section, len_idx_type_section); - wasm::fixup_len(v.m_func_section, len_idx_func_section); - wasm::fixup_len(v.m_export_section, len_idx_export_section); - wasm::fixup_len(v.m_code_section, len_idx_code_section); - - } catch (const CodeGenError &e) { - Error error; - return error; + void visit_FileWrite(const ASR::FileWrite_t &x) { + if (x.m_fmt != nullptr) { + diag.codegen_warning_label("format string in `print` is not implemented yet and it is currently treated as '*'", + {x.m_fmt->base.loc}, "treated as '*'"); } - auto t2 = std::chrono::high_resolution_clock::now(); - time_visit_asr = - std::chrono::duration_cast(t2 - t1) - .count(); + if (x.m_unit != nullptr) { + diag.codegen_error_label("unit in write() is not implemented yet", + {x.m_unit->base.loc}, "not implemented"); + throw CodeGenAbort(); + } + handle_print(x); + } + + void visit_FileRead(const ASR::FileRead_t &x) { + if (x.m_fmt != nullptr) { + diag.codegen_warning_label("format string in read() is not implemented yet and it is currently treated as '*'", + {x.m_fmt->base.loc}, "treated as '*'"); + } + if (x.m_unit != nullptr) { + diag.codegen_error_label("unit in read() is not implemented yet", + {x.m_unit->base.loc}, "not implemented"); + throw CodeGenAbort(); + } + diag.codegen_error_label("The intrinsic function read() is not implemented yet in the LLVM backend", + {x.base.base.loc}, "not implemented"); + throw CodeGenAbort(); + } + + void print_msg(std::string msg) { + ASR::StringConstant_t n; + n.m_s = new char[msg.length() + 1]; + strcpy(n.m_s, msg.c_str()); + visit_StringConstant(n); + wasm::emit_i32_const(m_code_section, m_al, avail_mem_loc - last_str_len); + wasm::emit_i32_const(m_code_section, m_al, last_str_len); + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["print_str"]); + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["flush_buf"]); } - // { - // auto t1 = std::chrono::high_resolution_clock::now(); - // v.m_a.verify(); - // auto t2 = std::chrono::high_resolution_clock::now(); - // time_verify = - // std::chrono::duration_cast(t2 - - // t1).count(); - // } + void exit() { + // exit_code would be on stack, so add it to JavaScript Output buffer by printing it. + // this exit code would be read by JavaScript glue code + wasm::emit_call(m_code_section, m_al, m_func_name_idx_map["print_i32"]); + wasm::emit_unreachable(m_code_section, m_al); // raise trap/exception + } + + void visit_Stop(const ASR::Stop_t &x) { + print_msg("STOP"); + if (x.m_code && ASRUtils::expr_type(x.m_code)->type == ASR::ttypeType::Integer) { + this->visit_expr(*x.m_code); + } else { + wasm::emit_i32_const(m_code_section, m_al, 0); // zero exit code + } + exit(); + } + + void visit_ErrorStop(const ASR::ErrorStop_t & /* x */) { + print_msg("ERROR STOP"); + wasm::emit_i32_const(m_code_section, m_al, 1); // non-zero exit code + exit(); + } + + void visit_If(const ASR::If_t &x) { + this->visit_expr(*x.m_test); + wasm::emit_b8(m_code_section, m_al, 0x04); + wasm::emit_b8(m_code_section, m_al, 0x40); // empty block type + for (size_t i=0; ivisit_stmt(*x.m_body[i]); + } + if(x.n_orelse){ + wasm::emit_b8(m_code_section, m_al, 0x05); // starting of else + for (size_t i=0; ivisit_stmt(*x.m_orelse[i]); + } + } + wasm::emit_expr_end(m_code_section, m_al); + } +}; + +Result> asr_to_wasm_bytes_stream(ASR::TranslationUnit_t &asr, Allocator &al, diag::Diagnostics &diagnostics) { + ASRToWASMVisitor v(al, diagnostics); + Vec wasm_bytes; + + pass_wrap_global_stmts_into_function(al, asr, "f"); + pass_replace_do_loops(al, asr); + + try { + v.visit_asr((ASR::asr_t &)asr); + } catch (const CodeGenError &e) { + diagnostics.diagnostics.push_back(e.d); + return Error(); + } + + { + wasm_bytes.reserve(al, 8U /* preamble size */ + 8U /* (section id + section size) */ * 6U /* number of sections */ + + v.m_type_section.size() + v.m_import_section.size() + v.m_func_section.size() + + v.m_export_section.size() + v.m_code_section.size() + v.m_data_section.size()); + + wasm::emit_header(wasm_bytes, al); // emit header and version + wasm::encode_section(wasm_bytes, v.m_type_section, al, 1U); + wasm::encode_section(wasm_bytes, v.m_import_section, al, 2U); + wasm::encode_section(wasm_bytes, v.m_func_section, al, 3U); + wasm::encode_section(wasm_bytes, v.m_export_section, al, 7U); + wasm::encode_section(wasm_bytes, v.m_code_section, al, 10U); + wasm::encode_section(wasm_bytes, v.m_data_section, al, 11U); + } + + return wasm_bytes; +} + +Result asr_to_wasm(ASR::TranslationUnit_t &asr, Allocator &al, const std::string &filename, + bool time_report, diag::Diagnostics &diagnostics) { + int time_visit_asr = 0; + int time_save = 0; + + auto t1 = std::chrono::high_resolution_clock::now(); + Result> wasm = asr_to_wasm_bytes_stream(asr, al, diagnostics); + auto t2 = std::chrono::high_resolution_clock::now(); + time_visit_asr = std::chrono::duration_cast(t2 - t1).count(); + if (!wasm.ok) { + return wasm.error; + } { auto t1 = std::chrono::high_resolution_clock::now(); - // v.m_a.save_binary(filename); - FILE *fp = fopen(filename.c_str(), "wb"); - fwrite(v.m_preamble.data(), sizeof(uint8_t), v.m_preamble.size(), fp); - fwrite(v.m_type_section.data(), sizeof(uint8_t), - v.m_type_section.size(), fp); - fwrite(v.m_func_section.data(), sizeof(uint8_t), - v.m_func_section.size(), fp); - fwrite(v.m_export_section.data(), sizeof(uint8_t), - v.m_export_section.size(), fp); - fwrite(v.m_code_section.data(), sizeof(uint8_t), - v.m_code_section.size(), fp); - fclose(fp); + wasm::save_bin(wasm.result, filename); auto t2 = std::chrono::high_resolution_clock::now(); - time_save = - std::chrono::duration_cast(t2 - t1) - .count(); + time_save = std::chrono::duration_cast(t2 - t1).count(); } if (time_report) { std::cout << "Codegen Time report:" << std::endl; - std::cout << "Global: " << std::setw(5) << time_pass_global - << std::endl; - std::cout << "Do loops: " << std::setw(5) << time_pass_do_loops - << std::endl; - std::cout << "ASR -> wasm: " << std::setw(5) << time_visit_asr - << std::endl; - std::cout << "Verify: " << std::setw(5) << time_verify << std::endl; + std::cout << "ASR -> wasm: " << std::setw(5) << time_visit_asr << std::endl; std::cout << "Save: " << std::setw(5) << time_save << std::endl; - int total = time_pass_global + time_pass_do_loops + time_visit_asr + - time_verify + time_verify + time_save; + int total = time_visit_asr + time_save; std::cout << "Total: " << std::setw(5) << total << std::endl; } return 0; diff --git a/src/libasr/codegen/asr_to_wasm.h b/src/libasr/codegen/asr_to_wasm.h index 2eb830a4e0..e38182c796 100644 --- a/src/libasr/codegen/asr_to_wasm.h +++ b/src/libasr/codegen/asr_to_wasm.h @@ -5,9 +5,12 @@ namespace LFortran { - // Generates a 32-bit wasm Linux executable binary `filename` + // Generates a wasm binary stream from ASR + Result> asr_to_wasm_bytes_stream(ASR::TranslationUnit_t &asr, Allocator &al, diag::Diagnostics &diagnostics); + + // Generates a wasm binary to `filename` Result asr_to_wasm(ASR::TranslationUnit_t &asr, Allocator &al, - const std::string &filename, bool time_report); + const std::string &filename, bool time_report, diag::Diagnostics &diagnostics); } // namespace LFortran diff --git a/src/libasr/codegen/asr_to_x86.cpp b/src/libasr/codegen/asr_to_x86.cpp index 03327b2eab..4cde48c616 100644 --- a/src/libasr/codegen/asr_to_x86.cpp +++ b/src/libasr/codegen/asr_to_x86.cpp @@ -302,61 +302,44 @@ class ASRToX86Visitor : public ASR::BaseVisitor } } - void visit_BinOp(const ASR::BinOp_t &x) { + void visit_IntegerBinOp(const ASR::IntegerBinOp_t &x) { this->visit_expr(*x.m_right); m_a.asm_push_r32(X86Reg::eax); this->visit_expr(*x.m_left); m_a.asm_pop_r32(X86Reg::ecx); // The left operand is in eax, the right operand is in ecx // Leave the result in eax. - if (x.m_type->type == ASR::ttypeType::Integer) { - switch (x.m_op) { - case ASR::binopType::Add: { - m_a.asm_add_r32_r32(X86Reg::eax, X86Reg::ecx); - break; - }; - case ASR::binopType::Sub: { - m_a.asm_sub_r32_r32(X86Reg::eax, X86Reg::ecx); - break; - }; - case ASR::binopType::Mul: { - m_a.asm_mov_r32_imm32(X86Reg::edx, 0); - m_a.asm_mul_r32(X86Reg::ecx); - break; - }; - case ASR::binopType::Div: { - m_a.asm_mov_r32_imm32(X86Reg::edx, 0); - m_a.asm_div_r32(X86Reg::ecx); - break; - }; - case ASR::binopType::Pow: { - throw CodeGenError("Pow not implemented yet."); - break; - }; + switch (x.m_op) { + case ASR::binopType::Add: { + m_a.asm_add_r32_r32(X86Reg::eax, X86Reg::ecx); + break; + }; + case ASR::binopType::Sub: { + m_a.asm_sub_r32_r32(X86Reg::eax, X86Reg::ecx); + break; + }; + case ASR::binopType::Mul: { + m_a.asm_mov_r32_imm32(X86Reg::edx, 0); + m_a.asm_mul_r32(X86Reg::ecx); + break; + }; + case ASR::binopType::Div: { + m_a.asm_mov_r32_imm32(X86Reg::edx, 0); + m_a.asm_div_r32(X86Reg::ecx); + break; + }; + default: { + throw CodeGenError("Binary operator '" + ASRUtils::binop_to_str_python(x.m_op) + "' not supported yet"); } - } else { - throw CodeGenError("Binop: Only Integer types implemented so far"); } } - void visit_UnaryOp(const ASR::UnaryOp_t &x) { - this->visit_expr(*x.m_operand); - if (x.m_type->type == ASR::ttypeType::Integer) { - if (x.m_op == ASR::unaryopType::UAdd) { - // eax = eax - return; - } else if (x.m_op == ASR::unaryopType::USub) { - m_a.asm_neg_r32(X86Reg::eax); - return; - } else { - throw CodeGenError("Unary type not implemented yet"); - } - } else { - throw CodeGenError("UnaryOp: type not supported yet"); - } + void visit_IntegerUnaryMinus(const ASR::IntegerUnaryMinus_t &x) { + this->visit_expr(*x.m_arg); + m_a.asm_neg_r32(X86Reg::eax); } - void visit_Compare(const ASR::Compare_t &x) { + void visit_IntegerCompare(const ASR::IntegerCompare_t &x) { std::string id = std::to_string(get_hash((ASR::asr_t*)&x)); this->visit_expr(*x.m_right); m_a.asm_push_r32(X86Reg::eax); @@ -365,46 +348,40 @@ class ASRToX86Visitor : public ASR::BaseVisitor // The left operand is in eax, the right operand is in ecx // Leave the result in eax. m_a.asm_cmp_r32_r32(X86Reg::eax, X86Reg::ecx); - LFORTRAN_ASSERT(LFortran::ASRUtils::expr_type(x.m_left)->type == LFortran::ASRUtils::expr_type(x.m_right)->type); - ASR::ttypeType optype = LFortran::ASRUtils::expr_type(x.m_left)->type; - if (optype == ASR::ttypeType::Integer) { - switch (x.m_op) { - case (ASR::cmpopType::Eq) : { - m_a.asm_je_label(".compare1" + id); - break; - } - case (ASR::cmpopType::Gt) : { - m_a.asm_jg_label(".compare1" + id); - break; - } - case (ASR::cmpopType::GtE) : { - m_a.asm_jge_label(".compare1" + id); - break; - } - case (ASR::cmpopType::Lt) : { - m_a.asm_jl_label(".compare1" + id); - break; - } - case (ASR::cmpopType::LtE) : { - m_a.asm_jle_label(".compare1" + id); - break; - } - case (ASR::cmpopType::NotEq) : { - m_a.asm_jne_label(".compare1" + id); - break; - } - default : { - throw CodeGenError("Comparison operator not implemented"); - } + switch (x.m_op) { + case (ASR::cmpopType::Eq) : { + m_a.asm_je_label(".compare1" + id); + break; + } + case (ASR::cmpopType::Gt) : { + m_a.asm_jg_label(".compare1" + id); + break; + } + case (ASR::cmpopType::GtE) : { + m_a.asm_jge_label(".compare1" + id); + break; + } + case (ASR::cmpopType::Lt) : { + m_a.asm_jl_label(".compare1" + id); + break; + } + case (ASR::cmpopType::LtE) : { + m_a.asm_jle_label(".compare1" + id); + break; + } + case (ASR::cmpopType::NotEq) : { + m_a.asm_jne_label(".compare1" + id); + break; + } + default : { + throw CodeGenError("Comparison operator not implemented"); } - m_a.asm_mov_r32_imm32(X86Reg::eax, 0); - m_a.asm_jmp_label(".compareend" + id); - m_a.add_label(".compare1" + id); - m_a.asm_mov_r32_imm32(X86Reg::eax, 1); - m_a.add_label(".compareend" + id); - } else { - throw CodeGenError("Only Integer implemented in Compare"); } + m_a.asm_mov_r32_imm32(X86Reg::eax, 0); + m_a.asm_jmp_label(".compareend" + id); + m_a.add_label(".compare1" + id); + m_a.asm_mov_r32_imm32(X86Reg::eax, 1); + m_a.add_label(".compareend" + id); } void visit_Assignment(const ASR::Assignment_t &x) { diff --git a/src/libasr/codegen/evaluator.cpp b/src/libasr/codegen/evaluator.cpp index 48c4807c57..1850f0a7fa 100644 --- a/src/libasr/codegen/evaluator.cpp +++ b/src/libasr/codegen/evaluator.cpp @@ -157,6 +157,13 @@ LLVMEvaluator::LLVMEvaluator(const std::string &t) LLVMInitializeX86AsmPrinter(); LLVMInitializeX86AsmParser(); #endif +#ifdef HAVE_TARGET_WASM + LLVMInitializeWebAssemblyTarget(); + LLVMInitializeWebAssemblyTargetInfo(); + LLVMInitializeWebAssemblyTargetMC(); + LLVMInitializeWebAssemblyAsmPrinter(); + LLVMInitializeWebAssemblyAsmParser(); +#endif context = std::make_unique(); @@ -423,6 +430,9 @@ void LLVMEvaluator::print_targets() #ifdef HAVE_TARGET_X86 LLVMInitializeX86TargetInfo(); #endif +#ifdef HAVE_TARGET_WASM + LLVMInitializeWebAssemblyTargetInfo(); +#endif llvm::raw_ostream &os = llvm::outs(); llvm::TargetRegistry::printRegisteredTargetsForVersion(os); } diff --git a/src/libasr/codegen/llvm_array_utils.cpp b/src/libasr/codegen/llvm_array_utils.cpp index f6cbd97b6c..2b6d6f84e3 100644 --- a/src/libasr/codegen/llvm_array_utils.cpp +++ b/src/libasr/codegen/llvm_array_utils.cpp @@ -259,8 +259,12 @@ namespace LFortran { } llvm::Value* SimpleCMODescriptor:: - get_pointer_to_dimension_descriptor_array(llvm::Value* arr) { - return LLVM::CreateLoad(*builder, llvm_utils->create_gep(arr, 2)); + get_pointer_to_dimension_descriptor_array(llvm::Value* arr, bool load) { + llvm::Value* dim_des_arr_ptr = llvm_utils->create_gep(arr, 2); + if( !load ) { + return dim_des_arr_ptr; + } + return LLVM::CreateLoad(*builder, dim_des_arr_ptr); } llvm::Value* SimpleCMODescriptor:: @@ -272,10 +276,19 @@ namespace LFortran { return LLVM::CreateLoad(*builder, rank_ptr); } + void SimpleCMODescriptor:: + set_rank(llvm::Value* arr, llvm::Value* rank) { + llvm::Value* rank_ptr = llvm_utils->create_gep(arr, 4); + LLVM::CreateStore(*builder, rank, rank_ptr); + } + llvm::Value* SimpleCMODescriptor:: - get_dimension_size(llvm::Value* dim_des_arr, llvm::Value* dim) { - return LLVM::CreateLoad(*builder, - llvm_utils->create_gep(llvm_utils->create_ptr_gep(dim_des_arr, dim), 3)); + get_dimension_size(llvm::Value* dim_des_arr, llvm::Value* dim, bool load) { + llvm::Value* dim_size = llvm_utils->create_gep(llvm_utils->create_ptr_gep(dim_des_arr, dim), 3); + if( !load ) { + return dim_size; + } + return LLVM::CreateLoad(*builder, dim_size); } void SimpleCMODescriptor::fill_array_details( @@ -398,12 +411,20 @@ namespace LFortran { return LLVM::CreateLoad(*builder, llvm_utils->create_gep(arr, 1)); } - llvm::Value* SimpleCMODescriptor::get_lower_bound(llvm::Value* dim_des) { - return LLVM::CreateLoad(*builder, llvm_utils->create_gep(dim_des, 1)); + llvm::Value* SimpleCMODescriptor::get_lower_bound(llvm::Value* dim_des, bool load) { + llvm::Value* lb = llvm_utils->create_gep(dim_des, 1); + if( !load ) { + return lb; + } + return LLVM::CreateLoad(*builder, lb); } - llvm::Value* SimpleCMODescriptor::get_upper_bound(llvm::Value* dim_des) { - return LLVM::CreateLoad(*builder, llvm_utils->create_gep(dim_des, 2)); + llvm::Value* SimpleCMODescriptor::get_upper_bound(llvm::Value* dim_des, bool load) { + llvm::Value* ub = llvm_utils->create_gep(dim_des, 2); + if( !load ) { + return ub; + } + return LLVM::CreateLoad(*builder, ub); } llvm::Value* SimpleCMODescriptor::get_stride(llvm::Value*) { diff --git a/src/libasr/codegen/llvm_array_utils.h b/src/libasr/codegen/llvm_array_utils.h index 3e47b4479e..4f8715873d 100644 --- a/src/libasr/codegen/llvm_array_utils.h +++ b/src/libasr/codegen/llvm_array_utils.h @@ -185,7 +185,7 @@ namespace LFortran { * implemented by current class). */ virtual - llvm::Value* get_lower_bound(llvm::Value* dim_des) = 0; + llvm::Value* get_lower_bound(llvm::Value* dim_des, bool load=true) = 0; /* * Returns upper bound in the input @@ -193,7 +193,7 @@ namespace LFortran { * implemented by current class. */ virtual - llvm::Value* get_upper_bound(llvm::Value* dim_des) = 0; + llvm::Value* get_upper_bound(llvm::Value* dim_des, bool load=true) = 0; /* * Returns stride in the input @@ -210,18 +210,21 @@ namespace LFortran { */ virtual llvm::Value* get_dimension_size(llvm::Value* dim_des_arr, - llvm::Value* dim) = 0; + llvm::Value* dim, bool load=true) = 0; virtual llvm::Value* get_rank(llvm::Value* arr, bool get_pointer=false) = 0; + virtual + void set_rank(llvm::Value* arr, llvm::Value* rank) = 0; + /* * Returns pointer to dimension descriptor array * in the input array descriptor according to the rules * implemented by current class. */ virtual - llvm::Value* get_pointer_to_dimension_descriptor_array(llvm::Value* arr) = 0; + llvm::Value* get_pointer_to_dimension_descriptor_array(llvm::Value* arr, bool load=true) = 0; /* * Returns pointer to the dimension descriptor @@ -325,21 +328,24 @@ namespace LFortran { virtual llvm::Value* get_rank(llvm::Value* arr, bool get_pointer=false); + virtual + void set_rank(llvm::Value* arr, llvm::Value* rank); + virtual llvm::Value* get_offset(llvm::Value* dim_des); virtual - llvm::Value* get_lower_bound(llvm::Value* dim_des); + llvm::Value* get_lower_bound(llvm::Value* dim_des, bool load=true); virtual - llvm::Value* get_upper_bound(llvm::Value* dim_des); + llvm::Value* get_upper_bound(llvm::Value* dim_des, bool load=true); virtual llvm::Value* get_dimension_size(llvm::Value* dim_des_arr, - llvm::Value* dim); + llvm::Value* dim, bool load=true); virtual - llvm::Value* get_pointer_to_dimension_descriptor_array(llvm::Value* arr); + llvm::Value* get_pointer_to_dimension_descriptor_array(llvm::Value* arr, bool load=true); virtual llvm::Value* get_pointer_to_dimension_descriptor(llvm::Value* dim_des_arr, diff --git a/src/libasr/codegen/llvm_utils.cpp b/src/libasr/codegen/llvm_utils.cpp index 0e3b1a8bde..a02649cc2d 100644 --- a/src/libasr/codegen/llvm_utils.cpp +++ b/src/libasr/codegen/llvm_utils.cpp @@ -12,6 +12,11 @@ namespace LFortran { return builder.CreateLoad(t2, x); } + llvm::Value* CreateStore(llvm::IRBuilder<> &builder, llvm::Value *x, llvm::Value *y) { + LFORTRAN_ASSERT(y->getType()->isPointerTy()); + return builder.CreateStore(x, y); + } + llvm::Value* CreateGEP(llvm::IRBuilder<> &builder, llvm::Value *x, std::vector &idx) { llvm::Type *t = x->getType(); @@ -26,7 +31,7 @@ namespace LFortran { llvm::Type *t2 = t->getContainedType(0); return builder.CreateInBoundsGEP(t2, x, idx); } - } + } // namespace LLVM LLVMUtils::LLVMUtils(llvm::LLVMContext& context, llvm::IRBuilder<>* _builder): @@ -59,4 +64,4 @@ namespace LFortran { return LLVM::CreateInBoundsGEP(*builder, ptr, idx_vec); } -} // LFortran +} // namespace LFortran diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index 9d679a7816..ff8d16cb1d 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -10,9 +10,10 @@ namespace LFortran { namespace LLVM { - llvm::Value* CreateLoad(llvm::IRBuilder<> &builder, llvm::Value *x); - llvm::Value* CreateGEP(llvm::IRBuilder<> &builder, llvm::Value *x, std::vector &idx); - llvm::Value* CreateInBoundsGEP(llvm::IRBuilder<> &builder, llvm::Value *x, std::vector &idx); + llvm::Value* CreateLoad(llvm::IRBuilder<> &builder, llvm::Value *x); + llvm::Value* CreateStore(llvm::IRBuilder<> &builder, llvm::Value *x, llvm::Value *y); + llvm::Value* CreateGEP(llvm::IRBuilder<> &builder, llvm::Value *x, std::vector &idx); + llvm::Value* CreateInBoundsGEP(llvm::IRBuilder<> &builder, llvm::Value *x, std::vector &idx); } class LLVMUtils { @@ -21,7 +22,7 @@ namespace LFortran { llvm::LLVMContext& context; llvm::IRBuilder<>* builder; - + public: LLVMUtils(llvm::LLVMContext& context, diff --git a/src/libasr/codegen/wasm_assembler.h b/src/libasr/codegen/wasm_assembler.h index 0a7fd794b1..2acac21ddc 100644 --- a/src/libasr/codegen/wasm_assembler.h +++ b/src/libasr/codegen/wasm_assembler.h @@ -6,37 +6,26 @@ namespace LFortran { namespace wasm { -std::vector encode_signed_leb128(int32_t n) { - std::vector out; - auto more = true; - do { - uint8_t byte = n & 0x7f; - n >>= 7; - more = !((((n == 0) && ((byte & 0x40) == 0)) || - ((n == -1) && ((byte & 0x40) != 0)))); - if (more) { - byte |= 0x80; - } - out.emplace_back(byte); - } while (more); - return out; -} +enum type { + i32 = 0x7F, + i64 = 0x7E, + f32 = 0x7D, + f64 = 0x7C +}; -std::vector encode_unsigned_leb128(uint32_t n) { - std::vector out; +void emit_leb128_u32(Vec &code, Allocator &al, uint32_t n) { // for u32 do { uint8_t byte = n & 0x7f; n >>= 7; if (n != 0) { byte |= 0x80; } - out.emplace_back(byte); + code.push_back(al, byte); } while (n != 0); - return out; } -void emit_signed_leb128(Vec &code, Allocator &al, int32_t n) { - auto more = true; +void emit_leb128_i32(Vec &code, Allocator &al, int32_t n) { // for i32 + bool more = true; do { uint8_t byte = n & 0x7f; n >>= 7; @@ -49,15 +38,34 @@ void emit_signed_leb128(Vec &code, Allocator &al, int32_t n) { } while (more); } -void emit_unsigned_leb128(Vec &code, Allocator &al, uint32_t n) { +void emit_leb128_i64(Vec &code, Allocator &al, int64_t n) { // for i64 + bool more = true; do { uint8_t byte = n & 0x7f; n >>= 7; - if (n != 0) { + more = !((((n == 0) && ((byte & 0x40) == 0)) || + ((n == -1) && ((byte & 0x40) != 0)))); + if (more) { byte |= 0x80; } code.push_back(al, byte); - } while (n != 0); + } while (more); +} + +void emit_ieee754_f32(Vec &code, Allocator &al, float z) { // for f32 + uint8_t encoded_float[sizeof(z)]; + std::memcpy(&encoded_float, &z, sizeof(z)); + for(auto &byte:encoded_float){ + code.push_back(al, byte); + } +} + +void emit_ieee754_f64(Vec &code, Allocator &al, double z) { // for f64 + uint8_t encoded_float[sizeof(z)]; + std::memcpy(&encoded_float, &z, sizeof(z)); + for(auto &byte:encoded_float){ + code.push_back(al, byte); + } } // function to emit header of Wasm Binary Format @@ -72,28 +80,54 @@ void emit_header(Vec &code, Allocator &al) { code.push_back(al, 0x00); } +// function to append a given bytecode to the end of the code +void emit_b8(Vec &code, Allocator &al, uint8_t x) { + code.push_back(al, x); +} + // function to emit unsigned 32 bit integer void emit_u32(Vec &code, Allocator &al, uint32_t x) { - emit_unsigned_leb128(code, al, x); + emit_leb128_u32(code, al, x); } // function to emit signed 32 bit integer void emit_i32(Vec &code, Allocator &al, int32_t x) { - emit_signed_leb128(code, al, x); + emit_leb128_i32(code, al, x); } -// function to append a given bytecode to the end of the code -void emit_b8(Vec &code, Allocator &al, uint8_t x) { - code.push_back(al, x); +// function to emit signed 64 bit integer +void emit_i64(Vec &code, Allocator &al, int64_t x) { + emit_leb128_i64(code, al, x); +} + +// function to emit 32 bit float +void emit_f32(Vec &code, Allocator &al, float x) { + emit_ieee754_f32(code, al, x); +} + +// function to emit 64 bit float +void emit_f64(Vec &code, Allocator &al, double x) { + emit_ieee754_f64(code, al, x); } -void emit_u32_b32_idx(Vec &code, uint32_t idx, +// function to emit string +void emit_str(Vec &code, Allocator &al, std::string text){ + std::vector text_bytes(text.size()); + std::memcpy(text_bytes.data(), text.data(), text.size()); + emit_u32(code, al, text_bytes.size()); + for(auto &byte:text_bytes) + emit_b8(code, al, byte); +} + +void emit_u32_b32_idx(Vec &code, Allocator &al, uint32_t idx, uint32_t section_size) { /* Encodes the integer `i` using LEB128 and adds trailing zeros to always occupy 4 bytes. Stores the int `i` at the index `idx` in `code`. */ - std::vector num = encode_unsigned_leb128(section_size); + Vec num; + num.reserve(al, 4); + emit_leb128_u32(num, al, section_size); std::vector num_4b = {0x80, 0x80, 0x80, 0x00}; assert(num.size() <= 4); for (uint32_t i = 0; i < num.size(); i++) { @@ -105,9 +139,9 @@ void emit_u32_b32_idx(Vec &code, uint32_t idx, } // function to fixup length at the given length index -void fixup_len(Vec &code, uint32_t len_idx) { +void fixup_len(Vec &code, Allocator &al, uint32_t len_idx) { uint32_t section_len = code.size() - len_idx - 4u; - emit_u32_b32_idx(code, len_idx, section_len); + emit_u32_b32_idx(code, al, len_idx, section_len); } // function to emit length placeholder @@ -120,15 +154,39 @@ uint32_t emit_len_placeholder(Vec &code, Allocator &al) { return len_idx; } -// function to emit a i32.const instruction -void emit_i32_const(Vec &code, Allocator &al, int32_t x) { - code.push_back(al, 0x41); - emit_i32(code, al, x); +void emit_export_fn(Vec &code, Allocator &al, const std::string& name, + uint32_t idx) { + emit_str(code, al, name); + emit_b8(code, al, 0x00); // for exporting function + emit_u32(code, al, idx); } -// function to emit end of wasm expression -void emit_expr_end(Vec &code, Allocator &al) { - code.push_back(al, 0x0B); +void emit_import_fn(Vec &code, Allocator &al, const std::string &mod_name, + const std::string& fn_name, uint32_t type_idx) +{ + emit_str(code, al, mod_name); + emit_str(code, al, fn_name); + emit_b8(code, al, 0x00); // for importing function + emit_u32(code, al, type_idx); +} + +void emit_import_mem(Vec &code, Allocator &al, const std::string &mod_name, + const std::string& mem_name, uint32_t min_limit, uint32_t /* max_limit */) { + emit_str(code, al, mod_name); + emit_str(code, al, mem_name); + emit_b8(code, al, 0x02); // for importing memory + emit_b8(code, al, 0x00); // for specifying min page limit of memory + // max page limit can also be specifid, but currently omitting it. + emit_u32(code, al, min_limit); +} + +void encode_section(Vec &des, Vec §ion_content, Allocator &al, uint32_t section_id){ + // every section in WebAssembly is encoded by adding its section id, followed by the content size and lastly the contents + emit_u32(des, al, section_id); + emit_u32(des, al, section_content.size()); + for(auto &byte:section_content){ + des.push_back(al, byte); + } } // function to emit get local variable at given index @@ -143,40 +201,314 @@ void emit_set_local(Vec &code, Allocator &al, uint32_t idx) { emit_u32(code, al, idx); } -// function to emit i32.add instruction -void emit_i32_add(Vec &code, Allocator &al) { - code.push_back(al, 0x6A); +// function to emit call instruction +void emit_call(Vec &code, Allocator &al, uint32_t idx) { + code.push_back(al, 0x10); + emit_u32(code, al, idx); } -// function to emit i32.sub instruction -void emit_i32_sub(Vec &code, Allocator &al) { - code.push_back(al, 0x6B); +// function to emit end of wasm expression +void emit_expr_end(Vec &code, Allocator &al) { + code.push_back(al, 0x0B); } +/**************************** Integer Operations ****************************/ + +// function to emit a i32.const instruction +void emit_i32_const(Vec &code, Allocator &al, int32_t x) { + code.push_back(al, 0x41); + emit_i32(code, al, x); +} + +// function to emit i32.clz instruction +void emit_i32_clz(Vec &code, Allocator &al) { code.push_back(al, 0x67); } + +// function to emit i32.ctz instruction +void emit_i32_ctz(Vec &code, Allocator &al) { code.push_back(al, 0x68); } + +// function to emit i32.popcnt instruction +void emit_i32_popcnt(Vec &code, Allocator &al) { code.push_back(al, 0x69); } + +// function to emit i32.add instruction +void emit_i32_add(Vec &code, Allocator &al) { code.push_back(al, 0x6A); } + +// function to emit i32.sub instruction +void emit_i32_sub(Vec &code, Allocator &al) { code.push_back(al, 0x6B); } + // function to emit i32.mul instruction -void emit_i32_mul(Vec &code, Allocator &al) { - code.push_back(al, 0x6C); +void emit_i32_mul(Vec &code, Allocator &al) { code.push_back(al, 0x6C); } + +// function to emit i32.div_s instruction +void emit_i32_div_s(Vec &code, Allocator &al) { code.push_back(al, 0x6D); } + +// function to emit i32.div_u instruction +void emit_i32_div_u(Vec &code, Allocator &al) { code.push_back(al, 0x6E); } + +// function to emit i32.rem_s instruction +void emit_i32_rem_s(Vec &code, Allocator &al) { code.push_back(al, 0x6F); } + +// function to emit i32.rem_u instruction +void emit_i32_rem_u(Vec &code, Allocator &al) { code.push_back(al, 0x70); } + +// function to emit i32.and instruction +void emit_i32_and(Vec &code, Allocator &al) { code.push_back(al, 0x71); } + +// function to emit i32.or instruction +void emit_i32_or(Vec &code, Allocator &al) { code.push_back(al, 0x72); } + +// function to emit i32.xor instruction +void emit_i32_xor(Vec &code, Allocator &al) { code.push_back(al, 0x73); } + +// function to emit i32.shl instruction +void emit_i32_shl(Vec &code, Allocator &al) { code.push_back(al, 0x74); } + +// function to emit i32.shr_s instruction +void emit_i32_shr_s(Vec &code, Allocator &al) { code.push_back(al, 0x75); } + +// function to emit i32.shr_u instruction +void emit_i32_shr_u(Vec &code, Allocator &al) { code.push_back(al, 0x76); } + +// function to emit i32.rotl instruction +void emit_i32_rotl(Vec &code, Allocator &al) { code.push_back(al, 0x77); } + +// function to emit i32.rotr instruction +void emit_i32_rotr(Vec &code, Allocator &al) { code.push_back(al, 0x78); } + + +// function to emit a i64.const instruction +void emit_i64_const(Vec &code, Allocator &al, int64_t x) { + code.push_back(al, 0x42); + emit_i64(code, al, x); } -// function to emit i32.div instruction -void emit_i32_div(Vec &code, Allocator &al) { - code.push_back(al, 0x6D); +// function to emit i64.clz instruction +void emit_i64_clz(Vec &code, Allocator &al) { code.push_back(al, 0x79); } + +// function to emit i64.ctz instruction +void emit_i64_ctz(Vec &code, Allocator &al) { code.push_back(al, 0x7A); } + +// function to emit i64.popcnt instruction +void emit_i64_popcnt(Vec &code, Allocator &al) { code.push_back(al, 0x7B); } + +// function to emit i64.add instruction +void emit_i64_add(Vec &code, Allocator &al) { code.push_back(al, 0x7C); } + +// function to emit i64.sub instruction +void emit_i64_sub(Vec &code, Allocator &al) { code.push_back(al, 0x7D); } + +// function to emit i64.mul instruction +void emit_i64_mul(Vec &code, Allocator &al) { code.push_back(al, 0x7E); } + +// function to emit i64.div_s instruction +void emit_i64_div_s(Vec &code, Allocator &al) { code.push_back(al, 0x7F); } + +// function to emit i64.div_u instruction +void emit_i64_div_u(Vec &code, Allocator &al) { code.push_back(al, 0x80); } + +// function to emit i64.rem_s instruction +void emit_i64_rem_s(Vec &code, Allocator &al) { code.push_back(al, 0x81); } + +// function to emit i64.rem_u instruction +void emit_i64_rem_u(Vec &code, Allocator &al) { code.push_back(al, 0x82); } + +// function to emit i64.and instruction +void emit_i64_and(Vec &code, Allocator &al) { code.push_back(al, 0x83); } + +// function to emit i64.or instruction +void emit_i64_or(Vec &code, Allocator &al) { code.push_back(al, 0x84); } + +// function to emit i64.xor instruction +void emit_i64_xor(Vec &code, Allocator &al) { code.push_back(al, 0x85); } + +// function to emit i64.shl instruction +void emit_i64_shl(Vec &code, Allocator &al) { code.push_back(al, 0x86); } + +// function to emit i64.shr_s instruction +void emit_i64_shr_s(Vec &code, Allocator &al) { code.push_back(al, 0x87); } + +// function to emit i64.shr_u instruction +void emit_i64_shr_u(Vec &code, Allocator &al) { code.push_back(al, 0x88); } + +// function to emit i64.rotl instruction +void emit_i64_rotl(Vec &code, Allocator &al) { code.push_back(al, 0x89); } + +// function to emit i64.rotr instruction +void emit_i64_rotr(Vec &code, Allocator &al) { code.push_back(al, 0x8A); } + + + +/**************************** Floating Point Operations ****************************/ + +// function to emit a f32.const instruction +void emit_f32_const(Vec &code, Allocator &al, float x) { + code.push_back(al, 0x43); + emit_f32(code, al, x); } -// function to emit call instruction -void emit_call(Vec &code, Allocator &al, uint32_t idx) { - code.push_back(al, 0x10); - emit_u32(code, al, idx); + +// function to emit f32.abs instruction +void emit_f32_abs(Vec &code, Allocator &al) { code.push_back(al, 0x8B); } + +// function to emit f32.neg instruction +void emit_f32_neg(Vec &code, Allocator &al) { code.push_back(al, 0x8C); } + +// function to emit f32.ceil instruction +void emit_f32_ceil(Vec &code, Allocator &al) { code.push_back(al, 0x8D); } + +// function to emit f32.floor instruction +void emit_f32_floor(Vec &code, Allocator &al) { code.push_back(al, 0x8E); } + +// function to emit f32.trunc instruction +void emit_f32_trunc(Vec &code, Allocator &al) { code.push_back(al, 0x8F); } + +// function to emit f32.nearest instruction +void emit_f32_nearest(Vec &code, Allocator &al) { code.push_back(al, 0x90); } + +// function to emit f32.sqrt instruction +void emit_f32_sqrt(Vec &code, Allocator &al) { code.push_back(al, 0x91); } + +// function to emit f32.add instruction +void emit_f32_add(Vec &code, Allocator &al) { code.push_back(al, 0x92); } + +// function to emit f32.sub instruction +void emit_f32_sub(Vec &code, Allocator &al) { code.push_back(al, 0x93); } + +// function to emit f32.mul instruction +void emit_f32_mul(Vec &code, Allocator &al) { code.push_back(al, 0x94); } + +// function to emit f32.div instruction +void emit_f32_div(Vec &code, Allocator &al) { code.push_back(al, 0x95); } + +// function to emit f32.min instruction +void emit_f32_min(Vec &code, Allocator &al) { code.push_back(al, 0x96); } + +// function to emit f32.max instruction +void emit_f32_max(Vec &code, Allocator &al) { code.push_back(al, 0x97); } + +// function to emit f32.copysign instruction +void emit_f32_copysign(Vec &code, Allocator &al) { code.push_back(al, 0x98); } + + +// function to emit a f64.const instruction +void emit_f64_const(Vec &code, Allocator &al, double x) { + code.push_back(al, 0x44); + emit_f64(code, al, x); } -void emit_export_fn(Vec &code, Allocator &al, const std::string& name, - uint32_t idx) { - std::vector name_bytes(name.size()); - std::memcpy(name_bytes.data(), name.data(), name.size()); - emit_u32(code, al, name_bytes.size()); - for(auto &byte:name_bytes) - emit_b8(code, al, byte); - emit_b8(code, al, 0x00); - emit_u32(code, al, idx); +// function to emit f64.abs instruction +void emit_f64_abs(Vec &code, Allocator &al) { code.push_back(al, 0x99); } + +// function to emit f64.neg instruction +void emit_f64_neg(Vec &code, Allocator &al) { code.push_back(al, 0x9A); } + +// function to emit f64.ceil instruction +void emit_f64_ceil(Vec &code, Allocator &al) { code.push_back(al, 0x9B); } + +// function to emit f64.floor instruction +void emit_f64_floor(Vec &code, Allocator &al) { code.push_back(al, 0x9C); } + +// function to emit f64.trunc instruction +void emit_f64_trunc(Vec &code, Allocator &al) { code.push_back(al, 0x9D); } + +// function to emit f64.nearest instruction +void emit_f64_nearest(Vec &code, Allocator &al) { code.push_back(al, 0x9E); } + +// function to emit f64.sqrt instruction +void emit_f64_sqrt(Vec &code, Allocator &al) { code.push_back(al, 0x9F); } + +// function to emit f64.add instruction +void emit_f64_add(Vec &code, Allocator &al) { code.push_back(al, 0xA0); } + +// function to emit f64.sub instruction +void emit_f64_sub(Vec &code, Allocator &al) { code.push_back(al, 0xA1); } + +// function to emit f64.mul instruction +void emit_f64_mul(Vec &code, Allocator &al) { code.push_back(al, 0xA2); } + +// function to emit f64.div instruction +void emit_f64_div(Vec &code, Allocator &al) { code.push_back(al, 0xA3); } + +// function to emit f64.min instruction +void emit_f64_min(Vec &code, Allocator &al) { code.push_back(al, 0xA4); } + +// function to emit f64.max instruction +void emit_f64_max(Vec &code, Allocator &al) { code.push_back(al, 0xA5); } + +// function to emit f64.copysign instruction +void emit_f64_copysign(Vec &code, Allocator &al) { code.push_back(al, 0xA6); } + + +// function to emit string +void emit_str_const(Vec &code, Allocator &al, uint32_t mem_idx, const std::string &text) { + emit_u32(code, al, 0U); // for active mode of memory with default mem_idx of 0 + emit_i32_const(code, al, (int32_t)mem_idx); // specifying memory location as instructions + emit_expr_end(code, al); // end instructions + emit_str(code, al, text); +} + + +void emit_unreachable(Vec &code, Allocator &al){ + code.push_back(al, 0x00); +} + +void save_js_glue(std::string filename){ + std::string js_glue = +R"(function define_imports(memory, outputBuffer, stdout_print) { + const printNum = (num) => outputBuffer.push(num.toString()); + const printStr = (startIdx, strSize) => outputBuffer.push( + new TextDecoder("utf8").decode(new Uint8Array(memory.buffer, startIdx, strSize))); + const flushBuffer = () => { + stdout_print(outputBuffer.join(" ") + "\n"); + outputBuffer.length = 0; + } + var imports = { + js: { + memory: memory, + /* functions */ + print_i32: printNum, + print_i64: printNum, + print_f32: printNum, + print_f64: printNum, + print_str: printStr, + flush_buf: flushBuffer, + }, + }; + return imports; +} + +async function run_wasm(bytes, imports) { + var res; + try { res = await WebAssembly.instantiate(bytes, imports); } + catch (e) { console.log(e); return 1 /* non-zero return value */; } + const { _lcompilers_main } = res.instance.exports; + try { _lcompilers_main() } + catch (e) { return 1; } + return 0; +} + +async function execute_code(bytes, stdout_print) { + var outputBuffer = []; + var memory = new WebAssembly.Memory({ initial: 10, maximum: 100 }); // initial 640Kb and max 6.4Mb + var imports = define_imports(memory, outputBuffer, stdout_print); + const exec_status = await run_wasm(bytes, imports); + return (exec_status ? outputBuffer[0] : 0); // the last element denotes the actual execution status +} + +const fs = require("fs"); +const wasmBuffer = fs.readFileSync(")" + filename + +R"("); +execute_code(wasmBuffer, (text) => process.stdout.write(text)).then().catch((e) => console.log(e)) +)"; + filename += ".js"; + std::ofstream out(filename); + out << js_glue; + out.close(); +} + +void save_bin(Vec &code, std::string filename){ + std::ofstream out(filename); + out.write((const char*) code.p, code.size()); + out.close(); + save_js_glue(filename); } } // namespace wasm diff --git a/src/libasr/codegen/wasm_to_wat.cpp b/src/libasr/codegen/wasm_to_wat.cpp new file mode 100644 index 0000000000..5115aca1de --- /dev/null +++ b/src/libasr/codegen/wasm_to_wat.cpp @@ -0,0 +1,306 @@ +#include + +#include +#include + +// #define WAT_DEBUG + +#ifdef WAT_DEBUG +#define DEBUG(s) std::cout << s << std::endl +#else +#define DEBUG(s) +#endif + +namespace LFortran { + +namespace wasm { + +void WASMDecoder::load_file(std::string filename) { + std::ifstream file(filename, std::ios::binary); + file.seekg(0, std::ios::end); + size_t size = file.tellg(); + file.seekg(0, std::ios::beg); + wasm_bytes.reserve(al, size); + file.read((char*)wasm_bytes.data(), size); + file.close(); +} + +void WASMDecoder::decode_type_section(uint32_t offset) { + // read type section contents + uint32_t no_of_func_types = read_u32(wasm_bytes, offset); + DEBUG("no_of_func_types: " + std::to_string(no_of_func_types)); + func_types.resize(al, no_of_func_types); + + for (uint32_t i = 0; i < no_of_func_types; i++) { + if (wasm_bytes[offset] != 0x60) { + throw LFortran::LFortranException("Invalid type section"); + } + offset++; + + // read result type 1 + uint32_t no_of_params = read_u32(wasm_bytes, offset); + func_types.p[i].param_types.resize(al, no_of_params); + + for (uint32_t j = 0; j < no_of_params; j++) { + func_types.p[i].param_types.p[j] = read_b8(wasm_bytes, offset); + } + + uint32_t no_of_results = read_u32(wasm_bytes, offset); + func_types.p[i].result_types.resize(al, no_of_results); + + for (uint32_t j = 0; j < no_of_results; j++) { + func_types.p[i].result_types.p[j] = read_b8(wasm_bytes, offset); + } + } +} + +void WASMDecoder::decode_imports_section(uint32_t offset) { + // read imports section contents + uint32_t no_of_imports = read_u32(wasm_bytes, offset); + DEBUG("no_of_imports: " + std::to_string(no_of_imports)); + imports.resize(al, no_of_imports); + + for (uint32_t i = 0; i < no_of_imports; i++) { + uint32_t mod_name_size = read_u32(wasm_bytes, offset); + imports.p[i].mod_name.resize(mod_name_size); // do not pass al to this resize as it is std::string.resize() + for (uint32_t j = 0; j < mod_name_size; j++) { + imports.p[i].mod_name[j] = read_b8(wasm_bytes, offset); + } + + uint32_t name_size = read_u32(wasm_bytes, offset); + imports.p[i].name.resize(name_size); // do not pass al to this resize as it is std::string.resize() + for (uint32_t j = 0; j < name_size; j++) { + imports.p[i].name[j] = read_b8(wasm_bytes, offset); + } + + imports.p[i].kind = read_b8(wasm_bytes, offset); + + switch (imports.p[i].kind) + { + case 0x00: { + imports.p[i].type_idx = read_u32(wasm_bytes, offset); + break; + } + case 0x02: { + uint8_t byte = read_b8(wasm_bytes, offset); + if(byte == 0x00){ + imports.p[i].mem_page_size_limits.first = read_u32(wasm_bytes, offset); + imports.p[i].mem_page_size_limits.second = imports.p[i].mem_page_size_limits.first; + } + else { + LFORTRAN_ASSERT(byte == 0x01); + imports.p[i].mem_page_size_limits.first = read_u32(wasm_bytes, offset); + imports.p[i].mem_page_size_limits.second = read_u32(wasm_bytes, offset); + } + break; + } + + default: { + std::cout << "Only importing functions and memory are currently supported" << std::endl; + LFORTRAN_ASSERT(false); + } + } + } +} + +void WASMDecoder::decode_function_section(uint32_t offset) { + // read function section contents + uint32_t no_of_indices = read_u32(wasm_bytes, offset); + DEBUG("no_of_indices: " + std::to_string(no_of_indices)); + type_indices.resize(al, no_of_indices); + + for (uint32_t i = 0; i < no_of_indices; i++) { + type_indices.p[i] = read_u32(wasm_bytes, offset); + } +} + +void WASMDecoder::decode_export_section(uint32_t offset) { + // read export section contents + uint32_t no_of_exports = read_u32(wasm_bytes, offset); + DEBUG("no_of_exports: " + std::to_string(no_of_exports)); + exports.resize(al, no_of_exports); + + for (uint32_t i = 0; i < no_of_exports; i++) { + uint32_t name_size = read_u32(wasm_bytes, offset); + exports.p[i].name.resize(name_size); // do not pass al to this resize as it is std::string.resize() + for (uint32_t j = 0; j < name_size; j++) { + exports.p[i].name[j] = read_b8(wasm_bytes, offset); + } + DEBUG("export name: " + exports.p[i].name); + exports.p[i].kind = read_b8(wasm_bytes, offset); + DEBUG("export kind: " + std::to_string(exports.p[i].kind)); + exports.p[i].index = read_u32(wasm_bytes, offset); + DEBUG("export index: " + std::to_string(exports.p[i].index)); + } +} + +void WASMDecoder::decode_code_section(uint32_t offset) { + // read code section contents + uint32_t no_of_codes = read_u32(wasm_bytes, offset); + DEBUG("no_of_codes: " + std::to_string(no_of_codes)); + codes.resize(al, no_of_codes); + + for (uint32_t i = 0; i < no_of_codes; i++) { + codes.p[i].size = read_u32(wasm_bytes, offset); + uint32_t code_start_offset = offset; + uint32_t no_of_locals = read_u32(wasm_bytes, offset); + DEBUG("no_of_locals: " + std::to_string(no_of_locals)); + codes.p[i].locals.resize(al, no_of_locals); + + DEBUG("Entering loop"); + for (uint32_t j = 0U; j < no_of_locals; j++) { + codes.p[i].locals.p[j].count = read_u32(wasm_bytes, offset); + DEBUG("count: " + std::to_string(codes.p[i].locals.p[j].count)); + codes.p[i].locals.p[j].type = read_b8(wasm_bytes, offset); + DEBUG("type: " + std::to_string(codes.p[i].locals.p[j].type)); + } + DEBUG("Exiting loop"); + + codes.p[i].insts_start_index = offset; + + // skip offset to directly the end of instructions + offset = code_start_offset + codes.p[i].size; + } +} + +void WASMDecoder::decode_data_section(uint32_t offset) { + // read code section contents + uint32_t no_of_data_segments = read_u32(wasm_bytes, offset); + DEBUG("no_of_data_segments: " + std::to_string(no_of_data_segments)); + data_segments.resize(al, no_of_data_segments); + + for (uint32_t i = 0; i < no_of_data_segments; i++) { + uint32_t num = read_u32(wasm_bytes, offset); + if(num != 0){ + throw LFortran::LFortranException("Only active default memory (index = 0) is currently supported"); + } + + { + WASM_INSTS_VISITOR::WATVisitor v = WASM_INSTS_VISITOR::WATVisitor(wasm_bytes, offset, "", ""); + v.decode_instructions(); + data_segments.p[i].insts = v.src; + offset = v.offset; + } + + uint32_t text_size = read_u32(wasm_bytes, offset); + data_segments.p[i].text.resize(text_size); // do not pass al to this resize as it is std::string.resize() + for (uint32_t j = 0; j < text_size; j++) { + data_segments.p[i].text[j] = read_b8(wasm_bytes, offset); + } + } +} + +void WASMDecoder::decode_wasm() { + // first 8 bytes are magic number and wasm version number + // currently, in this first version, we are skipping them + uint32_t index = 8U; + + while (index < wasm_bytes.size()) { + uint32_t section_id = read_u32(wasm_bytes, index); + uint32_t section_size = read_u32(wasm_bytes, index); + switch (section_id) { + case 1U: + decode_type_section(index); + // exit(0); + break; + case 2U: + decode_imports_section(index); + // exit(0); + break; + case 3U: + decode_function_section(index); + // exit(0); + break; + case 7U: + decode_export_section(index); + // exit(0); + break; + case 10U: + decode_code_section(index); + // exit(0) + break; + case 11U: + decode_data_section(index); + // exit(0) + break; + default: + std::cout << "Unknown section id: " << section_id << std::endl; + break; + } + index += section_size; + } + + LFORTRAN_ASSERT(index == wasm_bytes.size()); + LFORTRAN_ASSERT(type_indices.size() == codes.size()); +} + +std::string WASMDecoder::get_wat() { + std::string result = "(module"; + std::string indent = "\n "; + for(uint32_t i = 0U; i < func_types.size(); i++){ + result += indent + "(type (;" + std::to_string(i)+ ";) (func (param"; + for (uint32_t j = 0; j < func_types[i].param_types.size(); j++) { + result += " " + var_type_to_string[func_types[i].param_types.p[j]]; + } + result += ") (result"; + for (uint32_t j = 0; j < func_types[i].result_types.size(); j++) { + result += " " + var_type_to_string[func_types[i].result_types.p[j]]; + } + result += ")))"; + } + + for(uint32_t i = 0; i < imports.size(); i++){ + result += indent + "(import \"" + imports[i].mod_name + "\" \"" + imports[i].name + "\" "; + if(imports[i].kind == 0x00){ + result += "(func (;" + std::to_string(i) + ";) (type " + std::to_string(imports[i].type_idx) + ")))"; + } + else if(imports[i].kind == 0x02){ + result += "(memory (;0;) " + std::to_string(imports[i].mem_page_size_limits.first) + "))"; + } + } + + for (uint32_t i = 0; i < type_indices.size(); i++) { + uint32_t func_index = type_indices.p[i]; + result += indent + "(func $" + std::to_string(func_index); + result += " (type " + std::to_string(func_index) + ") (param"; + for (uint32_t j = 0; j < func_types[func_index].param_types.size(); j++) { + result += " " + var_type_to_string[func_types[func_index].param_types.p[j]]; + } + result += ") (result"; + for (uint32_t j = 0; j < func_types[func_index].result_types.size(); j++) { + result += " " + var_type_to_string[func_types[func_index].result_types.p[j]]; + } + result += ")"; + result += indent + " (local"; + for (uint32_t j = 0; j < codes.p[i].locals.size(); j++) { + for (uint32_t k = 0; k < codes.p[i].locals.p[j].count; k++) { + result += " " + var_type_to_string[codes.p[i].locals.p[j].type]; + } + } + result += ")"; + + { + WASM_INSTS_VISITOR::WATVisitor v = WASM_INSTS_VISITOR::WATVisitor(wasm_bytes, codes.p[i].insts_start_index, "", indent + " "); + v.decode_instructions(); + result += v.src; + } + + result += indent + ")"; + } + + for (uint32_t i = 0; i < exports.size(); i++) { + result += indent + "(export \"" + exports.p[i].name + "\" (" + kind_to_string[exports.p[i].kind] + " $" + std::to_string(exports.p[i].index) + "))"; + } + + for(uint32_t i = 0; i < data_segments.size(); i++){ + result += indent + "(data (;" + std::to_string(i) + ";) (" + data_segments[i].insts + ") \"" + data_segments[i].text + "\")"; + } + + result += "\n)\n"; + + return result; +} + +} // namespace wasm + +} // namespace LFortran diff --git a/src/libasr/codegen/wasm_to_wat.h b/src/libasr/codegen/wasm_to_wat.h new file mode 100644 index 0000000000..b8551c5485 --- /dev/null +++ b/src/libasr/codegen/wasm_to_wat.h @@ -0,0 +1,104 @@ +#ifndef LFORTRAN_WASM_TO_WAT_H +#define LFORTRAN_WASM_TO_WAT_H + +#include + +namespace LFortran { + +namespace WASM_INSTS_VISITOR { + +class WATVisitor : public BaseWASMVisitor { + public: + std::string src, indent; + + WATVisitor(Vec &code, uint32_t offset, std::string src, std::string indent) : BaseWASMVisitor(code, offset), src(src), indent(indent) {} + + void visit_Unreachable() { src += indent + "unreachable"; } + void visit_Return() { src += indent + "return"; } + void visit_Call(uint32_t func_index) { src += indent + "call " + std::to_string(func_index); } + void visit_LocalGet(uint32_t localidx) { src += indent + "local.get " + std::to_string(localidx); } + void visit_LocalSet(uint32_t localidx) { src += indent + "local.set " + std::to_string(localidx); } + void visit_EmtpyBlockType() {} + void visit_If() { + src += indent + "if"; + { + WATVisitor v = WATVisitor(code, offset, "", indent + " "); + v.decode_instructions(); + src += v.src; + offset = v.offset; + } + src += indent + "end"; + } + void visit_Else() { src += indent + "\b\b\b\b" + "else"; } + + void visit_I32Const(int32_t value) { src += indent + "i32.const " + std::to_string(value); } + void visit_I32Add() { src += indent + "i32.add"; } + void visit_I32Sub() { src += indent + "i32.sub"; } + void visit_I32Mul() { src += indent + "i32.mul"; } + void visit_I32DivS() { src += indent + "i32.div_s"; } + + void visit_I64Const(int64_t value) { src += indent + "i64.const " + std::to_string(value); } + void visit_I64Add() { src += indent + "i64.add"; } + void visit_I64Sub() { src += indent + "i64.sub"; } + void visit_I64Mul() { src += indent + "i64.mul"; } + void visit_I64DivS() { src += indent + "i64.div_s"; } + + void visit_F32Const(float value) { src += indent + "f32.const " + std::to_string(value); } + void visit_F32Add() { src += indent + "f32.add"; } + void visit_F32Sub() { src += indent + "f32.sub"; } + void visit_F32Mul() { src += indent + "f32.mul"; } + void visit_F32DivS() { src += indent + "f32.div_s"; } + + void visit_F64Const(double value) { src += indent + "f64.const " + std::to_string(value); } + void visit_F64Add() { src += indent + "f64.add"; } + void visit_F64Sub() { src += indent + "f64.sub"; } + void visit_F64Mul() { src += indent + "f64.mul"; } + void visit_F64DivS() { src += indent + "f64.div_s"; } +}; + +} // namespace WASM_INSTS_VISITOR + +namespace wasm { + +class WASMDecoder { + public: + std::unordered_map var_type_to_string; + std::unordered_map kind_to_string; + + Allocator &al; + Vec wasm_bytes; + + Vec func_types; + Vec imports; + Vec type_indices; + Vec exports; + Vec codes; + Vec data_segments; + + WASMDecoder(Allocator &al) : al(al) { + var_type_to_string = {{0x7F, "i32"}, {0x7E, "i64"}, {0x7D, "f32"}, {0x7C, "f64"}}; + kind_to_string = {{0x00, "func"}, {0x01, "table"}, {0x02, "mem"}, {0x03, "global"}}; + + // wasm_bytes.reserve(al, 1024 * 128); + // func_types.reserve(al, 1024 * 128); + // type_indices.reserve(al, 1024 * 128); + // exports.reserve(al, 1024 * 128); + // codes.reserve(al, 1024 * 128); + } + + void load_file(std::string filename); + void decode_type_section(uint32_t offset); + void decode_imports_section(uint32_t offset); + void decode_function_section(uint32_t offset); + void decode_export_section(uint32_t offset); + void decode_code_section(uint32_t offset); + void decode_data_section(uint32_t offset); + void decode_wasm(); + std::string get_wat(); +}; + +} // namespace wasm + +} // namespace LFortran + +#endif // LFORTRAN_WASM_TO_WAT_H diff --git a/src/libasr/codegen/wasm_utils.cpp b/src/libasr/codegen/wasm_utils.cpp new file mode 100644 index 0000000000..dce146d16d --- /dev/null +++ b/src/libasr/codegen/wasm_utils.cpp @@ -0,0 +1,117 @@ +#include + +namespace LFortran { + +namespace wasm { + +uint32_t decode_leb128_u32(Vec &code, uint32_t &offset) { + uint32_t result = 0U; + uint32_t shift = 0U; + while (true) { + uint8_t byte = code.p[offset++]; + uint32_t slice = byte & 0x7f; + result |= slice << shift; + if ((byte & 0x80) == 0) { + return result; + } + shift += 7; + } +} + +int32_t decode_leb128_i32(Vec &code, uint32_t &offset) { + int32_t result = 0; + uint32_t shift = 0U; + uint8_t byte; + + do { + byte = code.p[offset++]; + uint32_t slice = byte & 0x7f; + result |= slice << shift; + shift += 7; + } while (byte & 0x80); + + // Sign extend negative numbers if needed. + if ((shift < 32U) && (byte & 0x40)) { + result |= (-1U << shift); + } + + return result; +} + +int64_t decode_leb128_i64(Vec &code, uint32_t &offset) { + int64_t result = 0; + uint32_t shift = 0U; + uint8_t byte; + + do { + byte = code.p[offset++]; + uint64_t slice = byte & 0x7f; + result |= slice << shift; + shift += 7; + } while (byte & 0x80); + + // Sign extend negative numbers if needed. + if ((shift < 64U) && (byte & 0x40)) { + result |= (-1ULL << shift); + } + + return result; +} + +float decode_ieee754_f32(Vec &code, uint32_t &offset) { + float value = 0.0; + std::memcpy(&value, &code.p[offset], sizeof(value)); + offset += sizeof(value); + return value; +} + +double decode_ieee754_f64(Vec &code, uint32_t &offset) { + double value = 0.0; + std::memcpy(&value, &code.p[offset], sizeof(value)); + offset += sizeof(value); + return value; +} + +uint8_t read_b8(Vec &code, uint32_t &offset) { + LFORTRAN_ASSERT(offset < code.size()); + return code.p[offset++]; +} + +float read_f32(Vec & code, uint32_t & offset) { + LFORTRAN_ASSERT(offset + sizeof(float) <= code.size()); + return decode_ieee754_f32(code, offset); +} + +double read_f64(Vec & code, uint32_t & offset) { + LFORTRAN_ASSERT(offset + sizeof(double) <= code.size()); + return decode_ieee754_f64(code, offset); +} + +uint32_t read_u32(Vec &code, uint32_t &offset) { return decode_leb128_u32(code, offset); } + +int32_t read_i32(Vec &code, uint32_t &offset) { return decode_leb128_i32(code, offset); } + +int64_t read_i64(Vec &code, uint32_t &offset) { return decode_leb128_i64(code, offset); } + +void hexdump(void *ptr, int buflen) { + unsigned char *buf = (unsigned char *)ptr; + int i, j; + for (i = 0; i < buflen; i += 16) { + printf("%06x: ", i); + for (j = 0; j < 16; j++) { + if (i + j < buflen) + printf("%02x ", buf[i + j]); + else + printf(" "); + } + printf(" "); + for (j = 0; j < 16; j++) { + if (i + j < buflen) printf("%c", isprint(buf[i + j]) ? buf[i + j] : '.'); + } + printf("\n"); + } +} + +} // namespace wasm + +} // namespace LFortran diff --git a/src/libasr/codegen/wasm_utils.h b/src/libasr/codegen/wasm_utils.h new file mode 100644 index 0000000000..ad005ec4f3 --- /dev/null +++ b/src/libasr/codegen/wasm_utils.h @@ -0,0 +1,73 @@ +#ifndef LFORTRAN_WASM_UTILS_H +#define LFORTRAN_WASM_UTILS_H + +#include +#include + +#include +#include + +namespace LFortran { + +namespace wasm { + +struct FuncType { + Vec param_types; + Vec result_types; +}; + +struct Export { + std::string name; + uint8_t kind; + uint32_t index; +}; + +struct Local { + uint32_t count; + uint8_t type; +}; + +struct Code { + int size; + Vec locals; + uint32_t insts_start_index; +}; + +struct Import { + std::string mod_name; + std::string name; + uint8_t kind; + union { + uint32_t type_idx; + std::pair mem_page_size_limits; + }; +}; + +struct Data { + std::string insts; + std::string text; +}; + +uint32_t decode_leb128_u32(Vec &code, uint32_t &offset); +int32_t decode_leb128_i32(Vec &code, uint32_t &offset); +int64_t decode_leb128_i64(Vec &code, uint32_t &offset); + +uint8_t read_b8(Vec &code, uint32_t &offset); + +float read_f32(Vec & code, uint32_t & offset); + +double read_f64(Vec & code, uint32_t & offset); + +uint32_t read_u32(Vec &code, uint32_t &offset); + +int32_t read_i32(Vec &code, uint32_t &offset); + +int64_t read_i64(Vec &code, uint32_t &offset); + +void hexdump(void *ptr, int buflen); + +} // namespace wasm + +} // namespace LFortran + +#endif // LFORTRAN_WASM_UTILS_H diff --git a/src/libasr/config.h.in b/src/libasr/config.h.in index 0de5d0a161..cc0e058a02 100644 --- a/src/libasr/config.h.in +++ b/src/libasr/config.h.in @@ -10,6 +10,9 @@ /* Define if LLVM is enabled */ #cmakedefine HAVE_LFORTRAN_LLVM +/* Define if RAPIDJSON is found */ +#cmakedefine HAVE_LFORTRAN_RAPIDJSON + /* Define if stacktrace is enabled */ #cmakedefine HAVE_LFORTRAN_STACKTRACE #cmakedefine HAVE_LFORTRAN_BFD diff --git a/src/libasr/containers.h b/src/libasr/containers.h index 8fee330285..c9509fdce2 100644 --- a/src/libasr/containers.h +++ b/src/libasr/containers.h @@ -81,6 +81,11 @@ struct Vec { return n; } + void resize(Allocator &al, size_t max){ + reserve(al, max); + n = max; + } + size_t capacity() const { return max; } @@ -175,6 +180,19 @@ struct Str { static_assert(std::is_standard_layout::value); static_assert(std::is_trivial::value); +template +std::string string_format(const std::string& format, Args && ...args) +{ + auto size = std::snprintf(nullptr, 0, format.c_str(), std::forward(args)...); + std::string output(size, '\0'); + std::sprintf(&output[0], format.c_str(), std::forward(args)...); + return output; +} + +static inline std::string double_to_scientific(double x) { + return string_format("%25.17e", x); +} + } // namespace LFortran diff --git a/src/libasr/lsp/JSONRPC2Connection.cpp b/src/libasr/lsp/JSONRPC2Connection.cpp new file mode 100644 index 0000000000..39dce5ab23 --- /dev/null +++ b/src/libasr/lsp/JSONRPC2Connection.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include "JSONRPC2Connection.hpp" + +class EOFError : public std::exception { + public: + std::string error_msg () { + return "Reached end of file..."; + } +}; + +class JSONRPC2ProtocolError : public std::exception { + public: + std::string msg; + JSONRPC2ProtocolError(std::string msg) { + this->msg = msg; + } + std::string error_msg () { + return msg; + } +}; + +int JSONRPC2Connection::_read_header_content_length(std::string line) { + if (line.size() < 2 || (line[line.size() - 1] == '\n' && line[line.size() - 2] == '\r')) { + throw JSONRPC2ProtocolError("Line endings must be \r\n"); + } + if (line.substr(0, 16) == "Content-Length: ") { + // Example -> Content-length: 100 + int length = std::stoi(line.substr(16, line.size() - 16)); + return length; + } + return -1; +} + +std::string JSONRPC2Connection::read(int length) { + std::string body = ""; + int exit_seq = 0; + int idx = 0; + while (idx < length) { + int c = getchar(); + if (c == EOF) break; + if (idx == 0 && c != 123) continue; + if (exit_seq == 0 && c == '\r') { + ++exit_seq; + } else if (exit_seq == 0 && c == '\n'){ + break; + } else { + body += c; + idx++; + } + } + return body; +} + +rapidjson::Document JSONRPC2Connection::_json_parse(std::string body) { + rapidjson::Document doc; + doc.Parse(body.c_str()); + return doc; +} + +rapidjson::Document JSONRPC2Connection::_receive() { + std::string line; + std::getline(std::cin, line); + if (line.size() == 0) { + throw(EOFError()); + } + int length = this->_read_header_content_length(line); + std::string body = this->read(length); + return _json_parse(body); +} + +void JSONRPC2Connection::_send(rapidjson::Document& body) { + std::string body_str = json_to_string(body); + int content_length = body_str.size(); + std::string response = "Content-Length: " + std::to_string(content_length) + "\r\n" + + "Content-Type: application/vscode-jsonrpc; charset=utf8\r\n\r\n"; + std::cout << response; + std::cout << body_str; +} + +void JSONRPC2Connection::write_message(int rid, rapidjson::Document& response) { + rapidjson::Document body(rapidjson::kObjectType); + rapidjson::Document::AllocatorType &allocator = body.GetAllocator(); + body.SetObject(); + body.AddMember("jsonrpc", rapidjson::Value().SetString("2.0", allocator), allocator); + body.AddMember("id", rapidjson::Value().SetInt(rid), allocator); + body.AddMember("result", response, allocator); + this->_send(body); +} + +rapidjson::Document JSONRPC2Connection::read_message() { + rapidjson::Document res_empty; + try { + rapidjson::Document res = this->_receive(); + return res; + } catch (EOFError) { + return res_empty; + } + return res_empty; +} + +void JSONRPC2Connection::send_notification(std::string method, rapidjson::Document ¶ms) { + rapidjson::Document body(rapidjson::kObjectType); + rapidjson::Document::AllocatorType &allocator = body.GetAllocator(); + body.SetObject(); + body.AddMember("jsonrpc", rapidjson::Value().SetString("2.0", allocator), allocator); + body.AddMember("method", rapidjson::Value().SetString(method.c_str(), allocator), allocator); + body.AddMember("params", params, allocator); + rapidjson::StringBuffer buffer; + buffer.Clear(); + rapidjson::Writer writer(buffer); + body.Accept(writer); + std::string str_body(buffer.GetString()); + this->_send(body); +} + +std::string JSONRPC2Connection::json_to_string(rapidjson::Document &json) { + rapidjson::StringBuffer strbuf; + strbuf.Clear(); + rapidjson::Writer writer(strbuf); + json.Accept(writer); + return strbuf.GetString(); +} \ No newline at end of file diff --git a/src/libasr/lsp/JSONRPC2Connection.hpp b/src/libasr/lsp/JSONRPC2Connection.hpp new file mode 100644 index 0000000000..167b3c0016 --- /dev/null +++ b/src/libasr/lsp/JSONRPC2Connection.hpp @@ -0,0 +1,22 @@ +#ifndef JSONRPC2_CONNECTION_HPP +#define JSONRPC2_CONNECTION_HPP + + +#include +#include + +class JSONRPC2Connection { + public: + JSONRPC2Connection() {} + rapidjson::Document read_message(); + int _read_header_content_length(std::string); + std::string read(int); + rapidjson::Document _receive(); + rapidjson::Document _json_parse(std::string); + void _send(rapidjson::Document&); + void write_message(int, rapidjson::Document&); + void send_notification(std::string, rapidjson::Document&); + std::string json_to_string(rapidjson::Document&); +}; + +#endif \ No newline at end of file diff --git a/src/libasr/lsp/LPythonServer.cpp b/src/libasr/lsp/LPythonServer.cpp new file mode 100644 index 0000000000..05e9004e53 --- /dev/null +++ b/src/libasr/lsp/LPythonServer.cpp @@ -0,0 +1,170 @@ +#include +#include + +#include +#include + +#include "LPythonServer.hpp" +#include "JSONRPC2Connection.hpp" +struct handle_functions +{ + JSONRPC2Connection* conn; + + handle_functions() { + this->conn = new JSONRPC2Connection(); + } + + rapidjson::Document serve_initialize(rapidjson::Document &/*request*/) { + rapidjson::Document capabilities(rapidjson::kObjectType); + rapidjson::Document::AllocatorType &allocator = capabilities.GetAllocator(); + capabilities.SetObject(); + rapidjson::Document server_capabilities(rapidjson::kObjectType); + server_capabilities.SetObject(); + server_capabilities.AddMember("textDocumentSync", rapidjson::Value().SetInt(2), allocator); + server_capabilities.AddMember("documentSymbolProvider", rapidjson::Value().SetBool(true), allocator); + capabilities.AddMember("capabilities", server_capabilities, allocator); + return capabilities; + } + + void serve_onSave(rapidjson::Document &request) { + std::string uri = request["params"]["textDocument"]["uri"].GetString(); + int start_line = 2; + int start_column = 0; + int end_line = 3; + int end_column = 10; + std::string msg = "lpyth"; + + rapidjson::Document range_obj(rapidjson::kObjectType); + rapidjson::Document::AllocatorType &allocator = range_obj.GetAllocator(); + range_obj.SetObject(); + + rapidjson::Document start_detail(rapidjson::kObjectType); + start_detail.SetObject(); + start_detail.AddMember("line", rapidjson::Value().SetInt(start_line), allocator); + start_detail.AddMember("character", rapidjson::Value().SetInt(start_column), allocator); + range_obj.AddMember("start", start_detail, allocator); + + rapidjson::Document end_detail(rapidjson::kObjectType); + end_detail.SetObject(); + end_detail.AddMember("line", rapidjson::Value().SetInt(end_line), allocator); + end_detail.AddMember("character", rapidjson::Value().SetInt(end_column), allocator); + range_obj.AddMember("end", end_detail, allocator); + + rapidjson::Document diag_results(rapidjson::kArrayType); + diag_results.SetArray(); + + rapidjson::Document diag_capture(rapidjson::kObjectType); + diag_capture.AddMember("source", rapidjson::Value().SetString("lsp", allocator), allocator); + diag_capture.AddMember("range", range_obj, allocator); + diag_capture.AddMember("message", rapidjson::Value().SetString(msg.c_str(), allocator), allocator); + diag_capture.AddMember("severity", rapidjson::Value().SetInt(2), allocator); + diag_results.PushBack(diag_capture, allocator); + + rapidjson::Document message_send(rapidjson::kObjectType); + message_send.SetObject(); + message_send.AddMember("uri", rapidjson::Value().SetString(uri.c_str(), allocator), allocator); + message_send.AddMember("diagnostics", diag_results, allocator); + + this->conn->send_notification( + "textDocument/publishDiagnostics", + message_send + ); + } + + void serve_document_symbol(rapidjson::Document &request, JSONRPC2Connection& obj, int rid) { + std::string uri = request["params"]["textDocument"]["uri"].GetString(); + + int start_character = 0; + int start_line = 1; + int end_character = 10; + int end_line = 10; + + rapidjson::Document range_object(rapidjson::kObjectType); + rapidjson::Document::AllocatorType &allocator = range_object.GetAllocator(); + range_object.SetObject(); + + rapidjson::Document start_detail(rapidjson::kObjectType); + start_detail.SetObject(); + start_detail.AddMember("character", rapidjson::Value().SetInt(start_character), allocator); + start_detail.AddMember("line", rapidjson::Value().SetInt(start_line), allocator); + range_object.AddMember("start", start_detail, allocator); + + rapidjson::Document end_detail(rapidjson::kObjectType); + end_detail.SetObject(); + end_detail.AddMember("character", rapidjson::Value().SetInt(end_character), allocator); + end_detail.AddMember("line", rapidjson::Value().SetInt(end_line), allocator); + range_object.AddMember("end", end_detail, allocator); + + rapidjson::Document location_object(rapidjson::kObjectType); + location_object.SetObject(); + location_object.AddMember("range", range_object, allocator); + location_object.AddMember("uri", rapidjson::Value().SetString(uri.c_str(), allocator), allocator); + + rapidjson::Document test_output(rapidjson::kArrayType); + test_output.SetArray(); + + rapidjson::Document test_capture(rapidjson::kObjectType); + test_capture.SetObject(); + test_capture.AddMember("kind", rapidjson::Value().SetInt(12), allocator); + test_capture.AddMember("location", location_object, allocator); + test_capture.AddMember("name", rapidjson::Value().SetString("lsp_symbols", allocator), allocator); + test_output.PushBack(test_capture, test_output.GetAllocator()); + + obj.write_message(rid, test_output); + } +}; + +typedef rapidjson::Document (handle_functions::*json_handle)(rapidjson::Document &); +typedef void (handle_functions::*void_handle)(rapidjson::Document &); +typedef void (handle_functions::*void_and_json_handle)(rapidjson::Document &, JSONRPC2Connection &, int rid); + +typedef std::map json_mapfun; +typedef std::map void_mapfun; +typedef std::map void_json_mapfun; + +void LPythonServer::handle(rapidjson::Document &request) { + json_mapfun json_handler; + void_mapfun void_handler; + void_json_mapfun json_void_handler; + + json_handler["initialize"] = &handle_functions::serve_initialize; + json_void_handler["textDocument/documentSymbol"] = &handle_functions::serve_document_symbol; + void_handler["textDocument/didSave"] = &handle_functions::serve_onSave; + + std::string request_method = request["method"].GetString(); + + if (request.HasMember("id")) { + json_mapfun::iterator x = json_handler.find(request_method); + void_json_mapfun::iterator y = json_void_handler.find(request_method); + + if (y != json_void_handler.end()) { + handle_functions h; + (h.*(y->second))(request, *this->conn, request["id"].GetInt()); + } else if (x != json_handler.end()) { + handle_functions h; + rapidjson::Document resp; + resp = (h.*(x->second))(request); + rapidjson::StringBuffer buffer; + buffer.Clear(); + rapidjson::Writer writer(buffer); + resp.Accept(writer); + std::string resp_str( buffer.GetString() ); + int rid = request["id"].GetInt(); + this->conn->write_message(rid, resp); + } + } + else { + void_mapfun::iterator x = void_handler.find(request_method); + if (x != void_handler.end()) { + handle_functions h; + (h.*(x->second))(request); + } + } +} + +void LPythonServer::run(std::string /*path*/) { + while (this->running) { + rapidjson::Document request = this->conn->read_message(); + this->handle(request); + } +} diff --git a/src/libasr/lsp/LPythonServer.hpp b/src/libasr/lsp/LPythonServer.hpp new file mode 100644 index 0000000000..a5cc242f16 --- /dev/null +++ b/src/libasr/lsp/LPythonServer.hpp @@ -0,0 +1,21 @@ +#ifndef LPYTHON_SERVER_HPP +#define LPYTHON_SERVER_HPP + +#include +#include + +#include "JSONRPC2Connection.hpp" + +class LPythonServer { + public: + bool running = false; + JSONRPC2Connection* conn; + LPythonServer() { + this->running = true; + this->conn = new JSONRPC2Connection(); + } + void run(std::string); + void handle(rapidjson::Document &); +}; + +#endif \ No newline at end of file diff --git a/src/libasr/pass/arr_slice.cpp b/src/libasr/pass/arr_slice.cpp index c58ccac9e0..2df811333d 100644 --- a/src/libasr/pass/arr_slice.cpp +++ b/src/libasr/pass/arr_slice.cpp @@ -33,7 +33,6 @@ The function `pass_replace_arr_slice` transforms the ASR tree in-place. class ArrSliceVisitor : public PassUtils::PassVisitor { private: - ASR::TranslationUnit_t &unit; ASR::expr_t* slice_var; bool create_slice_var; @@ -43,15 +42,14 @@ class ArrSliceVisitor : public PassUtils::PassVisitor std::string rl_path; public: - ArrSliceVisitor(Allocator &al, ASR::TranslationUnit_t &unit_, - const std::string &rl_path) : PassVisitor(al, nullptr), unit(unit_), + ArrSliceVisitor(Allocator &al, const std::string &rl_path) : PassVisitor(al, nullptr), slice_var(nullptr), create_slice_var(false), slice_counter(0), rl_path(rl_path) { pass_result.reserve(al, 1); } - ASR::ttype_t* get_array_from_slice(const ASR::ArrayRef_t& x, ASR::expr_t* arr_var) { + ASR::ttype_t* get_array_from_slice(const ASR::ArraySection_t& x, ASR::expr_t* arr_var) { Vec m_dims; m_dims.reserve(al, x.n_args); ASR::ttype_t* int32_type = LFortran::ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, 4, nullptr, 0)); @@ -60,15 +58,13 @@ class ArrSliceVisitor : public PassUtils::PassVisitor if( x.m_args[i].m_step != nullptr ) { ASR::expr_t *start = nullptr, *end = nullptr, *step = nullptr; if( x.m_args[i].m_left == nullptr ) { - start = PassUtils::get_bound(arr_var, i + 1, "lbound", - al, unit, rl_path, current_scope); + start = PassUtils::get_bound(arr_var, i + 1, "lbound", al); } else { start = x.m_args[i].m_left; } if( x.m_args[i].m_right == nullptr ) { - end = PassUtils::get_bound(arr_var, i + 1, "ubound", - al, unit, rl_path, current_scope); + end = PassUtils::get_bound(arr_var, i + 1, "ubound", al); } else { end = x.m_args[i].m_right; } @@ -83,18 +79,12 @@ class ArrSliceVisitor : public PassUtils::PassVisitor end = PassUtils::to_int32(end, int32_type, al); step = PassUtils::to_int32(step, int32_type, al); - ASR::expr_t* gap = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, x.base.base.loc, - end, ASR::binopType::Sub, start, - int32_type, nullptr, nullptr)); - // ASR::expr_t* slice_size = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, x.base.base.loc, - // gap, ASR::binopType::Add, const_1, - // int64_type, nullptr)); - ASR::expr_t* slice_size = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, x.base.base.loc, - gap, ASR::binopType::Div, step, - int32_type, nullptr, nullptr)); - ASR::expr_t* actual_size = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, x.base.base.loc, - slice_size, ASR::binopType::Add, const_1, - int32_type, nullptr, nullptr)); + ASR::expr_t* gap = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, x.base.base.loc, + end, ASR::binopType::Sub, start, int32_type, nullptr)); + ASR::expr_t* slice_size = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, x.base.base.loc, + gap, ASR::binopType::Div, step, int32_type, nullptr)); + ASR::expr_t* actual_size = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, x.base.base.loc, + slice_size, ASR::binopType::Add, const_1, int32_type, nullptr)); ASR::dimension_t curr_dim; curr_dim.loc = x.base.base.loc; curr_dim.m_start = const_1; @@ -153,9 +143,9 @@ class ArrSliceVisitor : public PassUtils::PassVisitor return new_type; } - void visit_ArrayRef(const ASR::ArrayRef_t& x) { - if( PassUtils::is_slice_present(x) && create_slice_var ) { - ASR::expr_t* x_arr_var = LFortran::ASRUtils::EXPR(ASR::make_Var_t(al, x.base.base.loc, x.m_v)); + void visit_ArraySection(const ASR::ArraySection_t& x) { + if( create_slice_var ) { + ASR::expr_t* x_arr_var = x.m_v; Str new_name_str; new_name_str.from_str(al, "~" + std::to_string(slice_counter) + "_slice"); slice_counter += 1; @@ -178,12 +168,12 @@ class ArrSliceVisitor : public PassUtils::PassVisitor head.m_v = idx_vars_value[i]; if( x.m_args[i].m_step != nullptr ) { if( x.m_args[i].m_left == nullptr ) { - head.m_start = PassUtils::get_bound(x_arr_var, i + 1, "lbound", al, unit, rl_path, current_scope); + head.m_start = PassUtils::get_bound(x_arr_var, i + 1, "lbound", al); } else { head.m_start = x.m_args[i].m_left; } if( x.m_args[i].m_right == nullptr ) { - head.m_end = PassUtils::get_bound(x_arr_var, i + 1, "ubound", al, unit, rl_path, current_scope); + head.m_end = PassUtils::get_bound(x_arr_var, i + 1, "ubound", al); } else { head.m_end = x.m_args[i].m_right; } @@ -197,7 +187,7 @@ class ArrSliceVisitor : public PassUtils::PassVisitor doloop_body.reserve(al, 1); if( doloop == nullptr ) { ASR::expr_t* target_ref = PassUtils::create_array_ref(slice_sym, idx_vars_target, al, x.base.base.loc, x.m_type); - ASR::expr_t* value_ref = PassUtils::create_array_ref(x.m_v, idx_vars_value, al, x.base.base.loc, x.m_type); + ASR::expr_t* value_ref = PassUtils::create_array_ref(x.m_v, idx_vars_value, al); ASR::stmt_t* assign_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, x.base.base.loc, target_ref, value_ref, nullptr)); doloop_body.push_back(al, assign_stmt); } else { @@ -205,7 +195,7 @@ class ArrSliceVisitor : public PassUtils::PassVisitor doloop_body.push_back(al, set_to_one); doloop_body.push_back(al, doloop); } - ASR::expr_t* inc_expr = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, x.base.base.loc, idx_vars_target[i], ASR::binopType::Add, const_1, int32_type, nullptr, nullptr)); + ASR::expr_t* inc_expr = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, x.base.base.loc, idx_vars_target[i], ASR::binopType::Add, const_1, int32_type, nullptr)); ASR::stmt_t* assign_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, x.base.base.loc, idx_vars_target[i], inc_expr, nullptr)); doloop_body.push_back(al, assign_stmt); doloop = LFortran::ASRUtils::STMT(ASR::make_DoLoop_t(al, x.base.base.loc, head, doloop_body.p, doloop_body.size())); @@ -217,6 +207,10 @@ class ArrSliceVisitor : public PassUtils::PassVisitor } void visit_Assignment(const ASR::Assignment_t& x) { + if( ASR::is_a(*ASRUtils::expr_type(x.m_target)) && + ASR::is_a(*x.m_value) ) { + return ; + } this->visit_expr(*x.m_value); // If any slicing happened then do loop must have been created // So, the current assignment should be inserted into pass_result @@ -226,8 +220,22 @@ class ArrSliceVisitor : public PassUtils::PassVisitor } } - void visit_BinOp(const ASR::BinOp_t& x) { - ASR::BinOp_t& xx = const_cast(x); + void visit_IntegerBinOp(const ASR::IntegerBinOp_t& x) { + handle_BinOp(x); + } + void visit_RealBinOp(const ASR::RealBinOp_t& x) { + handle_BinOp(x); + } + void visit_ComplexBinOp(const ASR::ComplexBinOp_t& x) { + handle_BinOp(x); + } + void visit_LogicalBinOp(const ASR::LogicalBinOp_t& x) { + handle_BinOp(x); + } + + template + void handle_BinOp(const T& x) { + T& xx = const_cast(x); create_slice_var = true; slice_var = nullptr; this->visit_expr(*x.m_left); @@ -265,7 +273,7 @@ class ArrSliceVisitor : public PassUtils::PassVisitor void pass_replace_arr_slice(Allocator &al, ASR::TranslationUnit_t &unit, const std::string &rl_path) { - ArrSliceVisitor v(al, unit, rl_path); + ArrSliceVisitor v(al, rl_path); v.visit_TranslationUnit(unit); LFORTRAN_ASSERT(asr_verify(unit)); } diff --git a/src/libasr/pass/array_op.cpp b/src/libasr/pass/array_op.cpp index 3d66c14d17..3bd6026756 100644 --- a/src/libasr/pass/array_op.cpp +++ b/src/libasr/pass/array_op.cpp @@ -63,7 +63,6 @@ nodes are implemented and more are yet to be implemented with time. class ArrayOpVisitor : public PassUtils::PassVisitor { private: - ASR::TranslationUnit_t &unit; /* This pointer stores the result of a node. @@ -98,8 +97,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor std::string rl_path; public: - ArrayOpVisitor(Allocator &al, ASR::TranslationUnit_t &unit_, - const std::string &rl_path) : PassVisitor(al, nullptr), unit(unit_), + ArrayOpVisitor(Allocator &al, + const std::string &rl_path) : PassVisitor(al, nullptr), tmp_val(nullptr), result_var(nullptr), use_custom_loop_params(false), result_var_num(0), rl_path(rl_path) { @@ -177,6 +176,10 @@ class ArrayOpVisitor : public PassUtils::PassVisitor ASR::Subroutine_t *s = ASR::down_cast(item.second); visit_Subroutine(*s); } + if (is_a(*item.second)) { + ASR::AssociateBlock_t *s = ASR::down_cast(item.second); + visit_AssociateBlock(*s); + } if (is_a(*item.second)) { ASR::Function_t *s = ASR::down_cast(item.second); visit_Function(*s); @@ -229,12 +232,16 @@ class ArrayOpVisitor : public PassUtils::PassVisitor } void visit_Assignment(const ASR::Assignment_t& x) { + if( ASR::is_a(*ASRUtils::expr_type(x.m_target)) && + ASR::is_a(*x.m_value) ) { + return ; + } if( PassUtils::is_array(x.m_target) ) { result_var = x.m_target; this->visit_expr(*(x.m_value)); - } else if( PassUtils::is_slice_present(x.m_target) ) { - ASR::ArrayRef_t* array_ref = ASR::down_cast(x.m_target); - result_var = LFortran::ASRUtils::EXPR(ASR::make_Var_t(al, x.m_target->base.loc, array_ref->m_v)); + } else if( ASR::is_a(*x.m_target) ) { + ASR::ArraySection_t* array_ref = ASR::down_cast(x.m_target); + result_var = array_ref->m_v; result_lbound.reserve(al, array_ref->n_args); result_ubound.reserve(al, array_ref->n_args); result_inc.reserve(al, array_ref->n_args); @@ -243,12 +250,12 @@ class ArrayOpVisitor : public PassUtils::PassVisitor for( int i = 0; i < (int) array_ref->n_args; i++ ) { if( array_ref->m_args[i].m_step != nullptr ) { if( array_ref->m_args[i].m_left == nullptr ) { - m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al, unit, rl_path, current_scope); + m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al); } else { m_start = array_ref->m_args[i].m_left; } if( array_ref->m_args[i].m_right == nullptr ) { - m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al, unit, rl_path, current_scope); + m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al); } else { m_end = array_ref->m_args[i].m_right; } @@ -286,10 +293,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor for( int i = 0; i < ndims; i++ ) { ASR::dimension_t new_m_dim; new_m_dim.loc = m_dims[i].loc; - new_m_dim.m_start = PassUtils::get_bound(sibling, i + 1, "lbound", - al, unit, rl_path, current_scope); - new_m_dim.m_end = PassUtils::get_bound(sibling, i + 1, "ubound", - al, unit, rl_path, current_scope); + new_m_dim.m_start = PassUtils::get_bound(sibling, i + 1, "lbound", al); + new_m_dim.m_end = PassUtils::get_bound(sibling, i + 1, "ubound", al); new_m_dims.push_back(al, new_m_dim); } return PassUtils::set_dim_rank(sibling_type, new_m_dims.p, ndims, true, &al); @@ -358,8 +363,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor for( int i = n_dims - 1; i >= 0; i-- ) { ASR::do_loop_head_t head; head.m_v = idx_vars[i]; - head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al, unit, rl_path, current_scope); - head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al, unit, rl_path, current_scope); + head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al); + head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al); head.m_increment = nullptr; head.loc = head.m_v->base.loc; Vec doloop_body; @@ -394,8 +399,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor // TODO: Add an If debug node to check if the lower and upper bounds of both the arrays are same. ASR::do_loop_head_t head; head.m_v = idx_vars[i]; - head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al, unit, rl_path, current_scope); - head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al, unit, rl_path, current_scope); + head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al); + head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al); head.m_increment = nullptr; head.loc = head.m_v->base.loc; Vec doloop_body; @@ -420,11 +425,28 @@ class ArrayOpVisitor : public PassUtils::PassVisitor } } - void visit_UnaryOp(const ASR::UnaryOp_t& x) { + void visit_IntegerUnaryMinus(const ASR::IntegerUnaryMinus_t &x) { + handle_UnaryOp(x, 0); + } + void visit_RealUnaryMinus(const ASR::RealUnaryMinus_t &x) { + handle_UnaryOp(x, 1); + } + void visit_ComplexUnaryMinus(const ASR::ComplexUnaryMinus_t &x) { + handle_UnaryOp(x, 2); + } + void visit_IntegerBitNot(const ASR::IntegerBitNot_t &x) { + handle_UnaryOp(x, 3); + } + void visit_LogicalNot(const ASR::LogicalNot_t &x) { + handle_UnaryOp(x, 4); + } + + template + void handle_UnaryOp(const T& x, int unary_type) { std::string res_prefix = "_unary_op_res"; ASR::expr_t* result_var_copy = result_var; result_var = nullptr; - this->visit_expr(*(x.m_operand)); + this->visit_expr(*(x.m_arg)); ASR::expr_t* operand = tmp_val; int rank_operand = PassUtils::get_rank(operand); if( rank_operand == 0 ) { @@ -448,8 +470,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor // TODO: Add an If debug node to check if the lower and upper bounds of both the arrays are same. ASR::do_loop_head_t head; head.m_v = idx_vars[i]; - head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al, unit, rl_path, current_scope); - head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al, unit, rl_path, current_scope); + head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al); + head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al); head.m_increment = nullptr; head.loc = head.m_v->base.loc; Vec doloop_body; @@ -457,9 +479,23 @@ class ArrayOpVisitor : public PassUtils::PassVisitor if( doloop == nullptr ) { ASR::expr_t* ref = PassUtils::create_array_ref(operand, idx_vars, al); ASR::expr_t* res = PassUtils::create_array_ref(result_var, idx_vars, al); - ASR::expr_t* op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_UnaryOp_t( - al, x.base.base.loc, - x.m_op, ref, x.m_type, nullptr)); + ASR::expr_t* op_el_wise = nullptr; + if (unary_type == 0) { + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_IntegerUnaryMinus_t(al, x.base.base.loc, + ref, x.m_type, nullptr)); + } else if (unary_type == 1) { + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_RealUnaryMinus_t(al, x.base.base.loc, + ref, x.m_type, nullptr)); + } else if (unary_type == 2) { + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_ComplexUnaryMinus_t(al, x.base.base.loc, + ref, x.m_type, nullptr)); + } else if (unary_type == 3) { + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_IntegerBitNot_t(al, x.base.base.loc, + ref, x.m_type, nullptr)); + } else if (unary_type == 4) { + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_LogicalNot_t(al, x.base.base.loc, + ref, x.m_type, nullptr)); + } ASR::stmt_t* assign = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, x.base.base.loc, res, op_el_wise, nullptr)); doloop_body.push_back(al, assign); } else { @@ -517,8 +553,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor head.m_end = result_ubound[i]; head.m_increment = result_inc[i]; } else { - head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al, unit, rl_path, current_scope); - head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al, unit, rl_path, current_scope); + head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al); + head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al); head.m_increment = nullptr; } head.loc = head.m_v->base.loc; @@ -530,21 +566,45 @@ class ArrayOpVisitor : public PassUtils::PassVisitor ASR::expr_t* res = PassUtils::create_array_ref(result_var, idx_vars, al); ASR::expr_t* op_el_wise = nullptr; switch( x.class_type ) { - case ASR::exprType::BinOp: - op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t( + case ASR::exprType::IntegerBinOp: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t( + al, x.base.base.loc, + ref_1, (ASR::binopType)x.m_op, ref_2, x.m_type, nullptr)); + break; + case ASR::exprType::RealBinOp: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_RealBinOp_t( al, x.base.base.loc, - ref_1, (ASR::binopType)x.m_op, ref_2, - x.m_type, nullptr, nullptr)); + ref_1, (ASR::binopType)x.m_op, ref_2, x.m_type, nullptr)); break; - case ASR::exprType::Compare: - op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_Compare_t( + case ASR::exprType::ComplexBinOp: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_ComplexBinOp_t( al, x.base.base.loc, - ref_1, (ASR::cmpopType)x.m_op, ref_2, x.m_type, nullptr, nullptr)); + ref_1, (ASR::binopType)x.m_op, ref_2, x.m_type, nullptr)); break; - case ASR::exprType::BoolOp: - op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_BoolOp_t( + case ASR::exprType::LogicalBinOp: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_LogicalBinOp_t( al, x.base.base.loc, - ref_1, (ASR::boolopType)x.m_op, ref_2, x.m_type, nullptr)); + ref_1, (ASR::logicalbinopType)x.m_op, ref_2, x.m_type, nullptr)); + break; + case ASR::exprType::IntegerCompare: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_IntegerCompare_t( + al, x.base.base.loc, + ref_1, (ASR::cmpopType)x.m_op, ref_2, x.m_type, nullptr)); + break; + case ASR::exprType::RealCompare: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_RealCompare_t( + al, x.base.base.loc, + ref_1, (ASR::cmpopType)x.m_op, ref_2, x.m_type, nullptr)); + break; + case ASR::exprType::ComplexCompare: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_ComplexCompare_t( + al, x.base.base.loc, + ref_1, (ASR::cmpopType)x.m_op, ref_2, x.m_type, nullptr)); + break; + case ASR::exprType::LogicalCompare: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_LogicalCompare_t( + al, x.base.base.loc, + ref_1, (ASR::cmpopType)x.m_op, ref_2, x.m_type, nullptr)); break; default: throw LFortranException("The desired operation is not supported yet for arrays."); @@ -556,9 +616,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor doloop_body.push_back(al, set_to_one); doloop_body.push_back(al, doloop); } - ASR::expr_t* inc_expr = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, x.base.base.loc, idx_vars_value[i], - ASR::binopType::Add, const_1, int32_type, - nullptr, nullptr)); + ASR::expr_t* inc_expr = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, x.base.base.loc, idx_vars_value[i], + ASR::binopType::Add, const_1, int32_type, nullptr)); ASR::stmt_t* assign_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, x.base.base.loc, idx_vars_value[i], inc_expr, nullptr)); doloop_body.push_back(al, assign_stmt); doloop = LFortran::ASRUtils::STMT(ASR::make_DoLoop_t(al, x.base.base.loc, head, doloop_body.p, doloop_body.size())); @@ -601,8 +660,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor head.m_end = result_ubound[i]; head.m_increment = result_inc[i]; } else { - head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al, unit, rl_path, current_scope); - head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al, unit, rl_path, current_scope); + head.m_start = PassUtils::get_bound(result_var, i + 1, "lbound", al); + head.m_end = PassUtils::get_bound(result_var, i + 1, "ubound", al); head.m_increment = nullptr; } head.loc = head.m_v->base.loc; @@ -613,21 +672,45 @@ class ArrayOpVisitor : public PassUtils::PassVisitor ASR::expr_t* res = PassUtils::create_array_ref(result_var, idx_vars, al); ASR::expr_t* op_el_wise = nullptr; switch( x.class_type ) { - case ASR::exprType::BinOp: - op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t( + case ASR::exprType::IntegerBinOp: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t( + al, x.base.base.loc, + ref, (ASR::binopType)x.m_op, other_expr, x.m_type, nullptr)); + break; + case ASR::exprType::RealBinOp: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_RealBinOp_t( + al, x.base.base.loc, + ref, (ASR::binopType)x.m_op, other_expr, x.m_type, nullptr)); + break; + case ASR::exprType::ComplexBinOp: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_ComplexBinOp_t( + al, x.base.base.loc, + ref, (ASR::binopType)x.m_op, other_expr, x.m_type, nullptr)); + break; + case ASR::exprType::LogicalBinOp: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_LogicalBinOp_t( + al, x.base.base.loc, + ref, (ASR::logicalbinopType)x.m_op, other_expr, x.m_type, nullptr)); + break; + case ASR::exprType::IntegerCompare: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_IntegerCompare_t( + al, x.base.base.loc, + ref, (ASR::cmpopType)x.m_op, other_expr, x.m_type, nullptr)); + break; + case ASR::exprType::RealCompare: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_RealCompare_t( al, x.base.base.loc, - ref, (ASR::binopType)x.m_op, other_expr, - x.m_type, nullptr, nullptr)); + ref, (ASR::cmpopType)x.m_op, other_expr, x.m_type, nullptr)); break; - case ASR::exprType::Compare: - op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_Compare_t( + case ASR::exprType::ComplexCompare: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_ComplexCompare_t( al, x.base.base.loc, - ref, (ASR::cmpopType)x.m_op, other_expr, x.m_type, nullptr, nullptr)); + ref, (ASR::cmpopType)x.m_op, other_expr, x.m_type, nullptr)); break; - case ASR::exprType::BoolOp: - op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_BoolOp_t( + case ASR::exprType::LogicalCompare: + op_el_wise = LFortran::ASRUtils::EXPR(ASR::make_LogicalCompare_t( al, x.base.base.loc, - ref, (ASR::boolopType)x.m_op, other_expr, x.m_type, nullptr)); + ref, (ASR::cmpopType)x.m_op, other_expr, x.m_type, nullptr)); break; default: throw LFortranException("The desired operation is not supported yet for arrays."); @@ -639,7 +722,8 @@ class ArrayOpVisitor : public PassUtils::PassVisitor doloop_body.push_back(al, set_to_one); doloop_body.push_back(al, doloop); } - ASR::expr_t* inc_expr = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, x.base.base.loc, idx_vars_value[i], ASR::binopType::Add, const_1, int32_type, nullptr, nullptr)); + ASR::expr_t* inc_expr = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, x.base.base.loc, idx_vars_value[i], + ASR::binopType::Add, const_1, int32_type, nullptr)); ASR::stmt_t* assign_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, x.base.base.loc, idx_vars_value[i], inc_expr, nullptr)); doloop_body.push_back(al, assign_stmt); doloop = LFortran::ASRUtils::STMT(ASR::make_DoLoop_t(al, x.base.base.loc, head, doloop_body.p, doloop_body.size())); @@ -650,16 +734,36 @@ class ArrayOpVisitor : public PassUtils::PassVisitor } } - void visit_BinOp(const ASR::BinOp_t &x) { - visit_ArrayOpCommon(x, "_bin_op_res"); + void visit_IntegerBinOp(const ASR::IntegerBinOp_t &x) { + visit_ArrayOpCommon(x, "_bin_op_res"); + } + + void visit_RealBinOp(const ASR::RealBinOp_t &x) { + visit_ArrayOpCommon(x, "_bin_op_res"); + } + + void visit_ComplexBinOp(const ASR::ComplexBinOp_t &x) { + visit_ArrayOpCommon(x, "_bin_op_res"); + } + + void visit_LogicalBinOp(const ASR::LogicalBinOp_t &x) { + visit_ArrayOpCommon(x, "_bool_op_res"); + } + + void visit_IntegerCompare(const ASR::IntegerCompare_t &x) { + visit_ArrayOpCommon(x, "_comp_op_res"); + } + + void visit_RealCompare(const ASR::RealCompare_t &x) { + visit_ArrayOpCommon(x, "_comp_op_res"); } - void visit_Compare(const ASR::Compare_t &x) { - visit_ArrayOpCommon(x, "_comp_op_res"); + void visit_ComplexCompare(const ASR::ComplexCompare_t &x) { + visit_ArrayOpCommon(x, "_comp_op_res"); } - void visit_BoolOp(const ASR::BoolOp_t &x) { - visit_ArrayOpCommon(x, "_bool_op_res"); + void visit_LogicalCompare(const ASR::LogicalCompare_t &x) { + visit_ArrayOpCommon(x, "_comp_op_res"); } void visit_ArraySize(const ASR::ArraySize_t& x) { @@ -711,7 +815,7 @@ class ArrayOpVisitor : public PassUtils::PassVisitor void pass_replace_array_op(Allocator &al, ASR::TranslationUnit_t &unit, const std::string &rl_path) { - ArrayOpVisitor v(al, unit, rl_path); + ArrayOpVisitor v(al, rl_path); v.visit_TranslationUnit(unit); LFORTRAN_ASSERT(asr_verify(unit)); } diff --git a/src/libasr/pass/class_constructor.cpp b/src/libasr/pass/class_constructor.cpp index d3208593dc..b698bbfa06 100644 --- a/src/libasr/pass/class_constructor.cpp +++ b/src/libasr/pass/class_constructor.cpp @@ -21,13 +21,36 @@ class ClassConstructorVisitor : public PassUtils::PassVisitor(x); + current_scope = xx.m_symtab; + for( auto item: current_scope->get_scope() ) { + if( ASR::is_a(*item.second) ) { + ASR::Variable_t* variable = ASR::down_cast(item.second); + if( variable->m_symbolic_value ) { + result_var = ASRUtils::EXPR(ASR::make_Var_t(al, variable->base.base.loc, + item.second)); + is_init_constructor = false; + this->visit_expr(*variable->m_symbolic_value); + if( is_init_constructor ) { + variable->m_symbolic_value = nullptr; + } + } + } + } + transform_stmts(xx.m_body, xx.n_body); + } + void visit_Assignment(const ASR::Assignment_t& x) { if( x.m_value->type == ASR::exprType::DerivedTypeConstructor ) { is_constructor_present = true; @@ -37,10 +60,14 @@ class ClassConstructorVisitor : public PassUtils::PassVisitor(x.m_type); - ASR::DerivedType_t* dt_dertype = (ASR::DerivedType_t*)(&( - LFortran::ASRUtils::symbol_get_past_external(dt_der->m_derived_type)->base)); - for( size_t i = 0; i < dt_dertype->n_members; i++ ) { + ASR::DerivedType_t* dt_dertype = ASR::down_cast( + LFortran::ASRUtils::symbol_get_past_external(dt_der->m_derived_type)); + for( size_t i = 0; i < std::min(dt_dertype->n_members, x.n_args); i++ ) { ASR::symbol_t* member = dt_dertype->m_symtab->resolve_symbol(std::string(dt_dertype->m_members[i], strlen(dt_dertype->m_members[i]))); ASR::expr_t* derived_ref = LFortran::ASRUtils::EXPR(ASRUtils::getDerivedRef_t(al, x.base.base.loc, (ASR::asr_t*)result_var, member, current_scope)); ASR::stmt_t* assign = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, x.base.base.loc, derived_ref, x.m_args[i], nullptr)); diff --git a/src/libasr/pass/div_to_mul.cpp b/src/libasr/pass/div_to_mul.cpp index 0833e18a00..a4cfeccb0e 100644 --- a/src/libasr/pass/div_to_mul.cpp +++ b/src/libasr/pass/div_to_mul.cpp @@ -46,7 +46,7 @@ class DivToMulVisitor : public PassUtils::PassVisitor pass_result.reserve(al, 1); } - void visit_BinOp(const ASR::BinOp_t& x) { + void visit_RealBinOp(const ASR::RealBinOp_t& x) { visit_expr(*x.m_left); visit_expr(*x.m_right); if( x.m_op == ASR::binopType::Div ) { @@ -66,7 +66,7 @@ class DivToMulVisitor : public PassUtils::PassVisitor break; } if( is_feasible ) { - ASR::BinOp_t& xx = const_cast(x); + ASR::RealBinOp_t& xx = const_cast(x); xx.m_op = ASR::binopType::Mul; xx.m_right = right_inverse; } diff --git a/src/libasr/pass/flip_sign.cpp b/src/libasr/pass/flip_sign.cpp index 1f83c3b51d..a7a81963fd 100644 --- a/src/libasr/pass/flip_sign.cpp +++ b/src/libasr/pass/flip_sign.cpp @@ -118,13 +118,12 @@ class FlipSignVisitor : public PassUtils::SkipOptimizationSubroutineVisitortype == ASR::exprType::UnaryOp ) { + if( x.m_value->type == ASR::exprType::RealUnaryMinus ) { is_unary_op_present = true; ASR::symbol_t* sym = nullptr; - ASR::UnaryOp_t* negation = ASR::down_cast(x.m_value); - if( negation->m_operand->type == ASR::exprType::Var && - negation->m_op == ASR::unaryopType::USub ) { - ASR::Var_t* var = ASR::down_cast(negation->m_operand); + ASR::RealUnaryMinus_t* negation = ASR::down_cast(x.m_value); + if( negation->m_arg->type == ASR::exprType::Var ) { + ASR::Var_t* var = ASR::down_cast(negation->m_arg); sym = var->m_v; } if( x.m_target->type == ASR::exprType::Var ) { @@ -135,7 +134,28 @@ class FlipSignVisitor : public PassUtils::SkipOptimizationSubroutineVisitor + void handle_Compare(const T& x) { is_compare_present = true; ASR::expr_t* potential_one = nullptr; ASR::expr_t* potential_func_call = nullptr; diff --git a/src/libasr/pass/fma.cpp b/src/libasr/pass/fma.cpp index bffc9b790f..9ab42b08b5 100644 --- a/src/libasr/pass/fma.cpp +++ b/src/libasr/pass/fma.cpp @@ -53,23 +53,25 @@ class FMAVisitor : public PassUtils::SkipOptimizationFunctionVisitor } bool is_BinOpMul(ASR::expr_t* expr) { - if( expr->type == ASR::exprType::BinOp ) { - ASR::BinOp_t* expr_binop = ASR::down_cast(expr); + if (ASR::is_a(*expr)) { + ASR::RealBinOp_t* expr_binop = ASR::down_cast(expr); return expr_binop->m_op == ASR::binopType::Mul; } return false; } - void visit_BinOp(const ASR::BinOp_t& x_const) { + void visit_IntegerBinOp(const ASR::IntegerBinOp_t& /*x*/) { } + void visit_ComplexBinOp(const ASR::ComplexBinOp_t& /*x*/) { } + void visit_LogicalBinOp(const ASR::LogicalBinOp_t& /*x*/) { } + + void visit_RealBinOp(const ASR::RealBinOp_t& x_const) { if( !from_fma ) { return ; } from_fma = true; - if( x_const.m_type->type != ASR::ttypeType::Real ) { - return ; - } - ASR::BinOp_t& x = const_cast(x_const); + LFORTRAN_ASSERT(ASRUtils::is_real(*x_const.m_type)) + ASR::RealBinOp_t& x = const_cast(x_const); fma_var = nullptr; visit_expr(*x.m_left); @@ -102,18 +104,16 @@ class FMAVisitor : public PassUtils::SkipOptimizationFunctionVisitor } if( is_other_expr_negative ) { - other_expr = ASRUtils::EXPR(ASR::make_UnaryOp_t(al, other_expr->base.loc, - ASR::unaryopType::USub, other_expr, ASRUtils::expr_type(other_expr), - nullptr)); + other_expr = ASRUtils::EXPR(ASR::make_RealUnaryMinus_t(al, other_expr->base.loc, other_expr, + ASRUtils::expr_type(other_expr), nullptr)); } - ASR::BinOp_t* mul_binop = ASR::down_cast(mul_expr); + ASR::RealBinOp_t* mul_binop = ASR::down_cast(mul_expr); ASR::expr_t *first_arg = mul_binop->m_left, *second_arg = mul_binop->m_right; if( is_mul_expr_negative ) { - first_arg = ASRUtils::EXPR(ASR::make_UnaryOp_t(al, first_arg->base.loc, - ASR::unaryopType::USub, first_arg, ASRUtils::expr_type(first_arg), - nullptr)); + first_arg = ASRUtils::EXPR(ASR::make_RealUnaryMinus_t(al, first_arg->base.loc, first_arg, + ASRUtils::expr_type(first_arg), nullptr)); } fma_var = PassUtils::get_fma(other_expr, first_arg, second_arg, @@ -134,13 +134,30 @@ class FMAVisitor : public PassUtils::SkipOptimizationFunctionVisitor from_fma = false; } - void visit_UnaryOp(const ASR::UnaryOp_t& x) { + void visit_IntegerUnaryMinus(const ASR::IntegerUnaryMinus_t &x) { + visit_UnaryOp(x); + } + void visit_RealUnaryMinus(const ASR::RealUnaryMinus_t &x) { + visit_UnaryOp(x); + } + void visit_ComplexUnaryMinus(const ASR::ComplexUnaryMinus_t &x) { + visit_UnaryOp(x); + } + void visit_IntegerBitNot(const ASR::IntegerBitNot_t &x) { + visit_UnaryOp(x); + } + void visit_LogicalNot(const ASR::LogicalNot_t &x) { + visit_UnaryOp(x); + } + + template + void visit_UnaryOp(const T& x) { from_fma = true; - ASR::UnaryOp_t& xx = const_cast(x); + T& xx = const_cast(x); fma_var = nullptr; - visit_expr(*x.m_operand); + visit_expr(*x.m_arg); if( fma_var ) { - xx.m_operand = fma_var; + xx.m_arg = fma_var; } fma_var = nullptr; from_fma = false; diff --git a/src/libasr/pass/implied_do_loops.cpp b/src/libasr/pass/implied_do_loops.cpp index 4047600d38..7fc91907e8 100644 --- a/src/libasr/pass/implied_do_loops.cpp +++ b/src/libasr/pass/implied_do_loops.cpp @@ -62,7 +62,24 @@ class ImpliedDoLoopVisitor : public PassUtils::PassVisitor contains_array = false; } - void visit_BinOp(const ASR::BinOp_t& x) { + void visit_IntegerBinOp(const ASR::IntegerBinOp_t& x) { + handle_BinOp(x); + } + + void visit_RealBinOp(const ASR::RealBinOp_t& x) { + handle_BinOp(x); + } + + void visit_ComplexBinOp(const ASR::ComplexBinOp_t& x) { + handle_BinOp(x); + } + + void visit_LogicalBinOp(const ASR::LogicalBinOp_t& x) { + handle_BinOp(x); + } + + template + void handle_BinOp(const T& x) { if( contains_array ) { return ; } @@ -83,16 +100,15 @@ class ImpliedDoLoopVisitor : public PassUtils::PassVisitor head.loc = head.m_v->base.loc; Vec doloop_body; doloop_body.reserve(al, 1); - ASR::symbol_t* arr = arr_var->m_v; ASR::ttype_t *_type = LFortran::ASRUtils::expr_type(idoloop->m_start); ASR::expr_t* const_1 = LFortran::ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, arr_var->base.base.loc, 1, _type)); ASR::expr_t *const_n, *offset, *num_grps, *grp_start; const_n = offset = num_grps = grp_start = nullptr; if( arr_idx == nullptr ) { const_n = LFortran::ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, arr_var->base.base.loc, idoloop->n_values, _type)); - offset = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, arr_var->base.base.loc, idoloop->m_var, ASR::binopType::Sub, idoloop->m_start, _type, nullptr, nullptr)); - num_grps = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, arr_var->base.base.loc, offset, ASR::binopType::Mul, const_n, _type, nullptr, nullptr)); - grp_start = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, arr_var->base.base.loc, num_grps, ASR::binopType::Add, const_1, _type, nullptr, nullptr)); + offset = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, arr_var->base.base.loc, idoloop->m_var, ASR::binopType::Sub, idoloop->m_start, _type, nullptr)); + num_grps = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, arr_var->base.base.loc, offset, ASR::binopType::Mul, const_n, _type, nullptr)); + grp_start = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, arr_var->base.base.loc, num_grps, ASR::binopType::Add, const_1, _type, nullptr)); } for( size_t i = 0; i < idoloop->n_values; i++ ) { Vec args; @@ -101,9 +117,8 @@ class ImpliedDoLoopVisitor : public PassUtils::PassVisitor ai.m_left = nullptr; if( arr_idx == nullptr ) { ASR::expr_t* const_i = LFortran::ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, arr_var->base.base.loc, i, _type)); - ASR::expr_t* idx = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, arr_var->base.base.loc, - grp_start, ASR::binopType::Add, const_i, - _type, nullptr, nullptr)); + ASR::expr_t* idx = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, arr_var->base.base.loc, + grp_start, ASR::binopType::Add, const_i, _type, nullptr)); ai.m_right = idx; } else { ai.m_right = arr_idx; @@ -111,16 +126,21 @@ class ImpliedDoLoopVisitor : public PassUtils::PassVisitor ai.m_step = nullptr; args.reserve(al, 1); args.push_back(al, ai); - ASR::expr_t* array_ref = LFortran::ASRUtils::EXPR(ASR::make_ArrayRef_t(al, arr_var->base.base.loc, arr, - args.p, args.size(), - LFortran::ASRUtils::expr_type(LFortran::ASRUtils::EXPR((ASR::asr_t*)arr_var)), nullptr)); + ASR::ttype_t* array_ref_type = ASRUtils::expr_type(ASRUtils::EXPR((ASR::asr_t*)arr_var)); + Vec empty_dims; + empty_dims.reserve(al, 1); + array_ref_type = ASRUtils::duplicate_type(al, array_ref_type, &empty_dims); + ASR::expr_t* array_ref = LFortran::ASRUtils::EXPR(ASR::make_ArrayItem_t(al, arr_var->base.base.loc, + ASRUtils::EXPR((ASR::asr_t*)arr_var), + args.p, args.size(), + array_ref_type, nullptr)); if( idoloop->m_values[i]->type == ASR::exprType::ImpliedDoLoop ) { throw LFortranException("Pass for nested ImpliedDoLoop nodes isn't implemented yet."); // idoloop->m_values[i]->base.loc } ASR::stmt_t* doloop_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, arr_var->base.base.loc, array_ref, idoloop->m_values[i], nullptr)); doloop_body.push_back(al, doloop_stmt); if( arr_idx != nullptr ) { - ASR::expr_t* increment = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, arr_var->base.base.loc, arr_idx, ASR::binopType::Add, const_1, LFortran::ASRUtils::expr_type(arr_idx), nullptr, nullptr)); + ASR::expr_t* increment = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, arr_var->base.base.loc, arr_idx, ASR::binopType::Add, const_1, LFortran::ASRUtils::expr_type(arr_idx), nullptr)); ASR::stmt_t* assign_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, arr_var->base.base.loc, arr_idx, increment, nullptr)); doloop_body.push_back(al, assign_stmt); } @@ -130,6 +150,10 @@ class ImpliedDoLoopVisitor : public PassUtils::PassVisitor } void visit_Assignment(const ASR::Assignment_t &x) { + if( ASR::is_a(*ASRUtils::expr_type(x.m_target)) && + ASR::is_a(*x.m_value) ) { + return ; + } if( x.m_value->type == ASR::exprType::ArrayConstant ) { ASR::ArrayConstant_t* arr_init = ((ASR::ArrayConstant_t*)(&(x.m_value->base))); if( arr_init->n_args == 1 && arr_init->m_args[0] != nullptr && @@ -171,12 +195,17 @@ class ImpliedDoLoopVisitor : public PassUtils::PassVisitor ai.m_step = nullptr; args.reserve(al, 1); args.push_back(al, ai); - ASR::expr_t* array_ref = LFortran::ASRUtils::EXPR(ASR::make_ArrayRef_t(al, arr_var->base.base.loc, arr_var->m_v, - args.p, args.size(), - LFortran::ASRUtils::expr_type(LFortran::ASRUtils::EXPR((ASR::asr_t*)arr_var)), nullptr)); + ASR::ttype_t* array_ref_type = ASRUtils::expr_type(ASRUtils::EXPR((ASR::asr_t*)arr_var)); + Vec empty_dims; + empty_dims.reserve(al, 1); + array_ref_type = ASRUtils::duplicate_type(al, array_ref_type, &empty_dims); + ASR::expr_t* array_ref = LFortran::ASRUtils::EXPR(ASR::make_ArrayItem_t(al, arr_var->base.base.loc, + ASRUtils::EXPR((ASR::asr_t*)arr_var), + args.p, args.size(), + array_ref_type, nullptr)); ASR::stmt_t* assign_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, arr_var->base.base.loc, array_ref, arr_init->m_args[k], nullptr)); pass_result.push_back(al, assign_stmt); - ASR::expr_t* increment = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, arr_var->base.base.loc, idx_var, ASR::binopType::Add, const_1, LFortran::ASRUtils::expr_type(idx_var), nullptr, nullptr)); + ASR::expr_t* increment = LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, arr_var->base.base.loc, idx_var, ASR::binopType::Add, const_1, LFortran::ASRUtils::expr_type(idx_var), nullptr)); assign_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, arr_var->base.base.loc, idx_var, increment, nullptr)); pass_result.push_back(al, assign_stmt); } @@ -198,8 +227,8 @@ class ImpliedDoLoopVisitor : public PassUtils::PassVisitor for( int i = n_dims - 1; i >= 0; i-- ) { ASR::do_loop_head_t head; head.m_v = idx_vars[i]; - head.m_start = PassUtils::get_bound(x.m_target, n_dims, "lbound", al, unit, rl_path, current_scope); - head.m_end = PassUtils::get_bound(x.m_target, n_dims, "ubound", al, unit, rl_path, current_scope); + head.m_start = PassUtils::get_bound(x.m_target, n_dims, "lbound", al); + head.m_end = PassUtils::get_bound(x.m_target, n_dims, "ubound", al); head.m_increment = nullptr; head.loc = head.m_v->base.loc; Vec doloop_body; diff --git a/src/libasr/pass/inline_function_calls.cpp b/src/libasr/pass/inline_function_calls.cpp index b6d72627fc..f2bb853c3c 100644 --- a/src/libasr/pass/inline_function_calls.cpp +++ b/src/libasr/pass/inline_function_calls.cpp @@ -58,6 +58,9 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitorget_unique_name("~empty_block"); + if( empty_block_name != "~empty_block" ) { + empty_block = scope->get_symbol("~empty_block"); + } else { + SymbolTable* empty_symtab = al.make_new(scope); + empty_block = ASR::down_cast(ASR::make_Block_t(al, loc, + empty_symtab, + s2c(al, empty_block_name), nullptr, 0)); + scope->add_symbol(empty_block_name, empty_block); + } + } + + void remove_empty_block(SymbolTable* scope) { + scope->erase_symbol("~empty_block"); + } + void visit_FunctionCall(const ASR::FunctionCall_t& x) { // If this node is visited by any other visitor // or it is being visited while inlining another function call @@ -240,6 +263,10 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitorm_symtab->get_scope() ) { + if( startswith(itr.first, "~empty_block") ) { + set_empty_block(current_scope, func->base.base.loc); + continue; + } ASR::Variable_t* func_var = ASR::down_cast(itr.second); std::string func_var_name = itr.first; if( arg2value.find(func_var_name) == arg2value.end() ) { @@ -315,6 +342,13 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitorbase.base.loc); + uint64_t block_call_label = label_generator->get_unique_label(); + ASR::stmt_t* block_call = ASRUtils::STMT(ASR::make_BlockCall_t(al, x.base.base.loc, + block_call_label, empty_block)); + label_generator->add_node_with_unique_label((ASR::asr_t*) block_call, + block_call_label); + return_replacer.set_goto_label(block_call_label); // If duplication is successfull then fill the // pass result with assignment statements // (for local variables in the loop just below) @@ -323,9 +357,19 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitorn_body; i++ ) { + return_replacer.current_stmt = &func_copy.p[i]; + return_replacer.has_replacement_happened = false; + return_replacer.replace_stmt(func_copy[i]); + is_goto_added = is_goto_added || return_replacer.has_replacement_happened; pass_result.push_back(al, func_copy[i]); } + if( is_goto_added ) { + pass_result.push_back(al, block_call); + } else { + remove_empty_block(current_scope); + } } inlining_function = false; current_routine_scope = nullptr; @@ -349,8 +393,25 @@ class InlineFunctionCallVisitor : public PassUtils::PassVisitor(x); + void visit_IntegerBinOp(const ASR::IntegerBinOp_t& x) { + handle_BinOp(x); + } + + void visit_RealBinOp(const ASR::RealBinOp_t& x) { + handle_BinOp(x); + } + + void visit_ComplexBinOp(const ASR::ComplexBinOp_t& x) { + handle_BinOp(x); + } + + void visit_LogicalBinOp(const ASR::LogicalBinOp_t& x) { + handle_BinOp(x); + } + + template + void handle_BinOp(const T& x) { + T& xx = const_cast(x); from_inline_function_call = true; function_result_var = nullptr; visit_expr(*x.m_left); diff --git a/src/libasr/pass/loop_unroll.cpp b/src/libasr/pass/loop_unroll.cpp index f5bfa85277..9f4788d9aa 100644 --- a/src/libasr/pass/loop_unroll.cpp +++ b/src/libasr/pass/loop_unroll.cpp @@ -56,10 +56,15 @@ class LoopUnrollVisitor : public PassUtils::PassVisitor !ASRUtils::is_value_constant(x_inc, _inc) ) { return ; } - int64_t loop_size = std::ceil( ((float) (_end - _start + 1)) / ((float) _inc) ); + int64_t loop_size = (_end - _start)/_inc + 1; int64_t unroll_factor_ = std::min(unroll_factor, loop_size); bool create_unrolled_loop = unroll_factor_ < loop_size; - int64_t new_end = unroll_factor_ * (loop_size / unroll_factor_); + // Avoid unnecessary loop unrolling + if( !create_unrolled_loop ) { + return ; + } + int64_t groups = loop_size / unroll_factor_; + int64_t new_end = _start + (groups - 1) * _inc * unroll_factor_ + (unroll_factor_ - 1) * _inc; int64_t remaining_part = loop_size % unroll_factor_; ASR::ttype_t *int32_type = LFortran::ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, 4, nullptr, 0)); @@ -88,19 +93,13 @@ class LoopUnrollVisitor : public PassUtils::PassVisitor } pass_result.push_back(al, init_stmt); - if( create_unrolled_loop ) { - ASR::stmt_t* unrolled_whileloop = ASRUtils::STMT(ASR::make_WhileLoop_t(al, x.base.base.loc, - whileloop->m_test, unrolled_loop.p, unrolled_loop.size())); - pass_result.push_back(al, unrolled_whileloop); - for( int64_t i = 0; i < remaining_part; i++ ) { - for( size_t i = 0; i < whileloop->n_body; i++ ) { - ASR::stmt_t* m_body_copy = node_duplicator.duplicate_stmt(whileloop->m_body[i]); - pass_result.push_back(al, m_body_copy); - } - } - } else { - for( size_t i = 0; i < unrolled_loop.size(); i++ ) { - pass_result.push_back(al, unrolled_loop[i]); + ASR::stmt_t* unrolled_whileloop = ASRUtils::STMT(ASR::make_WhileLoop_t(al, x.base.base.loc, + whileloop->m_test, unrolled_loop.p, unrolled_loop.size())); + pass_result.push_back(al, unrolled_whileloop); + for( int64_t i = 0; i < remaining_part; i++ ) { + for( size_t i = 0; i < whileloop->n_body; i++ ) { + ASR::stmt_t* m_body_copy = node_duplicator.duplicate_stmt(whileloop->m_body[i]); + pass_result.push_back(al, m_body_copy); } } } diff --git a/src/libasr/pass/loop_vectorise.cpp b/src/libasr/pass/loop_vectorise.cpp new file mode 100644 index 0000000000..686d078381 --- /dev/null +++ b/src/libasr/pass/loop_vectorise.cpp @@ -0,0 +1,199 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +namespace LFortran { + +using ASR::down_cast; +using ASR::is_a; + +/* + +This ASR pass converts loops over arrays with a call to internal +optimization routine for loop vectorisation. This allows backend +specific code generation for vector operations resulting in optimized +code. + +Converts: + + i: i32 + for i in range(9216): + a[i] = b[i] + +to: + + for i in range(0, 9216, 8): + vector_copy(8, a[i*8:(i+1)*8], b[i*8:(i+1)*8]) + +*/ +class LoopVectoriseVisitor : public PassUtils::SkipOptimizationSubroutineVisitor +{ +private: + ASR::TranslationUnit_t &unit; + + std::string rl_path; + + // To make sure that FMA is applied only for + // the nodes implemented in this class + bool from_loop_vectorise; + + const int64_t avx512 = 512; + +public: + LoopVectoriseVisitor(Allocator &al_, ASR::TranslationUnit_t &unit_, + const std::string& rl_path_) : SkipOptimizationSubroutineVisitor(al_), + unit(unit_), rl_path(rl_path_), from_loop_vectorise(false) + { + pass_result.reserve(al, 1); + } + + bool is_loop(const ASR::stmt_t& x) { + return (ASR::is_a(x) || + ASR::is_a(x)); + } + + bool is_vector_copy(ASR::stmt_t* x, Vec& arrays) { + if( !ASR::is_a(*x) ) { + return false; + } + ASR::Assignment_t* x_assignment = ASR::down_cast(x); + ASR::expr_t* target = x_assignment->m_target; + ASR::expr_t* value = x_assignment->m_value; + if( !ASR::is_a(*target) || + !ASR::is_a(*value) ) { + return false; + } + ASR::ArrayItem_t* target_array_ref = ASR::down_cast(target); + ASR::ArrayItem_t* value_array_ref = ASR::down_cast(value); + if( target_array_ref->m_args->m_left || + target_array_ref->m_args->m_step || + value_array_ref->m_args->m_left || + value_array_ref->m_args->m_step ) { + return false; + } + arrays.push_back(al, target_array_ref->m_v); + arrays.push_back(al, value_array_ref->m_v); + return true; + } + + int64_t select_vector_instruction_size() { + return avx512; + } + + int64_t get_vector_length(ASR::ttype_t* type) { + int kind = ASRUtils::extract_kind_from_ttype_t(type); + int64_t instruction_length = select_vector_instruction_size(); + // TODO: Add check for divisibility and raise error if needed. + return instruction_length/(kind * 8); + } + + void get_vector_intrinsic(ASR::stmt_t* loop_stmt, ASR::expr_t* index, + ASR::expr_t*& vector_length, + Vec& vectorised_loop_body) { + LFORTRAN_ASSERT(vectorised_loop_body.reserve_called); + Vec arrays; + arrays.reserve(al, 2); + if( is_vector_copy(loop_stmt, arrays) ) { + ASR::expr_t *target_sym = arrays[0], *value_sym = arrays[1]; + ASR::ttype_t* target_type = ASRUtils::expr_type(target_sym); + int64_t vector_length_int = get_vector_length(target_type); + vector_length = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loop_stmt->base.loc, + vector_length_int, ASRUtils::expr_type(index))); + ASR::expr_t* start = ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loop_stmt->base.loc, index, ASR::binopType::Mul, + vector_length, ASRUtils::expr_type(index), nullptr)); + ASR::expr_t* one = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loop_stmt->base.loc, + 1, ASRUtils::expr_type(index))); + ASR::expr_t* next_index = ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loop_stmt->base.loc, index, ASR::binopType::Add, + one, ASRUtils::expr_type(index), nullptr)); + ASR::expr_t* end = ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loop_stmt->base.loc, next_index, ASR::binopType::Mul, + vector_length, ASRUtils::expr_type(index), nullptr)); + vectorised_loop_body.push_back(al, PassUtils::get_vector_copy(target_sym, value_sym, start, + end, one, vector_length, + al, unit, + current_scope, loop_stmt->base.loc)); + return ; + } + } + + void vectorise_loop(const ASR::DoLoop_t& x) { + // Do Vectorisation of Loop inside this function + ASR::expr_t* loop_start = x.m_head.m_start; + ASR::expr_t* loop_end = x.m_head.m_end; + ASR::expr_t* loop_inc = x.m_head.m_increment; + ASR::expr_t* loop_start_value = ASRUtils::expr_value(loop_start); + ASR::expr_t* loop_end_value = ASRUtils::expr_value(loop_end); + ASR::expr_t* loop_inc_value = ASRUtils::expr_value(loop_inc); + if( !ASRUtils::is_value_constant(loop_start_value) || + !ASRUtils::is_value_constant(loop_end_value) || + !ASRUtils::is_value_constant(loop_inc_value) ) { + // Skip vectorisation of variable sized loops + return ; + } + ASR::stmt_t* loop_stmt = x.m_body[0]; + int64_t loop_start_int = -1, loop_end_int = -1, loop_inc_int = -1; + ASRUtils::extract_value(loop_start_value, loop_start_int); + ASRUtils::extract_value(loop_end_value, loop_end_int); + ASRUtils::extract_value(loop_inc_value, loop_inc_int); + int64_t loop_size = (loop_end_int - loop_start_int) / loop_inc_int + 1; + ASR::expr_t* vector_length = nullptr; + Vec vectorised_loop_body; + vectorised_loop_body.reserve(al, x.n_body); + get_vector_intrinsic(loop_stmt, x.m_head.m_v, + vector_length, vectorised_loop_body); + if( !vector_length ) { + return ; + } + ASR::do_loop_head_t vectorised_loop_head; + vectorised_loop_head.m_start = loop_start; + int64_t vector_length_int = -1; + ASRUtils::extract_value(vector_length, vector_length_int); + // TODO: Add tests for loop sizes not divisible by vector_length. + vectorised_loop_head.m_end = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, x.m_head.m_v->base.loc, + loop_size/vector_length_int - 1, ASRUtils::expr_type(x.m_head.m_v))); + // TODO: Update this for increments other 1. + ASR::expr_t* one = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loop_stmt->base.loc, + 1, ASRUtils::expr_type(x.m_head.m_v))); + vectorised_loop_head.m_increment = one; + vectorised_loop_head.m_v = x.m_head.m_v; + vectorised_loop_head.loc = x.m_head.loc; + + ASR::stmt_t* vectorised_loop = ASRUtils::STMT(ASR::make_DoLoop_t(al, x.base.base.loc, + vectorised_loop_head, vectorised_loop_body.p, + vectorised_loop_body.size())); + pass_result.push_back(al, vectorised_loop); + } + + void visit_DoLoop(const ASR::DoLoop_t& x) { + from_loop_vectorise = true; + if( x.n_body == 1 ) { + // Vectorise + if( is_loop(*x.m_body[0]) ) { + from_loop_vectorise = false; + visit_stmt(*x.m_body[0]); + return ; + } + vectorise_loop(x); + } + from_loop_vectorise = false; + } + +}; + +void pass_loop_vectorise(Allocator &al, ASR::TranslationUnit_t &unit, + const std::string& rl_path) { + LoopVectoriseVisitor v(al, unit, rl_path); + v.visit_TranslationUnit(unit); + LFORTRAN_ASSERT(asr_verify(unit)); +} + + +} // namespace LFortran diff --git a/src/libasr/pass/loop_vectorise.h b/src/libasr/pass/loop_vectorise.h new file mode 100644 index 0000000000..9b937b77bf --- /dev/null +++ b/src/libasr/pass/loop_vectorise.h @@ -0,0 +1,13 @@ +#ifndef LIBASR_PASS_LOOP_VECTORISE_H +#define LIBASR_PASS_LOOP_VECTORISE_H + +#include + +namespace LFortran { + + void pass_loop_vectorise(Allocator &al, ASR::TranslationUnit_t &unit, + const std::string& rl_path); + +} // namespace LFortran + +#endif // LIBASR_PASS_LOOP_VECTORISE_H diff --git a/src/libasr/pass/nested_vars.cpp b/src/libasr/pass/nested_vars.cpp index 26e2530e78..4d8a54c896 100644 --- a/src/libasr/pass/nested_vars.cpp +++ b/src/libasr/pass/nested_vars.cpp @@ -114,6 +114,16 @@ class NestedVarVisitor : public ASR::BaseWalkVisitor return type_ptr; } + inline llvm::Type* getLogicalType(int /*a_kind*/, bool get_pointer=false) { + llvm::Type* type_ptr = nullptr; + if (get_pointer) { + type_ptr = llvm::Type::getInt1PtrTy(context); + } else { + type_ptr = llvm::Type::getInt1Ty(context); + } + return type_ptr; + } + template void visit_procedure(const T &x) { nesting_depth++; @@ -298,9 +308,14 @@ class NestedVarVisitor : public ASR::BaseWalkVisitor rel_type = getFPType(a_kind)->getPointerTo(); break; } + case ASR::ttypeType::Logical: { + int a_kind = down_cast(v->m_type)-> + m_kind; + rel_type = getLogicalType(a_kind)->getPointerTo(); + break; + } default: { - throw LFortranException("Variable type not \ - supported in nested functions"); + throw LFortranException("Variable type not supported in nested functions"); break; } } diff --git a/src/libasr/pass/param_to_const.cpp b/src/libasr/pass/param_to_const.cpp index 28bab387f0..fbf68aa093 100644 --- a/src/libasr/pass/param_to_const.cpp +++ b/src/libasr/pass/param_to_const.cpp @@ -49,18 +49,56 @@ class VarVisitor : public ASR::BaseWalkVisitor } } - void visit_UnaryOp(const ASR::UnaryOp_t& x) { - ASR::UnaryOp_t& x_unconst = const_cast(x); + void visit_IntegerUnaryMinus(const ASR::IntegerUnaryMinus_t &x) { + visit_UnaryOp(x); + } + void visit_RealUnaryMinus(const ASR::RealUnaryMinus_t &x) { + visit_UnaryOp(x); + } + void visit_ComplexUnaryMinus(const ASR::ComplexUnaryMinus_t &x) { + visit_UnaryOp(x); + } + void visit_IntegerBitNot(const ASR::IntegerBitNot_t &x) { + visit_UnaryOp(x); + } + void visit_LogicalNot(const ASR::LogicalNot_t &x) { + visit_UnaryOp(x); + } + + template + void visit_UnaryOp(const T& x) { + T& x_unconst = const_cast(x); asr = nullptr; - this->visit_expr(*x.m_operand); + this->visit_expr(*x.m_arg); if( asr != nullptr ) { - x_unconst.m_operand = asr; + x_unconst.m_arg = asr; } asr = const_cast(&(x.base)); } - void visit_Compare(const ASR::Compare_t& x) { - ASR::Compare_t& x_unconst = const_cast(x); + void visit_IntegerCompare(const ASR::IntegerCompare_t& x) { + handle_Compare(x); + } + + void visit_RealCompare(const ASR::RealCompare_t &x) { + handle_Compare(x); + } + + void visit_ComplexCompare(const ASR::ComplexCompare_t &x) { + handle_Compare(x); + } + + void visit_LogicalCompare(const ASR::LogicalCompare_t &x) { + handle_Compare(x); + } + + void visit_StringCompare(const ASR::StringCompare_t &x) { + handle_Compare(x); + } + + template + void handle_Compare(const T& x) { + T& x_unconst = const_cast(x); asr = nullptr; this->visit_expr(*x.m_left); if( asr != nullptr ) { @@ -74,8 +112,25 @@ class VarVisitor : public ASR::BaseWalkVisitor asr = const_cast(&(x.base)); } - void visit_BinOp(const ASR::BinOp_t& x) { - ASR::BinOp_t& x_unconst = const_cast(x); + void visit_IntegerBinOp(const ASR::IntegerBinOp_t& x) { + handle_BinOp(x); + } + + void visit_RealBinOp(const ASR::RealBinOp_t& x) { + handle_BinOp(x); + } + + void visit_ComplexBinOp(const ASR::ComplexBinOp_t& x) { + handle_BinOp(x); + } + + void visit_LogicalBinOp(const ASR::LogicalBinOp_t& x) { + handle_BinOp(x); + } + + template + void handle_BinOp(const T& x) { + T& x_unconst = const_cast(x); asr = nullptr; this->visit_expr(*x.m_left); if( asr != nullptr ) { diff --git a/src/libasr/pass/pass_manager.h b/src/libasr/pass/pass_manager.h new file mode 100644 index 0000000000..6153b9660c --- /dev/null +++ b/src/libasr/pass/pass_manager.h @@ -0,0 +1,262 @@ +#ifndef LCOMPILERS_PASS_MANAGER_H +#define LCOMPILERS_PASS_MANAGER_H + +#include +#include +#include + +// TODO: Remove lpython/lfortran includes, make it compiler agnostic +#if __has_include() + #include +#endif + +#if __has_include() + #include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace LCompilers { + + enum ASRPass { + do_loops, global_stmts, implied_do_loops, array_op, + arr_slice, print_arr, class_constructor, unused_functions, + flip_sign, div_to_mul, fma, sign_from_value, + inline_function_calls, loop_unroll, dead_code_removal, + forall, select_case, loop_vectorise + }; + + class PassManager { + private: + + std::vector _passes; + std::vector _with_optimization_passes; + std::vector _user_defined_passes; + std::map _passes_db = { + {"do_loops", ASRPass::do_loops}, + {"global_stmts", ASRPass::global_stmts}, + {"implied_do_loops", ASRPass::implied_do_loops}, + {"array_op", ASRPass::array_op}, + {"arr_slice", ASRPass::arr_slice}, + {"print_arr", ASRPass::print_arr}, + {"class_constructor", ASRPass::class_constructor}, + {"unused_functions", ASRPass::unused_functions}, + {"flip_sign", ASRPass::flip_sign}, + {"div_to_mul", ASRPass::div_to_mul}, + {"fma", ASRPass::fma}, + {"sign_from_value", ASRPass::sign_from_value}, + {"inline_function_calls", ASRPass::inline_function_calls}, + {"loop_unroll", ASRPass::loop_unroll}, + {"dead_code_removal", ASRPass::dead_code_removal}, + {"forall", ASRPass::forall}, + {"select_case", ASRPass::select_case}, + {"loop_vectorise", ASRPass::loop_vectorise} + }; + + bool is_fast; + bool apply_default_passes; + + void _apply_passes(Allocator& al, LFortran::ASR::TranslationUnit_t* asr, + std::vector& passes, std::string& run_fun, + bool always_run) { + for (size_t i = 0; i < passes.size(); i++) { + switch (passes[i]) { + case (ASRPass::do_loops) : { + LFortran::pass_replace_do_loops(al, *asr); + break; + } + case (ASRPass::global_stmts) : { + LFortran::pass_wrap_global_stmts_into_function(al, *asr, run_fun); + break; + } + case (ASRPass::implied_do_loops) : { + LFortran::pass_replace_implied_do_loops(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::array_op) : { + LFortran::pass_replace_array_op(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::flip_sign) : { + LFortran::pass_replace_flip_sign(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::fma) : { + LFortran::pass_replace_fma(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::loop_unroll) : { + LFortran::pass_loop_unroll(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::inline_function_calls) : { + LFortran::pass_inline_function_calls(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::dead_code_removal) : { + LFortran::pass_dead_code_removal(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::sign_from_value) : { + LFortran::pass_replace_sign_from_value(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::div_to_mul) : { + LFortran::pass_replace_div_to_mul(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::class_constructor) : { + LFortran::pass_replace_class_constructor(al, *asr); + break; + } + case (ASRPass::arr_slice) : { + LFortran::pass_replace_arr_slice(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::print_arr) : { + LFortran::pass_replace_print_arr(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + case (ASRPass::unused_functions) : { + LFortran::pass_unused_functions(al, *asr, always_run); + break; + } + case (ASRPass::forall) : { + LFortran::pass_replace_forall(al, *asr); + break ; + } + case (ASRPass::select_case) : { + LFortran::pass_replace_select_case(al, *asr); + break; + } + case (ASRPass::loop_vectorise) : { + LFortran::pass_loop_vectorise(al, *asr, LFortran::get_runtime_library_dir()); + break; + } + } + } + } + + public: + + PassManager(): is_fast{false}, apply_default_passes{false} { + _passes = { + ASRPass::global_stmts, + ASRPass::class_constructor, + ASRPass::implied_do_loops, + ASRPass::arr_slice, + ASRPass::array_op, + ASRPass::print_arr, + ASRPass::do_loops, + ASRPass::forall, + ASRPass::select_case, + ASRPass::unused_functions + }; + + _with_optimization_passes = { + ASRPass::global_stmts, + ASRPass::class_constructor, + ASRPass::implied_do_loops, + ASRPass::arr_slice, + ASRPass::array_op, + ASRPass::print_arr, + ASRPass::loop_vectorise, + ASRPass::loop_unroll, + ASRPass::do_loops, + ASRPass::forall, + ASRPass::dead_code_removal, + ASRPass::select_case, + ASRPass::unused_functions, + ASRPass::flip_sign, + ASRPass::sign_from_value, + ASRPass::div_to_mul, + ASRPass::fma, + ASRPass::inline_function_calls + }; + + _user_defined_passes.clear(); + } + + void parse_pass_arg(std::string& arg_pass) { + _user_defined_passes.clear(); + if (arg_pass == "") { + return ; + } + + std::string current_pass = ""; + for( size_t i = 0; i < arg_pass.size(); i++ ) { + char ch = arg_pass[i]; + if( ch != ' ' && ch != ',' ) { + current_pass.push_back(ch); + } + if( ch == ',' || i == arg_pass.size() - 1 ) { + current_pass = LFortran::to_lower(current_pass); + if( _passes_db.find(current_pass) == _passes_db.end() ) { + std::cerr << current_pass << " isn't supported yet."; + std::cerr << " Only the following passes are supported:- "<& idx_vars, Allocator& al) { - ASR::Var_t* arr_var = ASR::down_cast(arr_expr); - ASR::symbol_t* arr = arr_var->m_v; - return create_array_ref(arr, idx_vars, al, arr_expr->base.loc, LFortran::ASRUtils::expr_type(LFortran::ASRUtils::EXPR((ASR::asr_t*)arr_var))); + Vec args; + args.reserve(al, 1); + for( size_t i = 0; i < idx_vars.size(); i++ ) { + ASR::array_index_t ai; + ai.loc = arr_expr->base.loc; + ai.m_left = nullptr; + ai.m_right = idx_vars[i]; + ai.m_step = nullptr; + args.push_back(al, ai); + } + Vec empty_dims; + empty_dims.reserve(al, 1); + ASR::ttype_t* _type = ASRUtils::expr_type(arr_expr); + _type = ASRUtils::duplicate_type(al, _type, &empty_dims); + ASR::expr_t* array_ref = LFortran::ASRUtils::EXPR(ASR::make_ArrayItem_t(al, + arr_expr->base.loc, arr_expr, + args.p, args.size(), + _type, nullptr)); + return array_ref; } ASR::expr_t* create_array_ref(ASR::symbol_t* arr, Vec& idx_vars, Allocator& al, @@ -173,7 +189,11 @@ namespace LFortran { ai.m_step = nullptr; args.push_back(al, ai); } - ASR::expr_t* array_ref = LFortran::ASRUtils::EXPR(ASR::make_ArrayRef_t(al, loc, arr, + Vec empty_dims; + empty_dims.reserve(al, 1); + _type = ASRUtils::duplicate_type(al, _type, &empty_dims); + ASR::expr_t* arr_var = ASRUtils::EXPR(ASR::make_Var_t(al, loc, arr)); + ASR::expr_t* array_ref = LFortran::ASRUtils::EXPR(ASR::make_ArrayItem_t(al, loc, arr_var, args.p, args.size(), _type, nullptr)); return array_ref; @@ -314,34 +334,50 @@ namespace LFortran { return v; } + ASR::expr_t* create_compare_helper(Allocator &al, const Location &loc, ASR::expr_t* left, ASR::expr_t* right, + ASR::cmpopType op) { + ASR::ttype_t* type = ASRUtils::expr_type(left); + // TODO: compute `value`: + if (ASRUtils::is_integer(*type)) { + return ASRUtils::EXPR(ASR::make_IntegerCompare_t(al, loc, left, op, right, type, nullptr)); + } else if (ASRUtils::is_real(*type)) { + return ASRUtils::EXPR(ASR::make_RealCompare_t(al, loc, left, op, right, type, nullptr)); + } else if (ASRUtils::is_complex(*type)) { + return ASRUtils::EXPR(ASR::make_ComplexCompare_t(al, loc, left, op, right, type, nullptr)); + } else if (ASRUtils::is_logical(*type)) { + return ASRUtils::EXPR(ASR::make_LogicalCompare_t(al, loc, left, op, right, type, nullptr)); + } else if (ASRUtils::is_character(*type)) { + return ASRUtils::EXPR(ASR::make_StringCompare_t(al, loc, left, op, right, type, nullptr)); + } else { + throw LFortranException("Type not supported"); + } + } + + ASR::expr_t* create_binop_helper(Allocator &al, const Location &loc, ASR::expr_t* left, ASR::expr_t* right, + ASR::binopType op) { + ASR::ttype_t* type = ASRUtils::expr_type(left); + // TODO: compute `value`: + if (ASRUtils::is_integer(*type)) { + return ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loc, left, op, right, type, nullptr)); + } else if (ASRUtils::is_real(*type)) { + return ASRUtils::EXPR(ASR::make_RealBinOp_t(al, loc, left, op, right, type, nullptr)); + } else if (ASRUtils::is_complex(*type)) { + return ASRUtils::EXPR(ASR::make_ComplexBinOp_t(al, loc, left, op, right, type, nullptr)); + } else { + throw LFortranException("Type not supported"); + } + } ASR::expr_t* get_bound(ASR::expr_t* arr_expr, int dim, std::string bound, - Allocator& al, ASR::TranslationUnit_t& unit, - const std::string& rl_path, - SymbolTable*& current_scope) { - // Loads ubound/lbound from the module already in ASR - ASR::symbol_t *v = import_function2(bound, "lpython_builtin", al, - unit, current_scope); - if (!v) { - // If it fails, try to load from the source until we fix - // LFortran to preload this module - v = import_function(bound, "lfortran_intrinsic_builtin", al, - unit, rl_path, current_scope, arr_expr->base.loc); + Allocator& al) { + ASR::ttype_t* int32_type = LFortran::ASRUtils::TYPE(ASR::make_Integer_t(al, arr_expr->base.loc, 4, nullptr, 0)); + ASR::expr_t* dim_expr = LFortran::ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, arr_expr->base.loc, dim, int32_type)); + ASR::arrayboundType bound_type = ASR::arrayboundType::LBound; + if( bound == "ubound" ) { + bound_type = ASR::arrayboundType::UBound; } - ASR::ExternalSymbol_t* v_ext = ASR::down_cast(v); - ASR::Function_t* mfn = ASR::down_cast(v_ext->m_external); - Vec args; - args.reserve(al, 2); - ASR::call_arg_t arg0, arg1; - arg0.loc = arr_expr->base.loc, arg0.m_value = arr_expr; - args.push_back(al, arg0); - ASR::expr_t* const_1 = LFortran::ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, arr_expr->base.loc, dim, LFortran::ASRUtils::expr_type(mfn->m_args[1]))); - arg1.loc = const_1->base.loc, arg1.m_value = const_1; - args.push_back(al, arg1); - ASR::ttype_t *type = LFortran::ASRUtils::EXPR2VAR(ASR::down_cast( - LFortran::ASRUtils::symbol_get_past_external(v))->m_return_var)->m_type; - return LFortran::ASRUtils::EXPR(ASR::make_FunctionCall_t(al, arr_expr->base.loc, v, nullptr, - args.p, args.size(), type, nullptr, nullptr)); + return LFortran::ASRUtils::EXPR(ASR::make_ArrayBound_t(al, arr_expr->base.loc, arr_expr, dim_expr, + int32_type, bound_type, nullptr)); } @@ -390,25 +426,6 @@ namespace LFortran { return nullptr; } - bool is_slice_present(const ASR::ArrayRef_t& x) { - bool slice_present = false; - for( size_t i = 0; i < x.n_args; i++ ) { - if( x.m_args[i].m_step != nullptr ) { - slice_present = true; - break; - } - } - return slice_present; - } - - bool is_slice_present(const ASR::expr_t* x) { - if( x == nullptr || x->type != ASR::exprType::ArrayRef ) { - return false; - } - ASR::ArrayRef_t* array_ref = ASR::down_cast(x); - return is_slice_present(*array_ref); - } - ASR::expr_t* create_auxiliary_variable_for_expr(ASR::expr_t* expr, std::string& name, Allocator& al, SymbolTable*& current_scope, ASR::stmt_t*& assign_stmt) { ASR::asr_t* expr_sym = ASR::make_Variable_t(al, expr->base.loc, current_scope, s2c(al, name), @@ -460,6 +477,97 @@ namespace LFortran { loc, v, args, current_scope, al, err)); } + ASR::symbol_t* insert_fallback_vector_copy(Allocator& al, ASR::TranslationUnit_t& unit, + SymbolTable*& global_scope, std::vector& types, + std::string prefix) { + const int num_args = 6; + std::string vector_copy_name = prefix; + for( ASR::ttype_t*& type: types ) { + vector_copy_name += ASRUtils::type_to_str_python(type, false); + } + vector_copy_name += "@IntrinsicOptimization"; + if( global_scope->resolve_symbol(vector_copy_name) ) { + return global_scope->resolve_symbol(vector_copy_name); + } + Vec arg_exprs; + arg_exprs.reserve(al, num_args); + SymbolTable* vector_copy_symtab = al.make_new(global_scope); + for( int i = 0; i < num_args; i++ ) { + std::string arg_name = "arg" + std::to_string(i); + ASR::symbol_t* arg = ASR::down_cast(ASR::make_Variable_t(al, unit.base.base.loc, vector_copy_symtab, + s2c(al, arg_name), ASR::intentType::In, nullptr, nullptr, ASR::storage_typeType::Default, + types[std::min(i, (int) types.size() - 1)], ASR::abiType::Source, ASR::accessType::Public, + ASR::presenceType::Required, false)); + ASR::expr_t* arg_expr = ASRUtils::EXPR(ASR::make_Var_t(al, arg->base.loc, arg)); + arg_exprs.push_back(al, arg_expr); + vector_copy_symtab->add_symbol(arg_name, arg); + } + Vec body; + body.reserve(al, 1); + ASR::do_loop_head_t do_loop_head; + do_loop_head.m_start = arg_exprs[2]; + do_loop_head.m_end = arg_exprs[3]; + do_loop_head.m_increment = arg_exprs[4]; + do_loop_head.loc = arg_exprs[2]->base.loc; + Vec idx_vars; + create_idx_vars(idx_vars, 1, arg_exprs[2]->base.loc, + al, vector_copy_symtab); + do_loop_head.m_v = idx_vars[0]; + Vec loop_body; + loop_body.reserve(al, 1); + ASR::expr_t* target = create_array_ref(arg_exprs[0], idx_vars, al); + ASR::expr_t* value = create_array_ref(arg_exprs[1], idx_vars, al); + ASR::stmt_t* copy_stmt = ASRUtils::STMT(ASR::make_Assignment_t(al, target->base.loc, + target, value, nullptr)); + loop_body.push_back(al, copy_stmt); + ASR::stmt_t* fallback_loop = ASRUtils::STMT(ASR::make_DoLoop_t(al, do_loop_head.loc, + do_loop_head, loop_body.p, loop_body.size())); + Vec fallback_while_loop = replace_doloop(al, *ASR::down_cast(fallback_loop), + (int) ASR::cmpopType::Lt); + for( size_t i = 0; i < fallback_while_loop.size(); i++ ) { + body.push_back(al, fallback_while_loop[i]); + } + ASR::asr_t* vector_copy_asr = ASR::make_Subroutine_t(al, unit.base.base.loc, vector_copy_symtab, + s2c(al, vector_copy_name), arg_exprs.p, arg_exprs.size(), body.p, + body.size(), ASR::abiType::Source, ASR::accessType::Public, ASR::deftypeType::Implementation, + nullptr, false, false); + global_scope->add_symbol(vector_copy_name, ASR::down_cast(vector_copy_asr)); + return ASR::down_cast(vector_copy_asr); + } + + ASR::stmt_t* get_vector_copy(ASR::expr_t* array0, ASR::expr_t* array1, ASR::expr_t* start, + ASR::expr_t* end, ASR::expr_t* step, ASR::expr_t* vector_length, + Allocator& al, ASR::TranslationUnit_t& unit, + SymbolTable*& global_scope, Location& loc) { + ASR::ttype_t* array0_type = ASRUtils::expr_type(array0); + ASR::ttype_t* array1_type = ASRUtils::expr_type(array1); + ASR::ttype_t* index_type = ASRUtils::expr_type(start); + std::vector types = {array0_type, array1_type, index_type}; + ASR::symbol_t *v = insert_fallback_vector_copy(al, unit, global_scope, + types, + "vector_copy_"); + Vec args; + args.reserve(al, 6); + ASR::call_arg_t arg0_, arg1_, arg2_, arg3_, arg4_, arg5_; + ASR::expr_t* array0_expr = array0; + arg0_.loc = array0->base.loc, arg0_.m_value = array0_expr; + args.push_back(al, arg0_); + ASR::expr_t* array1_expr = array1; + arg1_.loc = array1->base.loc, arg1_.m_value = array1_expr; + args.push_back(al, arg1_); + arg2_.loc = start->base.loc, arg2_.m_value = start; + args.push_back(al, arg2_); + arg3_.loc = end->base.loc, arg3_.m_value = end; + args.push_back(al, arg3_); + arg4_.loc = step->base.loc, arg4_.m_value = step; + args.push_back(al, arg4_); + arg5_.loc = vector_length->base.loc, arg5_.m_value = vector_length; + args.push_back(al, arg5_); + return ASRUtils::STMT(ASR::make_SubroutineCall_t(al, loc, v, + nullptr, args.p, args.size(), + nullptr)); + } + ASR::expr_t* get_sign_from_value(ASR::expr_t* arg0, ASR::expr_t* arg1, Allocator& al, ASR::TranslationUnit_t& unit, std::string& rl_path, SymbolTable*& current_scope, Location& loc, @@ -478,7 +586,8 @@ namespace LFortran { loc, v, args, current_scope, al, err)); } - Vec replace_doloop(Allocator &al, const ASR::DoLoop_t &loop) { + Vec replace_doloop(Allocator &al, const ASR::DoLoop_t &loop, + int comp) { Location loc = loop.base.base.loc; ASR::expr_t *a=loop.m_head.m_start; ASR::expr_t *b=loop.m_head.m_end; @@ -497,36 +606,36 @@ namespace LFortran { c = LFortran::ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 1, type)); } LFORTRAN_ASSERT(c); - int increment; - if (c->type == ASR::exprType::IntegerConstant) { - increment = ASR::down_cast(c)->m_n; - } else if (c->type == ASR::exprType::UnaryOp) { - ASR::UnaryOp_t *u = ASR::down_cast(c); - LFORTRAN_ASSERT(u->m_op == ASR::unaryopType::USub); - LFORTRAN_ASSERT(u->m_operand->type == ASR::exprType::IntegerConstant); - increment = - ASR::down_cast(u->m_operand)->m_n; - } else { - throw LFortranException("Do loop increment type not supported"); - } ASR::cmpopType cmp_op; - if (increment > 0) { - cmp_op = ASR::cmpopType::LtE; + if( comp == -1 ) { + int increment; + if (c->type == ASR::exprType::IntegerConstant) { + increment = ASR::down_cast(c)->m_n; + } else if (c->type == ASR::exprType::IntegerUnaryMinus) { + ASR::IntegerUnaryMinus_t *u = ASR::down_cast(c); + increment = - ASR::down_cast(u->m_arg)->m_n; + } else { + throw LFortranException("Do loop increment type not supported"); + } + if (increment > 0) { + cmp_op = ASR::cmpopType::LtE; + } else { + cmp_op = ASR::cmpopType::GtE; + } } else { - cmp_op = ASR::cmpopType::GtE; + cmp_op = (ASR::cmpopType) comp; } ASR::expr_t *target = loop.m_head.m_v; ASR::ttype_t *type = LFortran::ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4, nullptr, 0)); stmt1 = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, loc, target, - LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, loc, a, ASR::binopType::Sub, c, type, nullptr, nullptr)), - nullptr)); + LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loc, a, ASR::binopType::Sub, c, type, nullptr)), nullptr)); - cond = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, - LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, loc, target, ASR::binopType::Add, c, type, nullptr, nullptr)), - cmp_op, b, type, nullptr, nullptr)); + cond = LFortran::ASRUtils::EXPR(ASR::make_IntegerCompare_t(al, loc, + LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loc, target, ASR::binopType::Add, c, type, nullptr)), + cmp_op, b, type, nullptr)); inc_stmt = LFortran::ASRUtils::STMT(ASR::make_Assignment_t(al, loc, target, - LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, loc, target, ASR::binopType::Add, c, type, nullptr, nullptr)), - nullptr)); + LFortran::ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loc, target, ASR::binopType::Add, c, type, nullptr)), nullptr)); } Vec body; body.reserve(al, loop.n_body + (inc_stmt != nullptr)); diff --git a/src/libasr/pass/pass_utils.h b/src/libasr/pass/pass_utils.h index e4cab450a0..6e101ef94c 100644 --- a/src/libasr/pass/pass_utils.h +++ b/src/libasr/pass/pass_utils.h @@ -25,10 +25,14 @@ namespace LFortran { void create_idx_vars(Vec& idx_vars, int n_dims, const Location& loc, Allocator& al, SymbolTable*& current_scope, std::string suffix="_k"); + ASR::expr_t* create_compare_helper(Allocator &al, const Location &loc, ASR::expr_t* left, ASR::expr_t* right, + ASR::cmpopType op); + + ASR::expr_t* create_binop_helper(Allocator &al, const Location &loc, ASR::expr_t* left, ASR::expr_t* right, + ASR::binopType op); + ASR::expr_t* get_bound(ASR::expr_t* arr_expr, int dim, std::string bound, - Allocator& al, ASR::TranslationUnit_t& unit, - const std::string &rl_path, - SymbolTable*& current_scope); + Allocator& al); ASR::stmt_t* get_flipsign(ASR::expr_t* arg0, ASR::expr_t* arg1, @@ -39,10 +43,6 @@ namespace LFortran { ASR::expr_t* to_int32(ASR::expr_t* x, ASR::ttype_t* int32type, Allocator& al); - bool is_slice_present(const ASR::ArrayRef_t& x); - - bool is_slice_present(const ASR::expr_t* x); - ASR::expr_t* create_auxiliary_variable_for_expr(ASR::expr_t* expr, std::string& name, Allocator& al, SymbolTable*& current_scope, ASR::stmt_t*& assign_stmt); @@ -59,7 +59,13 @@ namespace LFortran { SymbolTable*& current_scope, Location& loc, const std::function err); - Vec replace_doloop(Allocator &al, const ASR::DoLoop_t &loop); + ASR::stmt_t* get_vector_copy(ASR::expr_t* array0, ASR::expr_t* array1, ASR::expr_t* start, + ASR::expr_t* end, ASR::expr_t* step, ASR::expr_t* vector_length, + Allocator& al, ASR::TranslationUnit_t& unit, + SymbolTable*& global_scope, Location& loc); + + Vec replace_doloop(Allocator &al, const ASR::DoLoop_t &loop, + int comp=-1); template class PassVisitor: public ASR::BaseWalkVisitor { @@ -70,7 +76,7 @@ namespace LFortran { public: - bool asr_changed, retain_original_stmt; + bool asr_changed, retain_original_stmt, remove_original_stmt; Allocator& al; Vec pass_result; SymbolTable* current_scope; @@ -83,11 +89,19 @@ namespace LFortran { void transform_stmts(ASR::stmt_t **&m_body, size_t &n_body) { Vec body; body.reserve(al, n_body); + if (pass_result.size() > 0) { + asr_changed = true; + for (size_t j=0; j < pass_result.size(); j++) { + body.push_back(al, pass_result[j]); + } + pass_result.n = 0; + } for (size_t i=0; i 0) { asr_changed = true; @@ -99,7 +113,7 @@ namespace LFortran { retain_original_stmt = false; } pass_result.n = 0; - } else { + } else if(!remove_original_stmt) { body.push_back(al, m_body[i]); } } @@ -124,6 +138,10 @@ namespace LFortran { ASR::Function_t *s = ASR::down_cast(item.second); self().visit_Function(*s); } + if (ASR::is_a(*item.second)) { + ASR::AssociateBlock_t *s = ASR::down_cast(item.second); + self().visit_AssociateBlock(*s); + } } } @@ -143,6 +161,12 @@ namespace LFortran { transform_stmts(xx.m_body, xx.n_body); } + void visit_AssociateBlock(const ASR::AssociateBlock_t& x) { + ASR::AssociateBlock_t &xx = const_cast(x); + current_scope = xx.m_symtab; + transform_stmts(xx.m_body, xx.n_body); + } + }; template diff --git a/src/libasr/pass/print_arr.cpp b/src/libasr/pass/print_arr.cpp index 8290869bb6..fb8d978865 100644 --- a/src/libasr/pass/print_arr.cpp +++ b/src/libasr/pass/print_arr.cpp @@ -30,11 +30,9 @@ The function `pass_replace_print_arr` transforms the ASR tree in-place. class PrintArrVisitor : public PassUtils::PassVisitor { private: - ASR::TranslationUnit_t &unit; std::string rl_path; public: - PrintArrVisitor(Allocator &al, ASR::TranslationUnit_t &unit_, - const std::string &rl_path_) : PassVisitor(al, nullptr), unit(unit_), + PrintArrVisitor(Allocator &al, const std::string &rl_path_) : PassVisitor(al, nullptr), rl_path(rl_path_) { pass_result.reserve(al, 1); @@ -48,12 +46,13 @@ class PrintArrVisitor : public PassUtils::PassVisitor Vec idx_vars; PassUtils::create_idx_vars(idx_vars, n_dims, x.base.base.loc, al, current_scope); ASR::stmt_t* doloop = nullptr; - ASR::stmt_t* empty_print_endl = LFortran::ASRUtils::STMT(ASR::make_Print_t(al, x.base.base.loc, nullptr, nullptr, 0)); + ASR::stmt_t* empty_print_endl = LFortran::ASRUtils::STMT(ASR::make_Print_t(al, x.base.base.loc, + nullptr, nullptr, 0, nullptr, nullptr)); for( int i = n_dims - 1; i >= 0; i-- ) { ASR::do_loop_head_t head; head.m_v = idx_vars[i]; - head.m_start = PassUtils::get_bound(arr_expr, i + 1, "lbound", al, unit, rl_path, current_scope); - head.m_end = PassUtils::get_bound(arr_expr, i + 1, "ubound", al, unit, rl_path, current_scope); + head.m_start = PassUtils::get_bound(arr_expr, i + 1, "lbound", al); + head.m_end = PassUtils::get_bound(arr_expr, i + 1, "ubound", al); head.m_increment = nullptr; head.loc = head.m_v->base.loc; Vec doloop_body; @@ -64,7 +63,7 @@ class PrintArrVisitor : public PassUtils::PassVisitor print_args.reserve(al, 1); print_args.push_back(al, ref); ASR::stmt_t* print_stmt = LFortran::ASRUtils::STMT(ASR::make_Print_t(al, x.base.base.loc, nullptr, - print_args.p, print_args.size())); + print_args.p, print_args.size(), nullptr, nullptr)); doloop_body.push_back(al, print_stmt); } else { doloop_body.push_back(al, doloop); @@ -81,7 +80,7 @@ class PrintArrVisitor : public PassUtils::PassVisitor void pass_replace_print_arr(Allocator &al, ASR::TranslationUnit_t &unit, const std::string &rl_path) { - PrintArrVisitor v(al, unit, rl_path); + PrintArrVisitor v(al, rl_path); v.visit_TranslationUnit(unit); LFORTRAN_ASSERT(asr_verify(unit)); } diff --git a/src/libasr/pass/select_case.cpp b/src/libasr/pass/select_case.cpp index ec06ecf599..c923de521a 100644 --- a/src/libasr/pass/select_case.cpp +++ b/src/libasr/pass/select_case.cpp @@ -51,18 +51,18 @@ This ASR pass replaces select-case construct with if-then-else-if statements. Th inline ASR::expr_t* gen_test_expr_CaseStmt(Allocator& al, const Location& loc, ASR::CaseStmt_t* Case_Stmt, ASR::expr_t* a_test) { ASR::expr_t* test_expr = nullptr; if( Case_Stmt->n_test == 1 ) { - test_expr = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, a_test, ASR::cmpopType::Eq, Case_Stmt->m_test[0], LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); + test_expr = PassUtils::create_compare_helper(al, loc, a_test, Case_Stmt->m_test[0], ASR::cmpopType::Eq); } else if( Case_Stmt->n_test == 2 ) { - ASR::expr_t* left = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, a_test, ASR::cmpopType::Eq, Case_Stmt->m_test[0], LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); - ASR::expr_t* right = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, a_test, ASR::cmpopType::Eq, Case_Stmt->m_test[1], LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); - test_expr = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, loc, left, ASR::binopType::Add, right, LFortran::ASRUtils::expr_type(left), nullptr, nullptr)); + ASR::expr_t* left = PassUtils::create_compare_helper(al, loc, a_test, Case_Stmt->m_test[0], ASR::cmpopType::Eq); + ASR::expr_t* right = PassUtils::create_compare_helper(al, loc, a_test, Case_Stmt->m_test[1], ASR::cmpopType::Eq); + test_expr = PassUtils::create_binop_helper(al, loc, left, right, ASR::binopType::Add); } else { - ASR::expr_t* left = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, a_test, ASR::cmpopType::Eq, Case_Stmt->m_test[0], LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); - ASR::expr_t* right = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, a_test, ASR::cmpopType::Eq, Case_Stmt->m_test[1], LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); - test_expr = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, loc, left, ASR::binopType::Add, right, LFortran::ASRUtils::expr_type(left), nullptr, nullptr)); + ASR::expr_t* left = PassUtils::create_compare_helper(al, loc, a_test, Case_Stmt->m_test[0], ASR::cmpopType::Eq); + ASR::expr_t* right = PassUtils::create_compare_helper(al, loc, a_test, Case_Stmt->m_test[1], ASR::cmpopType::Eq); + test_expr = PassUtils::create_binop_helper(al, loc, left, right, ASR::binopType::Add); for( std::uint32_t j = 2; j < Case_Stmt->n_test; j++ ) { - ASR::expr_t* newExpr = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, a_test, ASR::cmpopType::Eq, Case_Stmt->m_test[j], LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); - test_expr = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, loc, test_expr, ASR::binopType::Add, newExpr, LFortran::ASRUtils::expr_type(newExpr), nullptr, nullptr)); + ASR::expr_t* newExpr = PassUtils::create_compare_helper(al, loc, a_test, Case_Stmt->m_test[j], ASR::cmpopType::Eq); + test_expr = PassUtils::create_binop_helper(al, loc, test_expr, newExpr, ASR::binopType::Add); } } return test_expr; @@ -71,13 +71,13 @@ inline ASR::expr_t* gen_test_expr_CaseStmt(Allocator& al, const Location& loc, A inline ASR::expr_t* gen_test_expr_CaseStmt_Range(Allocator& al, const Location& loc, ASR::CaseStmt_Range_t* Case_Stmt, ASR::expr_t* a_test) { ASR::expr_t* test_expr = nullptr; if( Case_Stmt->m_start != nullptr && Case_Stmt->m_end == nullptr ) { - test_expr = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, Case_Stmt->m_start, ASR::cmpopType::LtE, a_test, LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); + test_expr = PassUtils::create_compare_helper(al, loc, Case_Stmt->m_start, a_test, ASR::cmpopType::LtE); } else if( Case_Stmt->m_start == nullptr && Case_Stmt->m_end != nullptr ) { - test_expr = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, a_test, ASR::cmpopType::LtE, Case_Stmt->m_end, LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); + test_expr = PassUtils::create_compare_helper(al, loc, a_test, Case_Stmt->m_end, ASR::cmpopType::LtE); } else if( Case_Stmt->m_start != nullptr && Case_Stmt->m_end != nullptr ) { - ASR::expr_t* left = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, Case_Stmt->m_start, ASR::cmpopType::LtE, a_test, LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); - ASR::expr_t* right = LFortran::ASRUtils::EXPR(ASR::make_Compare_t(al, loc, a_test, ASR::cmpopType::LtE, Case_Stmt->m_end, LFortran::ASRUtils::expr_type(a_test), nullptr, nullptr)); - test_expr = LFortran::ASRUtils::EXPR(ASR::make_BinOp_t(al, loc, left, ASR::binopType::Mul, right, LFortran::ASRUtils::expr_type(left), nullptr, nullptr)); + ASR::expr_t* left = PassUtils::create_compare_helper(al, loc, Case_Stmt->m_start, a_test, ASR::cmpopType::LtE); + ASR::expr_t* right = PassUtils::create_compare_helper(al, loc, a_test, Case_Stmt->m_end, ASR::cmpopType::LtE); + test_expr = PassUtils::create_binop_helper(al, loc, left, right, ASR::binopType::Mul); } return test_expr; } @@ -90,13 +90,13 @@ void case_to_if(Allocator& al, const ASR::Select_t& x, ASR::expr_t* a_test, Vec< case ASR::case_stmtType::CaseStmt: { ASR::CaseStmt_t* Case_Stmt = (ASR::CaseStmt_t*)(&(case_body->base)); ASR::expr_t* test_expr = gen_test_expr_CaseStmt(al, x.base.base.loc, Case_Stmt, a_test); - last_if_else = LFortran::ASRUtils::STMT(ASR::make_If_t(al, x.base.base.loc, test_expr, Case_Stmt->m_body, Case_Stmt->n_body, x.m_default, x.n_default)); + last_if_else = ASRUtils::STMT(ASR::make_If_t(al, x.base.base.loc, test_expr, Case_Stmt->m_body, Case_Stmt->n_body, x.m_default, x.n_default)); break; } case ASR::case_stmtType::CaseStmt_Range: { ASR::CaseStmt_Range_t* Case_Stmt = (ASR::CaseStmt_Range_t*)(&(case_body->base)); ASR::expr_t* test_expr = gen_test_expr_CaseStmt_Range(al, x.base.base.loc, Case_Stmt, a_test); - last_if_else = LFortran::ASRUtils::STMT(ASR::make_If_t(al, x.base.base.loc, test_expr, Case_Stmt->m_body, Case_Stmt->n_body, x.m_default, x.n_default)); + last_if_else = ASRUtils::STMT(ASR::make_If_t(al, x.base.base.loc, test_expr, Case_Stmt->m_body, Case_Stmt->n_body, x.m_default, x.n_default)); break; } } @@ -125,7 +125,7 @@ void case_to_if(Allocator& al, const ASR::Select_t& x, ASR::expr_t* a_test, Vec< Vec if_body_vec; if_body_vec.reserve(al, 1); if_body_vec.push_back(al, last_if_else); - last_if_else = LFortran::ASRUtils::STMT(ASR::make_If_t(al, x.base.base.loc, test_expr, m_body, n_body, if_body_vec.p, if_body_vec.size())); + last_if_else = ASRUtils::STMT(ASR::make_If_t(al, x.base.base.loc, test_expr, m_body, n_body, if_body_vec.p, if_body_vec.size())); } body.reserve(al, 1); body.push_back(al, last_if_else); diff --git a/src/libasr/pass/sign_from_value.cpp b/src/libasr/pass/sign_from_value.cpp index a21b2876a7..991b6ca00d 100644 --- a/src/libasr/pass/sign_from_value.cpp +++ b/src/libasr/pass/sign_from_value.cpp @@ -69,7 +69,7 @@ class SignFromValueVisitor : public PassUtils::SkipOptimizationFunctionVisitor(func_sym); - if( ASRUtils::is_intrinsic_function(func) && + if( ASRUtils::is_intrinsic_procedure(func) && std::string(func->m_name).find("sign") == std::string::npos ) { return nullptr; } @@ -80,13 +80,26 @@ class SignFromValueVisitor : public PassUtils::SkipOptimizationFunctionVisitor + void handle_BinOp(const T& x_const) { if( !from_sign_from_value ) { return ; } from_sign_from_value = true; - ASR::BinOp_t& x = const_cast(x_const); + T& x = const_cast(x_const); sign_from_value_var = nullptr; visit_expr(*x.m_left); diff --git a/src/libasr/pass/unused_functions.cpp b/src/libasr/pass/unused_functions.cpp index 86915f5802..0a042c344a 100644 --- a/src/libasr/pass/unused_functions.cpp +++ b/src/libasr/pass/unused_functions.cpp @@ -244,8 +244,9 @@ class UnusedFunctionsVisitor : public ASR::BaseWalkVisitor fn_unused; diff --git a/src/libasr/pass/unused_functions.h b/src/libasr/pass/unused_functions.h index d0e0d6c33b..ea723c34b3 100644 --- a/src/libasr/pass/unused_functions.h +++ b/src/libasr/pass/unused_functions.h @@ -5,7 +5,8 @@ namespace LFortran { - void pass_unused_functions(Allocator &al, ASR::TranslationUnit_t &unit); + void pass_unused_functions(Allocator &al, ASR::TranslationUnit_t &unit, + bool always_run); } // namespace LFortran diff --git a/src/libasr/serialization.cpp b/src/libasr/serialization.cpp index 6879f0ae2d..1919e40ceb 100644 --- a/src/libasr/serialization.cpp +++ b/src/libasr/serialization.cpp @@ -202,6 +202,28 @@ class FixParentSymtabVisitor : public BaseWalkVisitor current_symtab = parent_symtab; } + void visit_AssociateBlock(const AssociateBlock_t &x) { + SymbolTable *parent_symtab = current_symtab; + current_symtab = x.m_symtab; + x.m_symtab->parent = parent_symtab; + x.m_symtab->asr_owner = (asr_t*)&x; + for (auto &a : x.m_symtab->get_scope()) { + this->visit_symbol(*a.second); + } + current_symtab = parent_symtab; + } + + void visit_Block(const Block_t &x) { + SymbolTable *parent_symtab = current_symtab; + current_symtab = x.m_symtab; + x.m_symtab->parent = parent_symtab; + x.m_symtab->asr_owner = (asr_t*)&x; + for (auto &a : x.m_symtab->get_scope()) { + this->visit_symbol(*a.second); + } + current_symtab = parent_symtab; + } + void visit_Function(const Function_t &x) { SymbolTable *parent_symtab = current_symtab; current_symtab = x.m_symtab; diff --git a/src/libasr/utils.h b/src/libasr/utils.h index baeed78d4d..8c76264a04 100644 --- a/src/libasr/utils.h +++ b/src/libasr/utils.h @@ -21,6 +21,7 @@ struct CompilerOptions { bool c_preprocessor = false; std::vector c_preprocessor_defines; bool prescan = true; + bool disable_main = false; bool symtab_only = false; bool show_stacktrace = false; bool use_colors = true; diff --git a/src/libasr/wasm_instructions.txt b/src/libasr/wasm_instructions.txt new file mode 100644 index 0000000000..e28dc3cc07 --- /dev/null +++ b/src/libasr/wasm_instructions.txt @@ -0,0 +1,437 @@ +0x40 ⇒ emtpy_block_type +0x00 ⇒ unreachable +0x01 ⇒ nop +-- 0x02 bt:blocktype (in:instr)* 0x0B ⇒ block bt in* end +-- 0x03 bt:blocktype (in:instr)* 0x0B ⇒ loop bt in* end +0x04 ⇒ if +0x05 ⇒ else +0x0C u32:labelidx:𝑙 ⇒ br 𝑙 +0x0D u32:labelidx:𝑙 ⇒ br_if 𝑙 +-- 0x0E 𝑙*:vec(labelidx) 𝑙𝑁:labelidx ⇒ br_table 𝑙* 𝑙𝑁 +0x0F ⇒ return +0x10 u32:funcidx:𝑥 ⇒ call 𝑥 +0x11 u32:typeidx:𝑥 u32:tableidx:𝑦 ⇒ call_indirect 𝑥 𝑦 +0xD0 u8:reftype:𝑡 ⇒ ref.null 𝑡 +0xD1 ⇒ ref.is_null +0xD2 u32:funcidx:𝑥 ⇒ ref.func 𝑥 +0x1A ⇒ drop +0x1B ⇒ select +-- 0x1C 𝑡*:vec(valtype) ⇒ select 𝑡* +0x20 u32:localidx:𝑥 ⇒ local.get 𝑥 +0x21 u32:localidx:𝑥 ⇒ local.set 𝑥 +0x22 u32:localidx:𝑥 ⇒ local.tee 𝑥 +0x23 u32:globalidx:𝑥 ⇒ global.get 𝑥 +0x24 u32:globalidx:𝑥 ⇒ global.set 𝑥 +0x25 u32:tableidx:𝑥 ⇒ table.get 𝑥 +0x26 u32:tableidx:𝑥 ⇒ table.set 𝑥 +0xFC u32:num:12 u32:elemidx:𝑥 u32:tableidx:𝑦 ⇒ table.init 𝑥 𝑦 +0xFC u32:num:13 u32:elemidx:𝑥 ⇒ elem.drop 𝑥 +0xFC u32:num:14 u32:des_tableidx:𝑥 u32:src_tableidx:𝑦 ⇒ table.copy 𝑥 𝑦 +0xFC u32:num:15 u32:tableidx:𝑥 ⇒ table.grow 𝑥 +0xFC u32:num:16 u32:tableidx:𝑥 ⇒ table.size 𝑥 +0xFC u32:num:17 u32:tableidx:𝑥 ⇒ table.fill 𝑥 +0x28 u32:align:𝒶 u32:offset:𝑜 ⇒ i32.load 𝑚 +0x29 u32:align:𝒶 u32:offset:𝑜 ⇒ i64.load 𝑚 +0x2A u32:align:𝒶 u32:offset:𝑜 ⇒ f32.load 𝑚 +0x2B u32:align:𝒶 u32:offset:𝑜 ⇒ f64.load 𝑚 +0x2C u32:align:𝒶 u32:offset:𝑜 ⇒ i32.load8_s 𝑚 +0x2D u32:align:𝒶 u32:offset:𝑜 ⇒ i32.load8_u 𝑚 +0x2E u32:align:𝒶 u32:offset:𝑜 ⇒ i32.load16_s 𝑚 +0x2F u32:align:𝒶 u32:offset:𝑜 ⇒ i32.load16_u 𝑚 +0x30 u32:align:𝒶 u32:offset:𝑜 ⇒ i64.load8_s 𝑚 +0x31 u32:align:𝒶 u32:offset:𝑜 ⇒ i64.load8_u 𝑚 +0x32 u32:align:𝒶 u32:offset:𝑜 ⇒ i64.load16_s 𝑚 +0x33 u32:align:𝒶 u32:offset:𝑜 ⇒ i64.load16_u 𝑚 +0x34 u32:align:𝒶 u32:offset:𝑜 ⇒ i64.load32_s 𝑚 +0x35 u32:align:𝒶 u32:offset:𝑜 ⇒ i64.load32_u 𝑚 +0x36 u32:align:𝒶 u32:offset:𝑜 ⇒ i32.store 𝑚 +0x37 u32:align:𝒶 u32:offset:𝑜 ⇒ i64.store 𝑚 +0x38 u32:align:𝒶 u32:offset:𝑜 ⇒ f32.store 𝑚 +0x39 u32:align:𝒶 u32:offset:𝑜 ⇒ f64.store 𝑚 +0x3A u32:align:𝒶 u32:offset:𝑜 ⇒ i32.store8 𝑚 +0x3B u32:align:𝒶 u32:offset:𝑜 ⇒ i32.store16 𝑚 +0x3C u32:align:𝒶 u32:offset:𝑜 ⇒ i64.store8 𝑚 +0x3D u32:align:𝒶 u32:offset:𝑜 ⇒ i64.store16 𝑚 +0x3E u32:align:𝒶 u32:offset:𝑜 ⇒ i64.store32 𝑚 +-- 0x3F u8:temp_byte:0x00 ⇒ memory.size +-- 0x40 u8:temp_byte:0x00 ⇒ memory.grow +-- 0xFC u32:num:8 u32:dataidx:𝑥 u8:temp_byte:0x00 ⇒ memory.init 𝑥 +0xFC u32:num:9 u32:dataidx:𝑥 ⇒ data.drop 𝑥 +-- 0xFC u32:num:10 u8:temp_byte1:0x00 u8:temp_byte2:0x00 ⇒ memory.copy +-- 0xFC u32:num:11 u8:temp_byte:0x00 ⇒ memory.fill +0x41 i32:n:𝑛 ⇒ i32.const 𝑛 +0x42 i64:n:𝑛 ⇒ i64.const 𝑛 +0x43 f32:z:𝑧 ⇒ f32.const 𝑧 +0x44 f64:z:𝑧 ⇒ f64.const 𝑧 +0x45 ⇒ i32.eqz +0x46 ⇒ i32.eq +0x47 ⇒ i32.ne +0x48 ⇒ i32.lt_s +0x49 ⇒ i32.lt_u +0x4A ⇒ i32.gt_s +0x4B ⇒ i32.gt_u +0x4C ⇒ i32.le_s +0x4D ⇒ i32.le_u +0x4E ⇒ i32.ge_s +0x4F ⇒ i32.ge_u +0x50 ⇒ i64.eqz +0x51 ⇒ i64.eq +0x52 ⇒ i64.ne +0x53 ⇒ i64.lt_s +0x54 ⇒ i64.lt_u +0x55 ⇒ i64.gt_s +0x56 ⇒ i64.gt_u +0x57 ⇒ i64.le_s +0x58 ⇒ i64.le_u +0x59 ⇒ i64.ge_s +0x5A ⇒ i64.ge_u +0x5B ⇒ f32.eq +0x5C ⇒ f32.ne +0x5D ⇒ f32.lt +0x5E ⇒ f32.gt +0x5F ⇒ f32.le +0x60 ⇒ f32.ge +0x61 ⇒ f64.eq +0x62 ⇒ f64.ne +0x63 ⇒ f64.lt +0x64 ⇒ f64.gt +0x65 ⇒ f64.le +0x66 ⇒ f64.ge +0x67 ⇒ i32.clz +0x68 ⇒ i32.ctz +0x69 ⇒ i32.popcnt +0x6A ⇒ i32.add +0x6B ⇒ i32.sub +0x6C ⇒ i32.mul +0x6D ⇒ i32.div_s +0x6E ⇒ i32.div_u +0x6F ⇒ i32.rem_s +0x70 ⇒ i32.rem_u +0x71 ⇒ i32.and +0x72 ⇒ i32.or +0x73 ⇒ i32.xor +0x74 ⇒ i32.shl +0x75 ⇒ i32.shr_s +0x76 ⇒ i32.shr_u +0x77 ⇒ i32.rotl +0x78 ⇒ i32.rotr +0x79 ⇒ i64.clz +0x7A ⇒ i64.ctz +0x7B ⇒ i64.popcnt +0x7C ⇒ i64.add +0x7D ⇒ i64.sub +0x7E ⇒ i64.mul +0x7F ⇒ i64.div_s +0x80 ⇒ i64.div_u +0x81 ⇒ i64.rem_s +0x82 ⇒ i64.rem_u +0x83 ⇒ i64.and +0x84 ⇒ i64.or +0x85 ⇒ i64.xor +0x86 ⇒ i64.shl +0x87 ⇒ i64.shr_s +0x88 ⇒ i64.shr_u +0x89 ⇒ i64.rotl +0x8A ⇒ i64.rotr +0x8B ⇒ f32.abs +0x8C ⇒ f32.neg +0x8D ⇒ f32.ceil +0x8E ⇒ f32.floor +0x8F ⇒ f32.trunc +0x90 ⇒ f32.nearest +0x91 ⇒ f32.sqrt +0x92 ⇒ f32.add +0x93 ⇒ f32.sub +0x94 ⇒ f32.mul +0x95 ⇒ f32.div +0x96 ⇒ f32.min +0x97 ⇒ f32.max +0x98 ⇒ f32.copysign +0x99 ⇒ f64.abs +0x9A ⇒ f64.neg +0x9B ⇒ f64.ceil +0x9C ⇒ f64.floor +0x9D ⇒ f64.trunc +0x9E ⇒ f64.nearest +0x9F ⇒ f64.sqrt +0xA0 ⇒ f64.add +0xA1 ⇒ f64.sub +0xA2 ⇒ f64.mul +0xA3 ⇒ f64.div +0xA4 ⇒ f64.min +0xA5 ⇒ f64.max +0xA6 ⇒ f64.copysign +0xA7 ⇒ i32.wrap_i64 +0xA8 ⇒ i32.trunc_f32_s +0xA9 ⇒ i32.trunc_f32_u +0xAA ⇒ i32.trunc_f64_s +0xAB ⇒ i32.trunc_f64_u +0xAC ⇒ i64.extend_i32_s +0xAD ⇒ i64.extend_i32_u +0xAE ⇒ i64.trunc_f32_s +0xAF ⇒ i64.trunc_f32_u +0xB0 ⇒ i64.trunc_f64_s +0xB1 ⇒ i64.trunc_f64_u +0xB2 ⇒ f32.convert_i32_s +0xB3 ⇒ f32.convert_i32_u +0xB4 ⇒ f32.convert_i64_s +0xB5 ⇒ f32.convert_i64_u +0xB6 ⇒ f32.demote_f64 +0xB7 ⇒ f64.convert_i32_s +0xB8 ⇒ f64.convert_i32_u +0xB9 ⇒ f64.convert_i64_s +0xBA ⇒ f64.convert_i64_u +0xBB ⇒ f64.promote_f32 +0xBC ⇒ i32.reinterpret_f32 +0xBD ⇒ i64.reinterpret_f64 +0xBE ⇒ f32.reinterpret_i32 +0xBF ⇒ f64.reinterpret_i64 +0xC0 ⇒ i32.extend8_s +0xC1 ⇒ i32.extend16_s +0xC2 ⇒ i64.extend8_s +0xC3 ⇒ i64.extend16_s +0xC4 ⇒ i64.extend32_s +0xFC u32:num:0 ⇒ i32.trunc_sat_f32_s +0xFC u32:num:1 ⇒ i32.trunc_sat_f32_u +0xFC u32:num:2 ⇒ i32.trunc_sat_f64_s +0xFC u32:num:3 ⇒ i32.trunc_sat_f64_u +0xFC u32:num:4 ⇒ i64.trunc_sat_f32_s +0xFC u32:num:5 ⇒ i64.trunc_sat_f32_u +0xFC u32:num:6 ⇒ i64.trunc_sat_f64_s +0xFC u32:num:7 ⇒ i64.trunc_sat_f64_u +0xFD u32:num:0 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load 𝑚 +0xFD u32:num:1 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load8x8_s 𝑚 +0xFD u32:num:2 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load8x8_u 𝑚 +0xFD u32:num:3 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load16x4_s 𝑚 +0xFD u32:num:4 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load16x4_u 𝑚 +0xFD u32:num:5 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load32x2_s 𝑚 +0xFD u32:num:6 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load32x2_u 𝑚 +0xFD u32:num:7 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load8_splat 𝑚 +0xFD u32:num:8 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load16_splat 𝑚 +0xFD u32:num:9 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load32_splat 𝑚 +0xFD u32:num:10 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load64_splat 𝑚 +0xFD u32:num:92 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load32_zero 𝑚 +0xFD u32:num:93 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.load64_zero 𝑚 +0xFD u32:num:11 u32:align:𝒶 u32:offset:𝑜 ⇒ v128.store 𝑚 +0xFD u32:num:84 u32:align:𝒶 u32:offset:𝑜 u8:laneidx:𝑙 ⇒ v128.load8_lane 𝑚 𝑙 +0xFD u32:num:85 u32:align:𝒶 u32:offset:𝑜 u8:laneidx:𝑙 ⇒ v128.load16_lane 𝑚 𝑙 +0xFD u32:num:86 u32:align:𝒶 u32:offset:𝑜 u8:laneidx:𝑙 ⇒ v128.load32_lane 𝑚 𝑙 +0xFD u32:num:87 u32:align:𝒶 u32:offset:𝑜 u8:laneidx:𝑙 ⇒ v128.load64_lane 𝑚 𝑙 +0xFD u32:num:88 u32:align:𝒶 u32:offset:𝑜 u8:laneidx:𝑙 ⇒ v128.store8_lane 𝑚 𝑙 +0xFD u32:num:89 u32:align:𝒶 u32:offset:𝑜 u8:laneidx:𝑙 ⇒ v128.store16_lane 𝑚 𝑙 +0xFD u32:num:90 u32:align:𝒶 u32:offset:𝑜 u8:laneidx:𝑙 ⇒ v128.store32_lane 𝑚 𝑙 +0xFD u32:num:91 u32:align:𝒶 u32:offset:𝑜 u8:laneidx:𝑙 ⇒ v128.store64_lane 𝑚 𝑙 +-- 0xFD u32:num:12 (𝑏:byte)16 ⇒ v128.const bytes−1 i128(𝑏0 . . . 𝑏15) +-- 0xFD u32:num:13 (u8:laneidx:𝑙)16 ⇒ i8x16.shuffle 𝑙16 +0xFD u32:num:21 u8:laneidx:𝑙 ⇒ i8x16.extract_lane_s 𝑙 +0xFD u32:num:22 u8:laneidx:𝑙 ⇒ i8x16.extract_lane_u 𝑙 +0xFD u32:num:23 u8:laneidx:𝑙 ⇒ i8x16.replace_lane 𝑙 +0xFD u32:num:24 u8:laneidx:𝑙 ⇒ i16x8.extract_lane_s 𝑙 +0xFD u32:num:25 u8:laneidx:𝑙 ⇒ i16x8.extract_lane_u 𝑙 +0xFD u32:num:26 u8:laneidx:𝑙 ⇒ i16x8.replace_lane 𝑙 +0xFD u32:num:27 u8:laneidx:𝑙 ⇒ i32x4.extract_lane 𝑙 +0xFD u32:num:28 u8:laneidx:𝑙 ⇒ i32x4.replace_lane 𝑙 +0xFD u32:num:29 u8:laneidx:𝑙 ⇒ i64x2.extract_lane 𝑙 +0xFD u32:num:30 u8:laneidx:𝑙 ⇒ i64x2.replace_lane 𝑙 +0xFD u32:num:31 u8:laneidx:𝑙 ⇒ f32x4.extract_lane 𝑙 +0xFD u32:num:32 u8:laneidx:𝑙 ⇒ f32x4.replace_lane 𝑙 +0xFD u32:num:33 u8:laneidx:𝑙 ⇒ f64x2.extract_lane 𝑙 +0xFD u32:num:34 u8:laneidx:𝑙 ⇒ f64x2.replace_lane 𝑙 +0xFD u32:num:14 ⇒ i8x16.swizzle +0xFD u32:num:15 ⇒ i8x16.splat +0xFD u32:num:16 ⇒ i16x8.splat +0xFD u32:num:17 ⇒ i32x4.splat +0xFD u32:num:18 ⇒ i64x2.splat +0xFD u32:num:19 ⇒ f32x4.splat +0xFD u32:num:20 ⇒ f64x2.splat +0xFD u32:num:35 ⇒ i8x16.eq +0xFD u32:num:36 ⇒ i8x16.ne +0xFD u32:num:37 ⇒ i8x16.lt_s +0xFD u32:num:38 ⇒ i8x16.lt_u +0xFD u32:num:39 ⇒ i8x16.gt_s +0xFD u32:num:40 ⇒ i8x16.gt_u +0xFD u32:num:41 ⇒ i8x16.le_s +0xFD u32:num:42 ⇒ i8x16.le_u +0xFD u32:num:43 ⇒ i8x16.ge_s +0xFD u32:num:44 ⇒ i8x16.ge_u +0xFD u32:num:45 ⇒ i16x8.eq +0xFD u32:num:46 ⇒ i16x8.ne +0xFD u32:num:47 ⇒ i16x8.lt_s +0xFD u32:num:48 ⇒ i16x8.lt_u +0xFD u32:num:49 ⇒ i16x8.gt_s +0xFD u32:num:50 ⇒ i16x8.gt_u +0xFD u32:num:51 ⇒ i16x8.le_s +0xFD u32:num:52 ⇒ i16x8.le_u +0xFD u32:num:53 ⇒ i16x8.ge_s +0xFD u32:num:54 ⇒ i16x8.ge_u +0xFD u32:num:55 ⇒ i32x4.eq +0xFD u32:num:56 ⇒ i32x4.ne +0xFD u32:num:57 ⇒ i32x4.lt_s +0xFD u32:num:58 ⇒ i32x4.lt_u +0xFD u32:num:59 ⇒ i32x4.gt_s +0xFD u32:num:60 ⇒ i32x4.gt_u +0xFD u32:num:61 ⇒ i32x4.le_s +0xFD u32:num:62 ⇒ i32x4.le_u +0xFD u32:num:63 ⇒ i32x4.ge_s +0xFD u32:num:64 ⇒ i32x4.ge_u +0xFD u32:num:214 ⇒ i64x2.eq +0xFD u32:num:215 ⇒ i64x2.ne +0xFD u32:num:216 ⇒ i64x2.lt_s +0xFD u32:num:217 ⇒ i64x2.gt_s +0xFD u32:num:218 ⇒ i64x2.le_s +0xFD u32:num:219 ⇒ i64x2.ge_s +0xFD u32:num:65 ⇒ f32x4.eq +0xFD u32:num:66 ⇒ f32x4.ne +0xFD u32:num:67 ⇒ f32x4.lt +0xFD u32:num:68 ⇒ f32x4.gt +0xFD u32:num:69 ⇒ f32x4.le +0xFD u32:num:70 ⇒ f32x4.ge +0xFD u32:num:71 ⇒ f64x2.eq +0xFD u32:num:72 ⇒ f64x2.ne +0xFD u32:num:73 ⇒ f64x2.lt +0xFD u32:num:74 ⇒ f64x2.gt +0xFD u32:num:75 ⇒ f64x2.le +0xFD u32:num:76 ⇒ f64x2.ge +0xFD u32:num:77 ⇒ v128.not +0xFD u32:num:78 ⇒ v128.and +0xFD u32:num:79 ⇒ v128.andnot +0xFD u32:num:80 ⇒ v128.or +0xFD u32:num:81 ⇒ v128.xor +0xFD u32:num:82 ⇒ v128.bitselect +0xFD u32:num:83 ⇒ v128.any_true +0xFD u32:num:96 ⇒ i8x16.abs +0xFD u32:num:97 ⇒ i8x16.neg +0xFD u32:num:98 ⇒ i8x16.popcnt +0xFD u32:num:99 ⇒ i8x16.all_true +0xFD u32:num:100 ⇒ i8x16.bitmask +0xFD u32:num:101 ⇒ i8x16.narrow_i16x8_s +0xFD u32:num:102 ⇒ i8x16.narrow_i16x8_u +0xFD u32:num:107 ⇒ i8x16.shl +0xFD u32:num:108 ⇒ i8x16.shr_s +0xFD u32:num:109 ⇒ i8x16.shr_u +0xFD u32:num:110 ⇒ i8x16.add +0xFD u32:num:111 ⇒ i8x16.add_sat_s +0xFD u32:num:112 ⇒ i8x16.add_sat_u +0xFD u32:num:113 ⇒ i8x16.sub +0xFD u32:num:114 ⇒ i8x16.sub_sat_s +0xFD u32:num:115 ⇒ i8x16.sub_sat_u +0xFD u32:num:118 ⇒ i8x16.min_s +0xFD u32:num:119 ⇒ i8x16.min_u +0xFD u32:num:120 ⇒ i8x16.max_s +0xFD u32:num:121 ⇒ i8x16.max_u +0xFD u32:num:123 ⇒ i8x16.avgr_u +0xFD u32:num:124 ⇒ i16x8.extadd_pairwise_i8x16_s +0xFD u32:num:125 ⇒ i16x8.extadd_pairwise_i8x16_u +0xFD u32:num:128 ⇒ i16x8.abs +0xFD u32:num:129 ⇒ i16x8.neg +0xFD u32:num:130 ⇒ i16x8.q15mulr_sat_s +0xFD u32:num:131 ⇒ i16x8.all_true +0xFD u32:num:132 ⇒ i16x8.bitmask +0xFD u32:num:133 ⇒ i16x8.narrow_i32x4_s +0xFD u32:num:134 ⇒ i16x8.narrow_i32x4_u +0xFD u32:num:135 ⇒ i16x8.extend_low_i8x16_s +0xFD u32:num:136 ⇒ i16x8.extend_high_i8x16_s +0xFD u32:num:137 ⇒ i16x8.extend_low_i8x16_u +0xFD u32:num:138 ⇒ i16x8.extend_high_i8x16_u +0xFD u32:num:139 ⇒ i16x8.shl +0xFD u32:num:140 ⇒ i16x8.shr_s +0xFD u32:num:141 ⇒ i16x8.shr_u +0xFD u32:num:142 ⇒ i16x8.add +0xFD u32:num:143 ⇒ i16x8.add_sat_s +0xFD u32:num:144 ⇒ i16x8.add_sat_u +0xFD u32:num:145 ⇒ i16x8.sub +0xFD u32:num:146 ⇒ i16x8.sub_sat_s +0xFD u32:num:147 ⇒ i16x8.sub_sat_u +0xFD u32:num:149 ⇒ i16x8.mul +0xFD u32:num:150 ⇒ i16x8.min_s +0xFD u32:num:151 ⇒ i16x8.min_u +0xFD u32:num:152 ⇒ i16x8.max_s +0xFD u32:num:153 ⇒ i16x8.max_u +0xFD u32:num:155 ⇒ i16x8.avgr_u +0xFD u32:num:156 ⇒ i16x8.extmul_low_i8x16_s +0xFD u32:num:157 ⇒ i16x8.extmul_high_i8x16_s +0xFD u32:num:158 ⇒ i16x8.extmul_low_i8x16_u +0xFD u32:num:159 ⇒ i16x8.extmul_high_i8x16_u +0xFD u32:num:126 ⇒ i32x4.extadd_pairwise_i16x8_s +0xFD u32:num:127 ⇒ i32x4.extadd_pairwise_i16x8_u +0xFD u32:num:160 ⇒ i32x4.abs +0xFD u32:num:161 ⇒ i32x4.neg +0xFD u32:num:163 ⇒ i32x4.all_true +0xFD u32:num:164 ⇒ i32x4.bitmask +0xFD u32:num:167 ⇒ i32x4.extend_low_i16x8_s +0xFD u32:num:168 ⇒ i32x4.extend_high_i16x8_s +0xFD u32:num:169 ⇒ i32x4.extend_low_i16x8_u +0xFD u32:num:170 ⇒ i32x4.extend_high_i16x8_u +0xFD u32:num:171 ⇒ i32x4.shl +0xFD u32:num:172 ⇒ i32x4.shr_s +0xFD u32:num:173 ⇒ i32x4.shr_u +0xFD u32:num:174 ⇒ i32x4.add +0xFD u32:num:177 ⇒ i32x4.sub +0xFD u32:num:181 ⇒ i32x4.mul +0xFD u32:num:182 ⇒ i32x4.min_s +0xFD u32:num:183 ⇒ i32x4.min_u +0xFD u32:num:184 ⇒ i32x4.max_s +0xFD u32:num:185 ⇒ i32x4.max_u +0xFD u32:num:186 ⇒ i32x4.dot_i16x8_s +0xFD u32:num:188 ⇒ i32x4.extmul_low_i16x8_s +0xFD u32:num:189 ⇒ i32x4.extmul_high_i16x8_s +0xFD u32:num:190 ⇒ i32x4.extmul_low_i16x8_u +0xFD u32:num:191 ⇒ i32x4.extmul_high_i16x8_u +0xFD u32:num:192 ⇒ i64x2.abs +0xFD u32:num:193 ⇒ i64x2.neg +0xFD u32:num:195 ⇒ i64x2.all_true +0xFD u32:num:196 ⇒ i64x2.bitmask +0xFD u32:num:199 ⇒ i64x2.extend_low_i32x4_s +0xFD u32:num:200 ⇒ i64x2.extend_high_i32x4_s +0xFD u32:num:201 ⇒ i64x2.extend_low_i32x4_u +0xFD u32:num:202 ⇒ i64x2.extend_high_i32x4_u +0xFD u32:num:203 ⇒ i64x2.shl +0xFD u32:num:204 ⇒ i64x2.shr_s +0xFD u32:num:205 ⇒ i64x2.shr_u +0xFD u32:num:206 ⇒ i64x2.add +0xFD u32:num:209 ⇒ i64x2.sub +0xFD u32:num:213 ⇒ i64x2.mul +0xFD u32:num:220 ⇒ i64x2.extmul_low_i32x4_s +0xFD u32:num:221 ⇒ i64x2.extmul_high_i32x4_s +0xFD u32:num:222 ⇒ i64x2.extmul_low_i32x4_u +0xFD u32:num:223 ⇒ i64x2.extmul_high_i32x4_u +0xFD u32:num:103 ⇒ f32x4.ceil +0xFD u32:num:104 ⇒ f32x4.floor +0xFD u32:num:105 ⇒ f32x4.trunc +0xFD u32:num:106 ⇒ f32x4.nearest +0xFD u32:num:224 ⇒ f32x4.abs +0xFD u32:num:225 ⇒ f32x4.neg +0xFD u32:num:227 ⇒ f32x4.sqrt +0xFD u32:num:228 ⇒ f32x4.add +0xFD u32:num:229 ⇒ f32x4.sub +0xFD u32:num:230 ⇒ f32x4.mul +0xFD u32:num:231 ⇒ f32x4.div +0xFD u32:num:232 ⇒ f32x4.min +0xFD u32:num:233 ⇒ f32x4.max +0xFD u32:num:234 ⇒ f32x4.pmin +0xFD u32:num:235 ⇒ f32x4.pmax +0xFD u32:num:116 ⇒ f64x2.ceil +0xFD u32:num:117 ⇒ f64x2.floor +0xFD u32:num:122 ⇒ f64x2.trunc +0xFD u32:num:148 ⇒ f64x2.nearest +0xFD u32:num:236 ⇒ f64x2.abs +0xFD u32:num:237 ⇒ f64x2.neg +0xFD u32:num:239 ⇒ f64x2.sqrt +0xFD u32:num:240 ⇒ f64x2.add +0xFD u32:num:241 ⇒ f64x2.sub +0xFD u32:num:242 ⇒ f64x2.mul +0xFD u32:num:243 ⇒ f64x2.div +0xFD u32:num:244 ⇒ f64x2.min +0xFD u32:num:245 ⇒ f64x2.max +0xFD u32:num:246 ⇒ f64x2.pmin +0xFD u32:num:247 ⇒ f64x2.pmax +0xFD u32:num:248 ⇒ i32x4.trunc_sat_f32x4_s +0xFD u32:num:249 ⇒ i32x4.trunc_sat_f32x4_u +0xFD u32:num:250 ⇒ f32x4.convert_i32x4_s +0xFD u32:num:251 ⇒ f32x4.convert_i32x4_u +0xFD u32:num:252 ⇒ i32x4.trunc_sat_f64x2_s_zero +0xFD u32:num:253 ⇒ i32x4.trunc_sat_f64x2_u_zero +0xFD u32:num:254 ⇒ f64x2.convert_low_i32x4_s +0xFD u32:num:255 ⇒ f64x2.convert_low_i32x4_u +0xFD u32:num:94 ⇒ f32x4.demote_f64x2_zero +0xFD u32:num:95 ⇒ f64x2.promote_low_f32x4 diff --git a/src/libasr/wasm_instructions_visitor.py b/src/libasr/wasm_instructions_visitor.py new file mode 100644 index 0000000000..11d705ae28 --- /dev/null +++ b/src/libasr/wasm_instructions_visitor.py @@ -0,0 +1,200 @@ +import sys +import os +import re + +HEAD = r"""#ifndef LFORTRAN_%(MOD)s_H +#define LFORTRAN_%(MOD)s_H + +// Generated by grammar/wasm_instructions_visitor.py + +#include +#include +#include +#include +#include +#include +#include + + +namespace LFortran { + +namespace %(MOD)s { + +""" + +FOOT = r""" +} // namespace %(MOD)s + +} // namespace LFortran + +#endif // LFORTRAN_%(MOD)s_H +""" + +class WASMInstructionsVisitor(): + def __init__(self, stream, data): + self.stream = stream + self.data = data + + def visitWASMInstructions(self, mod, *args): + self.emit("template ", 0) + self.emit("class BaseWASMVisitor {", 0) + self.emit("private:", 0) + self.emit( "Derived& self() { return static_cast(*this); }", 1) + self.emit("public:", 0) + self.emit( "Vec &code;", 1) + self.emit( "uint32_t offset;\n", 1) + + self.emit( "BaseWASMVisitor(Vec &code, uint32_t offset): code(code), offset(offset) {}", 1) + + for inst in mod["instructions"]: + self.emit("void visit_%s(%s) {throw LFortran::LFortranException(\"visit_%s() not implemented\");}\n" % (inst["func"], make_param_list(inst["params"]), inst["func"]), 1) + + self.emit( "void decode_instructions() {", 1) + self.emit( "uint8_t cur_byte = wasm::read_b8(code, offset);", 2) + self.emit( "while (cur_byte != 0x0B) {", 2) + self.emit( "switch (cur_byte) {", 3) + for inst in filter(lambda i: i["opcode"] not in ["0xFC", "0xFD"], mod["instructions"]): + self.emit( "case %s: {" % (inst["opcode"]), 4) + for param in inst["params"]: + self.emit( "%s %s = %s(code, offset);" % (param["type"], param["name"], param["read_func"]), 5) + self.emit( "self().visit_%s(%s);" % (inst["func"], make_param_list(inst["params"], call=True)), 5) + self.emit( "break;", 5) + self.emit( "}", 4) + + self.emit( "case 0xFC: {", 4) + self.emit( "uint32_t num = wasm::read_u32(code, offset);", 5) + self.emit( "switch(num) {", 5) + for inst in filter(lambda i: i["opcode"] == "0xFC", mod["instructions"]): + self.emit( "case %sU: {" % (inst["params"][0]["val"]), 6) + for param in inst["params"][1:]: # first param is already read right at the start of case 0xFC + self.emit( "%s %s = %s(code, offset);" % (param["type"], param["name"], param["read_func"]), 7) + self.emit( "self().visit_%s(%s);" % (inst["func"], make_param_list(inst["params"], call=True)), 7) + self.emit( "break;", 7) + self.emit( "}", 6) + self.emit( "default: {", 6) + self.emit( "throw LFortran::LFortranException(\"Unknown num for opcode 0xFC\");", 7) + self.emit( "}", 6) + self.emit( "}", 5) + self.emit( "break;", 5) + self.emit( "}", 4) + + self.emit( "case 0xFD: {", 4) + self.emit( "uint32_t num = wasm::read_u32(code, offset);", 5) + self.emit( "switch(num) {", 5) + for inst in filter(lambda i: i["opcode"] == "0xFD", mod["instructions"]): + self.emit( "case %sU: {" % (inst["params"][0]["val"]), 6) + for param in inst["params"][1:]: # first param is already read right at the start of case 0xFD + self.emit( "%s %s = %s(code, offset);" % (param["type"], param["name"], param["read_func"]), 7) + self.emit( "self().visit_%s(%s);" % (inst["func"], make_param_list(inst["params"], call=True)), 7) + self.emit( "break;", 7) + self.emit( "}", 6) + self.emit( "default: {", 6) + self.emit( "throw LFortran::LFortranException(\"Unknown num for opcode 0xFD\");", 7) + self.emit( "}", 6) + self.emit( "}", 5) + self.emit( "break;", 5) + self.emit( "}", 4) + + self.emit( "default: {", 4) + self.emit( "throw LFortran::LFortranException(\"Unknown opcode\");", 5) + self.emit( "}", 4) + self.emit( "}", 3) + self.emit( "cur_byte = wasm::read_b8(code, offset);", 3) + self.emit( "}", 2) + self.emit( "}", 1) + self.emit("};", 0) + + + def emit(self, line, level=0): + indent = " "*level + self.stream.write(indent + line + "\n") + +def make_param_list(params, call = False): + params = list(filter(lambda param: param["val"] != "0x00" and param["name"] != "num", params)) + if call: + return ", ".join(map(lambda param: param["name"], params)) + return ", ".join(map(lambda param: param["type"] + " /*" + param["name"] + "*/", params)) + +def read_file(path): + with open(path, encoding="utf-8") as fp: + return fp.read() + +def process_raw_instructions(instructions_raw): + instructions = [] + for line in instructions_raw.splitlines(): + if line.startswith("--"): + continue + if len(instructions) > 0 and line.startswith(" "): + instructions[-1].append(line.strip()) + else: + instructions.append(line.strip()) + return instructions + +def get_func_name(func): + splitted_name = re.split("[\._]", func) + return "".join(map(lambda name_sub_part: name_sub_part.capitalize(), splitted_name)) + +param_read_function = { + "uint8_t": "wasm::read_b8", + "uint32_t": "wasm::read_u32", + "int32_t": "wasm::read_i32", + "int64_t": "wasm::read_i64", + "float": "wasm::read_f32", + "double": "wasm::read_f64" +} + +param_type = { + "u8": "uint8_t", + "u32": "uint32_t", + "i32": "int32_t", + "i64": "int64_t", + "f32": "float", + "f64": "double", +} + +def parse_param_info(param_info): + type_info, name, val = param_info.split(":") + type = param_type[type_info] + read_func = param_read_function[type] + return {"type": type, "read_func": read_func, "name": name, "val": val} + +def parse_instructions(instructions): + instructions_info = [] + for inst in instructions: + binary_info, text_info = inst.split(" ⇒ ") + binary_info = binary_info.strip().split(" ") + opcode = binary_info[0] + params_info = binary_info[1:] + text_info = text_info.strip().split(" ") + func = get_func_name(text_info[0]) # first parameter is the function name + text_params = text_info[1:] # text_params are currently not needed and hence not used further + params = list(map(lambda param_info: parse_param_info(param_info), params_info)) + instructions_info.append({"opcode": opcode, "func": func, "params": params}) + return instructions_info + +def main(argv): + if len(argv) == 3: + def_file, out_file = argv[1:] + elif len(argv) == 1: + print("Assuming default values of wasm_instructions.txt and wasm_visitor.h") + here = os.path.dirname(__file__) + def_file = os.path.join(here, "wasm_instructions.txt") + out_file = os.path.join(here, "wasm_visitor.h") + else: + print("invalid arguments") + return 2 + instructions_raw = read_file(def_file) + instructions = process_raw_instructions(instructions_raw) + instructions_info = parse_instructions(instructions) + subs = {"MOD": "WASM_INSTS_VISITOR"} + fp = open(out_file, "w", encoding="utf-8") + try: + fp.write(HEAD % subs) + wasm_instructions_visitor = WASMInstructionsVisitor(fp, None) + wasm_instructions_visitor.visitWASMInstructions({"instructions": instructions_info}) + fp.write(FOOT % subs) + finally: + fp.close() + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/src/lpython/parser/parser.cpp b/src/lpython/parser/parser.cpp index 139f8e86c8..307cb39866 100644 --- a/src/lpython/parser/parser.cpp +++ b/src/lpython/parser/parser.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include @@ -84,6 +86,32 @@ void Parser::handle_yyerror(const Location &loc, const std::string &msg) throw parser_local::ParserError(message, loc); } +bool file_exists(const std::string &name) { + std::ifstream file(name); + if (!file.is_open()) { + return false; + } + return true; +} + +std::string unique_filename(const std::string &prefix) { + uint64_t ms = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); + ms = ms % 1000000000; + srand((unsigned) ms); + std::string hex = "0123456789ABCDEF"; + std::string random_hash; + for (int i=0; i < 6; i++) { + random_hash += hex[rand() % 16]; + } + int counter = 1; + std::string filename = prefix + random_hash + std::to_string(counter); + while (file_exists(filename)) { + counter++; + filename = prefix + random_hash + std::to_string(counter); + } + return filename; +} + Result parse_python_file(Allocator &al, const std::string &runtime_library_dir, const std::string &infile, @@ -100,17 +128,18 @@ Result parse_python_file(Allocator &al, return Error(); } } else { - std::string pycmd = "python " + runtime_library_dir + "/lpython_parser.py " + infile; + std::string outfile = unique_filename(infile); + std::string pycmd = "python " + runtime_library_dir + + "/lpython_parser.py " + infile + " " + outfile; int err = std::system(pycmd.c_str()); if (err != 0) { std::cerr << "The command '" << pycmd << "' failed." << std::endl; return Error(); } - std::string infile_ser = "ser.txt"; std::string input; - bool status = read_file(infile_ser, input); + bool status = read_file(outfile, input); if (!status) { - std::cerr << "The file '" << infile_ser << "' cannot be read." << std::endl; + std::cerr << "The file '" << outfile << "' cannot be read." << std::endl; return Error(); } ast = LPython::deserialize_ast(al, input); diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index 9076e33cee..3140cd9260 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -104,6 +104,7 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg) %token TK_STRING %token TK_COMMENT %token TK_EOLCOMMENT +%token TK_TYPE_COMMENT %token TK_POW "**" %token TK_FLOOR_DIV "//" %token TK_RIGHTSHIFT ">>" @@ -131,6 +132,8 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg) %token TK_GT ">" %token TK_GE ">=" %token TK_NOT "not" +%token TK_IS_NOT "is not" +%token TK_NOT_IN "not in" %token TK_AND "and" %token TK_OR "or" %token TK_TRUE "True" @@ -156,8 +159,8 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg) %token KW_GLOBAL %token KW_IF %token KW_IMPORT -%token KW_IN -%token KW_IS +%token KW_IN "in" +%token KW_IS "is" %token KW_LAMBDA %token KW_NONE %token KW_NONLOCAL @@ -198,7 +201,6 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg) %type tuple_item %type ann_assignment_statement %type delete_statement -%type del_target_list %type return_statement %type expression_statment %type module @@ -233,8 +235,14 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg) %type keyword_items %type function_call %type primary +%type while_statement %type sep %type sep_one +%type string +%type ternary_if_statement +%type list_comprehension +%type id_list +%type id_item // Precedence @@ -242,7 +250,9 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg) %left "or" %left "and" %precedence "not" -%left "==" "!=" ">=" ">" "<=" "<" //"is not" "is" "not in" "in" +%left "==" "!=" ">=" ">" "<=" "<" "is not" "is" "not in" "in" // "in" +%precedence FOR +%left KW_IF KW_ELSE %left "|" %left "^" %left "&" @@ -287,8 +297,9 @@ statements1 ; statement - : single_line_statement sep + : single_line_statement sep { $$ = $1; } | multi_line_statement + | multi_line_statement sep { $$ = $1; } ; single_line_statement @@ -319,6 +330,7 @@ multi_line_statement | async_func_def | async_for_stmt | async_with_stmt + | while_statement ; expression_statment @@ -350,6 +362,8 @@ assert_statement tuple_item : expr_list { $$ = TUPLE_01($1, @$); } + | expr_list "," { $$ = TUPLE_03($1, @$); } + | "(" expr_list "," ")" { $$ = TUPLE_03($2, @$); } | "(" expr_list "," expr ")" { $$ = TUPLE_01(TUPLE_($2, $4), @$); } ; @@ -386,18 +400,20 @@ ann_assignment_statement | expr ":" expr "=" expr { $$ = ANNASSIGN_02($1, $3, $5, @$); } ; -del_target_list - : del_target_list "," expr { $$ = $1; LIST_ADD($$, $3); } - | expr { LIST_NEW($$); LIST_ADD($$, $1); } - ; - delete_statement - : KW_DEL del_target_list { $$ = DELETE($2, @$); } + : KW_DEL expr_list { $$ = DELETE_01($2, @$); } + | KW_DEL expr_list "," { $$ = DELETE_01($2, @$); } + | KW_DEL "(" ")" { $$ = DELETE_02(@$); } + | KW_DEL "(" expr_list "," ")" { + $$ = DELETE_03(SET_EXPR_CTX_02($3, Del), @$); } + | KW_DEL "(" expr_list "," expr ")" { + $$ = DELETE_03(SET_EXPR_CTX_02(TUPLE_($3, $5), Del), @$); } ; return_statement : KW_RETURN { $$ = RETURN_01(@$); } | KW_RETURN tuple_item { $$ = RETURN_02($2, @$); } + | KW_RETURN "(" ")" { $$ = RETURN_03(@$); } ; module @@ -447,6 +463,10 @@ if_statement_single : KW_IF expr TK_COLON single_line_statement { $$ = IF_01($2, $4, @$); } ; +ternary_if_statement + : expr KW_IF expr KW_ELSE expr { $$ = TERNARY($3, $1, $5, @$); } + ; + nonlocal_statement : KW_NONLOCAL expr_list { $$ = NON_LOCAL($2, @$); } ; @@ -468,9 +488,14 @@ if_statement ; for_statement - : KW_FOR expr KW_IN expr ":" sep statements { $$ = FOR_01($2, $4, $7, @$); } - | KW_FOR expr KW_IN expr ":" sep statements KW_ELSE ":" sep statements { - $$ = FOR_02($2, $4, $7, $11, @$); } + : KW_FOR tuple_item KW_IN expr ":" sep statements { + $$ = FOR_01($2, $4, $7, @$); } + | KW_FOR tuple_item KW_IN expr ":" sep statements KW_ELSE ":" + sep statements { $$ = FOR_02($2, $4, $7, $11, @$); } + | KW_FOR tuple_item KW_IN expr ":" TK_TYPE_COMMENT TK_NEWLINE statements { + $$ = FOR_03($2, $4, $6, $8, @$); } + | KW_FOR tuple_item KW_IN expr ":" TK_TYPE_COMMENT TK_NEWLINE statements + KW_ELSE ":" sep statements { $$ = FOR_04($2, $4, $8, $12, $6, @$); } ; except_statement @@ -516,8 +541,8 @@ decorators_opt ; decorators - : decorators "@" expr TK_NEWLINE { $$ = $1; LIST_ADD($$, $3); } - | "@" expr TK_NEWLINE { LIST_NEW($$); LIST_ADD($$, $2); } + : decorators "@" expr sep { $$ = $1; LIST_ADD($$, $3); } + | "@" expr sep { LIST_NEW($$); LIST_ADD($$, $2); } ; parameter @@ -543,6 +568,7 @@ parameter_list_starargs $$ = STAR_ARGS_03($2, $4, $7, @$); } | "*" parameter "," "**" parameter { $$ = STAR_ARGS_04($2, $5, @$); } | "**" parameter { $$ = STAR_ARGS_05($2, @$); } + | defparameter_list "," "*" parameter { $$ = STAR_ARGS_06($1, $4, @$); } | defparameter_list "," "*" parameter "," defparameter_list { $$ = STAR_ARGS_07($1, $4, $6, @$); } @@ -551,12 +577,35 @@ parameter_list_starargs | defparameter_list "," "*" parameter "," "**" parameter { $$ = STAR_ARGS_09($1, $4, $7, @$); } | defparameter_list "," "**" parameter { $$ = STAR_ARGS_10($1, $4, @$); } + + | defparameter_list "," "/" { $$ = STAR_ARGS_11($1, @$); } + | defparameter_list "," "/" "," "*" parameter { + $$ = STAR_ARGS_12($1, $6, @$); } + | defparameter_list "," "/" "," "*" parameter "," defparameter_list { + $$ = STAR_ARGS_13($1, $6, $8, @$); } + | defparameter_list "," "/" "," "*" parameter "," defparameter_list + "," "**" parameter { $$ = STAR_ARGS_14($1, $6, $8, $11, @$); } + | defparameter_list "," "/" "," "**" parameter { + $$ = STAR_ARGS_15($1, $6, @$); } + | defparameter_list "," "/" "," "*" parameter "," "**" parameter { + $$ = STAR_ARGS_16($1, $6, $9, @$); } + | defparameter_list "," "/" "," defparameter_list "," "*" parameter { + $$ = STAR_ARGS_17($1, $5, $8, @$); } + | defparameter_list "," "/" "," defparameter_list "," "**" parameter { + $$ = STAR_ARGS_18($1, $5, $8, @$); } + | defparameter_list "," "/" "," defparameter_list "," "*" parameter + "," "**" parameter { $$ = STAR_ARGS_19($1, $5, $8, $11, @$); } + | defparameter_list "," "/" "," defparameter_list "," "*" parameter + "," defparameter_list "," "**" parameter { + $$ = STAR_ARGS_20($1, $5, $8, $10, $13, @$); } ; parameter_list_opt : defparameter_list { $$ = FUNC_ARG_LIST_01($1, @$); } | parameter_list_starargs { $$ = $1; } | %empty { $$ = FUNC_ARG_LIST_02(@$); } + | defparameter_list "," "/" "," defparameter_list { + $$ = FUNC_ARG_LIST_03($1, $5, @$); } ; function_def @@ -584,9 +633,9 @@ async_func_def ; async_for_stmt - : KW_ASYNC KW_FOR expr KW_IN expr ":" sep statements { + : KW_ASYNC KW_FOR tuple_item KW_IN expr ":" sep statements { $$ = ASYNC_FOR_01($3, $5, $8, @$); } - | KW_ASYNC KW_FOR expr KW_IN expr ":" sep statements KW_ELSE ":" sep + | KW_ASYNC KW_FOR tuple_item KW_IN expr ":" sep statements KW_ELSE ":" sep statements { $$ = ASYNC_FOR_02($3, $5, $8, $12, @$); } ; @@ -597,6 +646,12 @@ async_with_stmt $$ = ASYNC_WITH($4, $9, @$); } ; +while_statement + : KW_WHILE expr ":" sep statements { $$ = WHILE_01($2, $5, @$); } + | KW_WHILE expr ":" sep statements KW_ELSE ":" sep statements { + $$ = WHILE_02($2, $5, $9, @$); } + ; + slice_item_list : slice_item_list "," slice_item { $$ = $1; LIST_ADD($$, $3); } | slice_item { LIST_NEW($$); LIST_ADD($$, $1); } @@ -606,7 +661,7 @@ slice_item | expr ":" { $$ = SLICE_01( $1, nullptr, nullptr, @$); } | ":" expr { $$ = SLICE_01(nullptr, $2, nullptr, @$); } | expr ":" expr { $$ = SLICE_01( $1, $3, nullptr, @$); } - | ":" ":" { $$ = SLICE_01(nullptr, nullptr, nullptr, @$); } + | ":" ":" { $$ = SLICE_01(nullptr, nullptr, nullptr, @$); } | ":" ":" expr { $$ = SLICE_01(nullptr, nullptr, $3, @$); } | expr ":" ":" { $$ = SLICE_01( $1, nullptr, nullptr, @$); } | ":" expr ":" { $$ = SLICE_01(nullptr, $2, nullptr, @$); } @@ -623,8 +678,8 @@ expr_list_opt ; expr_list - : expr_list "," expr { $$ = $1; LIST_ADD($$, $3); } - | expr { LIST_NEW($$); LIST_ADD($$, $1); } + : expr_list "," expr %prec FOR { $$ = $1; LIST_ADD($$, $3); } + | expr %prec FOR { LIST_NEW($$); LIST_ADD($$, $1); } ; dict @@ -640,6 +695,24 @@ tuple_list : slice_item_list { $$ = TUPLE($1, @$); } ; +id_list + : id_list "," id { $$ = $1; LIST_ADD($$, $3); } + | id { LIST_NEW($$); LIST_ADD($$, $1); } + ; + +id_item + : id_list { $$ = ID_TUPLE_01($1, @$); } + | id_list "," { $$ = ID_TUPLE_03($1, @$); } + | "(" id ")" { $$ = $2; } + | "(" id_list "," ")" { $$ = ID_TUPLE_03($2, @$); } + | "(" id_list "," id ")" { $$ = ID_TUPLE_01(TUPLE_($2, $4), @$); } + ; + +list_comprehension + : "[" expr KW_FOR id_item KW_IN expr "]" { $$ = LIST_COMP_1($2, $4, $6, @$); } + | "[" expr KW_FOR id_item KW_IN expr KW_IF expr "]" { $$ = LIST_COMP_2($2, $4, $6, $8, @$); } + ; + keyword_item : id "=" expr { $$ = CALL_KEYWORD_01($1, $3, @$); } | "**" expr { $$ = CALL_KEYWORD_02($2, @$); } @@ -664,14 +737,22 @@ function_call | primary "(" keyword_items ")" { $$ = CALL_03($1, $3, @$); } ; +string + : string TK_STRING { $$ = STRING2($1, $2, @$); } // TODO + | TK_STRING { $$ = STRING1($1, @$); } + | id TK_STRING { $$ = STRING3($1, $2, @$); } + ; + expr : id { $$ = $1; } | TK_INTEGER { $$ = INTEGER($1, @$); } - | TK_STRING { $$ = STRING($1, @$); } + | string { $$ = $1; } | TK_REAL { $$ = FLOAT($1, @$); } | TK_IMAG_NUM { $$ = COMPLEX($1, @$); } | TK_TRUE { $$ = BOOL(true, @$); } | TK_FALSE { $$ = BOOL(false, @$); } + | KW_NONE { $$ = NONE(@$); } + | TK_ELLIPSIS { $$ = ELLIPSIS(@$); } | "(" expr ")" { $$ = $2; } | function_call { $$ = $1; } | "[" expr_list_opt "]" { $$ = LIST($2, @$); } @@ -679,8 +760,10 @@ expr | "{" expr_list "}" { $$ = SET($2, @$); } | "{" expr_list "," "}" { $$ = SET($2, @$); } | id "[" tuple_list "]" { $$ = SUBSCRIPT_01($1, $3, @$); } - | TK_STRING "[" tuple_list "]" { $$ = SUBSCRIPT_02($1, $3, @$); } + | string "[" tuple_list "]" { $$ = SUBSCRIPT_02($1, $3, @$); } | expr "." id { $$ = ATTRIBUTE_REF($1, $3, @$); } + | expr "." id "[" tuple_list "]" { + $$ = SUBSCRIPT_01(ATTRIBUTE_REF($1, $3, @$), $5, @$); } | "{" "}" { $$ = DICT_01(@$); } | "{" dict_list "}" { $$ = DICT_02($2, @$); } | KW_AWAIT expr %prec AWAIT { $$ = AWAIT($2, @$); } @@ -711,11 +794,18 @@ expr | expr "<=" expr { $$ = COMPARE($1, LtE, $3, @$); } | expr ">" expr { $$ = COMPARE($1, Gt, $3, @$); } | expr ">=" expr { $$ = COMPARE($1, GtE, $3, @$); } + | expr "is" expr { $$ = COMPARE($1, Is, $3, @$); } + | expr "is not" expr { $$ = COMPARE($1, IsNot, $3, @$); } + | expr "in" expr { $$ = COMPARE($1, In, $3, @$); } + | expr "not in" expr { $$ = COMPARE($1, NotIn, $3, @$); } | expr "and" expr { $$ = BOOLOP($1, And, $3, @$); } | expr "or" expr { $$ = BOOLOP($1, Or, $3, @$); } | "not" expr { $$ = UNARY($2, Not, @$); } + | ternary_if_statement { $$ = $1; } + + | list_comprehension { $$ = $1; } ; id diff --git a/src/lpython/parser/semantics.h b/src/lpython/parser/semantics.h index 93cbd2451e..a6afda94a2 100644 --- a/src/lpython/parser/semantics.h +++ b/src/lpython/parser/semantics.h @@ -109,13 +109,18 @@ static inline Vec SET_EXPR_CTX_02(Vec x, expr_contextType ctx) { #define ANNASSIGN_02(x, y, val, l) make_AnnAssign_t(p.m_a, l, \ EXPR(SET_EXPR_CTX_01(x, Store)), EXPR(y), EXPR(val), 1) -#define DELETE(e, l) make_Delete_t(p.m_a, l, \ +#define DELETE_01(e, l) make_Delete_t(p.m_a, l, \ EXPRS(SET_EXPR_CTX_02(e, Del)), e.size()) +#define DELETE_02(l) make_Delete_t(p.m_a, l, \ + EXPRS(A2LIST(p.m_a, SET_EXPR_CTX_01(TUPLE_EMPTY(l), Del))), 1) +#define DELETE_03(e, l) make_Delete_t(p.m_a, l, \ + EXPRS(A2LIST(p.m_a, SET_EXPR_CTX_01(TUPLE_01(e, l), Del))), 1) #define EXPR_01(e, l) make_Expr_t(p.m_a, l, EXPR(e)) #define RETURN_01(l) make_Return_t(p.m_a, l, nullptr) #define RETURN_02(e, l) make_Return_t(p.m_a, l, EXPR(e)) +#define RETURN_03(l) make_Return_t(p.m_a, l, EXPR(TUPLE_EMPTY(l))) #define PASS(l) make_Pass_t(p.m_a, l) #define BREAK(l) make_Break_t(p.m_a, l) @@ -134,18 +139,37 @@ static inline Vec SET_EXPR_CTX_02(Vec x, expr_contextType ctx) { #define NON_LOCAL(names, l) make_Nonlocal_t(p.m_a, l, \ REDUCE_ARGS(p.m_a, names), names.size()) +static inline ast_t *SET_STORE_01(ast_t *x) { + if(is_a(*EXPR(x))) { + size_t n_elts = down_cast2(x)->n_elts; + for(size_t i=0; i < n_elts; i++) { + SET_EXPR_CTX_01( + (ast_t *) down_cast2(x)->m_elts[i], Store); + } + } + return x; +} +static inline Vec SET_STORE_02(Vec x) { + for (size_t i=0; i < x.size(); i++) { + SET_STORE_01(x[i]); + } + return x; +} #define ASSIGNMENT(targets, val, l) make_Assign_t(p.m_a, l, \ - EXPRS(SET_EXPR_CTX_02(targets, Store)), targets.size(), \ + EXPRS(SET_EXPR_CTX_02(SET_STORE_02(targets), Store)), targets.size(), \ EXPR(val), nullptr) static inline ast_t* TUPLE_02(Allocator &al, Location &l, Vec elts) { if(is_a(*elts[0]) && elts.size() == 1) { return (ast_t*) elts[0]; } - return make_Tuple_t(al, l, EXPRS(SET_EXPR_CTX_02(elts, Store)), elts.size(), - expr_contextType::Store); + return make_Tuple_t(al, l, EXPRS(elts), elts.size(), expr_contextType::Load); } #define TUPLE_01(elts, l) TUPLE_02(p.m_a, l, elts) +#define TUPLE_03(elts, l) make_Tuple_t(p.m_a, l, \ + EXPRS(elts), elts.size(), expr_contextType::Load); +#define TUPLE_EMPTY(l) make_Tuple_t(p.m_a, l, \ + nullptr, 0, expr_contextType::Load) Vec TUPLE_APPEND(Allocator &al, Vec x, ast_t *y) { Vec v; @@ -211,13 +235,38 @@ int dot_count = 0; EXPR(e), STMTS(stmt), stmt.size(), STMTS(orelse), orelse.size()) #define IF_STMT_03(e, stmt, orelse, l) make_If_t(p.m_a, l, \ EXPR(e), STMTS(stmt), stmt.size(), STMTS(A2LIST(p.m_a, orelse)), 1) +#define TERNARY(test, body, orelse, l) make_IfExp_t(p.m_a, l, \ + EXPR(test), EXPR(body), EXPR(orelse)) + +static inline char *extract_type_comment(Allocator &al, LFortran::Str &s) { + std::string str = s.str(); + std::string kw{"type:"}; + + str.erase(str.begin()); // removes "#" at the beginning + str.erase(0, str.find_first_not_of(' ')); // trim left spaces + + std::string::size_type pos = 5; + str = str.substr(pos, str.size()); + str.erase(str.find_last_not_of(' ') + 1); // trim right spaces + str.erase(0, str.find_first_not_of(' ')); // trim left spaces + + s.from_str_view(str); + return s.c_str(al); +} #define FOR_01(target, iter, stmts, l) make_For_t(p.m_a, l, \ - EXPR(SET_EXPR_CTX_01(target, Store)), EXPR(iter), \ + EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \ STMTS(stmts), stmts.size(), nullptr, 0, nullptr) #define FOR_02(target, iter, stmts, orelse, l) make_For_t(p.m_a, l, \ - EXPR(SET_EXPR_CTX_01(target, Store)), EXPR(iter), \ + EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \ STMTS(stmts), stmts.size(), STMTS(orelse), orelse.size(), nullptr) +#define FOR_03(target, iter, type_comment, stmts, l) make_For_t(p.m_a, l, \ + EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \ + STMTS(stmts), stmts.size(), nullptr, 0, extract_type_comment(p.m_a, type_comment)) +#define FOR_04(target, iter, stmts, orelse, type_comment, l) make_For_t(p.m_a, l, \ + EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \ + STMTS(stmts), stmts.size(), STMTS(orelse), orelse.size(), \ + extract_type_comment(p.m_a, type_comment)) #define TRY_01(stmts, except, l) make_Try_t(p.m_a, l, \ STMTS(stmts), stmts.size(), \ @@ -311,6 +360,7 @@ static inline Args *FUNC_ARGS(Allocator &al, Location &l, nullptr, 0, vararg, 1, nullptr, 0, nullptr, 0, kwarg, 1, nullptr, 0) #define STAR_ARGS_05(kwarg, l) FUNC_ARGS(p.m_a, l, nullptr, 0, \ nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, kwarg, 1, nullptr, 0) + #define STAR_ARGS_06(args, vararg, l) FUNC_ARGS(p.m_a, l, nullptr, 0, \ args.p, args.n, vararg, 1, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0) #define STAR_ARGS_07(args, vararg, kwonlyargs, l) FUNC_ARGS(p.m_a, l, nullptr, 0, \ @@ -324,11 +374,45 @@ static inline Args *FUNC_ARGS(Allocator &al, Location &l, #define STAR_ARGS_10(args, kwarg, l) FUNC_ARGS(p.m_a, l, nullptr, 0, \ args.p, args.n, nullptr, 0, nullptr, 0, nullptr, 0, kwarg, 1, nullptr, 0) +#define STAR_ARGS_11(posonlyargs, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, nullptr, 0, nullptr, 0, nullptr, 0, \ + nullptr, 0, nullptr, 0, nullptr, 0) +#define STAR_ARGS_12(posonlyargs, vararg, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, nullptr, 0, vararg, 1, nullptr, 0, \ + nullptr, 0, nullptr, 0, nullptr, 0) +#define STAR_ARGS_13(posonlyargs, vararg, kwonlyargs, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, nullptr, 0, vararg, 1, \ + kwonlyargs.p, kwonlyargs.n, nullptr, 0, nullptr, 0, nullptr, 0) +#define STAR_ARGS_14(posonlyargs, vararg, kwonlyargs, kwarg, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, nullptr, 0, vararg, 1, \ + kwonlyargs.p, kwonlyargs.n, nullptr, 0, kwarg, 1, nullptr, 0) +#define STAR_ARGS_15(posonlyargs, kwarg, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, nullptr, 0, nullptr, 0, nullptr, 0, \ + nullptr, 0, kwarg, 1, nullptr, 0) +#define STAR_ARGS_16(posonlyargs, vararg, kwarg, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, nullptr, 0, vararg, 1, nullptr, 0, \ + nullptr, 0, kwarg, 1, nullptr, 0) +#define STAR_ARGS_17(posonlyargs, args, vararg, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, args.p, args.n, vararg, 1, nullptr, 0, \ + nullptr, 0, nullptr, 0, nullptr, 0) +#define STAR_ARGS_18(posonlyargs, args, kwarg, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, args.p, args.n, nullptr, 0, nullptr, 0, \ + nullptr, 0, kwarg, 1, nullptr, 0) +#define STAR_ARGS_19(posonlyargs, args, vararg, kwarg, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, args.p, args.n, vararg, 1, nullptr, 0, \ + nullptr, 0, kwarg, 1, nullptr, 0) +#define STAR_ARGS_20(posonlyargs, args, vararg, kwonlyargs, kwarg, l) \ + FUNC_ARGS(p.m_a, l, posonlyargs.p, posonlyargs.n, args.p, args.n, \ + vararg, 1, kwonlyargs.p, kwonlyargs.n, nullptr, 0, kwarg, 1, nullptr, 0) + #define FUNC_ARG_LIST_01(args, l) FUNC_ARGS(p.m_a, l, nullptr, 0, \ args.p, args.n, nullptr, 0, nullptr, 0, nullptr, 0, \ nullptr, 0, nullptr, 0) #define FUNC_ARG_LIST_02(l) FUNC_ARGS(p.m_a, l, nullptr, 0, \ nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0) +#define FUNC_ARG_LIST_03(posonlyargs, args, l) FUNC_ARGS(p.m_a, l, \ + posonlyargs.p, posonlyargs.n, args.p, args.n, nullptr, 0, nullptr, 0, \ + nullptr, 0, nullptr, 0, nullptr, 0) #define FUNCTION_01(decorator, id, args, stmts, l) \ make_FunctionDef_t(p.m_a, l, name2char(id), args->arguments, \ @@ -364,40 +448,147 @@ static inline Args *FUNC_ARGS(Allocator &al, Location &l, STMTS(stmts), stmts.size(), nullptr, 0, EXPR(return), nullptr) #define ASYNC_FOR_01(target, iter, stmts, l) make_AsyncFor_t(p.m_a, l, \ - EXPR(SET_EXPR_CTX_01(target, Store)), EXPR(iter), \ + EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \ STMTS(stmts), stmts.size(), nullptr, 0, nullptr) #define ASYNC_FOR_02(target, iter, stmts, orelse, l) make_AsyncFor_t(p.m_a, l, \ - EXPR(SET_EXPR_CTX_01(target, Store)), EXPR(iter), \ + EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \ STMTS(stmts), stmts.size(), STMTS(orelse), orelse.size(), nullptr) #define ASYNC_WITH(items, body, l) make_AsyncWith_t(p.m_a, l, \ items.p, items.size(), STMTS(body), body.size(), nullptr) -Vec MERGE_EXPR(Allocator &al, ast_t *x, ast_t *y) { - Vec v; - v.reserve(al, 2); - v.push_back(al, x); - v.push_back(al, y); - return v; +#define WHILE_01(e, stmts, l) make_While_t(p.m_a, l, \ + EXPR(e), STMTS(stmts), stmts.size(), nullptr, 0) +#define WHILE_02(e, stmts, orelse, l) make_While_t(p.m_a, l, \ + EXPR(e), STMTS(stmts), stmts.size(), STMTS(orelse), orelse.size()) + +static inline ast_t* BOOLOP_01(Allocator &al, Location &loc, + boolopType op, ast_t *x, ast_t *y) { + expr_t* x1 = EXPR(x); + expr_t* y1 = EXPR(y); + Vec v; + v.reserve(al, 4); + if (is_a(*x1)) { + BoolOp_t* tmp = down_cast(x1); + if (op == tmp->m_op) { + for(size_t i = 0; i < tmp->n_values; i++) { + v.push_back(al, tmp->m_values[i]); + } + v.push_back(al, y1); + } else { + v.push_back(al, x1); + v.push_back(al, y1); + } + } else { + v.push_back(al, x1); + v.push_back(al, y1); + } + return make_BoolOp_t(al, loc, op, v.p, v.n); } -#define BOOLOP(x, op, y, l) make_BoolOp_t(p.m_a, l, \ - boolopType::op, EXPRS(MERGE_EXPR(p.m_a, x, y)), 2) +#define BOOLOP(x, op, y, l) BOOLOP_01(p.m_a, l, op, x, y) #define BINOP(x, op, y, l) make_BinOp_t(p.m_a, l, \ EXPR(x), operatorType::op, EXPR(y)) #define UNARY(x, op, l) make_UnaryOp_t(p.m_a, l, unaryopType::op, EXPR(x)) #define COMPARE(x, op, y, l) make_Compare_t(p.m_a, l, \ EXPR(x), cmpopType::op, EXPRS(A2LIST(p.m_a, y)), 1) +char* concat_string(Allocator &al, ast_t *a, char *b) { + char *s = down_cast2(a)->m_value; + return LFortran::s2c(al, std::string(s) + std::string(b)); +} + +char* unescape(Allocator &al, LFortran::Str &s) { + std::string x; + for (size_t idx=0; idx < s.size(); idx++) { + if (s.p[idx] == '\\' && s.p[idx+1] == 'n') { + x += "\n"; + idx++; + } else { + x += s.p[idx]; + } + } + return LFortran::s2c(al, x); +} + #define SYMBOL(x, l) make_Name_t(p.m_a, l, \ x.c_str(p.m_a), expr_contextType::Load) // `x.int_n` is of type BigInt but we store the int64_t directly in AST #define INTEGER(x, l) make_ConstantInt_t(p.m_a, l, x, nullptr) -#define STRING(x, l) make_ConstantStr_t(p.m_a, l, x.c_str(p.m_a), nullptr) +#define STRING1(x, l) make_ConstantStr_t(p.m_a, l, unescape(p.m_a, x), nullptr) +#define STRING2(x, y, l) make_ConstantStr_t(p.m_a, l, concat_string(p.m_a, x, y.c_str(p.m_a)), nullptr) +#define STRING3(id, x, l) PREFIX_STRING(p.m_a, l, name2char(id), x.c_str(p.m_a)) #define FLOAT(x, l) make_ConstantFloat_t(p.m_a, l, x, nullptr) #define COMPLEX(x, l) make_ConstantComplex_t(p.m_a, l, 0, x, nullptr) #define BOOL(x, l) make_ConstantBool_t(p.m_a, l, x, nullptr) +static inline ast_t *PREFIX_STRING(Allocator &al, Location &l, char *prefix, char *s){ + Vec exprs; + exprs.reserve(al, 4); + ast_t *tmp = nullptr; + // Assuming prefix has only one character. + prefix[0] = tolower(prefix[0]); + if (strcmp(prefix, "f") == 0) { + std::string str = std::string(s); + std::string s1 = "\""; + std::string id; + std::vector strs; + bool open_paren = false; + for (size_t i = 0; i < str.length(); i++) { + if(str[i] == '{') { + if(s1 != "\"") { + s1.push_back('"'); + strs.push_back(s1); + s1 = "\""; + } + open_paren = true; + } else if (str[i] != '}' && open_paren) { + id.push_back(s[i]); + } else if (str[i] == '}') { + if(id != "") { + strs.push_back(id); + id = ""; + } + open_paren = false; + } else if (!open_paren) { + s1.push_back(s[i]); + } + if(i == str.length()-1 && s1 != "\"") { + s1.push_back('"'); + strs.push_back(s1); + } + } + + for (size_t i = 0; i < strs.size(); i++) { + if (strs[i][0] == '"') { + strs[i] = strs[i].substr(1, strs[i].length() - 2); + tmp = make_ConstantStr_t(al, l, LFortran::s2c(al, strs[i]), nullptr); + exprs.push_back(al, down_cast(tmp)); + } else { + tmp = make_Name_t(al, l, + LFortran::s2c(al, strs[i]), expr_contextType::Load); + tmp = make_FormattedValue_t(al, l, EXPR(tmp), -1, nullptr); + exprs.push_back(al, down_cast(tmp)); + } + } + tmp = make_JoinedStr_t(al, l, exprs.p, exprs.size()); + } else if (strcmp(prefix, "b") == 0) { + std::string str = std::string(s); + size_t start_pos = 0; + while((start_pos = str.find("\n", start_pos)) != std::string::npos) { + str.replace(start_pos, 1, "\\n"); + start_pos += 2; + } + str = "b'" + str + "'"; + tmp = make_ConstantBytes_t(al, l, LFortran::s2c(al, str), nullptr); + } else if (strcmp(prefix, "r") == 0 ) { + tmp = make_ConstantStr_t(al, l, s, nullptr); + } else { + throw LFortran::LFortranException("The string is not recognized by the parser."); + } + return tmp; +} + static inline keyword_t *CALL_KW(Allocator &al, Location &l, char *arg, expr_t* val) { keyword_t *r = al.allocate(); @@ -419,6 +610,34 @@ static inline keyword_t *CALL_KW(Allocator &al, Location &l, #define ATTRIBUTE_REF(val, attr, l) make_Attribute_t(p.m_a, l, \ EXPR(val), name2char(attr), expr_contextType::Load) +static inline comprehension_t *COMP(Allocator &al, Location &l, + expr_t *target, expr_t* iter, expr_t **ifs, size_t ifs_size, + int64_t is_async) { + comprehension_t *r = al.allocate(); + r->loc = l; + r->m_target = target; + r->m_iter = iter; + r->m_ifs = ifs; + r->n_ifs = ifs_size; + r->m_is_async = is_async; + return r; +} + +static inline ast_t* ID_TUPLE_02(Allocator &al, Location &l, Vec elts) { + if(is_a(*elts[0]) && elts.size() == 1) { + return (ast_t*) SET_EXPR_CTX_01(elts[0], Store); + } + return make_Tuple_t(al, l, EXPRS(SET_EXPR_CTX_02(SET_STORE_02(elts), Store)), elts.size(), expr_contextType::Store); +} +#define ID_TUPLE_01(elts, l) ID_TUPLE_02(p.m_a, l, elts) +#define ID_TUPLE_03(elts, l) make_Tuple_t(p.m_a, l, \ + EXPRS(SET_EXPR_CTX_02(SET_STORE_02(elts), Store)), elts.size(), expr_contextType::Store); + +#define LIST_COMP_1(expr, target, iter, l) make_ListComp_t(p.m_a, l, EXPR(expr), \ + COMP(p.m_a, l, EXPR(target), EXPR(iter), nullptr, 0, 0), 1) +#define LIST_COMP_2(expr, target, iter, ifs, l) make_ListComp_t(p.m_a, l, EXPR(expr), \ + COMP(p.m_a, l, EXPR(SET_EXPR_CTX_01(target, Store)), EXPR(iter), EXPRS(A2LIST(p.m_a, ifs)), 1, 0), 1) + expr_t* CHECK_TUPLE(expr_t *x) { if(is_a(*x) && down_cast(x)->n_elts == 1) { return down_cast(x)->m_elts[0]; @@ -427,12 +646,16 @@ expr_t* CHECK_TUPLE(expr_t *x) { } } +#define ELLIPSIS(l) make_ConstantEllipsis_t(p.m_a, l, nullptr) + +#define NONE(l) make_ConstantNone_t(p.m_a, l, nullptr) + #define TUPLE(elts, l) make_Tuple_t(p.m_a, l, \ EXPRS(elts), elts.size(), expr_contextType::Load) #define SUBSCRIPT_01(value, slice, l) make_Subscript_t(p.m_a, l, \ EXPR(value), CHECK_TUPLE(EXPR(slice)), expr_contextType::Load) #define SUBSCRIPT_02(s, slice, l) make_Subscript_t(p.m_a, l, \ - EXPR(STRING(s, l)), CHECK_TUPLE(EXPR(slice)), expr_contextType::Load) + EXPR(s), CHECK_TUPLE(EXPR(slice)), expr_contextType::Load) static inline ast_t* SLICE(Allocator &al, Location &l, ast_t *lower, ast_t *upper, ast_t *_step) { diff --git a/src/lpython/parser/tokenizer.h b/src/lpython/parser/tokenizer.h index 6ae3b611ad..58ee322a16 100644 --- a/src/lpython/parser/tokenizer.h +++ b/src/lpython/parser/tokenizer.h @@ -23,6 +23,7 @@ class Tokenizer bool indent = false; // Next line is expected to be indented int dedent = 0; // Allowed values: 0, 1, 2, see the code below the meaning of this state variable + bool colon_actual_last_token = false; // If the actual last token was a colon long int last_indent_length = 0; std::vector indent_length; diff --git a/src/lpython/parser/tokenizer.re b/src/lpython/parser/tokenizer.re index f2edf0d2dd..a5bd0842d5 100644 --- a/src/lpython/parser/tokenizer.re +++ b/src/lpython/parser/tokenizer.re @@ -31,6 +31,7 @@ bool lex_oct(const unsigned char *s, const unsigned char *e, uint64_t &u) bool lex_dec(const unsigned char *s, const unsigned char *e, uint64_t &u) { for (u = 0; s < e; ++s) { + if (*s == '_') continue; if (!adddgt<10>(u, *s - 0x30u)) { return false; } @@ -48,6 +49,7 @@ void lex_dec_int_large(Allocator &al, const unsigned char *s, return; } } + // TODO: remove underscore from large ints const unsigned char *start = s; Str num; num.p = (char*)start; @@ -262,20 +264,22 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost whitespace = [ \t\v\r]+; newline = "\n"; digit = [0-9]; - oct_digit = "0"[oO][0-7]+; - bin_digit = "0"[bB][01]+; - hex_digit = "0"[xX][0-9a-fA-F]+; + int_oct = "0"[oO][0-7]+; + int_bin = "0"[bB][01]+; + int_hex = "0"[xX][0-9a-fA-F]+; + int_dec = digit+ (digit | "_" digit)*; char = [a-zA-Z_]; name = char (char | digit)*; significand = (digit+ "." digit*) | ("." digit+); exp = [eE][-+]? digit+; - integer = digit+ | oct_digit | bin_digit | hex_digit; + integer = int_dec | int_oct | int_bin | int_hex; real = (significand exp?) | (digit+ exp); imag_number = (real | digit+)[jJ]; string1 = '"' ('\\"'|[^"\x00])* '"'; string2 = "'" ("\\'"|[^'\x00])* "'"; string3 = '"""' ( '\\"' | '"' [^"\x00] | '""' [^"\x00] | [^"\x00] )* '"""'; string4 = "'''" ( "\\'" | "'" [^'\x00] | "''" [^'\x00] | [^'\x00] )* "'''"; + type_comment = "#" whitespace? "type:" whitespace? [^\n\x00]*; comment = "#" [^\n\x00]*; // docstring = newline whitespace? string1 | string2; ws_comment = whitespace? comment? newline; @@ -356,8 +360,11 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost // Tokens newline { + if(cur[0] == '#') { RET(TK_NEWLINE); } if(parenlevel) { continue; } - if (last_token == yytokentype::TK_COLON) { + if (last_token == yytokentype::TK_COLON + || colon_actual_last_token) { + colon_actual_last_token = false; indent = true; } else if (cur[0] != ' ' && cur[0] != '\n' && last_indent_length > cur-tok) { @@ -379,7 +386,12 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost "+" { RET(TK_PLUS) } "-" { RET(TK_MINUS) } "=" { RET(TK_EQUAL) } - ":" { RET(TK_COLON) } + ":" { + if(cur[0] == '\n'){ + colon_actual_last_token = true; + } + RET(TK_COLON); + } ";" { RET(TK_SEMICOLON) } "/" { RET(TK_SLASH) } "%" { RET(TK_PERCENT) } @@ -426,6 +438,10 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost 'not' { RET(TK_NOT) } 'and' { RET(TK_AND) } 'or' { RET(TK_OR) } + 'is' whitespace 'not' { RET(TK_IS_NOT) } + 'is' whitespace? "\\" newline whitespace? 'not' { RET(TK_IS_NOT) } + 'not' whitespace 'in' { RET(TK_NOT_IN) } + 'not' whitespace? "\\" newline whitespace? 'in' { RET(TK_NOT_IN) } // True/False @@ -445,11 +461,22 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost RET(TK_IMAG_NUM) } - comment newline { + type_comment { + if (last_token == yytokentype::TK_COLON) { + indent = true; + } + token(yylval.string); + RET(TK_TYPE_COMMENT); + } + + comment { + if(last_token == -1) { RET(TK_COMMENT); } if(parenlevel) { continue; } line_num++; cur_line=cur; token(yylval.string); - yylval.string.n--; + // This is commented out because + // the last character in the comment was skipped. + // yylval.string.n--; token_loc(loc); if (last_token == yytokentype::TK_NEWLINE) { return yytokentype::TK_COMMENT; @@ -516,6 +543,7 @@ std::string token2text(const int token) T(TK_STRING, "string") T(TK_COMMENT, "comment") T(TK_EOLCOMMENT, "eolcomment") + T(TK_TYPE_COMMENT, "type_comment") T(TK_POW, "**") T(TK_FLOOR_DIV, "//") @@ -548,6 +576,8 @@ std::string token2text(const int token) T(TK_NOT, "not") T(TK_AND, "and") T(TK_OR, "or") + T(TK_IS_NOT, "is not") + T(TK_NOT_IN, "not in") T(TK_TRUE, "True") T(TK_FALSE, "False") @@ -645,6 +675,8 @@ std::string pickle_token(int token, const LFortran::YYSTYPE &yystype) t += " " + std::to_string(yystype.f) + "j"; } else if (token == yytokentype::TK_STRING) { t = t + " " + "\"" + yystype.string.str() + "\""; + } else if (token == yytokentype::TK_TYPE_COMMENT) { + t = t + " " + "\"" + yystype.string.str() + "\""; } t += ")"; return t; diff --git a/src/lpython/python_evaluator.cpp b/src/lpython/python_evaluator.cpp index 6c155b6f9b..39b8cbf84f 100644 --- a/src/lpython/python_evaluator.cpp +++ b/src/lpython/python_evaluator.cpp @@ -38,9 +38,11 @@ PythonCompiler::~PythonCompiler() = default; Result> PythonCompiler::get_llvm3( #ifdef HAVE_LFORTRAN_LLVM - ASR::TranslationUnit_t &asr, diag::Diagnostics &diagnostics + ASR::TranslationUnit_t &asr, LCompilers::PassManager& lpm, + diag::Diagnostics &diagnostics #else - ASR::TranslationUnit_t &/*asr*/, diag::Diagnostics &/*diagnostics*/ + ASR::TranslationUnit_t &/*asr*/, LCompilers::PassManager&/*lpm*/, + diag::Diagnostics &/*diagnostics*/ #endif ) { @@ -52,8 +54,7 @@ Result> PythonCompiler::get_llvm3( std::unique_ptr m; Result> res = asr_to_llvm(asr, diagnostics, - e->get_context(), al, compiler_options.platform, - compiler_options.fast, get_runtime_library_dir(), + e->get_context(), al, lpm, compiler_options.platform, run_fn); if (res.ok) { m = std::move(res.result); diff --git a/src/lpython/python_evaluator.h b/src/lpython/python_evaluator.h index 49077333ff..3b14385771 100644 --- a/src/lpython/python_evaluator.h +++ b/src/lpython/python_evaluator.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace LFortran { @@ -51,7 +52,7 @@ class PythonCompiler }; Result> get_llvm3(ASR::TranslationUnit_t &asr, - diag::Diagnostics &diagnostics); + LCompilers::PassManager& lpm, diag::Diagnostics &diagnostics); private: Allocator al; diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 70d8fbeffe..b6c8d7b441 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -75,7 +76,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 std::string &rl_path, + std::vector &rl_path, bool <ypes, bool &numpy, const std::function err) { ltypes = false; @@ -93,17 +94,26 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab, // Parse the module `module_name`.py to AST std::string infile0 = module_name + ".py"; - Result rinfile = get_full_path(infile0, rl_path, ltypes, - numpy); - if (!rinfile.ok) { + bool found = false; + std::string path_used = "", infile; + for (auto path: rl_path) { + Result rinfile = get_full_path(infile0, path, ltypes, numpy); + if (rinfile.ok) { + found = true; + infile = rinfile.result; + path_used = path; + break; + } + } + if (!found) { err("Could not find the module '" + infile0 + "'", loc); } if (ltypes) return nullptr; if (numpy) return nullptr; - std::string infile = rinfile.result; + // TODO: diagnostic should be an argument to this function diag::Diagnostics diagnostics; - Result r = parse_python_file(al, rl_path, infile, + Result r = parse_python_file(al, rl_path[0], infile, diagnostics, false); if (!r.ok) { err("The file '" + infile + "' failed to parse", loc); @@ -113,7 +123,8 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab, // Convert the module from AST to ASR LFortran::LocationManager lm; lm.in_filename = infile; - Result r2 = python_ast_to_asr(al, *ast, diagnostics, false, false); + Result r2 = python_ast_to_asr(al, *ast, + diagnostics, false, false, false, path_used); std::string input; read_file(infile, input); CompilerOptions compiler_options; @@ -269,12 +280,15 @@ class CommonVisitor : public AST::BaseVisitor { PythonIntrinsicProcedures intrinsic_procedures; AttributeHandler attr_handler; std::map &ast_overload; + std::string parent_dir; + Vec *current_body; CommonVisitor(Allocator &al, SymbolTable *symbol_table, diag::Diagnostics &diagnostics, bool main_module, - std::map &ast_overload) + std::map &ast_overload, std::string parent_dir) : diag{diagnostics}, al{al}, current_scope{symbol_table}, main_module{main_module}, - ast_overload{ast_overload} { + ast_overload{ast_overload}, parent_dir{parent_dir}, + current_body{nullptr} { current_module_dependencies.reserve(al, 4); } @@ -296,9 +310,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 ltypes, numpy; ASR::Module_t *m = load_module(al, tu_symtab, module_name, - loc, true, rl_path, + loc, true, paths, ltypes, numpy, [&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); } ); @@ -357,140 +372,42 @@ class CommonVisitor : public AST::BaseVisitor { return v; } - void handle_attribute(ASR::symbol_t *s, std::string attr_name, + void handle_attribute(ASR::expr_t *s, std::string attr_name, const Location &loc, Vec &args) { tmp = attr_handler.get_attribute(s, attr_name, al, loc, args, diag); return; } - void fill_func_calls_ttype_t(std::vector& func_calls, ASR::dimension_t* dims, size_t n_dims) { + void fill_expr_in_ttype_t(std::vector& exprs, ASR::dimension_t* dims, size_t n_dims) { for( size_t i = 0; i < n_dims; i++ ) { - func_calls.push_back(dims[i].m_start); - func_calls.push_back(dims[i].m_end); - } - } - - void fix_function_calls_ttype_t(std::vector& func_calls, - Vec& orig_args, - ASR::Function_t* orig_func=nullptr, - bool is_external_func=false) { - for( size_t i = 0; i < func_calls.size(); i++ ) { - ASR::expr_t* potential_call = func_calls[i]; - if (potential_call) { - // The case when expression in return type (like len_expr of character) - // is a function call. - if (ASR::is_a(*potential_call)) { - ASR::FunctionCall_t *fc = ASR::down_cast(potential_call); - ASR::symbol_t *new_es = fc->m_name; - // Import a function as external only if necessary - if( is_external_func ) { - ASR::Function_t *f = nullptr; - if (ASR::is_a(*fc->m_name)) { - f = ASR::down_cast(fc->m_name); - } else if( ASR::is_a(*fc->m_name) ) { - ASR::symbol_t* f_sym = ASRUtils::symbol_get_past_external(fc->m_name); - if( ASR::is_a(*f_sym) ) { - f = ASR::down_cast(f_sym); - } - } - ASR::Module_t *m = ASR::down_cast2(f->m_symtab->parent->asr_owner); - char *modname = m->m_name; - ASR::symbol_t *maybe_f = current_scope->resolve_symbol(std::string(f->m_name)); - std::string maybe_modname = ""; - if( maybe_f && ASR::is_a(*maybe_f) ) { - maybe_modname = ASR::down_cast(maybe_f)->m_module_name; - } - // If the Function to be imported is already present - // then do not import. - if( maybe_modname == std::string(modname) ) { - new_es = maybe_f; - } else { - // Import while assigning a new name to avoid conflicts - // For example, if someone is using `len` from a user - // define module then `get_unique_name` will avoid conflict - std::string unique_name = current_scope->get_unique_name(f->m_name); - Str s; s.from_str_view(unique_name); - char *unique_name_c = s.c_str(al); - LFORTRAN_ASSERT(current_scope->get_symbol(unique_name) == nullptr); - new_es = ASR::down_cast(ASR::make_ExternalSymbol_t( - al, f->base.base.loc, - /* a_symtab */ current_scope, - /* a_name */ unique_name_c, - (ASR::symbol_t*)f, - modname, nullptr, 0, - f->m_name, - ASR::accessType::Private - )); - current_scope->add_symbol(unique_name, new_es); - } - } - Vec args; - args.reserve(al, fc->n_args); - // The following substitutes args from the current scope - for (size_t i = 0; i < fc->n_args; i++) { - ASR::expr_t *arg = fc->m_args[i].m_value; - size_t arg_idx = i; - bool idx_found = false; - if (ASR::is_a(*arg)) { - std::string arg_name = ASRUtils::symbol_name(ASR::down_cast(arg)->m_v); - // Finds the index of the argument to be used for substitution - // Basically if we are calling maybe(string, ret_type=character(len=len(s))) - // where string is a variable in current scope and s is one of the arguments - // accepted by maybe i.e., maybe has a signature maybe(s). Then, we will - // replace s with string. So, the call would become, - // maybe(string, ret_type=character(len=len(string))) - for( size_t j = 0; j < orig_func->n_args && !idx_found; j++ ) { - if( ASR::is_a(*(orig_func->m_args[j])) ) { - std::string arg_name_2 = std::string(ASRUtils::symbol_name(ASR::down_cast(orig_func->m_args[j])->m_v)); - arg_idx = j; - idx_found = arg_name_2 == arg_name; - } - } - } - ASR::call_arg_t call_arg; - call_arg.loc = arg->base.loc; - if( idx_found ) { - arg = orig_args[arg_idx].m_value; - } - call_arg.m_value = arg; - args.push_back(al, call_arg); - } - ASR::expr_t *new_call_expr = ASR::down_cast(ASR::make_FunctionCall_t( - al, fc->base.base.loc, new_es, nullptr, args.p, args.n, fc->m_type, fc->m_value, fc->m_dt)); - func_calls[i] = new_call_expr; - } else { - // If the potential_call is not a call but any other expression - ASR::expr_t *arg = potential_call; - size_t arg_idx = 0; - bool idx_found = false; - if (ASR::is_a(*arg)) { - std::string arg_name = ASRUtils::symbol_name(ASR::down_cast(arg)->m_v); - // Finds the index of the argument to be used for substitution - // Basically if we are calling maybe(3, ret_type=character(len=n)) - // where 3 is an argument to be maybe and n is one of the arguments - // accepted by maybe i.e., maybe has a signature maybe(n). Then, we will - // replace n with 3. So, the call would become, - // maybe(string, ret_type=character(len=3)) - for( size_t j = 0; j < orig_func->n_args && !idx_found; j++ ) { - if( ASR::is_a(*(orig_func->m_args[j])) ) { - std::string arg_name_2 = std::string(ASRUtils::symbol_name(ASR::down_cast(orig_func->m_args[j])->m_v)); - arg_idx = j; - idx_found = arg_name_2 == arg_name; - } - } - } + exprs.push_back(dims[i].m_start); + exprs.push_back(dims[i].m_end); + } + } - if( idx_found ) { - func_calls[i] = orig_args[arg_idx].m_value; - } - } + void fix_exprs_ttype_t(std::vector& exprs, + Vec& orig_args, + ASR::Function_t* orig_func=nullptr) { + ASR::ExprStmtDuplicator expr_duplicator(al); + expr_duplicator.allow_procedure_calls = true; + ASRUtils::ReplaceArgVisitor arg_replacer(al, current_scope, orig_func, + orig_args); + for( size_t i = 0; i < exprs.size(); i++ ) { + ASR::expr_t* expri = exprs[i]; + if (expri) { + expr_duplicator.success = true; + ASR::expr_t* expri_copy = expr_duplicator.duplicate_expr(expri); + LFORTRAN_ASSERT(expr_duplicator.success); + arg_replacer.current_expr = &expri_copy; + arg_replacer.replace_expr(expri_copy); + exprs[i] = expri_copy; } } } ASR::ttype_t* handle_return_type(ASR::ttype_t *return_type, const Location &loc, - Vec& args, bool is_external_func_=true, + Vec& args, ASR::Function_t* f=nullptr) { // Rebuild the return type if needed and make FunctionCalls use ExternalSymbol std::vector func_calls; @@ -498,8 +415,8 @@ class CommonVisitor : public AST::BaseVisitor { case ASR::ttypeType::Character: { ASR::Character_t *t = ASR::down_cast(return_type); func_calls.push_back(t->m_len_expr); - fill_func_calls_ttype_t(func_calls, t->m_dims, t->n_dims); - fix_function_calls_ttype_t(func_calls, args, f, is_external_func_); + fill_expr_in_ttype_t(func_calls, t->m_dims, t->n_dims); + fix_exprs_ttype_t(func_calls, args, f); Vec new_dims; new_dims.reserve(al, t->n_dims); for( size_t i = 1; i < func_calls.size(); i += 2 ) { @@ -517,8 +434,8 @@ class CommonVisitor : public AST::BaseVisitor { } case ASR::ttypeType::Integer: { ASR::Integer_t *t = ASR::down_cast(return_type); - fill_func_calls_ttype_t(func_calls, t->m_dims, t->n_dims); - fix_function_calls_ttype_t(func_calls, args, f, is_external_func_); + fill_expr_in_ttype_t(func_calls, t->m_dims, t->n_dims); + fix_exprs_ttype_t(func_calls, args, f); Vec new_dims; new_dims.reserve(al, t->n_dims); for( size_t i = 0; i < func_calls.size(); i += 2 ) { @@ -532,8 +449,8 @@ class CommonVisitor : public AST::BaseVisitor { } case ASR::ttypeType::Real: { ASR::Real_t *t = ASR::down_cast(return_type); - fill_func_calls_ttype_t(func_calls, t->m_dims, t->n_dims); - fix_function_calls_ttype_t(func_calls, args, f, is_external_func_); + fill_expr_in_ttype_t(func_calls, t->m_dims, t->n_dims); + fix_exprs_ttype_t(func_calls, args, f); Vec new_dims; new_dims.reserve(al, t->n_dims); for( size_t i = 0; i < func_calls.size(); i += 2 ) { @@ -553,14 +470,109 @@ class CommonVisitor : public AST::BaseVisitor { return nullptr; } + void visit_expr_list(AST::expr_t** exprs, size_t n, + Vec exprs_vec) { + LFORTRAN_ASSERT(exprs_vec.reserve_called); + for( size_t i = 0; i < n; i++ ) { + this->visit_expr(*exprs[i]); + exprs_vec.push_back(al, ASRUtils::EXPR(tmp)); + } + } + + void visit_expr_list(AST::expr_t** exprs, size_t n, + Vec& call_args_vec) { + LFORTRAN_ASSERT(call_args_vec.reserve_called); + for( size_t i = 0; i < n; i++ ) { + this->visit_expr(*exprs[i]); + ASR::expr_t* expr = ASRUtils::EXPR(tmp); + ASR::call_arg_t arg; + arg.loc = expr->base.loc; + arg.m_value = expr; + call_args_vec.push_back(al, arg); + } + } + + void visit_expr_list(Vec& exprs, size_t n, + Vec& exprs_vec) { + LFORTRAN_ASSERT(exprs_vec.reserve_called); + for( size_t i = 0; i < n; i++ ) { + exprs_vec.push_back(al, exprs[i].m_value); + } + } + + void visit_expr_list_with_cast(ASR::expr_t** m_args, size_t n_args, + Vec& call_args_vec, + Vec& args) { + LFORTRAN_ASSERT(call_args_vec.reserve_called); + for (size_t i = 0; i < n_args; i++) { + ASR::call_arg_t c_arg; + c_arg.loc = args[i].loc; + c_arg.m_value = cast_helper(m_args[i], + args[i].m_value, true); + call_args_vec.push_back(al, c_arg); + } + } + + ASR::ttype_t* get_type_from_var_annotation(std::string var_annotation, + const Location& loc, Vec& dims, + AST::expr_t** m_args=nullptr, size_t n_args=0) { + ASR::ttype_t* type = nullptr; + if (var_annotation == "i8") { + type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, + 1, dims.p, dims.size())); + } else if (var_annotation == "i16") { + type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, + 2, dims.p, dims.size())); + } else if (var_annotation == "i32") { + type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, + 4, dims.p, dims.size())); + } else if (var_annotation == "i64") { + type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, + 8, dims.p, dims.size())); + } else if (var_annotation == "f32") { + type = ASRUtils::TYPE(ASR::make_Real_t(al, loc, + 4, dims.p, dims.size())); + } else if (var_annotation == "f64") { + type = ASRUtils::TYPE(ASR::make_Real_t(al, loc, + 8, dims.p, dims.size())); + } else if (var_annotation == "c32") { + type = ASRUtils::TYPE(ASR::make_Complex_t(al, loc, + 4, dims.p, dims.size())); + } else if (var_annotation == "c64") { + type = ASRUtils::TYPE(ASR::make_Complex_t(al, loc, + 8, dims.p, dims.size())); + } else if (var_annotation == "str") { + type = ASRUtils::TYPE(ASR::make_Character_t(al, loc, + 1, -2, nullptr, dims.p, dims.size())); + } else if (var_annotation == "bool") { + type = ASRUtils::TYPE(ASR::make_Logical_t(al, loc, + 4, dims.p, dims.size())); + } else if (var_annotation == "CPtr") { + type = ASRUtils::TYPE(ASR::make_CPtr_t(al, loc)); + } else if (var_annotation == "pointer") { + LFORTRAN_ASSERT(n_args == 1); + AST::expr_t* underlying_type = m_args[0]; + type = ast_expr_to_asr_type(underlying_type->base.loc, *underlying_type); + type = ASRUtils::TYPE(ASR::make_Pointer_t(al, loc, type)); + } else { + ASR::symbol_t* der_sym = ASRUtils::symbol_get_past_external( + current_scope->resolve_symbol(var_annotation)); + if( !der_sym || der_sym->type != ASR::symbolType::DerivedType ) { + throw SemanticError("Unsupported type annotation: " + var_annotation, loc); + } + type = ASRUtils::TYPE(ASR::make_Derived_t(al, loc, der_sym, dims.p, dims.size())); + } + return type; + } + // Function to create appropriate call based on symbol type. If it is external // generic symbol then it changes the name accordingly. ASR::asr_t* make_call_helper(Allocator &al, ASR::symbol_t* s, SymbolTable *current_scope, - Vec args, std::string call_name, const Location &loc) { + Vec args, std::string call_name, const Location &loc, + bool ignore_return_value=false) { ASR::symbol_t *s_generic = nullptr, *stemp = s; // handling ExternalSymbol - bool is_external = ASR::is_a(*s); s = ASRUtils::symbol_get_past_external(s); if (ASR::is_a(*s)) { s_generic = stemp; @@ -595,21 +607,124 @@ class CommonVisitor : public AST::BaseVisitor { if (ASR::is_a(*s)) { ASR::Function_t *func = ASR::down_cast(s); ASR::ttype_t *a_type = ASRUtils::expr_type(func->m_return_var); - a_type = handle_return_type(a_type, loc, args, is_external, func); + a_type = handle_return_type(a_type, loc, args, func); ASR::expr_t *value = nullptr; if (ASRUtils::is_intrinsic_function2(func)) { value = intrinsic_procedures.comptime_eval(call_name, al, loc, args); } - return ASR::make_FunctionCall_t(al, loc, stemp, - s_generic, args.p, args.size(), a_type, value, nullptr); + if (args.size() != func->n_args) { + std::string fnd = std::to_string(args.size()); + std::string org = std::to_string(func->n_args); + diag.add(diag::Diagnostic( + "Number of arguments does not match in the function call", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("(found: '" + fnd + "', expected: '" + org + "')", + {loc}) + }) + ); + throw SemanticAbort(); + } + Vec args_new; + args_new.reserve(al, func->n_args); + visit_expr_list_with_cast(func->m_args, func->n_args, args_new, args); + ASR::asr_t* func_call_asr = ASR::make_FunctionCall_t(al, loc, stemp, + s_generic, args_new.p, args_new.size(), + a_type, value, nullptr); + if( ignore_return_value ) { + std::string dummy_ret_name = current_scope->get_unique_name("__lcompilers_dummy"); + ASR::asr_t* variable_asr = ASR::make_Variable_t(al, loc, current_scope, + s2c(al, dummy_ret_name), ASR::intentType::Local, + nullptr, nullptr, ASR::storage_typeType::Default, + a_type, ASR::abiType::Source, ASR::accessType::Public, + ASR::presenceType::Required, false); + ASR::symbol_t* variable_sym = ASR::down_cast(variable_asr); + current_scope->add_symbol(dummy_ret_name, variable_sym); + ASR::expr_t* variable_var = ASRUtils::EXPR(ASR::make_Var_t(al, loc, variable_sym)); + return ASR::make_Assignment_t(al, loc, variable_var, ASRUtils::EXPR(func_call_asr), nullptr); + } else { + return func_call_asr; + } } else if (ASR::is_a(*s)) { + ASR::Subroutine_t *func = ASR::down_cast(s); + if (args.size() != func->n_args) { + std::string fnd = std::to_string(args.size()); + std::string org = std::to_string(func->n_args); + diag.add(diag::Diagnostic( + "Number of arguments does not match in the function call", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("(found: '" + fnd + "', expected: '" + org + "')", + {loc}) + }) + ); + throw SemanticAbort(); + } + Vec args_new; + args_new.reserve(al, func->n_args); + visit_expr_list_with_cast(func->m_args, func->n_args, args_new, args); return ASR::make_SubroutineCall_t(al, loc, stemp, - s_generic, args.p, args.size(), nullptr); + s_generic, args_new.p, args_new.size(), nullptr); + } else if(ASR::is_a(*s)) { + Vec args_new; + args_new.reserve(al, args.size()); + visit_expr_list(args, args.size(), args_new); + ASR::DerivedType_t* derivedtype = ASR::down_cast(s); + for( size_t i = 0; i < std::min(args.size(), derivedtype->n_members); i++ ) { + std::string member_name = derivedtype->m_members[i]; + ASR::Variable_t* member_var = ASR::down_cast( + derivedtype->m_symtab->resolve_symbol(member_name)); + args_new.p[i] = cast_helper(member_var->m_type, args_new[i], true); + } + ASR::ttype_t* der_type = ASRUtils::TYPE(ASR::make_Derived_t(al, loc, s, nullptr, 0)); + return ASR::make_DerivedTypeConstructor_t(al, loc, s, args_new.p, args_new.size(), der_type, nullptr); } else { throw SemanticError("Unsupported call type for " + call_name, loc); } } + void fill_dims_for_asr_type(Vec& dims, + ASR::expr_t* value, const Location& loc) { + ASR::dimension_t dim; + dim.loc = loc; + if (ASR::is_a(*value) || + ASR::is_a(*value)) { + ASR::ttype_t *itype = ASRUtils::expr_type(value); + ASR::expr_t* one = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 1, itype)); + ASR::expr_t* zero = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 0, itype)); + ASR::expr_t* comptime_val = nullptr; + int64_t value_int = -1; + ASRUtils::extract_value(ASRUtils::expr_value(value), value_int); + if( value_int != -1 ) { + comptime_val = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, value_int - 1, itype)); + } + dim.m_start = zero; + dim.m_end = ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, value->base.loc, value, ASR::binopType::Sub, + one, itype, comptime_val)); + dims.push_back(al, dim); + } else if(ASR::is_a(*value)) { + ASR::TupleConstant_t* tuple_constant = ASR::down_cast(value); + for( size_t i = 0; i < tuple_constant->n_elements; i++ ) { + ASR::expr_t *value = tuple_constant->m_elements[i]; + fill_dims_for_asr_type(dims, value, loc); + } + } else { + throw SemanticError("Only Integer, `:` or identifier in [] in Subscript supported for now in annotation" + "found, " + std::to_string(value->type), + loc); + } + } + + bool is_runtime_array(AST::expr_t* m_slice) { + if( AST::is_a(*m_slice) ) { + AST::Tuple_t* multidim = AST::down_cast(m_slice); + for( size_t i = 0; i < multidim->n_elts; i++ ) { + if( AST::is_a(*multidim->m_elts[i]) ) { + return true; + } + } + } + return false; + } + // Convert Python AST type annotation to an ASR type // Examples: // i32, i64, f32, f64 @@ -617,6 +732,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t * ast_expr_to_asr_type(const Location &loc, const AST::expr_t &annotation) { Vec dims; dims.reserve(al, 4); + AST::expr_t** m_args = nullptr; size_t n_args = 0; std::string var_annotation; if (AST::is_a(annotation)) { @@ -680,88 +796,75 @@ class CommonVisitor : public AST::BaseVisitor { throw SemanticError("`dict` annotation must have 2 elements: types of" " both keys and values", loc); } + } else if (var_annotation == "Pointer") { + ASR::ttype_t *type = ast_expr_to_asr_type(loc, *s->m_slice); + return ASRUtils::TYPE(ASR::make_Pointer_t(al, loc, type)); } else { - ASR::dimension_t dim; - dim.loc = loc; if (AST::is_a(*s->m_slice)) { + ASR::dimension_t dim; + dim.loc = loc; dim.m_start = nullptr; dim.m_end = nullptr; + dims.push_back(al, dim); + } else if( is_runtime_array(s->m_slice) ) { + AST::Tuple_t* tuple_multidim = AST::down_cast(s->m_slice); + for( size_t i = 0; i < tuple_multidim->n_elts; i++ ) { + if( AST::is_a(*tuple_multidim->m_elts[i]) ) { + ASR::dimension_t dim; + dim.loc = loc; + dim.m_start = nullptr; + dim.m_end = nullptr; + dims.push_back(al, dim); + } + } } else { this->visit_expr(*s->m_slice); ASR::expr_t *value = ASRUtils::EXPR(tmp); - if (ASR::is_a(*value) || ASR::is_a(*value)) { - ASR::ttype_t *itype = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, - 4, nullptr, 0)); - dim.m_start = ASR::down_cast(ASR::make_IntegerConstant_t(al, loc, 1, itype)); - dim.m_end = value; - } else { - throw SemanticError("Only Integer, `:` or identifier in [] in Subscript supported for now in annotation", - loc); - } + fill_dims_for_asr_type(dims, value, loc); } - - dims.push_back(al, dim); } } else { - throw SemanticError("Only Name or Subscript supported for now in annotation of annotated assignment.", + throw SemanticError("Only Name, Subscript, and Call supported for now in annotation of annotated assignment.", loc); } - ASR::ttype_t *type; - if (var_annotation == "i8") { - type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, - 1, dims.p, dims.size())); - } else if (var_annotation == "i16") { - type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, - 2, dims.p, dims.size())); - } else if (var_annotation == "i32") { - type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, - 4, dims.p, dims.size())); - } else if (var_annotation == "i64") { - type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, - 8, dims.p, dims.size())); - } else if (var_annotation == "f32") { - type = ASRUtils::TYPE(ASR::make_Real_t(al, loc, - 4, dims.p, dims.size())); - } else if (var_annotation == "f64") { - type = ASRUtils::TYPE(ASR::make_Real_t(al, loc, - 8, dims.p, dims.size())); - } else if (var_annotation == "c32") { - type = ASRUtils::TYPE(ASR::make_Complex_t(al, loc, - 4, dims.p, dims.size())); - } else if (var_annotation == "c64") { - type = ASRUtils::TYPE(ASR::make_Complex_t(al, loc, - 8, dims.p, dims.size())); - } else if (var_annotation == "str") { - type = ASRUtils::TYPE(ASR::make_Character_t(al, loc, - 1, -2, nullptr, dims.p, dims.size())); - } else if (var_annotation == "bool") { - type = ASRUtils::TYPE(ASR::make_Logical_t(al, loc, - 4, dims.p, dims.size())); - } else { - throw SemanticError("Unsupported type annotation: " + var_annotation, loc); - } - return type; + return get_type_from_var_annotation(var_annotation, annotation.base.loc, dims, m_args, n_args); } ASR::expr_t *index_add_one(const Location &loc, ASR::expr_t *idx) { // Add 1 to the index `idx`, assumes `idx` is of type Integer 4 - ASR::expr_t *overloaded = nullptr; ASR::expr_t *comptime_value = nullptr; ASR::ttype_t *a_type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4, nullptr, 0)); ASR::expr_t *constant_one = ASR::down_cast(ASR::make_IntegerConstant_t( al, loc, 1, a_type)); - return ASRUtils::EXPR(ASR::make_BinOp_t(al, loc, idx, - ASR::binopType::Add, constant_one, a_type, - comptime_value, overloaded)); + return ASRUtils::EXPR(ASR::make_IntegerBinOp_t(al, loc, idx, + ASR::binopType::Add, constant_one, a_type, comptime_value)); + } + + ASR::expr_t* cast_helper(ASR::expr_t* left, ASR::expr_t* right, bool is_assign) { + bool no_cast = ((ASR::is_a(*ASRUtils::expr_type(left)) && + ASR::is_a(*left)) || + (ASR::is_a(*ASRUtils::expr_type(right)) && + ASR::is_a(*right))); + ASR::ttype_t *right_type = ASRUtils::type_get_past_pointer(ASRUtils::expr_type(right)); + ASR::ttype_t *left_type = ASRUtils::type_get_past_pointer(ASRUtils::expr_type(left)); + if( no_cast ) { + int lkind = ASRUtils::extract_kind_from_ttype_t(left_type); + int rkind = ASRUtils::extract_kind_from_ttype_t(right_type); + if( left_type->type != right_type->type || lkind != rkind ) { + throw SemanticError("Casting for mismatching pointer types not supported yet.", + right_type->base.loc); + } + } + return cast_helper(left_type, right, is_assign); } // Casts `right` if needed to the type of `left` // (to be used during assignment, BinOp, or compare) ASR::expr_t* cast_helper(ASR::ttype_t *left_type, ASR::expr_t *right, bool is_assign=false) { - ASR::ttype_t *right_type = ASRUtils::expr_type(right); + ASR::ttype_t *right_type = ASRUtils::type_get_past_pointer(ASRUtils::expr_type(right)); if (ASRUtils::is_integer(*left_type) && ASRUtils::is_integer(*right_type)) { int lkind = ASR::down_cast(left_type)->m_kind; int rkind = ASR::down_cast(right_type)->m_kind; @@ -786,6 +889,10 @@ class CommonVisitor : public AST::BaseVisitor { al, right->base.loc, right, ASR::cast_kindType::ComplexToComplex, left_type)); } + } else if(is_assign && ASRUtils::is_integer(*left_type) && ASRUtils::is_real(*right_type)) { + return ASR::down_cast(ASRUtils::make_Cast_t_value( + al, right->base.loc, right, ASR::cast_kindType::RealToInteger, + left_type)); } else if (!is_assign && ASRUtils::is_real(*left_type) && ASRUtils::is_integer(*right_type)) { return ASR::down_cast(ASRUtils::make_Cast_t_value( al, right->base.loc, right, ASR::cast_kindType::IntegerToReal, @@ -856,6 +963,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t *right_type = ASRUtils::expr_type(right); ASR::ttype_t *dest_type = nullptr; ASR::expr_t *value = nullptr; + ASR::expr_t *overloaded = nullptr; bool right_is_int = ASRUtils::is_character(*left_type) && ASRUtils::is_integer(*right_type); bool left_is_int = ASRUtils::is_integer(*left_type) && ASRUtils::is_character(*right_type); @@ -1084,24 +1192,9 @@ class CommonVisitor : public AST::BaseVisitor { throw SemanticAbort(); } - // Check that the types are now the same - if (!ASRUtils::check_equal_type(ASRUtils::expr_type(left), - ASRUtils::expr_type(right))) { - std::string ltype = ASRUtils::type_to_str_python(ASRUtils::expr_type(left)); - std::string rtype = ASRUtils::type_to_str_python(ASRUtils::expr_type(right)); - diag.add(diag::Diagnostic( - "Type mismatch in binary operator, the types must be compatible", - diag::Level::Error, diag::Stage::Semantic, { - diag::Label("type mismatch ('" + ltype + "' and '" + rtype + "')", - {left->base.loc, right->base.loc}) - }) - ); - throw SemanticAbort(); - } - ASR::ttype_t* int_type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4, nullptr, 0)); - // Now, compute the result of the binary operations - if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { - if (ASRUtils::is_integer(*dest_type)) { + if (ASRUtils::is_integer(*dest_type)) { + + if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { int64_t left_value = ASR::down_cast( ASRUtils::expr_value(left))->m_n; int64_t right_value = ASR::down_cast( @@ -1113,12 +1206,41 @@ class CommonVisitor : public AST::BaseVisitor { case (ASR::binopType::Mul): { result = left_value * right_value; break; } case (ASR::binopType::Div): { result = left_value / right_value; break; } case (ASR::binopType::Pow): { result = std::pow(left_value, right_value); break; } + case (ASR::binopType::BitAnd): { result = left_value & right_value; break; } + case (ASR::binopType::BitOr): { result = left_value | right_value; break; } + case (ASR::binopType::BitXor): { result = left_value ^ right_value; break; } + case (ASR::binopType::BitLShift): { + if (right_value < 0) { + throw SemanticError("Negative shift count not allowed.", loc); + } + result = left_value << right_value; + break; + } + case (ASR::binopType::BitRShift): { + if (right_value < 0) { + throw SemanticError("Negative shift count not allowed.", loc); + } + result = left_value >> right_value; + break; + } default: { LFORTRAN_ASSERT(false); } // should never happen } value = ASR::down_cast(ASR::make_IntegerConstant_t( al, loc, result, dest_type)); } - else if (ASRUtils::is_real(*dest_type)) { + + tmp = ASR::make_IntegerBinOp_t(al, loc, left, op, right, dest_type, value); + + } else if (ASRUtils::is_real(*dest_type)) { + + if (op == ASR::binopType::BitAnd || op == ASR::binopType::BitOr || op == ASR::binopType::BitXor || + op == ASR::binopType::BitLShift || op == ASR::binopType::BitRShift) { + throw SemanticError("Unsupported binary operation on floats: '" + ASRUtils::binop_to_str_python(op) + "'", loc); + } + + right = cast_helper(left_type, right); + dest_type = ASRUtils::expr_type(right); + if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { double left_value = ASR::down_cast( ASRUtils::expr_value(left))->m_r; double right_value = ASR::down_cast( @@ -1135,7 +1257,17 @@ class CommonVisitor : public AST::BaseVisitor { value = ASR::down_cast(ASR::make_RealConstant_t( al, loc, result, dest_type)); } - else if (ASRUtils::is_complex(*dest_type)) { + + tmp = ASR::make_RealBinOp_t(al, loc, left, op, right, dest_type, value); + + } else if (ASRUtils::is_complex(*dest_type)) { + + if (op == ASR::binopType::BitAnd || op == ASR::binopType::BitOr || op == ASR::binopType::BitXor || + op == ASR::binopType::BitLShift || op == ASR::binopType::BitRShift) { + throw SemanticError("Unsupported binary operation on complex: '" + ASRUtils::binop_to_str_python(op) + "'", loc); + } + + if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { ASR::ComplexConstant_t *left0 = ASR::down_cast( ASRUtils::expr_value(left)); ASR::ComplexConstant_t *right0 = ASR::down_cast( @@ -1154,28 +1286,187 @@ class CommonVisitor : public AST::BaseVisitor { value = ASR::down_cast(ASR::make_ComplexConstant_t(al, loc, std::real(result), std::imag(result), dest_type)); } - else if (ASRUtils::is_logical(*dest_type)) { - int8_t left_value = ASR::down_cast( - ASRUtils::expr_value(left))->m_value; - int8_t right_value = ASR::down_cast( - ASRUtils::expr_value(right))->m_value; - int8_t result; - switch (op) { - case (ASR::binopType::Add): { result = left_value + right_value; break; } - case (ASR::binopType::Sub): { result = left_value - right_value; break; } - case (ASR::binopType::Mul): { result = left_value * right_value; break; } - case (ASR::binopType::Pow): { result = std::pow(left_value, right_value); break; } - case (ASR::binopType::Div): { } // TODO: Handle division of logicals - default: { LFORTRAN_ASSERT(false); } // should never happen - } - value = ASR::down_cast(ASR::make_IntegerConstant_t( - al, loc, result, int_type)); - dest_type = int_type; + + tmp = ASR::make_ComplexBinOp_t(al, loc, left, op, right, dest_type, value); + + } + + if (overloaded != nullptr) { + tmp = ASR::make_OverloadedBinOp_t(al, loc, left, op, right, dest_type, value, overloaded); + } + } + + bool is_dataclass(AST::expr_t** decorators, size_t n) { + if( n != 1 ) { + return false; + } + + AST::expr_t* decorator = decorators[0]; + if( !AST::is_a(*decorator) ) { + return false; + } + + AST::Name_t* dec_name = AST::down_cast(decorator); + return std::string(dec_name->m_id) == "dataclass"; + } + + void visit_AnnAssignUtil(const AST::AnnAssign_t& x, std::string& var_name, + bool wrap_derived_type_in_pointer=false) { + ASR::ttype_t *type = ast_expr_to_asr_type(x.base.base.loc, *x.m_annotation); + if( ASR::is_a(*type) && + wrap_derived_type_in_pointer ) { + type = ASRUtils::TYPE(ASR::make_Pointer_t(al, type->base.loc, type)); + } + + ASR::expr_t *value = nullptr; + ASR::expr_t *init_expr = nullptr; + tmp = nullptr; + if (x.m_value) { + this->visit_expr(*x.m_value); + } + if (tmp) { + value = ASRUtils::EXPR(tmp); + value = cast_helper(type, value, true); + if (!ASRUtils::check_equal_type(type, ASRUtils::expr_type(value))) { + std::string ltype = ASRUtils::type_to_str_python(type); + std::string rtype = ASRUtils::type_to_str_python(ASRUtils::expr_type(value)); + diag.add(diag::Diagnostic( + "Type mismatch in annotation-assignment, the types must be compatible", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("type mismatch ('" + ltype + "' and '" + rtype + "')", + {x.m_target->base.loc, value->base.loc}) + }) + ); + throw SemanticAbort(); } + init_expr = value; + // Set compile time to value to nullptr + // Once constant variables are supported + // in LPython set value according to the + // nature of the variable (nullptr if non-constant, + // otherwise ASRUtils::expr_value(init_expr). + value = nullptr; } - ASR::expr_t *overloaded = nullptr; - tmp = ASR::make_BinOp_t(al, loc, left, op, right, dest_type, - value, overloaded); + ASR::intentType s_intent = ASRUtils::intent_local; + ASR::storage_typeType storage_type = + ASR::storage_typeType::Default; + ASR::abiType current_procedure_abi_type = ASR::abiType::Source; + ASR::accessType s_access = ASR::accessType::Public; + ASR::presenceType s_presence = ASR::presenceType::Required; + bool value_attr = false; + ASR::asr_t *v = ASR::make_Variable_t(al, x.base.base.loc, current_scope, + s2c(al, var_name), s_intent, init_expr, value, storage_type, type, + current_procedure_abi_type, s_access, s_presence, + value_attr); + ASR::symbol_t* v_sym = ASR::down_cast(v); + // Convert initialisation at declaration to assignment + // only for non-global variables. For global variables + // keep relying on `m_symbolic_value`. + if( init_expr && current_body) { + ASR::expr_t* v_expr = ASRUtils::EXPR(ASR::make_Var_t(al, x.base.base.loc, v_sym)); + init_expr = cast_helper(ASRUtils::expr_type(v_expr), init_expr, true); + ASR::asr_t* assign = ASR::make_Assignment_t(al, x.base.base.loc, v_expr, + init_expr, nullptr); + current_body->push_back(al, ASRUtils::STMT(assign)); + ASR::Variable_t* v_variable = ASR::down_cast(v_sym); + v_variable->m_symbolic_value = nullptr; + v_variable->m_value = nullptr; + } + current_scope->add_symbol(var_name, v_sym); + + tmp = nullptr; + } + + void visit_ClassDef(const AST::ClassDef_t& x) { + std::string x_m_name = x.m_name; + if( current_scope->resolve_symbol(x_m_name) ) { + return ; + } + if( !is_dataclass(x.m_decorator_list, x.n_decorator_list) ) { + throw SemanticError("Only dataclass decorated classes are supported.", + x.base.base.loc); + } + + if( x.n_bases > 0 ) { + throw SemanticError("Inheritance in classes isn't supported yet.", + x.base.base.loc); + } + + SymbolTable *parent_scope = current_scope; + current_scope = al.make_new(parent_scope); + + Vec member_names; + member_names.reserve(al, x.n_body); + for( size_t i = 0; i < x.n_body; i++ ) { + LFORTRAN_ASSERT(AST::is_a(*x.m_body[i])); + AST::AnnAssign_t* ann_assign = AST::down_cast(x.m_body[i]); + LFORTRAN_ASSERT(AST::is_a(*ann_assign->m_target)); + AST::Name_t *n = AST::down_cast(ann_assign->m_target); + std::string var_name = n->m_id; + visit_AnnAssignUtil(*ann_assign, var_name, true); + member_names.push_back(al, n->m_id); + } + ASR::symbol_t* class_type = ASR::down_cast(ASR::make_DerivedType_t(al, + x.base.base.loc, current_scope, x.m_name, + member_names.p, member_names.size(), + ASR::abiType::Source, ASR::accessType::Public, + nullptr)); + current_scope = parent_scope; + current_scope->add_symbol(std::string(x.m_name), class_type); + } + + void add_name(const Location &loc) { + std::string var_name = "__name__"; + std::string var_value; + if (main_module) { + var_value = "__main__"; + } else { + // TODO: put the actual module name here + var_value = "__non_main__"; + } + size_t s_size = var_value.size(); + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Character_t(al, loc, + 1, s_size, nullptr, nullptr, 0)); + ASR::expr_t *value = ASRUtils::EXPR(ASR::make_StringConstant_t(al, + loc, s2c(al, var_value), type)); + ASR::expr_t *init_expr = value; + + ASR::intentType s_intent = ASRUtils::intent_local; + ASR::storage_typeType storage_type = + ASR::storage_typeType::Default; + ASR::abiType current_procedure_abi_type = ASR::abiType::Source; + ASR::accessType s_access = ASR::accessType::Public; + ASR::presenceType s_presence = ASR::presenceType::Required; + bool value_attr = false; + ASR::asr_t *v = ASR::make_Variable_t(al, loc, current_scope, + s2c(al, var_name), s_intent, init_expr, value, storage_type, type, + current_procedure_abi_type, s_access, s_presence, + value_attr); + current_scope->add_symbol(var_name, ASR::down_cast(v)); + } + + void add_lpython_version(const Location &loc) { + std::string var_name = "__LPYTHON_VERSION__"; + std::string var_value = LFORTRAN_VERSION; + size_t s_size = var_value.size(); + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Character_t(al, loc, + 1, s_size, nullptr, nullptr, 0)); + ASR::expr_t *value = ASRUtils::EXPR(ASR::make_StringConstant_t(al, + loc, s2c(al, var_value), type)); + ASR::expr_t *init_expr = value; + + ASR::intentType s_intent = ASRUtils::intent_local; + ASR::storage_typeType storage_type = + ASR::storage_typeType::Default; + ASR::abiType current_procedure_abi_type = ASR::abiType::Source; + ASR::accessType s_access = ASR::accessType::Public; + ASR::presenceType s_presence = ASR::presenceType::Required; + bool value_attr = false; + ASR::asr_t *v = ASR::make_Variable_t(al, loc, current_scope, + s2c(al, var_name), s_intent, init_expr, value, storage_type, type, + current_procedure_abi_type, s_access, s_presence, + value_attr); + current_scope->add_symbol(var_name, ASR::down_cast(v)); } void visit_Name(const AST::Name_t &x) { @@ -1183,6 +1474,24 @@ class CommonVisitor : public AST::BaseVisitor { ASR::symbol_t *s = current_scope->resolve_symbol(name); if (s) { tmp = ASR::make_Var_t(al, x.base.base.loc, s); + } else if (name == "i32" || name == "i64" || name == "f32" || name == "f64") { + int64_t i = -1; + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, + 4, nullptr, 0)); + tmp = ASR::make_IntegerConstant_t(al, x.base.base.loc, i, type); + } else if (name == "__name__") { + // __name__ was not declared yet in this scope, so we + // declare it first: + add_name(x.base.base.loc); + // And now resolve it: + ASR::symbol_t *s = current_scope->resolve_symbol(name); + LFORTRAN_ASSERT(s); + tmp = ASR::make_Var_t(al, x.base.base.loc, s); + } else if (name == "__LPYTHON_VERSION__") { + add_lpython_version(x.base.base.loc); + ASR::symbol_t *s = current_scope->resolve_symbol(name); + LFORTRAN_ASSERT(s); + tmp = ASR::make_Var_t(al, x.base.base.loc, s); } else { throw SemanticError("Variable '" + name + "' not declared", x.base.base.loc); @@ -1200,6 +1509,23 @@ class CommonVisitor : public AST::BaseVisitor { tmp = ASR::make_NamedExpr_t(al, x.base.base.loc, target, value, value_type); } + void visit_Tuple(const AST::Tuple_t &x) { + Vec elements; + elements.reserve(al, x.n_elts); + Vec tuple_type_vec; + tuple_type_vec.reserve(al, x.n_elts); + for (size_t i=0; ivisit_expr(*x.m_elts[i]); + ASR::expr_t *expr = ASRUtils::EXPR(tmp); + elements.push_back(al, expr); + tuple_type_vec.push_back(al, ASRUtils::expr_type(expr)); + } + 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_TupleConstant_t(al, x.base.base.loc, + elements.p, elements.size(), tuple_type); + } + void visit_ConstantInt(const AST::ConstantInt_t &x) { int64_t i = x.m_value; ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, @@ -1237,7 +1563,7 @@ class CommonVisitor : public AST::BaseVisitor { } void visit_BoolOp(const AST::BoolOp_t &x) { - ASR::boolopType op; + ASR::logicalbinopType op; if (x.n_values > 2) { throw SemanticError("Only two operands supported for boolean operations", x.base.base.loc); @@ -1247,8 +1573,8 @@ class CommonVisitor : public AST::BaseVisitor { this->visit_expr(*x.m_values[1]); ASR::expr_t *rhs = ASRUtils::EXPR(tmp); switch (x.m_op) { - case (AST::boolopType::And): { op = ASR::boolopType::And; break; } - case (AST::boolopType::Or): { op = ASR::boolopType::Or; break; } + case (AST::boolopType::And): { op = ASR::logicalbinopType::And; break; } + case (AST::boolopType::Or): { op = ASR::logicalbinopType::Or; break; } default : { throw SemanticError("Boolean operator type not supported", x.base.base.loc); @@ -1268,8 +1594,8 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::expr_value(rhs))->m_value; bool result; switch (op) { - case (ASR::boolopType::And): { result = left_value && right_value; break; } - case (ASR::boolopType::Or): { result = left_value || right_value; break; } + case (ASR::logicalbinopType::And): { result = left_value && right_value; break; } + case (ASR::logicalbinopType::Or): { result = left_value || right_value; break; } default : { throw SemanticError("Boolean operator type not supported", x.base.base.loc); @@ -1278,7 +1604,7 @@ class CommonVisitor : public AST::BaseVisitor { value = ASR::down_cast(ASR::make_LogicalConstant_t( al, x.base.base.loc, result, dest_type)); } - tmp = ASR::make_BoolOp_t(al, x.base.base.loc, lhs, op, rhs, dest_type, value); + tmp = ASR::make_LogicalBinOp_t(al, x.base.base.loc, lhs, op, rhs, dest_type, value); } void visit_BinOp(const AST::BinOp_t &x) { @@ -1295,12 +1621,12 @@ class CommonVisitor : public AST::BaseVisitor { case (AST::operatorType::Div) : { op = ASR::binopType::Div; break; } case (AST::operatorType::FloorDiv) : {op = ASR::binopType::Div; break;} case (AST::operatorType::Pow) : { op = ASR::binopType::Pow; break; } + case (AST::operatorType::BitOr) : { op = ASR::binopType::BitOr; break; } + case (AST::operatorType::BitAnd) : { op = ASR::binopType::BitAnd; break; } + case (AST::operatorType::BitXor) : { op = ASR::binopType::BitXor; break; } + case (AST::operatorType::LShift) : { op = ASR::binopType::BitLShift; break; } + case (AST::operatorType::RShift) : { op = ASR::binopType::BitRShift; break; } case (AST::operatorType::Mod) : { op_name = "_mod"; break; } - case (AST::operatorType::BitOr) : { op_name = "_bitwise_or"; break; } - case (AST::operatorType::BitAnd) : { op_name = "_bitwise_and"; break; } - case (AST::operatorType::BitXor) : { op_name = "_bitwise_xor"; break; } - case (AST::operatorType::LShift) : { op_name = "_bitwise_lshift"; break; } - case (AST::operatorType::RShift) : { op_name = "_bitwise_rshift"; break; } default : { throw SemanticError("Binary operator type not supported", x.base.base.loc); @@ -1329,116 +1655,200 @@ class CommonVisitor : public AST::BaseVisitor { void visit_UnaryOp(const AST::UnaryOp_t &x) { this->visit_expr(*x.m_operand); ASR::expr_t *operand = ASRUtils::EXPR(tmp); - ASR::unaryopType op; - switch (x.m_op) { - case (AST::unaryopType::Invert) : { op = ASR::unaryopType::Invert; break; } - case (AST::unaryopType::Not) : { op = ASR::unaryopType::Not; break; } - case (AST::unaryopType::UAdd) : { op = ASR::unaryopType::UAdd; break; } - case (AST::unaryopType::USub) : { op = ASR::unaryopType::USub; break; } - default : { - throw SemanticError("Unary operator type not supported", - x.base.base.loc); - } - } ASR::ttype_t *operand_type = ASRUtils::expr_type(operand); + ASR::ttype_t *dest_type = operand_type; ASR::ttype_t *logical_type = ASRUtils::TYPE( ASR::make_Logical_t(al, x.base.base.loc, 4, nullptr, 0)); ASR::ttype_t *int_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, - 4, nullptr, 0)); + 4, nullptr, 0)); ASR::expr_t *value = nullptr; - if (ASRUtils::expr_value(operand) != nullptr) { + if (x.m_op == AST::unaryopType::Invert) { + if (ASRUtils::is_integer(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + int64_t op_value = ASR::down_cast( + ASRUtils::expr_value(operand))->m_n; + value = ASR::down_cast(ASR::make_IntegerConstant_t( + al, x.base.base.loc, ~op_value, operand_type)); + } + tmp = ASR::make_IntegerBitNot_t(al, x.base.base.loc, operand, dest_type, value); + return; + } + else if (ASRUtils::is_real(*operand_type)) { + throw SemanticError("Unary operator '~' not supported for floats", + x.base.base.loc); + } + else if (ASRUtils::is_logical(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + bool op_value = ASR::down_cast( + ASRUtils::expr_value(operand))->m_value; + value = ASR::down_cast(ASR::make_IntegerConstant_t( + al, x.base.base.loc, op_value ? -2 : -1, int_type)); + } + // cast Logical to Integer + // Reason: Resultant type of an unary operation should be the same as operand type + ASR::expr_t *int_arg = ASR::down_cast(ASR::make_Cast_t( + al, x.base.base.loc, operand, ASR::cast_kindType::LogicalToInteger, + int_type, value)); + tmp = ASR::make_IntegerBitNot_t(al, x.base.base.loc, int_arg, int_type, value); + return; + } + else if (ASRUtils::is_complex(*operand_type)) { + throw SemanticError("Unary operator '~' not supported for complex type", + x.base.base.loc); + } + + } + else if (x.m_op == AST::unaryopType::Not) { - int64_t op_value = ASR::down_cast( + ASR::expr_t *logical_arg = operand; + if (ASRUtils::is_integer(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + int64_t op_value = ASR::down_cast( ASRUtils::expr_value(operand))->m_n; - if (op == ASR::unaryopType::Not) { bool b = (op_value == 0); value = ASR::down_cast(ASR::make_LogicalConstant_t( al, x.base.base.loc, b, logical_type)); - operand_type = logical_type; - } else { - int64_t result = 0; - switch (op) { - case (ASR::unaryopType::UAdd): { result = op_value; break; } - case (ASR::unaryopType::USub): { result = -op_value; break; } - case (ASR::unaryopType::Invert): { result = ~op_value; break; } - default: LFORTRAN_ASSERT(false); // should never happen - } - value = ASR::down_cast(ASR::make_IntegerConstant_t( - al, x.base.base.loc, result, operand_type)); } - - } else if (ASRUtils::is_real(*operand_type)) { - double op_value = ASR::down_cast( + // cast Integer to Logical + logical_arg = ASR::down_cast(ASR::make_Cast_t( + al, x.base.base.loc, operand, ASR::cast_kindType::IntegerToLogical, + logical_type, value)); + } + else if (ASRUtils::is_real(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + double op_value = ASR::down_cast( ASRUtils::expr_value(operand))->m_r; - if (op == ASR::unaryopType::Not) { bool b = (op_value == 0.0); value = ASR::down_cast(ASR::make_LogicalConstant_t( al, x.base.base.loc, b, logical_type)); - operand_type = logical_type; - } else { - double result = 0.0; - switch (op) { - case (ASR::unaryopType::UAdd): { result = op_value; break; } - case (ASR::unaryopType::USub): { result = -op_value; break; } - default: { - throw SemanticError("Bad operand type for unary " + - ASRUtils::unop_to_str(op) + ": " + ASRUtils::type_to_str_python(operand_type), - x.base.base.loc); - } - } - value = ASR::down_cast(ASR::make_RealConstant_t( - al, x.base.base.loc, result, operand_type)); } + // cast Real to Logical + logical_arg = ASR::down_cast(ASR::make_Cast_t( + al, x.base.base.loc, operand, ASR::cast_kindType::RealToLogical, + logical_type, value)); + } + else if (ASRUtils::is_logical(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + bool op_value = ASR::down_cast( + ASRUtils::expr_value(operand))->m_value; + value = ASR::down_cast(ASR::make_LogicalConstant_t( + al, x.base.base.loc, !op_value, logical_type)); + } + } + else if (ASRUtils::is_complex(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + ASR::ComplexConstant_t *c = ASR::down_cast( + ASRUtils::expr_value(operand)); + std::complex op_value(c->m_re, c->m_im); + bool b = (op_value.real() == 0.0 && op_value.imag() == 0.0); + tmp = ASR::make_LogicalConstant_t(al, x.base.base.loc, b, logical_type); + return; + } + // cast Complex to Logical + logical_arg = ASR::down_cast(ASR::make_Cast_t( + al, x.base.base.loc, operand, ASR::cast_kindType::ComplexToLogical, + logical_type, value)); + } + + tmp = ASR::make_LogicalNot_t(al, x.base.base.loc, logical_arg, logical_type, value); + return; + + } + else if (x.m_op == AST::unaryopType::UAdd) { - } else if (ASRUtils::is_logical(*operand_type)) { - bool op_value = ASR::down_cast( + if (ASRUtils::is_integer(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + int64_t op_value = ASR::down_cast( + ASRUtils::expr_value(operand))->m_n; + tmp = ASR::make_IntegerConstant_t(al, x.base.base.loc, op_value, operand_type); + } + } + else if (ASRUtils::is_real(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + double op_value = ASR::down_cast( + ASRUtils::expr_value(operand))->m_r; + tmp = ASR::make_RealConstant_t(al, x.base.base.loc, op_value, operand_type); + } + } + else if (ASRUtils::is_logical(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + bool op_value = ASR::down_cast( ASRUtils::expr_value(operand))->m_value; - if (op == ASR::unaryopType::Not) { - value = ASR::down_cast( - ASR::make_LogicalConstant_t(al, x.base.base.loc, !op_value, logical_type)); - } else { - int8_t result = 0; - switch (op) { - case (ASR::unaryopType::UAdd): { result = +op_value; break; } - case (ASR::unaryopType::USub): { result = -op_value; break; } - case (ASR::unaryopType::Invert): { result = op_value ? -2 : -1; break; } - default : LFORTRAN_ASSERT(false); // should never happen - } - value = ASR::down_cast( - ASR::make_IntegerConstant_t(al, x.base.base.loc, result, int_type)); - operand_type = int_type; + tmp = ASR::make_IntegerConstant_t(al, x.base.base.loc, +op_value, int_type); + return; + } + tmp = ASR::make_Cast_t(al, x.base.base.loc, operand, ASR::cast_kindType::LogicalToInteger, + int_type, value); + } + else if (ASRUtils::is_complex(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + ASR::ComplexConstant_t *c = ASR::down_cast( + ASRUtils::expr_value(operand)); + std::complex op_value(c->m_re, c->m_im); + tmp = ASR::make_ComplexConstant_t(al, x.base.base.loc, + std::real(op_value), std::imag(op_value), operand_type); + } + } + return; + + } + else if (x.m_op == AST::unaryopType::USub) { + + if (ASRUtils::is_integer(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + int64_t op_value = ASR::down_cast( + ASRUtils::expr_value(operand))->m_n; + value = ASR::down_cast(ASR::make_IntegerConstant_t( + al, x.base.base.loc, -op_value, operand_type)); + } + tmp = ASR::make_IntegerUnaryMinus_t(al, x.base.base.loc, operand, + operand_type, value); + return; + } + else if (ASRUtils::is_real(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + double op_value = ASR::down_cast( + ASRUtils::expr_value(operand))->m_r; + value = ASR::down_cast(ASR::make_RealConstant_t( + al, x.base.base.loc, -op_value, operand_type)); + } + tmp = ASR::make_RealUnaryMinus_t(al, x.base.base.loc, operand, + operand_type, value); + return; + } + else if (ASRUtils::is_logical(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + bool op_value = ASR::down_cast( + ASRUtils::expr_value(operand))->m_value; + value = ASR::down_cast(ASR::make_IntegerConstant_t( + al, x.base.base.loc, -op_value, int_type)); } - - } else if (ASRUtils::is_complex(*operand_type)) { - ASR::ComplexConstant_t *c = ASR::down_cast( + // cast Logical to Integer + ASR::expr_t *int_arg = ASR::down_cast(ASR::make_Cast_t( + al, x.base.base.loc, operand, ASR::cast_kindType::LogicalToInteger, + int_type, value)); + tmp = ASR::make_IntegerUnaryMinus_t(al, x.base.base.loc, int_arg, + int_type, value); + return; + } + else if (ASRUtils::is_complex(*operand_type)) { + if (ASRUtils::expr_value(operand) != nullptr) { + ASR::ComplexConstant_t *c = ASR::down_cast( ASRUtils::expr_value(operand)); - std::complex op_value(c->m_re, c->m_im); - std::complex result; - if (op == ASR::unaryopType::Not) { - bool b = (op_value.real() == 0.0 && op_value.imag() == 0.0); - value = ASR::down_cast( - ASR::make_LogicalConstant_t(al, x.base.base.loc, b, logical_type)); - operand_type = logical_type; - } else { - switch (op) { - case (ASR::unaryopType::UAdd): { result = op_value; break; } - case (ASR::unaryopType::USub): { result = -op_value; break; } - default: { - throw SemanticError("Bad operand type for unary " + - ASRUtils::unop_to_str(op) + ": " + ASRUtils::type_to_str_python(operand_type), - x.base.base.loc); - } - } + std::complex op_value(c->m_re, c->m_im); + std::complex result; + result = -op_value; value = ASR::down_cast( - ASR::make_ComplexConstant_t(al, x.base.base.loc, - std::real(result), std::imag(result), operand_type)); + ASR::make_ComplexConstant_t(al, x.base.base.loc, std::real(result), + std::imag(result), operand_type)); } + tmp = ASR::make_ComplexUnaryMinus_t(al, x.base.base.loc, operand, + operand_type, value); + return; } } - tmp = ASR::make_UnaryOp_t(al, x.base.base.loc, op, operand, operand_type, - value); } void visit_IfExp(const AST::IfExp_t &x) { @@ -1451,27 +1861,25 @@ class CommonVisitor : public AST::BaseVisitor { LFORTRAN_ASSERT(ASRUtils::check_equal_type(ASRUtils::expr_type(body), ASRUtils::expr_type(orelse))); tmp = ASR::make_IfExp_t(al, x.base.base.loc, test, body, orelse, - ASRUtils::expr_type(body)); + ASRUtils::expr_type(body), nullptr); } - void visit_Subscript(const AST::Subscript_t &x) { - this->visit_expr(*x.m_value); - ASR::expr_t *value = ASRUtils::EXPR(tmp); - Vec args; - args.reserve(al, 1); + bool visit_SubscriptIndices(AST::expr_t* m_slice, Vec& args, + ASR::expr_t* value, ASR::ttype_t* type, bool& is_item, + const Location& loc) { ASR::array_index_t ai; - ai.loc = x.base.base.loc; + ai.loc = loc; ai.m_left = nullptr; ai.m_right = nullptr; ai.m_step = nullptr; - ASR::symbol_t *s = ASR::down_cast(value)->m_v; - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; - if (AST::is_a(*x.m_slice)) { - AST::Slice_t *sl = AST::down_cast(x.m_slice); + if (AST::is_a(*m_slice)) { + AST::Slice_t *sl = AST::down_cast(m_slice); if (sl->m_lower != nullptr) { this->visit_expr(*sl->m_lower); - ai.m_left = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp)); + if (!ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) { + throw SemanticError("slice indices must be integers or None", tmp->loc); + } + ai.m_left = ASRUtils::EXPR(tmp); } if (sl->m_upper != nullptr) { this->visit_expr(*sl->m_upper); @@ -1482,36 +1890,62 @@ class CommonVisitor : public AST::BaseVisitor { } if (sl->m_step != nullptr) { this->visit_expr(*sl->m_step); - ai.m_step = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp)); + if (!ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) { + throw SemanticError("slice indices must be integers or None", tmp->loc); + } + ai.m_step = ASRUtils::EXPR(tmp); + } + if( ai.m_left != nullptr && + ASR::is_a(*ai.m_left) && + ASR::is_a(*ai.m_right) ) { + ASR::Variable_t* startv = ASRUtils::EXPR2VAR(ai.m_left); + ASR::Variable_t* endv = ASRUtils::EXPR2VAR(ai.m_right); + is_item = is_item && (startv == endv); + } else { + is_item = is_item && (ai.m_left == nullptr && + ai.m_step == nullptr && + ai.m_right != nullptr); } if (ASR::is_a(*type)) { - tmp = ASR::make_ListSection_t(al, x.base.base.loc, value, ai, - type, nullptr); - return; + tmp = ASR::make_ListSection_t(al, loc, value, ai, type, nullptr); + return false; } else if (ASR::is_a(*type)) { - ASR::ttype_t *int_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, - 4, nullptr, 0)); + ASR::ttype_t *int_type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4, nullptr, 0)); // If left is not present, assign it to the first ASR index (0 + 1) in string if (ai.m_left == nullptr) { ai.m_left = ASR::down_cast( - ASR::make_IntegerConstant_t(al, x.base.base.loc, 1, int_type)); + ASR::make_IntegerConstant_t(al, loc, 1, int_type)); + } else { + ai.m_left = index_add_one(loc, ai.m_left); } // If right is not present, then assign it to the last ASR index (-1 + 1) in string if (ai.m_right == nullptr) { ai.m_right = ASR::down_cast( - ASR::make_IntegerConstant_t(al, x.base.base.loc, 0, int_type)); + ASR::make_IntegerConstant_t(al, loc, 0, int_type)); } // If step is not present, assign it to 1 (step should be always present) if (ai.m_step == nullptr) { ai.m_step = ASR::down_cast( - ASR::make_IntegerConstant_t(al, x.base.base.loc, 1, int_type)); + ASR::make_IntegerConstant_t(al, loc, 1, int_type)); + } else { + ai.m_step = index_add_one(loc, ai.m_step); } - tmp = ASR::make_StringSection_t(al, x.base.base.loc, value, ai.m_left, ai.m_right, + tmp = ASR::make_StringSection_t(al, loc, value, ai.m_left, ai.m_right, ai.m_step, type, nullptr); - return; - } + return false; + } else if (ASR::is_a(*type)) { + throw SemanticError("unhashable type in dict: 'slice'", loc); + } + } else if(AST::is_a(*m_slice)) { + bool final_result = true; + AST::Tuple_t* indices = AST::down_cast(m_slice); + for( size_t i = 0; i < indices->n_elts; i++ ) { + final_result &= visit_SubscriptIndices(indices->m_elts[i], args, + value, type, is_item, loc); + } + return final_result; } else { - this->visit_expr(*x.m_slice); + this->visit_expr(*m_slice); if (!ASR::is_a(*type) && !ASRUtils::is_integer(*ASRUtils::expr_type(ASRUtils::EXPR(tmp)))) { std::string fnd = ASRUtils::type_to_str_python(ASRUtils::expr_type(ASRUtils::EXPR(tmp))); @@ -1534,37 +1968,70 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::type_to_str_python(ASRUtils::expr_type(index)) + "'", index->base.loc); } - tmp = make_DictItem_t(al, x.base.base.loc, s, index, nullptr, - ASR::down_cast(type)->m_value_type); - return; + tmp = make_DictItem_t(al, loc, value, index, nullptr, + ASR::down_cast(type)->m_value_type, nullptr); + return false; } else if (ASR::is_a(*type)) { - index = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp)); - tmp = make_ListItem_t(al, x.base.base.loc, s, index, + index = ASRUtils::EXPR(tmp); + tmp = make_ListItem_t(al, loc, value, index, ASR::down_cast(type)->m_type, nullptr); - return; + return false; } else if (ASR::is_a(*type)) { - index = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp)); + index = ASRUtils::EXPR(tmp); int i = ASR::down_cast(ASRUtils::EXPR(tmp))->m_n; - tmp = make_TupleItem_t(al, x.base.base.loc, s, index, + tmp = make_TupleItem_t(al, loc, value, index, ASR::down_cast(type)->m_type[i], nullptr); - return; + return false; } else { - index = index_add_one(x.base.base.loc, ASRUtils::EXPR(tmp)); + index = ASRUtils::EXPR(tmp); } ai.m_right = index; if (ASRUtils::is_character(*type)) { - tmp = ASR::make_StringItem_t(al, x.base.base.loc, value, index, type, nullptr); - return; + index = index_add_one(loc, index); + ai.m_right = index; + tmp = ASR::make_StringItem_t(al, loc, value, index, type, nullptr); + return false; } } + args.push_back(al, ai); + return true; + } + + void visit_Subscript(const AST::Subscript_t &x) { + this->visit_expr(*x.m_value); + ASR::expr_t *value = ASRUtils::EXPR(tmp); + ASR::ttype_t *type = ASRUtils::expr_type(value); + Vec args; + args.reserve(al, 1); + bool is_item = true; if (ASR::is_a(*type)) { throw SemanticError("'set' object is not subscriptable", x.base.base.loc); } - args.push_back(al, ai); - tmp = ASR::make_ArrayRef_t(al, x.base.base.loc, s, args.p, - args.size(), type, nullptr); + + if( !visit_SubscriptIndices(x.m_slice, args, value, type, + is_item, x.base.base.loc) ) { + return ; + } + + if( is_item ) { + for( size_t i = 0; i < args.size(); i++ ) { + args.p[i].m_left = nullptr; + args.p[i].m_step = nullptr; + } + } + ASR::expr_t* v_Var = value; + if( is_item ) { + Vec empty_dims; + empty_dims.reserve(al, 1); + type = ASRUtils::duplicate_type(al, type, &empty_dims); + tmp = ASR::make_ArrayItem_t(al, x.base.base.loc, v_Var, args.p, + args.size(), type, nullptr); + } else { + tmp = ASR::make_ArraySection_t(al, x.base.base.loc, v_Var, args.p, + args.size(), type, nullptr); + } } }; @@ -1584,7 +2051,6 @@ class SymbolTableVisitor : public CommonVisitor { bool is_interface = false; std::string interface_name = ""; bool is_derived_type = false; - Vec data_member_names; std::vector current_procedure_args; ASR::abiType current_procedure_abi_type = ASR::abiType::Source; std::map assgn; @@ -1595,8 +2061,8 @@ class SymbolTableVisitor : public CommonVisitor { SymbolTableVisitor(Allocator &al, SymbolTable *symbol_table, diag::Diagnostics &diagnostics, bool main_module, - std::map &ast_overload) - : CommonVisitor(al, symbol_table, diagnostics, main_module, ast_overload), is_derived_type{false} {} + std::map &ast_overload, std::string parent_dir) + : CommonVisitor(al, symbol_table, diagnostics, main_module, ast_overload, parent_dir), is_derived_type{false} {} ASR::symbol_t* resolve_symbol(const Location &loc, const std::string &sub_name) { @@ -1655,10 +2121,10 @@ class SymbolTableVisitor : public CommonVisitor { void visit_FunctionDef(const AST::FunctionDef_t &x) { SymbolTable *parent_scope = current_scope; current_scope = al.make_new(parent_scope); - Vec args; args.reserve(al, x.m_args.n_args); current_procedure_abi_type = ASR::abiType::Source; + bool current_procedure_interface = false; bool overload = false; if (x.n_decorator_list > 0) { for(size_t i=0; i { std::string name = AST::down_cast(dec)->m_id; if (name == "ccall") { current_procedure_abi_type = ASR::abiType::BindC; + current_procedure_interface = true; + } else if (name == "ccallback" || name == "ccallable") { + current_procedure_abi_type = ASR::abiType::BindC; } else if (name == "overload") { overload = true; } else if (name == "interface") { @@ -1733,11 +2202,12 @@ class SymbolTableVisitor : public CommonVisitor { } ASR::accessType s_access = ASR::accessType::Public; ASR::deftypeType deftype = ASR::deftypeType::Implementation; - if (current_procedure_abi_type == ASR::abiType::BindC) { + if (current_procedure_abi_type == ASR::abiType::BindC && + current_procedure_interface) { deftype = ASR::deftypeType::Interface; } char *bindc_name=nullptr; - if (x.m_returns) { + if (x.m_returns && !AST::is_a(*x.m_returns)) { if (AST::is_a(*x.m_returns) || AST::is_a(*x.m_returns)) { std::string return_var_name = "_lpython_return_variable"; ASR::ttype_t *type = ast_expr_to_asr_type(x.m_returns->base.loc, *x.m_returns); @@ -1815,12 +2285,13 @@ class SymbolTableVisitor : public CommonVisitor { if (!t) { std::string rl_path = get_runtime_library_dir(); SymbolTable *st = current_scope; + std::vector paths = {rl_path, parent_dir}; if (!main_module) { st = st->parent; } bool ltypes, numpy; t = (ASR::symbol_t*)(load_module(al, st, - msym, x.base.base.loc, false, rl_path, ltypes, numpy, + msym, x.base.base.loc, false, paths, ltypes, numpy, [&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); } )); if (ltypes || numpy) { @@ -1849,6 +2320,7 @@ class SymbolTableVisitor : public CommonVisitor { void visit_Import(const AST::Import_t &x) { ASR::symbol_t *t = nullptr; std::string rl_path = get_runtime_library_dir(); + std::vector paths = {rl_path, parent_dir}; SymbolTable *st = current_scope; std::vector mods; for (size_t i=0; i { for (auto &mod_sym : mods) { bool ltypes, numpy; t = (ASR::symbol_t*)(load_module(al, st, - mod_sym, x.base.base.loc, false, rl_path, ltypes, numpy, + mod_sym, x.base.base.loc, false, paths, ltypes, numpy, [&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); } )); if (ltypes || numpy) { @@ -1880,6 +2352,7 @@ class SymbolTableVisitor : public CommonVisitor { void visit_AnnAssign(const AST::AnnAssign_t &/*x*/) { // We skip this in the SymbolTable visitor, but visit it in the BodyVisitor } + void visit_Assign(const AST::Assign_t &/*x*/) { // We skip this in the SymbolTable visitor, but visit it in the BodyVisitor } @@ -1890,9 +2363,9 @@ class SymbolTableVisitor : public CommonVisitor { Result symbol_table_visitor(Allocator &al, const AST::Module_t &ast, diag::Diagnostics &diagnostics, bool main_module, - std::map &ast_overload) + std::map &ast_overload, std::string parent_dir) { - SymbolTableVisitor v(al, nullptr, diagnostics, main_module, ast_overload); + SymbolTableVisitor v(al, nullptr, diagnostics, main_module, ast_overload, parent_dir); try { v.visit_Module(ast); } catch (const SemanticError &e) { @@ -1912,11 +2385,10 @@ class BodyVisitor : public CommonVisitor { public: ASR::asr_t *asr; - Vec *current_body; BodyVisitor(Allocator &al, ASR::asr_t *unit, diag::Diagnostics &diagnostics, bool main_module, std::map &ast_overload) - : CommonVisitor(al, nullptr, diagnostics, main_module, ast_overload), asr{unit} {} + : CommonVisitor(al, nullptr, diagnostics, main_module, ast_overload, ""), asr{unit} {} // Transforms statements to a list of ASR statements // In addition, it also inserts the following nodes if needed: @@ -1925,11 +2397,11 @@ class BodyVisitor : public CommonVisitor { // The `body` Vec must already be reserved void transform_stmts(Vec &body, size_t n_body, AST::stmt_t **m_body) { tmp = nullptr; + Vec* current_body_copy = current_body; + current_body = &body; for (size_t i=0; ivisit_stmt(*m_body[i]); - current_body = nullptr; if (tmp != nullptr) { ASR::stmt_t* tmp_stmt = ASRUtils::STMT(tmp); body.push_back(al, tmp_stmt); @@ -1937,6 +2409,7 @@ class BodyVisitor : public CommonVisitor { // To avoid last statement to be entered twice once we exit this node tmp = nullptr; } + current_body = current_body_copy; } void visit_Module(const AST::Module_t &x) { @@ -2032,41 +2505,7 @@ class BodyVisitor : public CommonVisitor { } } - ASR::ttype_t *type = ast_expr_to_asr_type(x.base.base.loc, *x.m_annotation); - - ASR::expr_t *value = nullptr; - if (x.m_value) { - this->visit_expr(*x.m_value); - value = ASRUtils::EXPR(tmp); - value = cast_helper(type, value, true); - if (!ASRUtils::check_equal_type(type, ASRUtils::expr_type(value))) { - std::string ltype = ASRUtils::type_to_str_python(type); - std::string rtype = ASRUtils::type_to_str_python(ASRUtils::expr_type(value)); - diag.add(diag::Diagnostic( - "Type mismatch in annotation-assignment, the types must be compatible", - diag::Level::Error, diag::Stage::Semantic, { - diag::Label("type mismatch ('" + ltype + "' and '" + rtype + "')", - {x.m_target->base.loc, value->base.loc}) - }) - ); - throw SemanticAbort(); - } - } - ASR::expr_t *init_expr = nullptr; - ASR::intentType s_intent = ASRUtils::intent_local; - ASR::storage_typeType storage_type = - ASR::storage_typeType::Default; - ASR::abiType current_procedure_abi_type = ASR::abiType::Source; - ASR::accessType s_access = ASR::accessType::Public; - ASR::presenceType s_presence = ASR::presenceType::Required; - bool value_attr = false; - ASR::asr_t *v = ASR::make_Variable_t(al, x.base.base.loc, current_scope, - s2c(al, var_name), s_intent, init_expr, value, storage_type, type, - current_procedure_abi_type, s_access, s_presence, - value_attr); - current_scope->add_symbol(var_name, ASR::down_cast(v)); - - tmp = nullptr; + visit_AnnAssignUtil(x, var_name); } void visit_Delete(const AST::Delete_t &x) { @@ -2142,7 +2581,9 @@ class BodyVisitor : public CommonVisitor { ); throw SemanticAbort(); } - tmp = make_DictInsert_t(al, x.base.base.loc, s, key, val); + ASR::expr_t* se = ASR::down_cast( + ASR::make_Var_t(al, x.base.base.loc, s)); + tmp = make_DictInsert_t(al, x.base.base.loc, se, key, val); return; } } @@ -2167,7 +2608,26 @@ class BodyVisitor : public CommonVisitor { ASR::expr_t *value = ASRUtils::EXPR(tmp); ASR::ttype_t *target_type = ASRUtils::expr_type(target); ASR::ttype_t *value_type = ASRUtils::expr_type(value); + if( ASR::is_a(*target_type) && + ASR::is_a(*target) ) { + if( !ASR::is_a(*value) ) { + throw SemanticError("A pointer variable can only " + "be associated with the output " + "of pointer() call.", + value->base.loc); + } + if( !ASRUtils::check_equal_type(target_type, value_type) ) { + throw SemanticError("Casting not supported for different pointer types. Received " + "target pointer type, " + ASRUtils::type_to_str_python(target_type) + + " and value pointer type, " + ASRUtils::type_to_str_python(value_type), + x.base.base.loc); + } + tmp = ASR::make_Assignment_t(al, x.base.base.loc, target, value, nullptr); + return ; + } + value = cast_helper(target, value, true); + value_type = ASRUtils::expr_type(value); if (!ASRUtils::check_equal_type(target_type, value_type)) { std::string ltype = ASRUtils::type_to_str_python(target_type); std::string rtype = ASRUtils::type_to_str_python(value_type); @@ -2180,7 +2640,6 @@ class BodyVisitor : public CommonVisitor { ); throw SemanticAbort(); } - value = cast_helper(ASRUtils::expr_type(target), value, true); ASR::stmt_t *overloaded=nullptr; tmp = ASR::make_Assignment_t(al, x.base.base.loc, target, value, overloaded); @@ -2220,23 +2679,6 @@ class BodyVisitor : public CommonVisitor { list.size(), list_type); } - void visit_Tuple(const AST::Tuple_t &x) { - Vec elements; - elements.reserve(al, x.n_elts); - Vec tuple_type_vec; - tuple_type_vec.reserve(al, x.n_elts); - for (size_t i=0; ivisit_expr(*x.m_elts[i]); - ASR::expr_t *expr = ASRUtils::EXPR(tmp); - elements.push_back(al, expr); - tuple_type_vec.push_back(al, ASRUtils::expr_type(expr)); - } - 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_TupleConstant_t(al, x.base.base.loc, - elements.p, elements.size(), tuple_type); - } - void visit_For(const AST::For_t &x) { this->visit_expr(*x.m_target); ASR::expr_t *target=ASRUtils::EXPR(tmp); @@ -2346,50 +2788,117 @@ class BodyVisitor : public CommonVisitor { } + void visit_AttributeUtil(ASR::ttype_t* type, char* attr_char, + ASR::expr_t *e, const Location& loc) { + if( ASR::is_a(*type) ) { + ASR::Derived_t* der = ASR::down_cast(type); + ASR::symbol_t* der_sym = ASRUtils::symbol_get_past_external(der->m_derived_type); + ASR::DerivedType_t* der_type = ASR::down_cast(der_sym); + bool member_found = false; + std::string member_name = attr_char; + for( size_t i = 0; i < der_type->n_members && !member_found; i++ ) { + member_found = std::string(der_type->m_members[i]) == member_name; + } + if( !member_found ) { + throw SemanticError("No member " + member_name + + " found in " + std::string(der_type->m_name), + loc); + } + ASR::symbol_t* member_sym = der_type->m_symtab->resolve_symbol(member_name); + LFORTRAN_ASSERT(ASR::is_a(*member_sym)); + ASR::Variable_t* member_var = ASR::down_cast(member_sym); + tmp = ASR::make_DerivedRef_t(al, loc, e, member_sym, + member_var->m_type, nullptr); + } else if( ASR::is_a(*type) ) { + ASR::Pointer_t* ptr_type = ASR::down_cast(type); + visit_AttributeUtil(ptr_type->m_type, attr_char, e, loc); + } else { + throw SemanticError(ASRUtils::type_to_str_python(type) + " not supported yet in Attribute.", + loc); + } + } + + void visit_AttributeUtil(ASR::ttype_t* type, char* attr_char, + ASR::symbol_t *t, const Location& loc) { + if (ASRUtils::is_complex(*type)) { + std::string attr = attr_char; + if (attr == "imag") { + ASR::expr_t *val = ASR::down_cast(ASR::make_Var_t(al, loc, t)); + int kind = ASRUtils::extract_kind_from_ttype_t(type); + ASR::ttype_t *dest_type = ASR::down_cast(ASR::make_Real_t(al, loc, + kind, nullptr, 0)); + tmp = ASR::make_ComplexIm_t(al, loc, val, dest_type, nullptr); + return; + } else if (attr == "real") { + ASR::expr_t *val = ASR::down_cast(ASR::make_Var_t(al, loc, t)); + int kind = ASRUtils::extract_kind_from_ttype_t(type); + ASR::ttype_t *dest_type = ASR::down_cast(ASR::make_Real_t(al, loc, + kind, nullptr, 0)); + ASR::expr_t *value = ASR::down_cast(ASRUtils::make_Cast_t_value( + al, val->base.loc, val, ASR::cast_kindType::ComplexToReal, dest_type)); + tmp = ASR::make_ComplexRe_t(al, loc, val, dest_type, ASRUtils::expr_value(value)); + return; + } else { + throw SemanticError("'" + attr + "' is not implemented for Complex type", + loc); + } + } else if( ASR::is_a(*type) ) { + ASR::Derived_t* der = ASR::down_cast(type); + ASR::symbol_t* der_sym = ASRUtils::symbol_get_past_external(der->m_derived_type); + ASR::DerivedType_t* der_type = ASR::down_cast(der_sym); + bool member_found = false; + std::string member_name = attr_char; + for( size_t i = 0; i < der_type->n_members && !member_found; i++ ) { + member_found = std::string(der_type->m_members[i]) == member_name; + } + if( !member_found ) { + throw SemanticError("No member " + member_name + + " found in " + std::string(der_type->m_name), + loc); + } + ASR::expr_t *val = ASR::down_cast(ASR::make_Var_t(al, loc, t)); + ASR::symbol_t* member_sym = der_type->m_symtab->resolve_symbol(member_name); + LFORTRAN_ASSERT(ASR::is_a(*member_sym)); + ASR::Variable_t* member_var = ASR::down_cast(member_sym); + tmp = ASR::make_DerivedRef_t(al, loc, val, member_sym, + member_var->m_type, nullptr); + } else if(ASR::is_a(*type)) { + ASR::Pointer_t* p = ASR::down_cast(type); + visit_AttributeUtil(p->m_type, attr_char, t, loc); + } else { + throw SemanticError(ASRUtils::type_to_str_python(type) + " not supported yet in Attribute.", + loc); + } + } + void visit_Attribute(const AST::Attribute_t &x) { if (AST::is_a(*x.m_value)) { std::string value = AST::down_cast(x.m_value)->m_id; - ASR::symbol_t *t = current_scope->get_symbol(value); + ASR::symbol_t *t = current_scope->resolve_symbol(value); if (!t) { throw SemanticError("'" + value + "' is not defined in the scope", x.base.base.loc); } if (ASR::is_a(*t)) { ASR::Variable_t *var = ASR::down_cast(t); - if (ASRUtils::is_complex(*var->m_type)) { - std::string attr = x.m_attr; - if (attr == "imag") { - ASR::expr_t *val = ASR::down_cast(ASR::make_Var_t(al, x.base.base.loc, t)); - int kind = ASRUtils::extract_kind_from_ttype_t(var->m_type); - ASR::ttype_t *dest_type = ASR::down_cast(ASR::make_Real_t(al, x.base.base.loc, - kind, nullptr, 0)); - tmp = ASR::make_ComplexIm_t(al, x.base.base.loc, val, dest_type, nullptr); - return; - } else if (attr == "real") { - ASR::expr_t *val = ASR::down_cast(ASR::make_Var_t(al, x.base.base.loc, t)); - int kind = ASRUtils::extract_kind_from_ttype_t(var->m_type); - ASR::ttype_t *dest_type = ASR::down_cast(ASR::make_Real_t(al, x.base.base.loc, - kind, nullptr, 0)); - ASR::expr_t *value = ASR::down_cast(ASRUtils::make_Cast_t_value( - al, val->base.loc, val, ASR::cast_kindType::ComplexToReal, dest_type)); - tmp = ASR::make_ComplexRe_t(al, x.base.base.loc, val, dest_type, ASRUtils::expr_value(value)); - return; - } else { - throw SemanticError("'" + attr + "' is not implemented for Complex type", - x.base.base.loc); - } - - } else { - throw SemanticError("Only Complex type supported for now in Attribute", - x.base.base.loc); - } + visit_AttributeUtil(var->m_type, x.m_attr, t, x.base.base.loc); } else { throw SemanticError("Only Variable type is supported for now in Attribute", x.base.base.loc); } + } else if(AST::is_a(*x.m_value)) { + AST::Attribute_t* x_m_value = AST::down_cast(x.m_value); + visit_Attribute(*x_m_value); + ASR::expr_t* e = ASRUtils::EXPR(tmp); + visit_AttributeUtil(ASRUtils::expr_type(e), x.m_attr, e, x.base.base.loc); + } else if(AST::is_a(*x.m_value)) { + AST::Subscript_t* x_m_value = AST::down_cast(x.m_value); + visit_Subscript(*x_m_value); + ASR::expr_t* e = ASRUtils::EXPR(tmp); + visit_AttributeUtil(ASRUtils::expr_type(e), x.m_attr, e, x.base.base.loc); } else { - throw SemanticError("Only Name is supported for now in Attribute", + throw SemanticError("Only Name, Attribute is supported for now in Attribute", x.base.base.loc); } } @@ -2511,6 +3020,7 @@ class BodyVisitor : public CommonVisitor { left = cast_helper(ASRUtils::expr_type(right), left); right = cast_helper(ASRUtils::expr_type(left), right); } + ASR::ttype_t *dest_type = ASRUtils::expr_type(left); // Check that the types are now the same if (!ASRUtils::check_equal_type(ASRUtils::expr_type(left), @@ -2529,18 +3039,14 @@ class BodyVisitor : public CommonVisitor { ASR::ttype_t *type = ASRUtils::TYPE( ASR::make_Logical_t(al, x.base.base.loc, 4, nullptr, 0)); ASR::expr_t *value = nullptr; - ASR::ttype_t *source_type = left_type; - // Now, compute the result - if (ASRUtils::expr_value(left) != nullptr && - ASRUtils::expr_value(right) != nullptr) { - if (ASRUtils::is_integer(*source_type)) { + if (ASRUtils::is_integer(*dest_type)) { + + if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { int64_t left_value = ASR::down_cast( - ASRUtils::expr_value(left)) - ->m_n; + ASRUtils::expr_value(left))->m_n; int64_t right_value = ASR::down_cast( - ASRUtils::expr_value(right)) - ->m_n; + ASRUtils::expr_value(right))->m_n; bool result; switch (asr_op) { case (ASR::cmpopType::Eq): { result = left_value == right_value; break; } @@ -2556,13 +3062,17 @@ class BodyVisitor : public CommonVisitor { } value = ASR::down_cast(ASR::make_LogicalConstant_t( al, x.base.base.loc, result, type)); - } else if (ASRUtils::is_real(*source_type)) { + } + + tmp = ASR::make_IntegerCompare_t(al, x.base.base.loc, left, asr_op, right, type, value); + + } else if (ASRUtils::is_real(*dest_type)) { + + if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { double left_value = ASR::down_cast( - ASRUtils::expr_value(left)) - ->m_r; + ASRUtils::expr_value(left))->m_r; double right_value = ASR::down_cast( - ASRUtils::expr_value(right)) - ->m_r; + ASRUtils::expr_value(right))->m_r; bool result; switch (asr_op) { case (ASR::cmpopType::Eq): { result = left_value == right_value; break; } @@ -2578,7 +3088,13 @@ class BodyVisitor : public CommonVisitor { } value = ASR::down_cast(ASR::make_LogicalConstant_t( al, x.base.base.loc, result, type)); - } else if (ASR::is_a(*source_type)) { + } + + tmp = ASR::make_RealCompare_t(al, x.base.base.loc, left, asr_op, right, type, value); + + } else if (ASRUtils::is_complex(*dest_type)) { + + if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { ASR::ComplexConstant_t *left0 = ASR::down_cast(ASRUtils::expr_value(left)); ASR::ComplexConstant_t *right0 @@ -2605,8 +3121,13 @@ class BodyVisitor : public CommonVisitor { } value = ASR::down_cast(ASR::make_LogicalConstant_t( al, x.base.base.loc, result, type)); + } - } else if (ASRUtils::is_logical(*source_type)) { + tmp = ASR::make_ComplexCompare_t(al, x.base.base.loc, left, asr_op, right, type, value); + + } else if (ASRUtils::is_logical(*dest_type)) { + + if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { bool left_value = ASR::down_cast( ASRUtils::expr_value(left))->m_value; bool right_value = ASR::down_cast( @@ -2626,8 +3147,13 @@ class BodyVisitor : public CommonVisitor { } value = ASR::down_cast(ASR::make_LogicalConstant_t( al, x.base.base.loc, result, type)); + } - } else if (ASRUtils::is_character(*source_type)) { + tmp = ASR::make_LogicalCompare_t(al, x.base.base.loc, left, asr_op, right, type, value); + + } else if (ASRUtils::is_character(*dest_type)) { + + if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) { char* left_value = ASR::down_cast( ASRUtils::expr_value(left))->m_s; char* right_value = ASR::down_cast( @@ -2666,9 +3192,14 @@ class BodyVisitor : public CommonVisitor { value = ASR::down_cast(ASR::make_LogicalConstant_t( al, x.base.base.loc, result, type)); } + + tmp = ASR::make_StringCompare_t(al, x.base.base.loc, left, asr_op, right, type, value); + } + + if (overloaded != nullptr) { + tmp = ASR::make_OverloadedCompare_t(al, x.base.base.loc, left, asr_op, right, type, + value, overloaded); } - tmp = ASR::make_Compare_t(al, x.base.base.loc, left, asr_op, right, - type, value, overloaded); } void visit_Pass(const AST::Pass_t &/*x*/) { @@ -2760,6 +3291,15 @@ class BodyVisitor : public CommonVisitor { if (AST::is_a(*c->m_func)) { AST::Name_t *n = AST::down_cast(c->m_func); call_name = n->m_id; + ASR::symbol_t* s = current_scope->resolve_symbol(call_name); + if( call_name == "c_p_pointer" && !s ) { + tmp = create_CPtrToPointer(*c); + return; + } + if( call_name == "p_c_pointer" && !s ) { + tmp = create_PointerToCPtr(*c); + return; + } } else if (AST::is_a(*c->m_func)) { AST::Attribute_t *at = AST::down_cast(c->m_func); if (AST::is_a(*at->m_value)) { @@ -2775,7 +3315,9 @@ class BodyVisitor : public CommonVisitor { visit_expr(*c->m_args[i]); elements.push_back(al, ASRUtils::EXPR(tmp)); } - handle_attribute(t, at->m_attr, x.base.base.loc, elements); + ASR::expr_t *te = ASR::down_cast( + ASR::make_Var_t(al, x.base.base.loc, t)); + handle_attribute(te, at->m_attr, x.base.base.loc, elements); return; } } else { @@ -2785,19 +3327,52 @@ class BodyVisitor : public CommonVisitor { Vec args; args.reserve(al, c->n_args); - for (size_t i=0; in_args; i++) { - visit_expr(*c->m_args[i]); - ASR::expr_t *expr = ASRUtils::EXPR(tmp); - ASR::call_arg_t arg; - arg.loc = c->m_args[i]->base.loc; - arg.m_value = expr; - args.push_back(al, arg); - } + visit_expr_list(c->m_args, c->n_args, args); if (call_name == "print") { - ASR::expr_t *fmt=nullptr; + ASR::expr_t *fmt = nullptr; Vec args_expr = ASRUtils::call_arg2expr(al, args); + ASR::expr_t *separator = nullptr; + ASR::expr_t *end = nullptr; + if (c->n_keywords > 0) { + std::string arg_name; + for (size_t i = 0; i < c->n_keywords; i++) { + arg_name = c->m_keywords[i].m_arg; + if (arg_name == "sep") { + visit_expr(*c->m_keywords[i].m_value); + separator = ASRUtils::EXPR(tmp); + ASR::ttype_t *type = ASRUtils::expr_type(separator); + if (!ASRUtils::is_character(*type)) { + std::string found = ASRUtils::type_to_str(type); + diag.add(diag::Diagnostic( + "Separator is expected to be of string type", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("Expected string, found: " + found, + {separator->base.loc}) + }) + ); + throw SemanticAbort(); + } + } + if (arg_name == "end") { + visit_expr(*c->m_keywords[i].m_value); + end = ASRUtils::EXPR(tmp); + ASR::ttype_t *type = ASRUtils::expr_type(end); + if (!ASRUtils::is_character(*type)) { + std::string found = ASRUtils::type_to_str(type); + diag.add(diag::Diagnostic( + "End is expected to be of string type", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("Expected string, found: " + found, + {end->base.loc}) + }) + ); + throw SemanticAbort(); + } + } + } + } tmp = ASR::make_Print_t(al, x.base.base.loc, fmt, - args_expr.p, args_expr.size()); + args_expr.p, args_expr.size(), separator, end); return; } else if (call_name == "quit") { @@ -2819,7 +3394,7 @@ class BodyVisitor : public CommonVisitor { x.base.base.loc); } tmp = make_call_helper(al, s, current_scope, args, call_name, - x.base.base.loc); + x.base.base.loc, true); return; } this->visit_expr(*x.m_value); @@ -2850,6 +3425,29 @@ class BodyVisitor : public CommonVisitor { return (ASR::asr_t *)ASR::down_cast(ASR::make_Cast_t( al, loc, arg, ASR::cast_kindType::RealToInteger, to_type, value)); + } else if (ASRUtils::is_character(*type)) { + if (ASRUtils::expr_value(arg) != nullptr) { + char *c = ASR::down_cast( + ASRUtils::expr_value(arg))->m_s; + int ival = 0; + char *ch = c; + if (*ch == '-') { + ch++; + } + while (*ch) { + if (*ch == '.') { + throw SemanticError("invalid literal for int() with base 10: '"+ std::string(c) + "'", arg->base.loc); + } + if (*ch < '0' || *ch > '9') { + throw SemanticError("invalid literal for int() with base 10: '"+ std::string(c) + "'", arg->base.loc); + } + ch++; + } + ival = std::stoi(c); + return (ASR::asr_t *)ASR::down_cast(ASR::make_IntegerConstant_t(al, + loc, ival, to_type)); + } + // TODO: make int() work for non-constant strings } else if (ASRUtils::is_logical(*type)) { if (ASRUtils::expr_value(arg) != nullptr) { int32_t ival = ASR::down_cast( @@ -2890,27 +3488,18 @@ class BodyVisitor : public CommonVisitor { loc, dval, to_type)); } return (ASR::asr_t *)ASR::down_cast(ASR::make_Cast_t( - al, loc, arg, ASR::cast_kindType::IntegerToReal, - to_type, value)); + al, loc, arg, ASR::cast_kindType::IntegerToReal, + to_type, value)); } else if (ASRUtils::is_logical(*type)) { - int32_t ival = 0; - ASR::ttype_t *int_type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, - 4, nullptr, 0)); if (ASRUtils::expr_value(arg) != nullptr) { - ival = ASR::down_cast( + double dval = ASR::down_cast( ASRUtils::expr_value(arg))->m_value; - value = ASR::down_cast(make_IntegerConstant_t(al, - loc, ival, int_type)); + value = ASR::down_cast(make_RealConstant_t(al, + loc, dval, to_type)); } - ASR::expr_t *t = ASR::down_cast(ASR::make_Cast_t( - al, loc, arg, ASR::cast_kindType::LogicalToInteger, - int_type, value)); - double dval = ival; - value = ASR::down_cast(make_RealConstant_t(al, - loc, dval, to_type)); return (ASR::asr_t *)ASR::down_cast(ASR::make_Cast_t( - al, loc, t, ASR::cast_kindType::IntegerToReal, - to_type, value)); + al, loc, arg, ASR::cast_kindType::LogicalToReal, + to_type, value)); } else if (!ASRUtils::is_real(*type)) { std::string stype = ASRUtils::type_to_str_python(type); throw SemanticError( @@ -2920,6 +3509,72 @@ class BodyVisitor : public CommonVisitor { return nullptr; } + ASR::asr_t* handle_intrinsic_bool(Allocator &al, Vec args, + const Location &loc) { + ASR::expr_t *arg = nullptr, *value = nullptr; + ASR::ttype_t *type = nullptr; + if (args.size() > 0) { + arg = args[0].m_value; + type = ASRUtils::expr_type(arg); + } + ASR::ttype_t *to_type = ASRUtils::TYPE(ASR::make_Logical_t(al, loc, + 4, nullptr, 0)); + if (!arg) { + return ASR::make_LogicalConstant_t(al, loc, false, to_type); + } + if (ASRUtils::is_integer(*type)) { + if (ASRUtils::expr_value(arg) != nullptr) { + bool b = ASR::down_cast( + ASRUtils::expr_value(arg))->m_n; + value = ASR::down_cast(make_LogicalConstant_t(al, + loc, b, to_type)); + } + return (ASR::asr_t *)ASR::down_cast(ASR::make_Cast_t( + al, loc, arg, ASR::cast_kindType::IntegerToLogical, to_type, value)); + + } else if (ASRUtils::is_real(*type)) { + if (ASRUtils::expr_value(arg) != nullptr) { + bool b = ASR::down_cast( + ASRUtils::expr_value(arg))->m_r; + value = ASR::down_cast(make_LogicalConstant_t(al, + loc, b, to_type)); + } + return (ASR::asr_t *)ASR::down_cast(ASR::make_Cast_t( + al, loc, arg, ASR::cast_kindType::RealToLogical, to_type, value)); + + } else if (ASRUtils::is_character(*type)) { + if (ASRUtils::expr_value(arg) != nullptr) { + char *c = ASR::down_cast( + ASRUtils::expr_value(arg))->m_s; + value = ASR::down_cast(make_LogicalConstant_t(al, + loc, std::string(c) != "", to_type)); + } + return (ASR::asr_t *)ASR::down_cast(ASR::make_Cast_t( + al, loc, arg, ASR::cast_kindType::CharacterToLogical, to_type, value)); + + } else if (ASRUtils::is_complex(*type)) { + if (ASRUtils::expr_value(arg) != nullptr) { + ASR::ComplexConstant_t *c_arg = ASR::down_cast( + ASRUtils::expr_value(arg)); + std::complex c_value(c_arg->m_re, c_arg->m_im); + value = ASR::down_cast(make_LogicalConstant_t(al, + loc, c_value.real() != 0.0 || c_value.imag() != 0.0, to_type)); + } + return (ASR::asr_t *)ASR::down_cast(ASR::make_Cast_t( + al, loc, arg, ASR::cast_kindType::ComplexToLogical, to_type, value)); + + } else if (ASRUtils::is_logical(*type)) { + return (ASR::asr_t *)arg; + } else { + std::string stype = ASRUtils::type_to_str_python(type); + throw SemanticError( + "Conversion of '" + stype + "' to logical is not Implemented", + loc); + } + // TODO: Make this work if the argument is, let's say, a class. + return nullptr; + } + ASR::asr_t* handle_intrinsic_len(Allocator &al, Vec args, const Location &loc) { if (args.size() != 1) { @@ -2981,18 +3636,42 @@ class BodyVisitor : public CommonVisitor { throw SemanticError("len() is only supported for `str`, `set`, `dict`, `list` and `tuple`", loc); } + ASR::asr_t* create_CPtrToPointer(const AST::Call_t& x) { + if( x.n_args != 2 ) { + throw SemanticError("c_p_pointer accepts two positional arguments, " + "first a variable of c_ptr type and second " + " the target type of the first variable.", + x.base.base.loc); + } + visit_expr(*x.m_args[0]); + ASR::expr_t* cptr = ASRUtils::EXPR(tmp); + visit_expr(*x.m_args[1]); + ASR::expr_t* pptr = ASRUtils::EXPR(tmp); + return ASR::make_CPtrToPointer_t(al, x.base.base.loc, cptr, + pptr, nullptr); + } + + ASR::asr_t* create_PointerToCPtr(const AST::Call_t& x) { + if( x.n_args != 2 ) { + throw SemanticError("p_c_pointer accepts two positional arguments, " + "first a Pointer variable, second a CPtr variable.", + x.base.base.loc); + } + visit_expr(*x.m_args[0]); + ASR::expr_t* pptr = ASRUtils::EXPR(tmp); + visit_expr(*x.m_args[1]); + ASR::expr_t* cptr = ASRUtils::EXPR(tmp); + ASR::asr_t* pp = ASR::make_PointerToCPtr_t(al, x.base.base.loc, pptr, + ASRUtils::expr_type(cptr), nullptr); + return ASR::make_Assignment_t(al, x.base.base.loc, + cptr, ASR::down_cast(pp), nullptr); + } + void visit_Call(const AST::Call_t &x) { std::string call_name; Vec args; args.reserve(al, x.n_args); - for (size_t i=0; ibase.loc; - arg.m_value = expr; - args.push_back(al, arg); - } + visit_expr_list(x.m_args, x.n_args, args); if (AST::is_a(*x.m_func)) { AST::Name_t *n = AST::down_cast(x.m_func); call_name = n->m_id; @@ -3018,7 +3697,9 @@ class BodyVisitor : public CommonVisitor { for (size_t i=0; im_attr, x.base.base.loc, eles); + ASR::expr_t *se = ASR::down_cast( + ASR::make_Var_t(al, x.base.base.loc, st)); + handle_attribute(se, at->m_attr, x.base.base.loc, eles); return; } throw SemanticError("module '" + mod_name + "' is not imported", @@ -3088,6 +3769,11 @@ class BodyVisitor : public CommonVisitor { // with the type tmp = nullptr; return; + } else if (call_name == "empty_c_void_p") { + // TODO: check that `empty_c_void_p uses` has arguments that are compatible + // with the type + tmp = nullptr; + return; } else if (call_name == "TypeVar") { // Ignore TypeVar for now, we handle it based on the identifier itself tmp = nullptr; @@ -3108,20 +3794,27 @@ class BodyVisitor : public CommonVisitor { } tmp = ASR::make_LogicalConstant_t(al, x.base.base.loc, result, type); return; - } else if (call_name == "int" || call_name == "float") { + } else if (call_name == "int" || call_name == "float" || call_name == "bool") { if (args.size() > 1) { throw SemanticError("Either 0 or 1 argument is expected in '" + call_name + "'", x.base.base.loc); } if (call_name == "int") { tmp = handle_intrinsic_int(al, args, x.base.base.loc); - } else { + } else if (call_name == "float") { tmp = handle_intrinsic_float(al, args, x.base.base.loc); + } else { + tmp = handle_intrinsic_bool(al, args, x.base.base.loc); } return; } else if (call_name == "len") { tmp = handle_intrinsic_len(al, args, x.base.base.loc); return; + } else if( call_name == "pointer" ) { + ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Pointer_t(al, x.base.base.loc, + ASRUtils::expr_type(args[0].m_value))); + tmp = ASR::make_GetPointer_t(al, x.base.base.loc, args[0].m_value, type, nullptr); + return ; } else { // The function was not found and it is not intrinsic throw SemanticError("Function '" + call_name + "' is not declared and not intrinsic", @@ -3191,17 +3884,26 @@ std::string pickle_tree_python(AST::ast_t &ast, bool colors) { return v.get_str(); } +std::string get_parent_dir(const std::string &path) { + int idx = path.size()-1; + while (idx >= 0 && path[idx] != '/' && path[idx] != '\\') idx--; + if (idx == -1) { + return ""; + } + return path.substr(0,idx); +} + Result python_ast_to_asr(Allocator &al, AST::ast_t &ast, diag::Diagnostics &diagnostics, bool main_module, - bool symtab_only) + bool disable_main, bool symtab_only, std::string file_path) { std::map ast_overload; - + std::string parent_dir = get_parent_dir(file_path); AST::Module_t *ast_m = AST::down_cast2(&ast); ASR::asr_t *unit; auto res = symbol_table_visitor(al, *ast_m, diagnostics, main_module, - ast_overload); + ast_overload, parent_dir); if (res.ok) { unit = res.result; } else { @@ -3222,10 +3924,25 @@ Result python_ast_to_asr(Allocator &al, } if (main_module) { - // If it is a main module, turn it into a program. + // If it is a main module, turn it into a program // Note: we can modify this behavior for interactive mode later - pass_wrap_global_stmts_into_program(al, *tu, "_lpython_main_program"); - LFORTRAN_ASSERT(asr_verify(*tu)); + if (disable_main) { + if (tu->n_items > 0) { + diagnostics.add(diag::Diagnostic( + "The script is invoked as the main module and it has code to execute,\n" + "but `--disable-main` was passed so no code was generated for `main`.\n" + "We are removing all global executable code from ASR.", + diag::Level::Warning, diag::Stage::Semantic, {}) + ); + // We have to remove the code + tu->m_items=nullptr; + tu->n_items=0; + LFORTRAN_ASSERT(asr_verify(*tu)); + } + } else { + pass_wrap_global_stmts_into_program(al, *tu, "_lpython_main_program"); + LFORTRAN_ASSERT(asr_verify(*tu)); + } } return tu; diff --git a/src/lpython/semantics/python_ast_to_asr.h b/src/lpython/semantics/python_ast_to_asr.h index dc7b749f4f..75b0bb6054 100644 --- a/src/lpython/semantics/python_ast_to_asr.h +++ b/src/lpython/semantics/python_ast_to_asr.h @@ -7,10 +7,10 @@ namespace LFortran::LPython { std::string pickle_python(AST::ast_t &ast, bool colors=false, bool indent=false); - std::string pickle_tree_python(AST::ast_t &ast, bool colors=true); + std::string pickle_tree_python(AST::ast_t &ast, bool colors=true); Result python_ast_to_asr(Allocator &al, - LPython::AST::ast_t &ast, diag::Diagnostics &diagnostics, bool main_module, - bool symtab_only); + LPython::AST::ast_t &ast, diag::Diagnostics &diagnostics, + bool main_module, bool disable_main, bool symtab_only, std::string file_path); } // namespace LFortran diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 6f29dca952..09649a484c 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -11,7 +11,7 @@ namespace LFortran { struct AttributeHandler { - typedef ASR::asr_t* (*attribute_eval_callback)(ASR::symbol_t*, Allocator &, + typedef ASR::asr_t* (*attribute_eval_callback)(ASR::expr_t*, Allocator &, const Location &, Vec &, diag::Diagnostics &); std::map attribute_map; @@ -41,10 +41,9 @@ struct AttributeHandler { return ""; } - ASR::asr_t* get_attribute(ASR::symbol_t *s, std::string attr_name, + ASR::asr_t* get_attribute(ASR::expr_t *e, std::string attr_name, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(e); std::string class_name = get_type_name(type); if (class_name == "") { throw SemanticError("Type name is not implemented yet.", loc); @@ -53,21 +52,20 @@ struct AttributeHandler { auto search = attribute_map.find(key); if (search != attribute_map.end()) { attribute_eval_callback cb = search->second; - return cb(s, al, loc, args, diag); + return cb(e, al, loc, args, diag); } else { throw SemanticError(class_name + "." + attr_name + " is not implemented yet", loc); } } - static ASR::asr_t* eval_list_append(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_list_append(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { if (args.size() != 1) { throw SemanticError("append() takes exactly one argument", loc); } - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::expr_type(args[0]); if (!ASRUtils::check_equal_type(ele_type, list_type)) { @@ -85,14 +83,13 @@ struct AttributeHandler { return make_ListAppend_t(al, loc, s, args[0]); } - static ASR::asr_t* eval_list_remove(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_list_remove(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { if (args.size() != 1) { throw SemanticError("remove() takes exactly one argument", loc); } - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::expr_type(args[0]); if (!ASRUtils::check_equal_type(ele_type, list_type)) { @@ -110,7 +107,7 @@ struct AttributeHandler { return make_ListRemove_t(al, loc, s, args[0]); } - static ASR::asr_t* eval_list_insert(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_list_insert(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { if (args.size() != 2) { throw SemanticError("insert() takes exactly two arguments", @@ -125,8 +122,7 @@ struct AttributeHandler { } ASR::ttype_t *ele_type = ASRUtils::expr_type(args[1]); - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; if (!ASRUtils::check_equal_type(ele_type, list_type)) { std::string fnd = ASRUtils::type_to_str_python(ele_type); @@ -143,7 +139,7 @@ struct AttributeHandler { return make_ListInsert_t(al, loc, s, args[0], args[1]); } - static ASR::asr_t* eval_list_pop(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_list_pop(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { if (args.size() > 1) { throw SemanticError("pop() takes atmost one argument", @@ -152,8 +148,7 @@ struct AttributeHandler { ASR::expr_t *idx = nullptr; ASR::ttype_t *int_type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4, nullptr, 0)); - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; if (args.size() == 1) { ASR::ttype_t *pos_type = ASRUtils::expr_type(args[0]); @@ -178,28 +173,24 @@ struct AttributeHandler { return make_ListPop_t(al, loc, s, idx, list_type, nullptr); } - static ASR::asr_t* eval_set_pop(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_set_pop(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &/*diag*/) { if (args.size() != 0) { throw SemanticError("pop() takes no arguments (" + std::to_string(args.size()) + " given)", loc); } - - ASR::Variable_t *v = ASR::down_cast(s); - - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *set_type = ASR::down_cast(type)->m_type; return make_SetPop_t(al, loc, s, set_type, nullptr); } - static ASR::asr_t* eval_set_add(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_set_add(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { if (args.size() != 1) { throw SemanticError("add() takes exactly one argument", loc); } - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *set_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::expr_type(args[0]); if (!ASRUtils::check_equal_type(ele_type, set_type)) { @@ -218,14 +209,13 @@ struct AttributeHandler { return make_SetInsert_t(al, loc, s, args[0]); } - static ASR::asr_t* eval_set_remove(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_set_remove(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { if (args.size() != 1) { throw SemanticError("remove() takes exactly one argument", loc); } - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *set_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::expr_type(args[0]); if (!ASRUtils::check_equal_type(ele_type, set_type)) { @@ -244,15 +234,14 @@ struct AttributeHandler { return make_SetRemove_t(al, loc, s, args[0]); } - static ASR::asr_t* eval_dict_get(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_dict_get(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { ASR::expr_t *def = nullptr; if (args.size() > 2 || args.size() < 1) { throw SemanticError("'get' takes atleast 1 and atmost 2 arguments", loc); } - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *key_type = ASR::down_cast(type)->m_key_type; ASR::ttype_t *value_type = ASR::down_cast(type)->m_value_type; if (args.size() == 2) { @@ -282,16 +271,15 @@ struct AttributeHandler { ); throw SemanticAbort(); } - return make_DictItem_t(al, loc, s, args[0], def, value_type); + return make_DictItem_t(al, loc, s, args[0], def, value_type, nullptr); } - static ASR::asr_t* eval_dict_pop(ASR::symbol_t *s, Allocator &al, const Location &loc, + static ASR::asr_t* eval_dict_pop(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { if (args.size() != 1) { throw SemanticError("'pop' takes only one argument for now", loc); } - ASR::Variable_t *v = ASR::down_cast(s); - ASR::ttype_t *type = v->m_type; + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *key_type = ASR::down_cast(type)->m_key_type; ASR::ttype_t *value_type = ASR::down_cast(type)->m_value_type; if (!ASRUtils::check_equal_type(ASRUtils::expr_type(args[0]), key_type)) { diff --git a/src/lpython/semantics/python_comptime_eval.h b/src/lpython/semantics/python_comptime_eval.h index 2eeb3c009d..5cf61ecd5c 100644 --- a/src/lpython/semantics/python_comptime_eval.h +++ b/src/lpython/semantics/python_comptime_eval.h @@ -32,7 +32,6 @@ struct PythonIntrinsicProcedures { comptime_eval_map = { {"abs", {m_builtin, &eval_abs}}, {"str", {m_builtin, &eval_str}}, - {"bool", {m_builtin, &eval_bool}}, {"chr", {m_builtin, &eval_chr}}, {"ord", {m_builtin, &eval_ord}}, // {"len", {m_builtin, &eval_len}}, @@ -49,12 +48,7 @@ struct PythonIntrinsicProcedures { {"_lpython_floordiv", {m_builtin, &eval__lpython_floordiv}}, {"_mod", {m_builtin, &eval__mod}}, {"max" , {m_builtin , &eval_max}}, - {"min" , {m_builtin , &eval_min}}, - {"_bitwise_or", {m_builtin, &eval__bitwise_or}}, - {"_bitwise_and", {m_builtin, &eval__bitwise_and}}, - {"_bitwise_xor", {m_builtin, &eval__bitwise_xor}}, - {"_bitwise_lshift", {m_builtin, &eval__bitwise_lshift}}, - {"_bitwise_rshift", {m_builtin, &eval__bitwise_rshift}} + {"min" , {m_builtin , &eval_min}} }; } @@ -170,38 +164,6 @@ struct PythonIntrinsicProcedures { } } - static ASR::expr_t *eval_bool(Allocator &al, const Location &loc, Vec &args) { - LFORTRAN_ASSERT(ASRUtils::all_args_evaluated(args)); - if (args.size() != 1) { - throw SemanticError("bool() takes exactly one argument (" + - std::to_string(args.size()) + " given)", loc); - } - ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Logical_t(al, loc, - 4, nullptr, 0)); - ASR::expr_t* arg = args[0]; - ASR::ttype_t* t = ASRUtils::expr_type(arg); - bool result; - if (ASRUtils::is_real(*t)) { - result = ASR::down_cast(arg)->m_r; - } else if (ASRUtils::is_integer(*t)) { - result = ASR::down_cast(arg)->m_n; - } 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); - } else if (ASRUtils::is_logical(*t)) { - result = ASR::down_cast(arg)->m_value; - } else if (ASRUtils::is_character(*t)) { - char* c = ASR::down_cast(ASRUtils::expr_value(arg))->m_s; - result = strlen(s2c(al, std::string(c))); - } else { - throw SemanticError("bool() must have one real, integer, character," - " complex, or logical argument, not '" + ASRUtils::type_to_str_python(t) + "'", loc); - } - return ASR::down_cast(make_LogicalConstant_t(al, loc, result, type)); - } - static ASR::expr_t *eval_chr(Allocator &al, const Location &loc, Vec &args) { LFORTRAN_ASSERT(ASRUtils::all_args_evaluated(args)); ASR::expr_t* arg = args[0]; @@ -248,53 +210,6 @@ struct PythonIntrinsicProcedures { } } - #define BITWISE(X) \ - static ASR::expr_t *X(Allocator &al, const Location &loc, Vec &args) { \ - return eval_bitwise(al, loc, args, &X); \ - } - - BITWISE(eval__bitwise_or) - BITWISE(eval__bitwise_and) - BITWISE(eval__bitwise_xor) - BITWISE(eval__bitwise_lshift) - BITWISE(eval__bitwise_rshift) - - static ASR::expr_t *eval_bitwise(Allocator &al, const Location &loc, - Vec &args, const comptime_eval_callback X) { - if (args.size() != 2) { - throw SemanticError("Bitwise Operation must have two integer arguments.", loc); - } - ASR::expr_t* arg1 = ASRUtils::expr_value(args[0]), *arg2 = ASRUtils::expr_value(args[1]); - LFORTRAN_ASSERT(ASRUtils::check_equal_type(ASRUtils::expr_type(arg1), - ASRUtils::expr_type(arg2))); - ASR::ttype_t* type = ASRUtils::expr_type(arg1); - if (ASRUtils::is_integer(*type)) { - int64_t a = ASR::down_cast(arg1)->m_n; - int64_t b = ASR::down_cast(arg2)->m_n; - int64_t result = 0; - if (X == eval__bitwise_or) { - result = a | b; - } else if (X == eval__bitwise_and) { - result = a & b; - } else if (X == eval__bitwise_xor) { - result = a ^ b; - } else if (X == eval__bitwise_lshift) { - if (b < 0) { - throw SemanticError("Negative shift count not allowed.", loc); - } - result = a << b; - } else if (X == eval__bitwise_rshift) { - if (b < 0) { - throw SemanticError("Negative shift count not allowed.", loc); - } - result = a >> b; - } - return ASR::down_cast(ASR::make_IntegerConstant_t(al, loc, result, type)); - } else { - throw SemanticError("Bitwise Operation must have both integer arguments.", loc); - } - } - static ASR::expr_t *eval_ord(Allocator &al, const Location &loc, Vec &args) { LFORTRAN_ASSERT(ASRUtils::all_args_evaluated(args)); ASR::expr_t* char_expr = args[0]; diff --git a/src/runtime/impure/lfortran_intrinsics.c b/src/runtime/impure/lfortran_intrinsics.c index ef03ef6596..54e7c5ff27 100644 --- a/src/runtime/impure/lfortran_intrinsics.c +++ b/src/runtime/impure/lfortran_intrinsics.c @@ -614,6 +614,53 @@ LFORTRAN_API void _lfortran_strcat(char** s1, char** s2, char** dest) *dest = &(dest_char[0]); } +#define MIN(x, y) ((x < y) ? x : y) + +int str_compare(char **s1, char **s2) +{ + int s1_len = strlen(*s1); + int s2_len = strlen(*s2); + int lim = MIN(s1_len, s2_len); + int res = 0; + int i ; + for (i = 0; i < lim; i++) { + if ((*s1)[i] != (*s2)[i]) { + res = (*s1)[i] - (*s2)[i]; + break; + } + } + res = (i == lim)? s1_len - s2_len : res; + return res; +} +LFORTRAN_API bool _lpython_str_compare_eq(char **s1, char **s2) +{ + return str_compare(s1, s2) == 0; +} + +LFORTRAN_API bool _lpython_str_compare_noteq(char **s1, char **s2) +{ + return str_compare(s1, s2) != 0; +} + +LFORTRAN_API bool _lpython_str_compare_gt(char **s1, char **s2) +{ + return str_compare(s1, s2) > 0; +} + +LFORTRAN_API bool _lpython_str_compare_lte(char **s1, char **s2) +{ + return str_compare(s1, s2) <= 0; +} + +LFORTRAN_API bool _lpython_str_compare_lt(char **s1, char **s2) +{ + return str_compare(s1, s2) < 0; +} + +LFORTRAN_API bool _lpython_str_compare_gte(char **s1, char **s2) +{ + return str_compare(s1, s2) >= 0; +} //repeat str for n time LFORTRAN_API void _lfortran_strrepeat(char** s, int32_t n, char** dest) { @@ -637,7 +684,12 @@ LFORTRAN_API void _lfortran_strrepeat(char** s, int32_t n, char** dest) // idx1 and idx2 both start from 1 LFORTRAN_API char* _lfortran_str_copy(char* s, int32_t idx1, int32_t idx2) { + int s_len = strlen(s); + if(idx1 > s_len || idx1 <= (-1*s_len)){ + printf("String index out of Bounds\n"); + exit(1); + } if(idx1 <= 0) { idx1 = s_len + idx1; } diff --git a/src/runtime/impure/lfortran_intrinsics.h b/src/runtime/impure/lfortran_intrinsics.h index 617ec824b8..4e8573cc74 100644 --- a/src/runtime/impure/lfortran_intrinsics.h +++ b/src/runtime/impure/lfortran_intrinsics.h @@ -4,6 +4,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -136,6 +137,12 @@ LFORTRAN_API float _lfortran_satanh(float x); LFORTRAN_API double _lfortran_datanh(double x); LFORTRAN_API float_complex_t _lfortran_catanh(float_complex_t x); LFORTRAN_API double_complex_t _lfortran_zatanh(double_complex_t x); +LFORTRAN_API bool _lpython_str_compare_eq(char** s1, char** s2); +LFORTRAN_API bool _lpython_str_compare_noteq(char** s1, char** s2); +LFORTRAN_API bool _lpython_str_compare_gt(char** s1, char** s2); +LFORTRAN_API bool _lpython_str_compare_lte(char** s1, char** s2); +LFORTRAN_API bool _lpython_str_compare_lt(char** s1, char** s2); +LFORTRAN_API bool _lpython_str_compare_gte(char** s1, char** s2); LFORTRAN_API void _lfortran_strrepeat(char** s, int32_t n, char** dest); LFORTRAN_API void _lfortran_strcat(char** s1, char** s2, char** dest); LFORTRAN_API int _lfortran_str_len(char** s); diff --git a/src/runtime/lpython_builtin.py b/src/runtime/lpython_builtin.py index 3acba42c00..a727741284 100644 --- a/src/runtime/lpython_builtin.py +++ b/src/runtime/lpython_builtin.py @@ -35,10 +35,12 @@ def abs(x: f64) -> f64: """ Return the absolute value of `x`. """ + result: f64 if x >= 0.0: - return x + result = x else: - return -x + result = -x + return result @overload def abs(x: f32) -> f32: @@ -86,19 +88,37 @@ def abs(b: bool) -> i32: def abs(c: c32) -> f32: a: f32 b: f32 + result: f32 a = c.real b = _lfortran_caimag(c) - return (a**2 + b**2)**(1/2) + result = (a**2 + b**2)**(1/2) + return result @overload def abs(c: c64) -> f64: a: f64 b: f64 + result: f64 a = c.real b = _lfortran_zaimag(c) - return (a**2 + b**2)**(1/2) + result = (a**2 + b**2)**(1/2) + return result +@overload +def str() -> str: + return '' + +@overload +def str(x: str) -> str: + return x + +@overload +def str(x: bool) -> str: + if x: + return "True" + return "False" +@overload def str(x: i32) -> str: """ Return the string representation of an integer `x`. @@ -114,69 +134,15 @@ def str(x: i32) -> str: rev_result = '' rev_result_len: i32 rev_result_len = 0 - pos_to_str: list[str] - pos_to_str = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] while x > 0: - rev_result += pos_to_str[x - _lpython_floordiv(x, 10)*10] + rev_result += chr(48 + (x - _lpython_floordiv(x, 10)*10)) rev_result_len += 1 x = _lpython_floordiv(x, 10) pos: i32 - for pos in range(rev_result_len - 1, -1, -1): + for pos in range(rev_result_len - 1, 1, -1): result += rev_result[pos] return result -#: bool() as a generic procedure. -#: supported types for argument: -#: i8, i16, i32, i64, f32, f64, bool -@overload -def bool(x: i32) -> bool: - """ - Return False when the argument `x` is 0, True otherwise. - """ - return x != 0 - -@overload -def bool(x: i64) -> bool: - return x != 0 - -@overload -def bool(x: i8) -> bool: - return x != 0 - -@overload -def bool(x: i16) -> bool: - return x != 0 - -@overload -def bool(f: f32) -> bool: - return f != 0.0 - -@overload -def bool(f: f64) -> bool: - """ - Return False when the argument `x` is 0.0, True otherwise. - """ - return f != 0.0 - -@overload -def bool(s: str) -> bool: - """ - Return False when the argument `s` is an empty string, True otherwise. - """ - return len(s) > 0 - -@overload -def bool(b: bool) -> bool: - return b - -@overload -def bool(c: c32) -> bool: - return c.real != 0.0 or _lfortran_caimag(c) != 0.0 - -@overload -def bool(c: c64) -> bool: - return c.real != 0.0 or _lfortran_zaimag(c) != 0.0 - @interface def len(s: str) -> i32: """ @@ -386,12 +352,16 @@ def complex(x: f64) -> c64: @interface @overload def complex(x: i32) -> c32: - return x + 0*1j + result: c32 + result = x + 0*1j + return result @interface @overload def complex(x: f32) -> c32: - return x + 0*1j + result: c32 + result = x + 0*1j + return result @interface @overload @@ -409,7 +379,9 @@ def complex(x: f64, y: f64) -> c64: @interface @overload def complex(x: f32, y: f32) -> c32: - return x + y*1j + result: c32 + result = x + y*1j + return result @interface @overload @@ -499,10 +471,13 @@ def _lpython_floordiv(a: f32, b: f32) -> f32: r: f32 r = a/b result: i32 + resultf32: f32 result = int(r) if r >= 0.0 or result == r: - return float(result) - return float(result-1) + resultf32 = 1.0 * result + else: + resultf32 = 1.0 * result-1 + return resultf32 @overload def _lpython_floordiv(a: i32, b: i32) -> i32: @@ -605,55 +580,3 @@ def min(a: f64, b: f64) -> f64: return a else: return b - -@overload -def _bitwise_or(a: i32, b: i32) -> i32: - pass - -@overload -def _bitwise_or(a: i64, b: i64) -> i64: - pass - -@overload -def _bitwise_and(a: i32, b: i32) -> i32: - pass - -@overload -def _bitwise_and(a: i64, b: i64) -> i64: - pass - -@overload -def _bitwise_xor(a: i32, b: i32) -> i32: - pass - -@overload -def _bitwise_xor(a: i64, b: i64) -> i64: - pass - -@overload -def _bitwise_lshift(a: i32, b: i32) -> i32: - if b < 0: - raise ValueError("Negative shift count not allowed.") - return a*2**b - -@overload -def _bitwise_lshift(a: i64, b: i64) -> i64: - if b < 0: - raise ValueError("Negative shift count not allowed.") - return a*2**b - -@overload -def _bitwise_rshift(a: i32, b: i32) -> i32: - if b < 0: - raise ValueError("Negative shift count not allowed.") - i: i32 - i = 2 - return _lpython_floordiv(a, i**b) - -@overload -def _bitwise_rshift(a: i64, b: i64) -> i64: - if b < 0: - raise ValueError("Negative shift count not allowed.") - i: i64 - i = 2 - return _lpython_floordiv(a, i**b) diff --git a/src/runtime/lpython_parser.py b/src/runtime/lpython_parser.py index 2ad5ad90a3..b49e5898a2 100644 --- a/src/runtime/lpython_parser.py +++ b/src/runtime/lpython_parser.py @@ -3,8 +3,7 @@ import ast filename = sys.argv[1] -#filename = "doconcurrentloop_01.py" -#filename = "expr2.py" +filename_out = sys.argv[2] input = open(filename).read() a = ast.parse(input, type_comments=True) @@ -50,6 +49,12 @@ def visit_Constant(self, node): elif isinstance(node.value, complex): new_node = python_ast.ConstantComplex(node.value.real, node.value.imag, node.kind) + elif isinstance(node.value, Ellipsis.__class__): + new_node = python_ast.ConstantEllipsis(node.kind) + elif isinstance(node.value, None.__class__): + new_node = python_ast.ConstantNone(node.kind) + elif isinstance(node.value, bytes): + new_node = python_ast.ConstantBytes(str(node.value), node.kind) else: print(type(node.value)) raise Exception("Unsupported Constant type") @@ -70,6 +75,9 @@ def generic_visit(self, node): for item in value: if isinstance(item, ast.AST): new_list.append(self.visit(item)) + else: + if type(item) == str: + new_list.append(item) d[field] = new_list elif field in ["vararg", "kwarg"]: if value is None: @@ -116,9 +124,13 @@ def __init__(self): self.s = "0 " def write_int8(self, i): + assert i >= 0 self.s += str(i) + " " def write_int64(self, i): + if i < 0: + i += 2**64 + assert i >= 0 self.s += str(i) + " " def write_float64(self, f): @@ -139,4 +151,4 @@ def write_bool(self, b): #print() #print(v.s) -open("ser.txt", "w").write(v.s) +open(filename_out, "w").write(v.s) diff --git a/src/runtime/ltypes/ltypes.py b/src/runtime/ltypes/ltypes.py index 7b8d166bde..fcf39455e5 100644 --- a/src/runtime/ltypes/ltypes.py +++ b/src/runtime/ltypes/ltypes.py @@ -3,9 +3,12 @@ import ctypes import platform from typing import TypeVar +from dataclasses import dataclass -__slots__ = ["i8", "i16", "i32", "i64", "f32", "f64", "c32", "c64", - "overload", "ccall", "TypeVar"] +# TODO: this does not seem to restrict other imports +__slots__ = ["i8", "i16", "i32", "i64", "f32", "f64", "c32", "c64", "CPtr", + "overload", "ccall", "TypeVar", "pointer", "c_p_pointer", "Pointer", + "p_c_pointer"] # data-types @@ -16,6 +19,10 @@ def __init__(self, name): def __getitem__(self, params): return Array(self, params) +class Pointer: + def __getitem__(self, type): + return type + class Array: def __init__(self, type, dims): self._type = type @@ -29,6 +36,7 @@ def __init__(self, type, dims): f64 = Type("f64") c32 = Type("c32") c64 = Type("c64") +CPtr = Type("c_ptr") # Overloading support @@ -115,27 +123,41 @@ def convert_type_to_ctype(arg): return ctypes.c_int64 elif arg == i32: return ctypes.c_int32 + elif arg == i16: + return ctypes.c_int16 + elif arg == i8: + return ctypes.c_int8 + elif arg == CPtr: + return ctypes.c_void_p + elif arg == str: + return ctypes.c_char_p elif arg is None: raise NotImplementedError("Type cannot be None") elif isinstance(arg, Array): type = convert_type_to_ctype(arg._type) return ctypes.POINTER(type) else: - raise NotImplementedError("Type not implemented") + raise NotImplementedError("Type %r not implemented" % arg) def get_rtlib_dir(): current_dir = os.path.dirname(os.path.abspath(__file__)) return os.path.join(current_dir, "..") - def get_crtlib_name(): + def get_lib_name(name): if platform.system() == "Linux": - return "liblpython_runtime.so" + return "lib" + name + ".so" elif platform.system() == "Darwin": - return "liblpython_runtime.dylib" + return "lib" + name + ".dylib" elif platform.system() == "Windows": - return "lpython_runtime.dll" + return name + ".dll" else: raise NotImplementedError("Platform not implemented") def get_crtlib_path(): - return os.path.join(get_rtlib_dir(), get_crtlib_name()) + py_mod = os.environ["LPYTHON_PY_MOD_NAME"] + if py_mod == "": + return os.path.join(get_rtlib_dir(), + get_lib_name("lpython_runtime")) + else: + py_mod_path = os.environ["LPYTHON_PY_MOD_PATH"] + return os.path.join(py_mod_path, get_lib_name(py_mod)) self.name = f.__name__ self.args = f.__code__.co_varnames self.annotations = f.__annotations__ @@ -156,9 +178,47 @@ def get_crtlib_path(): def __call__(self, *args, **kwargs): if len(kwargs) > 0: raise Exception("kwargs are not supported") - return self.cf(*args) + new_args = [] + for arg in args: + if isinstance(arg, str): + new_args.append(arg.encode("utf-8")) + else: + new_args.append(arg) + return self.cf(*new_args) def ccall(f): wrapped_f = CTypes(f) return wrapped_f + +def pointer(x, type=None): + from numpy import ndarray + if isinstance(x, ndarray): + return ctypes.c_void_p(x.ctypes.data) + #return x.ctypes.data_as(ctypes.POINTER(ctypes.c_int32)) + else: + if type == i32: + #return ctypes.c_void_p(ctypes.pointer(ctypes.c_int32(x))) + #return ctypes.pointer(ctypes.c_int32(x)) + return ctypes.cast(ctypes.pointer(ctypes.c_int32(x)), + ctypes.c_void_p) + elif type == i64: + return ctypes.cast(ctypes.pointer(ctypes.c_int64(x)), + ctypes.c_void_p) + elif type == f32: + return ctypes.cast(ctypes.pointer(ctypes.c_float(x)), + ctypes.c_void_p) + elif type == f64: + return ctypes.cast(ctypes.pointer(ctypes.c_double(x)), + ctypes.c_void_p) + else: + raise Exception("Type not supported in pointer()") + +def c_p_pointer(cptr, targettype): + return pointer(targettype) + +def p_c_pointer(ptr, cptr): + cptr.value = ptr.value + +def empty_c_void_p(): + return ctypes.c_void_p() diff --git a/src/runtime/math.py b/src/runtime/math.py index d01edb4fe5..d6ef7bbd57 100644 --- a/src/runtime/math.py +++ b/src/runtime/math.py @@ -1,4 +1,4 @@ -from ltypes import i8, i16, i32, f32, f64, ccall +from ltypes import i8, i16, i32, f32, i64, f64, ccall pi: f64 = 3.141592653589793238462643383279502884197 @@ -7,21 +7,37 @@ # TODO: Change floor used inside functions implemented here to # floordiv operator (//) once the multiple import issue is fixed - +@overload def factorial(x: i32) -> i32: """ Computes the factorial of `x`. """ - if x < 0: - return 0 result: i32 + result = 0 + if x < 0: + return result result = 1 i: i32 for i in range(1, x+1): result *= i return result +@overload +def factorial(x: i64) -> i64: + """ + Computes the factorial of `x`. + """ + result: i64 + result = 0 + if x < 0: + return result + result = 1 + i: i64 + for i in range(1, x+1): + result *= i + return result + @overload def floor(x: i32) -> i32: return x @@ -207,7 +223,10 @@ def radians(x: f64) -> f64: """ return x * pi / 180.0 -def fabs(x: f64) -> f64: +# fabs +# supported data types: i32, i64, f32, f64 +@overload +def fabs(x: f32) -> f32: """ Return the absolute value of `x`. """ @@ -215,23 +234,110 @@ def fabs(x: f64) -> f64: return -x return x +@overload +def fabs(x: f64) -> f64: + """ + Return the absolute value of `x`. + """ + if x < 0.0: + return -x + return x -def ldexp(x: f64, i: i32) -> f64: - return x * (2**i) +@overload +def fabs(x: i64) -> f64: + """ + Return the absolute value of `x`. + """ + if x < 0.0: + return -float(x) + return float(x) +@overload +def fabs(x: i32) -> f64: + """ + Return the absolute value of `x`. + """ + if x < 0.0: + return -float(x) + return float(x) -def exp(x: f64) -> f64: +@overload +def fabs(x: i16) -> f64: """ - Return `e` raised to the power `x`. + Return the absolute value of `x`. """ - return e**x + if x < 0.0: + return -float(x) + return float(x) +@overload +def fabs(x: i8) -> f64: + """ + Return the absolute value of `x`. + """ + if x < 0.0: + return -float(x) + return float(x) +# pow +# supported data types: i32, i64, f32, f64 +@overload def pow(x: f64, y: f64) -> f64: + """ + Return `x` raised to the power `y`. + """ + if y < 0: + raise ValueError('y should be nonnegative') + result: f64 + result = x**y + return result + + +@overload +def pow(x: i64, y: i64) -> i64: + """ + Return `x` raised to the power `y`. + """ + if y < 0: + raise ValueError('y should be nonnegative') + result: i64 + result = x**y + return result + +@overload +def pow(x: f32, y: f32) -> f64: """ Return `x` raised to the power `y`. """ - return x**y + if y < 0: + raise ValueError('y should be nonnegative') + result: f64 + result = x**y + return result + +@overload +def pow(x: i32, y: i32) -> i32: + """ + Return `x` raised to the power `y`. + """ + if y < 0: + raise ValueError('y should be nonnegative') + result: i32 + result = x**y + return result + +@overload +def ldexp(x: f64, i: i32) -> f64: + result: f64 + result = x * (2**i) + return result + + +def exp(x: f64) -> f64: + """ + Return `e` raised to the power `x`. + """ + return e**x def mod(a: i32, b: i32) -> i32: diff --git a/src/runtime/platform.py b/src/runtime/platform.py new file mode 100644 index 0000000000..4c11b4977a --- /dev/null +++ b/src/runtime/platform.py @@ -0,0 +1,5 @@ +def python_implementation() -> str: + return "LPython" + +def python_version() -> str: + return __LPYTHON_VERSION__ \ No newline at end of file diff --git a/test_lfortran_cmdline b/test_lfortran_cmdline deleted file mode 100755 index 8e18975f8b..0000000000 --- a/test_lfortran_cmdline +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -x - -if [[ $1 == "" ]]; then - echo "Test local lfortran" - PATH="$(pwd):$PATH" - FC=lfortran -elif [[ $1 == "gfortran" ]]; then - echo "Test installed gfortran" - FC=gfortran -elif [[ $1 == "lfortran" ]]; then - echo "Test installed lfortran" - FC=lfortran -else - echo "Invalid option" - exit 1 -fi - -f=`pwd`/examples/expr2.f90 -ASM_PATTERN="movq\|movl\|retq" - -cd $(mktemp -d) -$FC $f -o a.out -[ -f "a.out" ] -[ -x "a.out" ] -./a.out - -cd $(mktemp -d) -$FC -c $f -[ -f "expr2.o" ] -[ ! -x "expr2.o" ] -$FC -o expr2 expr2.o -[ -f "expr2" ] -[ -x "expr2" ] -./expr2 - -cd $(mktemp -d) -$FC -o xx1 -c $f -[ -f "xx1" ] -[ ! -x "xx1" ] -$FC -o expr2 xx1 -[ -f "expr2" ] -[ -x "expr2" ] -./expr2 - -cd $(mktemp -d) -$FC -o xx1 $f -[ -f "xx1" ] -[ -x "xx1" ] -./xx1 - -cd $(mktemp -d) -$FC -S $f -[ -f "expr2.s" ] -grep $ASM_PATTERN expr2.s - -cd $(mktemp -d) -$FC -S -c $f -[ -f "expr2.s" ] -grep $ASM_PATTERN expr2.s - -cd $(mktemp -d) -$FC -S -o xx1 $f -[ -f "xx1" ] -grep $ASM_PATTERN xx1 - -cd $(mktemp -d) -$FC -S -o xx1 -c $f -[ -f "xx1" ] -grep $ASM_PATTERN xx1 - -echo "All tests succeeded" diff --git a/tests/bool1.py b/tests/bool1.py new file mode 100644 index 0000000000..d7b06a4568 --- /dev/null +++ b/tests/bool1.py @@ -0,0 +1,10 @@ +def test_bool(): + print(True) + print(False) + b: bool + b = True + print(b) + b = False + print(b) + +test_bool() diff --git a/tests/c_interop1.py b/tests/c_interop1.py new file mode 100644 index 0000000000..83aaca8ada --- /dev/null +++ b/tests/c_interop1.py @@ -0,0 +1,32 @@ +from ltypes import ccall, f32, f64, i32, i64 + +@ccall +def f(x: f64) -> f64: + pass + +@ccall +def g(a: f64, b: f32, c: i64, d: i32) -> None: + pass + +@ccallback +def h(x: f64) -> f64: + return x + 1.0 + +@ccallback +def l(a: f64, b: f32, c: i64, d: i32) -> None: + print("OK") + +def main0(): + i: f64 + x: f64 + x = 5.0 + i = f(x) + y: f32 + y = 5.4 + z: i64 + z = 3 + zz: i32 + zz = 2 + g(x, y, z, zz) + i = h(x) + l(x, y, z, zz) diff --git a/tests/constants1.py b/tests/constants1.py index 9e63160838..0759ea986a 100644 --- a/tests/constants1.py +++ b/tests/constants1.py @@ -65,7 +65,9 @@ def test_str(): s = str() s = str(5) s = str(-4) - s = str(5.6) + # TODO: This test had hidden failure and was noticed during type + # checking. + # s = str(5.6) s = str(True) s = str(False) s = str("5346") @@ -91,8 +93,7 @@ def test_int(): a = int(-5.00001) a = int(True) a = int(False) - # commented tests should work - # a = int("5346") + a = int("5346") def test_float(): diff --git a/tests/errors/test_annassign_type_mismatch2.py b/tests/errors/test_annassign_type_mismatch2.py new file mode 100644 index 0000000000..004804626f --- /dev/null +++ b/tests/errors/test_annassign_type_mismatch2.py @@ -0,0 +1,7 @@ +from ltypes import f64 + +def f(): + x: f64[5] = [1.0, 2.0, 3.0, 4.0, 5.0] + print(a) + +f() diff --git a/tests/errors/test_bitwise_on_complex.py b/tests/errors/test_bitwise_on_complex.py new file mode 100644 index 0000000000..66c48bb0d2 --- /dev/null +++ b/tests/errors/test_bitwise_on_complex.py @@ -0,0 +1,11 @@ +from ltypes import c32 + +def f(): + c1: c32 + c1 = 4+5j + c2: c32 + c2 = -5.6-3j + print(c1 | c2) + + +f() diff --git a/tests/errors/test_bitwise_on_float.py b/tests/errors/test_bitwise_on_float.py new file mode 100644 index 0000000000..1abc611f31 --- /dev/null +++ b/tests/errors/test_bitwise_on_float.py @@ -0,0 +1,11 @@ +from ltypes import f32 + +def f(): + f1: f32 + f1 = 4.5 + f2: f32 + f2 = 6.7 + print(f1 << f2) + + +f() diff --git a/tests/errors/test_dict7.py b/tests/errors/test_dict7.py new file mode 100644 index 0000000000..bb225ddab0 --- /dev/null +++ b/tests/errors/test_dict7.py @@ -0,0 +1,6 @@ +def f(): + d: dict[i32, i32] + d = {1: 2, 3: 4, 5: 6} + print(d[1:2]) + +f() diff --git a/tests/errors/test_func_args.py b/tests/errors/test_func_args.py new file mode 100644 index 0000000000..e47829c396 --- /dev/null +++ b/tests/errors/test_func_args.py @@ -0,0 +1,14 @@ +from ltypes import i64 + +def fib(n: i64) -> i64: + if n < 2: + return n + else: + return fib(n - 1) + fib(n - 2) + +def main(): + ans: i64 + ans = fib(35, 10) + print(ans) + +main() diff --git a/tests/errors/test_list_concat.py b/tests/errors/test_list_concat.py index 482e041e0b..cee7353fde 100644 --- a/tests/errors/test_list_concat.py +++ b/tests/errors/test_list_concat.py @@ -1,8 +1,8 @@ -from ltypes import i32, f32 +from ltypes import i32, f64 def main(): a: list[i32] a = [1, 2] - b: list[f32] + b: list[f64] b = [1.2, 3.4] a += b diff --git a/tests/errors/test_pointer_types.py b/tests/errors/test_pointer_types.py new file mode 100644 index 0000000000..bfd2a36d97 --- /dev/null +++ b/tests/errors/test_pointer_types.py @@ -0,0 +1,10 @@ +from ltypes import pointer, i16, Pointer, i32 + +def f(): + yptr1: Pointer[i16[:]] + y: i32[2] + y[0] = 1 + y[1] = 2 + yptr1 = pointer(y) + +f() diff --git a/tests/errors/test_print1.py b/tests/errors/test_print1.py new file mode 100644 index 0000000000..e3b74aea41 --- /dev/null +++ b/tests/errors/test_print1.py @@ -0,0 +1,3 @@ +def f(): + print("a", "b", sep=2) +f() diff --git a/tests/errors/test_print2.py b/tests/errors/test_print2.py new file mode 100644 index 0000000000..911b59ec62 --- /dev/null +++ b/tests/errors/test_print2.py @@ -0,0 +1,3 @@ +def f(): + print("a", "b", end=1) +f() \ No newline at end of file diff --git a/tests/errors/test_str_slicing2.py b/tests/errors/test_str_slicing2.py new file mode 100644 index 0000000000..78ceccdedb --- /dev/null +++ b/tests/errors/test_str_slicing2.py @@ -0,0 +1,6 @@ +def f(): + s: str + s = "abcd" + print(s[1.5:3]) + +f() \ No newline at end of file diff --git a/tests/errors/test_str_slicing3.py b/tests/errors/test_str_slicing3.py new file mode 100644 index 0000000000..070225f930 --- /dev/null +++ b/tests/errors/test_str_slicing3.py @@ -0,0 +1,6 @@ +def f(): + s: str + s = "abcd" + print(s[1:3:0.5]) + +f() \ No newline at end of file diff --git a/tests/errors/test_str_to_int.py b/tests/errors/test_str_to_int.py new file mode 100644 index 0000000000..f6f847df22 --- /dev/null +++ b/tests/errors/test_str_to_int.py @@ -0,0 +1,4 @@ +def test_e1(): + print(int('3abc')) + +test_e1() diff --git a/tests/errors/test_unsupported_type.py b/tests/errors/test_unsupported_type.py new file mode 100644 index 0000000000..5fb555cde6 --- /dev/null +++ b/tests/errors/test_unsupported_type.py @@ -0,0 +1,6 @@ +def f(): + i: i128 + i = 4 + print(i) + +f() \ No newline at end of file diff --git a/tests/loop1.py b/tests/loop1.py index 976639d586..26828047c0 100644 --- a/tests/loop1.py +++ b/tests/loop1.py @@ -19,9 +19,10 @@ def test_factorial_2(x: i32) -> i32: def test_factorial_3(x: i32) -> i64: - if x < 0: - return 0 result: i64 + result = 0 + if x < 0: + return result result = 1 while x > 0: result = result * x @@ -35,5 +36,6 @@ def main0(): i = test_factorial_2(4) j: i64 j = test_factorial_3(5) + #print(i, j) main0() diff --git a/tests/loop2.py b/tests/loop2.py index 16ab7f23a5..8c7ffbc465 100644 --- a/tests/loop2.py +++ b/tests/loop2.py @@ -9,4 +9,6 @@ def test_for(): break if i == 3: quit() - exit(0) + exit(2) + +test_for() diff --git a/tests/ltypes.py b/tests/ltypes1.py similarity index 100% rename from tests/ltypes.py rename to tests/ltypes1.py diff --git a/tests/parser/comprehension1.py b/tests/parser/comprehension1.py new file mode 100644 index 0000000000..391f54d814 --- /dev/null +++ b/tests/parser/comprehension1.py @@ -0,0 +1,17 @@ +# List Comprehension + +fruits = [f for f in fruit_list if f.startswith("a")] + +fruit_list = [fruit for fruit in fruits] + +sum_cord = [x + y for (x, y) in points if x > 0 and y > 0] + +transform_1 = [2*x + 6 for x in range(10)] + +distance_orig = [x**2 + y**2 + z**2 for x, y, z in points] + +odd_elements = [i for i in main_list if i & 1] + +first_ten_elements = [i for (i) in range(10)] + +another_ten_elements = [(i) for (i) in range(10)] diff --git a/tests/parser/ellipsis1.py b/tests/parser/ellipsis1.py new file mode 100644 index 0000000000..23f4436da8 --- /dev/null +++ b/tests/parser/ellipsis1.py @@ -0,0 +1,37 @@ +import numpy as np +from typing import Callable + +array = np.random.rand(2, 2, 2, 2) +print(array[..., 0]) +print(array[Ellipsis, 0]) + +def inject(get_next_item: Callable[..., str]) -> None: + ... + +def foo(x: ...) -> None: + ... + +class flow: + def __understand__(self, name: str, value: ...) -> None: ... + +def foo(x = ...): + return x + +def test(): + ... + +class Todo: + ... + +x = [1, [2, [...], 3]] +l = [..., 1, 2, 3] + +if x is ...: + pass + +def partial(func: Callable[..., str], *args) -> Callable[..., str]: + pass + +class xyz: + abc: str = ... + def __init__(self, name: str=...) -> None: ... diff --git a/tests/parser/ellipsis2.py b/tests/parser/ellipsis2.py new file mode 100644 index 0000000000..489d16fcd4 --- /dev/null +++ b/tests/parser/ellipsis2.py @@ -0,0 +1,35 @@ +import numpy as np +from typing import Callable + + +print(...) + +# TODO: Make this work +# def bar(x = ...): +# return x + +array = np.random.rand(2, 2, 2, 2) +print(array[..., 0]) +print(array[Ellipsis, 0]) + + +def test1(): + ... + + +def test2() -> None: + x = [1, [2, [...], 3]] + l = [..., 1, 2, 3] + ... + + +array = np.random.rand(2, 2, 2, 2) +print(array[..., 0]) + + +def foo(x: ...) -> None: + ... + + +def inject(get_next_item: Callable[..., str]) -> None: + ... diff --git a/tests/parser/for1.py b/tests/parser/for1.py index 3a5b12d165..29e217da34 100644 --- a/tests/parser/for1.py +++ b/tests/parser/for1.py @@ -31,3 +31,25 @@ sum: i32 = 0 for j in range(5): sum += j + +for _, x in y: + pass + +for (x, y) in z: + pass + +for i, a in enumerate([4, 5, 6, 7]): + print(i, ": ", a) + +# For-loops with type-comment + +for i in range(5): # type: int + pass + +for j in k: # type: List[str] + pass + +for i in range(5): # type:int + pass +else: + pass diff --git a/tests/parser/function_def1.py b/tests/parser/function_def1.py index 063ef83683..6b5cb4ab15 100644 --- a/tests/parser/function_def1.py +++ b/tests/parser/function_def1.py @@ -33,6 +33,11 @@ def tri_recursion(k): def test(a: i32) -> i32: return a + 10 +@overload +# Comment +def test(a: i64) -> i64: + return a + 10 + @overload def test(a: bool) -> i32: if a: @@ -50,9 +55,8 @@ def check(): check() -# TODO: -# def print_args(*args): -# print(args) +def print_args(*args): + print(args) -# def print_kwargs(**kwargs): -# print(kwargs) +def print_kwargs(**kwargs): + print(kwargs) diff --git a/tests/parser/function_def2.py b/tests/parser/function_def2.py index fe8f428990..48adb7c59c 100644 --- a/tests/parser/function_def2.py +++ b/tests/parser/function_def2.py @@ -43,6 +43,39 @@ def test_12(x, **args): def test_14(x, *y, z, **args: i32) -> i32: pass +def test_15(a, /): + pass + +def test_16(a, /, b, c): + pass + +def test_17(a, /, *b): + pass + +def test_18(a:i32, /, *b: i64, c: i32, d: i32): + pass + +def test_19(a, /, *b, c, **d): + pass + +def test_20(a, /, **b): + pass + +def test_21(a, /, *b, **c): + pass + +def test_22(a, /, b, c, *d): + pass + +def test_23(a, /, b, c, **d): + pass + +def test_24(a, /, b, c, *d, **e): + pass + +def test_25(a, /, b, c, *d, e, **f): + pass + test() test(x, y) test(x, y = 1, z = '123') diff --git a/tests/parser/global1.py b/tests/parser/global1.py new file mode 100644 index 0000000000..12acdba6ab --- /dev/null +++ b/tests/parser/global1.py @@ -0,0 +1,26 @@ +x = "global " + +def outer(): + x = "local" + + def inner(): + nonlocal x + x = "nonlocal" + assert x == "nonlocal" + inner() + + assert x == "nonlocal" + +def test_1(): + global x + y = "local" + x = x * 2 + assert x == "global global " + assert y == "local" + + +def check(): + test_1() + outer() + +check() diff --git a/tests/parser/statements1.py b/tests/parser/statements1.py index 6e07eb39e6..bad2ba187c 100644 --- a/tests/parser/statements1.py +++ b/tests/parser/statements1.py @@ -16,6 +16,10 @@ x = y = 1 x, y = 1, 2 x[i] = (1, 2) +x, y, z = t +(x, y, z) = t +x, = t +(x,) = t x += 1 @@ -23,11 +27,19 @@ y: i32 = 1 del x +del () +del (x, y) +del (x, y,) +del x, y, del x, y return return a + b return x(a) +return () +return (x, y) +return (x, y, ) +return x, y, return x, y global a @@ -45,12 +57,29 @@ 0O0127 -0b1101 0B1101 +32_768 +1_2 +234403_34_32_233_3 123. 123.45 12.34e+10 12+3j .12+.001j "String" +"String " "String" +'String ' 'String' +'String ' "String" +"String " "String"[1:] +x = ("String " +"String") +x = ("String " + +"String") +x = ("String " \ +"String") +x = "String " \ +"String" +x = "String " +"String" True False @@ -79,6 +108,62 @@ x > y x >= y +if type(x) is int: + pass + +if ((2 + 3)/2 - 1 is 5) is True: + pass + +if x is not type(float): + pass + +if x is \ + not type(int): + pass + +a = [1, 2, 3] + +if a not in [1, 2]: + pass + +if (a not in [1, 2]) not \ + in [True, False]: + pass + +if field in ["vararg", "kwarg"]: + if value is None: + pass + +if (a in list1): + pass + +"hello" in x +'a' in a.func() +'lo' in 'hello' + +for item in list1: + if item in list2: + pass + +if a in list1 and b not in list2 or c in list3: + pass + +comp = [i**2 for i in range(10) if i not in [3, 5, 7] and i in list3] + +# Fow showing the parsing order of 'in' in for-loop and 'in' in expr is correct +# and there is no conflict. Otherwise, the code below is gibberish. +for i in a in list1: + pass + +a.b[1] +a.b[1:] +a.b[:-1] +a.b[1:2] +a.b[:] +y.z[1:2:3] +y.z[1::3] +y.z[1::] + i: i32 = 4 if 2 > i : pass if i > 5 : break @@ -92,3 +177,13 @@ x = 1 a = {1, 2, 3} + +# Ternary operator (Conditional expressions) + +b = 6 if a == 2 else 8 + +'true' if True else 'false' + +result = x if not (a > b) else y + +print(a,"is greater") if (a > b) else print(b,"is Greater") diff --git a/tests/parser/statements2.py b/tests/parser/statements2.py new file mode 100644 index 0000000000..80c777fb65 --- /dev/null +++ b/tests/parser/statements2.py @@ -0,0 +1,10 @@ +a and b +a and b or c +a or b +a or b and c + +(a and b and c or (x or (y and (z or i)) or j)) +(a and (b and (c or d)) and (e and f) or x) and y + +# # TODO: Make this work similar to Old Parser +# (a or b and c) or z diff --git a/tests/parser/string1.py b/tests/parser/string1.py new file mode 100644 index 0000000000..2fc647596f --- /dev/null +++ b/tests/parser/string1.py @@ -0,0 +1,18 @@ +F"Hello, {first_name} {last_name}. You are {age} years old." +print(f"{__file__} executed in {elapsed} seconds.") + +"\nsometext\nanotherline\n" + +# TODO: Support format specifiers +# print(f"{__file__} executed in {elapsed:0.2f} seconds.") + +b"Some text goes here." +B""" +Multiple texts goes here. +""" + +r""" +Text +""" +R"Text" +r'a\tb\nA\tB' diff --git a/tests/parser/while1.py b/tests/parser/while1.py new file mode 100644 index 0000000000..8dc7c5f66b --- /dev/null +++ b/tests/parser/while1.py @@ -0,0 +1,11 @@ +from ltypes import i32 + +i: i32 = 10 + +while i < 3: + pass + +while i < 6: + pass +else: + pass diff --git a/tests/reference/asr-array_01_decl-39cf894.json b/tests/reference/asr-array_01_decl-39cf894.json new file mode 100644 index 0000000000..9de6947131 --- /dev/null +++ b/tests/reference/asr-array_01_decl-39cf894.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-array_01_decl-39cf894", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/array_01_decl.py", + "infile_hash": "e5f2b6082b67a8a7847e7051d7b4d3c954d1ea88d865326810543dca", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-array_01_decl-39cf894.stdout", + "stdout_hash": "3c22d34aae7280247cbdbb3e306279fa395498b5ec5b4cb0730c7d1c", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-array_01_decl-39cf894.stdout b/tests/reference/asr-array_01_decl-39cf894.stdout new file mode 100644 index 0000000000..1839d1dfb2 --- /dev/null +++ b/tests/reference/asr-array_01_decl-39cf894.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 8 {}) _lpython_main_program [] [(SubroutineCall 1 declare_arrays () [] ())] Source Public Implementation () .false. .false.), accept_f32_array: (Function (SymbolTable 4 {_lpython_return_variable: (Variable 4 _lpython_return_variable ReturnVar () () Default (Real 4 []) Source Public Required .false.), xf32: (Variable 4 xf32 InOut () () Default (Real 4 [(() ())]) Source Public Required .false.)}) accept_f32_array [(Var 4 xf32)] [(= (ArrayItem (Var 4 xf32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 4 []) ()) (Cast (RealConstant 3.20000000000000000e+01 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.20000000000000000e+01 (Real 4 []))) ()) (= (Var 4 _lpython_return_variable) (ArrayItem (Var 4 xf32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 4 []) ()) ()) (Return)] (Var 4 _lpython_return_variable) Source Public Implementation ()), accept_f64_array: (Function (SymbolTable 5 {_lpython_return_variable: (Variable 5 _lpython_return_variable ReturnVar () () Default (Real 8 []) Source Public Required .false.), xf64: (Variable 5 xf64 InOut () () Default (Real 8 [(() ())]) Source Public Required .false.)}) accept_f64_array [(Var 5 xf64)] [(= (ArrayItem (Var 5 xf64) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 8 []) ()) (RealConstant 6.40000000000000000e+01 (Real 8 [])) ()) (= (Var 5 _lpython_return_variable) (ArrayItem (Var 5 xf64) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 8 []) ()) ()) (Return)] (Var 5 _lpython_return_variable) Source Public Implementation ()), accept_i32_array: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), xi32: (Variable 2 xi32 InOut () () Default (Integer 4 [(() ())]) Source Public Required .false.)}) accept_i32_array [(Var 2 xi32)] [(= (ArrayItem (Var 2 xi32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 4 []) ()) (IntegerConstant 32 (Integer 4 [])) ()) (= (Var 2 _lpython_return_variable) (ArrayItem (Var 2 xi32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 4 []) ()) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ()), accept_i64_array: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 8 []) Source Public Required .false.), xi64: (Variable 3 xi64 InOut () () Default (Integer 8 [(() ())]) Source Public Required .false.)}) accept_i64_array [(Var 3 xi64)] [(= (ArrayItem (Var 3 xi64) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 8 []) ()) (Cast (IntegerConstant 64 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 3 _lpython_return_variable) (ArrayItem (Var 3 xi64) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 8 []) ()) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ()), declare_arrays: (Subroutine (SymbolTable 6 {ac32: (Variable 6 ac32 Local () () Default (Complex 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))))]) Source Public Required .false.), ac64: (Variable 6 ac64 Local () () Default (Complex 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 []))))]) Source Public Required .false.), af32: (Variable 6 af32 Local () () Default (Real 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))))]) Source Public Required .false.), af64: (Variable 6 af64 Local () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 []))))]) Source Public Required .false.), ai32: (Variable 6 ai32 Local () () Default (Integer 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))))]) Source Public Required .false.), ai64: (Variable 6 ai64 Local () () Default (Integer 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 []))))]) Source Public Required .false.)}) declare_arrays [] [(Print () [(FunctionCall 1 accept_i32_array () [((Var 6 ai32))] (Integer 4 []) () ())] () ()) (Print () [(FunctionCall 1 accept_i64_array () [((Var 6 ai64))] (Integer 8 []) () ())] () ()) (Print () [(FunctionCall 1 accept_f32_array () [((Var 6 af32))] (Real 4 []) () ())] () ()) (Print () [(FunctionCall 1 accept_f64_array () [((Var 6 af64))] (Real 8 []) () ())] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 7 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-array_02_decl-e8f6874.json b/tests/reference/asr-array_02_decl-e8f6874.json new file mode 100644 index 0000000000..acaa0d9d96 --- /dev/null +++ b/tests/reference/asr-array_02_decl-e8f6874.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-array_02_decl-e8f6874", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/array_02_decl.py", + "infile_hash": "49bfd0530662b64164eb87c7e1bc53d518a7ccc75469dfb7ced80e5f", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-array_02_decl-e8f6874.stdout", + "stdout_hash": "f45c320c9714cd62a564152d0cdafebfdab18ea352a46ccee7426d49", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-array_02_decl-e8f6874.stdout b/tests/reference/asr-array_02_decl-e8f6874.stdout new file mode 100644 index 0000000000..8a59290d9e --- /dev/null +++ b/tests/reference/asr-array_02_decl-e8f6874.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 8 {}) _lpython_main_program [] [(SubroutineCall 1 declare_arrays () [] ())] Source Public Implementation () .false. .false.), accept_multidim_f32_array: (Function (SymbolTable 4 {_lpython_return_variable: (Variable 4 _lpython_return_variable ReturnVar () () Default (Real 4 []) Source Public Required .false.), xf32: (Variable 4 xf32 InOut () () Default (Real 4 [(() ())]) Source Public Required .false.)}) accept_multidim_f32_array [(Var 4 xf32)] [(= (Var 4 _lpython_return_variable) (ArrayItem (Var 4 xf32) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Real 4 []) ()) ()) (Return)] (Var 4 _lpython_return_variable) Source Public Implementation ()), accept_multidim_f64_array: (Function (SymbolTable 5 {_lpython_return_variable: (Variable 5 _lpython_return_variable ReturnVar () () Default (Real 8 []) Source Public Required .false.), xf64: (Variable 5 xf64 InOut () () Default (Real 8 [(() ()) (() ())]) Source Public Required .false.)}) accept_multidim_f64_array [(Var 5 xf64)] [(= (Var 5 _lpython_return_variable) (ArrayItem (Var 5 xf64) [(() (IntegerConstant 0 (Integer 4 [])) ()) (() (IntegerConstant 1 (Integer 4 [])) ())] (Real 8 []) ()) ()) (Return)] (Var 5 _lpython_return_variable) Source Public Implementation ()), accept_multidim_i32_array: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), xi32: (Variable 2 xi32 InOut () () Default (Integer 4 [(() ()) (() ())]) Source Public Required .false.)}) accept_multidim_i32_array [(Var 2 xi32)] [(= (Var 2 _lpython_return_variable) (ArrayItem (Var 2 xi32) [(() (IntegerConstant 0 (Integer 4 [])) ()) (() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 4 []) ()) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ()), accept_multidim_i64_array: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 8 []) Source Public Required .false.), xi64: (Variable 3 xi64 InOut () () Default (Integer 8 [(() ()) (() ()) (() ())]) Source Public Required .false.)}) accept_multidim_i64_array [(Var 3 xi64)] [(= (Var 3 _lpython_return_variable) (ArrayItem (Var 3 xi64) [(() (IntegerConstant 9 (Integer 4 [])) ()) (() (IntegerConstant 9 (Integer 4 [])) ()) (() (IntegerConstant 9 (Integer 4 [])) ())] (Integer 8 []) ()) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ()), declare_arrays: (Subroutine (SymbolTable 6 {ac32: (Variable 6 ac32 Local () () Default (Complex 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 5 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 99 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 98 (Integer 4 []))))]) Source Public Required .false.), ac64: (Variable 6 ac64 Local () () Default (Complex 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 13 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 12 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 11 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 10 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 16 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 15 (Integer 4 []))))]) Source Public Required .false.), af32: (Variable 6 af32 Local () () Default (Real 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))))]) Source Public Required .false.), af64: (Variable 6 af64 Local () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 4 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))))]) Source Public Required .false.), ai32: (Variable 6 ai32 Local () () Default (Integer 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 3 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))))]) Source Public Required .false.), ai64: (Variable 6 ai64 Local () () Default (Integer 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 [])))) ((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 []))))]) Source Public Required .false.)}) declare_arrays [] [(Print () [(FunctionCall 1 accept_multidim_i32_array () [((Var 6 ai32))] (Integer 4 []) () ())] () ()) (Print () [(FunctionCall 1 accept_multidim_i64_array () [((Var 6 ai64))] (Integer 8 []) () ())] () ()) (Print () [(FunctionCall 1 accept_multidim_f32_array () [((Var 6 af32))] (Real 4 []) () ())] () ()) (Print () [(FunctionCall 1 accept_multidim_f64_array () [((Var 6 af64))] (Real 8 []) () ())] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 7 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-assert1-1ce92ea.json b/tests/reference/asr-assert1-1ce92ea.json index 494d11436b..b083afc294 100644 --- a/tests/reference/asr-assert1-1ce92ea.json +++ b/tests/reference/asr-assert1-1ce92ea.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-assert1-1ce92ea.stdout", - "stdout_hash": "8cbc1dd8c7394d071390db5e60301d6028c17dc648df132bdd736177", + "stdout_hash": "b70a9356b892f1a2818b1120dfad0018f4d64b53e88c502325ef98c6", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-assert1-1ce92ea.stdout b/tests/reference/asr-assert1-1ce92ea.stdout index 1c4e2db6b9..c161183999 100644 --- a/tests/reference/asr-assert1-1ce92ea.stdout +++ b/tests/reference/asr-assert1-1ce92ea.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_assert: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.)}) test_assert [] [(= (Var 2 a) (IntegerConstant 5 (Integer 4 [])) ()) (Assert (Compare (Var 2 a) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) () ()) (StringConstant "a is not 5" (Character 1 10 () []))) (Assert (Compare (Var 2 a) NotEq (IntegerConstant 10 (Integer 4 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_assert: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.)}) test_assert [] [(= (Var 2 a) (IntegerConstant 5 (Integer 4 [])) ()) (Assert (IntegerCompare (Var 2 a) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) ()) (StringConstant "a is not 5" (Character 1 10 () []))) (Assert (IntegerCompare (Var 2 a) NotEq (IntegerConstant 10 (Integer 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-assign1-886f049.json b/tests/reference/asr-assign1-886f049.json index d4cf64f4ea..85a952be0c 100644 --- a/tests/reference/asr-assign1-886f049.json +++ b/tests/reference/asr-assign1-886f049.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-assign1-886f049.stdout", - "stdout_hash": "1f41512bf4d7b4e6075aa0f29c546722c86ccd51788323c47c2996bf", + "stdout_hash": "e0cd419104a9f9d33db50d6adbf938af55edc369d615577248005313", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-assign1-886f049.stdout b/tests/reference/asr-assign1-886f049.stdout index 04f4a5745c..4ece459378 100644 --- a/tests/reference/asr-assign1-886f049.stdout +++ b/tests/reference/asr-assign1-886f049.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_augassign: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Character 1 -2 () []) Source Public Required .false.), r: (Variable 2 r Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Integer 4 []) Source Public Required .false.)}) test_augassign [] [(= (Var 2 r) (IntegerConstant 0 (Integer 4 [])) ()) (= (Var 2 r) (BinOp (Var 2 r) Add (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) () ()) ()) (= (Var 2 s) (IntegerConstant 5 (Integer 4 [])) ()) (= (Var 2 r) (BinOp (Var 2 r) Mul (Var 2 s) (Integer 4 []) () ()) ()) (= (Var 2 r) (BinOp (Var 2 r) Sub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) () ()) ()) (= (Var 2 s) (IntegerConstant 10 (Integer 4 [])) ()) (= (Var 2 r) (BinOp (Cast (Var 2 r) IntegerToReal (Real 8 []) ()) Div (Cast (Var 2 s) IntegerToReal (Real 8 []) ()) (Real 8 []) () ()) ()) (= (Var 2 a) (StringConstant "" (Character 1 0 () [])) ()) (= (Var 2 a) (StringConcat (Var 2 a) (StringConstant "test" (Character 1 4 () [])) (Character 1 2 () []) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_augassign: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Character 1 -2 () []) Source Public Required .false.), r: (Variable 2 r Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Integer 4 []) Source Public Required .false.)}) test_augassign [] [(= (Var 2 r) (IntegerConstant 0 (Integer 4 [])) ()) (= (Var 2 r) (IntegerBinOp (Var 2 r) Add (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) ()) ()) (= (Var 2 s) (IntegerConstant 5 (Integer 4 [])) ()) (= (Var 2 r) (IntegerBinOp (Var 2 r) Mul (Var 2 s) (Integer 4 []) ()) ()) (= (Var 2 r) (IntegerBinOp (Var 2 r) Sub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) ()) ()) (= (Var 2 s) (IntegerConstant 10 (Integer 4 [])) ()) (= (Var 2 r) (RealBinOp (Cast (Var 2 r) IntegerToReal (Real 8 []) ()) Div (Cast (Var 2 s) IntegerToReal (Real 8 []) ()) (Real 8 []) ()) ()) (= (Var 2 a) (StringConstant "" (Character 1 0 () [])) ()) (= (Var 2 a) (StringConcat (Var 2 a) (StringConstant "test" (Character 1 4 () [])) (Character 1 2 () []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-assign2-8d1a2ee.json b/tests/reference/asr-assign2-8d1a2ee.json index 777ef4dc69..d173f18d06 100644 --- a/tests/reference/asr-assign2-8d1a2ee.json +++ b/tests/reference/asr-assign2-8d1a2ee.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-assign2-8d1a2ee.stdout", - "stdout_hash": "543ba4ebcdcd0f6f9b360f6bde8fde60c4375e1e8b0d528e3bffc3c0", + "stdout_hash": "1faef0f925e9b0aef9c1c606170bf8a3795c2a076ea3de13e2f83143", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-assign2-8d1a2ee.stdout b/tests/reference/asr-assign2-8d1a2ee.stdout index 8a629c6fad..6016f9b490 100644 --- a/tests/reference/asr-assign2-8d1a2ee.stdout +++ b/tests/reference/asr-assign2-8d1a2ee.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {f: (Variable 1 f Local () (Cast (RealConstant 1.234568 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 1.234568 (Real 4 []))) Default (Real 4 []) Source Public Required .false.), f2: (Variable 1 f2 Local () (RealConstant 1.234568 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), i: (Variable 1 i Local () (IntegerConstant 5 (Integer 4 [])) Default (Integer 4 []) Source Public Required .false.), i2: (Variable 1 i2 Local () (Cast (IntegerConstant 53430903434 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) Default (Integer 8 []) Source Public Required .false.), main_program: (Program (SymbolTable 2 {}) main_program [] [])}) []) +(TranslationUnit (SymbolTable 1 {f: (Variable 1 f Local (Cast (RealConstant 1.23456788999999989e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 1.23456788999999989e+00 (Real 4 []))) () Default (Real 4 []) Source Public Required .false.), f2: (Variable 1 f2 Local (RealConstant 1.23456789012340007e+00 (Real 8 [])) () Default (Real 8 []) Source Public Required .false.), i: (Variable 1 i Local (IntegerConstant 5 (Integer 4 [])) () Default (Integer 4 []) Source Public Required .false.), i2: (Variable 1 i2 Local (Cast (IntegerConstant 53430903434 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) () Default (Integer 8 []) Source Public Required .false.), main_program: (Program (SymbolTable 2 {}) main_program [] [])}) []) diff --git a/tests/reference/asr-bindc_01-6d521a9.json b/tests/reference/asr-bindc_01-6d521a9.json new file mode 100644 index 0000000000..a60f4419a2 --- /dev/null +++ b/tests/reference/asr-bindc_01-6d521a9.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-bindc_01-6d521a9", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/bindc_01.py", + "infile_hash": "d4690d665de9b941c2581ad02041822e1e322dba55485cf8534dfe0a", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-bindc_01-6d521a9.stdout", + "stdout_hash": "d977f1baca4b5336cf1a3e813cf2d01a937a7f9db9169dd4abd37a06", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-bindc_01-6d521a9.stdout b/tests/reference/asr-bindc_01-6d521a9.stdout new file mode 100644 index 0000000000..689e0bc1b4 --- /dev/null +++ b/tests/reference/asr-bindc_01-6d521a9.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 3 {}) _lpython_main_program [] [(CPtrToPointer (Var 1 queries) (Var 1 x) ()) (Print () [(Var 1 queries) (Var 1 x)] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 2 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), queries: (Variable 1 queries Local () () Default (CPtr) Source Public Required .false.), x: (Variable 1 x Local () () Default (Pointer (Integer 2 [])) Source Public Required .false.)}) []) diff --git a/tests/reference/asr-bindc_02-bc1a7ea.json b/tests/reference/asr-bindc_02-bc1a7ea.json new file mode 100644 index 0000000000..2c5b9a5fe9 --- /dev/null +++ b/tests/reference/asr-bindc_02-bc1a7ea.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-bindc_02-bc1a7ea", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/bindc_02.py", + "infile_hash": "6cb36b53c00624e00b0457ee598e72dccd33d40b647a3bdc84949943", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-bindc_02-bc1a7ea.stdout", + "stdout_hash": "6282e37ff3c172de6814070fa202a47f77a78ea471e007501577d80c", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-bindc_02-bc1a7ea.stdout b/tests/reference/asr-bindc_02-bc1a7ea.stdout new file mode 100644 index 0000000000..429d72a1eb --- /dev/null +++ b/tests/reference/asr-bindc_02-bc1a7ea.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(CPtrToPointer (Var 1 queries) (Var 1 x) ()) (Print () [(Var 1 queries) (Var 1 x)] () ()) (SubroutineCall 1 f () [] ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 2 {y: (Variable 2 y Local () () Default (Integer 2 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))]) Source Public Required .false.), yptr1: (Variable 2 yptr1 Local () () Default (Pointer (Integer 2 [(() ())])) Source Public Required .false.), yq: (Variable 2 yq Local () () Default (CPtr) Source Public Required .false.)}) f [] [(= (ArrayItem (Var 2 y) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 2 []) ()) (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 2 []) ()) ()) (= (ArrayItem (Var 2 y) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Integer 2 []) ()) (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 2 []) ()) ()) (= (Var 2 yptr1) (GetPointer (Var 2 y) (Pointer (Integer 2 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))])) ()) ()) (Print () [(GetPointer (Var 2 y) (Pointer (Integer 2 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))])) ()) (Var 2 yptr1)] () ()) (Print () [(ArrayItem (Var 2 yptr1) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Pointer (Integer 2 [])) ()) (ArrayItem (Var 2 yptr1) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Pointer (Integer 2 [])) ())] () ()) (Assert (IntegerCompare (Cast (ArrayItem (Var 2 yptr1) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Pointer (Integer 2 [])) ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (Cast (ArrayItem (Var 2 yptr1) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Pointer (Integer 2 [])) ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ()) (CPtrToPointer (Var 2 yq) (Var 2 yptr1) ()) (Print () [(Var 2 yq) (Var 2 yptr1)] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), queries: (Variable 1 queries Local () () Default (CPtr) Source Public Required .false.), x: (Variable 1 x Local () () Default (Pointer (Integer 2 [(() ())])) Source Public Required .false.)}) []) diff --git a/tests/reference/asr-c_interop1-cf2e9b4.json b/tests/reference/asr-c_interop1-cf2e9b4.json new file mode 100644 index 0000000000..f4cf016808 --- /dev/null +++ b/tests/reference/asr-c_interop1-cf2e9b4.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-c_interop1-cf2e9b4", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/c_interop1.py", + "infile_hash": "e676d05044fa71c2bd65b09dd5ed2d20414f6b1c028ef528aab47748", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-c_interop1-cf2e9b4.stdout", + "stdout_hash": "b2bcc30028358bc577057acbdf4396c126082dd40fcbd03e16e8d447", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-c_interop1-cf2e9b4.stdout b/tests/reference/asr-c_interop1-cf2e9b4.stdout new file mode 100644 index 0000000000..a0af13f467 --- /dev/null +++ b/tests/reference/asr-c_interop1-cf2e9b4.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {f: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Real 8 []) BindC Public Required .false.), x: (Variable 2 x In () () Default (Real 8 []) BindC Public Required .true.)}) f [(Var 2 x)] [] (Var 2 _lpython_return_variable) BindC Public Interface ()), g: (Subroutine (SymbolTable 3 {a: (Variable 3 a In () () Default (Real 8 []) BindC Public Required .true.), b: (Variable 3 b In () () Default (Real 4 []) BindC Public Required .true.), c: (Variable 3 c In () () Default (Integer 8 []) BindC Public Required .true.), d: (Variable 3 d In () () Default (Integer 4 []) BindC Public Required .true.)}) g [(Var 3 a) (Var 3 b) (Var 3 c) (Var 3 d)] [] BindC Public Interface () .false. .false.), h: (Function (SymbolTable 4 {_lpython_return_variable: (Variable 4 _lpython_return_variable ReturnVar () () Default (Real 8 []) BindC Public Required .false.), x: (Variable 4 x In () () Default (Real 8 []) BindC Public Required .true.)}) h [(Var 4 x)] [(= (Var 4 _lpython_return_variable) (RealBinOp (Var 4 x) Add (RealConstant 1.00000000000000000e+00 (Real 8 [])) (Real 8 []) ()) ()) (Return)] (Var 4 _lpython_return_variable) BindC Public Implementation ()), l: (Subroutine (SymbolTable 5 {a: (Variable 5 a In () () Default (Real 8 []) BindC Public Required .true.), b: (Variable 5 b In () () Default (Real 4 []) BindC Public Required .true.), c: (Variable 5 c In () () Default (Integer 8 []) BindC Public Required .true.), d: (Variable 5 d In () () Default (Integer 4 []) BindC Public Required .true.)}) l [(Var 5 a) (Var 5 b) (Var 5 c) (Var 5 d)] [(Print () [(StringConstant "OK" (Character 1 2 () []))] () ())] BindC Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 6 {i: (Variable 6 i Local () () Default (Real 8 []) Source Public Required .false.), x: (Variable 6 x Local () () Default (Real 8 []) Source Public Required .false.), y: (Variable 6 y Local () () Default (Real 4 []) Source Public Required .false.), z: (Variable 6 z Local () () Default (Integer 8 []) Source Public Required .false.), zz: (Variable 6 zz Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(= (Var 6 x) (RealConstant 5.00000000000000000e+00 (Real 8 [])) ()) (= (Var 6 i) (FunctionCall 1 f () [((Var 6 x))] (Real 8 []) () ()) ()) (= (Var 6 y) (Cast (RealConstant 5.40000000000000036e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.40000000000000036e+00 (Real 4 []))) ()) (= (Var 6 z) (Cast (IntegerConstant 3 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 6 zz) (IntegerConstant 2 (Integer 4 [])) ()) (SubroutineCall 1 g () [((Var 6 x)) ((Var 6 y)) ((Var 6 z)) ((Var 6 zz))] ()) (= (Var 6 i) (FunctionCall 1 h () [((Var 6 x))] (Real 8 []) () ()) ()) (SubroutineCall 1 l () [((Var 6 x)) ((Var 6 y)) ((Var 6 z)) ((Var 6 zz))] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 7 {}) main_program [] [])}) []) diff --git a/tests/reference/asr-complex1-f26c460.json b/tests/reference/asr-complex1-f26c460.json index 0ac8c9364e..cd371f17e7 100644 --- a/tests/reference/asr-complex1-f26c460.json +++ b/tests/reference/asr-complex1-f26c460.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-complex1-f26c460.stdout", - "stdout_hash": "da64938647191f746cfab04fe5cf8a3640f6a5592e0b67c256749ee2", + "stdout_hash": "980e5b537a5cd5b271ecdd96e25987c18139ecaa38dd1a03c89af7e2", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-complex1-f26c460.stdout b/tests/reference/asr-complex1-f26c460.stdout index 63401551d6..98a703ee84 100644 --- a/tests/reference/asr-complex1-f26c460.stdout +++ b/tests/reference/asr-complex1-f26c460.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {complex@__lpython_overloaded_0__complex: (ExternalSymbol 1 complex@__lpython_overloaded_0__complex 5 __lpython_overloaded_0__complex lpython_builtin [] __lpython_overloaded_0__complex Public), complex@__lpython_overloaded_13__complex: (ExternalSymbol 1 complex@__lpython_overloaded_13__complex 5 __lpython_overloaded_13__complex lpython_builtin [] __lpython_overloaded_13__complex Public), complex@__lpython_overloaded_1__complex: (ExternalSymbol 1 complex@__lpython_overloaded_1__complex 5 __lpython_overloaded_1__complex lpython_builtin [] __lpython_overloaded_1__complex Public), complex@__lpython_overloaded_2__complex: (ExternalSymbol 1 complex@__lpython_overloaded_2__complex 5 __lpython_overloaded_2__complex lpython_builtin [] __lpython_overloaded_2__complex Public), complex@__lpython_overloaded_5__complex: (ExternalSymbol 1 complex@__lpython_overloaded_5__complex 5 __lpython_overloaded_5__complex lpython_builtin [] __lpython_overloaded_5__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 5 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 97 {}) main_program [] []), test: (Subroutine (SymbolTable 3 {x: (Variable 3 x Local () () Default (Complex 8 []) Source Public Required .false.), y: (Variable 3 y Local () () Default (Complex 8 []) Source Public Required .false.), z: (Variable 3 z Local () () Default (Complex 4 []) Source Public Required .false.)}) test [] [(= (Var 3 x) (BinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 2.000000 0.000000 (Complex 8 []))) Add (ComplexConstant 0.000000 3.000000 (Complex 8 [])) (Complex 8 []) (ComplexConstant 2.000000 3.000000 (Complex 8 [])) ()) ()) (= (Var 3 y) (BinOp (Cast (IntegerConstant 5 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 5.000000 0.000000 (Complex 8 []))) Add (ComplexConstant 0.000000 5.000000 (Complex 8 [])) (Complex 8 []) (ComplexConstant 5.000000 5.000000 (Complex 8 [])) ()) ()) (= (Var 3 z) (Cast (BinOp (Var 3 x) Add (Var 3 y) (Complex 8 []) () ()) ComplexToComplex (Complex 4 []) ()) ()) (= (Var 3 z) (Cast (BinOp (Var 3 x) Sub (Var 3 y) (Complex 8 []) () ()) ComplexToComplex (Complex 4 []) ()) ()) (= (Var 3 z) (Cast (BinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 2.000000 0.000000 (Complex 8 []))) Mul (Var 3 x) (Complex 8 []) () ()) ComplexToComplex (Complex 4 []) ()) ())] Source Public Implementation () .false. .false.), test_complex: (Subroutine (SymbolTable 2 {b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Complex 4 []) Source Public Required .false.), c1: (Variable 2 c1 Local () () Default (Complex 4 []) Source Public Required .false.), c2: (Variable 2 c2 Local () () Default (Complex 4 []) Source Public Required .false.), c3: (Variable 2 c3 Local () () Default (Complex 8 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 5 complex lpython_builtin [] complex Private)}) test_complex [] [(= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_0__complex 2 complex [] (Complex 8 []) (ComplexConstant 0.000000 0.000000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 0.000000 0.000000 (Complex 4 []))) ()) (= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_1__complex 2 complex [((RealConstant 3.400000 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.400000 0.000000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 3.400000 0.000000 (Complex 4 []))) ()) (= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_5__complex 2 complex [((RealConstant 5.000000 (Real 8 []))) ((RealConstant 4.300000 (Real 8 [])))] (Complex 8 []) (ComplexConstant 5.000000 4.300000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 5.000000 4.300000 (Complex 4 []))) ()) (= (Var 2 c) (FunctionCall 1 complex@__lpython_overloaded_2__complex 2 complex [((IntegerConstant 1 (Integer 4 [])))] (Complex 4 []) (ComplexConstant 1.000000 0.000000 (Complex 8 [])) ()) ()) (= (Var 2 c1) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.000000 4.000000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 3.000000 4.000000 (Complex 4 []))) ()) (= (Var 2 c2) (Cast (FunctionCall 1 complex@__lpython_overloaded_13__complex 2 complex [((IntegerConstant 2 (Integer 4 []))) ((RealConstant 4.500000 (Real 8 [])))] (Complex 8 []) (ComplexConstant 2.000000 4.500000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 2.000000 4.500000 (Complex 4 []))) ()) (= (Var 2 c3) (FunctionCall 1 complex@__lpython_overloaded_5__complex 2 complex [((RealConstant 3.000000 (Real 8 []))) ((RealConstant 4.000000 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.000000 4.000000 (Complex 8 [])) ()) ()) (= (Var 2 b) (Compare (Var 2 c1) NotEq (Var 2 c2) (Logical 4 []) () ()) ()) (= (Var 2 b) (Compare (Cast (Var 2 c1) ComplexToComplex (Complex 8 []) ()) Eq (Var 2 c3) (Logical 4 []) () ()) ()) (= (Var 2 c) (BinOp (Var 2 c1) Add (Var 2 c2) (Complex 4 []) () ()) ()) (= (Var 2 c) (BinOp (Var 2 c2) Sub (Var 2 c1) (Complex 4 []) () ()) ()) (= (Var 2 c) (BinOp (Var 2 c1) Mul (Var 2 c2) (Complex 4 []) () ()) ()) (= (Var 2 c) (Cast (BinOp (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 1.000000 2.000000 (Complex 8 [])) ()) Pow (FunctionCall 1 complex@__lpython_overloaded_5__complex 2 complex [((RealConstant 3.345340 (Real 8 []))) ((RealConstant 4.867868 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.345340 4.867868 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant 0.015553 0.065561 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 0.015553 0.065561 (Complex 4 []))) ()) (= (Var 2 c) (Cast (BinOp (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 1.000000 2.000000 (Complex 8 [])) ()) Mul (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.000000 4.000000 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant -5.000000 10.000000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant -5.000000 10.000000 (Complex 4 []))) ()) (= (Var 2 c) (Cast (BinOp (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 4.000000 5.000000 (Complex 8 [])) ()) Sub (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.000000 4.000000 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant 1.000000 1.000000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 1.000000 1.000000 (Complex 4 []))) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {complex@__lpython_overloaded_0__complex: (ExternalSymbol 1 complex@__lpython_overloaded_0__complex 5 __lpython_overloaded_0__complex lpython_builtin [] __lpython_overloaded_0__complex Public), complex@__lpython_overloaded_13__complex: (ExternalSymbol 1 complex@__lpython_overloaded_13__complex 5 __lpython_overloaded_13__complex lpython_builtin [] __lpython_overloaded_13__complex Public), complex@__lpython_overloaded_1__complex: (ExternalSymbol 1 complex@__lpython_overloaded_1__complex 5 __lpython_overloaded_1__complex lpython_builtin [] __lpython_overloaded_1__complex Public), complex@__lpython_overloaded_2__complex: (ExternalSymbol 1 complex@__lpython_overloaded_2__complex 5 __lpython_overloaded_2__complex lpython_builtin [] __lpython_overloaded_2__complex Public), complex@__lpython_overloaded_5__complex: (ExternalSymbol 1 complex@__lpython_overloaded_5__complex 5 __lpython_overloaded_5__complex lpython_builtin [] __lpython_overloaded_5__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 5 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 80 {}) main_program [] []), test: (Subroutine (SymbolTable 3 {x: (Variable 3 x Local () () Default (Complex 8 []) Source Public Required .false.), y: (Variable 3 y Local () () Default (Complex 8 []) Source Public Required .false.), z: (Variable 3 z Local () () Default (Complex 4 []) Source Public Required .false.)}) test [] [(= (Var 3 x) (ComplexBinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 []))) ()) (= (Var 3 y) (ComplexBinOp (Cast (IntegerConstant 5 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 5.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 5.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 []))) ()) (= (Var 3 z) (Cast (ComplexBinOp (Var 3 x) Add (Var 3 y) (Complex 8 []) ()) ComplexToComplex (Complex 4 []) ()) ()) (= (Var 3 z) (Cast (ComplexBinOp (Var 3 x) Sub (Var 3 y) (Complex 8 []) ()) ComplexToComplex (Complex 4 []) ()) ()) (= (Var 3 z) (Cast (ComplexBinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Mul (Var 3 x) (Complex 8 []) ()) ComplexToComplex (Complex 4 []) ()) ())] Source Public Implementation () .false. .false.), test_complex: (Subroutine (SymbolTable 2 {b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Complex 4 []) Source Public Required .false.), c1: (Variable 2 c1 Local () () Default (Complex 4 []) Source Public Required .false.), c2: (Variable 2 c2 Local () () Default (Complex 4 []) Source Public Required .false.), c3: (Variable 2 c3 Local () () Default (Complex 8 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 5 complex lpython_builtin [] complex Private)}) test_complex [] [(= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_0__complex 2 complex [] (Complex 8 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_1__complex 2 complex [((RealConstant 3.39999999999999991e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.39999999999999991e+00 0.00000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 3.39999999999999991e+00 0.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_5__complex 2 complex [((RealConstant 5.00000000000000000e+00 (Real 8 []))) ((RealConstant 4.29999999999999982e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 5.00000000000000000e+00 4.29999999999999982e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 5.00000000000000000e+00 4.29999999999999982e+00 (Complex 4 []))) ()) (= (Var 2 c) (FunctionCall 1 complex@__lpython_overloaded_2__complex 2 complex [((IntegerConstant 1 (Integer 4 [])))] (Complex 4 []) (ComplexConstant 1.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 [])) ()) ()) (= (Var 2 c1) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 2 c2) (Cast (FunctionCall 1 complex@__lpython_overloaded_13__complex 2 complex [((IntegerConstant 2 (Integer 4 []))) ((RealConstant 4.50000000000000000e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 4.50000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 2.00000000000000000e+00 4.50000000000000000e+00 (Complex 4 []))) ()) (= (Var 2 c3) (FunctionCall 1 complex@__lpython_overloaded_5__complex 2 complex [((RealConstant 3.00000000000000000e+00 (Real 8 []))) ((RealConstant 4.00000000000000000e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 [])) ()) ()) (= (Var 2 b) (ComplexCompare (Var 2 c1) NotEq (Var 2 c2) (Logical 4 []) ()) ()) (= (Var 2 b) (ComplexCompare (Cast (Var 2 c1) ComplexToComplex (Complex 8 []) ()) Eq (Var 2 c3) (Logical 4 []) ()) ()) (= (Var 2 c) (ComplexBinOp (Var 2 c1) Add (Var 2 c2) (Complex 4 []) ()) ()) (= (Var 2 c) (ComplexBinOp (Var 2 c2) Sub (Var 2 c1) (Complex 4 []) ()) ()) (= (Var 2 c) (ComplexBinOp (Var 2 c1) Mul (Var 2 c2) (Complex 4 []) ()) ()) (= (Var 2 c) (Cast (ComplexBinOp (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 1.00000000000000000e+00 2.00000000000000000e+00 (Complex 8 [])) ()) Pow (FunctionCall 1 complex@__lpython_overloaded_5__complex 2 complex [((RealConstant 3.34534000000000020e+00 (Real 8 []))) ((RealConstant 4.86786779999999997e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.34534000000000020e+00 4.86786779999999997e+00 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant 1.55532894199002149e-02 6.55611790271555805e-02 (Complex 8 []))) ComplexToComplex (Complex 4 []) (ComplexConstant 1.55532894199002149e-02 6.55611790271555805e-02 (Complex 4 []))) ()) (= (Var 2 c) (Cast (ComplexBinOp (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 1.00000000000000000e+00 2.00000000000000000e+00 (Complex 8 [])) ()) Mul (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant -5.00000000000000000e+00 1.00000000000000000e+01 (Complex 8 []))) ComplexToComplex (Complex 4 []) (ComplexConstant -5.00000000000000000e+00 1.00000000000000000e+01 (Complex 4 []))) ()) (= (Var 2 c) (Cast (ComplexBinOp (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 4.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 [])) ()) Sub (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant 1.00000000000000000e+00 1.00000000000000000e+00 (Complex 8 []))) ComplexToComplex (Complex 4 []) (ComplexConstant 1.00000000000000000e+00 1.00000000000000000e+00 (Complex 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-constants1-5828e8a.json b/tests/reference/asr-constants1-5828e8a.json index 47078f6036..923333bbaa 100644 --- a/tests/reference/asr-constants1-5828e8a.json +++ b/tests/reference/asr-constants1-5828e8a.json @@ -2,11 +2,11 @@ "basename": "asr-constants1-5828e8a", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/constants1.py", - "infile_hash": "680bb6f62b6e7d58fdddc891954816cea0c25b9201576498f149849e", + "infile_hash": "0a352bce3bcf6a5662115060afcaee46a32e2577c0be9ce8b343eeb4", "outfile": null, "outfile_hash": null, "stdout": "asr-constants1-5828e8a.stdout", - "stdout_hash": "0a1dc0f25e4d924292468fe539457de28f1366d752d7dacddc670278", + "stdout_hash": "7a914bb5a15cfa62e7a269d46f490ba2c8b182665b3e467880072893", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-constants1-5828e8a.stdout b/tests/reference/asr-constants1-5828e8a.stdout index 5d9aa79ce0..ff265cb21f 100644 --- a/tests/reference/asr-constants1-5828e8a.stdout +++ b/tests/reference/asr-constants1-5828e8a.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 13 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), abs@__lpython_overloaded_4__abs: (ExternalSymbol 1 abs@__lpython_overloaded_4__abs 13 __lpython_overloaded_4__abs lpython_builtin [] __lpython_overloaded_4__abs Public), abs@__lpython_overloaded_6__abs: (ExternalSymbol 1 abs@__lpython_overloaded_6__abs 13 __lpython_overloaded_6__abs lpython_builtin [] __lpython_overloaded_6__abs Public), abs@__lpython_overloaded_8__abs: (ExternalSymbol 1 abs@__lpython_overloaded_8__abs 13 __lpython_overloaded_8__abs lpython_builtin [] __lpython_overloaded_8__abs Public), bool@__lpython_overloaded_0__bool: (ExternalSymbol 1 bool@__lpython_overloaded_0__bool 13 __lpython_overloaded_0__bool lpython_builtin [] __lpython_overloaded_0__bool Public), bool@__lpython_overloaded_5__bool: (ExternalSymbol 1 bool@__lpython_overloaded_5__bool 13 __lpython_overloaded_5__bool lpython_builtin [] __lpython_overloaded_5__bool Public), bool@__lpython_overloaded_6__bool: (ExternalSymbol 1 bool@__lpython_overloaded_6__bool 13 __lpython_overloaded_6__bool lpython_builtin [] __lpython_overloaded_6__bool Public), bool@__lpython_overloaded_9__bool: (ExternalSymbol 1 bool@__lpython_overloaded_9__bool 13 __lpython_overloaded_9__bool lpython_builtin [] __lpython_overloaded_9__bool Public), complex@__lpython_overloaded_5__complex: (ExternalSymbol 1 complex@__lpython_overloaded_5__complex 13 __lpython_overloaded_5__complex lpython_builtin [] __lpython_overloaded_5__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 13 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 105 {}) main_program [] []), test_abs: (Subroutine (SymbolTable 4 {a: (Variable 4 a Local () () Default (Integer 4 []) Source Public Required .false.), abs: (ExternalSymbol 4 abs 13 abs lpython_builtin [] abs Private), b: (Variable 4 b Local () () Default (Real 4 []) Source Public Required .false.), complex: (ExternalSymbol 4 complex 13 complex lpython_builtin [] complex Private)}) test_abs [] [(= (Var 4 a) (FunctionCall 1 abs@__lpython_overloaded_4__abs 4 abs [((IntegerConstant 5 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 5 (Integer 4 [])) ()) ()) (= (Var 4 a) (FunctionCall 1 abs@__lpython_overloaded_4__abs 4 abs [((UnaryOp USub (IntegerConstant 500 (Integer 4 [])) (Integer 4 []) (IntegerConstant -500 (Integer 4 []))))] (Integer 4 []) (IntegerConstant 500 (Integer 4 [])) ()) ()) (= (Var 4 a) (FunctionCall 1 abs@__lpython_overloaded_6__abs 4 abs [((LogicalConstant .false. (Logical 4 [])))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) ()) (= (Var 4 a) (FunctionCall 1 abs@__lpython_overloaded_6__abs 4 abs [((LogicalConstant .true. (Logical 4 [])))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) ()) (= (Var 4 b) (Cast (FunctionCall 1 abs@__lpython_overloaded_0__abs 4 abs [((RealConstant 3.450000 (Real 8 [])))] (Real 8 []) (RealConstant 3.450000 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant 3.450000 (Real 4 []))) ()) (= (Var 4 b) (Cast (FunctionCall 1 abs@__lpython_overloaded_0__abs 4 abs [((UnaryOp USub (RealConstant 5346.340000 (Real 8 [])) (Real 8 []) (RealConstant -5346.340000 (Real 8 []))))] (Real 8 []) (RealConstant 5346.340000 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant 5346.340000 (Real 4 []))) ()) (= (Var 4 b) (Cast (FunctionCall 1 abs@__lpython_overloaded_8__abs 4 abs [((FunctionCall 1 complex@__lpython_overloaded_5__complex 4 complex [((RealConstant 3.450000 (Real 8 []))) ((RealConstant 5.600000 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.450000 5.600000 (Complex 8 [])) ()))] (Real 8 []) (RealConstant 6.577424 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant 6.577424 (Real 4 []))) ())] Source Public Implementation () .false. .false.), test_bool: (Subroutine (SymbolTable 6 {a: (Variable 6 a Local () () Default (Logical 4 []) Source Public Required .false.), bool: (ExternalSymbol 6 bool 13 bool lpython_builtin [] bool Private), complex: (ExternalSymbol 6 complex 13 complex lpython_builtin [] complex Private)}) test_bool [] [(= (Var 6 a) (FunctionCall 1 bool@__lpython_overloaded_0__bool 6 bool [((IntegerConstant 0 (Integer 4 [])))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ()) (= (Var 6 a) (FunctionCall 1 bool@__lpython_overloaded_0__bool 6 bool [((UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))))] (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 6 a) (FunctionCall 1 bool@__lpython_overloaded_6__bool 6 bool [((StringConstant "" (Character 1 0 () [])))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ()) (= (Var 6 a) (FunctionCall 1 bool@__lpython_overloaded_9__bool 6 bool [((FunctionCall 1 complex@__lpython_overloaded_9__complex 6 complex [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 0.000000 0.000000 (Complex 8 [])) ()))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ()) (Assert (Compare (Var 6 a) Eq (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) () ()) ()) (= (Var 6 a) (FunctionCall 1 bool@__lpython_overloaded_6__bool 6 bool [((StringConstant "t" (Character 1 1 () [])))] (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 6 a) (FunctionCall 1 bool@__lpython_overloaded_5__bool 6 bool [((RealConstant 2.300000 (Real 8 [])))] (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 6 a) Eq (LogicalConstant .true. (Logical 4 [])) (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.), bin: (ExternalSymbol 2 bin 13 bin lpython_builtin [] bin Private), hex: (ExternalSymbol 2 hex 13 hex lpython_builtin [] hex Private), oct: (ExternalSymbol 2 oct 13 oct lpython_builtin [] oct Private)}) test_boz [] [(= (Var 2 b) (FunctionCall 2 bin () [((IntegerConstant 5 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0b101" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 bin () [((IntegerConstant 64 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0b1000000" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 bin () [((UnaryOp USub (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0b1000010110" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 oct () [((IntegerConstant 8 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0o10" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 oct () [((IntegerConstant 56 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0o70" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 oct () [((UnaryOp USub (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0o1026" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 hex () [((IntegerConstant 42 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0x2a" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 hex () [((IntegerConstant 12648430 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0xc0ffee" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 hex () [((UnaryOp USub (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0x216" (Character 1 1 () [])) ()) ())] Source Public Implementation () .false. .false.), test_callable: (Subroutine (SymbolTable 8 {a: (Variable 8 a Local () () Default (Logical 4 []) Source Public Required .false.), b: (Variable 8 b Local () () Default (Integer 4 []) Source Public Required .false.)}) test_callable [] [(= (Var 8 b) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 8 a) (LogicalConstant .true. (Logical 4 [])) ()) (Assert (Compare (Var 8 a) Eq (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) () ()) ()) (= (Var 8 a) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (Compare (Var 8 a) Eq (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) () ()) ()) (= (Var 8 a) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (Compare (Var 8 a) Eq (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.), test_divmod: (Subroutine (SymbolTable 11 {a: (Variable 11 a Local () () Default (Tuple [(Integer 4 []) (Integer 4 [])]) Source Public Required .false.), divmod: (ExternalSymbol 11 divmod 13 divmod lpython_builtin [] divmod Private)}) test_divmod [] [(= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 9 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant 3 (Integer 4 [])) (IntegerConstant 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) ()) (= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 9 (Integer 4 []))) ((UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant -3 (Integer 4 [])) (IntegerConstant 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) ()) (= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) ()) (= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant 0 (Integer 4 [])) (IntegerConstant 4 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) ()) (= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant 0 (Integer 4 [])) (IntegerConstant 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) (RealConstant 0.000000 (Real 8 [])) ()) (= (Var 10 a) (Cast (IntegerConstant 5 (Integer 4 [])) IntegerToReal (Real 8 []) (RealConstant 5.000000 (Real 8 []))) ()) (= (Var 10 a) (Cast (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant -1.000000 (Real 8 []))) ()) (= (Var 10 a) (Cast (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 1 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant 1.000000 (Real 8 []))) ()) (= (Var 10 a) (Cast (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant 0.000000 (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) (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (Cast (RealConstant 4.560000 (Real 8 [])) RealToInteger (Integer 4 []) (IntegerConstant 4 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (Cast (UnaryOp USub (RealConstant 5.000010 (Real 8 [])) (Real 8 []) (RealConstant -5.000010 (Real 8 []))) RealToInteger (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 1 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 0 (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.), l: (Variable 5 l Local () () Default (List (Integer 4 [])) Source Public Required .false.)}) test_len [] [(= (Var 5 a) (StringLen (StringConstant "" (Character 1 0 () [])) (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) ()) (= (Var 5 a) (StringLen (StringConstant "test" (Character 1 4 () [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 []))) ()) (= (Var 5 a) (StringLen (StringConstant "this is a test" (Character 1 14 () [])) (Integer 4 []) (IntegerConstant 14 (Integer 4 []))) ()) (= (Var 5 a) (TupleLen (TupleConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))) ()) (= (Var 5 a) (TupleLen (TupleConstant [(TupleConstant [(StringConstant "c" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (RealConstant 3.400000 (Real 8 []))] (Tuple [(Character 1 1 () []) (Character 1 1 () []) (Real 8 [])])) (TupleConstant [(StringConstant "c" (Character 1 1 () [])) (IntegerConstant 3 (Integer 4 [])) (RealConstant 5.600000 (Real 8 []))] (Tuple [(Character 1 1 () []) (Integer 4 []) (Real 8 [])]))] (Tuple [(Tuple [(Character 1 1 () []) (Character 1 1 () []) (Real 8 [])]) (Tuple [(Character 1 1 () []) (Integer 4 []) (Real 8 [])])])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))) ()) (= (Var 5 a) (ListLen (ListConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (List (Integer 4 []))) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))) ()) (= (Var 5 a) (ListLen (ListConstant [(ListConstant [(UnaryOp USub (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))) (UnaryOp USub (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) (UnaryOp USub (IntegerConstant 6 (Integer 4 [])) (Integer 4 []) (IntegerConstant -6 (Integer 4 [])))] (List (Integer 4 []))) (ListConstant [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 [])))] (List (Integer 4 [])))] (List (List (Integer 4 [])))) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))) ()) (= (Var 5 a) (SetLen (SetConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Set (Integer 4 []))) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))) ()) (= (Var 5 a) (DictLen (DictConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] [(StringConstant "c" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (Dict (Integer 4 []) (Character 1 1 () []))) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))) ()) (= (Var 5 l) (ListConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 [])) (IntegerConstant 4 (Integer 4 []))] (List (Integer 4 []))) ()) (= (Var 5 a) (ListLen (Var 5 l) (Integer 4 []) ()) ()) (ListAppend 5 l (IntegerConstant 5 (Integer 4 []))) (= (Var 5 a) (ListLen (Var 5 l) (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.), chr: (ExternalSymbol 3 chr 13 chr lpython_builtin [] chr Private), ord: (ExternalSymbol 3 ord 13 ord lpython_builtin [] ord Private), s: (Variable 3 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_ord_chr [] [(= (Var 3 a) (FunctionCall 3 ord () [((StringConstant "5" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 53 (Integer 4 [])) ()) ()) (= (Var 3 s) (FunctionCall 3 chr () [((IntegerConstant 43 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "+" (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.), str: (ExternalSymbol 7 str 13 str lpython_builtin [] str Private)}) test_str [] [(= (Var 7 s) (FunctionCall 7 str () [] (Character 1 -2 () []) (StringConstant "" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 7 str () [((IntegerConstant 5 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "5" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 7 str () [((UnaryOp USub (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-4" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 7 str () [((RealConstant 5.600000 (Real 8 [])))] (Character 1 -2 () []) (StringConstant "5.600000" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 7 str () [((LogicalConstant .true. (Logical 4 [])))] (Character 1 -2 () []) (StringConstant "True" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 7 str () [((LogicalConstant .false. (Logical 4 [])))] (Character 1 -2 () []) (StringConstant "False" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 7 str () [((StringConstant "5346" (Character 1 4 () [])))] (Character 1 -2 () []) (StringConstant "5346" (Character 1 1 () [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 13 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), abs@__lpython_overloaded_4__abs: (ExternalSymbol 1 abs@__lpython_overloaded_4__abs 13 __lpython_overloaded_4__abs lpython_builtin [] __lpython_overloaded_4__abs Public), abs@__lpython_overloaded_6__abs: (ExternalSymbol 1 abs@__lpython_overloaded_6__abs 13 __lpython_overloaded_6__abs lpython_builtin [] __lpython_overloaded_6__abs Public), abs@__lpython_overloaded_8__abs: (ExternalSymbol 1 abs@__lpython_overloaded_8__abs 13 __lpython_overloaded_8__abs lpython_builtin [] __lpython_overloaded_8__abs Public), complex@__lpython_overloaded_5__complex: (ExternalSymbol 1 complex@__lpython_overloaded_5__complex 13 __lpython_overloaded_5__complex lpython_builtin [] __lpython_overloaded_5__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 13 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 88 {}) main_program [] []), str@__lpython_overloaded_0__str: (ExternalSymbol 1 str@__lpython_overloaded_0__str 13 __lpython_overloaded_0__str lpython_builtin [] __lpython_overloaded_0__str Public), str@__lpython_overloaded_1__str: (ExternalSymbol 1 str@__lpython_overloaded_1__str 13 __lpython_overloaded_1__str lpython_builtin [] __lpython_overloaded_1__str Public), str@__lpython_overloaded_2__str: (ExternalSymbol 1 str@__lpython_overloaded_2__str 13 __lpython_overloaded_2__str lpython_builtin [] __lpython_overloaded_2__str Public), str@__lpython_overloaded_3__str: (ExternalSymbol 1 str@__lpython_overloaded_3__str 13 __lpython_overloaded_3__str lpython_builtin [] __lpython_overloaded_3__str Public), test_abs: (Subroutine (SymbolTable 4 {a: (Variable 4 a Local () () Default (Integer 4 []) Source Public Required .false.), abs: (ExternalSymbol 4 abs 13 abs lpython_builtin [] abs Private), b: (Variable 4 b Local () () Default (Real 4 []) Source Public Required .false.), complex: (ExternalSymbol 4 complex 13 complex lpython_builtin [] complex Private)}) test_abs [] [(= (Var 4 a) (FunctionCall 1 abs@__lpython_overloaded_4__abs 4 abs [((IntegerConstant 5 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 5 (Integer 4 [])) ()) ()) (= (Var 4 a) (FunctionCall 1 abs@__lpython_overloaded_4__abs 4 abs [((IntegerUnaryMinus (IntegerConstant 500 (Integer 4 [])) (Integer 4 []) (IntegerConstant -500 (Integer 4 []))))] (Integer 4 []) (IntegerConstant 500 (Integer 4 [])) ()) ()) (= (Var 4 a) (FunctionCall 1 abs@__lpython_overloaded_6__abs 4 abs [((LogicalConstant .false. (Logical 4 [])))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) ()) (= (Var 4 a) (FunctionCall 1 abs@__lpython_overloaded_6__abs 4 abs [((LogicalConstant .true. (Logical 4 [])))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) ()) (= (Var 4 b) (Cast (FunctionCall 1 abs@__lpython_overloaded_0__abs 4 abs [((RealConstant 3.45000000000000018e+00 (Real 8 [])))] (Real 8 []) (RealConstant 3.45000000000000018e+00 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant 3.45000000000000018e+00 (Real 4 []))) ()) (= (Var 4 b) (Cast (FunctionCall 1 abs@__lpython_overloaded_0__abs 4 abs [((RealUnaryMinus (RealConstant 5.34634000000000015e+03 (Real 8 [])) (Real 8 []) (RealConstant -5.34634000000000015e+03 (Real 8 []))))] (Real 8 []) (RealConstant 5.34634000000000015e+03 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant 5.34634000000000015e+03 (Real 4 []))) ()) (= (Var 4 b) (Cast (FunctionCall 1 abs@__lpython_overloaded_8__abs 4 abs [((FunctionCall 1 complex@__lpython_overloaded_5__complex 4 complex [((RealConstant 3.45000000000000018e+00 (Real 8 []))) ((RealConstant 5.59999999999999964e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.45000000000000018e+00 5.59999999999999964e+00 (Complex 8 [])) ()))] (Real 8 []) (RealConstant 6.57742350772701823e+00 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant 6.57742350772701823e+00 (Real 4 []))) ())] Source Public Implementation () .false. .false.), test_bool: (Subroutine (SymbolTable 6 {a: (Variable 6 a Local () () Default (Logical 4 []) Source Public Required .false.), complex: (ExternalSymbol 6 complex 13 complex lpython_builtin [] complex Private)}) test_bool [] [(= (Var 6 a) (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 6 a) (Cast (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) IntegerToLogical (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 6 a) (Cast (StringConstant "" (Character 1 0 () [])) CharacterToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 6 a) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 6 complex [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 [])) ()) ComplexToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (Assert (LogicalCompare (Var 6 a) Eq (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) ()) ()) (= (Var 6 a) (Cast (StringConstant "t" (Character 1 1 () [])) CharacterToLogical (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 6 a) (Cast (RealConstant 2.29999999999999982e+00 (Real 8 [])) RealToLogical (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (LogicalCompare (Var 6 a) Eq (LogicalConstant .true. (Logical 4 [])) (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.), bin: (ExternalSymbol 2 bin 13 bin lpython_builtin [] bin Private), hex: (ExternalSymbol 2 hex 13 hex lpython_builtin [] hex Private), oct: (ExternalSymbol 2 oct 13 oct lpython_builtin [] oct Private)}) test_boz [] [(= (Var 2 b) (FunctionCall 2 bin () [((IntegerConstant 5 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0b101" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 bin () [((IntegerConstant 64 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0b1000000" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 bin () [((IntegerUnaryMinus (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0b1000010110" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 oct () [((IntegerConstant 8 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0o10" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 oct () [((IntegerConstant 56 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0o70" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 oct () [((IntegerUnaryMinus (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0o1026" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 hex () [((IntegerConstant 42 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0x2a" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 hex () [((IntegerConstant 12648430 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0xc0ffee" (Character 1 1 () [])) ()) ()) (= (Var 2 b) (FunctionCall 2 hex () [((IntegerUnaryMinus (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0x216" (Character 1 1 () [])) ()) ())] Source Public Implementation () .false. .false.), test_callable: (Subroutine (SymbolTable 8 {a: (Variable 8 a Local () () Default (Logical 4 []) Source Public Required .false.), b: (Variable 8 b Local () () Default (Integer 4 []) Source Public Required .false.)}) test_callable [] [(= (Var 8 b) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 8 a) (LogicalConstant .true. (Logical 4 [])) ()) (Assert (LogicalCompare (Var 8 a) Eq (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) ()) ()) (= (Var 8 a) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (LogicalCompare (Var 8 a) Eq (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) ()) ()) (= (Var 8 a) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (LogicalCompare (Var 8 a) Eq (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), test_divmod: (Subroutine (SymbolTable 11 {a: (Variable 11 a Local () () Default (Tuple [(Integer 4 []) (Integer 4 [])]) Source Public Required .false.), divmod: (ExternalSymbol 11 divmod 13 divmod lpython_builtin [] divmod Private)}) test_divmod [] [(= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 9 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant 3 (Integer 4 [])) (IntegerConstant 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) ()) (= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 9 (Integer 4 []))) ((IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant -3 (Integer 4 [])) (IntegerConstant 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) ()) (= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 0 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) ()) (= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant 0 (Integer 4 [])) (IntegerConstant 4 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 [])])) ()) ()) (= (Var 11 a) (FunctionCall 11 divmod () [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 [])]) (TupleConstant [(IntegerConstant 0 (Integer 4 [])) (IntegerConstant 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) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) (= (Var 10 a) (Cast (IntegerConstant 5 (Integer 4 [])) IntegerToReal (Real 8 []) (RealConstant 5.00000000000000000e+00 (Real 8 []))) ()) (= (Var 10 a) (Cast (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant -1.00000000000000000e+00 (Real 8 []))) ()) (= (Var 10 a) (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToReal (Real 8 []) (RealConstant 1.00000000000000000e+00 (Real 8 []))) ()) (= (Var 10 a) (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToReal (Real 8 []) (RealConstant 0.00000000000000000e+00 (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) (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (Cast (RealConstant 4.55999999999999961e+00 (Real 8 [])) RealToInteger (Integer 4 []) (IntegerConstant 4 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (Cast (RealUnaryMinus (RealConstant 5.00000999999999962e+00 (Real 8 [])) (Real 8 []) (RealConstant -5.00000999999999962e+00 (Real 8 []))) RealToInteger (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 1 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 9 a) (Cast (IntegerConstant 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.), l: (Variable 5 l Local () () Default (List (Integer 4 [])) Source Public Required .false.)}) test_len [] [(= (Var 5 a) (StringLen (StringConstant "" (Character 1 0 () [])) (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) ()) (= (Var 5 a) (StringLen (StringConstant "test" (Character 1 4 () [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 []))) ()) (= (Var 5 a) (StringLen (StringConstant "this is a test" (Character 1 14 () [])) (Integer 4 []) (IntegerConstant 14 (Integer 4 []))) ()) (= (Var 5 a) (TupleLen (TupleConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))) ()) (= (Var 5 a) (TupleLen (TupleConstant [(TupleConstant [(StringConstant "c" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (RealConstant 3.39999999999999991e+00 (Real 8 []))] (Tuple [(Character 1 1 () []) (Character 1 1 () []) (Real 8 [])])) (TupleConstant [(StringConstant "c" (Character 1 1 () [])) (IntegerConstant 3 (Integer 4 [])) (RealConstant 5.59999999999999964e+00 (Real 8 []))] (Tuple [(Character 1 1 () []) (Integer 4 []) (Real 8 [])]))] (Tuple [(Tuple [(Character 1 1 () []) (Character 1 1 () []) (Real 8 [])]) (Tuple [(Character 1 1 () []) (Integer 4 []) (Real 8 [])])])) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))) ()) (= (Var 5 a) (ListLen (ListConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (List (Integer 4 []))) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))) ()) (= (Var 5 a) (ListLen (ListConstant [(ListConstant [(IntegerUnaryMinus (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 6 (Integer 4 [])) (Integer 4 []) (IntegerConstant -6 (Integer 4 [])))] (List (Integer 4 []))) (ListConstant [(IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 [])))] (List (Integer 4 [])))] (List (List (Integer 4 [])))) (Integer 4 []) (IntegerConstant 2 (Integer 4 []))) ()) (= (Var 5 a) (SetLen (SetConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Set (Integer 4 []))) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))) ()) (= (Var 5 a) (DictLen (DictConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] [(StringConstant "c" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (Dict (Integer 4 []) (Character 1 1 () []))) (Integer 4 []) (IntegerConstant 3 (Integer 4 []))) ()) (= (Var 5 l) (ListConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 [])) (IntegerConstant 4 (Integer 4 []))] (List (Integer 4 []))) ()) (= (Var 5 a) (ListLen (Var 5 l) (Integer 4 []) ()) ()) (ListAppend (Var 5 l) (IntegerConstant 5 (Integer 4 []))) (= (Var 5 a) (ListLen (Var 5 l) (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.), chr: (ExternalSymbol 3 chr 13 chr lpython_builtin [] chr Private), ord: (ExternalSymbol 3 ord 13 ord lpython_builtin [] ord Private), s: (Variable 3 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_ord_chr [] [(= (Var 3 a) (FunctionCall 3 ord () [((StringConstant "5" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 53 (Integer 4 [])) ()) ()) (= (Var 3 s) (FunctionCall 3 chr () [((IntegerConstant 43 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "+" (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.), str: (ExternalSymbol 7 str 13 str lpython_builtin [] str Private)}) test_str [] [(= (Var 7 s) (FunctionCall 1 str@__lpython_overloaded_0__str 7 str [] (Character 1 -2 () []) (StringConstant "" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 1 str@__lpython_overloaded_3__str 7 str [((IntegerConstant 5 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "5" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 1 str@__lpython_overloaded_3__str 7 str [((IntegerUnaryMinus (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-4" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 1 str@__lpython_overloaded_2__str 7 str [((LogicalConstant .true. (Logical 4 [])))] (Character 1 -2 () []) (StringConstant "True" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 1 str@__lpython_overloaded_2__str 7 str [((LogicalConstant .false. (Logical 4 [])))] (Character 1 -2 () []) (StringConstant "False" (Character 1 1 () [])) ()) ()) (= (Var 7 s) (FunctionCall 1 str@__lpython_overloaded_1__str 7 str [((StringConstant "5346" (Character 1 4 () [])))] (Character 1 -2 () []) (StringConstant "5346" (Character 1 1 () [])) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-dictionary1-a105a36.json b/tests/reference/asr-dictionary1-a105a36.json index cbd033eb4c..5931017824 100644 --- a/tests/reference/asr-dictionary1-a105a36.json +++ b/tests/reference/asr-dictionary1-a105a36.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-dictionary1-a105a36.stdout", - "stdout_hash": "630b34fdc9d933db1c405d992fd3a4f5e619f2c6f014d746fe7013d0", + "stdout_hash": "15df809d562ceaa0e64f9ca9f35911be1f9c97540b80fe43d533d07a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-dictionary1-a105a36.stdout b/tests/reference/asr-dictionary1-a105a36.stdout index 248acde238..1b2142a7b9 100644 --- a/tests/reference/asr-dictionary1-a105a36.stdout +++ b/tests/reference/asr-dictionary1-a105a36.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 6 {}) main_program [] []), test_Dict: (Subroutine (SymbolTable 2 {x: (Variable 2 x Local () () Default (Dict (Integer 4 []) (Integer 4 [])) Source Public Required .false.), y: (Variable 2 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.), z: (Variable 2 z Local () () Default (Integer 4 []) Source Public Required .false.)}) test_Dict [] [(= (Var 2 x) (DictConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] [(IntegerConstant 2 (Integer 4 [])) (IntegerConstant 4 (Integer 4 []))] (Dict (Integer 4 []) (Integer 4 []))) ()) (= (Var 2 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 2 z) (DictItem 2 y (StringConstant "a" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 2 z) (DictItem 2 y (StringConstant "b" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 2 z) (DictItem 2 x (IntegerConstant 1 (Integer 4 [])) () (Integer 4 [])) ())] Source Public Implementation () .false. .false.), test_dict_get: (Subroutine (SymbolTable 4 {x: (Variable 4 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 4 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_get [] [(= (Var 4 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 4 x) (DictItem 4 y (StringConstant "a" (Character 1 1 () [])) () (Integer 4 [])) ()) (= (Var 4 x) (DictItem 4 y (StringConstant "a" (Character 1 1 () [])) (IntegerConstant 0 (Integer 4 [])) (Integer 4 [])) ())] Source Public Implementation () .false. .false.), test_dict_insert: (Subroutine (SymbolTable 3 {y: (Variable 3 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_insert [] [(= (Var 3 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (DictInsert 3 y (StringConstant "c" (Character 1 1 () [])) (UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))))] Source Public Implementation () .false. .false.), test_dict_pop: (Subroutine (SymbolTable 5 {x: (Variable 5 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 5 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_pop [] [(= (Var 5 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 []))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 5 x) (DictPop 5 y (StringConstant "a" (Character 1 1 () [])) (Integer 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 6 {}) main_program [] []), test_Dict: (Subroutine (SymbolTable 2 {x: (Variable 2 x Local () () Default (Dict (Integer 4 []) (Integer 4 [])) Source Public Required .false.), y: (Variable 2 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.), z: (Variable 2 z Local () () Default (Integer 4 []) Source Public Required .false.)}) test_Dict [] [(= (Var 2 x) (DictConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] [(IntegerConstant 2 (Integer 4 [])) (IntegerConstant 4 (Integer 4 []))] (Dict (Integer 4 []) (Integer 4 []))) ()) (= (Var 2 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 2 z) (DictItem (Var 2 y) (StringConstant "a" (Character 1 1 () [])) () (Integer 4 []) ()) ()) (= (Var 2 z) (DictItem (Var 2 y) (StringConstant "b" (Character 1 1 () [])) () (Integer 4 []) ()) ()) (= (Var 2 z) (DictItem (Var 2 x) (IntegerConstant 1 (Integer 4 [])) () (Integer 4 []) ()) ())] Source Public Implementation () .false. .false.), test_dict_get: (Subroutine (SymbolTable 4 {x: (Variable 4 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 4 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_get [] [(= (Var 4 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 4 x) (DictItem (Var 4 y) (StringConstant "a" (Character 1 1 () [])) () (Integer 4 []) ()) ()) (= (Var 4 x) (DictItem (Var 4 y) (StringConstant "a" (Character 1 1 () [])) (IntegerConstant 0 (Integer 4 [])) (Integer 4 []) ()) ())] Source Public Implementation () .false. .false.), test_dict_insert: (Subroutine (SymbolTable 3 {y: (Variable 3 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_insert [] [(= (Var 3 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 [])))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (DictInsert (Var 3 y) (StringConstant "c" (Character 1 1 () [])) (IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))))] Source Public Implementation () .false. .false.), test_dict_pop: (Subroutine (SymbolTable 5 {x: (Variable 5 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 5 y Local () () Default (Dict (Character 1 -2 () []) (Integer 4 [])) Source Public Required .false.)}) test_dict_pop [] [(= (Var 5 y) (DictConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 []))] (Dict (Character 1 1 () []) (Integer 4 []))) ()) (= (Var 5 x) (DictPop (Var 5 y) (StringConstant "a" (Character 1 1 () [])) (Integer 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-doconcurrentloop_01-3fdc189.json b/tests/reference/asr-doconcurrentloop_01-3fdc189.json index 7a69b656a5..a401ce1e12 100644 --- a/tests/reference/asr-doconcurrentloop_01-3fdc189.json +++ b/tests/reference/asr-doconcurrentloop_01-3fdc189.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-doconcurrentloop_01-3fdc189.stdout", - "stdout_hash": "d5a2db228796bffff987c05bb09922d050589f0739b5100039dc24b0", + "stdout_hash": "59caaae774258e2f54471c6262bdcdc7c6f544321fc3d8f595c37dbd", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-doconcurrentloop_01-3fdc189.stdout b/tests/reference/asr-doconcurrentloop_01-3fdc189.stdout index c5d8a11662..fe8cfd1f2c 100644 --- a/tests/reference/asr-doconcurrentloop_01-3fdc189.stdout +++ b/tests/reference/asr-doconcurrentloop_01-3fdc189.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 5 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 3 {a: (Variable 3 a Local () () Default (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]) Source Public Required .false.), b: (Variable 3 b Local () () Default (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]) Source Public Required .false.), c: (Variable 3 c Local () () Default (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]) Source Public Required .false.), i: (Variable 3 i Local () () Default (Integer 4 []) Source Public Required .false.), nsize: (Variable 3 nsize Local () () Default (Integer 4 []) Source Public Required .false.), scalar: (Variable 3 scalar Local () () Default (Real 4 []) Source Public Required .false.)}) main0 [] [(= (Var 3 scalar) (Cast (RealConstant 10.000000 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 10.000000 (Real 4 []))) ()) (= (Var 3 nsize) (IntegerConstant 1234 (Integer 4 [])) ()) (DoConcurrentLoop ((Var 3 i) (IntegerConstant 0 (Integer 4 [])) (BinOp (Var 3 nsize) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 1 (Integer 4 []))) [(= (ArrayRef 3 a [(() (BinOp (Var 3 i) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) ())] (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]) ()) (Cast (RealConstant 5.000000 (Real 8 [])) RealToReal (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]) (RealConstant 5.000000 (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]))) ()) (= (ArrayRef 3 b [(() (BinOp (Var 3 i) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) ())] (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]) ()) (Cast (RealConstant 5.000000 (Real 8 [])) RealToReal (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]) (RealConstant 5.000000 (Real 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 10000 (Integer 4 [])))]))) ())]) (SubroutineCall 1 triad () [((Var 3 a)) ((Var 3 b)) ((Var 3 scalar)) ((Var 3 c))] ()) (Print () [(StringConstant "End Stream Triad" (Character 1 16 () []))])] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 4 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), triad: (Subroutine (SymbolTable 2 {N: (Variable 2 N Local () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 2 a InOut () () Default (Real 4 [(() ())]) Source Public Required .false.), b: (Variable 2 b InOut () () Default (Real 4 [(() ())]) Source Public Required .false.), c: (Variable 2 c InOut () () Default (Real 4 [(() ())]) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), scalar: (Variable 2 scalar In () () Default (Real 4 []) Source Public Required .false.)}) triad [(Var 2 a) (Var 2 b) (Var 2 scalar) (Var 2 c)] [(= (Var 2 N) (IntegerConstant 1234 (Integer 4 [])) ()) (DoConcurrentLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (BinOp (Var 2 N) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 1 (Integer 4 []))) [(= (ArrayRef 2 c [(() (BinOp (Var 2 i) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) ())] (Real 4 [(() ())]) ()) (BinOp (ArrayRef 2 a [(() (BinOp (Var 2 i) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) ())] (Real 4 [(() ())]) ()) Add (BinOp (Var 2 scalar) Mul (ArrayRef 2 b [(() (BinOp (Var 2 i) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) ())] (Real 4 [(() ())]) ()) (Real 4 []) () ()) (Real 4 [(() ())]) () ()) ())])] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 5 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 3 {a: (Variable 3 a Local () () Default (Real 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10000 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9999 (Integer 4 []))))]) Source Public Required .false.), b: (Variable 3 b Local () () Default (Real 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10000 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9999 (Integer 4 []))))]) Source Public Required .false.), c: (Variable 3 c Local () () Default (Real 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10000 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9999 (Integer 4 []))))]) Source Public Required .false.), i: (Variable 3 i Local () () Default (Integer 4 []) Source Public Required .false.), nsize: (Variable 3 nsize Local () () Default (Integer 4 []) Source Public Required .false.), scalar: (Variable 3 scalar Local () () Default (Real 4 []) Source Public Required .false.)}) main0 [] [(= (Var 3 scalar) (Cast (RealConstant 1.00000000000000000e+01 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 1.00000000000000000e+01 (Real 4 []))) ()) (= (Var 3 nsize) (IntegerConstant 1234 (Integer 4 [])) ()) (DoConcurrentLoop ((Var 3 i) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (Var 3 nsize) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 1 (Integer 4 []))) [(= (ArrayItem (Var 3 a) [(() (Var 3 i) ())] (Real 4 []) ()) (Cast (RealConstant 5.00000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.00000000000000000e+00 (Real 4 []))) ()) (= (ArrayItem (Var 3 b) [(() (Var 3 i) ())] (Real 4 []) ()) (Cast (RealConstant 5.00000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.00000000000000000e+00 (Real 4 []))) ())]) (SubroutineCall 1 triad () [((Var 3 a)) ((Var 3 b)) ((Var 3 scalar)) ((Var 3 c))] ()) (Print () [(StringConstant "End Stream Triad" (Character 1 16 () []))] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 4 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), triad: (Subroutine (SymbolTable 2 {N: (Variable 2 N Local () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 2 a InOut () () Default (Real 4 [(() ())]) Source Public Required .false.), b: (Variable 2 b InOut () () Default (Real 4 [(() ())]) Source Public Required .false.), c: (Variable 2 c InOut () () Default (Real 4 [(() ())]) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), scalar: (Variable 2 scalar In () () Default (Real 4 []) Source Public Required .false.)}) triad [(Var 2 a) (Var 2 b) (Var 2 scalar) (Var 2 c)] [(= (Var 2 N) (IntegerConstant 1234 (Integer 4 [])) ()) (DoConcurrentLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (Var 2 N) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 1 (Integer 4 []))) [(= (ArrayItem (Var 2 c) [(() (Var 2 i) ())] (Real 4 []) ()) (RealBinOp (ArrayItem (Var 2 a) [(() (Var 2 i) ())] (Real 4 []) ()) Add (RealBinOp (Var 2 scalar) Mul (ArrayItem (Var 2 b) [(() (Var 2 i) ())] (Real 4 []) ()) (Real 4 []) ()) (Real 4 []) ()) ())])] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr1-8df2d66.json b/tests/reference/asr-expr1-8df2d66.json index b958fc0032..517d764ac3 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": "3e6010e171ba9438dae81691408224f63db3c4394d5026c89e2341ee", + "stdout_hash": "55f9f55dee231e83983edda8f8d32c62237355b32479440fba1aed98", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr1-8df2d66.stdout b/tests/reference/asr-expr1-8df2d66.stdout index 600728e816..73d82a3fa6 100644 --- a/tests/reference/asr-expr1-8df2d66.stdout +++ b/tests/reference/asr-expr1-8df2d66.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) 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 Private), 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) (IntegerConstant 0 (Integer 4 [])) (Integer 4 [])) ()) (If (NamedExpr (Var 2 a) (FunctionCall 2 ord () [((StringConstant "3" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 51 (Integer 4 [])) ()) (Integer 4 [])) [(= (Var 2 x) (IntegerConstant 1 (Integer 4 [])) ())] []) (WhileLoop (NamedExpr (Var 2 a) (IntegerConstant 1 (Integer 4 [])) (Integer 4 [])) [(= (Var 2 y) (IntegerConstant 1 (Integer 4 [])) ())])] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) 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 Private), 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) (IntegerConstant 0 (Integer 4 [])) (Integer 4 [])) ()) (If (NamedExpr (Var 2 a) (FunctionCall 2 ord () [((StringConstant "3" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 51 (Integer 4 [])) ()) (Integer 4 [])) [(= (Var 2 x) (IntegerConstant 1 (Integer 4 [])) ())] []) (WhileLoop (NamedExpr (Var 2 a) (IntegerConstant 1 (Integer 4 [])) (Integer 4 [])) [(= (Var 2 y) (IntegerConstant 1 (Integer 4 [])) ())])] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr10-efcbb1b.json b/tests/reference/asr-expr10-efcbb1b.json index fc20354302..dae4947c0c 100644 --- a/tests/reference/asr-expr10-efcbb1b.json +++ b/tests/reference/asr-expr10-efcbb1b.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr10-efcbb1b.stdout", - "stdout_hash": "61c0ab4590a17f4ea55862de60862706152c2b9b8e86071c3477c2a5", + "stdout_hash": "669170827767ee79c2ed756494c1f8ec17d5b46fad93f4eb63eed866", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr10-efcbb1b.stdout b/tests/reference/asr-expr10-efcbb1b.stdout index f24c55ccff..a8914ab604 100644 --- a/tests/reference/asr-expr10-efcbb1b.stdout +++ b/tests/reference/asr-expr10-efcbb1b.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {complex@__lpython_overloaded_13__complex: (ExternalSymbol 1 complex@__lpython_overloaded_13__complex 4 __lpython_overloaded_13__complex lpython_builtin [] __lpython_overloaded_13__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 4 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] []), test_UnaryOp: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), b1: (Variable 2 b1 Local () () Default (Logical 4 []) Source Public Required .false.), b2: (Variable 2 b2 Local () () Default (Logical 4 []) Source Public Required .false.), b3: (Variable 2 b3 Local () () Default (Logical 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Complex 4 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 4 complex lpython_builtin [] complex Private), f: (Variable 2 f Local () () Default (Real 4 []) Source Public Required .false.)}) test_UnaryOp [] [(= (Var 2 a) (UnaryOp UAdd (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 []))) ()) (= (Var 2 a) (UnaryOp USub (IntegerConstant 500 (Integer 4 [])) (Integer 4 []) (IntegerConstant -500 (Integer 4 []))) ()) (= (Var 2 a) (UnaryOp Invert (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -6 (Integer 4 []))) ()) (= (Var 2 b) (UnaryOp Not (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 b) (UnaryOp Not (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 b) (UnaryOp Not (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 f) (Cast (UnaryOp UAdd (RealConstant 1.000000 (Real 8 [])) (Real 8 []) (RealConstant 1.000000 (Real 8 []))) RealToReal (Real 4 []) (RealConstant 1.000000 (Real 4 []))) ()) (= (Var 2 f) (Cast (UnaryOp USub (RealConstant 183745.534000 (Real 8 [])) (Real 8 []) (RealConstant -183745.534000 (Real 8 []))) RealToReal (Real 4 []) (RealConstant -183745.534000 (Real 4 []))) ()) (= (Var 2 b1) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 b2) (UnaryOp Not (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 b3) (UnaryOp Not (Var 2 b2) (Logical 4 []) ()) ()) (= (Var 2 a) (UnaryOp UAdd (LogicalConstant .true. (Logical 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))) ()) (= (Var 2 a) (UnaryOp USub (LogicalConstant .false. (Logical 4 [])) (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) ()) (= (Var 2 a) (UnaryOp Invert (LogicalConstant .true. (Logical 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) ()) (= (Var 2 c) (Cast (UnaryOp UAdd (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 1.000000 2.000000 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant 1.000000 2.000000 (Complex 8 []))) ComplexToComplex (Complex 4 []) (ComplexConstant 1.000000 2.000000 (Complex 4 []))) ()) (= (Var 2 c) (Cast (UnaryOp USub (FunctionCall 1 complex@__lpython_overloaded_13__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((RealConstant 65.000000 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.000000 65.000000 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant -3.000000 -65.000000 (Complex 8 []))) ComplexToComplex (Complex 4 []) (ComplexConstant -3.000000 -65.000000 (Complex 4 []))) ()) (= (Var 2 b1) (UnaryOp Not (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.000000 4.000000 (Complex 8 [])) ()) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 b2) (UnaryOp Not (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 0.000000 0.000000 (Complex 8 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {complex@__lpython_overloaded_13__complex: (ExternalSymbol 1 complex@__lpython_overloaded_13__complex 4 __lpython_overloaded_13__complex lpython_builtin [] __lpython_overloaded_13__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 4 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] []), test_UnaryOp: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), b1: (Variable 2 b1 Local () () Default (Logical 4 []) Source Public Required .false.), b2: (Variable 2 b2 Local () () Default (Logical 4 []) Source Public Required .false.), b3: (Variable 2 b3 Local () () Default (Logical 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Complex 4 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 4 complex lpython_builtin [] complex Private), f: (Variable 2 f Local () () Default (Real 4 []) Source Public Required .false.)}) test_UnaryOp [] [(= (Var 2 a) (IntegerConstant 4 (Integer 4 [])) ()) (= (Var 2 a) (IntegerUnaryMinus (IntegerConstant 500 (Integer 4 [])) (Integer 4 []) (IntegerConstant -500 (Integer 4 []))) ()) (= (Var 2 a) (IntegerBitNot (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -6 (Integer 4 []))) ()) (= (Var 2 b) (LogicalNot (Cast (IntegerConstant 5 (Integer 4 [])) IntegerToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 b) (LogicalNot (Cast (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) IntegerToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 b) (LogicalNot (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToLogical (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 f) (Cast (RealConstant 1.00000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 1.00000000000000000e+00 (Real 4 []))) ()) (= (Var 2 f) (Cast (RealUnaryMinus (RealConstant 1.83745534000000014e+05 (Real 8 [])) (Real 8 []) (RealConstant -1.83745534000000014e+05 (Real 8 []))) RealToReal (Real 4 []) (RealConstant -1.83745534000000014e+05 (Real 4 []))) ()) (= (Var 2 b1) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 b2) (LogicalNot (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 b3) (LogicalNot (Var 2 b2) (Logical 4 []) ()) ()) (= (Var 2 a) (IntegerConstant 1 (Integer 4 [])) ()) (= (Var 2 a) (IntegerUnaryMinus (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) ()) (= (Var 2 a) (IntegerBitNot (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) ()) (= (Var 2 c) (Cast (ComplexConstant 1.00000000000000000e+00 2.00000000000000000e+00 (Complex 8 [])) ComplexToComplex (Complex 4 []) (ComplexConstant 1.00000000000000000e+00 2.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 2 c) (Cast (ComplexUnaryMinus (FunctionCall 1 complex@__lpython_overloaded_13__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((RealConstant 6.50000000000000000e+01 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 6.50000000000000000e+01 (Complex 8 [])) ()) (Complex 8 []) (ComplexConstant -3.00000000000000000e+00 -6.50000000000000000e+01 (Complex 8 []))) ComplexToComplex (Complex 4 []) (ComplexConstant -3.00000000000000000e+00 -6.50000000000000000e+01 (Complex 4 []))) ()) (= (Var 2 b1) (LogicalConstant .false. (Logical 4 [])) ()) (= (Var 2 b2) (LogicalConstant .true. (Logical 4 [])) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr11-9b91d35.json b/tests/reference/asr-expr11-9b91d35.json index 301bfe53d5..e14de06e80 100644 --- a/tests/reference/asr-expr11-9b91d35.json +++ b/tests/reference/asr-expr11-9b91d35.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr11-9b91d35.stdout", - "stdout_hash": "444e3c1ea0b1da808be7df9100ee2be0bfe2115d515a4510e4de394c", + "stdout_hash": "ef032c0d4460d06862fd172873b1c607f51634e098cfad22a1aa624f", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr11-9b91d35.stdout b/tests/reference/asr-expr11-9b91d35.stdout index 0f7334043d..9960fdb92b 100644 --- a/tests/reference/asr-expr11-9b91d35.stdout +++ b/tests/reference/asr-expr11-9b91d35.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_StrOp_repeat: (Subroutine (SymbolTable 2 {s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_StrOp_repeat [] [(= (Var 2 s) (StringRepeat (StringConstant "a" (Character 1 1 () [])) (IntegerConstant 2 (Integer 4 [])) (Character 1 2 () []) (StringConstant "aa" (Character 1 2 () []))) ()) (= (Var 2 s) (StringRepeat (StringConstant "a" (Character 1 1 () [])) (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (Character 1 0 () []) (StringConstant "" (Character 1 0 () []))) ()) (= (Var 2 s) (StringRepeat (StringConstant "test" (Character 1 4 () [])) (IntegerConstant 5 (Integer 4 [])) (Character 1 20 () []) (StringConstant "testtesttesttesttest" (Character 1 20 () []))) ()) (= (Var 2 s) (StringRepeat (StringConstant "bb" (Character 1 2 () [])) (IntegerConstant 4 (Integer 4 [])) (Character 1 8 () []) (StringConstant "bbbbbbbb" (Character 1 8 () []))) ()) (= (Var 2 s) (StringRepeat (StringConstant "bb" (Character 1 2 () [])) (UnaryOp USub (IntegerConstant 40 (Integer 4 [])) (Integer 4 []) (IntegerConstant -40 (Integer 4 []))) (Character 1 0 () []) (StringConstant "" (Character 1 0 () []))) ()) (= (Var 2 s) (StringRepeat (StringRepeat (StringConstant "a" (Character 1 1 () [])) (IntegerConstant 3 (Integer 4 [])) (Character 1 3 () []) (StringConstant "aaa" (Character 1 3 () []))) (IntegerConstant 3 (Integer 4 [])) (Character 1 9 () []) (StringConstant "aaaaaaaaa" (Character 1 9 () []))) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_StrOp_repeat: (Subroutine (SymbolTable 2 {s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_StrOp_repeat [] [(= (Var 2 s) (StringRepeat (StringConstant "a" (Character 1 1 () [])) (IntegerConstant 2 (Integer 4 [])) (Character 1 2 () []) (StringConstant "aa" (Character 1 2 () []))) ()) (= (Var 2 s) (StringRepeat (StringConstant "a" (Character 1 1 () [])) (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (Character 1 0 () []) (StringConstant "" (Character 1 0 () []))) ()) (= (Var 2 s) (StringRepeat (StringConstant "test" (Character 1 4 () [])) (IntegerConstant 5 (Integer 4 [])) (Character 1 20 () []) (StringConstant "testtesttesttesttest" (Character 1 20 () []))) ()) (= (Var 2 s) (StringRepeat (StringConstant "bb" (Character 1 2 () [])) (IntegerConstant 4 (Integer 4 [])) (Character 1 8 () []) (StringConstant "bbbbbbbb" (Character 1 8 () []))) ()) (= (Var 2 s) (StringRepeat (StringConstant "bb" (Character 1 2 () [])) (IntegerUnaryMinus (IntegerConstant 40 (Integer 4 [])) (Integer 4 []) (IntegerConstant -40 (Integer 4 []))) (Character 1 0 () []) (StringConstant "" (Character 1 0 () []))) ()) (= (Var 2 s) (StringRepeat (StringRepeat (StringConstant "a" (Character 1 1 () [])) (IntegerConstant 3 (Integer 4 [])) (Character 1 3 () []) (StringConstant "aaa" (Character 1 3 () []))) (IntegerConstant 3 (Integer 4 [])) (Character 1 9 () []) (StringConstant "aaaaaaaaa" (Character 1 9 () []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr12-5c5b71e.json b/tests/reference/asr-expr12-5c5b71e.json index ed354370fb..065177985e 100644 --- a/tests/reference/asr-expr12-5c5b71e.json +++ b/tests/reference/asr-expr12-5c5b71e.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr12-5c5b71e.stdout", - "stdout_hash": "1efafc1d01738628decba28f5cd3e85fbde11dc3aff3447d6ccbe9a5", + "stdout_hash": "a53006a7689b1090a548861e03db162360d3ee7a2b923c3e43bf53f7", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr12-5c5b71e.stdout b/tests/reference/asr-expr12-5c5b71e.stdout index 3eba3119ee..061f4710d7 100644 --- a/tests/reference/asr-expr12-5c5b71e.stdout +++ b/tests/reference/asr-expr12-5c5b71e.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 6 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), check: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 3 a Local () () Default (Integer 4 []) Source Public Required .false.)}) check [] [(= (Var 3 a) (FunctionCall 1 test () [((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) () ()) ()) (= (Var 3 _lpython_return_variable) (Var 3 a) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ()), main0: (Subroutine (SymbolTable 4 {x: (Variable 4 x Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(= (Var 4 x) (FunctionCall 1 check () [] (Integer 4 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 5 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 2 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b In () () Default (Integer 4 []) Source Public Required .false.)}) test [(Var 2 a) (Var 2 b)] [(= (Var 2 _lpython_return_variable) (BinOp (Var 2 a) Pow (Var 2 b) (Integer 4 []) () ()) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ())}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 6 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), check: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 3 a Local () () Default (Integer 4 []) Source Public Required .false.)}) check [] [(= (Var 3 a) (FunctionCall 1 test () [((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) () ()) ()) (= (Var 3 _lpython_return_variable) (Var 3 a) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ()), main0: (Subroutine (SymbolTable 4 {x: (Variable 4 x Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(= (Var 4 x) (FunctionCall 1 check () [] (Integer 4 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 5 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 2 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b In () () Default (Integer 4 []) Source Public Required .false.)}) test [(Var 2 a) (Var 2 b)] [(= (Var 2 _lpython_return_variable) (IntegerBinOp (Var 2 a) Pow (Var 2 b) (Integer 4 []) ()) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ())}) []) diff --git a/tests/reference/asr-expr13-81bdb5a.json b/tests/reference/asr-expr13-81bdb5a.json index 758c6942ea..8f31076892 100644 --- a/tests/reference/asr-expr13-81bdb5a.json +++ b/tests/reference/asr-expr13-81bdb5a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr13-81bdb5a.stdout", - "stdout_hash": "f0b3d96f369f1f8c256f5930608a7b74b80cc64cb6559f6afd54e039", + "stdout_hash": "68a5ffabe6bc792583ec1b00c4579a7c96bbd9b0c4c902dfcc40fbd5", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr13-81bdb5a.stdout b/tests/reference/asr-expr13-81bdb5a.stdout index b8df3aa986..cd19b50006 100644 --- a/tests/reference/asr-expr13-81bdb5a.stdout +++ b/tests/reference/asr-expr13-81bdb5a.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {complex@__lpython_overloaded_5__complex: (ExternalSymbol 1 complex@__lpython_overloaded_5__complex 4 __lpython_overloaded_5__complex lpython_builtin [] __lpython_overloaded_5__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 4 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] []), test_Compare: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Logical 4 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 4 complex lpython_builtin [] complex Private)}) test_Compare [] [(= (Var 2 a) (Compare (IntegerConstant 5 (Integer 4 [])) Gt (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (IntegerConstant 5 (Integer 4 [])) LtE (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (IntegerConstant 5 (Integer 4 [])) Lt (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (RealConstant 5.600000 (Real 8 [])) GtE (RealConstant 5.599990 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (RealConstant 3.300000 (Real 8 [])) Eq (RealConstant 3.300000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (RealConstant 3.300000 (Real 8 [])) NotEq (RealConstant 3.400000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.000000 4.000000 (Complex 8 [])) ()) Eq (FunctionCall 1 complex@__lpython_overloaded_5__complex 2 complex [((RealConstant 3.000000 (Real 8 []))) ((RealConstant 4.000000 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.000000 4.000000 (Complex 8 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (StringConstant "abc" (Character 1 3 () [])) Gt (StringConstant "abd" (Character 1 3 () [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (StringConstant "" (Character 1 0 () [])) Lt (StringConstant "s" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (StringConstant "-abs" (Character 1 4 () [])) GtE (StringConstant "abs" (Character 1 3 () [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (StringConstant "abcd" (Character 1 4 () [])) LtE (StringConstant "abcde" (Character 1 5 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (StringConstant "abc" (Character 1 3 () [])) Eq (StringConstant "abc" (Character 1 3 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (StringConstant "abc" (Character 1 3 () [])) NotEq (StringConstant "abd" (Character 1 3 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (StringConstant "" (Character 1 0 () [])) Eq (StringConstant "+" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (LogicalConstant .true. (Logical 4 [])) Gt (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (LogicalConstant .true. (Logical 4 [])) Eq (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (LogicalConstant .false. (Logical 4 [])) NotEq (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 a) (Compare (LogicalConstant .false. (Logical 4 [])) GtE (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {complex@__lpython_overloaded_5__complex: (ExternalSymbol 1 complex@__lpython_overloaded_5__complex 4 __lpython_overloaded_5__complex lpython_builtin [] __lpython_overloaded_5__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 4 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] []), test_Compare: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Logical 4 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 4 complex lpython_builtin [] complex Private)}) test_Compare [] [(= (Var 2 a) (IntegerCompare (IntegerConstant 5 (Integer 4 [])) Gt (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (IntegerCompare (IntegerConstant 5 (Integer 4 [])) LtE (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 a) (IntegerCompare (IntegerConstant 5 (Integer 4 [])) Lt (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 a) (RealCompare (RealConstant 5.59999999999999964e+00 (Real 8 [])) GtE (RealConstant 5.59999000000000002e+00 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (RealCompare (RealConstant 3.29999999999999982e+00 (Real 8 [])) Eq (RealConstant 3.29999999999999982e+00 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (RealCompare (RealConstant 3.29999999999999982e+00 (Real 8 [])) NotEq (RealConstant 3.39999999999999991e+00 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (ComplexCompare (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 [])) ()) Eq (FunctionCall 1 complex@__lpython_overloaded_5__complex 2 complex [((RealConstant 3.00000000000000000e+00 (Real 8 []))) ((RealConstant 4.00000000000000000e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (StringCompare (StringConstant "abc" (Character 1 3 () [])) Gt (StringConstant "abd" (Character 1 3 () [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 a) (StringCompare (StringConstant "" (Character 1 0 () [])) Lt (StringConstant "s" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (StringCompare (StringConstant "-abs" (Character 1 4 () [])) GtE (StringConstant "abs" (Character 1 3 () [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 a) (StringCompare (StringConstant "abcd" (Character 1 4 () [])) LtE (StringConstant "abcde" (Character 1 5 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (StringCompare (StringConstant "abc" (Character 1 3 () [])) Eq (StringConstant "abc" (Character 1 3 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (StringCompare (StringConstant "abc" (Character 1 3 () [])) NotEq (StringConstant "abd" (Character 1 3 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (StringCompare (StringConstant "" (Character 1 0 () [])) Eq (StringConstant "+" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ()) (= (Var 2 a) (LogicalCompare (LogicalConstant .true. (Logical 4 [])) Gt (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (LogicalCompare (LogicalConstant .true. (Logical 4 [])) Eq (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (LogicalCompare (LogicalConstant .false. (Logical 4 [])) NotEq (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a) (LogicalCompare (LogicalConstant .false. (Logical 4 [])) GtE (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr16-a3dc453.json b/tests/reference/asr-expr16-a3dc453.json index af5f523695..cc83791b08 100644 --- a/tests/reference/asr-expr16-a3dc453.json +++ b/tests/reference/asr-expr16-a3dc453.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr16-a3dc453.stdout", - "stdout_hash": "b3a710c69dd09b43e085f5c5c33275c5de9aff97c77e4e18168e0a5f", + "stdout_hash": "8649269b59b3784ecbb13a4d053d83b1cf2fe7b30f770b859e2aaa84", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr16-a3dc453.stdout b/tests/reference/asr-expr16-a3dc453.stdout index d0c0e6a5c1..3088e04b36 100644 --- a/tests/reference/asr-expr16-a3dc453.stdout +++ b/tests/reference/asr-expr16-a3dc453.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_issue_455: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Real 8 []) Source Public Required .false.), data: (Variable 2 data In () () Default (List (Integer 4 [])) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), sum: (Variable 2 sum Local () () Default (Real 8 []) Source Public Required .false.)}) test_issue_455 [(Var 2 data)] [(= (Var 2 sum) (RealConstant 0.000000 (Real 8 [])) ()) (DoLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (BinOp (ListLen (Var 2 data) (Integer 4 []) ()) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 1 (Integer 4 []))) [(= (Var 2 sum) (BinOp (Var 2 sum) Add (Cast (ListItem 2 data (BinOp (Var 2 i) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Integer 4 []) ()) IntegerToReal (Real 8 []) ()) (Real 8 []) () ()) ())]) (= (Var 2 _lpython_return_variable) (Var 2 sum) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ())}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_issue_455: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Real 8 []) Source Public Required .false.), data: (Variable 2 data In () () Default (List (Integer 4 [])) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), sum: (Variable 2 sum Local () () Default (Real 8 []) Source Public Required .false.)}) test_issue_455 [(Var 2 data)] [(= (Var 2 sum) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) (DoLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (ListLen (Var 2 data) (Integer 4 []) ()) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 1 (Integer 4 []))) [(= (Var 2 sum) (RealBinOp (Var 2 sum) Add (Cast (ListItem (Var 2 data) (Var 2 i) (Integer 4 []) ()) IntegerToReal (Real 8 []) ()) (Real 8 []) ()) ())]) (= (Var 2 _lpython_return_variable) (Var 2 sum) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ())}) []) diff --git a/tests/reference/asr-expr2-2e78a12.json b/tests/reference/asr-expr2-2e78a12.json index baa994df03..fd7ad0a848 100644 --- a/tests/reference/asr-expr2-2e78a12.json +++ b/tests/reference/asr-expr2-2e78a12.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr2-2e78a12.stdout", - "stdout_hash": "a7d29034e9aabc77d23f2024f7af73b7729850c8417860d15b056d5c", + "stdout_hash": "617ef36a932fd595a0fee2b08423fdaa8f392217aa034679dae66742", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr2-2e78a12.stdout b/tests/reference/asr-expr2-2e78a12.stdout index 31d5adccc8..7b68fa4637 100644 --- a/tests/reference/asr-expr2-2e78a12.stdout +++ b/tests/reference/asr-expr2-2e78a12.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_boolOp: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Logical 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.)}) test_boolOp [] [(= (Var 2 a) (LogicalConstant .false. (Logical 4 [])) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 a) (BoolOp (Var 2 a) And (Var 2 b) (Logical 4 []) ()) ()) (= (Var 2 b) (BoolOp (Var 2 a) Or (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) ()) ()) (= (Var 2 a) (BoolOp (Var 2 a) Or (Var 2 b) (Logical 4 []) ()) ()) (= (Var 2 a) (BoolOp (Var 2 a) And (Compare (Var 2 b) Eq (Var 2 b) (Logical 4 []) () ()) (Logical 4 []) ()) ()) (= (Var 2 a) (BoolOp (Var 2 a) And (Compare (Var 2 b) NotEq (Var 2 b) (Logical 4 []) () ()) (Logical 4 []) ()) ()) (= (Var 2 a) (BoolOp (Var 2 b) Or (Var 2 b) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_boolOp: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Logical 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.)}) test_boolOp [] [(= (Var 2 a) (LogicalConstant .false. (Logical 4 [])) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 a) (LogicalBinOp (Var 2 a) And (Var 2 b) (Logical 4 []) ()) ()) (= (Var 2 b) (LogicalBinOp (Var 2 a) Or (LogicalConstant .true. (Logical 4 [])) (Logical 4 []) ()) ()) (= (Var 2 a) (LogicalBinOp (Var 2 a) Or (Var 2 b) (Logical 4 []) ()) ()) (= (Var 2 a) (LogicalBinOp (Var 2 a) And (LogicalCompare (Var 2 b) Eq (Var 2 b) (Logical 4 []) ()) (Logical 4 []) ()) ()) (= (Var 2 a) (LogicalBinOp (Var 2 a) And (LogicalCompare (Var 2 b) NotEq (Var 2 b) (Logical 4 []) ()) (Logical 4 []) ()) ()) (= (Var 2 a) (LogicalBinOp (Var 2 b) Or (Var 2 b) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr3-10eb0a4.json b/tests/reference/asr-expr3-10eb0a4.json index 2bf85c5b0b..6ca5fb0397 100644 --- a/tests/reference/asr-expr3-10eb0a4.json +++ b/tests/reference/asr-expr3-10eb0a4.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr3-10eb0a4.stdout", - "stdout_hash": "704092ae1a6bb585f767e262b7babba442866a439d95fd62860dc1b5", + "stdout_hash": "01780e61d6383c37f10b6753c9be6f3da1e49c97f14ff72434b90033", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr3-10eb0a4.stdout b/tests/reference/asr-expr3-10eb0a4.stdout index ae6f01ae0b..e9a16dbb0b 100644 --- a/tests/reference/asr-expr3-10eb0a4.stdout +++ b/tests/reference/asr-expr3-10eb0a4.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_cast: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Real 4 []) Source Public Required .false.)}) test_cast [] [(= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (Cast (RealConstant 4.200000 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 4.200000 (Real 4 []))) ()) (= (Var 2 a) (BinOp (Cast (Var 2 a) IntegerToReal (Real 4 []) ()) Mul (Var 2 b) (Real 4 []) () ()) ()) (= (Var 2 b) (BinOp (Var 2 b) Add (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToReal (Real 4 []) ()) (Real 4 []) () ()) ()) (= (Var 2 a) (IntegerConstant 5 (Integer 4 [])) ()) (= (Var 2 a) (BinOp (Cast (Var 2 a) IntegerToReal (Real 8 []) ()) Sub (RealConstant 3.900000 (Real 8 [])) (Real 8 []) () ()) ()) (= (Var 2 a) (BinOp (Cast (Var 2 a) IntegerToReal (Real 8 []) ()) Div (Var 2 b) (Real 8 []) () ()) ()) (= (Var 2 b) (Cast (BinOp (Cast (IntegerConstant 3 (Integer 4 [])) IntegerToReal (Real 8 []) ()) Div (Cast (IntegerConstant 4 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) () ()) RealToReal (Real 4 []) ()) ()) (If (Compare (Cast (Var 2 a) IntegerToReal (Real 4 []) ()) Lt (Var 2 b) (Logical 4 []) () ()) [(Print () [(StringConstant "a < b" (Character 1 5 () []))])] [])] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_cast: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Real 4 []) Source Public Required .false.)}) test_cast [] [(= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (Cast (RealConstant 4.20000000000000018e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 4.20000000000000018e+00 (Real 4 []))) ()) (= (Var 2 a) (RealBinOp (Cast (Var 2 a) IntegerToReal (Real 4 []) ()) Mul (Var 2 b) (Real 4 []) ()) ()) (= (Var 2 b) (RealBinOp (Var 2 b) Add (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToReal (Real 4 []) ()) (Real 4 []) ()) ()) (= (Var 2 a) (IntegerConstant 5 (Integer 4 [])) ()) (= (Var 2 a) (RealBinOp (Cast (Var 2 a) IntegerToReal (Real 8 []) ()) Sub (RealConstant 3.89999999999999991e+00 (Real 8 [])) (Real 8 []) ()) ()) (= (Var 2 a) (RealBinOp (Cast (Var 2 a) IntegerToReal (Real 8 []) ()) Div (Var 2 b) (Real 4 []) ()) ()) (= (Var 2 b) (Cast (RealBinOp (Cast (IntegerConstant 3 (Integer 4 [])) IntegerToReal (Real 8 []) ()) Div (Cast (IntegerConstant 4 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) ()) RealToReal (Real 4 []) ()) ()) (If (RealCompare (Cast (Var 2 a) IntegerToReal (Real 4 []) ()) Lt (Var 2 b) (Logical 4 []) ()) [(Print () [(StringConstant "a < b" (Character 1 5 () []))] () ())] [])] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr6-368e5ed.json b/tests/reference/asr-expr6-368e5ed.json index 3ff616ad0d..49d36ebb20 100644 --- a/tests/reference/asr-expr6-368e5ed.json +++ b/tests/reference/asr-expr6-368e5ed.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr6-368e5ed.stdout", - "stdout_hash": "3cd2e3d185644ee302ac572556b042d0f60589088fb166d124e9930f", + "stdout_hash": "1b1ce0fc5f4c160dbc802f2e1a16fe4cea79ffcba28df8f317ffbe29", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr6-368e5ed.stdout b/tests/reference/asr-expr6-368e5ed.stdout index a394a5234c..2e43a251a4 100644 --- a/tests/reference/asr-expr6-368e5ed.stdout +++ b/tests/reference/asr-expr6-368e5ed.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_ifexp: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Integer 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Logical 4 []) Source Public Required .false.)}) test_ifexp [] [(= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (IfExp (Compare (Var 2 a) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) () ()) (IntegerConstant 6 (Integer 4 [])) (IntegerConstant 8 (Integer 4 [])) (Integer 4 [])) ()) (= (Var 2 c) (IfExp (Compare (Var 2 b) Gt (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) () ()) (LogicalConstant .true. (Logical 4 [])) (LogicalConstant .false. (Logical 4 [])) (Logical 4 [])) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_ifexp: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Integer 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Logical 4 []) Source Public Required .false.)}) test_ifexp [] [(= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (IfExp (IntegerCompare (Var 2 a) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) (IntegerConstant 6 (Integer 4 [])) (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) ()) ()) (= (Var 2 c) (IfExp (IntegerCompare (Var 2 b) Gt (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) ()) (LogicalConstant .true. (Logical 4 [])) (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr7-480ba2f.json b/tests/reference/asr-expr7-480ba2f.json index 53698b4fc1..f97732d094 100644 --- a/tests/reference/asr-expr7-480ba2f.json +++ b/tests/reference/asr-expr7-480ba2f.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr7-480ba2f.stdout", - "stdout_hash": "46baddcc31f19815c2225c526120c9ccae116a233cffa6b21f0ad4d4", + "stdout_hash": "fdadd32c594775efa68e87c6c9c297097800f7d83252c8a667d7acd9", "stderr": "asr-expr7-480ba2f.stderr", "stderr_hash": "28509dd59a386eebd632340a550d14299cd2a921ef6dc3ac7dbe7fe9", "returncode": 0 diff --git a/tests/reference/asr-expr7-480ba2f.stdout b/tests/reference/asr-expr7-480ba2f.stdout index c018c168b1..8dc6b808dd 100644 --- a/tests/reference/asr-expr7-480ba2f.stdout +++ b/tests/reference/asr-expr7-480ba2f.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 99 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main0: (Subroutine (SymbolTable 4 {c: (Variable 4 c Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(SubroutineCall 1 test_pow () [] ()) (= (Var 4 c) (FunctionCall 1 test_pow_1 () [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 98 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), pow@__lpython_overloaded_0__pow: (ExternalSymbol 1 pow@__lpython_overloaded_0__pow 6 __lpython_overloaded_0__pow lpython_builtin [] __lpython_overloaded_0__pow Public), test_pow: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 2 pow 6 pow lpython_builtin [] pow Private)}) test_pow [] [(= (Var 2 a) (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 4 (Integer 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_pow_1: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 3 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 3 b In () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 3 pow 6 pow lpython_builtin [] pow Private), res: (Variable 3 res Local () () Default (Integer 4 []) Source Public Required .false.)}) test_pow_1 [(Var 3 a) (Var 3 b)] [(= (Var 3 res) (FunctionCall 1 pow@__lpython_overloaded_0__pow 3 pow [((Var 3 a)) ((Var 3 b))] (Integer 4 []) () ()) ()) (= (Var 3 _lpython_return_variable) (Var 3 res) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ())}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 82 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main0: (Subroutine (SymbolTable 4 {c: (Variable 4 c Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(SubroutineCall 1 test_pow () [] ()) (= (Var 4 c) (FunctionCall 1 test_pow_1 () [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 81 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), pow@__lpython_overloaded_0__pow: (ExternalSymbol 1 pow@__lpython_overloaded_0__pow 6 __lpython_overloaded_0__pow lpython_builtin [] __lpython_overloaded_0__pow Public), test_pow: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 2 pow 6 pow lpython_builtin [] pow Private)}) test_pow [] [(= (Var 2 a) (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 4 (Integer 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_pow_1: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 3 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 3 b In () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 3 pow 6 pow lpython_builtin [] pow Private), res: (Variable 3 res Local () () Default (Integer 4 []) Source Public Required .false.)}) test_pow_1 [(Var 3 a) (Var 3 b)] [(= (Var 3 res) (FunctionCall 1 pow@__lpython_overloaded_0__pow 3 pow [((Var 3 a)) ((Var 3 b))] (Integer 4 []) () ()) ()) (= (Var 3 _lpython_return_variable) (Var 3 res) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ())}) []) diff --git a/tests/reference/asr-expr8-6beda60.json b/tests/reference/asr-expr8-6beda60.json index c62280e30c..c9d41791a5 100644 --- a/tests/reference/asr-expr8-6beda60.json +++ b/tests/reference/asr-expr8-6beda60.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr8-6beda60.stdout", - "stdout_hash": "c23885bae30f094055904951dc997d2b0b4cc46bc20050cea9027ddd", + "stdout_hash": "9b1a017e7fb97e3f722ef2789951971f6870775a12fd2247cf755f74", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr8-6beda60.stdout b/tests/reference/asr-expr8-6beda60.stdout index f2bc99b616..7a64613193 100644 --- a/tests/reference/asr-expr8-6beda60.stdout +++ b/tests/reference/asr-expr8-6beda60.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_floordiv@__lpython_overloaded_2___lpython_floordiv: (ExternalSymbol 1 _lpython_floordiv@__lpython_overloaded_2___lpython_floordiv 4 __lpython_overloaded_2___lpython_floordiv lpython_builtin [] __lpython_overloaded_2___lpython_floordiv Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] []), test_binop: (Subroutine (SymbolTable 2 {_lpython_floordiv: (ExternalSymbol 2 _lpython_floordiv 4 _lpython_floordiv lpython_builtin [] _lpython_floordiv Private), b1: (Variable 2 b1 Local () () Default (Logical 4 []) Source Public Required .false.), b2: (Variable 2 b2 Local () () Default (Logical 4 []) Source Public Required .false.), x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), x2: (Variable 2 x2 Local () () Default (Real 4 []) Source Public Required .false.)}) test_binop [] [(= (Var 2 x) (BinOp (IntegerConstant 2 (Integer 4 [])) Pow (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant 8 (Integer 4 [])) ()) ()) (= (Var 2 x2) (Cast (BinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToReal (Real 8 []) ()) Pow (RealConstant 3.500000 (Real 8 [])) (Real 8 []) () ()) RealToReal (Real 4 []) ()) ()) (= (Var 2 x) (BinOp (IntegerConstant 54 (Integer 4 [])) Sub (IntegerConstant 100 (Integer 4 [])) (Integer 4 []) (IntegerConstant -46 (Integer 4 [])) ()) ()) (= (Var 2 x2) (Cast (BinOp (BinOp (RealConstant 3.454000 (Real 8 [])) Sub (RealConstant 765.430000 (Real 8 [])) (Real 8 []) (RealConstant -761.976000 (Real 8 [])) ()) Add (RealConstant 534.600000 (Real 8 [])) (Real 8 []) (RealConstant -227.376000 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant -227.376000 (Real 4 []))) ()) (= (Var 2 x2) (Cast (BinOp (RealConstant 5346.565000 (Real 8 [])) Mul (RealConstant 3.450000 (Real 8 [])) (Real 8 []) (RealConstant 18445.649250 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant 18445.649250 (Real 4 []))) ()) (= (Var 2 x2) (Cast (BinOp (RealConstant 5346.565000 (Real 8 [])) Pow (RealConstant 3.450000 (Real 8 [])) (Real 8 []) (RealConstant 7275422789925.217773 (Real 8 [])) ()) RealToReal (Real 4 []) (RealConstant 7275422789925.217773 (Real 4 []))) ()) (= (Var 2 x) (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (= (Var 2 x) (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (= (Var 2 x) (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Mul (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (= (Var 2 x) (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Pow (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (= (Var 2 b1) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 b2) (LogicalConstant .false. (Logical 4 [])) ()) (= (Var 2 x) (FunctionCall 1 _lpython_floordiv@__lpython_overloaded_2___lpython_floordiv 2 _lpython_floordiv [((Cast (Var 2 b1) LogicalToInteger (Integer 4 []) ())) ((Cast (Var 2 b1) LogicalToInteger (Integer 4 []) ()))] (Integer 4 []) () ()) ()) (= (Var 2 x) (BinOp (Cast (Var 2 b1) LogicalToInteger (Integer 4 []) ()) Pow (Cast (Var 2 b2) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_floordiv@__lpython_overloaded_2___lpython_floordiv: (ExternalSymbol 1 _lpython_floordiv@__lpython_overloaded_2___lpython_floordiv 4 __lpython_overloaded_2___lpython_floordiv lpython_builtin [] __lpython_overloaded_2___lpython_floordiv Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] []), test_binop: (Subroutine (SymbolTable 2 {_lpython_floordiv: (ExternalSymbol 2 _lpython_floordiv 4 _lpython_floordiv lpython_builtin [] _lpython_floordiv Private), b1: (Variable 2 b1 Local () () Default (Logical 4 []) Source Public Required .false.), b2: (Variable 2 b2 Local () () Default (Logical 4 []) Source Public Required .false.), x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), x2: (Variable 2 x2 Local () () Default (Real 4 []) Source Public Required .false.)}) test_binop [] [(= (Var 2 x) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Pow (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant 8 (Integer 4 []))) ()) (= (Var 2 x2) (Cast (RealBinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToReal (Real 8 []) ()) Pow (RealConstant 3.50000000000000000e+00 (Real 8 [])) (Real 8 []) ()) RealToReal (Real 4 []) ()) ()) (= (Var 2 x) (IntegerBinOp (IntegerConstant 54 (Integer 4 [])) Sub (IntegerConstant 100 (Integer 4 [])) (Integer 4 []) (IntegerConstant -46 (Integer 4 []))) ()) (= (Var 2 x2) (Cast (RealBinOp (RealBinOp (RealConstant 3.45400000000000018e+00 (Real 8 [])) Sub (RealConstant 7.65429999999999950e+02 (Real 8 [])) (Real 8 []) (RealConstant -7.61975999999999999e+02 (Real 8 []))) Add (RealConstant 5.34600000000000023e+02 (Real 8 [])) (Real 8 []) (RealConstant -2.27375999999999976e+02 (Real 8 []))) RealToReal (Real 4 []) (RealConstant -2.27375999999999976e+02 (Real 4 []))) ()) (= (Var 2 x2) (Cast (RealBinOp (RealConstant 5.34656499999999960e+03 (Real 8 [])) Mul (RealConstant 3.45000000000000018e+00 (Real 8 [])) (Real 8 []) (RealConstant 1.84456492499999986e+04 (Real 8 []))) RealToReal (Real 4 []) (RealConstant 1.84456492499999986e+04 (Real 4 []))) ()) (= (Var 2 x2) (Cast (RealBinOp (RealConstant 5.34656499999999960e+03 (Real 8 [])) Pow (RealConstant 3.45000000000000018e+00 (Real 8 [])) (Real 8 []) (RealConstant 7.27542278992521777e+12 (Real 8 []))) RealToReal (Real 4 []) (RealConstant 7.27542278992521777e+12 (Real 4 []))) ()) (= (Var 2 x) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (= (Var 2 x) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (= (Var 2 x) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Mul (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (= (Var 2 x) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Pow (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (= (Var 2 b1) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 b2) (LogicalConstant .false. (Logical 4 [])) ()) (= (Var 2 x) (FunctionCall 1 _lpython_floordiv@__lpython_overloaded_2___lpython_floordiv 2 _lpython_floordiv [((Cast (Var 2 b1) LogicalToInteger (Integer 4 []) ())) ((Cast (Var 2 b1) LogicalToInteger (Integer 4 []) ()))] (Integer 4 []) () ()) ()) (= (Var 2 x) (IntegerBinOp (Cast (Var 2 b1) LogicalToInteger (Integer 4 []) ()) Pow (Cast (Var 2 b2) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr_01-211000e.json b/tests/reference/asr-expr_01-211000e.json index fd3468472d..b8023aca14 100644 --- a/tests/reference/asr-expr_01-211000e.json +++ b/tests/reference/asr-expr_01-211000e.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-expr_01-211000e.stdout", - "stdout_hash": "b594d58fc246aff7fb6e0893b7590f3205eea3525df5f32dbb81e29e", + "stdout_hash": "b0fb7135e427222df4813fabb1c1e33436c475342821d553ec0e13c7", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-expr_01-211000e.stdout b/tests/reference/asr-expr_01-211000e.stdout index 420bbe3966..19dc294929 100644 --- a/tests/reference/asr-expr_01-211000e.stdout +++ b/tests/reference/asr-expr_01-211000e.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 2 {x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), x2: (Variable 2 x2 Local () () Default (Integer 8 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 4 []) Source Public Required .false.), y2: (Variable 2 y2 Local () () Default (Real 8 []) Source Public Required .false.)}) main0 [] [(= (Var 2 x) (BinOp (BinOp (IntegerConstant 2 (Integer 4 [])) Add (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant 5 (Integer 4 [])) ()) Mul (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant 25 (Integer 4 [])) ()) ()) (Print () [(Var 2 x)])] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 2 {x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), x2: (Variable 2 x2 Local () () Default (Integer 8 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 4 []) Source Public Required .false.), y2: (Variable 2 y2 Local () () Default (Real 8 []) Source Public Required .false.)}) main0 [] [(= (Var 2 x) (IntegerBinOp (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Add (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant 5 (Integer 4 []))) Mul (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant 25 (Integer 4 []))) ()) (Print () [(Var 2 x)] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-expr_05-3a37324.json b/tests/reference/asr-expr_05-3a37324.json new file mode 100644 index 0000000000..b825664046 --- /dev/null +++ b/tests/reference/asr-expr_05-3a37324.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-expr_05-3a37324", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/expr_05.py", + "infile_hash": "ea9ac6984490195f1c6e1213faf8547b8b4c30a55af648ab3feb54d1", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-expr_05-3a37324.stdout", + "stdout_hash": "fd75979aead88e26485c4d2e0b7a376948883a1c07ae965d7dba8b39", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-expr_05-3a37324.stdout b/tests/reference/asr-expr_05-3a37324.stdout new file mode 100644 index 0000000000..94ca999e79 --- /dev/null +++ b/tests/reference/asr-expr_05-3a37324.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 82 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), _mod@__lpython_overloaded_0___mod: (ExternalSymbol 1 _mod@__lpython_overloaded_0___mod 6 __lpython_overloaded_0___mod lpython_builtin [] __lpython_overloaded_0___mod Public), lpython_builtin: (IntrinsicModule lpython_builtin), main0: (Subroutine (SymbolTable 4 {_mod: (ExternalSymbol 4 _mod 6 _mod lpython_builtin [] _mod Private), a: (Variable 4 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 4 b Local () () Default (Integer 4 []) Source Public Required .false.), i: (Variable 4 i Local () () Default (Integer 8 []) Source Public Required .false.), i1: (Variable 4 i1 Local () () Default (Integer 4 []) Source Public Required .false.), i2: (Variable 4 i2 Local () () Default (Integer 4 []) Source Public Required .false.), i3: (Variable 4 i3 Local () () Default (Integer 4 []) Source Public Required .false.), i4: (Variable 4 i4 Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(= (Var 4 a) (IntegerConstant 10 (Integer 4 [])) ()) (= (Var 4 b) (IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 test_multiply () [((Var 4 a)) ((Var 4 b))] (Integer 4 []) () ()) Eq (IntegerUnaryMinus (IntegerConstant 50 (Integer 4 [])) (Integer 4 []) (IntegerConstant -50 (Integer 4 []))) (Logical 4 []) ()) ()) (= (Var 4 i) (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 4 i) (IntegerBinOp (Var 4 i) Add (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) ()) ()) (Assert (IntegerCompare (Var 4 i) Eq (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) ()) (= (Var 4 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 4 b) (IntegerConstant 5 (Integer 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 test_mod () [((Var 4 a)) ((Var 4 b))] (Integer 4 []) () ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 test_mod () [((IntegerConstant 23 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Integer 4 []) () ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 4 a) (IntegerConstant 123282374 (Integer 4 [])) ()) (= (Var 4 b) (IntegerConstant 32771 (Integer 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 test_mod () [((Var 4 a)) ((Var 4 b))] (Integer 4 []) () ()) Eq (IntegerConstant 30643 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 4 a) (IntegerUnaryMinus (IntegerConstant 5345 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5345 (Integer 4 []))) ()) (= (Var 4 b) (IntegerUnaryMinus (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 _mod@__lpython_overloaded_0___mod 4 _mod [((Var 4 a)) ((Var 4 b))] (Integer 4 []) () ()) Eq (IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) (Logical 4 []) ()) ()) (= (Var 4 a) (IntegerUnaryMinus (IntegerConstant 123282374 (Integer 4 [])) (Integer 4 []) (IntegerConstant -123282374 (Integer 4 []))) ()) (= (Var 4 b) (IntegerConstant 32771 (Integer 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 test_mod () [((Var 4 a)) ((Var 4 b))] (Integer 4 []) () ()) Eq (IntegerConstant 2128 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) BitOr (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant 14 (Integer 4 []))) Eq (IntegerConstant 14 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerUnaryMinus (IntegerConstant 105346 (Integer 4 [])) (Integer 4 []) (IntegerConstant -105346 (Integer 4 []))) BitOr (IntegerUnaryMinus (IntegerConstant 32771 (Integer 4 [])) (Integer 4 []) (IntegerConstant -32771 (Integer 4 []))) (Integer 4 []) (IntegerConstant -32769 (Integer 4 []))) Eq (IntegerUnaryMinus (IntegerConstant 32769 (Integer 4 [])) (Integer 4 []) (IntegerConstant -32769 (Integer 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) BitAnd (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerUnaryMinus (IntegerConstant 105346 (Integer 4 [])) (Integer 4 []) (IntegerConstant -105346 (Integer 4 []))) BitAnd (IntegerUnaryMinus (IntegerConstant 32771 (Integer 4 [])) (Integer 4 []) (IntegerConstant -32771 (Integer 4 []))) (Integer 4 []) (IntegerConstant -105348 (Integer 4 []))) Eq (IntegerUnaryMinus (IntegerConstant 105348 (Integer 4 [])) (Integer 4 []) (IntegerConstant -105348 (Integer 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) BitXor (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant 14 (Integer 4 []))) Eq (IntegerConstant 14 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerUnaryMinus (IntegerConstant 105346 (Integer 4 [])) (Integer 4 []) (IntegerConstant -105346 (Integer 4 []))) BitXor (IntegerUnaryMinus (IntegerConstant 32771 (Integer 4 [])) (Integer 4 []) (IntegerConstant -32771 (Integer 4 []))) (Integer 4 []) (IntegerConstant 72579 (Integer 4 []))) Eq (IntegerConstant 72579 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) BitRShift (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 5 (Integer 4 []))) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerConstant 5 (Integer 4 [])) BitLShift (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 10 (Integer 4 []))) Eq (IntegerConstant 10 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 4 i1) (IntegerConstant 10 (Integer 4 [])) ()) (= (Var 4 i2) (IntegerConstant 4 (Integer 4 [])) ()) (Assert (IntegerCompare (IntegerBinOp (Var 4 i1) BitLShift (Var 4 i2) (Integer 4 []) ()) Eq (IntegerConstant 160 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (Var 4 i1) BitRShift (Var 4 i2) (Integer 4 []) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (Var 4 i1) BitAnd (Var 4 i2) (Integer 4 []) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (Var 4 i1) BitOr (Var 4 i2) (Integer 4 []) ()) Eq (IntegerConstant 14 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (Var 4 i1) BitXor (Var 4 i2) (Integer 4 []) ()) Eq (IntegerConstant 14 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerUnaryMinus (Var 4 i1) (Integer 4 []) ()) BitXor (IntegerUnaryMinus (Var 4 i2) (Integer 4 []) ()) (Integer 4 []) ()) Eq (IntegerConstant 10 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 4 i3) (IntegerConstant 432534534 (Integer 4 [])) ()) (= (Var 4 i4) (IntegerUnaryMinus (IntegerConstant 4325 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4325 (Integer 4 []))) ()) (Assert (IntegerCompare (IntegerBinOp (Var 4 i3) BitOr (Var 4 i4) (Integer 4 []) ()) Eq (IntegerUnaryMinus (IntegerConstant 225 (Integer 4 [])) (Integer 4 []) (IntegerConstant -225 (Integer 4 []))) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (Var 4 i4) BitRShift (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) ()) Eq (IntegerUnaryMinus (IntegerConstant 541 (Integer 4 [])) (Integer 4 []) (IntegerConstant -541 (Integer 4 []))) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerUnaryMinus (Var 4 i3) (Integer 4 []) ()) BitAnd (Var 4 i4) (Integer 4 []) ()) Eq (IntegerUnaryMinus (IntegerConstant 432534758 (Integer 4 [])) (Integer 4 []) (IntegerConstant -432534758 (Integer 4 []))) (Logical 4 []) ()) ()) (Assert (IntegerCompare (IntegerBinOp (IntegerUnaryMinus (Var 4 i3) (Integer 4 []) ()) BitXor (Var 4 i4) (Integer 4 []) ()) Eq (IntegerConstant 432530657 (Integer 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 81 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_mod: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), _mod: (ExternalSymbol 3 _mod 6 _mod lpython_builtin [] _mod Private), a: (Variable 3 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 3 b In () () Default (Integer 4 []) Source Public Required .false.)}) test_mod [(Var 3 a) (Var 3 b)] [(= (Var 3 _lpython_return_variable) (FunctionCall 1 _mod@__lpython_overloaded_0___mod 3 _mod [((Var 3 a)) ((Var 3 b))] (Integer 4 []) () ()) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ()), test_multiply: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 2 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b In () () Default (Integer 4 []) Source Public Required .false.)}) test_multiply [(Var 2 a) (Var 2 b)] [(= (Var 2 _lpython_return_variable) (IntegerBinOp (Var 2 a) Mul (Var 2 b) (Integer 4 []) ()) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ())}) []) diff --git a/tests/reference/asr-expr_07-7742668.json b/tests/reference/asr-expr_07-7742668.json new file mode 100644 index 0000000000..1236187ac3 --- /dev/null +++ b/tests/reference/asr-expr_07-7742668.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-expr_07-7742668", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/expr_07.py", + "infile_hash": "93d7dc8e33e95441ae207ead74fd68fbd1f7070211a51d857a449230", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-expr_07-7742668.stdout", + "stdout_hash": "53516de851c4119c95e2fc29c1eb7af88ed31609219c54dd26b759c2", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-expr_07-7742668.stdout b/tests/reference/asr-expr_07-7742668.stdout new file mode 100644 index 0000000000..db6b3d6d99 --- /dev/null +++ b/tests/reference/asr-expr_07-7742668.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 5 {}) _lpython_main_program [] [(SubroutineCall 1 f () [] ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 3 {a: (Variable 3 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 3 b Local () () Default (Integer 4 []) Source Public Required .false.), x: (Variable 3 x Local () () Default (Integer 4 []) Source Public Required .false.)}) f [] [(= (Var 3 a) (IntegerConstant 5 (Integer 4 [])) ()) (= (Var 3 x) (IntegerConstant 3 (Integer 4 [])) ()) (= (Var 3 x) (IntegerConstant 5 (Integer 4 [])) ()) (= (Var 3 b) (IntegerBinOp (Var 3 x) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) ()) ()) (Print () [(Var 3 a) (Var 3 b)] () ()) (SubroutineCall 1 g () [((IntegerBinOp (IntegerBinOp (Var 3 a) Mul (Var 3 b) (Integer 4 []) ()) Add (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) ()))] ())] Source Public Implementation () .false. .false.), g: (Subroutine (SymbolTable 2 {x: (Variable 2 x In () () Default (Integer 4 []) Source Public Required .false.)}) g [(Var 2 x)] [(Print () [(Var 2 x)] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 4 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), x: (Variable 1 x Local (IntegerConstant 7 (Integer 4 [])) () Default (Integer 4 []) Source Public Required .false.)}) []) diff --git a/tests/reference/asr-expr_09-f3e89c8.json b/tests/reference/asr-expr_09-f3e89c8.json new file mode 100644 index 0000000000..ddc98c3b94 --- /dev/null +++ b/tests/reference/asr-expr_09-f3e89c8.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-expr_09-f3e89c8", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/expr_09.py", + "infile_hash": "7a3cdb6538c8d2d8e4555683aeac4f9b074be2fcaa6fe4532c01bf1a", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-expr_09-f3e89c8.stdout", + "stdout_hash": "5da4a3546bf415881f8037e03874dd50aeff9e675176309489e3a9c2", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-expr_09-f3e89c8.stdout b/tests/reference/asr-expr_09-f3e89c8.stdout new file mode 100644 index 0000000000..a5eaaa8972 --- /dev/null +++ b/tests/reference/asr-expr_09-f3e89c8.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 2 {i1: (Variable 2 i1 Local () () Default (Integer 4 []) Source Public Required .false.), i2: (Variable 2 i2 Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(= (Var 2 i1) (IntegerConstant 10 (Integer 4 [])) ()) (= (Var 2 i2) (IntegerConstant 4 (Integer 4 [])) ()) (= (Var 2 i1) (IntegerConstant 3 (Integer 4 [])) ()) (= (Var 2 i2) (IntegerConstant 5 (Integer 4 [])) ()) (Print () [(IntegerBinOp (IntegerUnaryMinus (Var 2 i1) (Integer 4 []) ()) BitXor (IntegerUnaryMinus (Var 2 i2) (Integer 4 []) ()) (Integer 4 []) ())] () ()) (Assert (IntegerCompare (IntegerBinOp (IntegerUnaryMinus (Var 2 i1) (Integer 4 []) ()) BitXor (IntegerUnaryMinus (Var 2 i2) (Integer 4 []) ()) (Integer 4 []) ()) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-expr_10-d39708c.json b/tests/reference/asr-expr_10-d39708c.json new file mode 100644 index 0000000000..a25cf9dc07 --- /dev/null +++ b/tests/reference/asr-expr_10-d39708c.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-expr_10-d39708c", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/expr_10.py", + "infile_hash": "00aac96059a6e3d6615e357e73cd79b96646d200ef89978251c8ef5a", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-expr_10-d39708c.stdout", + "stdout_hash": "cd67a5c57c6282376469188abdeb71c9e0b375eb066ce0378f42b762", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-expr_10-d39708c.stdout b/tests/reference/asr-expr_10-d39708c.stdout new file mode 100644 index 0000000000..44d8c088eb --- /dev/null +++ b/tests/reference/asr-expr_10-d39708c.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 6 {}) _lpython_main_program [] [(SubroutineCall 1 test_fn1 () [] ())] Source Public Implementation () .false. .false.), g: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.)}) g [] [(= (Var 2 _lpython_return_variable) (IntegerConstant 5 (Integer 4 [])) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ()), gsubrout: (Subroutine (SymbolTable 3 {x: (Variable 3 x In () () Default (Integer 4 []) Source Public Required .false.)}) gsubrout [(Var 3 x)] [(Print () [(Var 3 x)] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 5 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_fn1: (Subroutine (SymbolTable 4 {__lcompilers_dummy: (Variable 4 __lcompilers_dummy Local () () Default (Integer 4 []) Source Public Required .false.), i: (Variable 4 i Local () () Default (Integer 4 []) Source Public Required .false.), j: (Variable 4 j Local () () Default (Integer 4 []) Source Public Required .false.)}) test_fn1 [] [(= (Var 4 i) (FunctionCall 1 g () [] (Integer 4 []) () ()) ()) (= (Var 4 j) (FunctionCall 1 g () [] (Integer 4 []) () ()) ()) (= (Var 4 __lcompilers_dummy) (FunctionCall 1 g () [] (Integer 4 []) () ()) ()) (SubroutineCall 1 gsubrout () [((Var 4 i))] ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-expr_12-6769be0.json b/tests/reference/asr-expr_12-6769be0.json new file mode 100644 index 0000000000..48def7a6ba --- /dev/null +++ b/tests/reference/asr-expr_12-6769be0.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-expr_12-6769be0", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/expr_12.py", + "infile_hash": "c8e08b659b74d9bff57f8a831a38421996e9e015cce2cf20e40e3e2e", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-expr_12-6769be0.stdout", + "stdout_hash": "cb69cc7b6ac51be7a2863d057660ab2647b1c79519a3966534abee73", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-expr_12-6769be0.stdout b/tests/reference/asr-expr_12-6769be0.stdout new file mode 100644 index 0000000000..153b2ef22d --- /dev/null +++ b/tests/reference/asr-expr_12-6769be0.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 6 {}) _lpython_main_program [] [(SubroutineCall 1 f () [] ())] Source Public Implementation () .false. .false.), check: (Subroutine (SymbolTable 3 {ptr: (Variable 3 ptr InOut () () Default (Pointer (Integer 2 [(() ())])) Source Public Required .false.)}) check [(Var 3 ptr)] [(Assert (IntegerCompare (Cast (ArrayItem (Var 3 ptr) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Pointer (Integer 2 [])) ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (Cast (ArrayItem (Var 3 ptr) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Pointer (Integer 2 [])) ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 4 {y: (Variable 4 y Local () () Default (Integer 2 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))]) Source Public Required .false.), yptr1: (Variable 4 yptr1 Local () () Default (Pointer (Integer 2 [(() ())])) Source Public Required .false.)}) f [] [(SubroutineCall 1 g () [((Var 4 yptr1)) ((Var 4 y))] ()) (SubroutineCall 1 check () [((Var 4 yptr1))] ())] Source Public Implementation () .false. .false.), g: (Subroutine (SymbolTable 2 {x: (Variable 2 x InOut () () Default (Pointer (Integer 2 [(() ())])) Source Public Required .false.), y: (Variable 2 y InOut () () Default (Integer 2 [(() ())]) Source Public Required .false.)}) g [(Var 2 x) (Var 2 y)] [(= (ArrayItem (Var 2 y) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 2 []) ()) (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 2 []) ()) ()) (= (ArrayItem (Var 2 y) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Integer 2 []) ()) (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 2 []) ()) ()) (= (Var 2 x) (GetPointer (Var 2 y) (Pointer (Integer 2 [(() ())])) ()) ()) (Print () [(ArrayItem (Var 2 x) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Pointer (Integer 2 [])) ()) (ArrayItem (Var 2 x) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Pointer (Integer 2 [])) ())] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 5 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-func_inline_01-56af272.json b/tests/reference/asr-func_inline_01-56af272.json new file mode 100644 index 0000000000..b1d1486b21 --- /dev/null +++ b/tests/reference/asr-func_inline_01-56af272.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-func_inline_01-56af272", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/func_inline_01.py", + "infile_hash": "6875179ba40c59c22fc55606261bf2c84290b50932f956c1d8152502", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-func_inline_01-56af272.stdout", + "stdout_hash": "6730f3a9635b6ae0033ad841fada3dfce1e420992722a5ef6c77af1c", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-func_inline_01-56af272.stdout b/tests/reference/asr-func_inline_01-56af272.stdout new file mode 100644 index 0000000000..2ad334e6de --- /dev/null +++ b/tests/reference/asr-func_inline_01-56af272.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 5 {}) _lpython_main_program [] [(SubroutineCall 1 main () [] ())] Source Public Implementation () .false. .false.), fib: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 8 []) Source Public Required .false.), n: (Variable 2 n In () () Default (Integer 8 []) Source Public Required .false.)}) fib [(Var 2 n)] [(If (IntegerCompare (Var 2 n) Lt (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) [(= (Var 2 _lpython_return_variable) (Var 2 n) ()) (Return)] []) (= (Var 2 _lpython_return_variable) (IntegerBinOp (FunctionCall 1 fib () [((IntegerBinOp (Var 2 n) Sub (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) ()))] (Integer 8 []) () ()) Add (FunctionCall 1 fib () [((IntegerBinOp (Var 2 n) Sub (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) ()))] (Integer 8 []) () ()) (Integer 8 []) ()) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ()), main: (Subroutine (SymbolTable 3 {ans: (Variable 3 ans Local () () Default (Integer 8 []) Source Public Required .false.), x: (Variable 3 x Local () () Default (Integer 8 []) Source Public Required .false.)}) main [] [(= (Var 3 x) (Cast (IntegerConstant 40 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 3 ans) (FunctionCall 1 fib () [((Var 3 x))] (Integer 8 []) () ()) ()) (Print () [(Var 3 ans)] () ()) (Assert (IntegerCompare (Var 3 ans) Eq (Cast (IntegerConstant 102334155 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 4 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-list1-770ba33.json b/tests/reference/asr-list1-770ba33.json index cf1cfc6b61..90e6450774 100644 --- a/tests/reference/asr-list1-770ba33.json +++ b/tests/reference/asr-list1-770ba33.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-list1-770ba33.stdout", - "stdout_hash": "3a53136106feb6476a27306081fc3b5aaa8589387775c55848aea08c", + "stdout_hash": "03552df04eb533e4782b5d12fe74235d5b9f6e6f8a1cabe402f17f7e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-list1-770ba33.stdout b/tests/reference/asr-list1-770ba33.stdout index 3bbd02b496..f60c93db73 100644 --- a/tests/reference/asr-list1-770ba33.stdout +++ b/tests/reference/asr-list1-770ba33.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_List: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (List (Integer 4 [])) Source Public Required .false.), b: (Variable 2 b Local () () Default (List (Character 1 -2 () [])) Source Public Required .false.), c: (Variable 2 c Local () () Default (List (List (Integer 4 []))) Source Public Required .false.), d: (Variable 2 d Local () () Default (Integer 4 []) Source Public Required .false.), e: (Variable 2 e Local () () Default (List (List (Character 1 -2 () []))) Source Public Required .false.)}) test_List [] [(= (Var 2 a) (ListConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (List (Integer 4 []))) ()) (= (Var 2 a) (ListConstant [(UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 [])))] (List (Integer 4 []))) ()) (= (Var 2 b) (ListConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (List (Character 1 1 () []))) ()) (= (Var 2 c) (ListConstant [(ListConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (List (Integer 4 []))) (ListConstant [(IntegerConstant 4 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])) (IntegerConstant 6 (Integer 4 []))] (List (Integer 4 [])))] (List (List (Integer 4 [])))) ()) (= (Var 2 d) (ListItem 2 a (BinOp (IntegerConstant 2 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Integer 4 []) ()) ()) (= (Var 2 e) (ListConstant [(ListConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (List (Character 1 1 () []))) (ListConstant [(StringConstant "d" (Character 1 1 () [])) (StringConstant "e" (Character 1 1 () []))] (List (Character 1 1 () [])))] (List (List (Character 1 1 () [])))) ()) (ListAppend 2 a (IntegerConstant 10 (Integer 4 []))) (ListRemove 2 a (IntegerConstant 1 (Integer 4 []))) (ListInsert 2 a (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 13 (Integer 4 []))) (= (Var 2 a) (ListSection (Var 2 a) ((BinOp (IntegerConstant 0 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 2 (Integer 4 [])) ()) (List (Integer 4 [])) ()) ()) (= (Var 2 d) (ListPop 2 a (IntegerConstant -1 (Integer 4 [])) (Integer 4 []) ()) ()) (= (Var 2 d) (ListPop 2 a (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) ()) ()) (= (Var 2 a) (ListConcat (Var 2 a) (ListConstant [(IntegerConstant 4 (Integer 4 [])) (IntegerConstant 5 (Integer 4 []))] (List (Integer 4 []))) (List (Integer 4 [])) ()) ()) (= (Var 2 a) (ListConcat (ListConstant [(IntegerConstant 6 (Integer 4 [])) (IntegerConstant 7 (Integer 4 []))] (List (Integer 4 []))) (Var 2 a) (List (Integer 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_List: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (List (Integer 4 [])) Source Public Required .false.), b: (Variable 2 b Local () () Default (List (Character 1 -2 () [])) Source Public Required .false.), c: (Variable 2 c Local () () Default (List (List (Integer 4 []))) Source Public Required .false.), d: (Variable 2 d Local () () Default (Integer 4 []) Source Public Required .false.), e: (Variable 2 e Local () () Default (List (List (Character 1 -2 () []))) Source Public Required .false.)}) test_List [] [(= (Var 2 a) (ListConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (List (Integer 4 []))) ()) (= (Var 2 a) (ListConstant [(IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 [])))] (List (Integer 4 []))) ()) (= (Var 2 b) (ListConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (List (Character 1 1 () []))) ()) (= (Var 2 c) (ListConstant [(ListConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (List (Integer 4 []))) (ListConstant [(IntegerConstant 4 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])) (IntegerConstant 6 (Integer 4 []))] (List (Integer 4 [])))] (List (List (Integer 4 [])))) ()) (= (Var 2 d) (ListItem (Var 2 a) (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) ()) ()) (= (Var 2 e) (ListConstant [(ListConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (List (Character 1 1 () []))) (ListConstant [(StringConstant "d" (Character 1 1 () [])) (StringConstant "e" (Character 1 1 () []))] (List (Character 1 1 () [])))] (List (List (Character 1 1 () [])))) ()) (ListAppend (Var 2 a) (IntegerConstant 10 (Integer 4 []))) (ListRemove (Var 2 a) (IntegerConstant 1 (Integer 4 []))) (ListInsert (Var 2 a) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 13 (Integer 4 []))) (= (Var 2 a) (ListSection (Var 2 a) ((IntegerConstant 0 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) ()) (List (Integer 4 [])) ()) ()) (= (Var 2 d) (ListPop (Var 2 a) (IntegerConstant -1 (Integer 4 [])) (Integer 4 []) ()) ()) (= (Var 2 d) (ListPop (Var 2 a) (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) ()) ()) (= (Var 2 a) (ListConcat (Var 2 a) (ListConstant [(IntegerConstant 4 (Integer 4 [])) (IntegerConstant 5 (Integer 4 []))] (List (Integer 4 []))) (List (Integer 4 [])) ()) ()) (= (Var 2 a) (ListConcat (ListConstant [(IntegerConstant 6 (Integer 4 [])) (IntegerConstant 7 (Integer 4 []))] (List (Integer 4 []))) (Var 2 a) (List (Integer 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-loop1-10d3109.json b/tests/reference/asr-loop1-10d3109.json index bba8d1ea0c..60d40dbe36 100644 --- a/tests/reference/asr-loop1-10d3109.json +++ b/tests/reference/asr-loop1-10d3109.json @@ -2,11 +2,11 @@ "basename": "asr-loop1-10d3109", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/loop1.py", - "infile_hash": "e50c7161122d599991fafb072d5db8fe7e54d017d56a5c1951a210ca", + "infile_hash": "c6799c859004650fdb3abca560c74e978e8f0d22d9f1e3466a074017", "outfile": null, "outfile_hash": null, "stdout": "asr-loop1-10d3109.stdout", - "stdout_hash": "5d36cb7c4513f77c3490bbc704a8a965aba5caca2d0ab82c35f52c3b", + "stdout_hash": "018b5f51d000937d2c27ca0b64b8e31d4e32b54981a72761b88079f5", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-loop1-10d3109.stdout b/tests/reference/asr-loop1-10d3109.stdout index a36fb3e5c1..93d61e1052 100644 --- a/tests/reference/asr-loop1-10d3109.stdout +++ b/tests/reference/asr-loop1-10d3109.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 7 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 5 {i: (Variable 5 i Local () () Default (Integer 4 []) Source Public Required .false.), j: (Variable 5 j Local () () Default (Integer 8 []) Source Public Required .false.)}) main0 [] [(= (Var 5 i) (FunctionCall 1 test_factorial_1 () [((IntegerConstant 4 (Integer 4 [])))] (Integer 4 []) () ()) ()) (= (Var 5 i) (FunctionCall 1 test_factorial_2 () [((IntegerConstant 4 (Integer 4 [])))] (Integer 4 []) () ()) ()) (= (Var 5 j) (FunctionCall 1 test_factorial_3 () [((IntegerConstant 5 (Integer 4 [])))] (Integer 8 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 6 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_factorial_1: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), result: (Variable 2 result Local () () Default (Integer 4 []) Source Public Required .false.), x: (Variable 2 x In () () Default (Integer 4 []) Source Public Required .false.)}) test_factorial_1 [(Var 2 x)] [(If (Compare (Var 2 x) Lt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) [(= (Var 2 _lpython_return_variable) (IntegerConstant 0 (Integer 4 [])) ()) (Return)] []) (= (Var 2 result) (IntegerConstant 1 (Integer 4 [])) ()) (WhileLoop (Compare (Var 2 x) Gt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) [(= (Var 2 result) (BinOp (Var 2 result) Mul (Var 2 x) (Integer 4 []) () ()) ()) (= (Var 2 x) (BinOp (Var 2 x) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) ())]) (= (Var 2 _lpython_return_variable) (Var 2 result) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ()), test_factorial_2: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), i: (Variable 3 i Local () () Default (Integer 4 []) Source Public Required .false.), result: (Variable 3 result Local () () Default (Integer 4 []) Source Public Required .false.), x: (Variable 3 x In () () Default (Integer 4 []) Source Public Required .false.)}) test_factorial_2 [(Var 3 x)] [(= (Var 3 result) (IntegerConstant 1 (Integer 4 [])) ()) (DoLoop ((Var 3 i) (IntegerConstant 1 (Integer 4 [])) (BinOp (BinOp (Var 3 x) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 1 (Integer 4 []))) [(= (Var 3 result) (BinOp (Var 3 result) Mul (Var 3 i) (Integer 4 []) () ()) ())]) (= (Var 3 _lpython_return_variable) (Var 3 result) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ()), test_factorial_3: (Function (SymbolTable 4 {_lpython_return_variable: (Variable 4 _lpython_return_variable ReturnVar () () Default (Integer 8 []) Source Public Required .false.), result: (Variable 4 result Local () () Default (Integer 8 []) Source Public Required .false.), x: (Variable 4 x In () () Default (Integer 4 []) Source Public Required .false.)}) test_factorial_3 [(Var 4 x)] [(If (Compare (Var 4 x) Lt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) [(= (Var 4 _lpython_return_variable) (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (Return)] []) (= (Var 4 result) (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (WhileLoop (Compare (Var 4 x) Gt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) [(= (Var 4 result) (BinOp (Var 4 result) Mul (Cast (Var 4 x) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) () ()) ()) (= (Var 4 x) (BinOp (Var 4 x) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) ())]) (= (Var 4 _lpython_return_variable) (Var 4 result) ()) (Return)] (Var 4 _lpython_return_variable) Source Public Implementation ())}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 7 {}) _lpython_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), main0: (Subroutine (SymbolTable 5 {i: (Variable 5 i Local () () Default (Integer 4 []) Source Public Required .false.), j: (Variable 5 j Local () () Default (Integer 8 []) Source Public Required .false.)}) main0 [] [(= (Var 5 i) (FunctionCall 1 test_factorial_1 () [((IntegerConstant 4 (Integer 4 [])))] (Integer 4 []) () ()) ()) (= (Var 5 i) (FunctionCall 1 test_factorial_2 () [((IntegerConstant 4 (Integer 4 [])))] (Integer 4 []) () ()) ()) (= (Var 5 j) (FunctionCall 1 test_factorial_3 () [((IntegerConstant 5 (Integer 4 [])))] (Integer 8 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 6 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_factorial_1: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), result: (Variable 2 result Local () () Default (Integer 4 []) Source Public Required .false.), x: (Variable 2 x In () () Default (Integer 4 []) Source Public Required .false.)}) test_factorial_1 [(Var 2 x)] [(If (IntegerCompare (Var 2 x) Lt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) [(= (Var 2 _lpython_return_variable) (IntegerConstant 0 (Integer 4 [])) ()) (Return)] []) (= (Var 2 result) (IntegerConstant 1 (Integer 4 [])) ()) (WhileLoop (IntegerCompare (Var 2 x) Gt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) [(= (Var 2 result) (IntegerBinOp (Var 2 result) Mul (Var 2 x) (Integer 4 []) ()) ()) (= (Var 2 x) (IntegerBinOp (Var 2 x) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) ())]) (= (Var 2 _lpython_return_variable) (Var 2 result) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ()), test_factorial_2: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), i: (Variable 3 i Local () () Default (Integer 4 []) Source Public Required .false.), result: (Variable 3 result Local () () Default (Integer 4 []) Source Public Required .false.), x: (Variable 3 x In () () Default (Integer 4 []) Source Public Required .false.)}) test_factorial_2 [(Var 3 x)] [(= (Var 3 result) (IntegerConstant 1 (Integer 4 [])) ()) (DoLoop ((Var 3 i) (IntegerConstant 1 (Integer 4 [])) (IntegerBinOp (IntegerBinOp (Var 3 x) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 1 (Integer 4 []))) [(= (Var 3 result) (IntegerBinOp (Var 3 result) Mul (Var 3 i) (Integer 4 []) ()) ())]) (= (Var 3 _lpython_return_variable) (Var 3 result) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ()), test_factorial_3: (Function (SymbolTable 4 {_lpython_return_variable: (Variable 4 _lpython_return_variable ReturnVar () () Default (Integer 8 []) Source Public Required .false.), result: (Variable 4 result Local () () Default (Integer 8 []) Source Public Required .false.), x: (Variable 4 x In () () Default (Integer 4 []) Source Public Required .false.)}) test_factorial_3 [(Var 4 x)] [(= (Var 4 result) (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (If (IntegerCompare (Var 4 x) Lt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) [(= (Var 4 _lpython_return_variable) (Var 4 result) ()) (Return)] []) (= (Var 4 result) (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (WhileLoop (IntegerCompare (Var 4 x) Gt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) [(= (Var 4 result) (IntegerBinOp (Var 4 result) Mul (Cast (Var 4 x) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) ()) ()) (= (Var 4 x) (IntegerBinOp (Var 4 x) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) ())]) (= (Var 4 _lpython_return_variable) (Var 4 result) ()) (Return)] (Var 4 _lpython_return_variable) Source Public Implementation ())}) []) diff --git a/tests/reference/asr-loop2-e874469.json b/tests/reference/asr-loop2-e874469.json index 1d1f5f7521..4da8d691ff 100644 --- a/tests/reference/asr-loop2-e874469.json +++ b/tests/reference/asr-loop2-e874469.json @@ -2,11 +2,11 @@ "basename": "asr-loop2-e874469", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/loop2.py", - "infile_hash": "0f1af9370fbae5de0ed9e612e933d7745598fc9c74b036496f4ae8ca", + "infile_hash": "7946c522ceb16f99810780d4aba7fa2593695a4b49fb35ea1f131f53", "outfile": null, "outfile_hash": null, "stdout": "asr-loop2-e874469.stdout", - "stdout_hash": "a979e1c01d3fbd5d3b2fb5904b83e7406eafe66f133fc091ef0c715e", + "stdout_hash": "84af16e2b0f0de7717fda74b8e2102000435cefb3a9554cf7c63d223", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-loop2-e874469.stdout b/tests/reference/asr-loop2-e874469.stdout index 5ea1fb921a..afe52675b0 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. .false.), test_for: (Subroutine (SymbolTable 5 {i: (Variable 5 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_for [] [(DoLoop ((Var 5 i) (IntegerConstant 0 (Integer 4 [])) (BinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 [])) ()) (IntegerConstant 1 (Integer 4 []))) [(If (Compare (Var 5 i) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) [(Cycle)] []) (If (Compare (Var 5 i) Gt (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) () ()) [(Exit)] []) (If (Compare (Var 5 i) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) () ()) [(Stop ())] [])]) (SubroutineCall 1 exit () [((IntegerConstant 0 (Integer 4 [])))] ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 7 {}) _lpython_main_program [] [(SubroutineCall 1 test_for () [] ())] Source Public Implementation () .false. .false.), exit: (ExternalSymbol 1 exit 3 exit sys [] exit Public), main_program: (Program (SymbolTable 6 {}) main_program [] [(SubroutineCall 1 _lpython_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) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 10 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9 (Integer 4 []))) (IntegerConstant 1 (Integer 4 []))) [(If (IntegerCompare (Var 5 i) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) [(Cycle)] []) (If (IntegerCompare (Var 5 i) Gt (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) ()) [(Exit)] []) (If (IntegerCompare (Var 5 i) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) ()) [(Stop ())] [])]) (SubroutineCall 1 exit () [((IntegerConstant 2 (Integer 4 [])))] ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-loop3-a579196.json b/tests/reference/asr-loop3-a579196.json index 8bc5e4b563..26c7893727 100644 --- a/tests/reference/asr-loop3-a579196.json +++ b/tests/reference/asr-loop3-a579196.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-loop3-a579196.stdout", - "stdout_hash": "dd66f0684ea8bf72afc71a43268b5e2a4aecaeeca919587a079d4fe0", + "stdout_hash": "fe0ba2f6ba756f59b61e9a05774f6dec70a0e15d574724f2415fb721", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-loop3-a579196.stdout b/tests/reference/asr-loop3-a579196.stdout index d29d904e24..4d0389d011 100644 --- a/tests/reference/asr-loop3-a579196.stdout +++ b/tests/reference/asr-loop3-a579196.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_pass: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.)}) test_pass [] [(= (Var 2 a) (IntegerConstant 1 (Integer 4 [])) ()) (WhileLoop (Compare (Var 2 a) Gt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) [])] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_pass: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.)}) test_pass [] [(= (Var 2 a) (IntegerConstant 1 (Integer 4 [])) ()) (WhileLoop (IntegerCompare (Var 2 a) Gt (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) [])] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-set1-b7b913a.json b/tests/reference/asr-set1-b7b913a.json index 900a2ccfb7..f103de9725 100644 --- a/tests/reference/asr-set1-b7b913a.json +++ b/tests/reference/asr-set1-b7b913a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-set1-b7b913a.stdout", - "stdout_hash": "07fd8c206e47eff16ad2c2cdd3079b9eede212c10958457c80406356", + "stdout_hash": "9bfaea9792d1016a5146fffcee4278afeae619d8ff531c90622bca23", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-set1-b7b913a.stdout b/tests/reference/asr-set1-b7b913a.stdout index 06cc615bf9..432294d1b2 100644 --- a/tests/reference/asr-set1-b7b913a.stdout +++ b/tests/reference/asr-set1-b7b913a.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_Set: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Set (Integer 4 [])) Source Public Required .false.), b: (Variable 2 b Local () () Default (Set (Character 1 -2 () [])) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_Set [] [(= (Var 2 a) (SetConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Set (Integer 4 []))) ()) (= (Var 2 a) (SetConstant [(IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 [])) (IntegerConstant 4 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])) (IntegerConstant 5 (Integer 4 []))] (Set (Integer 4 []))) ()) (SetInsert 2 a (IntegerConstant 9 (Integer 4 []))) (SetRemove 2 a (IntegerConstant 4 (Integer 4 []))) (= (Var 2 b) (SetConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (Set (Character 1 1 () []))) ()) (= (Var 2 s) (SetPop 2 b (Character 1 -2 () []) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_Set: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Set (Integer 4 [])) Source Public Required .false.), b: (Variable 2 b Local () () Default (Set (Character 1 -2 () [])) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_Set [] [(= (Var 2 a) (SetConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Set (Integer 4 []))) ()) (= (Var 2 a) (SetConstant [(IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 [])) (IntegerConstant 4 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])) (IntegerConstant 5 (Integer 4 []))] (Set (Integer 4 []))) ()) (SetInsert (Var 2 a) (IntegerConstant 9 (Integer 4 []))) (SetRemove (Var 2 a) (IntegerConstant 4 (Integer 4 []))) (= (Var 2 b) (SetConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (Set (Character 1 1 () []))) ()) (= (Var 2 s) (SetPop (Var 2 b) (Character 1 -2 () []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-structs_01-be14d49.json b/tests/reference/asr-structs_01-be14d49.json new file mode 100644 index 0000000000..34d1f10f0c --- /dev/null +++ b/tests/reference/asr-structs_01-be14d49.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-structs_01-be14d49", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/structs_01.py", + "infile_hash": "6586261b9b6e998bad980042375ce6206037a9bb5e1efb586edf691c", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-structs_01-be14d49.stdout", + "stdout_hash": "f73e3112d8fea2ac9a0800cca3219fbf35d0479fe1eff99a11a8f592", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-structs_01-be14d49.stdout b/tests/reference/asr-structs_01-be14d49.stdout new file mode 100644 index 0000000000..e04ffd375e --- /dev/null +++ b/tests/reference/asr-structs_01-be14d49.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {A: (DerivedType (SymbolTable 2 {x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 4 []) Source Public Required .false.)}) A [y x] Source Public ()), _lpython_main_program: (Subroutine (SymbolTable 7 {}) _lpython_main_program [] [(SubroutineCall 1 g () [] ())] Source Public Implementation () .false. .false.), change_struct: (Subroutine (SymbolTable 4 {a: (Variable 4 a In () () Default (Derived 1 A []) Source Public Required .false.)}) change_struct [(Var 4 a)] [(= (DerivedRef (Var 4 a) 2 x (Integer 4 []) ()) (IntegerBinOp (DerivedRef (Var 4 a) 2 x (Integer 4 []) ()) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) ()) (= (DerivedRef (Var 4 a) 2 y (Real 4 []) ()) (RealBinOp (DerivedRef (Var 4 a) 2 y (Real 4 []) ()) Add (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToReal (Real 4 []) ()) (Real 4 []) ()) ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 3 {a: (Variable 3 a In () () Default (Derived 1 A []) Source Public Required .false.)}) f [(Var 3 a)] [(Print () [(DerivedRef (Var 3 a) 2 x (Integer 4 []) ())] () ()) (Print () [(DerivedRef (Var 3 a) 2 y (Real 4 []) ())] () ())] Source Public Implementation () .false. .false.), g: (Subroutine (SymbolTable 5 {x: (Variable 5 x Local () () Default (Derived 1 A []) Source Public Required .false.)}) g [] [(= (Var 5 x) (DerivedTypeConstructor 1 A [(Cast (RealConstant 3.25000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.25000000000000000e+00 (Real 4 []))) (IntegerConstant 3 (Integer 4 []))] (Derived 1 A []) ()) ()) (SubroutineCall 1 f () [((Var 5 x))] ()) (Assert (IntegerCompare (DerivedRef (Var 5 x) 2 x (Integer 4 []) ()) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (DerivedRef (Var 5 x) 2 y (Real 4 []) ()) RealToReal (Real 8 []) ()) Eq (RealConstant 3.25000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (= (DerivedRef (Var 5 x) 2 x (Integer 4 []) ()) (IntegerConstant 5 (Integer 4 [])) ()) (= (DerivedRef (Var 5 x) 2 y (Real 4 []) ()) (Cast (RealConstant 5.50000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.50000000000000000e+00 (Real 4 []))) ()) (SubroutineCall 1 f () [((Var 5 x))] ()) (Assert (IntegerCompare (DerivedRef (Var 5 x) 2 x (Integer 4 []) ()) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (DerivedRef (Var 5 x) 2 y (Real 4 []) ()) RealToReal (Real 8 []) ()) Eq (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (SubroutineCall 1 change_struct () [((Var 5 x))] ()) (Assert (IntegerCompare (DerivedRef (Var 5 x) 2 x (Integer 4 []) ()) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (DerivedRef (Var 5 x) 2 y (Real 4 []) ()) RealToReal (Real 8 []) ()) Eq (RealConstant 6.50000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 6 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-structs_02-2ab459a.json b/tests/reference/asr-structs_02-2ab459a.json new file mode 100644 index 0000000000..106ce4cdba --- /dev/null +++ b/tests/reference/asr-structs_02-2ab459a.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-structs_02-2ab459a", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/structs_02.py", + "infile_hash": "0fd731b4917a779e353ab22d29a9dcaeecd767171e6d8ecf5191fde4", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-structs_02-2ab459a.stdout", + "stdout_hash": "e54a44fe0009dfd24652d67de5fe21d846bd7b2f3228d3201bac63a1", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-structs_02-2ab459a.stdout b/tests/reference/asr-structs_02-2ab459a.stdout new file mode 100644 index 0000000000..b643cb6c0e --- /dev/null +++ b/tests/reference/asr-structs_02-2ab459a.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {A: (DerivedType (SymbolTable 2 {x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 4 []) Source Public Required .false.)}) A [x y] Source Public ()), _lpython_main_program: (Subroutine (SymbolTable 6 {}) _lpython_main_program [] [(SubroutineCall 1 g () [] ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 3 {a: (Variable 3 a In () () Default (CPtr) BindC Public Required .true.), a1: (Variable 3 a1 Local () () Default (Derived 1 A []) Source Public Required .false.), a2: (Variable 3 a2 Local () () Default (Pointer (Derived 1 A [])) Source Public Required .false.), x: (Variable 3 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 3 y Local () () Default (Real 4 []) Source Public Required .false.)}) f [(Var 3 a)] [(= (Var 3 a1) (DerivedTypeConstructor 1 A [(IntegerConstant 3 (Integer 4 [])) (Cast (RealConstant 3.25000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.25000000000000000e+00 (Real 4 [])))] (Derived 1 A []) ()) ()) (= (Var 3 a2) (GetPointer (Var 3 a1) (Pointer (Derived 1 A [])) ()) ()) (Print () [(Var 3 a2) (GetPointer (Var 3 a1) (Pointer (Derived 1 A [])) ())] () ()) (= (Var 3 x) (DerivedRef (Var 3 a2) 2 x (Integer 4 []) ()) ()) (= (Var 3 y) (DerivedRef (Var 3 a2) 2 y (Real 4 []) ()) ()) (Assert (IntegerCompare (Var 3 x) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (Var 3 y) RealToReal (Real 8 []) ()) Eq (RealConstant 3.25000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (CPtrToPointer (Var 3 a) (Var 3 a2) ()) (Print () [(Var 3 a) (Var 3 a2) (GetPointer (Var 3 a1) (Pointer (Derived 1 A [])) ())] () ())] BindC Public Implementation () .false. .false.), g: (Subroutine (SymbolTable 4 {b: (Variable 4 b Local () () Default (CPtr) Source Public Required .false.)}) g [] [(SubroutineCall 1 f () [((Var 4 b))] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 5 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-structs_03-0cef911.json b/tests/reference/asr-structs_03-0cef911.json new file mode 100644 index 0000000000..0e51819006 --- /dev/null +++ b/tests/reference/asr-structs_03-0cef911.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-structs_03-0cef911", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/structs_03.py", + "infile_hash": "745be61ec57b0a39c6f981dadeb4d8f2cf9d5aef9ca00ab856510795", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-structs_03-0cef911.stdout", + "stdout_hash": "3b91bab4baea08ae57d88ac55a6d51074577f5765e69d59c360d1e87", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-structs_03-0cef911.stdout b/tests/reference/asr-structs_03-0cef911.stdout new file mode 100644 index 0000000000..c1ec1c8c41 --- /dev/null +++ b/tests/reference/asr-structs_03-0cef911.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {A: (DerivedType (SymbolTable 2 {x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 4 []) Source Public Required .false.)}) A [x y] Source Public ()), _lpython_main_program: (Subroutine (SymbolTable 6 {}) _lpython_main_program [] [(SubroutineCall 1 g () [] ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 3 {pa: (Variable 3 pa In () () Default (Pointer (Derived 1 A [])) Source Public Required .false.)}) f [(Var 3 pa)] [(Print () [(DerivedRef (Var 3 pa) 2 x (Integer 4 []) ())] () ()) (Print () [(DerivedRef (Var 3 pa) 2 y (Real 4 []) ())] () ())] Source Public Implementation () .false. .false.), g: (Subroutine (SymbolTable 4 {x: (Variable 4 x Local () () Default (Derived 1 A []) Source Public Required .false.), xp: (Variable 4 xp Local () () Default (Pointer (Derived 1 A [])) Source Public Required .false.)}) g [] [(= (Var 4 x) (DerivedTypeConstructor 1 A [(IntegerConstant 3 (Integer 4 [])) (Cast (RealConstant 3.25000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.25000000000000000e+00 (Real 4 [])))] (Derived 1 A []) ()) ()) (= (Var 4 xp) (GetPointer (Var 4 x) (Pointer (Derived 1 A [])) ()) ()) (Assert (IntegerCompare (DerivedRef (Var 4 xp) 2 x (Integer 4 []) ()) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (DerivedRef (Var 4 xp) 2 y (Real 4 []) ()) RealToReal (Real 8 []) ()) Eq (RealConstant 3.25000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (= (DerivedRef (Var 4 xp) 2 x (Integer 4 []) ()) (IntegerConstant 5 (Integer 4 [])) ()) (= (DerivedRef (Var 4 xp) 2 y (Real 4 []) ()) (Cast (RealConstant 5.50000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.50000000000000000e+00 (Real 4 []))) ()) (SubroutineCall 1 f () [((Var 4 xp))] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 5 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-structs_04-387747b.json b/tests/reference/asr-structs_04-387747b.json new file mode 100644 index 0000000000..69388ff867 --- /dev/null +++ b/tests/reference/asr-structs_04-387747b.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-structs_04-387747b", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/structs_04.py", + "infile_hash": "d1a2040f8609b23e5bde36c06a5f774e02b385911fb601c0d3d1f4bd", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-structs_04-387747b.stdout", + "stdout_hash": "e25864c1a7d7efd5e7f4eb78727665e0c9adb6854ea817f3c0acc047", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-structs_04-387747b.stdout b/tests/reference/asr-structs_04-387747b.stdout new file mode 100644 index 0000000000..f3a0dee80c --- /dev/null +++ b/tests/reference/asr-structs_04-387747b.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {A: (DerivedType (SymbolTable 2 {x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 4 []) Source Public Required .false.)}) A [y x] Source Public ()), B: (DerivedType (SymbolTable 3 {a: (Variable 3 a Local () () Default (Pointer (Derived 1 A [])) Source Public Required .false.), z: (Variable 3 z Local () () Default (Integer 4 []) Source Public Required .false.)}) B [a z] Source Public ()), _lpython_main_program: (Subroutine (SymbolTable 7 {}) _lpython_main_program [] [(SubroutineCall 1 g () [] ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 4 {b: (Variable 4 b In () () Default (Derived 1 B []) Source Public Required .false.)}) f [(Var 4 b)] [(Print () [(DerivedRef (Var 4 b) 3 z (Integer 4 []) ()) (DerivedRef (DerivedRef (Var 4 b) 3 a (Pointer (Derived 1 A [])) ()) 2 x (Integer 4 []) ()) (DerivedRef (DerivedRef (Var 4 b) 3 a (Pointer (Derived 1 A [])) ()) 2 y (Real 4 []) ())] () ()) (Assert (IntegerCompare (DerivedRef (Var 4 b) 3 z (Integer 4 []) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (DerivedRef (DerivedRef (Var 4 b) 3 a (Pointer (Derived 1 A [])) ()) 2 x (Integer 4 []) ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (DerivedRef (DerivedRef (Var 4 b) 3 a (Pointer (Derived 1 A [])) ()) 2 y (Real 4 []) ()) RealToReal (Real 8 []) ()) Eq (RealConstant 3.00000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), g: (Subroutine (SymbolTable 5 {a1: (Variable 5 a1 Local () () Default (Derived 1 A []) Source Public Required .false.), a2: (Variable 5 a2 Local () () Default (Derived 1 A []) Source Public Required .false.), b: (Variable 5 b Local () () Default (Derived 1 B []) Source Public Required .false.)}) g [] [(= (Var 5 a1) (DerivedTypeConstructor 1 A [(Cast (RealConstant 1.00000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 1.00000000000000000e+00 (Real 4 []))) (Cast (RealConstant 1.00000000000000000e+00 (Real 8 [])) RealToInteger (Integer 4 []) (IntegerConstant 1 (Integer 4 [])))] (Derived 1 A []) ()) ()) (= (Var 5 a2) (DerivedTypeConstructor 1 A [(Cast (RealConstant 2.00000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 2.00000000000000000e+00 (Real 4 []))) (Cast (RealConstant 2.00000000000000000e+00 (Real 8 [])) RealToInteger (Integer 4 []) (IntegerConstant 2 (Integer 4 [])))] (Derived 1 A []) ()) ()) (= (Var 5 b) (DerivedTypeConstructor 1 B [(Var 5 a1) (IntegerConstant 1 (Integer 4 []))] (Derived 1 B []) ()) ()) (= (DerivedRef (Var 5 b) 3 a (Pointer (Derived 1 A [])) ()) (Var 5 a2) ()) (= (DerivedRef (Var 5 b) 3 z (Integer 4 []) ()) (IntegerConstant 1 (Integer 4 [])) ()) (= (DerivedRef (DerivedRef (Var 5 b) 3 a (Pointer (Derived 1 A [])) ()) 2 x (Integer 4 []) ()) (IntegerConstant 2 (Integer 4 [])) ()) (= (DerivedRef (DerivedRef (Var 5 b) 3 a (Pointer (Derived 1 A [])) ()) 2 y (Real 4 []) ()) (Cast (RealConstant 3.00000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.00000000000000000e+00 (Real 4 []))) ()) (Assert (IntegerCompare (DerivedRef (Var 5 a1) 2 x (Integer 4 []) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (DerivedRef (Var 5 a1) 2 y (Real 4 []) ()) RealToReal (Real 8 []) ()) Eq (RealConstant 1.00000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (DerivedRef (Var 5 a2) 2 x (Integer 4 []) ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (DerivedRef (Var 5 a2) 2 y (Real 4 []) ()) RealToReal (Real 8 []) ()) Eq (RealConstant 3.00000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (SubroutineCall 1 f () [((Var 5 b))] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 6 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-structs_05-fa98307.json b/tests/reference/asr-structs_05-fa98307.json new file mode 100644 index 0000000000..56f5e3db43 --- /dev/null +++ b/tests/reference/asr-structs_05-fa98307.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-structs_05-fa98307", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/structs_05.py", + "infile_hash": "8022943f9e2faac2fac4bd147f9ccba284127429215ddef38d22beb8", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-structs_05-fa98307.stdout", + "stdout_hash": "57de79a2142ffd037b3c578a40ad5dd71fc1e9edc239bca15545d63a", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-structs_05-fa98307.stdout b/tests/reference/asr-structs_05-fa98307.stdout new file mode 100644 index 0000000000..2090ec2b2a --- /dev/null +++ b/tests/reference/asr-structs_05-fa98307.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {A: (DerivedType (SymbolTable 2 {x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 8 []) Source Public Required .false.)}) A [y x] Source Public ()), _lpython_main_program: (Subroutine (SymbolTable 84 {}) _lpython_main_program [] [(SubroutineCall 1 g () [] ())] Source Public Implementation () .false. .false.), abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 8 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), g: (Subroutine (SymbolTable 6 {y: (Variable 6 y Local () () Default (Derived 1 A [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))]) Source Public Required .false.)}) g [] [(= (ArrayItem (Var 6 y) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A []) ()) (DerivedTypeConstructor 1 A [(RealConstant 1.10000000000000009e+00 (Real 8 [])) (IntegerConstant 1 (Integer 4 []))] (Derived 1 A []) ()) ()) (= (ArrayItem (Var 6 y) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A []) ()) (DerivedTypeConstructor 1 A [(RealConstant 2.20000000000000018e+00 (Real 8 [])) (IntegerConstant 2 (Integer 4 []))] (Derived 1 A []) ()) ()) (SubroutineCall 1 verify () [((Var 6 y)) ((IntegerConstant 1 (Integer 4 []))) ((RealConstant 1.10000000000000009e+00 (Real 8 []))) ((IntegerConstant 2 (Integer 4 []))) ((RealConstant 2.20000000000000018e+00 (Real 8 [])))] ()) (SubroutineCall 1 update_1 () [((ArrayItem (Var 6 y) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A []) ()))] ()) (SubroutineCall 1 update_2 () [((Var 6 y))] ()) (SubroutineCall 1 verify () [((Var 6 y)) ((IntegerConstant 2 (Integer 4 []))) ((RealConstant 1.19999999999999996e+00 (Real 8 []))) ((IntegerConstant 3 (Integer 4 []))) ((RealConstant 2.29999999999999982e+00 (Real 8 [])))] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 83 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), update_1: (Subroutine (SymbolTable 4 {s: (Variable 4 s In () () Default (Derived 1 A []) Source Public Required .false.)}) update_1 [(Var 4 s)] [(= (DerivedRef (Var 4 s) 2 x (Integer 4 []) ()) (IntegerConstant 2 (Integer 4 [])) ()) (= (DerivedRef (Var 4 s) 2 y (Real 8 []) ()) (RealConstant 1.19999999999999996e+00 (Real 8 [])) ())] Source Public Implementation () .false. .false.), update_2: (Subroutine (SymbolTable 5 {s: (Variable 5 s InOut () () Default (Derived 1 A [(() ())]) Source Public Required .false.)}) update_2 [(Var 5 s)] [(= (DerivedRef (ArrayItem (Var 5 s) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 x (Integer 4 []) ()) (IntegerConstant 3 (Integer 4 [])) ()) (= (DerivedRef (ArrayItem (Var 5 s) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 y (Real 8 []) ()) (RealConstant 2.29999999999999982e+00 (Real 8 [])) ())] Source Public Implementation () .false. .false.), verify: (Subroutine (SymbolTable 3 {abs: (ExternalSymbol 3 abs 8 abs lpython_builtin [] abs Private), eps: (Variable 3 eps Local () () Default (Real 8 []) Source Public Required .false.), s: (Variable 3 s InOut () () Default (Derived 1 A [(() ())]) Source Public Required .false.), x1: (Variable 3 x1 In () () Default (Integer 4 []) Source Public Required .false.), x2: (Variable 3 x2 In () () Default (Integer 4 []) Source Public Required .false.), y1: (Variable 3 y1 In () () Default (Real 8 []) Source Public Required .false.), y2: (Variable 3 y2 In () () Default (Real 8 []) Source Public Required .false.)}) verify [(Var 3 s) (Var 3 x1) (Var 3 y1) (Var 3 x2) (Var 3 y2)] [(= (Var 3 eps) (RealConstant 9.99999999999999980e-13 (Real 8 [])) ()) (Print () [(DerivedRef (ArrayItem (Var 3 s) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 x (Integer 4 []) ()) (DerivedRef (ArrayItem (Var 3 s) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 y (Real 8 []) ())] () ()) (Assert (IntegerCompare (DerivedRef (ArrayItem (Var 3 s) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 x (Integer 4 []) ()) Eq (Var 3 x1) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (DerivedRef (ArrayItem (Var 3 s) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 y (Real 8 []) ()) Sub (Var 3 y1) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (Print () [(DerivedRef (ArrayItem (Var 3 s) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 x (Integer 4 []) ()) (DerivedRef (ArrayItem (Var 3 s) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 y (Real 8 []) ())] () ()) (Assert (IntegerCompare (DerivedRef (ArrayItem (Var 3 s) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 x (Integer 4 []) ()) Eq (Var 3 x2) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (DerivedRef (ArrayItem (Var 3 s) [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A []) ()) 2 y (Real 8 []) ()) Sub (Var 3 y2) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-subscript1-1acfc19.json b/tests/reference/asr-subscript1-1acfc19.json index 326593dccb..f945748fdb 100644 --- a/tests/reference/asr-subscript1-1acfc19.json +++ b/tests/reference/asr-subscript1-1acfc19.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-subscript1-1acfc19.stdout", - "stdout_hash": "5464d1192f8e11d05dcd3172a28c5710c79bcac6cb92aa3193bc2e48", + "stdout_hash": "fa2dc3dabbf7d17201c4bb54fa4fe94a4c702731a110be4791fec18a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-subscript1-1acfc19.stdout b/tests/reference/asr-subscript1-1acfc19.stdout index f8c35c4b48..6a47edc117 100644 --- a/tests/reference/asr-subscript1-1acfc19.stdout +++ b/tests/reference/asr-subscript1-1acfc19.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_subscript: (Subroutine (SymbolTable 2 {A: (Variable 2 A Local () () Default (Integer 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])))]) Source Public Required .false.), B: (Variable 2 B Local () () Default (Integer 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])))]) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_subscript [] [(= (Var 2 s) (StringConstant "abc" (Character 1 3 () [])) ()) (= (Var 2 s) (StringItem (Var 2 s) (BinOp (IntegerConstant 0 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (BinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 1 (Integer 4 [])) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerConstant 1 (Integer 4 [])) (IntegerConstant 0 (Integer 4 [])) (IntegerConstant 1 (Integer 4 [])) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerConstant 1 (Integer 4 [])) (IntegerConstant 0 (Integer 4 [])) (BinOp (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerConstant 1 (Integer 4 [])) (IntegerConstant 0 (Integer 4 [])) (BinOp (IntegerConstant 2 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (BinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 88 (Integer 4 [])) (BinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerConstant 1 (Integer 4 [])) (IntegerConstant 1 (Integer 4 [])) (BinOp (UnaryOp USub (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (BinOp (UnaryOp USub (IntegerConstant 89 (Integer 4 [])) (Integer 4 []) (IntegerConstant -89 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 0 (Integer 4 [])) (BinOp (IntegerConstant 4 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (BinOp (UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) (BinOp (UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (BinOp (IntegerConstant 2 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 3 (Integer 4 [])) (IntegerConstant 1 (Integer 4 [])) (Character 1 -2 () []) ()) ()) (= (Var 2 i) (ArrayRef 2 A [(() (BinOp (IntegerConstant 0 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) ())] (Integer 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])))]) ()) ()) (= (Var 2 B) (ArrayRef 2 A [((BinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 3 (Integer 4 [])) ())] (Integer 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])))]) ()) ()) (= (Var 2 B) (ArrayRef 2 A [((BinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (IntegerConstant 2 (Integer 4 [])) (BinOp (IntegerConstant 3 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()))] (Integer 4 [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])))]) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_subscript: (Subroutine (SymbolTable 2 {A: (Variable 2 A Local () () Default (Integer 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 5 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 []))))]) Source Public Required .false.), B: (Variable 2 B Local () () Default (Integer 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))]) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_subscript [] [(= (Var 2 s) (StringConstant "abc" (Character 1 3 () [])) ()) (= (Var 2 s) (StringItem (Var 2 s) (IntegerBinOp (IntegerConstant 0 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerBinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 1 (Integer 4 [])) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerConstant 1 (Integer 4 [])) (IntegerConstant 0 (Integer 4 [])) (IntegerConstant 1 (Integer 4 [])) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerConstant 1 (Integer 4 [])) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerConstant 1 (Integer 4 [])) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerBinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 88 (Integer 4 [])) (IntegerBinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerConstant 1 (Integer 4 [])) (IntegerConstant 1 (Integer 4 [])) (IntegerBinOp (IntegerUnaryMinus (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerBinOp (IntegerUnaryMinus (IntegerConstant 89 (Integer 4 [])) (Integer 4 []) (IntegerConstant -89 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 4 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerBinOp (IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) (IntegerBinOp (IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (Character 1 -2 () []) ()) ()) (= (Var 2 s) (StringSection (Var 2 s) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) (IntegerConstant 3 (Integer 4 [])) (IntegerConstant 1 (Integer 4 [])) (Character 1 -2 () []) ()) ()) (= (Var 2 i) (ArrayItem (Var 2 A) [(() (IntegerConstant 0 (Integer 4 [])) ())] (Integer 4 []) ()) ()) (= (Var 2 B) (ArraySection (Var 2 A) [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 3 (Integer 4 [])) ())] (Integer 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 5 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 []))))]) ()) ()) (= (Var 2 B) (ArraySection (Var 2 A) [((IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 [])))] (Integer 4 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 5 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 []))))]) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_annassign_type_mismatch-7dac7be.json b/tests/reference/asr-test_annassign_type_mismatch-7dac7be.json index b4b8bf736d..f16267b466 100644 --- a/tests/reference/asr-test_annassign_type_mismatch-7dac7be.json +++ b/tests/reference/asr-test_annassign_type_mismatch-7dac7be.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_annassign_type_mismatch-7dac7be.stderr", - "stderr_hash": "2e2230047083bb3431865114def04970e6c69c261d97bc7b05ecf365", + "stderr_hash": "26fc89f95c7dda5f1d9c3cb1af9843880cf693eb7b97125372b11f80", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr b/tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr index 8b597822c2..6fd7b199ea 100644 --- a/tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr +++ b/tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr @@ -2,4 +2,4 @@ semantic error: Type mismatch in annotation-assignment, the types must be compat --> tests/errors/test_annassign_type_mismatch.py:4:5 | 4 | x: i32[4] = [1, 2, 3, 4] - | ^ ^^^^^^^^^^^^ type mismatch ('i32' and 'list[i32]') + | ^ ^^^^^^^^^^^^ type mismatch ('i32[4]' and 'list[i32]') diff --git a/tests/reference/asr-test_annassign_type_mismatch2-fc883f7.json b/tests/reference/asr-test_annassign_type_mismatch2-fc883f7.json new file mode 100644 index 0000000000..7f906e610d --- /dev/null +++ b/tests/reference/asr-test_annassign_type_mismatch2-fc883f7.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_annassign_type_mismatch2-fc883f7", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_annassign_type_mismatch2.py", + "infile_hash": "21f89e1a00c786674c46a2a6bb76d9e9fce37e1d9e11532d5134f68d", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_annassign_type_mismatch2-fc883f7.stderr", + "stderr_hash": "873b4521e2155bc92405db41e7745a4fb5441b5d80f94467d7b1b637", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_annassign_type_mismatch2-fc883f7.stderr b/tests/reference/asr-test_annassign_type_mismatch2-fc883f7.stderr new file mode 100644 index 0000000000..2a4f9ccd10 --- /dev/null +++ b/tests/reference/asr-test_annassign_type_mismatch2-fc883f7.stderr @@ -0,0 +1,5 @@ +semantic error: Type mismatch in annotation-assignment, the types must be compatible + --> tests/errors/test_annassign_type_mismatch2.py:4:5 + | +4 | x: f64[5] = [1.0, 2.0, 3.0, 4.0, 5.0] + | ^ ^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('f64[5]' and 'list[f64]') diff --git a/tests/reference/asr-test_assign4-a2136e0.json b/tests/reference/asr-test_assign4-a2136e0.json index 0f65e9ab7f..b5a072f05e 100644 --- a/tests/reference/asr-test_assign4-a2136e0.json +++ b/tests/reference/asr-test_assign4-a2136e0.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_assign4-a2136e0.stderr", - "stderr_hash": "b47803e86e3b43c3191ec97fe750e85473c6a1f30918d97a1d0b58b3", + "stderr_hash": "633559add9bb76a26f7919c71128a853ac537411d65b75ac2f319e26", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_assign4-a2136e0.stderr b/tests/reference/asr-test_assign4-a2136e0.stderr index 33b404767e..308bc37d6e 100644 --- a/tests/reference/asr-test_assign4-a2136e0.stderr +++ b/tests/reference/asr-test_assign4-a2136e0.stderr @@ -1,5 +1,5 @@ -semantic error: Type mismatch in assignment, the types must be compatible - --> tests/errors/test_assign4.py:5:5 +semantic error: Assigning integer to float is not supported + --> tests/errors/test_assign4.py:5:9 | 5 | f = x - | ^ ^ type mismatch ('f64' and 'i32') + | ^ diff --git a/tests/reference/asr-test_bitwise_on_complex-dd9568b.json b/tests/reference/asr-test_bitwise_on_complex-dd9568b.json new file mode 100644 index 0000000000..24a2da2b22 --- /dev/null +++ b/tests/reference/asr-test_bitwise_on_complex-dd9568b.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_bitwise_on_complex-dd9568b", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_bitwise_on_complex.py", + "infile_hash": "5e03de6348ffb4fa922d726b314eb95eef2f332404e6be94f0b20139", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_bitwise_on_complex-dd9568b.stderr", + "stderr_hash": "58f7acb7f7187308d38c7c97fcd9e34b2022c42be1b6583b95b379af", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_bitwise_on_complex-dd9568b.stderr b/tests/reference/asr-test_bitwise_on_complex-dd9568b.stderr new file mode 100644 index 0000000000..7bb1052707 --- /dev/null +++ b/tests/reference/asr-test_bitwise_on_complex-dd9568b.stderr @@ -0,0 +1,5 @@ +semantic error: Unsupported binary operation on complex: '|' + --> tests/errors/test_bitwise_on_complex.py:8:11 + | +8 | print(c1 | c2) + | ^^^^^^^ diff --git a/tests/reference/asr-test_bitwise_on_float-2e09b30.json b/tests/reference/asr-test_bitwise_on_float-2e09b30.json new file mode 100644 index 0000000000..032da70d00 --- /dev/null +++ b/tests/reference/asr-test_bitwise_on_float-2e09b30.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_bitwise_on_float-2e09b30", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_bitwise_on_float.py", + "infile_hash": "db0fdc79b1041fc5745a4bc839181d870f95d8ebd5169a29530cb178", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_bitwise_on_float-2e09b30.stderr", + "stderr_hash": "1e77fcf2484ec7c10436c14ac2a498db59706d30d3c294b89b6b9090", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_bitwise_on_float-2e09b30.stderr b/tests/reference/asr-test_bitwise_on_float-2e09b30.stderr new file mode 100644 index 0000000000..d6733722d6 --- /dev/null +++ b/tests/reference/asr-test_bitwise_on_float-2e09b30.stderr @@ -0,0 +1,5 @@ +semantic error: Unsupported binary operation on floats: '<<' + --> tests/errors/test_bitwise_on_float.py:8:11 + | +8 | print(f1 << f2) + | ^^^^^^^^ diff --git a/tests/reference/asr-test_bool_binop-f856ef0.json b/tests/reference/asr-test_bool_binop-f856ef0.json new file mode 100644 index 0000000000..260b6b1685 --- /dev/null +++ b/tests/reference/asr-test_bool_binop-f856ef0.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_bool_binop-f856ef0", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_bool_binop.py", + "infile_hash": "6f578959884e05dde74f07328d3f32cb7cdf13349cc49c1e7d4d8972", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-test_bool_binop-f856ef0.stdout", + "stdout_hash": "737c71807584c327952e180914af27844d4e7b781f1a4e476af5f174", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-test_bool_binop-f856ef0.stdout b/tests/reference/asr-test_bool_binop-f856ef0.stdout new file mode 100644 index 0000000000..d1be975fb9 --- /dev/null +++ b/tests/reference/asr-test_bool_binop-f856ef0.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_floordiv@__lpython_overloaded_2___lpython_floordiv: (ExternalSymbol 1 _lpython_floordiv@__lpython_overloaded_2___lpython_floordiv 4 __lpython_overloaded_2___lpython_floordiv lpython_builtin [] __lpython_overloaded_2___lpython_floordiv Public), _lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 f () [] ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 2 {_lpython_floordiv: (ExternalSymbol 2 _lpython_floordiv 4 _lpython_floordiv lpython_builtin [] _lpython_floordiv Private), b1: (Variable 2 b1 Local () () Default (Logical 4 []) Source Public Required .false.), b2: (Variable 2 b2 Local () () Default (Logical 4 []) Source Public Required .false.), f: (Variable 2 f Local () () Default (Real 8 []) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.)}) f [] [(= (Var 2 i) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 2 i) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 2 i) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerBinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Mul (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 2 i) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 i) (FunctionCall 1 _lpython_floordiv@__lpython_overloaded_2___lpython_floordiv 2 _lpython_floordiv [((Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ())) ((Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (Var 2 i) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 i) (FunctionCall 1 _lpython_floordiv@__lpython_overloaded_2___lpython_floordiv 2 _lpython_floordiv [((Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ())) ((Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (Var 2 i) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Pow (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 2 i) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 b1) (LogicalConstant .false. (Logical 4 [])) ()) (= (Var 2 b2) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 f) (RealBinOp (Cast (Cast (Var 2 b1) LogicalToInteger (Integer 4 []) ()) IntegerToReal (Real 8 []) ()) Div (Cast (Cast (Var 2 b2) LogicalToInteger (Integer 4 []) ()) IntegerToReal (Real 8 []) ()) (Real 8 []) ()) ()) (Assert (RealCompare (Var 2 f) Eq (RealConstant 0.00000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-test_builtin-aa64615.json b/tests/reference/asr-test_builtin-aa64615.json index 1711e234a4..e46fe40487 100644 --- a/tests/reference/asr-test_builtin-aa64615.json +++ b/tests/reference/asr-test_builtin-aa64615.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin-aa64615.stdout", - "stdout_hash": "af9a5624280851a160124d6fd9d07ab531f2bb36f4ff7a4e2b02595b", + "stdout_hash": "45c81c3b269c4e0cbea508c62d88cfa243987ae6c4e1c07d35860898", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin-aa64615.stdout b/tests/reference/asr-test_builtin-aa64615.stdout index 9843554381..46f370fd49 100644 --- a/tests/reference/asr-test_builtin-aa64615.stdout +++ b/tests/reference/asr-test_builtin-aa64615.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 98 {}) _lpython_main_program [] [(SubroutineCall 1 test_ord () [] ()) (SubroutineCall 1 test_chr () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 97 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_chr: (Subroutine (SymbolTable 3 {capital_a: (Variable 3 capital_a Local () () Default (Character 1 -2 () []) Source Public Required .false.), capital_z: (Variable 3 capital_z Local () () Default (Character 1 -2 () []) Source Public Required .false.), chr: (ExternalSymbol 3 chr 5 chr lpython_builtin [] chr Private), dollar: (Variable 3 dollar Local () () Default (Character 1 -2 () []) Source Public Required .false.), exclamation: (Variable 3 exclamation Local () () Default (Character 1 -2 () []) Source Public Required .false.), i: (Variable 3 i Local () () Default (Integer 4 []) Source Public Required .false.), left_parenthesis: (Variable 3 left_parenthesis Local () () Default (Character 1 -2 () []) Source Public Required .false.), nine: (Variable 3 nine Local () () Default (Character 1 -2 () []) Source Public Required .false.), plus: (Variable 3 plus Local () () Default (Character 1 -2 () []) Source Public Required .false.), right_brace: (Variable 3 right_brace Local () () Default (Character 1 -2 () []) Source Public Required .false.), right_bracket: (Variable 3 right_bracket Local () () Default (Character 1 -2 () []) Source Public Required .false.), semicolon: (Variable 3 semicolon Local () () Default (Character 1 -2 () []) Source Public Required .false.), small_a: (Variable 3 small_a Local () () Default (Character 1 -2 () []) Source Public Required .false.), small_z: (Variable 3 small_z Local () () Default (Character 1 -2 () []) Source Public Required .false.), zero: (Variable 3 zero Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_chr [] [(= (Var 3 i) (IntegerConstant 33 (Integer 4 [])) ()) (= (Var 3 exclamation) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 33 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "!" (Character 1 1 () [])) ()) Eq (StringConstant "!" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 exclamation) Eq (StringConstant "!" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 36 (Integer 4 [])) ()) (= (Var 3 dollar) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 36 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "$" (Character 1 1 () [])) ()) Eq (StringConstant "$" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 dollar) Eq (StringConstant "$" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 40 (Integer 4 [])) ()) (= (Var 3 left_parenthesis) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 40 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "(" (Character 1 1 () [])) ()) Eq (StringConstant "(" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 left_parenthesis) Eq (StringConstant "(" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 43 (Integer 4 [])) ()) (= (Var 3 plus) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 43 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "+" (Character 1 1 () [])) ()) Eq (StringConstant "+" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 plus) Eq (StringConstant "+" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 48 (Integer 4 [])) ()) (= (Var 3 zero) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 48 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0" (Character 1 1 () [])) ()) Eq (StringConstant "0" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 zero) Eq (StringConstant "0" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 57 (Integer 4 [])) ()) (= (Var 3 nine) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 57 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "9" (Character 1 1 () [])) ()) Eq (StringConstant "9" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 nine) Eq (StringConstant "9" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 59 (Integer 4 [])) ()) (= (Var 3 semicolon) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 59 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant ";" (Character 1 1 () [])) ()) Eq (StringConstant ";" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 semicolon) Eq (StringConstant ";" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 65 (Integer 4 [])) ()) (= (Var 3 capital_a) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 65 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "A" (Character 1 1 () [])) ()) Eq (StringConstant "A" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 capital_a) Eq (StringConstant "A" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 90 (Integer 4 [])) ()) (= (Var 3 capital_z) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 90 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "Z" (Character 1 1 () [])) ()) Eq (StringConstant "Z" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 capital_z) Eq (StringConstant "Z" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 93 (Integer 4 [])) ()) (= (Var 3 right_bracket) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 93 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "]" (Character 1 1 () [])) ()) Eq (StringConstant "]" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 right_bracket) Eq (StringConstant "]" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 97 (Integer 4 [])) ()) (= (Var 3 small_a) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 97 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "a" (Character 1 1 () [])) ()) Eq (StringConstant "a" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 small_a) Eq (StringConstant "a" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 122 (Integer 4 [])) ()) (= (Var 3 small_z) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 122 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "z" (Character 1 1 () [])) ()) Eq (StringConstant "z" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 small_z) Eq (StringConstant "z" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (= (Var 3 i) (IntegerConstant 125 (Integer 4 [])) ()) (= (Var 3 right_brace) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [((IntegerConstant 125 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "}" (Character 1 1 () [])) ()) Eq (StringConstant "}" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 3 right_brace) Eq (StringConstant "}" (Character 1 1 () [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.), test_ord: (Subroutine (SymbolTable 2 {capital_a_unicode: (Variable 2 capital_a_unicode Local () () Default (Integer 4 []) Source Public Required .false.), capital_z_unicode: (Variable 2 capital_z_unicode Local () () Default (Integer 4 []) Source Public Required .false.), dollar_unicode: (Variable 2 dollar_unicode Local () () Default (Integer 4 []) Source Public Required .false.), exclamation_unicode: (Variable 2 exclamation_unicode Local () () Default (Integer 4 []) Source Public Required .false.), left_parenthesis_unicode: (Variable 2 left_parenthesis_unicode Local () () Default (Integer 4 []) Source Public Required .false.), nine_unicode: (Variable 2 nine_unicode Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 2 ord 5 ord lpython_builtin [] ord Private), plus_unicode: (Variable 2 plus_unicode Local () () Default (Integer 4 []) Source Public Required .false.), right_brace_unicode: (Variable 2 right_brace_unicode Local () () Default (Integer 4 []) Source Public Required .false.), right_bracket_unicode: (Variable 2 right_bracket_unicode Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.), semicolon_unicode: (Variable 2 semicolon_unicode Local () () Default (Integer 4 []) Source Public Required .false.), small_a_unicode: (Variable 2 small_a_unicode Local () () Default (Integer 4 []) Source Public Required .false.), small_z_unicode: (Variable 2 small_z_unicode Local () () Default (Integer 4 []) Source Public Required .false.), zero_unicode: (Variable 2 zero_unicode Local () () Default (Integer 4 []) Source Public Required .false.)}) test_ord [] [(= (Var 2 s) (StringConstant "!" (Character 1 1 () [])) ()) (= (Var 2 exclamation_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "!" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 33 (Integer 4 [])) ()) Eq (IntegerConstant 33 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 exclamation_unicode) Eq (IntegerConstant 33 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "$" (Character 1 1 () [])) ()) (= (Var 2 dollar_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "$" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 36 (Integer 4 [])) ()) Eq (IntegerConstant 36 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 dollar_unicode) Eq (IntegerConstant 36 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "(" (Character 1 1 () [])) ()) (= (Var 2 left_parenthesis_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "(" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 40 (Integer 4 [])) ()) Eq (IntegerConstant 40 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 left_parenthesis_unicode) Eq (IntegerConstant 40 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "+" (Character 1 1 () [])) ()) (= (Var 2 plus_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "+" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 43 (Integer 4 [])) ()) Eq (IntegerConstant 43 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 plus_unicode) Eq (IntegerConstant 43 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "0" (Character 1 1 () [])) ()) (= (Var 2 zero_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "0" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 48 (Integer 4 [])) ()) Eq (IntegerConstant 48 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 zero_unicode) Eq (IntegerConstant 48 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "9" (Character 1 1 () [])) ()) (= (Var 2 nine_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "9" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 57 (Integer 4 [])) ()) Eq (IntegerConstant 57 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 nine_unicode) Eq (IntegerConstant 57 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant ";" (Character 1 1 () [])) ()) (= (Var 2 semicolon_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant ";" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 59 (Integer 4 [])) ()) Eq (IntegerConstant 59 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 semicolon_unicode) Eq (IntegerConstant 59 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "A" (Character 1 1 () [])) ()) (= (Var 2 capital_a_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "A" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 65 (Integer 4 [])) ()) Eq (IntegerConstant 65 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 capital_a_unicode) Eq (IntegerConstant 65 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "Z" (Character 1 1 () [])) ()) (= (Var 2 capital_z_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "Z" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 90 (Integer 4 [])) ()) Eq (IntegerConstant 90 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 capital_z_unicode) Eq (IntegerConstant 90 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "]" (Character 1 1 () [])) ()) (= (Var 2 right_bracket_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "]" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 93 (Integer 4 [])) ()) Eq (IntegerConstant 93 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 right_bracket_unicode) Eq (IntegerConstant 93 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "a" (Character 1 1 () [])) ()) (= (Var 2 small_a_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "a" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 97 (Integer 4 [])) ()) Eq (IntegerConstant 97 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 small_a_unicode) Eq (IntegerConstant 97 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "z" (Character 1 1 () [])) ()) (= (Var 2 small_z_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "z" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 122 (Integer 4 [])) ()) Eq (IntegerConstant 122 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 small_z_unicode) Eq (IntegerConstant 122 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "}" (Character 1 1 () [])) ()) (= (Var 2 right_brace_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [((StringConstant "}" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 125 (Integer 4 [])) ()) Eq (IntegerConstant 125 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Var 2 right_brace_unicode) Eq (IntegerConstant 125 (Integer 4 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 81 {}) _lpython_main_program [] [(SubroutineCall 1 test_ord () [] ()) (SubroutineCall 1 test_chr () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 80 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_chr: (Subroutine (SymbolTable 3 {capital_a: (Variable 3 capital_a Local () () Default (Character 1 -2 () []) Source Public Required .false.), capital_z: (Variable 3 capital_z Local () () Default (Character 1 -2 () []) Source Public Required .false.), chr: (ExternalSymbol 3 chr 5 chr lpython_builtin [] chr Private), dollar: (Variable 3 dollar Local () () Default (Character 1 -2 () []) Source Public Required .false.), exclamation: (Variable 3 exclamation Local () () Default (Character 1 -2 () []) Source Public Required .false.), i: (Variable 3 i Local () () Default (Integer 4 []) Source Public Required .false.), left_parenthesis: (Variable 3 left_parenthesis Local () () Default (Character 1 -2 () []) Source Public Required .false.), nine: (Variable 3 nine Local () () Default (Character 1 -2 () []) Source Public Required .false.), plus: (Variable 3 plus Local () () Default (Character 1 -2 () []) Source Public Required .false.), right_brace: (Variable 3 right_brace Local () () Default (Character 1 -2 () []) Source Public Required .false.), right_bracket: (Variable 3 right_bracket Local () () Default (Character 1 -2 () []) Source Public Required .false.), semicolon: (Variable 3 semicolon Local () () Default (Character 1 -2 () []) Source Public Required .false.), small_a: (Variable 3 small_a Local () () Default (Character 1 -2 () []) Source Public Required .false.), small_z: (Variable 3 small_z Local () () Default (Character 1 -2 () []) Source Public Required .false.), zero: (Variable 3 zero Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_chr [] [(= (Var 3 i) (IntegerConstant 33 (Integer 4 [])) ()) (= (Var 3 exclamation) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 33 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "!" (Character 1 1 () [])) ()) Eq (StringConstant "!" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 exclamation) Eq (StringConstant "!" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 36 (Integer 4 [])) ()) (= (Var 3 dollar) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 36 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "$" (Character 1 1 () [])) ()) Eq (StringConstant "$" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 dollar) Eq (StringConstant "$" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 40 (Integer 4 [])) ()) (= (Var 3 left_parenthesis) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 40 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "(" (Character 1 1 () [])) ()) Eq (StringConstant "(" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 left_parenthesis) Eq (StringConstant "(" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 43 (Integer 4 [])) ()) (= (Var 3 plus) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 43 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "+" (Character 1 1 () [])) ()) Eq (StringConstant "+" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 plus) Eq (StringConstant "+" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 48 (Integer 4 [])) ()) (= (Var 3 zero) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 48 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0" (Character 1 1 () [])) ()) Eq (StringConstant "0" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 zero) Eq (StringConstant "0" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 57 (Integer 4 [])) ()) (= (Var 3 nine) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 57 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "9" (Character 1 1 () [])) ()) Eq (StringConstant "9" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 nine) Eq (StringConstant "9" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 59 (Integer 4 [])) ()) (= (Var 3 semicolon) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 59 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant ";" (Character 1 1 () [])) ()) Eq (StringConstant ";" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 semicolon) Eq (StringConstant ";" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 65 (Integer 4 [])) ()) (= (Var 3 capital_a) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 65 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "A" (Character 1 1 () [])) ()) Eq (StringConstant "A" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 capital_a) Eq (StringConstant "A" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 90 (Integer 4 [])) ()) (= (Var 3 capital_z) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 90 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "Z" (Character 1 1 () [])) ()) Eq (StringConstant "Z" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 capital_z) Eq (StringConstant "Z" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 93 (Integer 4 [])) ()) (= (Var 3 right_bracket) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 93 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "]" (Character 1 1 () [])) ()) Eq (StringConstant "]" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 right_bracket) Eq (StringConstant "]" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 97 (Integer 4 [])) ()) (= (Var 3 small_a) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 97 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "a" (Character 1 1 () [])) ()) Eq (StringConstant "a" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 small_a) Eq (StringConstant "a" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 122 (Integer 4 [])) ()) (= (Var 3 small_z) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 122 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "z" (Character 1 1 () [])) ()) Eq (StringConstant "z" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 small_z) Eq (StringConstant "z" (Character 1 1 () [])) (Logical 4 []) ()) ()) (= (Var 3 i) (IntegerConstant 125 (Integer 4 [])) ()) (= (Var 3 right_brace) (FunctionCall 3 chr () [((Var 3 i))] (Character 1 -2 () []) () ()) ()) (Assert (StringCompare (FunctionCall 3 chr () [((IntegerConstant 125 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "}" (Character 1 1 () [])) ()) Eq (StringConstant "}" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (Var 3 right_brace) Eq (StringConstant "}" (Character 1 1 () [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), test_ord: (Subroutine (SymbolTable 2 {capital_a_unicode: (Variable 2 capital_a_unicode Local () () Default (Integer 4 []) Source Public Required .false.), capital_z_unicode: (Variable 2 capital_z_unicode Local () () Default (Integer 4 []) Source Public Required .false.), dollar_unicode: (Variable 2 dollar_unicode Local () () Default (Integer 4 []) Source Public Required .false.), exclamation_unicode: (Variable 2 exclamation_unicode Local () () Default (Integer 4 []) Source Public Required .false.), left_parenthesis_unicode: (Variable 2 left_parenthesis_unicode Local () () Default (Integer 4 []) Source Public Required .false.), nine_unicode: (Variable 2 nine_unicode Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 2 ord 5 ord lpython_builtin [] ord Private), plus_unicode: (Variable 2 plus_unicode Local () () Default (Integer 4 []) Source Public Required .false.), right_brace_unicode: (Variable 2 right_brace_unicode Local () () Default (Integer 4 []) Source Public Required .false.), right_bracket_unicode: (Variable 2 right_bracket_unicode Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.), semicolon_unicode: (Variable 2 semicolon_unicode Local () () Default (Integer 4 []) Source Public Required .false.), small_a_unicode: (Variable 2 small_a_unicode Local () () Default (Integer 4 []) Source Public Required .false.), small_z_unicode: (Variable 2 small_z_unicode Local () () Default (Integer 4 []) Source Public Required .false.), zero_unicode: (Variable 2 zero_unicode Local () () Default (Integer 4 []) Source Public Required .false.)}) test_ord [] [(= (Var 2 s) (StringConstant "!" (Character 1 1 () [])) ()) (= (Var 2 exclamation_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "!" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 33 (Integer 4 [])) ()) Eq (IntegerConstant 33 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 exclamation_unicode) Eq (IntegerConstant 33 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "$" (Character 1 1 () [])) ()) (= (Var 2 dollar_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "$" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 36 (Integer 4 [])) ()) Eq (IntegerConstant 36 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 dollar_unicode) Eq (IntegerConstant 36 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "(" (Character 1 1 () [])) ()) (= (Var 2 left_parenthesis_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "(" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 40 (Integer 4 [])) ()) Eq (IntegerConstant 40 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 left_parenthesis_unicode) Eq (IntegerConstant 40 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "+" (Character 1 1 () [])) ()) (= (Var 2 plus_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "+" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 43 (Integer 4 [])) ()) Eq (IntegerConstant 43 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 plus_unicode) Eq (IntegerConstant 43 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "0" (Character 1 1 () [])) ()) (= (Var 2 zero_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "0" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 48 (Integer 4 [])) ()) Eq (IntegerConstant 48 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 zero_unicode) Eq (IntegerConstant 48 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "9" (Character 1 1 () [])) ()) (= (Var 2 nine_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "9" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 57 (Integer 4 [])) ()) Eq (IntegerConstant 57 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 nine_unicode) Eq (IntegerConstant 57 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant ";" (Character 1 1 () [])) ()) (= (Var 2 semicolon_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant ";" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 59 (Integer 4 [])) ()) Eq (IntegerConstant 59 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 semicolon_unicode) Eq (IntegerConstant 59 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "A" (Character 1 1 () [])) ()) (= (Var 2 capital_a_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "A" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 65 (Integer 4 [])) ()) Eq (IntegerConstant 65 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 capital_a_unicode) Eq (IntegerConstant 65 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "Z" (Character 1 1 () [])) ()) (= (Var 2 capital_z_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "Z" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 90 (Integer 4 [])) ()) Eq (IntegerConstant 90 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 capital_z_unicode) Eq (IntegerConstant 90 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "]" (Character 1 1 () [])) ()) (= (Var 2 right_bracket_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "]" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 93 (Integer 4 [])) ()) Eq (IntegerConstant 93 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 right_bracket_unicode) Eq (IntegerConstant 93 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "a" (Character 1 1 () [])) ()) (= (Var 2 small_a_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "a" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 97 (Integer 4 [])) ()) Eq (IntegerConstant 97 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 small_a_unicode) Eq (IntegerConstant 97 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "z" (Character 1 1 () [])) ()) (= (Var 2 small_z_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "z" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 122 (Integer 4 [])) ()) Eq (IntegerConstant 122 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 small_z_unicode) Eq (IntegerConstant 122 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "}" (Character 1 1 () [])) ()) (= (Var 2 right_brace_unicode) (FunctionCall 2 ord () [((Var 2 s))] (Integer 4 []) () ()) ()) (Assert (IntegerCompare (FunctionCall 2 ord () [((StringConstant "}" (Character 1 1 () [])))] (Integer 4 []) (IntegerConstant 125 (Integer 4 [])) ()) Eq (IntegerConstant 125 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Var 2 right_brace_unicode) Eq (IntegerConstant 125 (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 index f92cdc62e2..62e45bc77d 100644 --- a/tests/reference/asr-test_builtin_abs-c74d2c9.json +++ b/tests/reference/asr-test_builtin_abs-c74d2c9.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_abs-c74d2c9.stdout", - "stdout_hash": "e2d7d8e2897099e46219a6b8d1fcd0b9c977cb4c22f7375d95f315ec", + "stdout_hash": "4788122a946005af9894bbfb4f296738144712f7746eddb3b1a9a7ec", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_abs-c74d2c9.stdout b/tests/reference/asr-test_builtin_abs-c74d2c9.stdout index 662b01b0bf..f42f5b0e19 100644 --- a/tests/reference/asr-test_builtin_abs-c74d2c9.stdout +++ b/tests/reference/asr-test_builtin_abs-c74d2c9.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 test_abs () [] ())] Source Public Implementation () .false. .false.), abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 4 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), abs@__lpython_overloaded_1__abs: (ExternalSymbol 1 abs@__lpython_overloaded_1__abs 4 __lpython_overloaded_1__abs lpython_builtin [] __lpython_overloaded_1__abs Public), abs@__lpython_overloaded_2__abs: (ExternalSymbol 1 abs@__lpython_overloaded_2__abs 4 __lpython_overloaded_2__abs lpython_builtin [] __lpython_overloaded_2__abs Public), abs@__lpython_overloaded_3__abs: (ExternalSymbol 1 abs@__lpython_overloaded_3__abs 4 __lpython_overloaded_3__abs lpython_builtin [] __lpython_overloaded_3__abs Public), abs@__lpython_overloaded_4__abs: (ExternalSymbol 1 abs@__lpython_overloaded_4__abs 4 __lpython_overloaded_4__abs lpython_builtin [] __lpython_overloaded_4__abs Public), abs@__lpython_overloaded_5__abs: (ExternalSymbol 1 abs@__lpython_overloaded_5__abs 4 __lpython_overloaded_5__abs lpython_builtin [] __lpython_overloaded_5__abs Public), abs@__lpython_overloaded_6__abs: (ExternalSymbol 1 abs@__lpython_overloaded_6__abs 4 __lpython_overloaded_6__abs lpython_builtin [] __lpython_overloaded_6__abs Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_abs: (Subroutine (SymbolTable 2 {abs: (ExternalSymbol 2 abs 4 abs lpython_builtin [] abs Private), b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), i2: (Variable 2 i2 Local () () Default (Integer 8 []) Source Public Required .false.), i3: (Variable 2 i3 Local () () Default (Integer 1 []) Source Public Required .false.), i4: (Variable 2 i4 Local () () Default (Integer 2 []) Source Public Required .false.), x: (Variable 2 x Local () () Default (Real 8 []) Source Public Required .false.), x2: (Variable 2 x2 Local () () Default (Real 4 []) Source Public Required .false.)}) test_abs [] [(= (Var 2 x) (RealConstant 5.500000 (Real 8 [])) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((Var 2 x))] (Real 8 []) () ()) Eq (RealConstant 5.500000 (Real 8 [])) (Logical 4 []) () ()) ()) (= (Var 2 x) (UnaryOp USub (RealConstant 5.500000 (Real 8 [])) (Real 8 []) (RealConstant -5.500000 (Real 8 []))) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((Var 2 x))] (Real 8 []) () ()) Eq (RealConstant 5.500000 (Real 8 [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealConstant 5.500000 (Real 8 [])))] (Real 8 []) (RealConstant 5.500000 (Real 8 [])) ()) Eq (RealConstant 5.500000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((UnaryOp USub (RealConstant 5.500000 (Real 8 [])) (Real 8 []) (RealConstant -5.500000 (Real 8 []))))] (Real 8 []) (RealConstant 5.500000 (Real 8 [])) ()) Eq (RealConstant 5.500000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 x2) (Cast (UnaryOp USub (RealConstant 5.500000 (Real 8 [])) (Real 8 []) (RealConstant -5.500000 (Real 8 []))) RealToReal (Real 4 []) (RealConstant -5.500000 (Real 4 []))) ()) (Assert (Compare (Cast (FunctionCall 1 abs@__lpython_overloaded_1__abs 2 abs [((Var 2 x2))] (Real 4 []) () ()) RealToReal (Real 8 []) ()) Eq (RealConstant 5.500000 (Real 8 [])) (Logical 4 []) () ()) ()) (= (Var 2 i) (UnaryOp USub (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_4__abs 2 abs [((Var 2 i))] (Integer 4 []) () ()) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_4__abs 2 abs [((UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 i2) (Cast (UnaryOp USub (IntegerConstant 6 (Integer 4 [])) (Integer 4 []) (IntegerConstant -6 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_5__abs 2 abs [((Var 2 i2))] (Integer 8 []) () ()) Eq (Cast (IntegerConstant 6 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) () ()) ()) (= (Var 2 i3) (Cast (UnaryOp USub (IntegerConstant 7 (Integer 4 [])) (Integer 4 []) (IntegerConstant -7 (Integer 4 []))) IntegerToInteger (Integer 1 []) ()) ()) (Assert (Compare (Cast (FunctionCall 1 abs@__lpython_overloaded_2__abs 2 abs [((Var 2 i3))] (Integer 1 []) () ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 7 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 i4) (Cast (UnaryOp USub (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) (IntegerConstant -8 (Integer 4 []))) IntegerToInteger (Integer 2 []) ()) ()) (Assert (Compare (Cast (FunctionCall 1 abs@__lpython_overloaded_3__abs 2 abs [((Var 2 i4))] (Integer 2 []) () ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 8 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_6__abs 2 abs [((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 b) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_6__abs 2 abs [((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 test_abs () [] ())] Source Public Implementation () .false. .false.), abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 4 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), abs@__lpython_overloaded_1__abs: (ExternalSymbol 1 abs@__lpython_overloaded_1__abs 4 __lpython_overloaded_1__abs lpython_builtin [] __lpython_overloaded_1__abs Public), abs@__lpython_overloaded_2__abs: (ExternalSymbol 1 abs@__lpython_overloaded_2__abs 4 __lpython_overloaded_2__abs lpython_builtin [] __lpython_overloaded_2__abs Public), abs@__lpython_overloaded_3__abs: (ExternalSymbol 1 abs@__lpython_overloaded_3__abs 4 __lpython_overloaded_3__abs lpython_builtin [] __lpython_overloaded_3__abs Public), abs@__lpython_overloaded_4__abs: (ExternalSymbol 1 abs@__lpython_overloaded_4__abs 4 __lpython_overloaded_4__abs lpython_builtin [] __lpython_overloaded_4__abs Public), abs@__lpython_overloaded_5__abs: (ExternalSymbol 1 abs@__lpython_overloaded_5__abs 4 __lpython_overloaded_5__abs lpython_builtin [] __lpython_overloaded_5__abs Public), abs@__lpython_overloaded_6__abs: (ExternalSymbol 1 abs@__lpython_overloaded_6__abs 4 __lpython_overloaded_6__abs lpython_builtin [] __lpython_overloaded_6__abs Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_abs: (Subroutine (SymbolTable 2 {abs: (ExternalSymbol 2 abs 4 abs lpython_builtin [] abs Private), b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), i2: (Variable 2 i2 Local () () Default (Integer 8 []) Source Public Required .false.), i3: (Variable 2 i3 Local () () Default (Integer 1 []) Source Public Required .false.), i4: (Variable 2 i4 Local () () Default (Integer 2 []) Source Public Required .false.), x: (Variable 2 x Local () () Default (Real 8 []) Source Public Required .false.), x2: (Variable 2 x2 Local () () Default (Real 4 []) Source Public Required .false.)}) test_abs [] [(= (Var 2 x) (RealConstant 5.50000000000000000e+00 (Real 8 [])) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((Var 2 x))] (Real 8 []) () ()) Eq (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (= (Var 2 x) (RealUnaryMinus (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -5.50000000000000000e+00 (Real 8 []))) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((Var 2 x))] (Real 8 []) () ()) Eq (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealConstant 5.50000000000000000e+00 (Real 8 [])))] (Real 8 []) (RealConstant 5.50000000000000000e+00 (Real 8 [])) ()) Eq (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealUnaryMinus (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -5.50000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 5.50000000000000000e+00 (Real 8 [])) ()) Eq (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 x2) (Cast (RealUnaryMinus (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -5.50000000000000000e+00 (Real 8 []))) RealToReal (Real 4 []) (RealConstant -5.50000000000000000e+00 (Real 4 []))) ()) (Assert (RealCompare (Cast (FunctionCall 1 abs@__lpython_overloaded_1__abs 2 abs [((Var 2 x2))] (Real 4 []) () ()) RealToReal (Real 8 []) ()) Eq (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 abs@__lpython_overloaded_4__abs 2 abs [((Var 2 i))] (Integer 4 []) () ()) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 abs@__lpython_overloaded_4__abs 2 abs [((IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 i2) (Cast (IntegerUnaryMinus (IntegerConstant 6 (Integer 4 [])) (Integer 4 []) (IntegerConstant -6 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 abs@__lpython_overloaded_5__abs 2 abs [((Var 2 i2))] (Integer 8 []) () ()) Eq (Cast (IntegerConstant 6 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) ()) (= (Var 2 i3) (Cast (IntegerUnaryMinus (IntegerConstant 7 (Integer 4 [])) (Integer 4 []) (IntegerConstant -7 (Integer 4 []))) IntegerToInteger (Integer 1 []) ()) ()) (Assert (IntegerCompare (Cast (FunctionCall 1 abs@__lpython_overloaded_2__abs 2 abs [((Var 2 i3))] (Integer 1 []) () ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 7 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 i4) (Cast (IntegerUnaryMinus (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) (IntegerConstant -8 (Integer 4 []))) IntegerToInteger (Integer 2 []) ()) ()) (Assert (IntegerCompare (Cast (FunctionCall 1 abs@__lpython_overloaded_3__abs 2 abs [((Var 2 i4))] (Integer 2 []) () ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 8 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 abs@__lpython_overloaded_6__abs 2 abs [((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 b) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 abs@__lpython_overloaded_6__abs 2 abs [((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_bin-52ba9fa.json b/tests/reference/asr-test_builtin_bin-52ba9fa.json index 72c2419617..5acc93fcdb 100644 --- a/tests/reference/asr-test_builtin_bin-52ba9fa.json +++ b/tests/reference/asr-test_builtin_bin-52ba9fa.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_bin-52ba9fa.stdout", - "stdout_hash": "c2820513efd3ff7d8fca3d896f4a5ce4ea8f0f927dca26158a4f043c", + "stdout_hash": "7697ad3cbf51eaee36414dd989c7a9cf63c42f078a75dd004e62871c", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_bin-52ba9fa.stdout b/tests/reference/asr-test_builtin_bin-52ba9fa.stdout index de73adab7d..20deaafdec 100644 --- a/tests/reference/asr-test_builtin_bin-52ba9fa.stdout +++ b/tests/reference/asr-test_builtin_bin-52ba9fa.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 test_bin () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_bin: (Subroutine (SymbolTable 2 {bin: (ExternalSymbol 2 bin 4 bin lpython_builtin [] bin Private), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_bin [] [(= (Var 2 i) (IntegerConstant 5 (Integer 4 [])) ()) (Assert (Compare (FunctionCall 2 bin () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "0b101" (Character 1 5 () [])) (Logical 4 []) () ()) ()) (= (Var 2 i) (IntegerConstant 64 (Integer 4 [])) ()) (Assert (Compare (FunctionCall 2 bin () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "0b1000000" (Character 1 9 () [])) (Logical 4 []) () ()) ()) (= (Var 2 i) (UnaryOp USub (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))) ()) (Assert (Compare (FunctionCall 2 bin () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "-0b1000010110" (Character 1 13 () [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 bin () [((IntegerConstant 64 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0b1000000" (Character 1 1 () [])) ()) Eq (StringConstant "0b1000000" (Character 1 9 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 2 bin () [((UnaryOp USub (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0b1000010110" (Character 1 1 () [])) ()) Eq (StringConstant "-0b1000010110" (Character 1 13 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 test_bin () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_bin: (Subroutine (SymbolTable 2 {bin: (ExternalSymbol 2 bin 4 bin lpython_builtin [] bin Private), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_bin [] [(= (Var 2 i) (IntegerConstant 5 (Integer 4 [])) ()) (Assert (StringCompare (FunctionCall 2 bin () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "0b101" (Character 1 5 () [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerConstant 64 (Integer 4 [])) ()) (Assert (StringCompare (FunctionCall 2 bin () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "0b1000000" (Character 1 9 () [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerUnaryMinus (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))) ()) (Assert (StringCompare (FunctionCall 2 bin () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "-0b1000010110" (Character 1 13 () [])) (Logical 4 []) ()) ()) (Assert (StringCompare (FunctionCall 2 bin () [((IntegerConstant 64 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0b1000000" (Character 1 1 () [])) ()) Eq (StringConstant "0b1000000" (Character 1 9 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (FunctionCall 2 bin () [((IntegerUnaryMinus (IntegerConstant 534 (Integer 4 [])) (Integer 4 []) (IntegerConstant -534 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0b1000010110" (Character 1 1 () [])) ()) Eq (StringConstant "-0b1000010110" (Character 1 13 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_bool-330223a.json b/tests/reference/asr-test_builtin_bool-330223a.json index 205ce30e34..f71d401d86 100644 --- a/tests/reference/asr-test_builtin_bool-330223a.json +++ b/tests/reference/asr-test_builtin_bool-330223a.json @@ -2,11 +2,11 @@ "basename": "asr-test_builtin_bool-330223a", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/test_builtin_bool.py", - "infile_hash": "4dfa3350f4c58f8d6375fdde90997ef51a16035983c73dd391086149", + "infile_hash": "bf43e9b787161410aa1245f1f412212d0f01224bf7ec8d527793f44a", "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_bool-330223a.stdout", - "stdout_hash": "59f8e0666f4589641b7d2bc71449af8e2e127a1b5dca77b9b22df8ce", + "stdout_hash": "0f00874391239a1918a0fc1c17ac4309a528b6c31f54b0db1f9b7acf", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_bool-330223a.stdout b/tests/reference/asr-test_builtin_bool-330223a.stdout index 12dd45abdb..0cd0890093 100644 --- a/tests/reference/asr-test_builtin_bool-330223a.stdout +++ b/tests/reference/asr-test_builtin_bool-330223a.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 test_bool () [] ())] Source Public Implementation () .false. .false.), bool@__lpython_overloaded_0__bool: (ExternalSymbol 1 bool@__lpython_overloaded_0__bool 4 __lpython_overloaded_0__bool lpython_builtin [] __lpython_overloaded_0__bool Public), bool@__lpython_overloaded_1__bool: (ExternalSymbol 1 bool@__lpython_overloaded_1__bool 4 __lpython_overloaded_1__bool lpython_builtin [] __lpython_overloaded_1__bool Public), bool@__lpython_overloaded_2__bool: (ExternalSymbol 1 bool@__lpython_overloaded_2__bool 4 __lpython_overloaded_2__bool lpython_builtin [] __lpython_overloaded_2__bool Public), bool@__lpython_overloaded_3__bool: (ExternalSymbol 1 bool@__lpython_overloaded_3__bool 4 __lpython_overloaded_3__bool lpython_builtin [] __lpython_overloaded_3__bool Public), bool@__lpython_overloaded_4__bool: (ExternalSymbol 1 bool@__lpython_overloaded_4__bool 4 __lpython_overloaded_4__bool lpython_builtin [] __lpython_overloaded_4__bool Public), bool@__lpython_overloaded_5__bool: (ExternalSymbol 1 bool@__lpython_overloaded_5__bool 4 __lpython_overloaded_5__bool lpython_builtin [] __lpython_overloaded_5__bool Public), bool@__lpython_overloaded_6__bool: (ExternalSymbol 1 bool@__lpython_overloaded_6__bool 4 __lpython_overloaded_6__bool lpython_builtin [] __lpython_overloaded_6__bool Public), bool@__lpython_overloaded_7__bool: (ExternalSymbol 1 bool@__lpython_overloaded_7__bool 4 __lpython_overloaded_7__bool lpython_builtin [] __lpython_overloaded_7__bool Public), bool@__lpython_overloaded_8__bool: (ExternalSymbol 1 bool@__lpython_overloaded_8__bool 4 __lpython_overloaded_8__bool lpython_builtin [] __lpython_overloaded_8__bool Public), bool@__lpython_overloaded_9__bool: (ExternalSymbol 1 bool@__lpython_overloaded_9__bool 4 __lpython_overloaded_9__bool lpython_builtin [] __lpython_overloaded_9__bool Public), complex@__lpython_overloaded_13__complex: (ExternalSymbol 1 complex@__lpython_overloaded_13__complex 4 __lpython_overloaded_13__complex lpython_builtin [] __lpython_overloaded_13__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 4 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_bool: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), a2: (Variable 2 a2 Local () () Default (Integer 8 []) Source Public Required .false.), a3: (Variable 2 a3 Local () () Default (Integer 1 []) Source Public Required .false.), a4: (Variable 2 a4 Local () () Default (Integer 2 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), bool: (ExternalSymbol 2 bool 4 bool lpython_builtin [] bool Private), c: (Variable 2 c Local () () Default (Complex 4 []) Source Public Required .false.), c1: (Variable 2 c1 Local () () Default (Complex 8 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 4 complex lpython_builtin [] complex Private), f: (Variable 2 f Local () () Default (Real 8 []) Source Public Required .false.), f2: (Variable 2 f2 Local () () Default (Real 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_bool [] [(= (Var 2 a) (IntegerConstant 34 (Integer 4 [])) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_0__bool 2 bool [((Var 2 a))] (Logical 4 []) () ()) ()) (= (Var 2 a) (IntegerConstant 0 (Integer 4 [])) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_0__bool 2 bool [((Var 2 a))] (Logical 4 []) () ()) (Logical 4 []) ()) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_0__bool 2 bool [((UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))))] (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_0__bool 2 bool [((IntegerConstant 0 (Integer 4 [])))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a2) (Cast (IntegerConstant 34 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_1__bool 2 bool [((Var 2 a2))] (Logical 4 []) () ()) ()) (= (Var 2 a3) (Cast (IntegerConstant 34 (Integer 4 [])) IntegerToInteger (Integer 1 []) ()) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_2__bool 2 bool [((Var 2 a3))] (Logical 4 []) () ()) ()) (= (Var 2 a4) (Cast (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) IntegerToInteger (Integer 2 []) ()) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_3__bool 2 bool [((Var 2 a4))] (Logical 4 []) () ()) ()) (= (Var 2 f) (RealConstant 0.000000 (Real 8 [])) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_5__bool 2 bool [((Var 2 f))] (Logical 4 []) () ()) (Logical 4 []) ()) ()) (= (Var 2 f) (RealConstant 1.000000 (Real 8 [])) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_5__bool 2 bool [((Var 2 f))] (Logical 4 []) () ()) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_5__bool 2 bool [((RealConstant 56.786866 (Real 8 [])))] (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_5__bool 2 bool [((RealConstant 0.000000 (Real 8 [])))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 f2) (Cast (UnaryOp USub (RealConstant 235.600000 (Real 8 [])) (Real 8 []) (RealConstant -235.600000 (Real 8 []))) RealToReal (Real 4 []) (RealConstant -235.600000 (Real 4 []))) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_4__bool 2 bool [((Var 2 f2))] (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "" (Character 1 0 () [])) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_6__bool 2 bool [((Var 2 s))] (Logical 4 []) () ()) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "str" (Character 1 3 () [])) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_6__bool 2 bool [((Var 2 s))] (Logical 4 []) () ()) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_6__bool 2 bool [((StringConstant "" (Character 1 0 () [])))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_6__bool 2 bool [((StringConstant "str" (Character 1 3 () [])))] (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_7__bool 2 bool [((Var 2 b))] (Logical 4 []) () ()) ()) (= (Var 2 b) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_7__bool 2 bool [((Var 2 b))] (Logical 4 []) () ()) (Logical 4 []) ()) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_7__bool 2 bool [((LogicalConstant .true. (Logical 4 [])))] (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_7__bool 2 bool [((LogicalConstant .false. (Logical 4 [])))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 2.000000 3.000000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 2.000000 3.000000 (Complex 4 []))) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_8__bool 2 bool [((Var 2 c))] (Logical 4 []) () ()) ()) (= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 0.000000 0.000000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 0.000000 0.000000 (Complex 4 []))) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_8__bool 2 bool [((Var 2 c))] (Logical 4 []) () ()) (Logical 4 []) ()) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_9__bool 2 bool [((BinOp (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 0.000000 0.000000 (Complex 8 []))) Add (ComplexConstant 0.000000 0.000000 (Complex 8 [])) (Complex 8 []) (ComplexConstant 0.000000 0.000000 (Complex 8 [])) ()))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 c1) (FunctionCall 1 complex@__lpython_overloaded_13__complex 2 complex [((IntegerConstant 0 (Integer 4 []))) ((RealConstant 0.100202 (Real 8 [])))] (Complex 8 []) (ComplexConstant 0.000000 0.100202 (Complex 8 [])) ()) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_9__bool 2 bool [((Var 2 c1))] (Logical 4 []) () ()) ()) (Assert (UnaryOp Not (FunctionCall 1 bool@__lpython_overloaded_9__bool 2 bool [((FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 0.000000 0.000000 (Complex 8 [])) ()))] (Logical 4 []) (LogicalConstant .false. (Logical 4 [])) ()) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (FunctionCall 1 bool@__lpython_overloaded_9__bool 2 bool [((BinOp (Cast (IntegerConstant 3 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 3.000000 0.000000 (Complex 8 []))) Add (ComplexConstant 0.000000 5.000000 (Complex 8 [])) (Complex 8 []) (ComplexConstant 3.000000 5.000000 (Complex 8 [])) ()))] (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 test_bool () [] ())] Source Public Implementation () .false. .false.), complex@__lpython_overloaded_13__complex: (ExternalSymbol 1 complex@__lpython_overloaded_13__complex 4 __lpython_overloaded_13__complex lpython_builtin [] __lpython_overloaded_13__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 4 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_bool: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), a2: (Variable 2 a2 Local () () Default (Integer 8 []) Source Public Required .false.), a3: (Variable 2 a3 Local () () Default (Integer 1 []) Source Public Required .false.), a4: (Variable 2 a4 Local () () Default (Integer 2 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Complex 4 []) Source Public Required .false.), c1: (Variable 2 c1 Local () () Default (Complex 8 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 4 complex lpython_builtin [] complex Private), f: (Variable 2 f Local () () Default (Real 8 []) Source Public Required .false.), f2: (Variable 2 f2 Local () () Default (Real 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_bool [] [(= (Var 2 a) (IntegerConstant 34 (Integer 4 [])) ()) (Assert (Cast (Var 2 a) IntegerToLogical (Logical 4 []) ()) ()) (= (Var 2 a) (IntegerConstant 0 (Integer 4 [])) ()) (Assert (LogicalNot (Cast (Var 2 a) IntegerToLogical (Logical 4 []) ()) (Logical 4 []) ()) ()) (Assert (Cast (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) IntegerToLogical (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (LogicalNot (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a2) (Cast (IntegerConstant 34 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (Assert (Cast (Var 2 a2) IntegerToLogical (Logical 4 []) ()) ()) (= (Var 2 a3) (Cast (IntegerConstant 34 (Integer 4 [])) IntegerToInteger (Integer 1 []) ()) ()) (Assert (Cast (Var 2 a3) IntegerToLogical (Logical 4 []) ()) ()) (= (Var 2 a4) (Cast (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) IntegerToInteger (Integer 2 []) ()) ()) (Assert (Cast (Var 2 a4) IntegerToLogical (Logical 4 []) ()) ()) (= (Var 2 f) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) (Assert (LogicalNot (Cast (Var 2 f) RealToLogical (Logical 4 []) ()) (Logical 4 []) ()) ()) (= (Var 2 f) (RealConstant 1.00000000000000000e+00 (Real 8 [])) ()) (Assert (Cast (Var 2 f) RealToLogical (Logical 4 []) ()) ()) (Assert (Cast (RealConstant 5.67868658000000011e+01 (Real 8 [])) RealToLogical (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (LogicalNot (Cast (RealConstant 0.00000000000000000e+00 (Real 8 [])) RealToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 f2) (Cast (RealUnaryMinus (RealConstant 2.35599999999999994e+02 (Real 8 [])) (Real 8 []) (RealConstant -2.35599999999999994e+02 (Real 8 []))) RealToReal (Real 4 []) (RealConstant -2.35599999999999994e+02 (Real 4 []))) ()) (Assert (Cast (Var 2 f2) RealToLogical (Logical 4 []) ()) ()) (= (Var 2 f2) (Cast (RealConstant 5.33999999999999969e-05 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.33999999999999969e-05 (Real 4 []))) ()) (Assert (Cast (Var 2 f2) RealToLogical (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "" (Character 1 0 () [])) ()) (Assert (LogicalNot (Cast (Var 2 s) CharacterToLogical (Logical 4 []) ()) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "str" (Character 1 3 () [])) ()) (Assert (Cast (Var 2 s) CharacterToLogical (Logical 4 []) ()) ()) (Assert (LogicalNot (Cast (StringConstant "" (Character 1 0 () [])) CharacterToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (Cast (StringConstant "str" (Character 1 3 () [])) CharacterToLogical (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (Assert (Var 2 b) ()) (= (Var 2 b) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (LogicalNot (Var 2 b) (Logical 4 []) ()) ()) (Assert (LogicalConstant .true. (Logical 4 [])) ()) (Assert (LogicalNot (LogicalConstant .false. (Logical 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 2.00000000000000000e+00 3.00000000000000000e+00 (Complex 4 []))) ()) (Assert (Cast (Var 2 c) ComplexToLogical (Logical 4 []) ()) ()) (= (Var 2 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 4 []))) ()) (Assert (LogicalNot (Cast (Var 2 c) ComplexToLogical (Logical 4 []) ()) (Logical 4 []) ()) ()) (Assert (LogicalNot (Cast (ComplexBinOp (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) ComplexToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 c1) (FunctionCall 1 complex@__lpython_overloaded_13__complex 2 complex [((IntegerConstant 0 (Integer 4 []))) ((RealConstant 1.00201999999999999e-01 (Real 8 [])))] (Complex 8 []) (ComplexConstant 0.00000000000000000e+00 1.00201999999999999e-01 (Complex 8 [])) ()) ()) (Assert (Cast (Var 2 c1) ComplexToLogical (Logical 4 []) ()) ()) (Assert (LogicalNot (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 [])) ()) ComplexToLogical (Logical 4 []) (LogicalConstant .false. (Logical 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (Cast (ComplexBinOp (Cast (IntegerConstant 3 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 []))) ComplexToLogical (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_float-20601dd.json b/tests/reference/asr-test_builtin_float-20601dd.json index 22585f6377..b54fcb8368 100644 --- a/tests/reference/asr-test_builtin_float-20601dd.json +++ b/tests/reference/asr-test_builtin_float-20601dd.json @@ -2,11 +2,11 @@ "basename": "asr-test_builtin_float-20601dd", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/test_builtin_float.py", - "infile_hash": "98ef04ee76f3e5b962137f5df3dedf69fbb8c2db89e1c67ffee1bd47", + "infile_hash": "824d2ab2d647bb8c1b02dd47a04dfa7b8849dd4bd407c7b5aef6305c", "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_float-20601dd.stdout", - "stdout_hash": "e44c187ca84c6a0a6077fa20b63d30cbd52de6ce1bd3f5aeedc278a1", + "stdout_hash": "462dd29e0093794d80c4811389a24d57fbe579439d5456e46783591b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_float-20601dd.stdout b/tests/reference/asr-test_builtin_float-20601dd.stdout index 5affbba511..0cef6d00c9 100644 --- a/tests/reference/asr-test_builtin_float-20601dd.stdout +++ b/tests/reference/asr-test_builtin_float-20601dd.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 test_float () [] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_float: (Subroutine (SymbolTable 2 {i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_float [] [(= (Var 2 i) (IntegerConstant 34 (Integer 4 [])) ()) (Assert (Compare (RealConstant 0.000000 (Real 8 [])) Eq (RealConstant 0.000000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (IntegerConstant 34 (Integer 4 [])) IntegerToReal (Real 8 []) (RealConstant 34.000000 (Real 8 []))) Eq (RealConstant 34.000000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (Var 2 i) IntegerToReal (Real 8 []) ()) Eq (RealConstant 34.000000 (Real 8 [])) (Logical 4 []) () ()) ()) (= (Var 2 i) (UnaryOp USub (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) ()) (Assert (Compare (Cast (UnaryOp USub (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant -4235.000000 (Real 8 []))) Eq (UnaryOp USub (RealConstant 4235.000000 (Real 8 [])) (Real 8 []) (RealConstant -4235.000000 (Real 8 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (IntegerConstant 34 (Integer 4 [])) IntegerToReal (Real 8 []) (RealConstant 34.000000 (Real 8 []))) Eq (RealConstant 34.000000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (UnaryOp USub (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant -4235.000000 (Real 8 []))) Eq (UnaryOp USub (RealConstant 4235.000000 (Real 8 [])) (Real 8 []) (RealConstant -4235.000000 (Real 8 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 1 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant 1.000000 (Real 8 []))) Eq (RealConstant 1.000000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant 0.000000 (Real 8 []))) Eq (RealConstant 0.000000 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 test_float () [] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_float: (Subroutine (SymbolTable 2 {b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), f: (Variable 2 f Local () () Default (Real 8 []) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_float [] [(= (Var 2 i) (IntegerConstant 34 (Integer 4 [])) ()) (Assert (RealCompare (RealConstant 0.00000000000000000e+00 (Real 8 [])) Eq (RealConstant 0.00000000000000000e+00 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (RealCompare (Cast (IntegerConstant 34 (Integer 4 [])) IntegerToReal (Real 8 []) (RealConstant 3.40000000000000000e+01 (Real 8 []))) Eq (RealConstant 3.40000000000000000e+01 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (RealCompare (Cast (Var 2 i) IntegerToReal (Real 8 []) ()) Eq (RealConstant 3.40000000000000000e+01 (Real 8 [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerUnaryMinus (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) ()) (Assert (RealCompare (Cast (IntegerUnaryMinus (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant -4.23500000000000000e+03 (Real 8 []))) Eq (RealUnaryMinus (RealConstant 4.23500000000000000e+03 (Real 8 [])) (Real 8 []) (RealConstant -4.23500000000000000e+03 (Real 8 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (RealCompare (Cast (IntegerConstant 34 (Integer 4 [])) IntegerToReal (Real 8 []) (RealConstant 3.40000000000000000e+01 (Real 8 []))) Eq (RealConstant 3.40000000000000000e+01 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (RealCompare (Cast (IntegerUnaryMinus (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) IntegerToReal (Real 8 []) (RealConstant -4.23500000000000000e+03 (Real 8 []))) Eq (RealUnaryMinus (RealConstant 4.23500000000000000e+03 (Real 8 [])) (Real 8 []) (RealConstant -4.23500000000000000e+03 (Real 8 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (RealCompare (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToReal (Real 8 []) (RealConstant 1.00000000000000000e+00 (Real 8 []))) Eq (RealConstant 1.00000000000000000e+00 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (RealCompare (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToReal (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))) Eq (RealConstant 0.00000000000000000e+00 (Real 8 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 f) (Cast (Var 2 b) LogicalToReal (Real 8 []) ()) ()) (Assert (RealCompare (Var 2 f) Eq (RealConstant 1.00000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ()) (= (Var 2 b) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (RealCompare (Cast (Cast (Var 2 b) LogicalToInteger (Integer 4 []) ()) IntegerToReal (Real 8 []) ()) Eq (RealConstant 0.00000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_hex-64bd268.json b/tests/reference/asr-test_builtin_hex-64bd268.json index 171d12f1e9..3ff54a5ae7 100644 --- a/tests/reference/asr-test_builtin_hex-64bd268.json +++ b/tests/reference/asr-test_builtin_hex-64bd268.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_hex-64bd268.stdout", - "stdout_hash": "36bc32628917196579424e872a4788210ae67fabe317149970bcc08f", + "stdout_hash": "41608a29b58f6ad9c4ecd1b4c9f3b3c0b425bcd85aff9ed9a595493c", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_hex-64bd268.stdout b/tests/reference/asr-test_builtin_hex-64bd268.stdout index 87b1e23aad..6319d672c7 100644 --- a/tests/reference/asr-test_builtin_hex-64bd268.stdout +++ b/tests/reference/asr-test_builtin_hex-64bd268.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 test_hex () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_hex: (Subroutine (SymbolTable 2 {hex: (ExternalSymbol 2 hex 4 hex lpython_builtin [] hex Private), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_hex [] [(= (Var 2 i) (IntegerConstant 34 (Integer 4 [])) ()) (Assert (Compare (FunctionCall 2 hex () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "0x22" (Character 1 4 () [])) (Logical 4 []) () ()) ()) (= (Var 2 i) (UnaryOp USub (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) ()) (Assert (Compare (FunctionCall 2 hex () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "-0x108b" (Character 1 7 () [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 hex () [((IntegerConstant 34 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0x22" (Character 1 1 () [])) ()) Eq (StringConstant "0x22" (Character 1 4 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 2 hex () [((UnaryOp USub (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0x108b" (Character 1 1 () [])) ()) Eq (StringConstant "-0x108b" (Character 1 7 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 test_hex () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_hex: (Subroutine (SymbolTable 2 {hex: (ExternalSymbol 2 hex 4 hex lpython_builtin [] hex Private), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.)}) test_hex [] [(= (Var 2 i) (IntegerConstant 34 (Integer 4 [])) ()) (Assert (StringCompare (FunctionCall 2 hex () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "0x22" (Character 1 4 () [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerUnaryMinus (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) ()) (Assert (StringCompare (FunctionCall 2 hex () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "-0x108b" (Character 1 7 () [])) (Logical 4 []) ()) ()) (Assert (StringCompare (FunctionCall 2 hex () [((IntegerConstant 34 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0x22" (Character 1 1 () [])) ()) Eq (StringConstant "0x22" (Character 1 4 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (FunctionCall 2 hex () [((IntegerUnaryMinus (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0x108b" (Character 1 1 () [])) ()) Eq (StringConstant "-0x108b" (Character 1 7 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_int-8f88fdc.json b/tests/reference/asr-test_builtin_int-8f88fdc.json index 1db8367dca..dc295131ef 100644 --- a/tests/reference/asr-test_builtin_int-8f88fdc.json +++ b/tests/reference/asr-test_builtin_int-8f88fdc.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_int-8f88fdc.stdout", - "stdout_hash": "0dcd8288c641bdbd9ed9a9d589d381fbc005cf061182cecfe6f52798", + "stdout_hash": "3c4ed96b7f702170610cfe9a7c42b1f632522e31538d044c05165306", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_int-8f88fdc.stdout b/tests/reference/asr-test_builtin_int-8f88fdc.stdout index cd863b413d..ced252689e 100644 --- a/tests/reference/asr-test_builtin_int-8f88fdc.stdout +++ b/tests/reference/asr-test_builtin_int-8f88fdc.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 6 {}) _lpython_main_program [] [(SubroutineCall 1 check_all () [] ())] Source Public Implementation () .false. .false.), check_all: (Subroutine (SymbolTable 4 {}) check_all [] [(SubroutineCall 1 test_int () [] ()) (SubroutineCall 1 test_bool_to_int () [] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 5 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_bool_to_int: (Subroutine (SymbolTable 3 {b: (Variable 3 b Local () () Default (Integer 4 []) Source Public Required .false.)}) test_bool_to_int [] [(= (Var 3 b) (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (BinOp (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 3 b) (BinOp (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (BinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) (Integer 4 []) () ()) Sub (BinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) () ()) (Integer 4 []) () ()) ()) (Assert (Compare (Var 3 b) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) () ()) ())] Source Public Implementation () .false. .false.), test_int: (Subroutine (SymbolTable 2 {f: (Variable 2 f Local () () Default (Real 8 []) Source Public Required .false.)}) test_int [] [(= (Var 2 f) (RealConstant 5.678000 (Real 8 [])) ()) (Assert (Compare (IntegerConstant 0 (Integer 4 [])) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (RealConstant 5.678000 (Real 8 [])) RealToInteger (Integer 4 []) (IntegerConstant 5 (Integer 4 []))) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (Var 2 f) RealToInteger (Integer 4 []) ()) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 f) (UnaryOp USub (RealConstant 183745.230000 (Real 8 [])) (Real 8 []) (RealConstant -183745.230000 (Real 8 []))) ()) (Assert (Compare (Cast (UnaryOp USub (RealConstant 183745.230000 (Real 8 [])) (Real 8 []) (RealConstant -183745.230000 (Real 8 []))) RealToInteger (Integer 4 []) (IntegerConstant -183745 (Integer 4 []))) Eq (UnaryOp USub (IntegerConstant 183745 (Integer 4 [])) (Integer 4 []) (IntegerConstant -183745 (Integer 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (Var 2 f) RealToInteger (Integer 4 []) ()) Eq (UnaryOp USub (IntegerConstant 183745 (Integer 4 [])) (Integer 4 []) (IntegerConstant -183745 (Integer 4 []))) (Logical 4 []) () ()) ()) (Assert (Compare (Cast (RealConstant 5.500000 (Real 8 [])) RealToInteger (Integer 4 []) (IntegerConstant 5 (Integer 4 []))) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (UnaryOp USub (RealConstant 5.500000 (Real 8 [])) (Real 8 []) (RealConstant -5.500000 (Real 8 []))) RealToInteger (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) Eq (UnaryOp USub (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 1 (Integer 4 []))) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 6 {}) _lpython_main_program [] [(SubroutineCall 1 check_all () [] ())] Source Public Implementation () .false. .false.), check_all: (Subroutine (SymbolTable 4 {}) check_all [] [(SubroutineCall 1 test_int () [] ()) (SubroutineCall 1 test_bool_to_int () [] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 5 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_bool_to_int: (Subroutine (SymbolTable 3 {b: (Variable 3 b Local () () Default (Integer 4 []) Source Public Required .false.)}) test_bool_to_int [] [(= (Var 3 b) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (IntegerBinOp (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) Sub (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 3 b) (IntegerBinOp (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (IntegerBinOp (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) (Integer 4 []) ()) Sub (IntegerBinOp (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) Add (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) ()) (Integer 4 []) ()) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 3 b) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), test_int: (Subroutine (SymbolTable 2 {f: (Variable 2 f Local () () Default (Real 8 []) Source Public Required .false.)}) test_int [] [(= (Var 2 f) (RealConstant 5.67799999999999994e+00 (Real 8 [])) ()) (Assert (IntegerCompare (IntegerConstant 0 (Integer 4 [])) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Cast (RealConstant 5.67799999999999994e+00 (Real 8 [])) RealToInteger (Integer 4 []) (IntegerConstant 5 (Integer 4 []))) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Cast (Var 2 f) RealToInteger (Integer 4 []) ()) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 f) (RealUnaryMinus (RealConstant 1.83745230000000010e+05 (Real 8 [])) (Real 8 []) (RealConstant -1.83745230000000010e+05 (Real 8 []))) ()) (Assert (IntegerCompare (Cast (RealUnaryMinus (RealConstant 1.83745230000000010e+05 (Real 8 [])) (Real 8 []) (RealConstant -1.83745230000000010e+05 (Real 8 []))) RealToInteger (Integer 4 []) (IntegerConstant -183745 (Integer 4 []))) Eq (IntegerUnaryMinus (IntegerConstant 183745 (Integer 4 [])) (Integer 4 []) (IntegerConstant -183745 (Integer 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Cast (Var 2 f) RealToInteger (Integer 4 []) ()) Eq (IntegerUnaryMinus (IntegerConstant 183745 (Integer 4 [])) (Integer 4 []) (IntegerConstant -183745 (Integer 4 []))) (Logical 4 []) ()) ()) (Assert (IntegerCompare (Cast (RealConstant 5.50000000000000000e+00 (Real 8 [])) RealToInteger (Integer 4 []) (IntegerConstant 5 (Integer 4 []))) Eq (IntegerConstant 5 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Cast (RealUnaryMinus (RealConstant 5.50000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -5.50000000000000000e+00 (Real 8 []))) RealToInteger (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) Eq (IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Cast (LogicalConstant .true. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 1 (Integer 4 []))) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (Cast (LogicalConstant .false. (Logical 4 [])) LogicalToInteger (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_len-55b0dec.json b/tests/reference/asr-test_builtin_len-55b0dec.json index f9ad257442..76f31e7eda 100644 --- a/tests/reference/asr-test_builtin_len-55b0dec.json +++ b/tests/reference/asr-test_builtin_len-55b0dec.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_len-55b0dec.stdout", - "stdout_hash": "5848f4307a138db4aeb3df85134c377170b7bbbffdb4be980853260d", + "stdout_hash": "394cc4d2cbd71e5f20531c2fe9dc000123bad5b3cee108bd72c4d0a1", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_len-55b0dec.stdout b/tests/reference/asr-test_builtin_len-55b0dec.stdout index 64eacdf421..9979a4209f 100644 --- a/tests/reference/asr-test_builtin_len-55b0dec.stdout +++ b/tests/reference/asr-test_builtin_len-55b0dec.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 test_len () [] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_len: (Subroutine (SymbolTable 2 {s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_len [] [(= (Var 2 s) (StringConstant "abcd" (Character 1 4 () [])) ()) (Assert (Compare (StringLen (Var 2 s) (Integer 4 []) ()) Eq (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (StringConstant "" (Character 1 0 () [])) ()) (Assert (Compare (StringLen (Var 2 s) (Integer 4 []) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) ()) (Assert (Compare (StringLen (StringConstant "abcd" (Character 1 4 () [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 []))) Eq (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (StringLen (StringConstant "" (Character 1 0 () [])) (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 test_len () [] ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_len: (Subroutine (SymbolTable 2 {s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_len [] [(= (Var 2 s) (StringConstant "abcd" (Character 1 4 () [])) ()) (Assert (IntegerCompare (StringLen (Var 2 s) (Integer 4 []) ()) Eq (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 s) (StringConstant "" (Character 1 0 () [])) ()) (Assert (IntegerCompare (StringLen (Var 2 s) (Integer 4 []) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (StringLen (StringConstant "abcd" (Character 1 4 () [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 []))) Eq (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (StringLen (StringConstant "" (Character 1 0 () [])) (Integer 4 []) (IntegerConstant 0 (Integer 4 []))) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_oct-20b9066.json b/tests/reference/asr-test_builtin_oct-20b9066.json index 53aeaf1bbd..d94e3fea07 100644 --- a/tests/reference/asr-test_builtin_oct-20b9066.json +++ b/tests/reference/asr-test_builtin_oct-20b9066.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_oct-20b9066.stdout", - "stdout_hash": "e14d5015d4bb2be92a374be00ca92fcddd520b05f14f706d5cf8c17a", + "stdout_hash": "7117b271980109ef4e35778a40672fa8ce30018697e98b03d8ce8b53", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_oct-20b9066.stdout b/tests/reference/asr-test_builtin_oct-20b9066.stdout index 6fae380958..b8c25676b9 100644 --- a/tests/reference/asr-test_builtin_oct-20b9066.stdout +++ b/tests/reference/asr-test_builtin_oct-20b9066.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 test_oct () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_oct: (Subroutine (SymbolTable 2 {i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), oct: (ExternalSymbol 2 oct 4 oct lpython_builtin [] oct Private)}) test_oct [] [(= (Var 2 i) (IntegerConstant 34 (Integer 4 [])) ()) (Assert (Compare (FunctionCall 2 oct () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "0o42" (Character 1 4 () [])) (Logical 4 []) () ()) ()) (= (Var 2 i) (UnaryOp USub (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) ()) (Assert (Compare (FunctionCall 2 oct () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "-0o10213" (Character 1 8 () [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 oct () [((IntegerConstant 34 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0o42" (Character 1 1 () [])) ()) Eq (StringConstant "0o42" (Character 1 4 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 2 oct () [((UnaryOp USub (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0o10213" (Character 1 1 () [])) ()) Eq (StringConstant "-0o10213" (Character 1 8 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 test_oct () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_oct: (Subroutine (SymbolTable 2 {i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), oct: (ExternalSymbol 2 oct 4 oct lpython_builtin [] oct Private)}) test_oct [] [(= (Var 2 i) (IntegerConstant 34 (Integer 4 [])) ()) (Assert (StringCompare (FunctionCall 2 oct () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "0o42" (Character 1 4 () [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerUnaryMinus (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))) ()) (Assert (StringCompare (FunctionCall 2 oct () [((Var 2 i))] (Character 1 -2 () []) () ()) Eq (StringConstant "-0o10213" (Character 1 8 () [])) (Logical 4 []) ()) ()) (Assert (StringCompare (FunctionCall 2 oct () [((IntegerConstant 34 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "0o42" (Character 1 1 () [])) ()) Eq (StringConstant "0o42" (Character 1 4 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (FunctionCall 2 oct () [((IntegerUnaryMinus (IntegerConstant 4235 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4235 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-0o10213" (Character 1 1 () [])) ()) Eq (StringConstant "-0o10213" (Character 1 8 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_pow-f02fcda.json b/tests/reference/asr-test_builtin_pow-f02fcda.json index ea4f32f9f6..b88e28a54b 100644 --- a/tests/reference/asr-test_builtin_pow-f02fcda.json +++ b/tests/reference/asr-test_builtin_pow-f02fcda.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_pow-f02fcda.stdout", - "stdout_hash": "dbb4ceee118828e7bbefe832a6176b58f39c2b4d8e886a031cf2ca46", + "stdout_hash": "30f3b3177706508b18e864fdd9820f074fb37634bfc963cb0544e082", "stderr": "asr-test_builtin_pow-f02fcda.stderr", "stderr_hash": "180e1adfbb0d9c63a2fffa31951bbd629b3f1950cf0d97ca1389efe5", "returncode": 0 diff --git a/tests/reference/asr-test_builtin_pow-f02fcda.stdout b/tests/reference/asr-test_builtin_pow-f02fcda.stdout index b66a705dfc..66602343f8 100644 --- a/tests/reference/asr-test_builtin_pow-f02fcda.stdout +++ b/tests/reference/asr-test_builtin_pow-f02fcda.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 test_pow () [] ())] Source Public Implementation () .false. .false.), abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 4 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 4 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), pow@__lpython_overloaded_0__pow: (ExternalSymbol 1 pow@__lpython_overloaded_0__pow 4 __lpython_overloaded_0__pow lpython_builtin [] __lpython_overloaded_0__pow Public), pow@__lpython_overloaded_1__pow: (ExternalSymbol 1 pow@__lpython_overloaded_1__pow 4 __lpython_overloaded_1__pow lpython_builtin [] __lpython_overloaded_1__pow Public), pow@__lpython_overloaded_2__pow: (ExternalSymbol 1 pow@__lpython_overloaded_2__pow 4 __lpython_overloaded_2__pow lpython_builtin [] __lpython_overloaded_2__pow Public), pow@__lpython_overloaded_3__pow: (ExternalSymbol 1 pow@__lpython_overloaded_3__pow 4 __lpython_overloaded_3__pow lpython_builtin [] __lpython_overloaded_3__pow Public), pow@__lpython_overloaded_4__pow: (ExternalSymbol 1 pow@__lpython_overloaded_4__pow 4 __lpython_overloaded_4__pow lpython_builtin [] __lpython_overloaded_4__pow Public), pow@__lpython_overloaded_5__pow: (ExternalSymbol 1 pow@__lpython_overloaded_5__pow 4 __lpython_overloaded_5__pow lpython_builtin [] __lpython_overloaded_5__pow Public), pow@__lpython_overloaded_6__pow: (ExternalSymbol 1 pow@__lpython_overloaded_6__pow 4 __lpython_overloaded_6__pow lpython_builtin [] __lpython_overloaded_6__pow Public), pow@__lpython_overloaded_7__pow: (ExternalSymbol 1 pow@__lpython_overloaded_7__pow 4 __lpython_overloaded_7__pow lpython_builtin [] __lpython_overloaded_7__pow Public), pow@__lpython_overloaded_8__pow: (ExternalSymbol 1 pow@__lpython_overloaded_8__pow 4 __lpython_overloaded_8__pow lpython_builtin [] __lpython_overloaded_8__pow Public), pow@__lpython_overloaded_9__pow: (ExternalSymbol 1 pow@__lpython_overloaded_9__pow 4 __lpython_overloaded_9__pow lpython_builtin [] __lpython_overloaded_9__pow Public), test_pow: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), a1: (Variable 2 a1 Local () (RealConstant 4.500000 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), a2: (Variable 2 a2 Local () (RealConstant 2.300000 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), abs: (ExternalSymbol 2 abs 4 abs lpython_builtin [] abs Private), b: (Variable 2 b Local () () Default (Integer 4 []) Source Public Required .false.), b1: (Variable 2 b1 Local () (LogicalConstant .true. (Logical 4 [])) Default (Logical 4 []) Source Public Required .false.), b2: (Variable 2 b2 Local () (LogicalConstant .false. (Logical 4 [])) Default (Logical 4 []) Source Public Required .false.), c1: (Variable 2 c1 Local () () Default (Complex 4 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 4 complex lpython_builtin [] complex Private), eps: (Variable 2 eps Local () () Default (Real 8 []) Source Public Required .false.), f1: (Variable 2 f1 Local () () Default (Real 4 []) Source Public Required .false.), f2: (Variable 2 f2 Local () () Default (Real 4 []) Source Public Required .false.), i1: (Variable 2 i1 Local () () Default (Integer 8 []) Source Public Required .false.), i2: (Variable 2 i2 Local () () Default (Integer 8 []) Source Public Required .false.), p: (Variable 2 p Local () () Default (Real 4 []) Source Public Required .false.), pow: (ExternalSymbol 2 pow 4 pow lpython_builtin [] pow Private), x: (Variable 2 x Local () (IntegerConstant 3 (Integer 4 [])) Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () (RealConstant 2.300000 (Real 8 [])) Default (Real 8 []) Source Public Required .false.)}) test_pow [] [(= (Var 2 eps) (RealConstant 0.000000 (Real 8 [])) ()) (= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (IntegerConstant 5 (Integer 4 [])) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((Var 2 a)) ((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 32 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 a) (IntegerConstant 6 (Integer 4 [])) ()) (= (Var 2 b) (IntegerConstant 3 (Integer 4 [])) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((Var 2 a)) ((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 216 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (IntegerConstant 0 (Integer 4 [])) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((Var 2 a)) ((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) ()) (= (Var 2 a) (IntegerConstant 6 (Integer 4 [])) ()) (= (Var 2 b) (UnaryOp USub (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))) ()) (= (Var 2 i1) (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 2 i2) (Cast (IntegerConstant 5 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_1__pow 2 pow [((Var 2 i1)) ((Var 2 i2))] (Integer 8 []) () ()) Eq (Cast (IntegerConstant 32 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) () ()) ()) (= (Var 2 i1) (Cast (IntegerConstant 6 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 2 i2) (Cast (UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 2 f1) (Cast (BinOp (Cast (IntegerConstant 525346 (Integer 4 [])) IntegerToReal (Real 8 []) ()) Div (Cast (IntegerConstant 66456 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) () ()) RealToReal (Real 4 []) ()) ()) (= (Var 2 f2) (Cast (RealConstant 3.000000 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.000000 (Real 4 []))) ()) (= (Var 2 p) (FunctionCall 1 pow@__lpython_overloaded_2__pow 2 pow [((Var 2 f1)) ((Var 2 f2))] (Real 4 []) () ()) ()) (= (Var 2 f1) (FunctionCall 1 pow@__lpython_overloaded_4__pow 2 pow [((Var 2 a)) ((Var 2 f2))] (Real 4 []) () ()) ()) (= (Var 2 f1) (FunctionCall 1 pow@__lpython_overloaded_5__pow 2 pow [((Var 2 f2)) ((Var 2 a))] (Real 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_8__pow 2 pow [((Var 2 b1)) ((Var 2 b2))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_8__pow 2 pow [((Var 2 b2)) ((Var 2 b1))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_8__pow 2 pow [((Var 2 b1)) ((Var 2 b2))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_8__pow 2 pow [((LogicalConstant .false. (Logical 4 []))) ((LogicalConstant .false. (Logical 4 [])))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((Var 2 a1)) ((Var 2 a2))] (Real 8 []) (RealConstant 31.797193 (Real 8 [])) ()) Sub (RealConstant 31.797193 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((Var 2 a2)) ((Var 2 a1))] (Real 8 []) (RealConstant 42.439989 (Real 8 [])) ()) Sub (RealConstant 42.439989 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_6__pow 2 pow [((Var 2 x)) ((Var 2 y))] (Real 8 []) (RealConstant 12.513503 (Real 8 [])) ()) Sub (RealConstant 12.513503 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_7__pow 2 pow [((Var 2 y)) ((Var 2 x))] (Real 8 []) (RealConstant 12.167000 (Real 8 [])) ()) Sub (RealConstant 12.167000 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_6__pow 2 pow [((Var 2 x)) ((RealConstant 5.500000 (Real 8 [])))] (Real 8 []) (RealConstant 420.888346 (Real 8 [])) ()) Sub (RealConstant 420.888346 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (Cast (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))))] (Integer 4 []) (RealConstant 0.500000 (Real 8 [])) ()) IntegerToReal (Real 8 []) ()) Sub (RealConstant 0.500000 (Real 8 [])) (Real 8 []) () ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (Cast (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 6 (Integer 4 []))) ((UnaryOp USub (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))))] (Integer 4 []) (RealConstant 0.000772 (Real 8 [])) ()) IntegerToReal (Real 8 []) ()) Sub (RealConstant 0.000772 (Real 8 [])) (Real 8 []) () ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (Cast (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 [])))) ((UnaryOp USub (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))))] (Integer 4 []) (RealConstant -0.004115 (Real 8 [])) ()) IntegerToReal (Real 8 []) ()) Add (RealConstant 0.004115 (Real 8 [])) (Real 8 []) () ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (Cast (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 6 (Integer 4 []))) ((UnaryOp USub (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))))] (Integer 4 []) (RealConstant 0.000772 (Real 8 [])) ()) IntegerToReal (Real 8 []) ()) Sub (RealConstant 0.000772 (Real 8 [])) (Real 8 []) () ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((RealConstant 4.500000 (Real 8 []))) ((RealConstant 2.300000 (Real 8 [])))] (Real 8 []) (RealConstant 31.797193 (Real 8 [])) ()) Sub (RealConstant 31.797193 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((RealConstant 2.300000 (Real 8 []))) ((RealConstant 0.000000 (Real 8 [])))] (Real 8 []) (RealConstant 1.000000 (Real 8 [])) ()) Sub (RealConstant 1.000000 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((RealConstant 2.300000 (Real 8 []))) ((UnaryOp USub (RealConstant 1.500000 (Real 8 [])) (Real 8 []) (RealConstant -1.500000 (Real 8 []))))] (Real 8 []) (RealConstant 0.286687 (Real 8 [])) ()) Sub (RealConstant 0.286687 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_6__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((RealConstant 3.400000 (Real 8 [])))] (Real 8 []) (RealConstant 10.556063 (Real 8 [])) ()) Sub (RealConstant 10.556063 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_6__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((UnaryOp USub (RealConstant 3.400000 (Real 8 [])) (Real 8 []) (RealConstant -3.400000 (Real 8 []))))] (Real 8 []) (RealConstant 0.094732 (Real 8 [])) ()) Sub (RealConstant 0.094732 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_7__pow 2 pow [((RealConstant 3.400000 (Real 8 []))) ((IntegerConstant 9 (Integer 4 [])))] (Real 8 []) (RealConstant 60716.992766 (Real 8 [])) ()) Sub (RealConstant 60716.992766 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_7__pow 2 pow [((RealConstant 0.000000 (Real 8 []))) ((IntegerConstant 53 (Integer 4 [])))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Sub (RealConstant 0.000000 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 16 (Integer 4 [])) ()) Eq (IntegerConstant 16 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((BinOp (FunctionCall 1 pow@__lpython_overloaded_7__pow 2 pow [((UnaryOp USub (RealConstant 4235.000000 (Real 8 [])) (Real 8 []) (RealConstant -4235.000000 (Real 8 [])))) ((IntegerConstant 52 (Integer 4 [])))] (Real 8 []) (RealConstant 394800380598526378720936476336799774273305305904443955996320177992404102454228192853661558132283280490733920647962082901303487965679010854404517306573035287122910924343151116372519789002752.000000 (Real 8 [])) ()) Sub (RealConstant 394800380598526378720936476336799774273305305904443955996320177992404102454228192853661558132283280490733920647962082901303487965679010854404517306573035287122910924343151116372519789002752.000000 (Real 8 [])) (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()))] (Real 8 []) (RealConstant 0.000000 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) () ()) ()) (= (Var 2 c1) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 4.000000 5.000000 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 4.000000 5.000000 (Complex 4 []))) ()) (= (Var 2 c1) (FunctionCall 1 pow@__lpython_overloaded_9__pow 2 pow [((Var 2 c1)) ((IntegerConstant 4 (Integer 4 [])))] (Complex 4 []) () ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 test_pow () [] ())] Source Public Implementation () .false. .false.), abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 4 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 4 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), pow@__lpython_overloaded_0__pow: (ExternalSymbol 1 pow@__lpython_overloaded_0__pow 4 __lpython_overloaded_0__pow lpython_builtin [] __lpython_overloaded_0__pow Public), pow@__lpython_overloaded_1__pow: (ExternalSymbol 1 pow@__lpython_overloaded_1__pow 4 __lpython_overloaded_1__pow lpython_builtin [] __lpython_overloaded_1__pow Public), pow@__lpython_overloaded_2__pow: (ExternalSymbol 1 pow@__lpython_overloaded_2__pow 4 __lpython_overloaded_2__pow lpython_builtin [] __lpython_overloaded_2__pow Public), pow@__lpython_overloaded_3__pow: (ExternalSymbol 1 pow@__lpython_overloaded_3__pow 4 __lpython_overloaded_3__pow lpython_builtin [] __lpython_overloaded_3__pow Public), pow@__lpython_overloaded_4__pow: (ExternalSymbol 1 pow@__lpython_overloaded_4__pow 4 __lpython_overloaded_4__pow lpython_builtin [] __lpython_overloaded_4__pow Public), pow@__lpython_overloaded_5__pow: (ExternalSymbol 1 pow@__lpython_overloaded_5__pow 4 __lpython_overloaded_5__pow lpython_builtin [] __lpython_overloaded_5__pow Public), pow@__lpython_overloaded_6__pow: (ExternalSymbol 1 pow@__lpython_overloaded_6__pow 4 __lpython_overloaded_6__pow lpython_builtin [] __lpython_overloaded_6__pow Public), pow@__lpython_overloaded_7__pow: (ExternalSymbol 1 pow@__lpython_overloaded_7__pow 4 __lpython_overloaded_7__pow lpython_builtin [] __lpython_overloaded_7__pow Public), pow@__lpython_overloaded_8__pow: (ExternalSymbol 1 pow@__lpython_overloaded_8__pow 4 __lpython_overloaded_8__pow lpython_builtin [] __lpython_overloaded_8__pow Public), pow@__lpython_overloaded_9__pow: (ExternalSymbol 1 pow@__lpython_overloaded_9__pow 4 __lpython_overloaded_9__pow lpython_builtin [] __lpython_overloaded_9__pow Public), test_pow: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), a1: (Variable 2 a1 Local () () Default (Real 8 []) Source Public Required .false.), a2: (Variable 2 a2 Local () () Default (Real 8 []) Source Public Required .false.), abs: (ExternalSymbol 2 abs 4 abs lpython_builtin [] abs Private), b: (Variable 2 b Local () () Default (Integer 4 []) Source Public Required .false.), b1: (Variable 2 b1 Local () () Default (Logical 4 []) Source Public Required .false.), b2: (Variable 2 b2 Local () () Default (Logical 4 []) Source Public Required .false.), c1: (Variable 2 c1 Local () () Default (Complex 4 []) Source Public Required .false.), complex: (ExternalSymbol 2 complex 4 complex lpython_builtin [] complex Private), eps: (Variable 2 eps Local () () Default (Real 8 []) Source Public Required .false.), f1: (Variable 2 f1 Local () () Default (Real 4 []) Source Public Required .false.), f2: (Variable 2 f2 Local () () Default (Real 4 []) Source Public Required .false.), i1: (Variable 2 i1 Local () () Default (Integer 8 []) Source Public Required .false.), i2: (Variable 2 i2 Local () () Default (Integer 8 []) Source Public Required .false.), p: (Variable 2 p Local () () Default (Real 4 []) Source Public Required .false.), pow: (ExternalSymbol 2 pow 4 pow lpython_builtin [] pow Private), x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 8 []) Source Public Required .false.)}) test_pow [] [(= (Var 2 eps) (RealConstant 9.99999999999999980e-13 (Real 8 [])) ()) (= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (IntegerConstant 5 (Integer 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((Var 2 a)) ((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 32 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 a) (IntegerConstant 6 (Integer 4 [])) ()) (= (Var 2 b) (IntegerConstant 3 (Integer 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((Var 2 a)) ((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 216 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (IntegerConstant 0 (Integer 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((Var 2 a)) ((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 a) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 b) (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) ()) (= (Var 2 a) (IntegerConstant 6 (Integer 4 [])) ()) (= (Var 2 b) (IntegerUnaryMinus (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))) ()) (= (Var 2 i1) (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 2 i2) (Cast (IntegerConstant 5 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_1__pow 2 pow [((Var 2 i1)) ((Var 2 i2))] (Integer 8 []) () ()) Eq (Cast (IntegerConstant 32 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) ()) (= (Var 2 i1) (Cast (IntegerConstant 6 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 2 i2) (Cast (IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 2 f1) (Cast (RealBinOp (Cast (IntegerConstant 525346 (Integer 4 [])) IntegerToReal (Real 8 []) ()) Div (Cast (IntegerConstant 66456 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) ()) RealToReal (Real 4 []) ()) ()) (= (Var 2 f2) (Cast (RealConstant 3.00000000000000000e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.00000000000000000e+00 (Real 4 []))) ()) (= (Var 2 p) (FunctionCall 1 pow@__lpython_overloaded_2__pow 2 pow [((Var 2 f1)) ((Var 2 f2))] (Real 4 []) () ()) ()) (= (Var 2 f1) (FunctionCall 1 pow@__lpython_overloaded_4__pow 2 pow [((Var 2 a)) ((Var 2 f2))] (Real 4 []) () ()) ()) (= (Var 2 f1) (FunctionCall 1 pow@__lpython_overloaded_5__pow 2 pow [((Var 2 f2)) ((Var 2 a))] (Real 4 []) () ()) ()) (= (Var 2 b1) (LogicalConstant .true. (Logical 4 [])) ()) (= (Var 2 b2) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_8__pow 2 pow [((Var 2 b1)) ((Var 2 b2))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_8__pow 2 pow [((Var 2 b2)) ((Var 2 b1))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_8__pow 2 pow [((Var 2 b1)) ((Var 2 b2))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_8__pow 2 pow [((LogicalConstant .false. (Logical 4 []))) ((LogicalConstant .false. (Logical 4 [])))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 a1) (RealConstant 4.50000000000000000e+00 (Real 8 [])) ()) (= (Var 2 a2) (RealConstant 2.29999999999999982e+00 (Real 8 [])) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((Var 2 a1)) ((Var 2 a2))] (Real 8 []) () ()) Sub (RealConstant 3.17971929089206000e+01 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((Var 2 a2)) ((Var 2 a1))] (Real 8 []) () ()) Sub (RealConstant 4.24399889427765871e+01 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (= (Var 2 x) (IntegerConstant 3 (Integer 4 [])) ()) (= (Var 2 y) (RealConstant 2.29999999999999982e+00 (Real 8 [])) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_6__pow 2 pow [((Var 2 x)) ((Var 2 y))] (Real 8 []) () ()) Sub (RealConstant 1.25135025328431819e+01 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_7__pow 2 pow [((Var 2 y)) ((Var 2 x))] (Real 8 []) () ()) Sub (RealConstant 1.21669999999999980e+01 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_6__pow 2 pow [((Var 2 x)) ((RealConstant 5.50000000000000000e+00 (Real 8 [])))] (Real 8 []) () ()) Sub (RealConstant 4.20888346239237194e+02 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (Cast (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))))] (Integer 4 []) (RealConstant 5.00000000000000000e-01 (Real 8 [])) ()) IntegerToReal (Real 8 []) ()) Sub (RealConstant 5.00000000000000000e-01 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (Cast (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 6 (Integer 4 []))) ((IntegerUnaryMinus (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))))] (Integer 4 []) (RealConstant 7.71604938271604895e-04 (Real 8 [])) ()) IntegerToReal (Real 8 []) ()) Sub (RealConstant 7.71604938271604895e-04 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (Cast (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 [])))) ((IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))))] (Integer 4 []) (RealConstant -4.11522633744856002e-03 (Real 8 [])) ()) IntegerToReal (Real 8 []) ()) Add (RealConstant 4.11522633744856002e-03 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (Cast (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 6 (Integer 4 []))) ((IntegerUnaryMinus (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 []))))] (Integer 4 []) (RealConstant 7.71604938271604895e-04 (Real 8 [])) ()) IntegerToReal (Real 8 []) ()) Sub (RealConstant 7.71604938271604895e-04 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((RealConstant 4.50000000000000000e+00 (Real 8 []))) ((RealConstant 2.29999999999999982e+00 (Real 8 [])))] (Real 8 []) (RealConstant 3.17971929089206000e+01 (Real 8 [])) ()) Sub (RealConstant 3.17971929089206000e+01 (Real 8 [])) (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((RealConstant 2.29999999999999982e+00 (Real 8 []))) ((RealConstant 0.00000000000000000e+00 (Real 8 [])))] (Real 8 []) (RealConstant 1.00000000000000000e+00 (Real 8 [])) ()) Sub (RealConstant 1.00000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_3__pow 2 pow [((RealConstant 2.29999999999999982e+00 (Real 8 []))) ((RealUnaryMinus (RealConstant 1.50000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -1.50000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 2.86687162345994395e-01 (Real 8 [])) ()) Sub (RealConstant 2.86687162345994395e-01 (Real 8 [])) (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_6__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((RealConstant 3.39999999999999991e+00 (Real 8 [])))] (Real 8 []) (RealConstant 1.05560632861831536e+01 (Real 8 [])) ()) Sub (RealConstant 1.05560632861831536e+01 (Real 8 [])) (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_6__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((RealUnaryMinus (RealConstant 3.39999999999999991e+00 (Real 8 [])) (Real 8 []) (RealConstant -3.39999999999999991e+00 (Real 8 []))))] (Real 8 []) (RealConstant 9.47322854068998882e-02 (Real 8 [])) ()) Sub (RealConstant 9.47322854068998882e-02 (Real 8 [])) (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_7__pow 2 pow [((RealConstant 3.39999999999999991e+00 (Real 8 []))) ((IntegerConstant 9 (Integer 4 [])))] (Real 8 []) (RealConstant 6.07169927664639836e+04 (Real 8 [])) ()) Sub (RealConstant 6.07169927664639836e+04 (Real 8 [])) (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_7__pow 2 pow [((RealConstant 0.00000000000000000e+00 (Real 8 []))) ((IntegerConstant 53 (Integer 4 [])))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Sub (RealConstant 0.00000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 16 (Integer 4 [])) ()) Eq (IntegerConstant 16 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (FunctionCall 1 pow@__lpython_overloaded_7__pow 2 pow [((RealUnaryMinus (RealConstant 4.23500000000000000e+03 (Real 8 [])) (Real 8 []) (RealConstant -4.23500000000000000e+03 (Real 8 [])))) ((IntegerConstant 52 (Integer 4 [])))] (Real 8 []) (RealConstant 3.94800380598526379e+188 (Real 8 [])) ()) Sub (RealConstant 3.94800380598526379e+188 (Real 8 [])) (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 []))))] (Real 8 []) (RealConstant 0.00000000000000000e+00 (Real 8 [])) ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (= (Var 2 c1) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 2 complex [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 4.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 4.00000000000000000e+00 5.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 2 c1) (FunctionCall 1 pow@__lpython_overloaded_9__pow 2 pow [((Var 2 c1)) ((IntegerConstant 4 (Integer 4 [])))] (Complex 4 []) () ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_round-7417a21.json b/tests/reference/asr-test_builtin_round-7417a21.json index d2817b55f0..6373697337 100644 --- a/tests/reference/asr-test_builtin_round-7417a21.json +++ b/tests/reference/asr-test_builtin_round-7417a21.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_round-7417a21.stdout", - "stdout_hash": "fcd2c79bce527b9ecf9dd6cce059f97c5fe17aecf7c055565041869c", + "stdout_hash": "e58175911619d368d6f3185c1b31a8b4735e49bd7392fe742adab624", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_round-7417a21.stdout b/tests/reference/asr-test_builtin_round-7417a21.stdout index 16ffde368a..42019e880a 100644 --- a/tests/reference/asr-test_builtin_round-7417a21.stdout +++ b/tests/reference/asr-test_builtin_round-7417a21.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 test_round () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), round@__lpython_overloaded_0__round: (ExternalSymbol 1 round@__lpython_overloaded_0__round 4 __lpython_overloaded_0__round lpython_builtin [] __lpython_overloaded_0__round Public), round@__lpython_overloaded_1__round: (ExternalSymbol 1 round@__lpython_overloaded_1__round 4 __lpython_overloaded_1__round lpython_builtin [] __lpython_overloaded_1__round Public), round@__lpython_overloaded_2__round: (ExternalSymbol 1 round@__lpython_overloaded_2__round 4 __lpython_overloaded_2__round lpython_builtin [] __lpython_overloaded_2__round Public), round@__lpython_overloaded_3__round: (ExternalSymbol 1 round@__lpython_overloaded_3__round 4 __lpython_overloaded_3__round lpython_builtin [] __lpython_overloaded_3__round Public), round@__lpython_overloaded_4__round: (ExternalSymbol 1 round@__lpython_overloaded_4__round 4 __lpython_overloaded_4__round lpython_builtin [] __lpython_overloaded_4__round Public), round@__lpython_overloaded_5__round: (ExternalSymbol 1 round@__lpython_overloaded_5__round 4 __lpython_overloaded_5__round lpython_builtin [] __lpython_overloaded_5__round Public), round@__lpython_overloaded_6__round: (ExternalSymbol 1 round@__lpython_overloaded_6__round 4 __lpython_overloaded_6__round lpython_builtin [] __lpython_overloaded_6__round Public), test_round: (Subroutine (SymbolTable 2 {b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), f: (Variable 2 f Local () () Default (Real 8 []) Source Public Required .false.), f2: (Variable 2 f2 Local () () Default (Real 4 []) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), i2: (Variable 2 i2 Local () () Default (Integer 1 []) Source Public Required .false.), i3: (Variable 2 i3 Local () () Default (Integer 2 []) Source Public Required .false.), i4: (Variable 2 i4 Local () () Default (Integer 8 []) Source Public Required .false.), round: (ExternalSymbol 2 round 4 round lpython_builtin [] round Private)}) test_round [] [(= (Var 2 f) (RealConstant 5.678000 (Real 8 [])) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 f) (UnaryOp USub (RealConstant 183745.230000 (Real 8 [])) (Real 8 []) (RealConstant -183745.230000 (Real 8 []))) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (UnaryOp USub (IntegerConstant 183745 (Integer 4 [])) (Integer 4 []) (IntegerConstant -183745 (Integer 4 []))) (Logical 4 []) () ()) ()) (= (Var 2 f) (RealConstant 44.340000 (Real 8 [])) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerConstant 44 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 f) (RealConstant 0.500000 (Real 8 [])) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 f) (UnaryOp USub (RealConstant 50.500000 (Real 8 [])) (Real 8 []) (RealConstant -50.500000 (Real 8 []))) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (UnaryOp USub (IntegerConstant 50 (Integer 4 [])) (Integer 4 []) (IntegerConstant -50 (Integer 4 []))) (Logical 4 []) () ()) ()) (= (Var 2 f) (RealConstant 1.500000 (Real 8 [])) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 13.001000 (Real 8 [])))] (Integer 4 []) (IntegerConstant 13 (Integer 4 [])) ()) Eq (IntegerConstant 13 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((UnaryOp USub (RealConstant 40.499990 (Real 8 [])) (Real 8 []) (RealConstant -40.499990 (Real 8 []))))] (Integer 4 []) (IntegerConstant -40 (Integer 4 [])) ()) Eq (UnaryOp USub (IntegerConstant 40 (Integer 4 [])) (Integer 4 []) (IntegerConstant -40 (Integer 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 0.500000 (Real 8 [])))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((UnaryOp USub (RealConstant 0.500000 (Real 8 [])) (Real 8 []) (RealConstant -0.500000 (Real 8 []))))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 1.500000 (Real 8 [])))] (Integer 4 []) (IntegerConstant 2 (Integer 4 [])) ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 50.500000 (Real 8 [])))] (Integer 4 []) (IntegerConstant 50 (Integer 4 [])) ()) Eq (IntegerConstant 50 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 56.780000 (Real 8 [])))] (Integer 4 []) (IntegerConstant 57 (Integer 4 [])) ()) Eq (IntegerConstant 57 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 f2) (Cast (RealConstant 5.678000 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.678000 (Real 4 []))) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_1__round 2 round [((Var 2 f2))] (Integer 4 []) () ()) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 i) (UnaryOp USub (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_2__round 2 round [((Var 2 i))] (Integer 4 []) () ()) Eq (UnaryOp USub (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_2__round 2 round [((IntegerConstant 4 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 4 (Integer 4 [])) ()) Eq (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (= (Var 2 i2) (Cast (IntegerConstant 7 (Integer 4 [])) IntegerToInteger (Integer 1 []) ()) ()) (Assert (Compare (Cast (FunctionCall 1 round@__lpython_overloaded_4__round 2 round [((Var 2 i2))] (Integer 1 []) () ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 7 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 i3) (Cast (UnaryOp USub (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) (IntegerConstant -8 (Integer 4 []))) IntegerToInteger (Integer 2 []) ()) ()) (Assert (Compare (Cast (FunctionCall 1 round@__lpython_overloaded_5__round 2 round [((Var 2 i3))] (Integer 2 []) () ()) IntegerToInteger (Integer 4 []) ()) Eq (UnaryOp USub (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) (IntegerConstant -8 (Integer 4 []))) (Logical 4 []) () ()) ()) (= (Var 2 i4) (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_3__round 2 round [((Var 2 i4))] (Integer 8 []) () ()) Eq (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) () ()) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_6__round 2 round [((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) () ()) ()) (= (Var 2 b) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_6__round 2 round [((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 1 round@__lpython_overloaded_6__round 2 round [((LogicalConstant .false. (Logical 4 [])))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 test_round () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), round@__lpython_overloaded_0__round: (ExternalSymbol 1 round@__lpython_overloaded_0__round 4 __lpython_overloaded_0__round lpython_builtin [] __lpython_overloaded_0__round Public), round@__lpython_overloaded_1__round: (ExternalSymbol 1 round@__lpython_overloaded_1__round 4 __lpython_overloaded_1__round lpython_builtin [] __lpython_overloaded_1__round Public), round@__lpython_overloaded_2__round: (ExternalSymbol 1 round@__lpython_overloaded_2__round 4 __lpython_overloaded_2__round lpython_builtin [] __lpython_overloaded_2__round Public), round@__lpython_overloaded_3__round: (ExternalSymbol 1 round@__lpython_overloaded_3__round 4 __lpython_overloaded_3__round lpython_builtin [] __lpython_overloaded_3__round Public), round@__lpython_overloaded_4__round: (ExternalSymbol 1 round@__lpython_overloaded_4__round 4 __lpython_overloaded_4__round lpython_builtin [] __lpython_overloaded_4__round Public), round@__lpython_overloaded_5__round: (ExternalSymbol 1 round@__lpython_overloaded_5__round 4 __lpython_overloaded_5__round lpython_builtin [] __lpython_overloaded_5__round Public), round@__lpython_overloaded_6__round: (ExternalSymbol 1 round@__lpython_overloaded_6__round 4 __lpython_overloaded_6__round lpython_builtin [] __lpython_overloaded_6__round Public), test_round: (Subroutine (SymbolTable 2 {b: (Variable 2 b Local () () Default (Logical 4 []) Source Public Required .false.), f: (Variable 2 f Local () () Default (Real 8 []) Source Public Required .false.), f2: (Variable 2 f2 Local () () Default (Real 4 []) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), i2: (Variable 2 i2 Local () () Default (Integer 1 []) Source Public Required .false.), i3: (Variable 2 i3 Local () () Default (Integer 2 []) Source Public Required .false.), i4: (Variable 2 i4 Local () () Default (Integer 8 []) Source Public Required .false.), round: (ExternalSymbol 2 round 4 round lpython_builtin [] round Private)}) test_round [] [(= (Var 2 f) (RealConstant 5.67799999999999994e+00 (Real 8 [])) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 f) (RealUnaryMinus (RealConstant 1.83745230000000010e+05 (Real 8 [])) (Real 8 []) (RealConstant -1.83745230000000010e+05 (Real 8 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerUnaryMinus (IntegerConstant 183745 (Integer 4 [])) (Integer 4 []) (IntegerConstant -183745 (Integer 4 []))) (Logical 4 []) ()) ()) (= (Var 2 f) (RealConstant 4.43400000000000034e+01 (Real 8 [])) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerConstant 44 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 f) (RealConstant 5.00000000000000000e-01 (Real 8 [])) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 f) (RealUnaryMinus (RealConstant 5.05000000000000000e+01 (Real 8 [])) (Real 8 []) (RealConstant -5.05000000000000000e+01 (Real 8 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerUnaryMinus (IntegerConstant 50 (Integer 4 [])) (Integer 4 []) (IntegerConstant -50 (Integer 4 []))) (Logical 4 []) ()) ()) (= (Var 2 f) (RealConstant 1.50000000000000000e+00 (Real 8 [])) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((Var 2 f))] (Integer 4 []) () ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 1.30009999999999994e+01 (Real 8 [])))] (Integer 4 []) (IntegerConstant 13 (Integer 4 [])) ()) Eq (IntegerConstant 13 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealUnaryMinus (RealConstant 4.04999899999999968e+01 (Real 8 [])) (Real 8 []) (RealConstant -4.04999899999999968e+01 (Real 8 []))))] (Integer 4 []) (IntegerConstant -40 (Integer 4 [])) ()) Eq (IntegerUnaryMinus (IntegerConstant 40 (Integer 4 [])) (Integer 4 []) (IntegerConstant -40 (Integer 4 []))) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 5.00000000000000000e-01 (Real 8 [])))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealUnaryMinus (RealConstant 5.00000000000000000e-01 (Real 8 [])) (Real 8 []) (RealConstant -5.00000000000000000e-01 (Real 8 []))))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 1.50000000000000000e+00 (Real 8 [])))] (Integer 4 []) (IntegerConstant 2 (Integer 4 [])) ()) Eq (IntegerConstant 2 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 5.05000000000000000e+01 (Real 8 [])))] (Integer 4 []) (IntegerConstant 50 (Integer 4 [])) ()) Eq (IntegerConstant 50 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_0__round 2 round [((RealConstant 5.67800000000000011e+01 (Real 8 [])))] (Integer 4 []) (IntegerConstant 57 (Integer 4 [])) ()) Eq (IntegerConstant 57 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 f2) (Cast (RealConstant 5.67799999999999994e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.67799999999999994e+00 (Real 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_1__round 2 round [((Var 2 f2))] (Integer 4 []) () ()) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_2__round 2 round [((Var 2 i))] (Integer 4 []) () ()) Eq (IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_2__round 2 round [((IntegerConstant 4 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 4 (Integer 4 [])) ()) Eq (IntegerConstant 4 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (= (Var 2 i2) (Cast (IntegerConstant 7 (Integer 4 [])) IntegerToInteger (Integer 1 []) ()) ()) (Assert (IntegerCompare (Cast (FunctionCall 1 round@__lpython_overloaded_4__round 2 round [((Var 2 i2))] (Integer 1 []) () ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerConstant 7 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 i3) (Cast (IntegerUnaryMinus (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) (IntegerConstant -8 (Integer 4 []))) IntegerToInteger (Integer 2 []) ()) ()) (Assert (IntegerCompare (Cast (FunctionCall 1 round@__lpython_overloaded_5__round 2 round [((Var 2 i3))] (Integer 2 []) () ()) IntegerToInteger (Integer 4 []) ()) Eq (IntegerUnaryMinus (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) (IntegerConstant -8 (Integer 4 []))) (Logical 4 []) ()) ()) (= (Var 2 i4) (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_3__round 2 round [((Var 2 i4))] (Integer 8 []) () ()) Eq (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) ()) (= (Var 2 b) (LogicalConstant .true. (Logical 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_6__round 2 round [((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (= (Var 2 b) (LogicalConstant .false. (Logical 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_6__round 2 round [((Var 2 b))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 round@__lpython_overloaded_6__round 2 round [((LogicalConstant .false. (Logical 4 [])))] (Integer 4 []) (IntegerConstant 0 (Integer 4 [])) ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_builtin_str-580e920.json b/tests/reference/asr-test_builtin_str-580e920.json index 59cf1529d7..d1d85af455 100644 --- a/tests/reference/asr-test_builtin_str-580e920.json +++ b/tests/reference/asr-test_builtin_str-580e920.json @@ -2,11 +2,11 @@ "basename": "asr-test_builtin_str-580e920", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/test_builtin_str.py", - "infile_hash": "78e2ffc58b91b3a348f90eb66c980e8bbc147f340b8f20f1bb9d7911", + "infile_hash": "9b5d5eaaa6856df8ac20b9f34b434749709c46cdcb3dbd313fd9ee9a", "outfile": null, "outfile_hash": null, "stdout": "asr-test_builtin_str-580e920.stdout", - "stdout_hash": "26ccda1447736d73f7e9dd377a9085ea6c7dff348dd956e1d5e2b47d", + "stdout_hash": "409450a916b0725c49a3da948ac3642649ec6856c9e495706f84ad5a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_builtin_str-580e920.stdout b/tests/reference/asr-test_builtin_str-580e920.stdout index 4b0fda75a3..0bbab26bbb 100644 --- a/tests/reference/asr-test_builtin_str-580e920.stdout +++ b/tests/reference/asr-test_builtin_str-580e920.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 test_str_int () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_str_int: (Subroutine (SymbolTable 2 {s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.), str: (ExternalSymbol 2 str 4 str lpython_builtin [] str Private)}) test_str_int [] [(= (Var 2 s) (FunctionCall 2 str () [((IntegerConstant 356 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "356" (Character 1 1 () [])) ()) ()) (Assert (Compare (Var 2 s) Eq (StringConstant "356" (Character 1 3 () [])) (Logical 4 []) () ()) ()) (= (Var 2 s) (FunctionCall 2 str () [((UnaryOp USub (IntegerConstant 567 (Integer 4 [])) (Integer 4 []) (IntegerConstant -567 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-567" (Character 1 1 () [])) ()) ()) (Assert (Compare (Var 2 s) Eq (StringConstant "-567" (Character 1 4 () [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 str () [((IntegerConstant 4 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "4" (Character 1 1 () [])) ()) Eq (StringConstant "4" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 2 str () [((UnaryOp USub (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-5" (Character 1 1 () [])) ()) Eq (StringConstant "-5" (Character 1 2 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 81 {}) _lpython_main_program [] [(SubroutineCall 1 test_str_int () [] ()) (SubroutineCall 1 str_conv_for_variables () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 80 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), str@__lpython_overloaded_0__str: (ExternalSymbol 1 str@__lpython_overloaded_0__str 5 __lpython_overloaded_0__str lpython_builtin [] __lpython_overloaded_0__str Public), str@__lpython_overloaded_1__str: (ExternalSymbol 1 str@__lpython_overloaded_1__str 5 __lpython_overloaded_1__str lpython_builtin [] __lpython_overloaded_1__str Public), str@__lpython_overloaded_2__str: (ExternalSymbol 1 str@__lpython_overloaded_2__str 5 __lpython_overloaded_2__str lpython_builtin [] __lpython_overloaded_2__str Public), str@__lpython_overloaded_3__str: (ExternalSymbol 1 str@__lpython_overloaded_3__str 5 __lpython_overloaded_3__str lpython_builtin [] __lpython_overloaded_3__str Public), str_conv_for_variables: (Subroutine (SymbolTable 3 {str: (ExternalSymbol 3 str 5 str lpython_builtin [] str Private), x: (Variable 3 x Local () () Default (Integer 4 []) Source Public Required .false.)}) str_conv_for_variables [] [(= (Var 3 x) (IntegerConstant 123 (Integer 4 [])) ()) (Assert (StringCompare (StringConstant "123" (Character 1 3 () [])) Eq (FunctionCall 1 str@__lpython_overloaded_3__str 3 str [((Var 3 x))] (Character 1 -2 () []) () ()) (Logical 4 []) ()) ()) (= (Var 3 x) (IntegerConstant 12345 (Integer 4 [])) ()) (Assert (StringCompare (StringConstant "12345" (Character 1 5 () [])) Eq (FunctionCall 1 str@__lpython_overloaded_3__str 3 str [((Var 3 x))] (Character 1 -2 () []) () ()) (Logical 4 []) ()) ()) (= (Var 3 x) (IntegerUnaryMinus (IntegerConstant 12 (Integer 4 [])) (Integer 4 []) (IntegerConstant -12 (Integer 4 []))) ()) (Assert (StringCompare (StringConstant "-12" (Character 1 3 () [])) Eq (FunctionCall 1 str@__lpython_overloaded_3__str 3 str [((Var 3 x))] (Character 1 -2 () []) () ()) (Logical 4 []) ()) ()) (= (Var 3 x) (IntegerUnaryMinus (IntegerConstant 121212 (Integer 4 [])) (Integer 4 []) (IntegerConstant -121212 (Integer 4 []))) ()) (Assert (StringCompare (StringConstant "-121212" (Character 1 7 () [])) Eq (FunctionCall 1 str@__lpython_overloaded_3__str 3 str [((Var 3 x))] (Character 1 -2 () []) () ()) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), test_str_int: (Subroutine (SymbolTable 2 {s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.), str: (ExternalSymbol 2 str 5 str lpython_builtin [] str Private)}) test_str_int [] [(= (Var 2 s) (FunctionCall 1 str@__lpython_overloaded_3__str 2 str [((IntegerConstant 356 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "356" (Character 1 1 () [])) ()) ()) (Assert (StringCompare (Var 2 s) Eq (StringConstant "356" (Character 1 3 () [])) (Logical 4 []) ()) ()) (= (Var 2 s) (FunctionCall 1 str@__lpython_overloaded_3__str 2 str [((IntegerUnaryMinus (IntegerConstant 567 (Integer 4 [])) (Integer 4 []) (IntegerConstant -567 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-567" (Character 1 1 () [])) ()) ()) (Assert (StringCompare (Var 2 s) Eq (StringConstant "-567" (Character 1 4 () [])) (Logical 4 []) ()) ()) (Assert (StringCompare (FunctionCall 1 str@__lpython_overloaded_3__str 2 str [((IntegerConstant 4 (Integer 4 [])))] (Character 1 -2 () []) (StringConstant "4" (Character 1 1 () [])) ()) Eq (StringConstant "4" (Character 1 1 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (FunctionCall 1 str@__lpython_overloaded_3__str 2 str [((IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))))] (Character 1 -2 () []) (StringConstant "-5" (Character 1 1 () [])) ()) Eq (StringConstant "-5" (Character 1 2 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (FunctionCall 1 str@__lpython_overloaded_0__str 2 str [] (Character 1 -2 () []) (StringConstant "" (Character 1 1 () [])) ()) Eq (StringConstant "" (Character 1 0 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (FunctionCall 1 str@__lpython_overloaded_1__str 2 str [((StringConstant "1234" (Character 1 4 () [])))] (Character 1 -2 () []) (StringConstant "1234" (Character 1 1 () [])) ()) Eq (StringConstant "1234" (Character 1 4 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (FunctionCall 1 str@__lpython_overloaded_2__str 2 str [((LogicalConstant .false. (Logical 4 [])))] (Character 1 -2 () []) (StringConstant "False" (Character 1 1 () [])) ()) Eq (StringConstant "False" (Character 1 5 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (StringCompare (FunctionCall 1 str@__lpython_overloaded_2__str 2 str [((LogicalConstant .true. (Logical 4 [])))] (Character 1 -2 () []) (StringConstant "True" (Character 1 1 () [])) ()) Eq (StringConstant "True" (Character 1 4 () [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_c_interop_01-e374f43.json b/tests/reference/asr-test_c_interop_01-e374f43.json new file mode 100644 index 0000000000..28c8fc61e7 --- /dev/null +++ b/tests/reference/asr-test_c_interop_01-e374f43.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_c_interop_01-e374f43", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_c_interop_01.py", + "infile_hash": "3760f9f3872552e5bf9ca4b05160f6f74a3570813111441de4066b8e", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-test_c_interop_01-e374f43.stdout", + "stdout_hash": "6b74516d71c6533f5659a859d3364732aef1ac10ffae3c17712e4f42", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-test_c_interop_01-e374f43.stdout b/tests/reference/asr-test_c_interop_01-e374f43.stdout new file mode 100644 index 0000000000..602791a7c4 --- /dev/null +++ b/tests/reference/asr-test_c_interop_01-e374f43.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lfortran_bgt32: (Function (SymbolTable 4 {_lpython_return_variable: (Variable 4 _lpython_return_variable ReturnVar () () Default (Integer 4 []) BindC Public Required .false.), i: (Variable 4 i In () () Default (Integer 4 []) BindC Public Required .true.), j: (Variable 4 j In () () Default (Integer 4 []) BindC Public Required .true.)}) _lfortran_bgt32 [(Var 4 i) (Var 4 j)] [] (Var 4 _lpython_return_variable) BindC Public Interface ()), _lfortran_bgt64: (Function (SymbolTable 5 {_lpython_return_variable: (Variable 5 _lpython_return_variable ReturnVar () () Default (Integer 4 []) BindC Public Required .false.), i: (Variable 5 i In () () Default (Integer 8 []) BindC Public Required .true.), j: (Variable 5 j In () () Default (Integer 8 []) BindC Public Required .true.)}) _lfortran_bgt64 [(Var 5 i) (Var 5 j)] [] (Var 5 _lpython_return_variable) BindC Public Interface ()), _lfortran_dsin: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Real 8 []) BindC Public Required .false.), x: (Variable 2 x In () () Default (Real 8 []) BindC Public Required .true.)}) _lfortran_dsin [(Var 2 x)] [] (Var 2 _lpython_return_variable) BindC Public Interface ()), _lfortran_ssin: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Real 4 []) BindC Public Required .false.), x: (Variable 3 x In () () Default (Real 4 []) BindC Public Required .true.)}) _lfortran_ssin [(Var 3 x)] [] (Var 3 _lpython_return_variable) BindC Public Interface ()), _lpython_main_program: (Subroutine (SymbolTable 84 {}) _lpython_main_program [] [(SubroutineCall 1 test_c_callbacks () [] ())] Source Public Implementation () .false. .false.), abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 8 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), abs@__lpython_overloaded_1__abs: (ExternalSymbol 1 abs@__lpython_overloaded_1__abs 8 __lpython_overloaded_1__abs lpython_builtin [] __lpython_overloaded_1__abs Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 83 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_c_callbacks: (Subroutine (SymbolTable 6 {abs: (ExternalSymbol 6 abs 8 abs lpython_builtin [] abs Private), pi: (Variable 6 pi Local () () Default (Real 8 []) Source Public Required .false.)}) test_c_callbacks [] [(= (Var 6 pi) (RealConstant 3.14159265358979312e+00 (Real 8 [])) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 6 abs [((RealBinOp (FunctionCall 1 _lfortran_dsin () [((Var 6 pi))] (Real 8 []) () ()) Sub (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 6 abs [((RealBinOp (FunctionCall 1 _lfortran_dsin () [((RealBinOp (Var 6 pi) Div (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) ()))] (Real 8 []) () ()) Sub (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (FunctionCall 1 abs@__lpython_overloaded_1__abs 6 abs [((RealBinOp (FunctionCall 1 _lfortran_ssin () [((Cast (Var 6 pi) RealToReal (Real 4 []) ()))] (Real 4 []) () ()) Sub (Cast (IntegerConstant 0 (Integer 4 [])) IntegerToReal (Real 4 []) ()) (Real 4 []) ()))] (Real 4 []) () ()) RealToReal (Real 8 []) ()) Lt (RealConstant 9.99999999999999955e-07 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (Cast (FunctionCall 1 abs@__lpython_overloaded_1__abs 6 abs [((RealBinOp (FunctionCall 1 _lfortran_ssin () [((Cast (RealBinOp (Var 6 pi) Div (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) ()) RealToReal (Real 4 []) ()))] (Real 4 []) () ()) Sub (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToReal (Real 4 []) ()) (Real 4 []) ()))] (Real 4 []) () ()) RealToReal (Real 8 []) ()) Lt (RealConstant 9.99999999999999955e-07 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 _lfortran_bgt32 () [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 _lfortran_bgt32 () [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 _lfortran_bgt64 () [((Cast (IntegerConstant 3 (Integer 4 [])) IntegerToInteger (Integer 8 []) ())) ((Cast (IntegerConstant 4 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()))] (Integer 4 []) () ()) Eq (IntegerConstant 0 (Integer 4 [])) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 _lfortran_bgt64 () [((Cast (IntegerConstant 4 (Integer 4 [])) IntegerToInteger (Integer 8 []) ())) ((Cast (IntegerConstant 3 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()))] (Integer 4 []) () ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_complex-70f026c.json b/tests/reference/asr-test_complex-70f026c.json new file mode 100644 index 0000000000..e18d21532e --- /dev/null +++ b/tests/reference/asr-test_complex-70f026c.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_complex-70f026c", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_complex.py", + "infile_hash": "a455235423e067edbeccb4c1edc326a0d97867921e0333d779fb3510", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-test_complex-70f026c.stdout", + "stdout_hash": "38aa7cfd6ee77ee8120ac23fe86553d033743d5a0437952e5623aa8b", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-test_complex-70f026c.stdout b/tests/reference/asr-test_complex-70f026c.stdout new file mode 100644 index 0000000000..f40c245f01 --- /dev/null +++ b/tests/reference/asr-test_complex-70f026c.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 87 {}) _lpython_main_program [] [(SubroutineCall 1 check () [] ())] Source Public Implementation () .false. .false.), abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 11 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), abs@__lpython_overloaded_7__abs: (ExternalSymbol 1 abs@__lpython_overloaded_7__abs 11 __lpython_overloaded_7__abs lpython_builtin [] __lpython_overloaded_7__abs Public), abs@__lpython_overloaded_8__abs: (ExternalSymbol 1 abs@__lpython_overloaded_8__abs 11 __lpython_overloaded_8__abs lpython_builtin [] __lpython_overloaded_8__abs Public), check: (Subroutine (SymbolTable 9 {}) check [] [(SubroutineCall 1 test_real_imag () [] ()) (SubroutineCall 1 test_complex () [] ()) (SubroutineCall 1 test_complex_abs () [] ()) (SubroutineCall 1 test_complex_binop_32 () [] ()) (SubroutineCall 1 test_complex_binop_64 () [] ()) (SubroutineCall 1 test_complex_unary_minus () [] ()) (SubroutineCall 1 test_complex_not () [] ())] Source Public Implementation () .false. .false.), complex@__lpython_overloaded_10__complex: (ExternalSymbol 1 complex@__lpython_overloaded_10__complex 11 __lpython_overloaded_10__complex lpython_builtin [] __lpython_overloaded_10__complex Public), complex@__lpython_overloaded_11__complex: (ExternalSymbol 1 complex@__lpython_overloaded_11__complex 11 __lpython_overloaded_11__complex lpython_builtin [] __lpython_overloaded_11__complex Public), complex@__lpython_overloaded_12__complex: (ExternalSymbol 1 complex@__lpython_overloaded_12__complex 11 __lpython_overloaded_12__complex lpython_builtin [] __lpython_overloaded_12__complex Public), complex@__lpython_overloaded_13__complex: (ExternalSymbol 1 complex@__lpython_overloaded_13__complex 11 __lpython_overloaded_13__complex lpython_builtin [] __lpython_overloaded_13__complex Public), complex@__lpython_overloaded_14__complex: (ExternalSymbol 1 complex@__lpython_overloaded_14__complex 11 __lpython_overloaded_14__complex lpython_builtin [] __lpython_overloaded_14__complex Public), complex@__lpython_overloaded_5__complex: (ExternalSymbol 1 complex@__lpython_overloaded_5__complex 11 __lpython_overloaded_5__complex lpython_builtin [] __lpython_overloaded_5__complex Public), complex@__lpython_overloaded_6__complex: (ExternalSymbol 1 complex@__lpython_overloaded_6__complex 11 __lpython_overloaded_6__complex lpython_builtin [] __lpython_overloaded_6__complex Public), complex@__lpython_overloaded_7__complex: (ExternalSymbol 1 complex@__lpython_overloaded_7__complex 11 __lpython_overloaded_7__complex lpython_builtin [] __lpython_overloaded_7__complex Public), complex@__lpython_overloaded_8__complex: (ExternalSymbol 1 complex@__lpython_overloaded_8__complex 11 __lpython_overloaded_8__complex lpython_builtin [] __lpython_overloaded_8__complex Public), complex@__lpython_overloaded_9__complex: (ExternalSymbol 1 complex@__lpython_overloaded_9__complex 11 __lpython_overloaded_9__complex lpython_builtin [] __lpython_overloaded_9__complex Public), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 86 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_complex: (Subroutine (SymbolTable 3 {a: (Variable 3 a Local () () Default (Real 8 []) Source Public Required .false.), a2: (Variable 3 a2 Local () () Default (Real 4 []) Source Public Required .false.), a3: (Variable 3 a3 Local () () Default (Real 4 []) Source Public Required .false.), abs: (ExternalSymbol 3 abs 11 abs lpython_builtin [] abs Private), complex: (ExternalSymbol 3 complex 11 complex lpython_builtin [] complex Private), eps: (Variable 3 eps Local () () Default (Real 8 []) Source Public Required .false.), i1: (Variable 3 i1 Local () () Default (Integer 4 []) Source Public Required .false.), i2: (Variable 3 i2 Local () () Default (Integer 8 []) Source Public Required .false.), x: (Variable 3 x Local () () Default (Complex 8 []) Source Public Required .false.), x2: (Variable 3 x2 Local () () Default (Complex 4 []) Source Public Required .false.)}) test_complex [] [(= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_5__complex 3 complex [((RealConstant 4.50000000000000000e+00 (Real 8 []))) ((RealConstant 6.70000000000000018e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 4.50000000000000000e+00 6.70000000000000018e+00 (Complex 8 [])) ()) ()) (= (Var 3 eps) (RealConstant 9.99999999999999980e-13 (Real 8 [])) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexRe (Var 3 x) (Real 8 []) ()) Sub (RealConstant 4.50000000000000000e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexIm (Var 3 x) (Real 8 []) ()) Sub (RealConstant 6.70000000000000018e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_9__complex 3 complex [((IntegerUnaryMinus (IntegerConstant 4 (Integer 4 [])) (Integer 4 []) (IntegerConstant -4 (Integer 4 [])))) ((IntegerConstant 2 (Integer 4 [])))] (Complex 8 []) (ComplexConstant -4.00000000000000000e+00 2.00000000000000000e+00 (Complex 8 [])) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexRe (Var 3 x) (Real 8 []) ()) Sub (RealUnaryMinus (RealConstant 4.00000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -4.00000000000000000e+00 (Real 8 []))) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexIm (Var 3 x) (Real 8 []) ()) Sub (RealConstant 2.00000000000000000e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_13__complex 3 complex [((IntegerConstant 4 (Integer 4 []))) ((RealConstant 7.88999999999999968e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 4.00000000000000000e+00 7.88999999999999968e+00 (Complex 8 [])) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexRe (Var 3 x) (Real 8 []) ()) Sub (RealConstant 4.00000000000000000e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexIm (Var 3 x) (Real 8 []) ()) Sub (RealConstant 7.88999999999999968e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_14__complex 3 complex [((RealConstant 5.59999999999999964e+00 (Real 8 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 5.59999999999999964e+00 0.00000000000000000e+00 (Complex 8 [])) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexRe (Var 3 x) (Real 8 []) ()) Sub (RealConstant 5.59999999999999964e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexIm (Var 3 x) (Real 8 []) ()) Sub (RealConstant 0.00000000000000000e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (= (Var 3 a) (RealConstant 5.34600000000000023e+02 (Real 8 [])) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_5__complex 3 complex [((Var 3 a)) ((RealUnaryMinus (Var 3 a) (Real 8 []) ()))] (Complex 8 []) () ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexRe (Var 3 x) (Real 8 []) ()) Sub (RealConstant 5.34600000000000023e+02 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (ComplexIm (Var 3 x) (Real 8 []) ()) Sub (RealUnaryMinus (RealConstant 5.34600000000000023e+02 (Real 8 [])) (Real 8 []) (RealConstant -5.34600000000000023e+02 (Real 8 []))) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (= (Var 3 a2) (Cast (RealUnaryMinus (RealConstant 4.23543080634815226e+02 (Real 8 [])) (Real 8 []) (RealConstant -4.23543080634815226e+02 (Real 8 []))) RealToReal (Real 4 []) (RealConstant -4.23543080634815226e+02 (Real 4 []))) ()) (= (Var 3 a3) (Cast (RealConstant 3.45000000000000000e+01 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.45000000000000000e+01 (Real 4 []))) ()) (= (Var 3 x2) (FunctionCall 1 complex@__lpython_overloaded_6__complex 3 complex [((Var 3 a2)) ((Var 3 a3))] (Complex 4 []) () ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (Cast (ComplexIm (Var 3 x2) (Real 4 []) ()) RealToReal (Real 8 []) ()) Sub (RealConstant 3.45000000000000000e+01 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (= (Var 3 i1) (IntegerUnaryMinus (IntegerConstant 5 (Integer 4 [])) (Integer 4 []) (IntegerConstant -5 (Integer 4 []))) ()) (= (Var 3 i2) (Cast (IntegerUnaryMinus (IntegerConstant 6 (Integer 4 [])) (Integer 4 []) (IntegerConstant -6 (Integer 4 []))) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_7__complex 3 complex [((Var 3 a3)) ((Var 3 a))] (Complex 8 []) () ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_8__complex 3 complex [((Var 3 a)) ((Var 3 a3))] (Complex 8 []) () ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_11__complex 3 complex [((Var 3 i1)) ((Var 3 i2))] (Complex 8 []) () ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_9__complex 3 complex [((Var 3 i1)) ((IntegerUnaryMinus (Var 3 i1) (Integer 4 []) ()))] (Complex 8 []) () ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_10__complex 3 complex [((IntegerUnaryMinus (Var 3 i2) (Integer 8 []) ())) ((IntegerUnaryMinus (Var 3 i2) (Integer 8 []) ()))] (Complex 8 []) () ()) ()) (= (Var 3 x) (FunctionCall 1 complex@__lpython_overloaded_12__complex 3 complex [((Var 3 i2)) ((IntegerUnaryMinus (Var 3 i1) (Integer 4 []) ()))] (Complex 8 []) () ()) ())] Source Public Implementation () .false. .false.), test_complex_abs: (Subroutine (SymbolTable 4 {abs: (ExternalSymbol 4 abs 11 abs lpython_builtin [] abs Private), complex: (ExternalSymbol 4 complex 11 complex lpython_builtin [] complex Private), eps: (Variable 4 eps Local () () Default (Real 8 []) Source Public Required .false.), x: (Variable 4 x Local () () Default (Complex 4 []) Source Public Required .false.), y: (Variable 4 y Local () () Default (Complex 8 []) Source Public Required .false.)}) test_complex_abs [] [(= (Var 4 x) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 4 complex [((IntegerConstant 3 (Integer 4 []))) ((IntegerConstant 4 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 4 eps) (RealConstant 9.99999999999999980e-13 (Real 8 [])) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 4 abs [((RealBinOp (Cast (FunctionCall 1 abs@__lpython_overloaded_7__abs 4 abs [((Var 4 x))] (Real 4 []) () ()) RealToReal (Real 8 []) ()) Sub (RealConstant 5.00000000000000000e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 4 eps) (Logical 4 []) ()) ()) (= (Var 4 y) (FunctionCall 1 complex@__lpython_overloaded_9__complex 4 complex [((IntegerConstant 6 (Integer 4 []))) ((IntegerConstant 8 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 6.00000000000000000e+00 8.00000000000000000e+00 (Complex 8 [])) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 4 abs [((RealBinOp (FunctionCall 1 abs@__lpython_overloaded_8__abs 4 abs [((Var 4 y))] (Real 8 []) () ()) Sub (RealConstant 1.00000000000000000e+01 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 4 eps) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), test_complex_binop_32: (Subroutine (SymbolTable 5 {x: (Variable 5 x Local () () Default (Complex 4 []) Source Public Required .false.), y: (Variable 5 y Local () () Default (Complex 4 []) Source Public Required .false.), z: (Variable 5 z Local () () Default (Complex 4 []) Source Public Required .false.)}) test_complex_binop_32 [] [(= (Var 5 x) (Cast (ComplexBinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 []))) ComplexToComplex (Complex 4 []) (ComplexConstant 2.00000000000000000e+00 3.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 5 y) (Cast (ComplexBinOp (Cast (IntegerConstant 4 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 4.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 4.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 []))) ComplexToComplex (Complex 4 []) (ComplexConstant 4.00000000000000000e+00 5.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 5 z) (ComplexBinOp (Var 5 x) Add (Var 5 y) (Complex 4 []) ()) ()) (= (Var 5 z) (ComplexBinOp (Var 5 x) Sub (Var 5 y) (Complex 4 []) ()) ()) (= (Var 5 z) (ComplexBinOp (Var 5 x) Mul (Var 5 y) (Complex 4 []) ()) ()) (= (Var 5 z) (ComplexBinOp (Var 5 x) Pow (Var 5 y) (Complex 4 []) ()) ())] Source Public Implementation () .false. .false.), test_complex_binop_64: (Subroutine (SymbolTable 6 {x: (Variable 6 x Local () () Default (Complex 8 []) Source Public Required .false.), y: (Variable 6 y Local () () Default (Complex 8 []) Source Public Required .false.), z: (Variable 6 z Local () () Default (Complex 8 []) Source Public Required .false.)}) test_complex_binop_64 [] [(= (Var 6 x) (ComplexBinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 []))) ()) (= (Var 6 y) (ComplexBinOp (Cast (IntegerConstant 4 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 4.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 4.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 []))) ()) (= (Var 6 z) (ComplexBinOp (Var 6 x) Add (Var 6 y) (Complex 8 []) ()) ()) (= (Var 6 z) (ComplexBinOp (Var 6 x) Sub (Var 6 y) (Complex 8 []) ()) ()) (= (Var 6 z) (ComplexBinOp (Var 6 x) Mul (Var 6 y) (Complex 8 []) ()) ()) (= (Var 6 z) (ComplexBinOp (Var 6 x) Pow (Var 6 y) (Complex 8 []) ()) ())] Source Public Implementation () .false. .false.), test_complex_not: (Subroutine (SymbolTable 8 {b: (Variable 8 b Local () () Default (Logical 4 []) Source Public Required .false.), c: (Variable 8 c Local () () Default (Complex 4 []) Source Public Required .false.), c2: (Variable 8 c2 Local () () Default (Complex 8 []) Source Public Required .false.), complex: (ExternalSymbol 8 complex 11 complex lpython_builtin [] complex Private)}) test_complex_not [] [(= (Var 8 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 8 complex [((IntegerConstant 4 (Integer 4 []))) ((IntegerConstant 5 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 4.00000000000000000e+00 5.00000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 4.00000000000000000e+00 5.00000000000000000e+00 (Complex 4 []))) ()) (= (Var 8 b) (LogicalNot (Cast (Var 8 c) ComplexToLogical (Logical 4 []) ()) (Logical 4 []) ()) ()) (Assert (LogicalNot (Var 8 b) (Logical 4 []) ()) ()) (= (Var 8 c2) (FunctionCall 1 complex@__lpython_overloaded_9__complex 8 complex [((IntegerConstant 0 (Integer 4 []))) ((IntegerConstant 0 (Integer 4 [])))] (Complex 8 []) (ComplexConstant 0.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 [])) ()) ()) (= (Var 8 b) (LogicalNot (Cast (Var 8 c2) ComplexToLogical (Logical 4 []) ()) (Logical 4 []) ()) ()) (Assert (Var 8 b) ())] Source Public Implementation () .false. .false.), test_complex_unary_minus: (Subroutine (SymbolTable 7 {_c: (Variable 7 _c Local () () Default (Complex 4 []) Source Public Required .false.), abs: (ExternalSymbol 7 abs 11 abs lpython_builtin [] abs Private), c: (Variable 7 c Local () () Default (Complex 4 []) Source Public Required .false.), c2: (Variable 7 c2 Local () () Default (Complex 8 []) Source Public Required .false.), complex: (ExternalSymbol 7 complex 11 complex lpython_builtin [] complex Private)}) test_complex_unary_minus [] [(= (Var 7 c) (Cast (FunctionCall 1 complex@__lpython_overloaded_13__complex 7 complex [((IntegerConstant 3 (Integer 4 []))) ((RealConstant 4.50000000000000000e+00 (Real 8 [])))] (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.50000000000000000e+00 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 3.00000000000000000e+00 4.50000000000000000e+00 (Complex 4 []))) ()) (= (Var 7 _c) (ComplexUnaryMinus (Var 7 c) (Complex 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 7 abs [((RealBinOp (Cast (ComplexRe (Var 7 _c) (Real 4 []) ()) RealToReal (Real 8 []) ()) Sub (RealUnaryMinus (RealConstant 3.00000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -3.00000000000000000e+00 (Real 8 []))) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 7 abs [((RealBinOp (Cast (ComplexIm (Var 7 _c) (Real 4 []) ()) RealToReal (Real 8 []) ()) Sub (RealUnaryMinus (RealConstant 4.50000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -4.50000000000000000e+00 (Real 8 []))) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (= (Var 7 _c) (Cast (FunctionCall 1 complex@__lpython_overloaded_9__complex 7 complex [((IntegerConstant 5 (Integer 4 []))) ((IntegerUnaryMinus (IntegerConstant 78 (Integer 4 [])) (Integer 4 []) (IntegerConstant -78 (Integer 4 []))))] (Complex 8 []) (ComplexConstant 5.00000000000000000e+00 -7.80000000000000000e+01 (Complex 8 [])) ()) ComplexToComplex (Complex 4 []) (ComplexConstant 5.00000000000000000e+00 -7.80000000000000000e+01 (Complex 4 []))) ()) (= (Var 7 _c) (ComplexUnaryMinus (Var 7 _c) (Complex 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 7 abs [((RealBinOp (Cast (ComplexRe (Var 7 _c) (Real 4 []) ()) RealToReal (Real 8 []) ()) Sub (RealUnaryMinus (RealConstant 5.00000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -5.00000000000000000e+00 (Real 8 []))) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 7 abs [((RealBinOp (Cast (ComplexIm (Var 7 _c) (Real 4 []) ()) RealToReal (Real 8 []) ()) Sub (RealConstant 7.80000000000000000e+01 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (= (Var 7 c2) (FunctionCall 1 complex@__lpython_overloaded_5__complex 7 complex [((RealUnaryMinus (RealConstant 4.50000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -4.50000000000000000e+00 (Real 8 [])))) ((RealUnaryMinus (RealConstant 7.79999999999999982e+00 (Real 8 [])) (Real 8 []) (RealConstant -7.79999999999999982e+00 (Real 8 []))))] (Complex 8 []) (ComplexConstant -4.50000000000000000e+00 -7.79999999999999982e+00 (Complex 8 [])) ()) ()) (= (Var 7 c2) (ComplexUnaryMinus (Var 7 c2) (Complex 8 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 7 abs [((RealBinOp (ComplexRe (Var 7 c2) (Real 8 []) ()) Sub (RealConstant 4.50000000000000000e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 7 abs [((RealBinOp (ComplexIm (Var 7 c2) (Real 8 []) ()) Sub (RealConstant 7.79999999999999982e+00 (Real 8 [])) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (= (Var 7 c2) (ComplexBinOp (Cast (IntegerConstant 3 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 3.00000000000000000e+00 4.00000000000000000e+00 (Complex 8 []))) ()) (= (Var 7 c2) (ComplexUnaryMinus (Var 7 c2) (Complex 8 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 7 abs [((RealBinOp (ComplexRe (Var 7 c2) (Real 8 []) ()) Sub (RealUnaryMinus (RealConstant 3.00000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -3.00000000000000000e+00 (Real 8 []))) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 7 abs [((RealBinOp (ComplexIm (Var 7 c2) (Real 8 []) ()) Sub (RealUnaryMinus (RealConstant 4.00000000000000000e+00 (Real 8 [])) (Real 8 []) (RealConstant -4.00000000000000000e+00 (Real 8 []))) (Real 8 []) ()))] (Real 8 []) () ()) Lt (RealConstant 9.99999999999999980e-13 (Real 8 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), test_real_imag: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Real 8 []) Source Public Required .false.), abs: (ExternalSymbol 2 abs 11 abs lpython_builtin [] abs Private), b: (Variable 2 b Local () () Default (Real 8 []) Source Public Required .false.), eps: (Variable 2 eps Local () () Default (Real 8 []) Source Public Required .false.), x: (Variable 2 x Local () () Default (Complex 8 []) Source Public Required .false.)}) test_real_imag [] [(= (Var 2 x) (ComplexBinOp (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToComplex (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 0.00000000000000000e+00 (Complex 8 []))) Add (ComplexConstant 0.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 [])) (Complex 8 []) (ComplexConstant 2.00000000000000000e+00 3.00000000000000000e+00 (Complex 8 []))) ()) (= (Var 2 eps) (RealConstant 9.99999999999999980e-13 (Real 8 [])) ()) (= (Var 2 a) (ComplexRe (Var 2 x) (Real 8 []) ()) ()) (= (Var 2 b) (ComplexIm (Var 2 x) (Real 8 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (Var 2 a) Sub (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 2 abs [((RealBinOp (Var 2 b) Sub (Cast (IntegerConstant 3 (Integer 4 [])) IntegerToReal (Real 8 []) ()) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 2 eps) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_dict7-1415e14.json b/tests/reference/asr-test_dict7-1415e14.json new file mode 100644 index 0000000000..64eb4e7eb3 --- /dev/null +++ b/tests/reference/asr-test_dict7-1415e14.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_dict7-1415e14", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_dict7.py", + "infile_hash": "37950c687da9eedd23b6803bade370f46cb40fb89270d032722caf33", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_dict7-1415e14.stderr", + "stderr_hash": "a51d1d4a46839e1f4258410e979ba83a14abe8c011482e30be2336cd", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_dict7-1415e14.stderr b/tests/reference/asr-test_dict7-1415e14.stderr new file mode 100644 index 0000000000..7884efa64e --- /dev/null +++ b/tests/reference/asr-test_dict7-1415e14.stderr @@ -0,0 +1,5 @@ +semantic error: unhashable type in dict: 'slice' + --> tests/errors/test_dict7.py:4:11 + | +4 | print(d[1:2]) + | ^^^^^^ diff --git a/tests/reference/asr-test_func_args-a898a72.json b/tests/reference/asr-test_func_args-a898a72.json new file mode 100644 index 0000000000..b0faead823 --- /dev/null +++ b/tests/reference/asr-test_func_args-a898a72.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_func_args-a898a72", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_func_args.py", + "infile_hash": "99520afdb87aa1addb3c6add4aa8c4237ac8db7ad21899d21591a736", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_func_args-a898a72.stderr", + "stderr_hash": "b498b34cd18395e17ab982dc47abb832c01bd16ede103fad53068304", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_func_args-a898a72.stderr b/tests/reference/asr-test_func_args-a898a72.stderr new file mode 100644 index 0000000000..ec5891080a --- /dev/null +++ b/tests/reference/asr-test_func_args-a898a72.stderr @@ -0,0 +1,5 @@ +semantic error: Number of arguments does not match in the function call + --> tests/errors/test_func_args.py:11:11 + | +11 | ans = fib(35, 10) + | ^^^^^^^^^^^ (found: '2', expected: '1') diff --git a/tests/reference/asr-test_integer_bitnot-08e2e96.json b/tests/reference/asr-test_integer_bitnot-08e2e96.json new file mode 100644 index 0000000000..f6ce2b4d9f --- /dev/null +++ b/tests/reference/asr-test_integer_bitnot-08e2e96.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_integer_bitnot-08e2e96", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_integer_bitnot.py", + "infile_hash": "dc976a358fbeebedead889f8e85b3eed4ac77ee20f68fcac58b81429", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-test_integer_bitnot-08e2e96.stdout", + "stdout_hash": "83445930ef49014cbc66033f75f3d9910819cbf5edc79330549ce292", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-test_integer_bitnot-08e2e96.stdout b/tests/reference/asr-test_integer_bitnot-08e2e96.stdout new file mode 100644 index 0000000000..1123c9045e --- /dev/null +++ b/tests/reference/asr-test_integer_bitnot-08e2e96.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 f () [] ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 2 {i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), res: (Variable 2 res Local () () Default (Integer 4 []) Source Public Required .false.)}) f [] [(= (Var 2 i) (IntegerConstant 5 (Integer 4 [])) ()) (= (Var 2 res) (IntegerBitNot (Var 2 i) (Integer 4 []) ()) ()) (Assert (IntegerCompare (Var 2 res) Eq (IntegerUnaryMinus (IntegerConstant 6 (Integer 4 [])) (Integer 4 []) (IntegerConstant -6 (Integer 4 []))) (Logical 4 []) ()) ()) (= (Var 2 i) (IntegerUnaryMinus (IntegerConstant 235346 (Integer 4 [])) (Integer 4 []) (IntegerConstant -235346 (Integer 4 []))) ()) (Assert (IntegerCompare (IntegerBitNot (Var 2 i) (Integer 4 []) ()) Eq (IntegerConstant 235345 (Integer 4 [])) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-test_list_concat-41d186f.json b/tests/reference/asr-test_list_concat-41d186f.json index 5ab89ff790..39aaca5e0d 100644 --- a/tests/reference/asr-test_list_concat-41d186f.json +++ b/tests/reference/asr-test_list_concat-41d186f.json @@ -2,12 +2,12 @@ "basename": "asr-test_list_concat-41d186f", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/errors/test_list_concat.py", - "infile_hash": "e5cb4c9712d578c4a88d2c12f9dea9ed10531b30bda4bb0cdda392fa", + "infile_hash": "ae10f20b909a0ace3daca1f4c0856f1cf652753a62fa8c7dceedb93b", "outfile": null, "outfile_hash": null, "stdout": null, "stdout_hash": null, "stderr": "asr-test_list_concat-41d186f.stderr", - "stderr_hash": "40b83e988e6e02beadaeeafbed4b29e65c985dfd596dd1d0f4a7bd3f", + "stderr_hash": "b8de00229ea445c4fd167ebb520a055301a1b7c7751f5eff9b0bd6eb", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_list_concat-41d186f.stderr b/tests/reference/asr-test_list_concat-41d186f.stderr index 27fc6eabc7..14b110b6e4 100644 --- a/tests/reference/asr-test_list_concat-41d186f.stderr +++ b/tests/reference/asr-test_list_concat-41d186f.stderr @@ -2,4 +2,4 @@ semantic error: Both the lists should be of the same type for concatenation. --> tests/errors/test_list_concat.py:8:3 | 8 | a += b - | ^ ^ type mismatch ('list[i32]' and 'list[f32]') + | ^ ^ type mismatch ('list[i32]' and 'list[f64]') diff --git a/tests/reference/asr-test_max_min-3c2fc51.json b/tests/reference/asr-test_max_min-3c2fc51.json index 603e07e4eb..15af2e2718 100644 --- a/tests/reference/asr-test_max_min-3c2fc51.json +++ b/tests/reference/asr-test_max_min-3c2fc51.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_max_min-3c2fc51.stdout", - "stdout_hash": "e2533628dcc91553b33df1d2e628c8f52f5420f8f3df1f4234258e62", + "stdout_hash": "b15541485f86051f55a60aae5e777efcb2627de0df9f5b33c940aa0c", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_max_min-3c2fc51.stdout b/tests/reference/asr-test_max_min-3c2fc51.stdout index 9ddce66daf..cbecb6e0e4 100644 --- a/tests/reference/asr-test_max_min-3c2fc51.stdout +++ b/tests/reference/asr-test_max_min-3c2fc51.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 101 {}) _lpython_main_program [] [(SubroutineCall 1 check () [] ())] Source Public Implementation () .false. .false.), check: (Subroutine (SymbolTable 6 {}) check [] [(SubroutineCall 1 test_max_int () [] ()) (SubroutineCall 1 test_max_float () [] ()) (SubroutineCall 1 test_min_int () [] ()) (SubroutineCall 1 test_min_float () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 100 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), max@__lpython_overloaded_0__max: (ExternalSymbol 1 max@__lpython_overloaded_0__max 8 __lpython_overloaded_0__max lpython_builtin [] __lpython_overloaded_0__max Public), max@__lpython_overloaded_1__max: (ExternalSymbol 1 max@__lpython_overloaded_1__max 8 __lpython_overloaded_1__max lpython_builtin [] __lpython_overloaded_1__max Public), max@__lpython_overloaded_2__max: (ExternalSymbol 1 max@__lpython_overloaded_2__max 8 __lpython_overloaded_2__max lpython_builtin [] __lpython_overloaded_2__max Public), max@__lpython_overloaded_3__max: (ExternalSymbol 1 max@__lpython_overloaded_3__max 8 __lpython_overloaded_3__max lpython_builtin [] __lpython_overloaded_3__max Public), min@__lpython_overloaded_0__min: (ExternalSymbol 1 min@__lpython_overloaded_0__min 8 __lpython_overloaded_0__min lpython_builtin [] __lpython_overloaded_0__min Public), min@__lpython_overloaded_1__min: (ExternalSymbol 1 min@__lpython_overloaded_1__min 8 __lpython_overloaded_1__min lpython_builtin [] __lpython_overloaded_1__min Public), min@__lpython_overloaded_2__min: (ExternalSymbol 1 min@__lpython_overloaded_2__min 8 __lpython_overloaded_2__min lpython_builtin [] __lpython_overloaded_2__min Public), min@__lpython_overloaded_3__min: (ExternalSymbol 1 min@__lpython_overloaded_3__min 8 __lpython_overloaded_3__min lpython_builtin [] __lpython_overloaded_3__min Public), test_max_float: (Subroutine (SymbolTable 3 {d: (Variable 3 d Local () (RealConstant 23.233000 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), e: (Variable 3 e Local () (RealConstant 23.223300 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), f: (Variable 3 f Local () (RealConstant 21.230000 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), max: (ExternalSymbol 3 max 8 max lpython_builtin [] max Private)}) test_max_float [] [(Assert (Compare (FunctionCall 1 max@__lpython_overloaded_2__max 3 max [((Var 3 d)) ((Var 3 e)) ((Var 3 f))] (Real 8 []) (RealConstant 23.233000 (Real 8 [])) ()) Eq (Var 3 d) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 max@__lpython_overloaded_3__max 3 max [((Var 3 e)) ((Var 3 f))] (Real 8 []) (RealConstant 23.223300 (Real 8 [])) ()) Eq (Var 3 e) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_max_int: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () (IntegerConstant 1 (Integer 4 [])) Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () (IntegerConstant 2 (Integer 4 [])) Default (Integer 4 []) Source Public Required .false.), c: (Variable 2 c Local () (IntegerConstant 3 (Integer 4 [])) Default (Integer 4 []) Source Public Required .false.), max: (ExternalSymbol 2 max 8 max lpython_builtin [] max Private)}) test_max_int [] [(Assert (Compare (FunctionCall 1 max@__lpython_overloaded_0__max 2 max [((Var 2 a)) ((Var 2 b))] (Integer 4 []) (IntegerConstant 2 (Integer 4 [])) ()) Eq (Var 2 b) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 max@__lpython_overloaded_1__max 2 max [((Var 2 a)) ((Var 2 b)) ((Var 2 c))] (Integer 4 []) (IntegerConstant 3 (Integer 4 [])) ()) Eq (Var 2 c) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 max@__lpython_overloaded_1__max 2 max [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 3 (Integer 4 [])) ()) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 max@__lpython_overloaded_0__max 2 max [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 6 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 6 (Integer 4 [])) ()) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_min_float: (Subroutine (SymbolTable 5 {d: (Variable 5 d Local () (RealConstant 23.233000 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), e: (Variable 5 e Local () (RealConstant 23.223300 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), f: (Variable 5 f Local () (RealConstant 21.230000 (Real 8 [])) Default (Real 8 []) Source Public Required .false.), min: (ExternalSymbol 5 min 8 min lpython_builtin [] min Private)}) test_min_float [] [(Assert (Compare (FunctionCall 1 min@__lpython_overloaded_2__min 5 min [((Var 5 d)) ((Var 5 e)) ((Var 5 f))] (Real 8 []) (RealConstant 21.230000 (Real 8 [])) ()) Eq (Var 5 f) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 min@__lpython_overloaded_3__min 5 min [((Var 5 e)) ((Var 5 f))] (Real 8 []) (RealConstant 21.230000 (Real 8 [])) ()) Eq (Var 5 f) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_min_int: (Subroutine (SymbolTable 4 {a: (Variable 4 a Local () (IntegerConstant 1 (Integer 4 [])) Default (Integer 4 []) Source Public Required .false.), b: (Variable 4 b Local () (IntegerConstant 2 (Integer 4 [])) Default (Integer 4 []) Source Public Required .false.), c: (Variable 4 c Local () (IntegerConstant 3 (Integer 4 [])) Default (Integer 4 []) Source Public Required .false.), min: (ExternalSymbol 4 min 8 min lpython_builtin [] min Private)}) test_min_int [] [(Assert (Compare (FunctionCall 1 min@__lpython_overloaded_0__min 4 min [((Var 4 a)) ((Var 4 b))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (Var 4 a) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 min@__lpython_overloaded_1__min 4 min [((Var 4 a)) ((Var 4 b)) ((Var 4 c))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (Var 4 a) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 min@__lpython_overloaded_1__min 4 min [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 1 min@__lpython_overloaded_0__min 4 min [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 6 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 84 {}) _lpython_main_program [] [(SubroutineCall 1 check () [] ())] Source Public Implementation () .false. .false.), check: (Subroutine (SymbolTable 6 {}) check [] [(SubroutineCall 1 test_max_int () [] ()) (SubroutineCall 1 test_max_float () [] ()) (SubroutineCall 1 test_min_int () [] ()) (SubroutineCall 1 test_min_float () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 83 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), max@__lpython_overloaded_0__max: (ExternalSymbol 1 max@__lpython_overloaded_0__max 8 __lpython_overloaded_0__max lpython_builtin [] __lpython_overloaded_0__max Public), max@__lpython_overloaded_1__max: (ExternalSymbol 1 max@__lpython_overloaded_1__max 8 __lpython_overloaded_1__max lpython_builtin [] __lpython_overloaded_1__max Public), max@__lpython_overloaded_2__max: (ExternalSymbol 1 max@__lpython_overloaded_2__max 8 __lpython_overloaded_2__max lpython_builtin [] __lpython_overloaded_2__max Public), max@__lpython_overloaded_3__max: (ExternalSymbol 1 max@__lpython_overloaded_3__max 8 __lpython_overloaded_3__max lpython_builtin [] __lpython_overloaded_3__max Public), min@__lpython_overloaded_0__min: (ExternalSymbol 1 min@__lpython_overloaded_0__min 8 __lpython_overloaded_0__min lpython_builtin [] __lpython_overloaded_0__min Public), min@__lpython_overloaded_1__min: (ExternalSymbol 1 min@__lpython_overloaded_1__min 8 __lpython_overloaded_1__min lpython_builtin [] __lpython_overloaded_1__min Public), min@__lpython_overloaded_2__min: (ExternalSymbol 1 min@__lpython_overloaded_2__min 8 __lpython_overloaded_2__min lpython_builtin [] __lpython_overloaded_2__min Public), min@__lpython_overloaded_3__min: (ExternalSymbol 1 min@__lpython_overloaded_3__min 8 __lpython_overloaded_3__min lpython_builtin [] __lpython_overloaded_3__min Public), test_max_float: (Subroutine (SymbolTable 3 {d: (Variable 3 d Local () () Default (Real 8 []) Source Public Required .false.), e: (Variable 3 e Local () () Default (Real 8 []) Source Public Required .false.), f: (Variable 3 f Local () () Default (Real 8 []) Source Public Required .false.), max: (ExternalSymbol 3 max 8 max lpython_builtin [] max Private)}) test_max_float [] [(= (Var 3 d) (RealConstant 2.32330000000000005e+01 (Real 8 [])) ()) (= (Var 3 e) (RealConstant 2.32232999999999983e+01 (Real 8 [])) ()) (= (Var 3 f) (RealConstant 2.12300000000000004e+01 (Real 8 [])) ()) (Assert (RealCompare (FunctionCall 1 max@__lpython_overloaded_2__max 3 max [((Var 3 d)) ((Var 3 e)) ((Var 3 f))] (Real 8 []) () ()) Eq (Var 3 d) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 max@__lpython_overloaded_3__max 3 max [((Var 3 e)) ((Var 3 f))] (Real 8 []) () ()) Eq (Var 3 e) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), test_max_int: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Integer 4 []) Source Public Required .false.), c: (Variable 2 c Local () () Default (Integer 4 []) Source Public Required .false.), max: (ExternalSymbol 2 max 8 max lpython_builtin [] max Private)}) test_max_int [] [(= (Var 2 a) (IntegerConstant 1 (Integer 4 [])) ()) (= (Var 2 b) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 2 c) (IntegerConstant 3 (Integer 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 max@__lpython_overloaded_0__max 2 max [((Var 2 a)) ((Var 2 b))] (Integer 4 []) () ()) Eq (Var 2 b) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 max@__lpython_overloaded_1__max 2 max [((Var 2 a)) ((Var 2 b)) ((Var 2 c))] (Integer 4 []) () ()) Eq (Var 2 c) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 max@__lpython_overloaded_1__max 2 max [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 3 (Integer 4 [])) ()) Eq (IntegerConstant 3 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 max@__lpython_overloaded_0__max 2 max [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 6 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 6 (Integer 4 [])) ()) Eq (IntegerConstant 6 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.), test_min_float: (Subroutine (SymbolTable 5 {d: (Variable 5 d Local () () Default (Real 8 []) Source Public Required .false.), e: (Variable 5 e Local () () Default (Real 8 []) Source Public Required .false.), f: (Variable 5 f Local () () Default (Real 8 []) Source Public Required .false.), min: (ExternalSymbol 5 min 8 min lpython_builtin [] min Private)}) test_min_float [] [(= (Var 5 d) (RealConstant 2.32330000000000005e+01 (Real 8 [])) ()) (= (Var 5 e) (RealConstant 2.32232999999999983e+01 (Real 8 [])) ()) (= (Var 5 f) (RealConstant 2.12300000000000004e+01 (Real 8 [])) ()) (Assert (RealCompare (FunctionCall 1 min@__lpython_overloaded_2__min 5 min [((Var 5 d)) ((Var 5 e)) ((Var 5 f))] (Real 8 []) () ()) Eq (Var 5 f) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 min@__lpython_overloaded_3__min 5 min [((Var 5 e)) ((Var 5 f))] (Real 8 []) () ()) Eq (Var 5 f) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), test_min_int: (Subroutine (SymbolTable 4 {a: (Variable 4 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 4 b Local () () Default (Integer 4 []) Source Public Required .false.), c: (Variable 4 c Local () () Default (Integer 4 []) Source Public Required .false.), min: (ExternalSymbol 4 min 8 min lpython_builtin [] min Private)}) test_min_int [] [(= (Var 4 a) (IntegerConstant 1 (Integer 4 [])) ()) (= (Var 4 b) (IntegerConstant 2 (Integer 4 [])) ()) (= (Var 4 c) (IntegerConstant 3 (Integer 4 [])) ()) (Assert (IntegerCompare (FunctionCall 1 min@__lpython_overloaded_0__min 4 min [((Var 4 a)) ((Var 4 b))] (Integer 4 []) () ()) Eq (Var 4 a) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 min@__lpython_overloaded_1__min 4 min [((Var 4 a)) ((Var 4 b)) ((Var 4 c))] (Integer 4 []) () ()) Eq (Var 4 a) (Logical 4 []) ()) ()) (Assert (IntegerCompare (FunctionCall 1 min@__lpython_overloaded_1__min 4 min [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 3 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ()) (Assert (IntegerCompare (FunctionCall 1 min@__lpython_overloaded_0__min 4 min [((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 6 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 1 (Integer 4 [])) ()) Eq (IntegerConstant 1 (Integer 4 [])) (Logical 4 []) (LogicalConstant .true. (Logical 4 []))) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-test_pointer_types-1bf0d01.json b/tests/reference/asr-test_pointer_types-1bf0d01.json new file mode 100644 index 0000000000..42f36c3bce --- /dev/null +++ b/tests/reference/asr-test_pointer_types-1bf0d01.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_pointer_types-1bf0d01", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_pointer_types.py", + "infile_hash": "750a2bb08545b8c11e44585855545060693c59a71df5989ac5371720", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_pointer_types-1bf0d01.stderr", + "stderr_hash": "6e2863e63e4e4d002a9ef2fad9369ee5b2b037afa1dc2fd2e86c05c4", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_pointer_types-1bf0d01.stderr b/tests/reference/asr-test_pointer_types-1bf0d01.stderr new file mode 100644 index 0000000000..0afffd00ba --- /dev/null +++ b/tests/reference/asr-test_pointer_types-1bf0d01.stderr @@ -0,0 +1,5 @@ +semantic error: Casting not supported for different pointer types. Received target pointer type, Pointer[i16[:]] and value pointer type, Pointer[i32[2]] + --> tests/errors/test_pointer_types.py:8:5 + | +8 | yptr1 = pointer(y) + | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/reference/asr-test_pow-3f5d550.json b/tests/reference/asr-test_pow-3f5d550.json index 90fca31226..cedb8b8aa8 100644 --- a/tests/reference/asr-test_pow-3f5d550.json +++ b/tests/reference/asr-test_pow-3f5d550.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-test_pow-3f5d550.stdout", - "stdout_hash": "1d95b02ebb991f178184b28e37de1d4482d196ccf25c24e31e04684d", + "stdout_hash": "ded780c5decb1e9d004681c6c2a1231a21858a8715ba4088ff78c48d", "stderr": "asr-test_pow-3f5d550.stderr", "stderr_hash": "3d950301563cce75654f28bf41f6f53428ed1f5ae997774345f374a3", "returncode": 0 diff --git a/tests/reference/asr-test_pow-3f5d550.stdout b/tests/reference/asr-test_pow-3f5d550.stdout index d99f001522..1954622d34 100644 --- a/tests/reference/asr-test_pow-3f5d550.stdout +++ b/tests/reference/asr-test_pow-3f5d550.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 97 {}) _lpython_main_program [] [(SubroutineCall 1 main () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main: (Subroutine (SymbolTable 2 {pow: (ExternalSymbol 2 pow 4 pow lpython_builtin [] pow Private)}) main [] [(Print () [(FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 4 (Integer 4 [])) ())]) (Print () [(BinOp (IntegerConstant 2 (Integer 4 [])) Pow (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 [])) ())])] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 96 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), pow@__lpython_overloaded_0__pow: (ExternalSymbol 1 pow@__lpython_overloaded_0__pow 4 __lpython_overloaded_0__pow lpython_builtin [] __lpython_overloaded_0__pow Public)}) []) +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 80 {}) _lpython_main_program [] [(SubroutineCall 1 main () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main: (Subroutine (SymbolTable 2 {pow: (ExternalSymbol 2 pow 4 pow lpython_builtin [] pow Private)}) main [] [(Print () [(FunctionCall 1 pow@__lpython_overloaded_0__pow 2 pow [((IntegerConstant 2 (Integer 4 []))) ((IntegerConstant 2 (Integer 4 [])))] (Integer 4 []) (IntegerConstant 4 (Integer 4 [])) ())] () ()) (Print () [(IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Pow (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant 4 (Integer 4 [])))] () ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 79 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), pow@__lpython_overloaded_0__pow: (ExternalSymbol 1 pow@__lpython_overloaded_0__pow 4 __lpython_overloaded_0__pow lpython_builtin [] __lpython_overloaded_0__pow Public)}) []) diff --git a/tests/reference/asr-test_print1-f1f36f1.json b/tests/reference/asr-test_print1-f1f36f1.json new file mode 100644 index 0000000000..0c4988e3a3 --- /dev/null +++ b/tests/reference/asr-test_print1-f1f36f1.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_print1-f1f36f1", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_print1.py", + "infile_hash": "824e91278f3717dbe58ef4c18f8df06f9c7d4644ca6f3a65cccdc9e0", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_print1-f1f36f1.stderr", + "stderr_hash": "da6324bcc282ecb93fe6784b206f8a9d8f04ae56341339b13de71bd4", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_print1-f1f36f1.stderr b/tests/reference/asr-test_print1-f1f36f1.stderr new file mode 100644 index 0000000000..b28bc75a72 --- /dev/null +++ b/tests/reference/asr-test_print1-f1f36f1.stderr @@ -0,0 +1,5 @@ +semantic error: Separator is expected to be of string type + --> tests/errors/test_print1.py:2:25 + | +2 | print("a", "b", sep=2) + | ^ Expected string, found: integer diff --git a/tests/reference/asr-test_print1-f1f36f1.stdout b/tests/reference/asr-test_print1-f1f36f1.stdout new file mode 100644 index 0000000000..ad782f8b19 --- /dev/null +++ b/tests/reference/asr-test_print1-f1f36f1.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 f () [] ())] Source Public Implementation () .false. .false.), f: (Subroutine (SymbolTable 2 {}) f [] [(Print () [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () []))] (IntegerConstant 2 (Integer 4 [])))] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/asr-test_print2-64acb15.json b/tests/reference/asr-test_print2-64acb15.json new file mode 100644 index 0000000000..050b4cc698 --- /dev/null +++ b/tests/reference/asr-test_print2-64acb15.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_print2-64acb15", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_print2.py", + "infile_hash": "af07d17d5b3f16db024a3e893923988349c8f6c8bf1a6c5507d56a6d", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_print2-64acb15.stderr", + "stderr_hash": "e92bba85b957e7034c5172981b3b27ed7b3f0ac62167d82175890bc9", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_print2-64acb15.stderr b/tests/reference/asr-test_print2-64acb15.stderr new file mode 100644 index 0000000000..6ed1c334b1 --- /dev/null +++ b/tests/reference/asr-test_print2-64acb15.stderr @@ -0,0 +1,5 @@ +semantic error: End is expected to be of string type + --> tests/errors/test_print2.py:2:26 + | +2 | print("a", "b", end=1) + | ^ Expected string, found: integer diff --git a/tests/reference/asr-test_str_slicing2-2f07e9a.json b/tests/reference/asr-test_str_slicing2-2f07e9a.json new file mode 100644 index 0000000000..dc63e9a7b0 --- /dev/null +++ b/tests/reference/asr-test_str_slicing2-2f07e9a.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_str_slicing2-2f07e9a", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_str_slicing2.py", + "infile_hash": "eb9027d2b6ec0aba9cc78aeedc1b0b36972ff36b076fecf547eeb014", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_str_slicing2-2f07e9a.stderr", + "stderr_hash": "48a9286126c2333bdf5237358bd4ad27acac4a16a78069c9bd36d089", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_str_slicing2-2f07e9a.stderr b/tests/reference/asr-test_str_slicing2-2f07e9a.stderr new file mode 100644 index 0000000000..94a5f03259 --- /dev/null +++ b/tests/reference/asr-test_str_slicing2-2f07e9a.stderr @@ -0,0 +1,5 @@ +semantic error: slice indices must be integers or None + --> tests/errors/test_str_slicing2.py:4:13 + | +4 | print(s[1.5:3]) + | ^^^ diff --git a/tests/reference/asr-test_str_slicing3-fe6a03c.json b/tests/reference/asr-test_str_slicing3-fe6a03c.json new file mode 100644 index 0000000000..d1fe49fdfe --- /dev/null +++ b/tests/reference/asr-test_str_slicing3-fe6a03c.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_str_slicing3-fe6a03c", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_str_slicing3.py", + "infile_hash": "b223abc3ec96fe91876fa188259f151d61383687776e8975df45b139", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_str_slicing3-fe6a03c.stderr", + "stderr_hash": "5f7553d1509bed25d5137abc4fc2cb1d2cb983a1fab81d8d178ed197", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_str_slicing3-fe6a03c.stderr b/tests/reference/asr-test_str_slicing3-fe6a03c.stderr new file mode 100644 index 0000000000..b1180c30ae --- /dev/null +++ b/tests/reference/asr-test_str_slicing3-fe6a03c.stderr @@ -0,0 +1,5 @@ +semantic error: slice indices must be integers or None + --> tests/errors/test_str_slicing3.py:4:17 + | +4 | print(s[1:3:0.5]) + | ^^^ diff --git a/tests/reference/asr-test_str_to_int-61553e7.json b/tests/reference/asr-test_str_to_int-61553e7.json new file mode 100644 index 0000000000..ac1093b9c8 --- /dev/null +++ b/tests/reference/asr-test_str_to_int-61553e7.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_str_to_int-61553e7", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_str_to_int.py", + "infile_hash": "da0ed82ada98ef2757178c4997af53abc82f4761a0e683a613216c64", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_str_to_int-61553e7.stderr", + "stderr_hash": "1998e37d9abe044f164c73ea1e000ce748ed43af5ea14c2eb4715f11", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_str_to_int-61553e7.stderr b/tests/reference/asr-test_str_to_int-61553e7.stderr new file mode 100644 index 0000000000..785d95ba7f --- /dev/null +++ b/tests/reference/asr-test_str_to_int-61553e7.stderr @@ -0,0 +1,5 @@ +semantic error: invalid literal for int() with base 10: '3abc' + --> tests/errors/test_str_to_int.py:2:15 + | +2 | print(int('3abc')) + | ^^^^^^ diff --git a/tests/reference/asr-test_unsupported_type-0d813dd.json b/tests/reference/asr-test_unsupported_type-0d813dd.json new file mode 100644 index 0000000000..357b39f378 --- /dev/null +++ b/tests/reference/asr-test_unsupported_type-0d813dd.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_unsupported_type-0d813dd", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_unsupported_type.py", + "infile_hash": "ff3af4fffe097c4ecd6ab673301b37806aefdd77c661d5b4afbbfc5d", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_unsupported_type-0d813dd.stderr", + "stderr_hash": "1675de57db132a5a4a589070d7c54ff23a57532bd967ccb416ff8c2a", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_unsupported_type-0d813dd.stderr b/tests/reference/asr-test_unsupported_type-0d813dd.stderr new file mode 100644 index 0000000000..2ea17a3b18 --- /dev/null +++ b/tests/reference/asr-test_unsupported_type-0d813dd.stderr @@ -0,0 +1,5 @@ +semantic error: Unsupported type annotation: i128 + --> tests/errors/test_unsupported_type.py:2:8 + | +2 | i: i128 + | ^^^^ diff --git a/tests/reference/asr-tuple1-09972ab.json b/tests/reference/asr-tuple1-09972ab.json index 366d81194d..f881d445b0 100644 --- a/tests/reference/asr-tuple1-09972ab.json +++ b/tests/reference/asr-tuple1-09972ab.json @@ -2,11 +2,11 @@ "basename": "asr-tuple1-09972ab", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/tuple1.py", - "infile_hash": "9ac0ef90dead58ed997d3b3cef99cbe8ef7658e09a0e72d0d7f19dad", + "infile_hash": "84bde837752a9a2998906c4aafdd87bcaaf0aff168187fcf47156b4c", "outfile": null, "outfile_hash": null, "stdout": "asr-tuple1-09972ab.stdout", - "stdout_hash": "9edc50454479a2846465e85bad91439567b8bc25d6556650b9073d0a", + "stdout_hash": "568051957577476cbf1fe1d1cb50abf8643e78900f0402f4032a8270", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-tuple1-09972ab.stdout b/tests/reference/asr-tuple1-09972ab.stdout index 3e6e152fb0..7f24e67178 100644 --- a/tests/reference/asr-tuple1-09972ab.stdout +++ b/tests/reference/asr-tuple1-09972ab.stdout @@ -1 +1 @@ -(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_Tuple: (Subroutine (SymbolTable 2 {a1: (Variable 2 a1 Local () () Default (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])]) Source Public Required .false.), a2: (Variable 2 a2 Local () () Default (Tuple [(Character 1 -2 () []) (Character 1 -2 () []) (Character 1 -2 () [])]) Source Public Required .false.), a3: (Variable 2 a3 Local () () Default (Tuple [(Integer 4 []) (Integer 4 []) (Real 4 []) (Character 1 -2 () [])]) Source Public Required .false.), a4: (Variable 2 a4 Local () () Default (Tuple [(Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])]) (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])]) Source Public Required .false.), a5: (Variable 2 a5 Local () () Default (Tuple [(Tuple [(Character 1 -2 () []) (Character 1 -2 () []) (Real 4 [])]) (Tuple [(Character 1 -2 () []) (Integer 4 []) (Real 4 [])])]) Source Public Required .false.), b0: (Variable 2 b0 Local () () Default (Integer 4 []) Source Public Required .false.), b1: (Variable 2 b1 Local () () Default (Integer 4 []) Source Public Required .false.)}) test_Tuple [] [(= (Var 2 a1) (TupleConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])) ()) (= (Var 2 a1) (TupleConstant [(UnaryOp USub (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) (UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])) ()) (= (Var 2 a2) (TupleConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (Tuple [(Character 1 1 () []) (Character 1 1 () []) (Character 1 1 () [])])) ()) (= (Var 2 a3) (TupleConstant [(UnaryOp USub (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (UnaryOp USub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (RealConstant 0.450000 (Real 8 [])) (StringConstant "d" (Character 1 1 () []))] (Tuple [(Integer 4 []) (Integer 4 []) (Real 8 []) (Character 1 1 () [])])) ()) (= (Var 2 a4) (TupleConstant [(TupleConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])) (TupleConstant [(IntegerConstant 4 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])) (IntegerConstant 6 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])]))] (Tuple [(Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])]) (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])])) ()) (= (Var 2 a5) (TupleConstant [(TupleConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (RealConstant 3.400000 (Real 8 []))] (Tuple [(Character 1 1 () []) (Character 1 1 () []) (Real 8 [])])) (TupleConstant [(StringConstant "c" (Character 1 1 () [])) (IntegerConstant 3 (Integer 4 [])) (RealConstant 5.600000 (Real 8 []))] (Tuple [(Character 1 1 () []) (Integer 4 []) (Real 8 [])]))] (Tuple [(Tuple [(Character 1 1 () []) (Character 1 1 () []) (Real 8 [])]) (Tuple [(Character 1 1 () []) (Integer 4 []) (Real 8 [])])])) ()) (= (Var 2 b0) (TupleItem 2 a1 (BinOp (IntegerConstant 0 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Integer 4 []) ()) ()) (= (TupleConstant [(Var 2 b0) (Var 2 b1)] (Tuple [(Integer 4 []) (Integer 4 [])])) (TupleConstant [(TupleItem 2 a1 (BinOp (IntegerConstant 2 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Integer 4 []) ()) (TupleItem 2 a1 (BinOp (IntegerConstant 1 (Integer 4 [])) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) () ()) (Integer 4 []) ())] (Tuple [(Integer 4 []) (Integer 4 [])])) ())] Source Public Implementation () .false. .false.)}) []) +(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_Tuple: (Subroutine (SymbolTable 2 {a1: (Variable 2 a1 Local () () Default (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])]) Source Public Required .false.), a2: (Variable 2 a2 Local () () Default (Tuple [(Character 1 -2 () []) (Character 1 -2 () []) (Character 1 -2 () [])]) Source Public Required .false.), a3: (Variable 2 a3 Local () () Default (Tuple [(Integer 4 []) (Integer 4 []) (Real 4 []) (Character 1 -2 () [])]) Source Public Required .false.), a4: (Variable 2 a4 Local () () Default (Tuple [(Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])]) (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])]) Source Public Required .false.), a5: (Variable 2 a5 Local () () Default (Tuple [(Tuple [(Character 1 -2 () []) (Character 1 -2 () []) (Real 4 [])]) (Tuple [(Character 1 -2 () []) (Integer 4 []) (Real 4 [])])]) Source Public Required .false.), b0: (Variable 2 b0 Local () () Default (Integer 4 []) Source Public Required .false.), b1: (Variable 2 b1 Local () () Default (Integer 4 []) Source Public Required .false.), float_mem: (Variable 2 float_mem Local () () Default (Real 4 []) Source Public Required .false.), float_mem1: (Variable 2 float_mem1 Local () () Default (Real 4 []) Source Public Required .false.), float_mem2: (Variable 2 float_mem2 Local () () Default (Real 4 []) Source Public Required .false.)}) test_Tuple [] [(= (Var 2 a1) (TupleConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])) ()) (= (Var 2 a1) (TupleConstant [(IntegerUnaryMinus (IntegerConstant 3 (Integer 4 [])) (Integer 4 []) (IntegerConstant -3 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 [])))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])) ()) (= (Var 2 a2) (TupleConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (StringConstant "c" (Character 1 1 () []))] (Tuple [(Character 1 1 () []) (Character 1 1 () []) (Character 1 1 () [])])) ()) (= (Var 2 float_mem) (Cast (RealConstant 4.50000000000000011e-01 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 4.50000000000000011e-01 (Real 4 []))) ()) (= (Var 2 a3) (TupleConstant [(IntegerUnaryMinus (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) (IntegerConstant -2 (Integer 4 []))) (IntegerUnaryMinus (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant -1 (Integer 4 []))) (Var 2 float_mem) (StringConstant "d" (Character 1 1 () []))] (Tuple [(Integer 4 []) (Integer 4 []) (Real 4 []) (Character 1 1 () [])])) ()) (= (Var 2 a4) (TupleConstant [(TupleConstant [(IntegerConstant 1 (Integer 4 [])) (IntegerConstant 2 (Integer 4 [])) (IntegerConstant 3 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])) (TupleConstant [(IntegerConstant 4 (Integer 4 [])) (IntegerConstant 5 (Integer 4 [])) (IntegerConstant 6 (Integer 4 []))] (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])]))] (Tuple [(Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])]) (Tuple [(Integer 4 []) (Integer 4 []) (Integer 4 [])])])) ()) (= (Var 2 float_mem1) (Cast (RealConstant 3.39999999999999991e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 3.39999999999999991e+00 (Real 4 []))) ()) (= (Var 2 float_mem2) (Cast (RealConstant 5.59999999999999964e+00 (Real 8 [])) RealToReal (Real 4 []) (RealConstant 5.59999999999999964e+00 (Real 4 []))) ()) (= (Var 2 a5) (TupleConstant [(TupleConstant [(StringConstant "a" (Character 1 1 () [])) (StringConstant "b" (Character 1 1 () [])) (Var 2 float_mem1)] (Tuple [(Character 1 1 () []) (Character 1 1 () []) (Real 4 [])])) (TupleConstant [(StringConstant "c" (Character 1 1 () [])) (IntegerConstant 3 (Integer 4 [])) (Var 2 float_mem2)] (Tuple [(Character 1 1 () []) (Integer 4 []) (Real 4 [])]))] (Tuple [(Tuple [(Character 1 1 () []) (Character 1 1 () []) (Real 4 [])]) (Tuple [(Character 1 1 () []) (Integer 4 []) (Real 4 [])])])) ()) (= (Var 2 b0) (TupleItem (Var 2 a1) (IntegerConstant 0 (Integer 4 [])) (Integer 4 []) ()) ()) (= (TupleConstant [(Var 2 b0) (Var 2 b1)] (Tuple [(Integer 4 []) (Integer 4 [])])) (TupleConstant [(TupleItem (Var 2 a1) (IntegerConstant 2 (Integer 4 [])) (Integer 4 []) ()) (TupleItem (Var 2 a1) (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ())] (Tuple [(Integer 4 []) (Integer 4 [])])) ())] Source Public Implementation () .false. .false.)}) []) diff --git a/tests/reference/asr-vec_01-66ac423.json b/tests/reference/asr-vec_01-66ac423.json new file mode 100644 index 0000000000..565f4dffee --- /dev/null +++ b/tests/reference/asr-vec_01-66ac423.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-vec_01-66ac423", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/vec_01.py", + "infile_hash": "eb012561316a4c1f1359bf7b5a0b9aee40944ece197a5bafd387a19f", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-vec_01-66ac423.stdout", + "stdout_hash": "898b1ffb8d283857d79b3abb9a616dbeefe8275cd9f6fc58f8600d5a", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-vec_01-66ac423.stdout b/tests/reference/asr-vec_01-66ac423.stdout new file mode 100644 index 0000000000..50b8753e55 --- /dev/null +++ b/tests/reference/asr-vec_01-66ac423.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 loop_vec () [] ())] Source Public Implementation () .false. .false.), loop_vec: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))))]) Source Public Required .false.), b: (Variable 2 b Local () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))))]) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.)}) loop_vec [] [(DoLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))) (IntegerConstant 1 (Integer 4 []))) [(= (ArrayItem (Var 2 b) [(() (Var 2 i) ())] (Real 8 []) ()) (RealConstant 5.00000000000000000e+00 (Real 8 [])) ())]) (DoLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))) (IntegerConstant 1 (Integer 4 []))) [(= (ArrayItem (Var 2 a) [(() (Var 2 i) ())] (Real 8 []) ()) (ArrayItem (Var 2 b) [(() (Var 2 i) ())] (Real 8 []) ()) ())]) (DoLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))) (IntegerConstant 1 (Integer 4 []))) [(Assert (RealCompare (ArrayItem (Var 2 a) [(() (Var 2 i) ())] (Real 8 []) ()) Eq (RealConstant 5.00000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ())])] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/ast-complex1-800b4bb.json b/tests/reference/ast-complex1-800b4bb.json index 9c714ec195..cd010beb03 100644 --- a/tests/reference/ast-complex1-800b4bb.json +++ b/tests/reference/ast-complex1-800b4bb.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "ast-complex1-800b4bb.stdout", - "stdout_hash": "1ea11e6b755f10df2603a52de51cb2c04605baeb0f90f01237bf6fb9", + "stdout_hash": "58f00fb2983c857ef011c649d8b43d19d448f073ba94a3ac18c89ea5", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-complex1-800b4bb.stdout b/tests/reference/ast-complex1-800b4bb.stdout index 8626bea9c5..421a08e35d 100644 --- a/tests/reference/ast-complex1-800b4bb.stdout +++ b/tests/reference/ast-complex1-800b4bb.stdout @@ -1 +1 @@ -(Module [(FunctionDef test_complex ([] [] [] [] [] [] []) [(AnnAssign (Name c Store) (Name c32 Load) () 1) (AnnAssign (Name c1 Store) (Name c32 Load) () 1) (AnnAssign (Name c2 Store) (Name c32 Load) () 1) (AnnAssign (Name c3 Store) (Name c64 Load) () 1) (AnnAssign (Name b Store) (Name bool Load) () 1) (Assign [(Name c Store)] (Call (Name complex Load) [] []) ()) (Assign [(Name c Store)] (Call (Name complex Load) [(ConstantFloat 3.400000 ())] []) ()) (Assign [(Name c Store)] (Call (Name complex Load) [(ConstantFloat 5.000000 ()) (ConstantFloat 4.300000 ())] []) ()) (Assign [(Name c Store)] (Call (Name complex Load) [(ConstantInt 1 ())] []) ()) (Assign [(Name c1 Store)] (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] []) ()) (Assign [(Name c2 Store)] (Call (Name complex Load) [(ConstantInt 2 ()) (ConstantFloat 4.500000 ())] []) ()) (Assign [(Name c3 Store)] (Call (Name complex Load) [(ConstantFloat 3.000000 ()) (ConstantFloat 4.000000 ())] []) ()) (Assign [(Name b Store)] (Compare (Name c1 Load) NotEq [(Name c2 Load)]) ()) (Assign [(Name b Store)] (Compare (Name c1 Load) Eq [(Name c3 Load)]) ()) (Assign [(Name c Store)] (BinOp (Name c1 Load) Add (Name c2 Load)) ()) (Assign [(Name c Store)] (BinOp (Name c2 Load) Sub (Name c1 Load)) ()) (Assign [(Name c Store)] (BinOp (Name c1 Load) Mult (Name c2 Load)) ()) (Assign [(Name c Store)] (BinOp (Call (Name complex Load) [(ConstantInt 1 ()) (ConstantInt 2 ())] []) Pow (Call (Name complex Load) [(ConstantFloat 3.345340 ()) (ConstantFloat 4.867868 ())] [])) ()) (Assign [(Name c Store)] (BinOp (Call (Name complex Load) [(ConstantInt 1 ()) (ConstantInt 2 ())] []) Mult (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] [])) ()) (Assign [(Name c Store)] (BinOp (Call (Name complex Load) [(ConstantInt 4 ()) (ConstantInt 5 ())] []) Sub (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] [])) ())] [] () ()) (FunctionDef test ([] [] [] [] [] [] []) [(AnnAssign (Name x Store) (Name c64 Load) () 1) (AnnAssign (Name y Store) (Name c64 Load) () 1) (AnnAssign (Name z Store) (Name c32 Load) () 1) (Assign [(Name x Store)] (BinOp (ConstantInt 2 ()) Add (ConstantComplex 0.000000 3.000000 ())) ()) (Assign [(Name y Store)] (BinOp (ConstantInt 5 ()) Add (ConstantComplex 0.000000 5.000000 ())) ()) (Assign [(Name z Store)] (BinOp (Name x Load) Add (Name y Load)) ()) (Assign [(Name z Store)] (BinOp (Name x Load) Sub (Name y Load)) ()) (Assign [(Name z Store)] (BinOp (ConstantInt 2 ()) Mult (Name x Load)) ())] [] () ())] []) +(Module [(FunctionDef test_complex ([] [] [] [] [] [] []) [(AnnAssign (Name c Store) (Name c32 Load) () 1) (AnnAssign (Name c1 Store) (Name c32 Load) () 1) (AnnAssign (Name c2 Store) (Name c32 Load) () 1) (AnnAssign (Name c3 Store) (Name c64 Load) () 1) (AnnAssign (Name b Store) (Name bool Load) () 1) (Assign [(Name c Store)] (Call (Name complex Load) [] []) ()) (Assign [(Name c Store)] (Call (Name complex Load) [(ConstantFloat 3.39999999999999991e+00 ())] []) ()) (Assign [(Name c Store)] (Call (Name complex Load) [(ConstantFloat 5.00000000000000000e+00 ()) (ConstantFloat 4.29999999999999982e+00 ())] []) ()) (Assign [(Name c Store)] (Call (Name complex Load) [(ConstantInt 1 ())] []) ()) (Assign [(Name c1 Store)] (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] []) ()) (Assign [(Name c2 Store)] (Call (Name complex Load) [(ConstantInt 2 ()) (ConstantFloat 4.50000000000000000e+00 ())] []) ()) (Assign [(Name c3 Store)] (Call (Name complex Load) [(ConstantFloat 3.00000000000000000e+00 ()) (ConstantFloat 4.00000000000000000e+00 ())] []) ()) (Assign [(Name b Store)] (Compare (Name c1 Load) NotEq [(Name c2 Load)]) ()) (Assign [(Name b Store)] (Compare (Name c1 Load) Eq [(Name c3 Load)]) ()) (Assign [(Name c Store)] (BinOp (Name c1 Load) Add (Name c2 Load)) ()) (Assign [(Name c Store)] (BinOp (Name c2 Load) Sub (Name c1 Load)) ()) (Assign [(Name c Store)] (BinOp (Name c1 Load) Mult (Name c2 Load)) ()) (Assign [(Name c Store)] (BinOp (Call (Name complex Load) [(ConstantInt 1 ()) (ConstantInt 2 ())] []) Pow (Call (Name complex Load) [(ConstantFloat 3.34534000000000020e+00 ()) (ConstantFloat 4.86786779999999997e+00 ())] [])) ()) (Assign [(Name c Store)] (BinOp (Call (Name complex Load) [(ConstantInt 1 ()) (ConstantInt 2 ())] []) Mult (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] [])) ()) (Assign [(Name c Store)] (BinOp (Call (Name complex Load) [(ConstantInt 4 ()) (ConstantInt 5 ())] []) Sub (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] [])) ())] [] () ()) (FunctionDef test ([] [] [] [] [] [] []) [(AnnAssign (Name x Store) (Name c64 Load) () 1) (AnnAssign (Name y Store) (Name c64 Load) () 1) (AnnAssign (Name z Store) (Name c32 Load) () 1) (Assign [(Name x Store)] (BinOp (ConstantInt 2 ()) Add (ConstantComplex 0.00000000000000000e+00 3.00000000000000000e+00 ())) ()) (Assign [(Name y Store)] (BinOp (ConstantInt 5 ()) Add (ConstantComplex 0.00000000000000000e+00 5.00000000000000000e+00 ())) ()) (Assign [(Name z Store)] (BinOp (Name x Load) Add (Name y Load)) ()) (Assign [(Name z Store)] (BinOp (Name x Load) Sub (Name y Load)) ()) (Assign [(Name z Store)] (BinOp (ConstantInt 2 ()) Mult (Name x Load)) ())] [] () ())] []) diff --git a/tests/reference/ast-constants1-91cb6ff.json b/tests/reference/ast-constants1-91cb6ff.json index 6d97ffe334..9a157e0da4 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": "680bb6f62b6e7d58fdddc891954816cea0c25b9201576498f149849e", + "infile_hash": "0a352bce3bcf6a5662115060afcaee46a32e2577c0be9ce8b343eeb4", "outfile": null, "outfile_hash": null, "stdout": "ast-constants1-91cb6ff.stdout", - "stdout_hash": "c8ef65f421b3d2ccb98c59ea04610136894722d78da454865a0c1f6b", + "stdout_hash": "215b4c5d0a30a557d205eb2096b909e9083efa816ec98c5057e4a447", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-constants1-91cb6ff.stdout b/tests/reference/ast-constants1-91cb6ff.stdout index 2538d728b7..8ab5553155 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 "c" ()) (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 "c" ()) (ConstantStr "b" ()) (ConstantStr "c" ())])] []) ()) (AnnAssign (Name l Store) (Subscript (Name list Load) (Name i32 Load) Load) () 1) (Assign [(Name l Store)] (List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ()) (ConstantInt 4 ())] Load) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Name l Load)] []) ()) (Expr (Call (Attribute (Name l Load) append Load) [(ConstantInt 5 ())] [])) (Assign [(Name a Store)] (Call (Name len Load) [(Name l Load)] []) ())] [] () ()) (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. ())] []) ())] [] () ()) (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. ())] []) ())] [] () ()) (FunctionDef test_divmod ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load)] Load) 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 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.45000000000000018e+00 ())] []) ()) (Assign [(Name b Store)] (Call (Name abs Load) [(UnaryOp USub (ConstantFloat 5.34634000000000015e+03 ()))] []) ()) (Assign [(Name b Store)] (Call (Name abs Load) [(Call (Name complex Load) [(ConstantFloat 3.45000000000000018e+00 ()) (ConstantFloat 5.59999999999999964e+00 ())] [])] []) ())] [] () ()) (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 "c" ()) (ConstantStr "b" ()) (ConstantFloat 3.39999999999999991e+00 ())] Load) (Tuple [(ConstantStr "c" ()) (ConstantInt 3 ()) (ConstantFloat 5.59999999999999964e+00 ())] 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 "c" ()) (ConstantStr "b" ()) (ConstantStr "c" ())])] []) ()) (AnnAssign (Name l Store) (Subscript (Name list Load) (Name i32 Load) Load) () 1) (Assign [(Name l Store)] (List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ()) (ConstantInt 4 ())] Load) ()) (Assign [(Name a Store)] (Call (Name len Load) [(Name l Load)] []) ()) (Expr (Call (Attribute (Name l Load) append Load) [(ConstantInt 5 ())] [])) (Assign [(Name a Store)] (Call (Name len Load) [(Name l Load)] []) ())] [] () ()) (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.29999999999999982e+00 ())] []) ()) (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) [(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.55999999999999961e+00 ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(ConstantInt 5 ())] []) ()) (Assign [(Name a Store)] (Call (Name int Load) [(UnaryOp USub (ConstantFloat 5.00000999999999962e+00 ()))] []) ()) (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.55999999999999961e+00 ())] []) ()) (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. ())] []) ())] [] () ()) (FunctionDef test_divmod ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load)] Load) 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/reference/ast-doconcurrentloop_01-ed7017b.json b/tests/reference/ast-doconcurrentloop_01-ed7017b.json index d26afaa842..98ee970c71 100644 --- a/tests/reference/ast-doconcurrentloop_01-ed7017b.json +++ b/tests/reference/ast-doconcurrentloop_01-ed7017b.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "ast-doconcurrentloop_01-ed7017b.stdout", - "stdout_hash": "c094717f0ec2f4766a1692441880820140edd25e35bc52a58ff64196", + "stdout_hash": "9bb84ccfc923d9d994d354fe887fd916995a7ac27eccf37cab76c2fd", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-doconcurrentloop_01-ed7017b.stdout b/tests/reference/ast-doconcurrentloop_01-ed7017b.stdout index b8b196b399..9fe67bd8dd 100644 --- a/tests/reference/ast-doconcurrentloop_01-ed7017b.stdout +++ b/tests/reference/ast-doconcurrentloop_01-ed7017b.stdout @@ -1 +1 @@ -(Module [(FunctionDef triad ([] [(a (Subscript (Name f32 Load) (Slice () () ()) Load) ()) (b (Subscript (Name f32 Load) (Slice () () ()) Load) ()) (scalar (Name f32 Load) ()) (c (Subscript (Name f32 Load) (Slice () () ()) Load) ())] [] [] [] [] []) [(AnnAssign (Name N Store) (Name i32 Load) () 1) (AnnAssign (Name i Store) (Name i32 Load) () 1) (Assign [(Name N Store)] (Call (Name size Load) [(Name a Load)] []) ()) (For (Name i Store) (Call (Name range Load) [(Name N Load)] []) [(Assign [(Subscript (Name c Load) (Name i Load) Store)] (BinOp (Subscript (Name a Load) (Name i Load) Load) Add (BinOp (Name scalar Load) Mult (Subscript (Name b Load) (Name i Load) Load))) ())] [] "parallel")] [] () ()) (FunctionDef main0 ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Subscript (Name f32 Load) (ConstantInt 10000 ()) Load) () 1) (AnnAssign (Name b Store) (Subscript (Name f32 Load) (ConstantInt 10000 ()) Load) () 1) (AnnAssign (Name c Store) (Subscript (Name f32 Load) (ConstantInt 10000 ()) Load) () 1) (AnnAssign (Name scalar Store) (Name f32 Load) () 1) (AnnAssign (Name i Store) (Name i32 Load) () 1) (AnnAssign (Name nsize Store) (Name i32 Load) () 1) (Assign [(Name scalar Store)] (ConstantFloat 10.000000 ()) ()) (Assign [(Name nsize Store)] (Call (Name size Load) [(Name a Load)] []) ()) (For (Name i Store) (Call (Name range Load) [(Name nsize Load)] []) [(Assign [(Subscript (Name a Load) (Name i Load) Store)] (ConstantFloat 5.000000 ()) ()) (Assign [(Subscript (Name b Load) (Name i Load) Store)] (ConstantFloat 5.000000 ()) ())] [] "parallel") (Expr (Call (Name triad Load) [(Name a Load) (Name b Load) (Name scalar Load) (Name c Load)] [])) (Expr (Call (Name print Load) [(ConstantStr "End Stream Triad" ())] []))] [] () ()) (Expr (Call (Name main0 Load) [] []))] []) +(Module [(FunctionDef triad ([] [(a (Subscript (Name f32 Load) (Slice () () ()) Load) ()) (b (Subscript (Name f32 Load) (Slice () () ()) Load) ()) (scalar (Name f32 Load) ()) (c (Subscript (Name f32 Load) (Slice () () ()) Load) ())] [] [] [] [] []) [(AnnAssign (Name N Store) (Name i32 Load) () 1) (AnnAssign (Name i Store) (Name i32 Load) () 1) (Assign [(Name N Store)] (Call (Name size Load) [(Name a Load)] []) ()) (For (Name i Store) (Call (Name range Load) [(Name N Load)] []) [(Assign [(Subscript (Name c Load) (Name i Load) Store)] (BinOp (Subscript (Name a Load) (Name i Load) Load) Add (BinOp (Name scalar Load) Mult (Subscript (Name b Load) (Name i Load) Load))) ())] [] "parallel")] [] () ()) (FunctionDef main0 ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Subscript (Name f32 Load) (ConstantInt 10000 ()) Load) () 1) (AnnAssign (Name b Store) (Subscript (Name f32 Load) (ConstantInt 10000 ()) Load) () 1) (AnnAssign (Name c Store) (Subscript (Name f32 Load) (ConstantInt 10000 ()) Load) () 1) (AnnAssign (Name scalar Store) (Name f32 Load) () 1) (AnnAssign (Name i Store) (Name i32 Load) () 1) (AnnAssign (Name nsize Store) (Name i32 Load) () 1) (Assign [(Name scalar Store)] (ConstantFloat 1.00000000000000000e+01 ()) ()) (Assign [(Name nsize Store)] (Call (Name size Load) [(Name a Load)] []) ()) (For (Name i Store) (Call (Name range Load) [(Name nsize Load)] []) [(Assign [(Subscript (Name a Load) (Name i Load) Store)] (ConstantFloat 5.00000000000000000e+00 ()) ()) (Assign [(Subscript (Name b Load) (Name i Load) Store)] (ConstantFloat 5.00000000000000000e+00 ()) ())] [] "parallel") (Expr (Call (Name triad Load) [(Name a Load) (Name b Load) (Name scalar Load) (Name c Load)] [])) (Expr (Call (Name print Load) [(ConstantStr "End Stream Triad" ())] []))] [] () ()) (Expr (Call (Name main0 Load) [] []))] []) diff --git a/tests/reference/ast-ellipsis1-4f6c4dd.json b/tests/reference/ast-ellipsis1-4f6c4dd.json new file mode 100644 index 0000000000..0e042fd21c --- /dev/null +++ b/tests/reference/ast-ellipsis1-4f6c4dd.json @@ -0,0 +1,13 @@ +{ + "basename": "ast-ellipsis1-4f6c4dd", + "cmd": "lpython --show-ast --no-color {infile} -o {outfile}", + "infile": "tests/parser/ellipsis1.py", + "infile_hash": "24df29cba718c679016f3758a2eccafbeb9cfebd56265fd8da16bee1", + "outfile": null, + "outfile_hash": null, + "stdout": "ast-ellipsis1-4f6c4dd.stdout", + "stdout_hash": "99ae0e12fd8efcd71433e66f10ba7ba5b59e165ddd5ded0072593b12", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast-ellipsis1-4f6c4dd.stdout b/tests/reference/ast-ellipsis1-4f6c4dd.stdout new file mode 100644 index 0000000000..51aa9eb229 --- /dev/null +++ b/tests/reference/ast-ellipsis1-4f6c4dd.stdout @@ -0,0 +1 @@ +(Module [(Import [(numpy np)]) (ImportFrom typing [(Callable ())] 0) (Assign [(Name array Store)] (Call (Attribute (Attribute (Name np Load) random Load) rand Load) [(ConstantInt 2 ()) (ConstantInt 2 ()) (ConstantInt 2 ()) (ConstantInt 2 ())] []) ()) (Expr (Call (Name print Load) [(Subscript (Name array Load) (Tuple [(ConstantEllipsis ()) (ConstantInt 0 ())] Load) Load)] [])) (Expr (Call (Name print Load) [(Subscript (Name array Load) (Tuple [(Name Ellipsis Load) (ConstantInt 0 ())] Load) Load)] [])) (FunctionDef inject ([] [(get_next_item (Subscript (Name Callable Load) (Tuple [(ConstantEllipsis ()) (Name str Load)] Load) Load) ())] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ()) (FunctionDef foo ([] [(x (ConstantEllipsis ()) ())] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ()) (ClassDef flow [] [] [(FunctionDef __understand__ ([] [(self () ()) (name (Name str Load) ()) (value (ConstantEllipsis ()) ())] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ())] []) (FunctionDef foo ([] [(x () ())] [] [] [] [] [(ConstantEllipsis ())]) [(Return (Name x Load))] [] () ()) (FunctionDef test ([] [] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] () ()) (ClassDef Todo [] [] [(Expr (ConstantEllipsis ()))] []) (Assign [(Name x Store)] (List [(ConstantInt 1 ()) (List [(ConstantInt 2 ()) (List [(ConstantEllipsis ())] Load) (ConstantInt 3 ())] Load)] Load) ()) (Assign [(Name l Store)] (List [(ConstantEllipsis ()) (ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (If (Compare (Name x Load) Is [(ConstantEllipsis ())]) [(Pass)] []) (FunctionDef partial ([] [(func (Subscript (Name Callable Load) (Tuple [(ConstantEllipsis ()) (Name str Load)] Load) Load) ())] [(args () ())] [] [] [] []) [(Pass)] [] (Subscript (Name Callable Load) (Tuple [(ConstantEllipsis ()) (Name str Load)] Load) Load) ()) (ClassDef xyz [] [] [(AnnAssign (Name abc Store) (Name str Load) (ConstantEllipsis ()) 1) (FunctionDef __init__ ([] [(self () ()) (name (Name str Load) ())] [] [] [] [] [(ConstantEllipsis ())]) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ())] [])] []) diff --git a/tests/reference/ast-expr10-a8d646d.json b/tests/reference/ast-expr10-a8d646d.json index 9f44b1eb73..1e311ef0d3 100644 --- a/tests/reference/ast-expr10-a8d646d.json +++ b/tests/reference/ast-expr10-a8d646d.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "ast-expr10-a8d646d.stdout", - "stdout_hash": "820db03eda69b292dc72d27b983684435a6b17bed2274761469e73c5", + "stdout_hash": "072ab27812c05ad1771af6427c8bdc60ec708d1350730671e370c90e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-expr10-a8d646d.stdout b/tests/reference/ast-expr10-a8d646d.stdout index ddf3ff7217..19f8956155 100644 --- a/tests/reference/ast-expr10-a8d646d.stdout +++ b/tests/reference/ast-expr10-a8d646d.stdout @@ -1 +1 @@ -(Module [(FunctionDef test_UnaryOp ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (UnaryOp UAdd (ConstantInt 4 ())) ()) (Assign [(Name a Store)] (UnaryOp USub (ConstantInt 500 ())) ()) (Assign [(Name a Store)] (UnaryOp Invert (ConstantInt 5 ())) ()) (AnnAssign (Name b Store) (Name bool Load) () 1) (Assign [(Name b Store)] (UnaryOp Not (ConstantInt 5 ())) ()) (Assign [(Name b Store)] (UnaryOp Not (UnaryOp USub (ConstantInt 1 ()))) ()) (Assign [(Name b Store)] (UnaryOp Not (ConstantInt 0 ())) ()) (AnnAssign (Name f Store) (Name f32 Load) () 1) (Assign [(Name f Store)] (UnaryOp UAdd (ConstantFloat 1.000000 ())) ()) (Assign [(Name f Store)] (UnaryOp USub (ConstantFloat 183745.534000 ())) ()) (AnnAssign (Name b1 Store) (Name bool Load) () 1) (AnnAssign (Name b2 Store) (Name bool Load) () 1) (AnnAssign (Name b3 Store) (Name bool Load) () 1) (Assign [(Name b1 Store)] (ConstantBool .true. ()) ()) (Assign [(Name b2 Store)] (UnaryOp Not (ConstantBool .false. ())) ()) (Assign [(Name b3 Store)] (UnaryOp Not (Name b2 Load)) ()) (Assign [(Name a Store)] (UnaryOp UAdd (ConstantBool .true. ())) ()) (Assign [(Name a Store)] (UnaryOp USub (ConstantBool .false. ())) ()) (Assign [(Name a Store)] (UnaryOp Invert (ConstantBool .true. ())) ()) (AnnAssign (Name c Store) (Name c32 Load) () 1) (Assign [(Name c Store)] (UnaryOp UAdd (Call (Name complex Load) [(ConstantInt 1 ()) (ConstantInt 2 ())] [])) ()) (Assign [(Name c Store)] (UnaryOp USub (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantFloat 65.000000 ())] [])) ()) (Assign [(Name b1 Store)] (UnaryOp Not (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] [])) ()) (Assign [(Name b2 Store)] (UnaryOp Not (Call (Name complex Load) [(ConstantInt 0 ()) (ConstantInt 0 ())] [])) ())] [] () ())] []) +(Module [(FunctionDef test_UnaryOp ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (UnaryOp UAdd (ConstantInt 4 ())) ()) (Assign [(Name a Store)] (UnaryOp USub (ConstantInt 500 ())) ()) (Assign [(Name a Store)] (UnaryOp Invert (ConstantInt 5 ())) ()) (AnnAssign (Name b Store) (Name bool Load) () 1) (Assign [(Name b Store)] (UnaryOp Not (ConstantInt 5 ())) ()) (Assign [(Name b Store)] (UnaryOp Not (UnaryOp USub (ConstantInt 1 ()))) ()) (Assign [(Name b Store)] (UnaryOp Not (ConstantInt 0 ())) ()) (AnnAssign (Name f Store) (Name f32 Load) () 1) (Assign [(Name f Store)] (UnaryOp UAdd (ConstantFloat 1.00000000000000000e+00 ())) ()) (Assign [(Name f Store)] (UnaryOp USub (ConstantFloat 1.83745534000000014e+05 ())) ()) (AnnAssign (Name b1 Store) (Name bool Load) () 1) (AnnAssign (Name b2 Store) (Name bool Load) () 1) (AnnAssign (Name b3 Store) (Name bool Load) () 1) (Assign [(Name b1 Store)] (ConstantBool .true. ()) ()) (Assign [(Name b2 Store)] (UnaryOp Not (ConstantBool .false. ())) ()) (Assign [(Name b3 Store)] (UnaryOp Not (Name b2 Load)) ()) (Assign [(Name a Store)] (UnaryOp UAdd (ConstantBool .true. ())) ()) (Assign [(Name a Store)] (UnaryOp USub (ConstantBool .false. ())) ()) (Assign [(Name a Store)] (UnaryOp Invert (ConstantBool .true. ())) ()) (AnnAssign (Name c Store) (Name c32 Load) () 1) (Assign [(Name c Store)] (UnaryOp UAdd (Call (Name complex Load) [(ConstantInt 1 ()) (ConstantInt 2 ())] [])) ()) (Assign [(Name c Store)] (UnaryOp USub (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantFloat 6.50000000000000000e+01 ())] [])) ()) (Assign [(Name b1 Store)] (UnaryOp Not (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] [])) ()) (Assign [(Name b2 Store)] (UnaryOp Not (Call (Name complex Load) [(ConstantInt 0 ()) (ConstantInt 0 ())] [])) ())] [] () ())] []) diff --git a/tests/reference/ast-expr13-c35ace1.json b/tests/reference/ast-expr13-c35ace1.json index 5a2c133700..2a7e650a74 100644 --- a/tests/reference/ast-expr13-c35ace1.json +++ b/tests/reference/ast-expr13-c35ace1.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "ast-expr13-c35ace1.stdout", - "stdout_hash": "4eefbd260e67134f1a3e011aaea29567cd6dde2f94e0c05e952d7101", + "stdout_hash": "35d5a71c6c3e9b4d63eac8d83fcc9f4118fb36e78c219da84f3c3761", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-expr13-c35ace1.stdout b/tests/reference/ast-expr13-c35ace1.stdout index 345eda34fd..372634ae3b 100644 --- a/tests/reference/ast-expr13-c35ace1.stdout +++ b/tests/reference/ast-expr13-c35ace1.stdout @@ -1 +1 @@ -(Module [(FunctionDef test_Compare ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name bool Load) () 1) (Assign [(Name a Store)] (Compare (ConstantInt 5 ()) Gt [(ConstantInt 4 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantInt 5 ()) LtE [(ConstantInt 4 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantInt 5 ()) Lt [(ConstantInt 4 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantFloat 5.600000 ()) GtE [(ConstantFloat 5.599990 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantFloat 3.300000 ()) Eq [(ConstantFloat 3.300000 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantFloat 3.300000 ()) NotEq [(ConstantFloat 3.400000 ())]) ()) (Assign [(Name a Store)] (Compare (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] []) Eq [(Call (Name complex Load) [(ConstantFloat 3.000000 ()) (ConstantFloat 4.000000 ())] [])]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "abc" ()) Gt [(ConstantStr "abd" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "" ()) Lt [(ConstantStr "s" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "-abs" ()) GtE [(ConstantStr "abs" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "abcd" ()) LtE [(ConstantStr "abcde" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "abc" ()) Eq [(ConstantStr "abc" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "abc" ()) NotEq [(ConstantStr "abd" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "" ()) Eq [(ConstantStr "+" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantBool .true. ()) Gt [(ConstantBool .false. ())]) ()) (Assign [(Name a Store)] (Compare (ConstantBool .true. ()) Eq [(ConstantBool .true. ())]) ()) (Assign [(Name a Store)] (Compare (ConstantBool .false. ()) NotEq [(ConstantBool .true. ())]) ()) (Assign [(Name a Store)] (Compare (ConstantBool .false. ()) GtE [(ConstantBool .true. ())]) ())] [] () ())] []) +(Module [(FunctionDef test_Compare ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name bool Load) () 1) (Assign [(Name a Store)] (Compare (ConstantInt 5 ()) Gt [(ConstantInt 4 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantInt 5 ()) LtE [(ConstantInt 4 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantInt 5 ()) Lt [(ConstantInt 4 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantFloat 5.59999999999999964e+00 ()) GtE [(ConstantFloat 5.59999000000000002e+00 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantFloat 3.29999999999999982e+00 ()) Eq [(ConstantFloat 3.29999999999999982e+00 ())]) ()) (Assign [(Name a Store)] (Compare (ConstantFloat 3.29999999999999982e+00 ()) NotEq [(ConstantFloat 3.39999999999999991e+00 ())]) ()) (Assign [(Name a Store)] (Compare (Call (Name complex Load) [(ConstantInt 3 ()) (ConstantInt 4 ())] []) Eq [(Call (Name complex Load) [(ConstantFloat 3.00000000000000000e+00 ()) (ConstantFloat 4.00000000000000000e+00 ())] [])]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "abc" ()) Gt [(ConstantStr "abd" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "" ()) Lt [(ConstantStr "s" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "-abs" ()) GtE [(ConstantStr "abs" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "abcd" ()) LtE [(ConstantStr "abcde" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "abc" ()) Eq [(ConstantStr "abc" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "abc" ()) NotEq [(ConstantStr "abd" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantStr "" ()) Eq [(ConstantStr "+" ())]) ()) (Assign [(Name a Store)] (Compare (ConstantBool .true. ()) Gt [(ConstantBool .false. ())]) ()) (Assign [(Name a Store)] (Compare (ConstantBool .true. ()) Eq [(ConstantBool .true. ())]) ()) (Assign [(Name a Store)] (Compare (ConstantBool .false. ()) NotEq [(ConstantBool .true. ())]) ()) (Assign [(Name a Store)] (Compare (ConstantBool .false. ()) GtE [(ConstantBool .true. ())]) ())] [] () ())] []) diff --git a/tests/reference/ast-expr3-c3dcaab.json b/tests/reference/ast-expr3-c3dcaab.json index 9a68941016..4b257766a4 100644 --- a/tests/reference/ast-expr3-c3dcaab.json +++ b/tests/reference/ast-expr3-c3dcaab.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "ast-expr3-c3dcaab.stdout", - "stdout_hash": "d099629b3c7833edafafd5ac29ab000c78e7d0e4047343a663d34049", + "stdout_hash": "f8d5b442736a175dab9573a8f12aa1389146c1672656c7e67be2cb34", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-expr3-c3dcaab.stdout b/tests/reference/ast-expr3-c3dcaab.stdout index 909ea87dc6..8b166f1336 100644 --- a/tests/reference/ast-expr3-c3dcaab.stdout +++ b/tests/reference/ast-expr3-c3dcaab.stdout @@ -1 +1 @@ -(Module [(FunctionDef test_cast ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (AnnAssign (Name b Store) (Name f32 Load) () 1) (Assign [(Name a Store)] (ConstantInt 2 ()) ()) (Assign [(Name b Store)] (ConstantFloat 4.200000 ()) ()) (AugAssign (Name a Store) Mult (Name b Load)) (AugAssign (Name b Store) Add (ConstantInt 1 ())) (Assign [(Name a Store)] (ConstantInt 5 ()) ()) (AugAssign (Name a Store) Sub (ConstantFloat 3.900000 ())) (AugAssign (Name a Store) Div (Name b Load)) (Assign [(Name b Store)] (BinOp (ConstantInt 3 ()) Div (ConstantInt 4 ())) ()) (If (Compare (Name a Load) Lt [(Name b Load)]) [(Expr (Call (Name print Load) [(ConstantStr "a < b" ())] []))] [])] [] () ())] []) +(Module [(FunctionDef test_cast ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (AnnAssign (Name b Store) (Name f32 Load) () 1) (Assign [(Name a Store)] (ConstantInt 2 ()) ()) (Assign [(Name b Store)] (ConstantFloat 4.20000000000000018e+00 ()) ()) (AugAssign (Name a Store) Mult (Name b Load)) (AugAssign (Name b Store) Add (ConstantInt 1 ())) (Assign [(Name a Store)] (ConstantInt 5 ()) ()) (AugAssign (Name a Store) Sub (ConstantFloat 3.89999999999999991e+00 ())) (AugAssign (Name a Store) Div (Name b Load)) (Assign [(Name b Store)] (BinOp (ConstantInt 3 ()) Div (ConstantInt 4 ())) ()) (If (Compare (Name a Load) Lt [(Name b Load)]) [(Expr (Call (Name print Load) [(ConstantStr "a < b" ())] []))] [])] [] () ())] []) diff --git a/tests/reference/ast-expr8-7db6b28.json b/tests/reference/ast-expr8-7db6b28.json index c178d30e0a..f812c4b81e 100644 --- a/tests/reference/ast-expr8-7db6b28.json +++ b/tests/reference/ast-expr8-7db6b28.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "ast-expr8-7db6b28.stdout", - "stdout_hash": "f8cbb30ab1c8273f90e5a7aaf5c0d817a6f62343252a90cca095e9c1", + "stdout_hash": "2b1d4b9762d703e0ccec933ec70684de16cfd1d59f5aebfb04f91522", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-expr8-7db6b28.stdout b/tests/reference/ast-expr8-7db6b28.stdout index 4ceeb0afc4..d860bb36cd 100644 --- a/tests/reference/ast-expr8-7db6b28.stdout +++ b/tests/reference/ast-expr8-7db6b28.stdout @@ -1 +1 @@ -(Module [(FunctionDef test_binop ([] [] [] [] [] [] []) [(AnnAssign (Name x Store) (Name i32 Load) () 1) (AnnAssign (Name x2 Store) (Name f32 Load) () 1) (Assign [(Name x Store)] (BinOp (ConstantInt 2 ()) Pow (ConstantInt 3 ())) ()) (Assign [(Name x2 Store)] (BinOp (ConstantInt 2 ()) Pow (ConstantFloat 3.500000 ())) ()) (Assign [(Name x Store)] (BinOp (ConstantInt 54 ()) Sub (ConstantInt 100 ())) ()) (Assign [(Name x2 Store)] (BinOp (BinOp (ConstantFloat 3.454000 ()) Sub (ConstantFloat 765.430000 ())) Add (ConstantFloat 534.600000 ())) ()) (Assign [(Name x2 Store)] (BinOp (ConstantFloat 5346.565000 ()) Mult (ConstantFloat 3.450000 ())) ()) (Assign [(Name x2 Store)] (BinOp (ConstantFloat 5346.565000 ()) Pow (ConstantFloat 3.450000 ())) ()) (Assign [(Name x Store)] (BinOp (ConstantBool .true. ()) Add (ConstantBool .true. ())) ()) (Assign [(Name x Store)] (BinOp (ConstantBool .true. ()) Sub (ConstantBool .false. ())) ()) (Assign [(Name x Store)] (BinOp (ConstantBool .true. ()) Mult (ConstantBool .false. ())) ()) (Assign [(Name x Store)] (BinOp (ConstantBool .true. ()) Pow (ConstantBool .false. ())) ()) (AnnAssign (Name b1 Store) (Name bool Load) () 1) (AnnAssign (Name b2 Store) (Name bool Load) () 1) (Assign [(Name b1 Store)] (ConstantBool .true. ()) ()) (Assign [(Name b2 Store)] (ConstantBool .false. ()) ()) (Assign [(Name x Store)] (BinOp (Name b1 Load) FloorDiv (Name b1 Load)) ()) (Assign [(Name x Store)] (BinOp (Name b1 Load) Pow (Name b2 Load)) ())] [] () ())] []) +(Module [(FunctionDef test_binop ([] [] [] [] [] [] []) [(AnnAssign (Name x Store) (Name i32 Load) () 1) (AnnAssign (Name x2 Store) (Name f32 Load) () 1) (Assign [(Name x Store)] (BinOp (ConstantInt 2 ()) Pow (ConstantInt 3 ())) ()) (Assign [(Name x2 Store)] (BinOp (ConstantInt 2 ()) Pow (ConstantFloat 3.50000000000000000e+00 ())) ()) (Assign [(Name x Store)] (BinOp (ConstantInt 54 ()) Sub (ConstantInt 100 ())) ()) (Assign [(Name x2 Store)] (BinOp (BinOp (ConstantFloat 3.45400000000000018e+00 ()) Sub (ConstantFloat 7.65429999999999950e+02 ())) Add (ConstantFloat 5.34600000000000023e+02 ())) ()) (Assign [(Name x2 Store)] (BinOp (ConstantFloat 5.34656499999999960e+03 ()) Mult (ConstantFloat 3.45000000000000018e+00 ())) ()) (Assign [(Name x2 Store)] (BinOp (ConstantFloat 5.34656499999999960e+03 ()) Pow (ConstantFloat 3.45000000000000018e+00 ())) ()) (Assign [(Name x Store)] (BinOp (ConstantBool .true. ()) Add (ConstantBool .true. ())) ()) (Assign [(Name x Store)] (BinOp (ConstantBool .true. ()) Sub (ConstantBool .false. ())) ()) (Assign [(Name x Store)] (BinOp (ConstantBool .true. ()) Mult (ConstantBool .false. ())) ()) (Assign [(Name x Store)] (BinOp (ConstantBool .true. ()) Pow (ConstantBool .false. ())) ()) (AnnAssign (Name b1 Store) (Name bool Load) () 1) (AnnAssign (Name b2 Store) (Name bool Load) () 1) (Assign [(Name b1 Store)] (ConstantBool .true. ()) ()) (Assign [(Name b2 Store)] (ConstantBool .false. ()) ()) (Assign [(Name x Store)] (BinOp (Name b1 Load) FloorDiv (Name b1 Load)) ()) (Assign [(Name x Store)] (BinOp (Name b1 Load) Pow (Name b2 Load)) ())] [] () ())] []) diff --git a/tests/reference/ast-global1-b2690cf.json b/tests/reference/ast-global1-b2690cf.json new file mode 100644 index 0000000000..ce6c6a5772 --- /dev/null +++ b/tests/reference/ast-global1-b2690cf.json @@ -0,0 +1,13 @@ +{ + "basename": "ast-global1-b2690cf", + "cmd": "lpython --show-ast --no-color {infile} -o {outfile}", + "infile": "tests/parser/global1.py", + "infile_hash": "cdbcc3f545f865cfc6e412f53fc6fd7cccdbc0d33b66e45460f3e916", + "outfile": null, + "outfile_hash": null, + "stdout": "ast-global1-b2690cf.stdout", + "stdout_hash": "3ed3e9f2f93355245cf31de3291cca941d508fd392e0453f00ea0aab", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast-global1-b2690cf.stdout b/tests/reference/ast-global1-b2690cf.stdout new file mode 100644 index 0000000000..e066612dc2 --- /dev/null +++ b/tests/reference/ast-global1-b2690cf.stdout @@ -0,0 +1 @@ +(Module [(Assign [(Name x Store)] (ConstantStr "global " ()) ()) (FunctionDef outer ([] [] [] [] [] [] []) [(Assign [(Name x Store)] (ConstantStr "local" ()) ()) (FunctionDef inner ([] [] [] [] [] [] []) [(Nonlocal [x]) (Assign [(Name x Store)] (ConstantStr "nonlocal" ()) ()) (Assert (Compare (Name x Load) Eq [(ConstantStr "nonlocal" ())]) ())] [] () ()) (Expr (Call (Name inner Load) [] [])) (Assert (Compare (Name x Load) Eq [(ConstantStr "nonlocal" ())]) ())] [] () ()) (FunctionDef test_1 ([] [] [] [] [] [] []) [(Global [x]) (Assign [(Name y Store)] (ConstantStr "local" ()) ()) (Assign [(Name x Store)] (BinOp (Name x Load) Mult (ConstantInt 2 ())) ()) (Assert (Compare (Name x Load) Eq [(ConstantStr "global global " ())]) ()) (Assert (Compare (Name y Load) Eq [(ConstantStr "local" ())]) ())] [] () ()) (FunctionDef check ([] [] [] [] [] [] []) [(Expr (Call (Name test_1 Load) [] [])) (Expr (Call (Name outer Load) [] []))] [] () ()) (Expr (Call (Name check Load) [] []))] []) diff --git a/tests/reference/ast-loop1-194a137.json b/tests/reference/ast-loop1-194a137.json index 6247241ab5..6c0145d04f 100644 --- a/tests/reference/ast-loop1-194a137.json +++ b/tests/reference/ast-loop1-194a137.json @@ -2,11 +2,11 @@ "basename": "ast-loop1-194a137", "cmd": "lpython --show-ast --no-color {infile} -o {outfile}", "infile": "tests/loop1.py", - "infile_hash": "e50c7161122d599991fafb072d5db8fe7e54d017d56a5c1951a210ca", + "infile_hash": "c6799c859004650fdb3abca560c74e978e8f0d22d9f1e3466a074017", "outfile": null, "outfile_hash": null, "stdout": "ast-loop1-194a137.stdout", - "stdout_hash": "0cc09fa5ddfef0db3b9115837fa64f543e814e01e7e4d1c94ebc7b78", + "stdout_hash": "e8ba69539f3b7cc54df74bc18d7085690900102ad13137938f5831a1", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-loop1-194a137.stdout b/tests/reference/ast-loop1-194a137.stdout index cfedd9abb8..839336fa0c 100644 --- a/tests/reference/ast-loop1-194a137.stdout +++ b/tests/reference/ast-loop1-194a137.stdout @@ -1 +1 @@ -(Module [(FunctionDef test_factorial_1 ([] [(x (Name i32 Load) ())] [] [] [] [] []) [(If (Compare (Name x Load) Lt [(ConstantInt 0 ())]) [(Return (ConstantInt 0 ()))] []) (AnnAssign (Name result Store) (Name i32 Load) () 1) (Assign [(Name result Store)] (ConstantInt 1 ()) ()) (While (Compare (Name x Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name result Load) Mult (Name x Load)) ()) (AugAssign (Name x Store) Sub (ConstantInt 1 ()))] []) (Return (Name result Load))] [] (Name i32 Load) ()) (FunctionDef test_factorial_2 ([] [(x (Name i32 Load) ())] [] [] [] [] []) [(AnnAssign (Name result Store) (Name i32 Load) () 1) (Assign [(Name result Store)] (ConstantInt 1 ()) ()) (AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 1 ()) (BinOp (Name x Load) Add (ConstantInt 1 ()))] []) [(Assign [(Name result Store)] (BinOp (Name result Load) Mult (Name i Load)) ())] [] ()) (Return (Name result Load))] [] (Name i32 Load) ()) (FunctionDef test_factorial_3 ([] [(x (Name i32 Load) ())] [] [] [] [] []) [(If (Compare (Name x Load) Lt [(ConstantInt 0 ())]) [(Return (ConstantInt 0 ()))] []) (AnnAssign (Name result Store) (Name i64 Load) () 1) (Assign [(Name result Store)] (ConstantInt 1 ()) ()) (While (Compare (Name x Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name result Load) Mult (Name x Load)) ()) (AugAssign (Name x Store) Sub (ConstantInt 1 ()))] []) (Return (Name result Load))] [] (Name i64 Load) ()) (FunctionDef main0 ([] [] [] [] [] [] []) [(AnnAssign (Name i Store) (Name i32 Load) () 1) (Assign [(Name i Store)] (Call (Name test_factorial_1 Load) [(ConstantInt 4 ())] []) ()) (Assign [(Name i Store)] (Call (Name test_factorial_2 Load) [(ConstantInt 4 ())] []) ()) (AnnAssign (Name j Store) (Name i64 Load) () 1) (Assign [(Name j Store)] (Call (Name test_factorial_3 Load) [(ConstantInt 5 ())] []) ())] [] () ()) (Expr (Call (Name main0 Load) [] []))] []) +(Module [(FunctionDef test_factorial_1 ([] [(x (Name i32 Load) ())] [] [] [] [] []) [(If (Compare (Name x Load) Lt [(ConstantInt 0 ())]) [(Return (ConstantInt 0 ()))] []) (AnnAssign (Name result Store) (Name i32 Load) () 1) (Assign [(Name result Store)] (ConstantInt 1 ()) ()) (While (Compare (Name x Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name result Load) Mult (Name x Load)) ()) (AugAssign (Name x Store) Sub (ConstantInt 1 ()))] []) (Return (Name result Load))] [] (Name i32 Load) ()) (FunctionDef test_factorial_2 ([] [(x (Name i32 Load) ())] [] [] [] [] []) [(AnnAssign (Name result Store) (Name i32 Load) () 1) (Assign [(Name result Store)] (ConstantInt 1 ()) ()) (AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 1 ()) (BinOp (Name x Load) Add (ConstantInt 1 ()))] []) [(Assign [(Name result Store)] (BinOp (Name result Load) Mult (Name i Load)) ())] [] ()) (Return (Name result Load))] [] (Name i32 Load) ()) (FunctionDef test_factorial_3 ([] [(x (Name i32 Load) ())] [] [] [] [] []) [(AnnAssign (Name result Store) (Name i64 Load) () 1) (Assign [(Name result Store)] (ConstantInt 0 ()) ()) (If (Compare (Name x Load) Lt [(ConstantInt 0 ())]) [(Return (Name result Load))] []) (Assign [(Name result Store)] (ConstantInt 1 ()) ()) (While (Compare (Name x Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name result Load) Mult (Name x Load)) ()) (AugAssign (Name x Store) Sub (ConstantInt 1 ()))] []) (Return (Name result Load))] [] (Name i64 Load) ()) (FunctionDef main0 ([] [] [] [] [] [] []) [(AnnAssign (Name i Store) (Name i32 Load) () 1) (Assign [(Name i Store)] (Call (Name test_factorial_1 Load) [(ConstantInt 4 ())] []) ()) (Assign [(Name i Store)] (Call (Name test_factorial_2 Load) [(ConstantInt 4 ())] []) ()) (AnnAssign (Name j Store) (Name i64 Load) () 1) (Assign [(Name j Store)] (Call (Name test_factorial_3 Load) [(ConstantInt 5 ())] []) ())] [] () ()) (Expr (Call (Name main0 Load) [] []))] []) diff --git a/tests/reference/ast-loop2-63bf329.json b/tests/reference/ast-loop2-63bf329.json index ecd9117272..7750a6dd5b 100644 --- a/tests/reference/ast-loop2-63bf329.json +++ b/tests/reference/ast-loop2-63bf329.json @@ -2,11 +2,11 @@ "basename": "ast-loop2-63bf329", "cmd": "lpython --show-ast --no-color {infile} -o {outfile}", "infile": "tests/loop2.py", - "infile_hash": "0f1af9370fbae5de0ed9e612e933d7745598fc9c74b036496f4ae8ca", + "infile_hash": "7946c522ceb16f99810780d4aba7fa2593695a4b49fb35ea1f131f53", "outfile": null, "outfile_hash": null, "stdout": "ast-loop2-63bf329.stdout", - "stdout_hash": "a5cd7c1a9f0bdb94b4ae8a8ec509111aede5651ea109408828ce40c8", + "stdout_hash": "5317e07f2df3b9e037ab5b1a76f1f1c873098a9931b4b85bc59360cd", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-loop2-63bf329.stdout b/tests/reference/ast-loop2-63bf329.stdout index 25d0e94601..643499511b 100644 --- a/tests/reference/ast-loop2-63bf329.stdout +++ b/tests/reference/ast-loop2-63bf329.stdout @@ -1 +1 @@ -(Module [(ImportFrom sys [(exit ())] 0) (FunctionDef test_for ([] [] [] [] [] [] []) [(AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 0 ()) (ConstantInt 10 ())] []) [(If (Compare (Name i Load) Eq [(ConstantInt 0 ())]) [(Continue)] []) (If (Compare (Name i Load) Gt [(ConstantInt 5 ())]) [(Break)] []) (If (Compare (Name i Load) Eq [(ConstantInt 3 ())]) [(Expr (Call (Name quit Load) [] []))] [])] [] ()) (Expr (Call (Name exit Load) [(ConstantInt 0 ())] []))] [] () ())] []) +(Module [(ImportFrom sys [(exit ())] 0) (FunctionDef test_for ([] [] [] [] [] [] []) [(AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 0 ()) (ConstantInt 10 ())] []) [(If (Compare (Name i Load) Eq [(ConstantInt 0 ())]) [(Continue)] []) (If (Compare (Name i Load) Gt [(ConstantInt 5 ())]) [(Break)] []) (If (Compare (Name i Load) Eq [(ConstantInt 3 ())]) [(Expr (Call (Name quit Load) [] []))] [])] [] ()) (Expr (Call (Name exit Load) [(ConstantInt 2 ())] []))] [] () ()) (Expr (Call (Name test_for Load) [] []))] []) diff --git a/tests/reference/ast-tuple1-2fb5396.json b/tests/reference/ast-tuple1-2fb5396.json index aa4b39d0e6..cc0d830c56 100644 --- a/tests/reference/ast-tuple1-2fb5396.json +++ b/tests/reference/ast-tuple1-2fb5396.json @@ -2,11 +2,11 @@ "basename": "ast-tuple1-2fb5396", "cmd": "lpython --show-ast --no-color {infile} -o {outfile}", "infile": "tests/tuple1.py", - "infile_hash": "9ac0ef90dead58ed997d3b3cef99cbe8ef7658e09a0e72d0d7f19dad", + "infile_hash": "84bde837752a9a2998906c4aafdd87bcaaf0aff168187fcf47156b4c", "outfile": null, "outfile_hash": null, "stdout": "ast-tuple1-2fb5396.stdout", - "stdout_hash": "c3f189969d25ad39adc6f3046c914b20a1a0fe4015480f661ce65aea", + "stdout_hash": "32e6513b7a4d436f83831e813be28acc1aafffbc44c5c41d93082039", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast-tuple1-2fb5396.stdout b/tests/reference/ast-tuple1-2fb5396.stdout index 280a4f625a..fa4669d3a3 100644 --- a/tests/reference/ast-tuple1-2fb5396.stdout +++ b/tests/reference/ast-tuple1-2fb5396.stdout @@ -1 +1 @@ -(Module [(FunctionDef test_Tuple ([] [] [] [] [] [] []) [(AnnAssign (Name a1 Store) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name a1 Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (Assign [(Name a1 Store)] (Tuple [(UnaryOp USub (ConstantInt 3 ())) (UnaryOp USub (ConstantInt 2 ())) (UnaryOp USub (ConstantInt 1 ()))] Load) ()) (AnnAssign (Name a2 Store) (Subscript (Name tuple Load) (Tuple [(Name str Load) (Name str Load) (Name str Load)] Load) Load) () 1) (Assign [(Name a2 Store)] (Tuple [(ConstantStr "a" ()) (ConstantStr "b" ()) (ConstantStr "c" ())] Load) ()) (AnnAssign (Name a3 Store) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load) (Name f32 Load) (Name str Load)] Load) Load) () 1) (Assign [(Name a3 Store)] (Tuple [(UnaryOp USub (ConstantInt 2 ())) (UnaryOp USub (ConstantInt 1 ())) (ConstantFloat 0.450000 ()) (ConstantStr "d" ())] Load) ()) (AnnAssign (Name a4 Store) (Subscript (Name tuple Load) (Tuple [(Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load) (Name i32 Load)] Load) Load) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load) (Name i32 Load)] Load) Load)] Load) Load) () 1) (Assign [(Name a4 Store)] (Tuple [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) (Tuple [(ConstantInt 4 ()) (ConstantInt 5 ()) (ConstantInt 6 ())] Load)] Load) ()) (AnnAssign (Name a5 Store) (Subscript (Name tuple Load) (Tuple [(Subscript (Name tuple Load) (Tuple [(Name str Load) (Name str Load) (Name f32 Load)] Load) Load) (Subscript (Name tuple Load) (Tuple [(Name str Load) (Name i32 Load) (Name f32 Load)] Load) Load)] Load) Load) () 1) (Assign [(Name a5 Store)] (Tuple [(Tuple [(ConstantStr "a" ()) (ConstantStr "b" ()) (ConstantFloat 3.400000 ())] Load) (Tuple [(ConstantStr "c" ()) (ConstantInt 3 ()) (ConstantFloat 5.600000 ())] Load)] Load) ()) (AnnAssign (Name b0 Store) (Name i32 Load) () 1) (AnnAssign (Name b1 Store) (Name i32 Load) () 1) (Assign [(Name b0 Store)] (Subscript (Name a1 Load) (ConstantInt 0 ()) Load) ()) (Assign [(Tuple [(Name b0 Store) (Name b1 Store)] Store)] (Tuple [(Subscript (Name a1 Load) (ConstantInt 2 ()) Load) (Subscript (Name a1 Load) (ConstantInt 1 ()) Load)] Load) ())] [] () ())] []) +(Module [(FunctionDef test_Tuple ([] [] [] [] [] [] []) [(AnnAssign (Name a1 Store) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load) (Name i32 Load)] Load) Load) () 1) (Assign [(Name a1 Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (Assign [(Name a1 Store)] (Tuple [(UnaryOp USub (ConstantInt 3 ())) (UnaryOp USub (ConstantInt 2 ())) (UnaryOp USub (ConstantInt 1 ()))] Load) ()) (AnnAssign (Name a2 Store) (Subscript (Name tuple Load) (Tuple [(Name str Load) (Name str Load) (Name str Load)] Load) Load) () 1) (Assign [(Name a2 Store)] (Tuple [(ConstantStr "a" ()) (ConstantStr "b" ()) (ConstantStr "c" ())] Load) ()) (AnnAssign (Name a3 Store) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load) (Name f32 Load) (Name str Load)] Load) Load) () 1) (AnnAssign (Name float_mem Store) (Name f32 Load) () 1) (Assign [(Name float_mem Store)] (ConstantFloat 4.50000000000000011e-01 ()) ()) (Assign [(Name a3 Store)] (Tuple [(UnaryOp USub (ConstantInt 2 ())) (UnaryOp USub (ConstantInt 1 ())) (Name float_mem Load) (ConstantStr "d" ())] Load) ()) (AnnAssign (Name a4 Store) (Subscript (Name tuple Load) (Tuple [(Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load) (Name i32 Load)] Load) Load) (Subscript (Name tuple Load) (Tuple [(Name i32 Load) (Name i32 Load) (Name i32 Load)] Load) Load)] Load) Load) () 1) (Assign [(Name a4 Store)] (Tuple [(Tuple [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) (Tuple [(ConstantInt 4 ()) (ConstantInt 5 ()) (ConstantInt 6 ())] Load)] Load) ()) (AnnAssign (Name a5 Store) (Subscript (Name tuple Load) (Tuple [(Subscript (Name tuple Load) (Tuple [(Name str Load) (Name str Load) (Name f32 Load)] Load) Load) (Subscript (Name tuple Load) (Tuple [(Name str Load) (Name i32 Load) (Name f32 Load)] Load) Load)] Load) Load) () 1) (AnnAssign (Name float_mem1 Store) (Name f32 Load) () 1) (AnnAssign (Name float_mem2 Store) (Name f32 Load) () 1) (Assign [(Name float_mem1 Store)] (ConstantFloat 3.39999999999999991e+00 ()) ()) (Assign [(Name float_mem2 Store)] (ConstantFloat 5.59999999999999964e+00 ()) ()) (Assign [(Name a5 Store)] (Tuple [(Tuple [(ConstantStr "a" ()) (ConstantStr "b" ()) (Name float_mem1 Load)] Load) (Tuple [(ConstantStr "c" ()) (ConstantInt 3 ()) (Name float_mem2 Load)] Load)] Load) ()) (AnnAssign (Name b0 Store) (Name i32 Load) () 1) (AnnAssign (Name b1 Store) (Name i32 Load) () 1) (Assign [(Name b0 Store)] (Subscript (Name a1 Load) (ConstantInt 0 ()) Load) ()) (Assign [(Tuple [(Name b0 Store) (Name b1 Store)] Store)] (Tuple [(Subscript (Name a1 Load) (ConstantInt 2 ()) Load) (Subscript (Name a1 Load) (ConstantInt 1 ()) Load)] Load) ())] [] () ())] []) diff --git a/tests/reference/ast_new-comment2-f0984d5.json b/tests/reference/ast_new-comment2-f0984d5.json new file mode 100644 index 0000000000..f133600f1a --- /dev/null +++ b/tests/reference/ast_new-comment2-f0984d5.json @@ -0,0 +1,13 @@ +{ + "basename": "ast_new-comment2-f0984d5", + "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", + "infile": "tests/tokens/comment2.py", + "infile_hash": "8bbf936b113be965ec25f99d010959c3d6551e0271fa70c76cff1693", + "outfile": null, + "outfile_hash": null, + "stdout": "ast_new-comment2-f0984d5.stdout", + "stdout_hash": "1668ba80cbd288c4926c8e48593f374a1e49963dff66747738f82fd8", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast_new-comment2-f0984d5.stdout b/tests/reference/ast_new-comment2-f0984d5.stdout new file mode 100644 index 0000000000..eb0b683210 --- /dev/null +++ b/tests/reference/ast_new-comment2-f0984d5.stdout @@ -0,0 +1 @@ +(Module [(FunctionDef main ([] [] [] [] [] [] []) [(If (Name foo Load) [(If (Name bar Load) [(Pass)] [])] [(Pass)]) (Return ())] [] () ()) (FunctionDef test ([] [] [] [] [] [] []) [(Expr (Call (Name print Load) [] []))] [] () ()) (FunctionDef main ([] [] [] [] [] [] []) [(Expr (Call (Name print Load) [] []))] [] () ()) (FunctionDef main ([] [] [] [] [] [] []) [(Expr (Call (Name print Load) [] [])) (Pass)] [] () ()) (FunctionDef main ([] [] [] [] [] [] []) [(If (Name foo Load) [(Pass) (Pass) (If (Name bar Load) [(Pass)] []) (Pass)] []) (Pass)] [] () ())] []) diff --git a/tests/reference/ast_new-comprehension1-69cf2af.json b/tests/reference/ast_new-comprehension1-69cf2af.json new file mode 100644 index 0000000000..05de6454b8 --- /dev/null +++ b/tests/reference/ast_new-comprehension1-69cf2af.json @@ -0,0 +1,13 @@ +{ + "basename": "ast_new-comprehension1-69cf2af", + "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", + "infile": "tests/parser/comprehension1.py", + "infile_hash": "28749607f6d0963094ffca1a9f62cac0f5292451d4f6a57df0a6edf2", + "outfile": null, + "outfile_hash": null, + "stdout": "ast_new-comprehension1-69cf2af.stdout", + "stdout_hash": "82857717cc1bc07fb8b46095b37c75b69f1058abfec0899323f19b78", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast_new-comprehension1-69cf2af.stdout b/tests/reference/ast_new-comprehension1-69cf2af.stdout new file mode 100644 index 0000000000..a73d74abde --- /dev/null +++ b/tests/reference/ast_new-comprehension1-69cf2af.stdout @@ -0,0 +1 @@ +(Module [(Assign [(Name fruits Store)] (ListComp (Name f Load) [((Name f Store) (Name fruit_list Load) [(Call (Attribute (Name f Load) startswith Load) [(ConstantStr "a" ())] [])] 0)]) ()) (Assign [(Name fruit_list Store)] (ListComp (Name fruit Load) [((Name fruit Store) (Name fruits Load) [] 0)]) ()) (Assign [(Name sum_cord Store)] (ListComp (BinOp (Name x Load) Add (Name y Load)) [((Tuple [(Name x Store) (Name y Store)] Store) (Name points Load) [(BoolOp And [(Compare (Name x Load) Gt [(ConstantInt 0 ())]) (Compare (Name y Load) Gt [(ConstantInt 0 ())])])] 0)]) ()) (Assign [(Name transform_1 Store)] (ListComp (BinOp (BinOp (ConstantInt 2 ()) Mult (Name x Load)) Add (ConstantInt 6 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name distance_orig Store)] (ListComp (BinOp (BinOp (BinOp (Name x Load) Pow (ConstantInt 2 ())) Add (BinOp (Name y Load) Pow (ConstantInt 2 ()))) Add (BinOp (Name z Load) Pow (ConstantInt 2 ()))) [((Tuple [(Name x Store) (Name y Store) (Name z Store)] Store) (Name points Load) [] 0)]) ()) (Assign [(Name odd_elements Store)] (ListComp (Name i Load) [((Name i Store) (Name main_list Load) [(BinOp (Name i Load) BitAnd (ConstantInt 1 ()))] 0)]) ()) (Assign [(Name first_ten_elements Store)] (ListComp (Name i Load) [((Name i Load) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Load) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ())] []) diff --git a/tests/reference/ast_new-ellipsis2-3a9750b.json b/tests/reference/ast_new-ellipsis2-3a9750b.json new file mode 100644 index 0000000000..8247382fd5 --- /dev/null +++ b/tests/reference/ast_new-ellipsis2-3a9750b.json @@ -0,0 +1,13 @@ +{ + "basename": "ast_new-ellipsis2-3a9750b", + "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", + "infile": "tests/parser/ellipsis2.py", + "infile_hash": "2e6669bafe4247887d3cd6d9f479ef9c02de96d2a018df4a716ae259", + "outfile": null, + "outfile_hash": null, + "stdout": "ast_new-ellipsis2-3a9750b.stdout", + "stdout_hash": "fea13952d8c4d5fda5c9ceb115f42765ff0855c332776a5589037bad", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast_new-ellipsis2-3a9750b.stdout b/tests/reference/ast_new-ellipsis2-3a9750b.stdout new file mode 100644 index 0000000000..cc4da52a66 --- /dev/null +++ b/tests/reference/ast_new-ellipsis2-3a9750b.stdout @@ -0,0 +1 @@ +(Module [(Import [(numpy np)]) (ImportFrom typing [(Callable ())] 0) (Expr (Call (Name print Load) [(ConstantEllipsis ())] [])) (Assign [(Name array Store)] (Call (Attribute (Attribute (Name np Load) random Load) rand Load) [(ConstantInt 2 ()) (ConstantInt 2 ()) (ConstantInt 2 ()) (ConstantInt 2 ())] []) ()) (Expr (Call (Name print Load) [(Subscript (Name array Load) (Tuple [(ConstantEllipsis ()) (ConstantInt 0 ())] Load) Load)] [])) (Expr (Call (Name print Load) [(Subscript (Name array Load) (Tuple [(Name Ellipsis Load) (ConstantInt 0 ())] Load) Load)] [])) (FunctionDef test1 ([] [] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] () ()) (FunctionDef test2 ([] [] [] [] [] [] []) [(Assign [(Name x Store)] (List [(ConstantInt 1 ()) (List [(ConstantInt 2 ()) (List [(ConstantEllipsis ())] Load) (ConstantInt 3 ())] Load)] Load) ()) (Assign [(Name l Store)] (List [(ConstantEllipsis ()) (ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ()) (Assign [(Name array Store)] (Call (Attribute (Attribute (Name np Load) random Load) rand Load) [(ConstantInt 2 ()) (ConstantInt 2 ()) (ConstantInt 2 ()) (ConstantInt 2 ())] []) ()) (Expr (Call (Name print Load) [(Subscript (Name array Load) (Tuple [(ConstantEllipsis ()) (ConstantInt 0 ())] Load) Load)] [])) (FunctionDef foo ([] [(x (ConstantEllipsis ()) ())] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ()) (FunctionDef inject ([] [(get_next_item (Subscript (Name Callable Load) (Tuple [(ConstantEllipsis ()) (Name str Load)] Load) Load) ())] [] [] [] [] []) [(Expr (ConstantEllipsis ()))] [] (ConstantNone ()) ())] []) diff --git a/tests/reference/ast_new-for1-887432e.json b/tests/reference/ast_new-for1-887432e.json index 8d7d022088..3cd9680d17 100644 --- a/tests/reference/ast_new-for1-887432e.json +++ b/tests/reference/ast_new-for1-887432e.json @@ -2,11 +2,11 @@ "basename": "ast_new-for1-887432e", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/for1.py", - "infile_hash": "60515a1800d4a8b1a2cad5ad7b23f75f2510e1d369e94065f01c0844", + "infile_hash": "f025995384e87a428a605ae718932f3fbc25aa3f8baa5508f2018997", "outfile": null, "outfile_hash": null, "stdout": "ast_new-for1-887432e.stdout", - "stdout_hash": "438c7ad856655fd2f666faab754e58f11179a800975359501be7b8fa", + "stdout_hash": "ddf8b7ff93327c03459a9ed17dfa3706131a59b3219e2b13739c7a55", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-for1-887432e.stdout b/tests/reference/ast_new-for1-887432e.stdout index 2c953bb81a..63365817d1 100644 --- a/tests/reference/ast_new-for1-887432e.stdout +++ b/tests/reference/ast_new-for1-887432e.stdout @@ -1 +1 @@ -(Module [(ImportFrom ltypes [(i32 ())] 0) (For (Name x Store) (Name fruits Load) [(Expr (Call (Name print Load) [(Name x Load)] []))] [] ()) (For (Name x Store) (Name fruits Load) [(Expr (Call (Name print Load) [(Name x Load)] [])) (If (Compare (Name x Load) Eq [(ConstantStr "banana" ())]) [(Break)] [])] [] ()) (For (Name x Store) (ConstantStr "banana" ()) [(Expr (Call (Name print Load) [(Name x Load)] []))] [] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 6 ())] []) [(Expr (Call (Name print Load) [(Name i Load)] []))] [] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 2 ()) (ConstantInt 30 ()) (ConstantInt 3 ())] []) [(Expr (Call (Name print Load) [(Name i Load)] []))] [] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(If (Compare (Name i Load) Eq [(ConstantInt 3 ())]) [(Continue)] []) (Expr (Call (Name print Load) [(Name i Load)] []))] [(Expr (Call (Name print Load) [(ConstantStr "Finally Completed!" ())] []))] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(For (Name j Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(Expr (Call (Name print Load) [(Name i Load) (Name j Load)] []))] [] ())] [] ()) (AnnAssign (Name sum Store) (Name i32 Load) (ConstantInt 0 ()) 1) (For (Name j Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(AugAssign (Name sum Store) Add (Name j Load))] [] ())] []) +(Module [(ImportFrom ltypes [(i32 ())] 0) (For (Name x Store) (Name fruits Load) [(Expr (Call (Name print Load) [(Name x Load)] []))] [] ()) (For (Name x Store) (Name fruits Load) [(Expr (Call (Name print Load) [(Name x Load)] [])) (If (Compare (Name x Load) Eq [(ConstantStr "banana" ())]) [(Break)] [])] [] ()) (For (Name x Store) (ConstantStr "banana" ()) [(Expr (Call (Name print Load) [(Name x Load)] []))] [] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 6 ())] []) [(Expr (Call (Name print Load) [(Name i Load)] []))] [] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 2 ()) (ConstantInt 30 ()) (ConstantInt 3 ())] []) [(Expr (Call (Name print Load) [(Name i Load)] []))] [] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(If (Compare (Name i Load) Eq [(ConstantInt 3 ())]) [(Continue)] []) (Expr (Call (Name print Load) [(Name i Load)] []))] [(Expr (Call (Name print Load) [(ConstantStr "Finally Completed!" ())] []))] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(For (Name j Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(Expr (Call (Name print Load) [(Name i Load) (Name j Load)] []))] [] ())] [] ()) (AnnAssign (Name sum Store) (Name i32 Load) (ConstantInt 0 ()) 1) (For (Name j Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(AugAssign (Name sum Store) Add (Name j Load))] [] ()) (For (Tuple [(Name _ Store) (Name x Store)] Store) (Name y Load) [(Pass)] [] ()) (For (Tuple [(Name x Store) (Name y Store)] Store) (Name z Load) [(Pass)] [] ()) (For (Tuple [(Name i Store) (Name a Store)] Store) (Call (Name enumerate Load) [(List [(ConstantInt 4 ()) (ConstantInt 5 ()) (ConstantInt 6 ()) (ConstantInt 7 ())] Load)] []) [(Expr (Call (Name print Load) [(Name i Load) (ConstantStr ": " ()) (Name a Load)] []))] [] ()) (For (Name i Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(Pass)] [] "int") (For (Name j Store) (Name k Load) [(Pass)] [] "List[str]") (For (Name i Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(Pass)] [(Pass)] "int")] []) diff --git a/tests/reference/ast_new-function_def1-1a872df.json b/tests/reference/ast_new-function_def1-1a872df.json index c484665423..cb33100145 100644 --- a/tests/reference/ast_new-function_def1-1a872df.json +++ b/tests/reference/ast_new-function_def1-1a872df.json @@ -2,11 +2,11 @@ "basename": "ast_new-function_def1-1a872df", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/function_def1.py", - "infile_hash": "4224c0bffeb39c449abfeba907eba690ee5ff15f9514c9a0c0922a92", + "infile_hash": "96c4a34f72e609e55af1688b793dc2d6fb375f82f661d16de0ea6fa9", "outfile": null, "outfile_hash": null, "stdout": "ast_new-function_def1-1a872df.stdout", - "stdout_hash": "19677f67c936f188ba070291048c6dd20a815c5fe66c13570051b3e7", + "stdout_hash": "ad5ea65f2ef1994819a5c48936f936ea955303c08253419d72aa450b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-function_def1-1a872df.stdout b/tests/reference/ast_new-function_def1-1a872df.stdout index d5823785ed..9e22d8927e 100644 --- a/tests/reference/ast_new-function_def1-1a872df.stdout +++ b/tests/reference/ast_new-function_def1-1a872df.stdout @@ -3,4 +3,4 @@ the person passed in as a parameter " ())) (Expr (Call (Name print Load) [(BinOp (BinOp (ConstantStr "Hello, " ()) Add (Name name Load)) Add (ConstantStr ". Good morning!" ()))] []))] [] () ()) (FunctionDef absolute_value ([] [(num () ())] [] [] [] [] []) [(Expr (ConstantStr "This function returns the absolute - value of the entered number" ())) (If (Compare (Name num Load) GtE [(ConstantInt 0 ())]) [(Return (Name num Load))] [(Return (UnaryOp USub (Name num Load)))])] [] () ()) (FunctionDef combine ([] [(fname () ()) (lname () ())] [] [] [] [] []) [(Expr (Call (Name print Load) [(BinOp (BinOp (Name fname Load) Add (ConstantStr " " ())) Add (Name lname Load))] []))] [] () ()) (FunctionDef tri_recursion ([] [(k () ())] [] [] [] [] []) [(If (Compare (Name k Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name k Load) Add (Call (Name tri_recursion Load) [(BinOp (Name k Load) Sub (ConstantInt 1 ()))] [])) ()) (Expr (Call (Name print Load) [(Name result Load)] []))] [(Assign [(Name result Store)] (ConstantInt 0 ()) ())]) (Return (Name result Load))] [] () ()) (FunctionDef test ([] [(a (Name i32 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef test ([] [(a (Name bool Load) ())] [] [] [] [] []) [(If (Name a Load) [(Return (ConstantInt 10 ()))] []) (Return (UnaryOp USub (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef check ([] [] [] [] [] [] []) [(Expr (Call (Name greet Load) [(ConstantStr "Xyz" ())] [])) (Expr (Call (Name print Load) [(Call (Name absolute_value Load) [(ConstantInt 2 ())] [])] [])) (Expr (Call (Name combine Load) [(ConstantStr "LPython" ()) (ConstantStr "Compiler" ())] [])) (Expr (Call (Name print Load) [(ConstantStr "Recursion Example Results: " ())] [])) (Expr (Call (Name tri_recursion Load) [(ConstantInt 6 ())] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantInt 15 ())] [])] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantBool .true. ())] [])] []))] [] () ()) (Expr (Call (Name check Load) [] []))] []) + value of the entered number" ())) (If (Compare (Name num Load) GtE [(ConstantInt 0 ())]) [(Return (Name num Load))] [(Return (UnaryOp USub (Name num Load)))])] [] () ()) (FunctionDef combine ([] [(fname () ()) (lname () ())] [] [] [] [] []) [(Expr (Call (Name print Load) [(BinOp (BinOp (Name fname Load) Add (ConstantStr " " ())) Add (Name lname Load))] []))] [] () ()) (FunctionDef tri_recursion ([] [(k () ())] [] [] [] [] []) [(If (Compare (Name k Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name k Load) Add (Call (Name tri_recursion Load) [(BinOp (Name k Load) Sub (ConstantInt 1 ()))] [])) ()) (Expr (Call (Name print Load) [(Name result Load)] []))] [(Assign [(Name result Store)] (ConstantInt 0 ()) ())]) (Return (Name result Load))] [] () ()) (FunctionDef test ([] [(a (Name i32 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef test ([] [(a (Name i64 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i64 Load) ()) (FunctionDef test ([] [(a (Name bool Load) ())] [] [] [] [] []) [(If (Name a Load) [(Return (ConstantInt 10 ()))] []) (Return (UnaryOp USub (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef check ([] [] [] [] [] [] []) [(Expr (Call (Name greet Load) [(ConstantStr "Xyz" ())] [])) (Expr (Call (Name print Load) [(Call (Name absolute_value Load) [(ConstantInt 2 ())] [])] [])) (Expr (Call (Name combine Load) [(ConstantStr "LPython" ()) (ConstantStr "Compiler" ())] [])) (Expr (Call (Name print Load) [(ConstantStr "Recursion Example Results: " ())] [])) (Expr (Call (Name tri_recursion Load) [(ConstantInt 6 ())] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantInt 15 ())] [])] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantBool .true. ())] [])] []))] [] () ()) (Expr (Call (Name check Load) [] [])) (FunctionDef print_args ([] [] [(args () ())] [] [] [] []) [(Expr (Call (Name print Load) [(Name args Load)] []))] [] () ()) (FunctionDef print_kwargs ([] [] [] [] [] [(kwargs () ())] []) [(Expr (Call (Name print Load) [(Name kwargs Load)] []))] [] () ())] []) diff --git a/tests/reference/ast_new-function_def2-52c4587.json b/tests/reference/ast_new-function_def2-52c4587.json index 041f57e70e..04c2d70aeb 100644 --- a/tests/reference/ast_new-function_def2-52c4587.json +++ b/tests/reference/ast_new-function_def2-52c4587.json @@ -2,11 +2,11 @@ "basename": "ast_new-function_def2-52c4587", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/function_def2.py", - "infile_hash": "44a8d24fcf31af93aea063d957af107d51131ae5eca3762eb0bdbf35", + "infile_hash": "1c1ef66b8a604487d0d72ea97722f252ea0424b9d43beca8ac27d386", "outfile": null, "outfile_hash": null, "stdout": "ast_new-function_def2-52c4587.stdout", - "stdout_hash": "ee51c7c928d4540f2cce026e78ec52910501a82790a7a0cf4ce8e505", + "stdout_hash": "f8afc2e912a93370a4ad5bcb847899a1fabb9785b53d7fe884b5e757", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-function_def2-52c4587.stdout b/tests/reference/ast_new-function_def2-52c4587.stdout index 72194e6c50..f9d3fc6147 100644 --- a/tests/reference/ast_new-function_def2-52c4587.stdout +++ b/tests/reference/ast_new-function_def2-52c4587.stdout @@ -1,3 +1,3 @@ (Module [(FunctionDef test_01 ([] [] [] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_02 ([] [] [(x (Name i32 Load) ())] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_03 ([] [] [(x () ())] [(y () ()) (z () ())] [] [] []) [(Pass)] [] () ()) (FunctionDef test_04 ([] [] [(x () ())] [(y () ()) (z () ())] [] [(args () ())] []) [(Pass)] [] () ()) (FunctionDef test_05 ([] [] [(x () ())] [] [] [(args () ())] []) [(Pass)] [] () ()) (FunctionDef test_06 ([] [] [] [] [] [(args () ())] []) [(Pass)] [] () ()) (FunctionDef test_07 ([] [(x (Name i32 Load) ()) (y () ())] [] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_08 ([] [(x () ())] [(y () ())] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_09 ([] [(x () ())] [(y () ())] [(z () ())] [] [] []) [(Pass)] [] () ()) (FunctionDef test_10 ([] [(x () ())] [(y () ())] [(z () ())] [] [(args (Name i32 Load) ())] []) [(Pass)] [] () ()) (FunctionDef test_11 ([] [(x () ())] [(y () ())] [] [] [(args () ())] []) [(Pass)] [] () ()) (FunctionDef test_12 ([] [(x () ())] [] [] [] [(args () ())] []) [(Pass)] [] () ()) (Expr (ConstantStr " TODO: defaults are not stored in AST -" ())) (FunctionDef test_14 ([] [(x () ())] [(y () ())] [(z () ())] [] [(args (Name i32 Load) ())] []) [(Pass)] [] (Name i32 Load) ()) (Expr (Call (Name test Load) [] [])) (Expr (Call (Name test Load) [(Name x Load) (Name y Load)] [])) (Expr (Call (Name test Load) [(Name x Load)] [(y (ConstantInt 1 ())) (z (ConstantStr "123" ()))])) (Expr (Call (Name test Load) [(ConstantInt 100 ())] [(() (Name x Load))])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load)] [(() (Name y Load))])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load) (Name y Load)] [])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load) (Starred (Name y Load) Load)] [])) (Expr (Call (Name test Load) [] [(() (Name x Load)) (() (Name y Load))])) (Expr (Call (Attribute (Name lp Load) test Load) [] [])) (Expr (Call (Attribute (Name lp Load) test Load) [(Name x Load) (Name y Load)] [])) (Expr (Call (Attribute (Name lp Load) test Load) [(Name x Load)] [(y (ConstantInt 1 ())) (z (ConstantStr "123" ()))]))] []) +" ())) (FunctionDef test_14 ([] [(x () ())] [(y () ())] [(z () ())] [] [(args (Name i32 Load) ())] []) [(Pass)] [] (Name i32 Load) ()) (FunctionDef test_15 ([(a () ())] [] [] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_16 ([(a () ())] [(b () ()) (c () ())] [] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_17 ([(a () ())] [] [(b () ())] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_18 ([(a (Name i32 Load) ())] [] [(b (Name i64 Load) ())] [(c (Name i32 Load) ()) (d (Name i32 Load) ())] [] [] []) [(Pass)] [] () ()) (FunctionDef test_19 ([(a () ())] [] [(b () ())] [(c () ())] [] [(d () ())] []) [(Pass)] [] () ()) (FunctionDef test_20 ([(a () ())] [] [] [] [] [(b () ())] []) [(Pass)] [] () ()) (FunctionDef test_21 ([(a () ())] [] [(b () ())] [] [] [(c () ())] []) [(Pass)] [] () ()) (FunctionDef test_22 ([(a () ())] [(b () ()) (c () ())] [(d () ())] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_23 ([(a () ())] [(b () ()) (c () ())] [] [] [] [(d () ())] []) [(Pass)] [] () ()) (FunctionDef test_24 ([(a () ())] [(b () ()) (c () ())] [(d () ())] [] [] [(e () ())] []) [(Pass)] [] () ()) (FunctionDef test_25 ([(a () ())] [(b () ()) (c () ())] [(d () ())] [(e () ())] [] [(f () ())] []) [(Pass)] [] () ()) (Expr (Call (Name test Load) [] [])) (Expr (Call (Name test Load) [(Name x Load) (Name y Load)] [])) (Expr (Call (Name test Load) [(Name x Load)] [(y (ConstantInt 1 ())) (z (ConstantStr "123" ()))])) (Expr (Call (Name test Load) [(ConstantInt 100 ())] [(() (Name x Load))])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load)] [(() (Name y Load))])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load) (Name y Load)] [])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load) (Starred (Name y Load) Load)] [])) (Expr (Call (Name test Load) [] [(() (Name x Load)) (() (Name y Load))])) (Expr (Call (Attribute (Name lp Load) test Load) [] [])) (Expr (Call (Attribute (Name lp Load) test Load) [(Name x Load) (Name y Load)] [])) (Expr (Call (Attribute (Name lp Load) test Load) [(Name x Load)] [(y (ConstantInt 1 ())) (z (ConstantStr "123" ()))]))] []) diff --git a/tests/reference/ast_new-global1-38edfbd.json b/tests/reference/ast_new-global1-38edfbd.json new file mode 100644 index 0000000000..185eab13e3 --- /dev/null +++ b/tests/reference/ast_new-global1-38edfbd.json @@ -0,0 +1,13 @@ +{ + "basename": "ast_new-global1-38edfbd", + "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", + "infile": "tests/parser/global1.py", + "infile_hash": "cdbcc3f545f865cfc6e412f53fc6fd7cccdbc0d33b66e45460f3e916", + "outfile": null, + "outfile_hash": null, + "stdout": "ast_new-global1-38edfbd.stdout", + "stdout_hash": "3ed3e9f2f93355245cf31de3291cca941d508fd392e0453f00ea0aab", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast_new-global1-38edfbd.stdout b/tests/reference/ast_new-global1-38edfbd.stdout new file mode 100644 index 0000000000..e066612dc2 --- /dev/null +++ b/tests/reference/ast_new-global1-38edfbd.stdout @@ -0,0 +1 @@ +(Module [(Assign [(Name x Store)] (ConstantStr "global " ()) ()) (FunctionDef outer ([] [] [] [] [] [] []) [(Assign [(Name x Store)] (ConstantStr "local" ()) ()) (FunctionDef inner ([] [] [] [] [] [] []) [(Nonlocal [x]) (Assign [(Name x Store)] (ConstantStr "nonlocal" ()) ()) (Assert (Compare (Name x Load) Eq [(ConstantStr "nonlocal" ())]) ())] [] () ()) (Expr (Call (Name inner Load) [] [])) (Assert (Compare (Name x Load) Eq [(ConstantStr "nonlocal" ())]) ())] [] () ()) (FunctionDef test_1 ([] [] [] [] [] [] []) [(Global [x]) (Assign [(Name y Store)] (ConstantStr "local" ()) ()) (Assign [(Name x Store)] (BinOp (Name x Load) Mult (ConstantInt 2 ())) ()) (Assert (Compare (Name x Load) Eq [(ConstantStr "global global " ())]) ()) (Assert (Compare (Name y Load) Eq [(ConstantStr "local" ())]) ())] [] () ()) (FunctionDef check ([] [] [] [] [] [] []) [(Expr (Call (Name test_1 Load) [] [])) (Expr (Call (Name outer Load) [] []))] [] () ()) (Expr (Call (Name check Load) [] []))] []) diff --git a/tests/reference/ast_new-statements1-e081093.json b/tests/reference/ast_new-statements1-e081093.json index b53ed8873b..b03886ae8a 100644 --- a/tests/reference/ast_new-statements1-e081093.json +++ b/tests/reference/ast_new-statements1-e081093.json @@ -2,11 +2,11 @@ "basename": "ast_new-statements1-e081093", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/statements1.py", - "infile_hash": "4aaaf4ec5106c798f6b639b7dab587b4b9c8412b2029b384445e4b20", + "infile_hash": "57c83f799b0bb53eaba09687c23c0285a45a466c493dc3269105b66b", "outfile": null, "outfile_hash": null, "stdout": "ast_new-statements1-e081093.stdout", - "stdout_hash": "6fa494880a0bec62c30b15379701a5d5c277817940419d8379312bb6", + "stdout_hash": "efb43978a8a9367cb0f8a127bcf0211f21226179fd5923c4ab3a490a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-statements1-e081093.stdout b/tests/reference/ast_new-statements1-e081093.stdout index 4b84ca47d0..cf13c71512 100644 --- a/tests/reference/ast_new-statements1-e081093.stdout +++ b/tests/reference/ast_new-statements1-e081093.stdout @@ -1 +1 @@ -(Module [(Pass) (Break) (Continue) (Raise () ()) (Raise (Call (Name NameError Load) [(ConstantStr "String" ())] []) ()) (Raise (Name RuntimeError Load) (Name exc Load)) (Assert (Compare (Call (Name len Load) [(Name marks Load)] []) NotEq [(ConstantInt 0 ())]) (ConstantStr "List is empty." ())) (Assert (Compare (Name x Load) Eq [(ConstantStr "String" ())]) ()) (Assign [(Name x Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Call (Name x Load) [] []) ()) (Assign [(Name x Store) (Name y Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Store) ()) (Assign [(Subscript (Name x Load) (Name i Load) Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Store) ()) (AugAssign (Name x Store) Add (ConstantInt 1 ())) (AnnAssign (Name x Store) (Name i64 Load) () 1) (AnnAssign (Name y Store) (Name i32 Load) (ConstantInt 1 ()) 1) (Delete [(Name x Del)]) (Delete [(Name x Del) (Name y Del)]) (Return ()) (Return (BinOp (Name a Load) Add (Name b Load))) (Return (Call (Name x Load) [(Name a Load)] [])) (Return (Tuple [(Name x Store) (Name y Store)] Store)) (Global [a]) (Global [a b]) (Nonlocal [a]) (Nonlocal [a b]) (Expr (ConstantInt 123 ())) (Expr (UnaryOp USub (ConstantInt 123 ()))) (Expr (UnaryOp USub (ConstantInt 291 ()))) (Expr (ConstantInt 6844 ())) (Expr (UnaryOp USub (ConstantInt 83 ()))) (Expr (ConstantInt 87 ())) (Expr (UnaryOp USub (ConstantInt 13 ()))) (Expr (ConstantInt 13 ())) (Expr (ConstantFloat 123.000000 ())) (Expr (ConstantFloat 123.450000 ())) (Expr (ConstantFloat 123400000000.000000 ())) (Expr (BinOp (ConstantInt 12 ()) Add (ConstantComplex 0.000000 3.000000 ()))) (Expr (BinOp (ConstantFloat 0.120000 ()) Add (ConstantComplex 0.000000 0.001000 ()))) (Expr (ConstantStr "String" ())) (Expr (ConstantBool .true. ())) (Expr (ConstantBool .false. ())) (Expr (BinOp (BinOp (Name x Load) Add (Name y Load)) Mult (Name z Load))) (Expr (BinOp (Name x Load) Sub (Name y Load))) (Expr (BinOp (Name x Load) Mult (Name y Load))) (Expr (BinOp (Name x Load) Div (Name y Load))) (Expr (BinOp (Name x Load) Mod (Name y Load))) (Expr (UnaryOp USub (Name y Load))) (Expr (UnaryOp UAdd (Name y Load))) (Expr (UnaryOp Invert (Name y Load))) (Expr (BinOp (Name x Load) Pow (Name y Load))) (Expr (BinOp (Name x Load) FloorDiv (Name y Load))) (Expr (BinOp (Name x Load) MatMult (Name y Load))) (Expr (BinOp (Name x Load) BitAnd (Name y Load))) (Expr (BinOp (Name x Load) BitOr (Name y Load))) (Expr (BinOp (Name x Load) BitXor (Name y Load))) (Expr (BinOp (Name x Load) LShift (Name y Load))) (Expr (BinOp (Name x Load) RShift (Name y Load))) (Expr (Compare (Name x Load) Eq [(Name y Load)])) (Expr (Compare (Name x Load) NotEq [(Name y Load)])) (Expr (Compare (Name x Load) Lt [(Name y Load)])) (Expr (Compare (Name x Load) LtE [(Name y Load)])) (Expr (Compare (Name x Load) Gt [(Name y Load)])) (Expr (Compare (Name x Load) GtE [(Name y Load)])) (AnnAssign (Name i Store) (Name i32 Load) (ConstantInt 4 ()) 1) (If (Compare (ConstantInt 2 ()) Gt [(Name i Load)]) [(Pass)] []) (If (Compare (Name i Load) Gt [(ConstantInt 5 ())]) [(Break)] []) (If (BoolOp And [(Compare (Name i Load) Eq [(ConstantInt 5 ())]) (Compare (Name i Load) Lt [(ConstantInt 10 ())])]) [(Assign [(Name i Store)] (ConstantInt 3 ()) ())] []) (For (Name i Store) (Call (Name range Load) [(Name N Load)] []) [(Assign [(Subscript (Name c Load) (Name i Load) Store)] (BinOp (Subscript (Name a Load) (Name i Load) Load) Add (BinOp (Name scalar Load) Mult (Subscript (Name b Load) (Name i Load) Load))) ())] [] ()) (Assign [(Name x Store)] (NamedExpr (Name y Store) (ConstantInt 0 ())) ()) (If (NamedExpr (Name a Store) (Call (Name ord Load) [(ConstantStr "3" ())] [])) [(Assign [(Name x Store)] (ConstantInt 1 ()) ())] []) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ())] []) +(Module [(Pass) (Break) (Continue) (Raise () ()) (Raise (Call (Name NameError Load) [(ConstantStr "String" ())] []) ()) (Raise (Name RuntimeError Load) (Name exc Load)) (Assert (Compare (Call (Name len Load) [(Name marks Load)] []) NotEq [(ConstantInt 0 ())]) (ConstantStr "List is empty." ())) (Assert (Compare (Name x Load) Eq [(ConstantStr "String" ())]) ()) (Assign [(Name x Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Call (Name x Load) [] []) ()) (Assign [(Name x Store) (Name y Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Subscript (Name x Load) (Name i Load) Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (AugAssign (Name x Store) Add (ConstantInt 1 ())) (AnnAssign (Name x Store) (Name i64 Load) () 1) (AnnAssign (Name y Store) (Name i32 Load) (ConstantInt 1 ()) 1) (Delete [(Name x Del)]) (Delete [(Tuple [] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Name x Del) (Name y Del)]) (Delete [(Name x Del) (Name y Del)]) (Return ()) (Return (BinOp (Name a Load) Add (Name b Load))) (Return (Call (Name x Load) [(Name a Load)] [])) (Return (Tuple [] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Global [a]) (Global [a b]) (Nonlocal [a]) (Nonlocal [a b]) (Expr (ConstantInt 123 ())) (Expr (UnaryOp USub (ConstantInt 123 ()))) (Expr (UnaryOp USub (ConstantInt 291 ()))) (Expr (ConstantInt 6844 ())) (Expr (UnaryOp USub (ConstantInt 83 ()))) (Expr (ConstantInt 87 ())) (Expr (UnaryOp USub (ConstantInt 13 ()))) (Expr (ConstantInt 13 ())) (Expr (ConstantInt 32768 ())) (Expr (ConstantInt 12 ())) (Expr (ConstantInt 23440334322333 ())) (Expr (ConstantFloat 1.23000000000000000e+02 ())) (Expr (ConstantFloat 1.23450000000000003e+02 ())) (Expr (ConstantFloat 1.23400000000000000e+11 ())) (Expr (BinOp (ConstantInt 12 ()) Add (ConstantComplex 0.00000000000000000e+00 3.00000000000000000e+00 ()))) (Expr (BinOp (ConstantFloat 1.19999999999999996e-01 ()) Add (ConstantComplex 0.00000000000000000e+00 1.00000000000000002e-03 ()))) (Expr (ConstantStr "String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (Subscript (ConstantStr "String String" ()) (Slice (ConstantInt 1 ()) () ()) Load)) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (BinOp (ConstantStr "String " ()) Add (ConstantStr "String" ())) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String " ()) ()) (Expr (ConstantStr "String" ())) (Expr (ConstantBool .true. ())) (Expr (ConstantBool .false. ())) (Expr (BinOp (BinOp (Name x Load) Add (Name y Load)) Mult (Name z Load))) (Expr (BinOp (Name x Load) Sub (Name y Load))) (Expr (BinOp (Name x Load) Mult (Name y Load))) (Expr (BinOp (Name x Load) Div (Name y Load))) (Expr (BinOp (Name x Load) Mod (Name y Load))) (Expr (UnaryOp USub (Name y Load))) (Expr (UnaryOp UAdd (Name y Load))) (Expr (UnaryOp Invert (Name y Load))) (Expr (BinOp (Name x Load) Pow (Name y Load))) (Expr (BinOp (Name x Load) FloorDiv (Name y Load))) (Expr (BinOp (Name x Load) MatMult (Name y Load))) (Expr (BinOp (Name x Load) BitAnd (Name y Load))) (Expr (BinOp (Name x Load) BitOr (Name y Load))) (Expr (BinOp (Name x Load) BitXor (Name y Load))) (Expr (BinOp (Name x Load) LShift (Name y Load))) (Expr (BinOp (Name x Load) RShift (Name y Load))) (Expr (Compare (Name x Load) Eq [(Name y Load)])) (Expr (Compare (Name x Load) NotEq [(Name y Load)])) (Expr (Compare (Name x Load) Lt [(Name y Load)])) (Expr (Compare (Name x Load) LtE [(Name y Load)])) (Expr (Compare (Name x Load) Gt [(Name y Load)])) (Expr (Compare (Name x Load) GtE [(Name y Load)])) (If (Compare (Call (Name type Load) [(Name x Load)] []) Is [(Name int Load)]) [(Pass)] []) (If (Compare (Compare (BinOp (BinOp (BinOp (ConstantInt 2 ()) Add (ConstantInt 3 ())) Div (ConstantInt 2 ())) Sub (ConstantInt 1 ())) Is [(ConstantInt 5 ())]) Is [(ConstantBool .true. ())]) [(Pass)] []) (If (Compare (Name x Load) IsNot [(Call (Name type Load) [(Name float Load)] [])]) [(Pass)] []) (If (Compare (Name x Load) IsNot [(Call (Name type Load) [(Name int Load)] [])]) [(Pass)] []) (Assign [(Name a Store)] (List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (If (Compare (Name a Load) NotIn [(List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)]) [(Pass)] []) (If (Compare (Compare (Name a Load) NotIn [(List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)]) NotIn [(List [(ConstantBool .true. ()) (ConstantBool .false. ())] Load)]) [(Pass)] []) (If (Compare (Name field Load) In [(List [(ConstantStr "vararg" ()) (ConstantStr "kwarg" ())] Load)]) [(If (Compare (Name value Load) Is [(ConstantNone ())]) [(Pass)] [])] []) (If (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] []) (Expr (Compare (ConstantStr "hello" ()) In [(Name x Load)])) (Expr (Compare (ConstantStr "a" ()) In [(Call (Attribute (Name a Load) func Load) [] [])])) (Expr (Compare (ConstantStr "lo" ()) In [(ConstantStr "hello" ())])) (For (Name item Store) (Name list1 Load) [(If (Compare (Name item Load) In [(Name list2 Load)]) [(Pass)] [])] [] ()) (If (BoolOp Or [(BoolOp And [(Compare (Name a Load) In [(Name list1 Load)]) (Compare (Name b Load) NotIn [(Name list2 Load)])]) (Compare (Name c Load) In [(Name list3 Load)])]) [(Pass)] []) (Assign [(Name comp Store)] (ListComp (BinOp (Name i Load) Pow (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(BoolOp And [(Compare (Name i Load) NotIn [(List [(ConstantInt 3 ()) (ConstantInt 5 ()) (ConstantInt 7 ())] Load)]) (Compare (Name i Load) In [(Name list3 Load)])])] 0)]) ()) (For (Name i Store) (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] [] ()) (Expr (Subscript (Attribute (Name a Load) b Load) (ConstantInt 1 ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice (ConstantInt 1 ()) () ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice () (UnaryOp USub (ConstantInt 1 ())) ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice () () ()) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) () (ConstantInt 3 ())) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) () ()) Load)) (AnnAssign (Name i Store) (Name i32 Load) (ConstantInt 4 ()) 1) (If (Compare (ConstantInt 2 ()) Gt [(Name i Load)]) [(Pass)] []) (If (Compare (Name i Load) Gt [(ConstantInt 5 ())]) [(Break)] []) (If (BoolOp And [(Compare (Name i Load) Eq [(ConstantInt 5 ())]) (Compare (Name i Load) Lt [(ConstantInt 10 ())])]) [(Assign [(Name i Store)] (ConstantInt 3 ()) ())] []) (For (Name i Store) (Call (Name range Load) [(Name N Load)] []) [(Assign [(Subscript (Name c Load) (Name i Load) Store)] (BinOp (Subscript (Name a Load) (Name i Load) Load) Add (BinOp (Name scalar Load) Mult (Subscript (Name b Load) (Name i Load) Load))) ())] [] "parallel") (Assign [(Name x Store)] (NamedExpr (Name y Store) (ConstantInt 0 ())) ()) (If (NamedExpr (Name a Store) (Call (Name ord Load) [(ConstantStr "3" ())] [])) [(Assign [(Name x Store)] (ConstantInt 1 ()) ())] []) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (Assign [(Name b Store)] (IfExp (Compare (Name a Load) Eq [(ConstantInt 2 ())]) (ConstantInt 6 ()) (ConstantInt 8 ())) ()) (Expr (IfExp (ConstantBool .true. ()) (ConstantStr "true" ()) (ConstantStr "false" ()))) (Assign [(Name result Store)] (IfExp (UnaryOp Not (Compare (Name a Load) Gt [(Name b Load)])) (Name x Load) (Name y Load)) ()) (Expr (IfExp (Compare (Name a Load) Gt [(Name b Load)]) (Call (Name print Load) [(Name a Load) (ConstantStr "is greater" ())] []) (Call (Name print Load) [(Name b Load) (ConstantStr "is Greater" ())] [])))] []) diff --git a/tests/reference/ast_new-statements2-c4cdc5f.json b/tests/reference/ast_new-statements2-c4cdc5f.json new file mode 100644 index 0000000000..9081042330 --- /dev/null +++ b/tests/reference/ast_new-statements2-c4cdc5f.json @@ -0,0 +1,13 @@ +{ + "basename": "ast_new-statements2-c4cdc5f", + "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", + "infile": "tests/parser/statements2.py", + "infile_hash": "a20fee19d7b8e6f8689f6badc2726fd618524af0aba84a7d0d0e5af5", + "outfile": null, + "outfile_hash": null, + "stdout": "ast_new-statements2-c4cdc5f.stdout", + "stdout_hash": "8b8d1514ec03d6081c0e716170ff41615cb00f9745a71e153f25179c", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast_new-statements2-c4cdc5f.stdout b/tests/reference/ast_new-statements2-c4cdc5f.stdout new file mode 100644 index 0000000000..4deefdc37c --- /dev/null +++ b/tests/reference/ast_new-statements2-c4cdc5f.stdout @@ -0,0 +1 @@ +(Module [(Expr (BoolOp And [(Name a Load) (Name b Load)])) (Expr (BoolOp Or [(BoolOp And [(Name a Load) (Name b Load)]) (Name c Load)])) (Expr (BoolOp Or [(Name a Load) (Name b Load)])) (Expr (BoolOp Or [(Name a Load) (BoolOp And [(Name b Load) (Name c Load)])])) (Expr (BoolOp Or [(BoolOp And [(Name a Load) (Name b Load) (Name c Load)]) (BoolOp Or [(Name x Load) (BoolOp And [(Name y Load) (BoolOp Or [(Name z Load) (Name i Load)])]) (Name j Load)])])) (Expr (BoolOp And [(BoolOp Or [(BoolOp And [(Name a Load) (BoolOp And [(Name b Load) (BoolOp Or [(Name c Load) (Name d Load)])]) (BoolOp And [(Name e Load) (Name f Load)])]) (Name x Load)]) (Name y Load)]))] []) diff --git a/tests/reference/ast_new-string1-96b90b3.json b/tests/reference/ast_new-string1-96b90b3.json new file mode 100644 index 0000000000..c11fab7984 --- /dev/null +++ b/tests/reference/ast_new-string1-96b90b3.json @@ -0,0 +1,13 @@ +{ + "basename": "ast_new-string1-96b90b3", + "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", + "infile": "tests/parser/string1.py", + "infile_hash": "f80422aba678d032cbe154b136dc6d63d61cecb1855cefd56c72a1f8", + "outfile": null, + "outfile_hash": null, + "stdout": "ast_new-string1-96b90b3.stdout", + "stdout_hash": "56a8537b091ac56f6256235a4a6bfe4cd12b7391613197e31bdae021", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast_new-string1-96b90b3.stdout b/tests/reference/ast_new-string1-96b90b3.stdout new file mode 100644 index 0000000000..b231095043 --- /dev/null +++ b/tests/reference/ast_new-string1-96b90b3.stdout @@ -0,0 +1,6 @@ +(Module [(Expr (JoinedStr [(ConstantStr "Hello, " ()) (FormattedValue (Name first_name Load) -1 ()) (ConstantStr " " ()) (FormattedValue (Name last_name Load) -1 ()) (ConstantStr ". You are " ()) (FormattedValue (Name age Load) -1 ()) (ConstantStr " years old." ())])) (Expr (Call (Name print Load) [(JoinedStr [(FormattedValue (Name __file__ Load) -1 ()) (ConstantStr " executed in " ()) (FormattedValue (Name elapsed Load) -1 ()) (ConstantStr " seconds." ())])] [])) (Expr (ConstantStr " +sometext +anotherline +" ())) (Expr (ConstantBytes "b'Some text goes here.'" ())) (Expr (ConstantBytes "b'\nMultiple texts goes here.\n'" ())) (Expr (ConstantStr " +Text +" ())) (Expr (ConstantStr "Text" ())) (Expr (ConstantStr "a\tb\nA\tB" ()))] []) diff --git a/tests/reference/ast_new-while1-a4c6382.json b/tests/reference/ast_new-while1-a4c6382.json new file mode 100644 index 0000000000..44b7642509 --- /dev/null +++ b/tests/reference/ast_new-while1-a4c6382.json @@ -0,0 +1,13 @@ +{ + "basename": "ast_new-while1-a4c6382", + "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", + "infile": "tests/parser/while1.py", + "infile_hash": "e27d72e6ee7ed22aafb02f3c9b6cf036e4d4bfd6c37dd41fc799fd34", + "outfile": null, + "outfile_hash": null, + "stdout": "ast_new-while1-a4c6382.stdout", + "stdout_hash": "494faaa8a33fdfa1391b3dc29ca52c552e402b7de99b2316c65984bf", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/ast_new-while1-a4c6382.stdout b/tests/reference/ast_new-while1-a4c6382.stdout new file mode 100644 index 0000000000..1122684882 --- /dev/null +++ b/tests/reference/ast_new-while1-a4c6382.stdout @@ -0,0 +1 @@ +(Module [(ImportFrom ltypes [(i32 ())] 0) (AnnAssign (Name i Store) (Name i32 Load) (ConstantInt 10 ()) 1) (While (Compare (Name i Load) Lt [(ConstantInt 3 ())]) [(Pass)] []) (While (Compare (Name i Load) Lt [(ConstantInt 6 ())]) [(Pass)] [(Pass)])] []) diff --git a/tests/reference/c-c_interop1-e215531.json b/tests/reference/c-c_interop1-e215531.json new file mode 100644 index 0000000000..c7b64eac0e --- /dev/null +++ b/tests/reference/c-c_interop1-e215531.json @@ -0,0 +1,13 @@ +{ + "basename": "c-c_interop1-e215531", + "cmd": "lpython --no-color --show-c {infile}", + "infile": "tests/c_interop1.py", + "infile_hash": "e676d05044fa71c2bd65b09dd5ed2d20414f6b1c028ef528aab47748", + "outfile": null, + "outfile_hash": null, + "stdout": "c-c_interop1-e215531.stdout", + "stdout_hash": "11cf8db8c889d3cecf22754b1cbefd486dacf602f0c3be8955b783b6", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/c-c_interop1-e215531.stdout b/tests/reference/c-c_interop1-e215531.stdout new file mode 100644 index 0000000000..5828379972 --- /dev/null +++ b/tests/reference/c-c_interop1-e215531.stdout @@ -0,0 +1,76 @@ +#include + +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +double f(double x); +void g(double a, float b, int64_t c, int32_t d); +double h(double x); +void l(double a, float b, int64_t c, int32_t d); +void main0(); + +// Implementations +double h(double x) +{ + double _lpython_return_variable; + _lpython_return_variable = x + 1.00000000000000000e+00; + return _lpython_return_variable; +} + +void l(double a, float b, int64_t c, int32_t d) +{ + printf("%s\n", "OK"); +} + +void main0() +{ + double i; + double x; + float y; + int64_t z; + int32_t zz; + x = 5.00000000000000000e+00; + i = f(x); + y = 5.40000000000000036e+00; + z = 3; + zz = 2; + g(x, y, z, zz); + i = h(x); + l(x, y, z, zz); +} + +int main(int argc, char* argv[]) +{ + return 0; +} diff --git a/tests/reference/c-expr7-bb2692a.json b/tests/reference/c-expr7-bb2692a.json new file mode 100644 index 0000000000..6dfe42d440 --- /dev/null +++ b/tests/reference/c-expr7-bb2692a.json @@ -0,0 +1,13 @@ +{ + "basename": "c-expr7-bb2692a", + "cmd": "lpython --no-color --show-c {infile}", + "infile": "tests/expr7.py", + "infile_hash": "4a455e2279eb7dd269d81c1a257dea625b17b100d92e304e5ac34421", + "outfile": null, + "outfile_hash": null, + "stdout": "c-expr7-bb2692a.stdout", + "stdout_hash": "d92016ec76d96205acde2d16bccf0e4ae23c3ad2c3c7f24117fd9a10", + "stderr": "c-expr7-bb2692a.stderr", + "stderr_hash": "28509dd59a386eebd632340a550d14299cd2a921ef6dc3ac7dbe7fe9", + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/c-expr7-bb2692a.stderr b/tests/reference/c-expr7-bb2692a.stderr new file mode 100644 index 0000000000..7d800cf4e4 --- /dev/null +++ b/tests/reference/c-expr7-bb2692a.stderr @@ -0,0 +1,11 @@ +style suggestion: Could have used '**' instead of 'pow' + --> tests/expr7.py:3:9 + | +3 | a = pow(2, 2) + | ^^^^^^^^^ '**' could be used instead + +style suggestion: Could have used '**' instead of 'pow' + --> tests/expr7.py:7:11 + | +7 | res = pow(a, b) + | ^^^^^^^^^ '**' could be used instead diff --git a/tests/reference/c-expr7-bb2692a.stdout b/tests/reference/c-expr7-bb2692a.stdout new file mode 100644 index 0000000000..92951d046b --- /dev/null +++ b/tests/reference/c-expr7-bb2692a.stdout @@ -0,0 +1,90 @@ +#include +#include +#include + +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void main0(); +void test_pow(); +int32_t test_pow_1(int32_t a, int32_t b); +int32_t __lpython_overloaded_0__pow(int32_t x, int32_t y); +float _lfortran_caimag(float complex x); +double _lfortran_zaimag(double complex x); + +// Implementations +void _lpython_main_program() +{ + main0(); +} + +void main0() +{ + int32_t c; + test_pow(); + c = test_pow_1(1, 2); +} + +void test_pow() +{ + int32_t a; + a = __lpython_overloaded_0__pow(2, 2); +} + +int32_t test_pow_1(int32_t a, int32_t b) +{ + int32_t _lpython_return_variable; + int32_t res; + res = __lpython_overloaded_0__pow(a, b); + _lpython_return_variable = res; + return _lpython_return_variable; +} + +int32_t __lpython_overloaded_0__pow(int32_t x, int32_t y) +{ + int32_t _lpython_return_variable; + _lpython_return_variable = pow(x, y); + return _lpython_return_variable; +} + +float _lfortran_caimag(float complex x); + +double _lfortran_zaimag(double complex x); + +int main(int argc, char* argv[]) +{ + _lpython_main_program(); + return 0; +} diff --git a/tests/reference/c-expr_11-c452314.json b/tests/reference/c-expr_11-c452314.json new file mode 100644 index 0000000000..178a814c7a --- /dev/null +++ b/tests/reference/c-expr_11-c452314.json @@ -0,0 +1,13 @@ +{ + "basename": "c-expr_11-c452314", + "cmd": "lpython --no-color --show-c {infile}", + "infile": "tests/../integration_tests/expr_11.py", + "infile_hash": "0519507fdfc01296c8161d8fae6706269bdb2d7b7da54512f5410fca", + "outfile": null, + "outfile_hash": null, + "stdout": "c-expr_11-c452314.stdout", + "stdout_hash": "739494cc9be85e9355203dafb1230c7ef9a43852641592e8b8319e5e", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/c-expr_11-c452314.stdout b/tests/reference/c-expr_11-c452314.stdout new file mode 100644 index 0000000000..211d50eb35 --- /dev/null +++ b/tests/reference/c-expr_11-c452314.stdout @@ -0,0 +1,60 @@ +#include + +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void f(); + +// Implementations +void _lpython_main_program() +{ + f(); +} + +void f() +{ + bool b; + int32_t i; + i = 3; + b = (bool)(i); + ASSERT(b); + printf("%d\n", b); +} + +int main(int argc, char* argv[]) +{ + _lpython_main_program(); + return 0; +} diff --git a/tests/reference/c-expr_12-93c7780.json b/tests/reference/c-expr_12-93c7780.json new file mode 100644 index 0000000000..303e065f85 --- /dev/null +++ b/tests/reference/c-expr_12-93c7780.json @@ -0,0 +1,13 @@ +{ + "basename": "c-expr_12-93c7780", + "cmd": "lpython --no-color --show-c {infile}", + "infile": "tests/../integration_tests/expr_12.py", + "infile_hash": "c8e08b659b74d9bff57f8a831a38421996e9e015cce2cf20e40e3e2e", + "outfile": null, + "outfile_hash": null, + "stdout": "c-expr_12-93c7780.stdout", + "stdout_hash": "15e70688598c75ec10b754b7d379cdbcc60ba46bd0b2eb44c1a69b80", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/c-expr_12-93c7780.stdout b/tests/reference/c-expr_12-93c7780.stdout new file mode 100644 index 0000000000..2b92084d45 --- /dev/null +++ b/tests/reference/c-expr_12-93c7780.stdout @@ -0,0 +1,89 @@ +#include + +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; + +struct i16_1 +{ + int16_t *data; + struct dimension_descriptor dims[1]; + bool is_allocated; +}; + +// Forward declarations +void _lpython_main_program(); +void check(struct i16_1* *ptr); +void f(); +void g(struct i16_1* *x, struct i16_1* y); + +// Implementations +void _lpython_main_program() +{ + f(); +} + +void check(struct i16_1* *ptr) +{ + ASSERT((*ptr)->data[(0 - (*ptr)->dims[0].lower_bound)] == 1); + ASSERT((*ptr)->data[(1 - (*ptr)->dims[0].lower_bound)] == 2); +} + +void f() +{ + struct i16_1 y_value; + struct i16_1* y = &y_value; + int16_t y_data[2]; + y->data = y_data; + y->dims[0].lower_bound = 0; + y->dims[0].upper_bound = 2 - 1; + struct i16_1 yptr1_value; + struct i16_1* yptr1 = &yptr1_value; +; + g(&yptr1, y); + check(&yptr1); +} + +void g(struct i16_1* *x, struct i16_1* y) +{ + y->data[(0 - y->dims[0].lower_bound)] = 1; + y->data[(1 - y->dims[0].lower_bound)] = 2; + (*x) = y; + printf("%d%s%d\n", (*x)->data[(0 - (*x)->dims[0].lower_bound)], " ", (*x)->data[(1 - (*x)->dims[0].lower_bound)]); +} + +int main(int argc, char* argv[]) +{ + _lpython_main_program(); + return 0; +} diff --git a/tests/reference/c-loop1-3e341c7.json b/tests/reference/c-loop1-3e341c7.json new file mode 100644 index 0000000000..314c7b5290 --- /dev/null +++ b/tests/reference/c-loop1-3e341c7.json @@ -0,0 +1,13 @@ +{ + "basename": "c-loop1-3e341c7", + "cmd": "lpython --no-color --show-c {infile}", + "infile": "tests/loop1.py", + "infile_hash": "c6799c859004650fdb3abca560c74e978e8f0d22d9f1e3466a074017", + "outfile": null, + "outfile_hash": null, + "stdout": "c-loop1-3e341c7.stdout", + "stdout_hash": "e08e4a1f49bac2a5b1d2f6d3d0aa26b1d18c86c2d2e92e956c91e3f3", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/c-loop1-3e341c7.stdout b/tests/reference/c-loop1-3e341c7.stdout new file mode 100644 index 0000000000..e4fd17672c --- /dev/null +++ b/tests/reference/c-loop1-3e341c7.stdout @@ -0,0 +1,110 @@ +#include + +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void main0(); +int32_t test_factorial_1(int32_t x); +int32_t test_factorial_2(int32_t x); +int64_t test_factorial_3(int32_t x); + +// Implementations +void _lpython_main_program() +{ + main0(); +} + +void main0() +{ + int32_t i; + int64_t j; + i = test_factorial_1(4); + i = test_factorial_2(4); + j = test_factorial_3(5); +} + +int32_t test_factorial_1(int32_t x) +{ + int32_t _lpython_return_variable; + int32_t result; + if (x < 0) { + _lpython_return_variable = 0; + return _lpython_return_variable; + } + result = 1; + while (x > 0) { + result = result*x; + x = x - 1; + } + _lpython_return_variable = result; + return _lpython_return_variable; +} + +int32_t test_factorial_2(int32_t x) +{ + int32_t _lpython_return_variable; + int32_t i; + int32_t result; + result = 1; + for (i=1; i<=x + 1 - 1; i++) { + result = result*i; + } + _lpython_return_variable = result; + return _lpython_return_variable; +} + +int64_t test_factorial_3(int32_t x) +{ + int64_t _lpython_return_variable; + int64_t result; + result = 0; + if (x < 0) { + _lpython_return_variable = result; + return _lpython_return_variable; + } + result = 1; + while (x > 0) { + result = result*x; + x = x - 1; + } + _lpython_return_variable = result; + return _lpython_return_variable; +} + +int main(int argc, char* argv[]) +{ + _lpython_main_program(); + return 0; +} diff --git a/tests/reference/c-loop2-ce7de51.json b/tests/reference/c-loop2-ce7de51.json new file mode 100644 index 0000000000..abe3222a9a --- /dev/null +++ b/tests/reference/c-loop2-ce7de51.json @@ -0,0 +1,13 @@ +{ + "basename": "c-loop2-ce7de51", + "cmd": "lpython --no-color --show-c {infile}", + "infile": "tests/loop2.py", + "infile_hash": "7946c522ceb16f99810780d4aba7fa2593695a4b49fb35ea1f131f53", + "outfile": null, + "outfile_hash": null, + "stdout": "c-loop2-ce7de51.stdout", + "stdout_hash": "21de5e08fb5e9bddada23a0e08ec66c952ffcf30d3b157c2aeeff98d", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/c-loop2-ce7de51.stdout b/tests/reference/c-loop2-ce7de51.stdout new file mode 100644 index 0000000000..afcf3fe12c --- /dev/null +++ b/tests/reference/c-loop2-ce7de51.stdout @@ -0,0 +1,73 @@ +#include + +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void test_for(); +void _xx_lcompilers_changed_exit_xx(int32_t error_code); + +// Implementations +void _lpython_main_program() +{ + test_for(); +} + +void test_for() +{ + int32_t i; + for (i=0; i<=10 - 1; i++) { + if (i == 0) { + continue; + } + if (i > 5) { + break; + } + if (i == 3) { + exit(0); + } + } + _xx_lcompilers_changed_exit_xx(2); +} + +void _xx_lcompilers_changed_exit_xx(int32_t error_code) +{ + exit(error_code); +} + +int main(int argc, char* argv[]) +{ + _lpython_main_program(); + return 0; +} diff --git a/tests/reference/c-print_01-4d44628.json b/tests/reference/c-print_01-4d44628.json new file mode 100644 index 0000000000..020147f687 --- /dev/null +++ b/tests/reference/c-print_01-4d44628.json @@ -0,0 +1,13 @@ +{ + "basename": "c-print_01-4d44628", + "cmd": "lpython --no-color --show-c {infile}", + "infile": "tests/../integration_tests/print_01.py", + "infile_hash": "4755131262f8eb382c206da769880635ad00787824c37f788d1c3d44", + "outfile": null, + "outfile_hash": null, + "stdout": "c-print_01-4d44628.stdout", + "stdout_hash": "4ab24d8f04f3ff2b361bf69dab7ab2d6c5f40ee79d064dc58aced844", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/c-print_01-4d44628.stdout b/tests/reference/c-print_01-4d44628.stdout new file mode 100644 index 0000000000..c7d9995922 --- /dev/null +++ b/tests/reference/c-print_01-4d44628.stdout @@ -0,0 +1,65 @@ + +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void f(); + +// Implementations +void _lpython_main_program() +{ + f(); +} + +void f() +{ + char * x; + char * y; + printf("%s\n", "Hello World!"); + x = ","; + y = "!!"; + printf("%s%s%s\n", "a", x, "b"); + x = "-+-+-"; + printf("%s%s%s%s%s\n", "a", x, "b", x, "c"); + printf("%s%s%s%s%s\n", "d", "=", "e", "=", "f"); + printf("%s%s%s%s%s\n", "x", "*\n", "y", "*\n", "z"); + printf("%s%s%s\n", "1", ":", "2"); + printf("%s%s%s\n", "LCompilers", " ", "LPython"); +} + +int main(int argc, char* argv[]) +{ + _lpython_main_program(); + return 0; +} diff --git a/tests/reference/c-test_issue_518-fbbd299.json b/tests/reference/c-test_issue_518-fbbd299.json new file mode 100644 index 0000000000..a9617be2a0 --- /dev/null +++ b/tests/reference/c-test_issue_518-fbbd299.json @@ -0,0 +1,13 @@ +{ + "basename": "c-test_issue_518-fbbd299", + "cmd": "lpython --no-color --show-c {infile}", + "infile": "tests/../integration_tests/test_issue_518.py", + "infile_hash": "20feb83ffed2a8042d4d41968c7efee5d0a57a2d1c8223fac81f3311", + "outfile": null, + "outfile_hash": null, + "stdout": "c-test_issue_518-fbbd299.stdout", + "stdout_hash": "89ab7f8ea0768b679a36909acc7689f55cac48896b3e062920e1a304", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/c-test_issue_518-fbbd299.stdout b/tests/reference/c-test_issue_518-fbbd299.stdout new file mode 100644 index 0000000000..672c2277c9 --- /dev/null +++ b/tests/reference/c-test_issue_518-fbbd299.stdout @@ -0,0 +1,80 @@ +#include + +#include +#include +#include +#include + +#define ASSERT(cond) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + exit(1); \ + } \ + } +#define ASSERT_MSG(cond, msg) \ + { \ + if (!(cond)) { \ + printf("%s%s", "ASSERT failed: ", __FILE__); \ + printf("%s%s", "\nfunction ", __func__); \ + printf("%s%d%s", "(), line number ", __LINE__, " at \n"); \ + printf("%s%s", #cond, "\n"); \ + printf("%s", "ERROR MESSAGE:\n"); \ + printf("%s%s", msg, "\n"); \ + exit(1); \ + } \ + } + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +int64_t fib(int64_t n); +void _xx_lcompilers_changed_main_xx(); +void main0(); + +// Implementations +void _lpython_main_program() +{ + main0(); + main(); +} + +int64_t fib(int64_t n) +{ + int64_t _lpython_return_variable; + if (n < 2) { + _lpython_return_variable = n; + return _lpython_return_variable; + } else { + _lpython_return_variable = fib(n - 1) + fib(n - 2); + return _lpython_return_variable; + } + return _lpython_return_variable; +} + +void _xx_lcompilers_changed_main_xx() +{ + int64_t ans; + ans = fib(10); + ASSERT(ans == 55); +} + +void main0() +{ + int64_t ans; + ans = fib(15); + ASSERT(ans == 610); +} + +int main(int argc, char* argv[]) +{ + _lpython_main_program(); + return 0; +} diff --git a/tests/reference/cpp-assert1-ba60925.json b/tests/reference/cpp-assert1-ba60925.json index 614a63fef4..bc85af6497 100644 --- a/tests/reference/cpp-assert1-ba60925.json +++ b/tests/reference/cpp-assert1-ba60925.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-assert1-ba60925.stdout", - "stdout_hash": "0d55633e9fc6c730c143ffb38d0e3c0ea8d6ac7c4b58906557c9ff3f", + "stdout_hash": "53b55e831edf78c24f014e840ff1d2994764b4811cd20920121bbaae", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-assert1-ba60925.stdout b/tests/reference/cpp-assert1-ba60925.stdout index 02e5355894..5428ace0b9 100644 --- a/tests/reference/cpp-assert1-ba60925.stdout +++ b/tests/reference/cpp-assert1-ba60925.stdout @@ -17,6 +17,17 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void test_assert(); +namespace { +} + +// Implementations void test_assert() { int a; diff --git a/tests/reference/cpp-doconcurrentloop_01-4e9f274.json b/tests/reference/cpp-doconcurrentloop_01-4e9f274.json index 4349cd5148..6d2e1d56ca 100644 --- a/tests/reference/cpp-doconcurrentloop_01-4e9f274.json +++ b/tests/reference/cpp-doconcurrentloop_01-4e9f274.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-doconcurrentloop_01-4e9f274.stdout", - "stdout_hash": "3c70b29d6cb3f91e591f9f43abf149b5c2123e03db2fc56143200159", + "stdout_hash": "9bb561c231e3818ca09e0360728ea61edce90358ff38b821509db884", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-doconcurrentloop_01-4e9f274.stdout b/tests/reference/cpp-doconcurrentloop_01-4e9f274.stdout index ea4bfc31d7..28fc327efa 100644 --- a/tests/reference/cpp-doconcurrentloop_01-4e9f274.stdout +++ b/tests/reference/cpp-doconcurrentloop_01-4e9f274.stdout @@ -17,6 +17,31 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; + +struct f32_10000_1 +{ + Kokkos::View* data; + dimension_descriptor dims[1]; + bool is_allocated; + + f32_10000_1(Kokkos::View* data_): data{data_} {}; +}; + +// Forward declarations +void _lpython_main_program(); +void main0(); + +template +void triad(T0* a, T1* b, float scalar, T2* c); +namespace { +} + +// Implementations void _lpython_main_program() { main0(); @@ -24,34 +49,48 @@ void _lpython_main_program() void main0() { - Kokkos::View a("a"); - Kokkos::View b("b"); - Kokkos::View c("c"); + Kokkos::View a_data("a_data", 10000); + f32_10000_1 a_value(&a_data); + f32_10000_1* a = &a_value; + a->dims[0].lower_bound = 0; + a->dims[0].upper_bound = 10000 - 1; + Kokkos::View b_data("b_data", 10000); + f32_10000_1 b_value(&b_data); + f32_10000_1* b = &b_value; + b->dims[0].lower_bound = 0; + b->dims[0].upper_bound = 10000 - 1; + Kokkos::View c_data("c_data", 10000); + f32_10000_1 c_value(&c_data); + f32_10000_1* c = &c_value; + c->dims[0].lower_bound = 0; + c->dims[0].upper_bound = 10000 - 1; int nsize; float scalar; - scalar = 10.000000; + scalar = 1.00000000000000000e+01; nsize = 1234; Kokkos::parallel_for(Kokkos::RangePolicy(0, nsize - 1+1), KOKKOS_LAMBDA(const long i) { - a[i + 1-1] = 5.000000; - b[i + 1-1] = 5.000000; + a->data->operator[](i - a->dims[0].lower_bound) = 5.00000000000000000e+00; + b->data->operator[](i - b->dims[0].lower_bound) = 5.00000000000000000e+00; }); triad(a, b, scalar, c); std::cout << "End Stream Triad" << std::endl; } -void triad(const Kokkos::View &a, const Kokkos::View &b, float scalar, const Kokkos::View &c) + +template +void triad(T0* a, T1* b, float scalar, T2* c) { int N; N = 1234; Kokkos::parallel_for(Kokkos::RangePolicy(0, N - 1+1), KOKKOS_LAMBDA(const long i) { - c[i + 1-1] = a[i + 1-1] + scalar*b[i + 1-1]; + c->data->operator[](i - c->dims[0].lower_bound) = a->data->operator[](i - a->dims[0].lower_bound) + scalar*b->data->operator[](i - b->dims[0].lower_bound); }); } namespace { void main2() { - _lpython_main_program(); + _lpython_main_program(); } } diff --git a/tests/reference/cpp-expr12-fd2ea87.json b/tests/reference/cpp-expr12-fd2ea87.json index 79ce8e0ff7..3209a9cb90 100644 --- a/tests/reference/cpp-expr12-fd2ea87.json +++ b/tests/reference/cpp-expr12-fd2ea87.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr12-fd2ea87.stdout", - "stdout_hash": "85ef23b2386cff66b61a97312bbeeb1543da4855c46b844c40159947", + "stdout_hash": "16e2493ec2f3c2ffe6f5f4fc70b1724628d80b847d773694e2b34f76", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr12-fd2ea87.stdout b/tests/reference/cpp-expr12-fd2ea87.stdout index da20091ef0..2fd104ce20 100644 --- a/tests/reference/cpp-expr12-fd2ea87.stdout +++ b/tests/reference/cpp-expr12-fd2ea87.stdout @@ -17,12 +17,26 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +int32_t check(); +void main0(); +int32_t test(int a, int b); +namespace { +} + +// Implementations void _lpython_main_program() { main0(); } -int check() +int32_t check() { int _lpython_return_variable; int a; @@ -37,7 +51,7 @@ void main0() x = check(); } -int test(int a, int b) +int32_t test(int a, int b) { int _lpython_return_variable; _lpython_return_variable = std::pow(a, b); @@ -47,7 +61,7 @@ int test(int a, int b) namespace { void main2() { - _lpython_main_program(); + _lpython_main_program(); } } diff --git a/tests/reference/cpp-expr15-1661c0d.json b/tests/reference/cpp-expr15-1661c0d.json index 0bbfc60512..80d07ca85f 100644 --- a/tests/reference/cpp-expr15-1661c0d.json +++ b/tests/reference/cpp-expr15-1661c0d.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr15-1661c0d.stdout", - "stdout_hash": "c5c1432ba6bba06295a9872b29999f019e7b1070bf64c34b8e0fcb9e", + "stdout_hash": "e3305bf4072f36329f274c61b5350069eb061c33db0dfad2309bbe0f", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr15-1661c0d.stdout b/tests/reference/cpp-expr15-1661c0d.stdout index 369f412c62..74313bd15a 100644 --- a/tests/reference/cpp-expr15-1661c0d.stdout +++ b/tests/reference/cpp-expr15-1661c0d.stdout @@ -17,6 +17,23 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +double test1(); +std::complex test2(); +int32_t test3(); +std::complex __lpython_overloaded_9__complex(int x, int y); +float _lfortran_caimag(std::complex x); +double _lfortran_zaimag(std::complex x); +namespace { +} + +// Implementations void _lpython_main_program() { std::cout << test1() << std::endl; @@ -28,7 +45,7 @@ double test1() { double _lpython_return_variable; double x; - x = 1.000000; + x = 1.00000000000000000e+00; _lpython_return_variable = x; return _lpython_return_variable; } @@ -42,7 +59,7 @@ std::complex test2() return _lpython_return_variable; } -int test3() +int32_t test3() { int _lpython_return_variable; std::complex x; @@ -67,7 +84,7 @@ double _lfortran_zaimag(std::complex x); namespace { void main2() { - _lpython_main_program(); + _lpython_main_program(); } } diff --git a/tests/reference/cpp-expr2-09c05ad.json b/tests/reference/cpp-expr2-09c05ad.json index d631dc648f..f27d421c2f 100644 --- a/tests/reference/cpp-expr2-09c05ad.json +++ b/tests/reference/cpp-expr2-09c05ad.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr2-09c05ad.stdout", - "stdout_hash": "6c3d7cb4d07c43d82bec9407b178bed4a6f9ef599efe996fb5a0e880", + "stdout_hash": "5401db0a1f1a2373b4af5a0b900948971a0db09c0fb61731248e7748", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr2-09c05ad.stdout b/tests/reference/cpp-expr2-09c05ad.stdout index efcd9ca746..92c6ca0ef4 100644 --- a/tests/reference/cpp-expr2-09c05ad.stdout +++ b/tests/reference/cpp-expr2-09c05ad.stdout @@ -17,6 +17,17 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void test_boolOp(); +namespace { +} + +// Implementations void test_boolOp() { bool a; diff --git a/tests/reference/cpp-expr3-9c516d4.json b/tests/reference/cpp-expr3-9c516d4.json index db651a42e6..4a2dec1a81 100644 --- a/tests/reference/cpp-expr3-9c516d4.json +++ b/tests/reference/cpp-expr3-9c516d4.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr3-9c516d4.stdout", - "stdout_hash": "fcd0aa25d8c2bceed00bf25734f244f327781de9ecfec48602001e51", + "stdout_hash": "da9607eab5ea52af03b2ba3b55eaff7486e7bf6fdb2971516324c392", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr3-9c516d4.stdout b/tests/reference/cpp-expr3-9c516d4.stdout index 026c17dcf7..a2d0d7158e 100644 --- a/tests/reference/cpp-expr3-9c516d4.stdout +++ b/tests/reference/cpp-expr3-9c516d4.stdout @@ -17,16 +17,27 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void test_cast(); +namespace { +} + +// Implementations void test_cast() { int a; float b; a = 2; - b = 4.200000; + b = 4.20000000000000018e+00; a = (float)(a)*b; b = b + (float)(1); a = 5; - a = (float)(a) - 3.900000; + a = (float)(a) - 3.89999999999999991e+00; a = (float)(a)/b; b = (float)(3)/(float)(4); if ((float)(a) < b) { diff --git a/tests/reference/cpp-expr5-1de0e30.json b/tests/reference/cpp-expr5-1de0e30.json index 2241f5a6d9..de1e9b9607 100644 --- a/tests/reference/cpp-expr5-1de0e30.json +++ b/tests/reference/cpp-expr5-1de0e30.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr5-1de0e30.stdout", - "stdout_hash": "c4b94ece3efeb57e537a3b5084d608c2e5974fd699370c007042803a", + "stdout_hash": "3c42d21ec57653b0b2f007761f5f203436d2b96cbd13a616a9c8e14e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr5-1de0e30.stdout b/tests/reference/cpp-expr5-1de0e30.stdout index 76afb92c22..987e458078 100644 --- a/tests/reference/cpp-expr5-1de0e30.stdout +++ b/tests/reference/cpp-expr5-1de0e30.stdout @@ -17,6 +17,17 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void test_StrOp_concat(); +namespace { +} + +// Implementations void test_StrOp_concat() { std::string s; diff --git a/tests/reference/cpp-expr6-f337f4f.json b/tests/reference/cpp-expr6-f337f4f.json index caf78342b7..498e1d5d8a 100644 --- a/tests/reference/cpp-expr6-f337f4f.json +++ b/tests/reference/cpp-expr6-f337f4f.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr6-f337f4f.stdout", - "stdout_hash": "8f34b920c822d50a500e646436e421cf7fcc64dd332d5316d964d480", + "stdout_hash": "478dab3faafde1d5d8e5176571bf928597b23ac4ad84c9a8c781b5bf", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr6-f337f4f.stdout b/tests/reference/cpp-expr6-f337f4f.stdout index 75a6451108..0077d43832 100644 --- a/tests/reference/cpp-expr6-f337f4f.stdout +++ b/tests/reference/cpp-expr6-f337f4f.stdout @@ -17,6 +17,17 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void test_ifexp(); +namespace { +} + +// Implementations void test_ifexp() { int a; diff --git a/tests/reference/cpp-expr7-529bd53.json b/tests/reference/cpp-expr7-529bd53.json index 376c27437c..2735fe7307 100644 --- a/tests/reference/cpp-expr7-529bd53.json +++ b/tests/reference/cpp-expr7-529bd53.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr7-529bd53.stdout", - "stdout_hash": "ffa3635df3217693ebcee996bd25a1dba620b52d741a3f0d0cdb2f6f", + "stdout_hash": "4bef0a6c627ce074197b3bf54162f8c2e24e2b66a7b324a0e5ca7b8b", "stderr": "cpp-expr7-529bd53.stderr", "stderr_hash": "28509dd59a386eebd632340a550d14299cd2a921ef6dc3ac7dbe7fe9", "returncode": 0 diff --git a/tests/reference/cpp-expr7-529bd53.stdout b/tests/reference/cpp-expr7-529bd53.stdout index 95327e8f5d..f93f363285 100644 --- a/tests/reference/cpp-expr7-529bd53.stdout +++ b/tests/reference/cpp-expr7-529bd53.stdout @@ -17,6 +17,23 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void main0(); +void test_pow(); +int32_t test_pow_1(int a, int b); +int32_t __lpython_overloaded_0__pow(int x, int y); +float _lfortran_caimag(std::complex x); +double _lfortran_zaimag(std::complex x); +namespace { +} + +// Implementations void _lpython_main_program() { main0(); @@ -35,7 +52,7 @@ void test_pow() a = __lpython_overloaded_0__pow(2, 2); } -int test_pow_1(int a, int b) +int32_t test_pow_1(int a, int b) { int _lpython_return_variable; int res; @@ -44,7 +61,7 @@ int test_pow_1(int a, int b) return _lpython_return_variable; } -int __lpython_overloaded_0__pow(int x, int y) +int32_t __lpython_overloaded_0__pow(int x, int y) { int _lpython_return_variable; _lpython_return_variable = std::pow(x, y); @@ -58,7 +75,7 @@ double _lfortran_zaimag(std::complex x); namespace { void main2() { - _lpython_main_program(); + _lpython_main_program(); } } diff --git a/tests/reference/cpp-expr8-704cece.json b/tests/reference/cpp-expr8-704cece.json index abe3e7e08d..77d2470ce8 100644 --- a/tests/reference/cpp-expr8-704cece.json +++ b/tests/reference/cpp-expr8-704cece.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr8-704cece.stdout", - "stdout_hash": "edb5949762120648068bb4c134c869f40a7cc92d124f22f7ef74592e", + "stdout_hash": "2505bf4cefef153ad87a401a9173b8beedc1b6e995ecd800535e26ad", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr8-704cece.stdout b/tests/reference/cpp-expr8-704cece.stdout index 06ae21d04a..1055c46ec5 100644 --- a/tests/reference/cpp-expr8-704cece.stdout +++ b/tests/reference/cpp-expr8-704cece.stdout @@ -17,6 +17,20 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void test_binop(); +int32_t __lpython_overloaded_2___lpython_floordiv(int a, int b); +float _lfortran_caimag(std::complex x); +double _lfortran_zaimag(std::complex x); +namespace { +} + +// Implementations void test_binop() { bool b1; @@ -24,11 +38,11 @@ void test_binop() int x; float x2; x = std::pow(2, 3); - x2 = std::pow((float)(2), 3.500000); + x2 = std::pow((float)(2), 3.50000000000000000e+00); x = 54 - 100; - x2 = 3.454000 - 765.430000 + 534.600000; - x2 = 5346.565000*3.450000; - x2 = std::pow(5346.565000, 3.450000); + x2 = 3.45400000000000018e+00 - 7.65429999999999950e+02 + 5.34600000000000023e+02; + x2 = 5.34656499999999960e+03* 3.45000000000000018e+00; + x2 = std::pow( 5.34656499999999960e+03, 3.45000000000000018e+00); x = (int)(true) + (int)(true); x = (int)(true) - (int)(false); x = (int)(true)*(int)(false); @@ -39,14 +53,14 @@ void test_binop() x = std::pow((int)(b1), (int)(b2)); } -int __lpython_overloaded_2___lpython_floordiv(int a, int b) +int32_t __lpython_overloaded_2___lpython_floordiv(int a, int b) { int _lpython_return_variable; float r; int result; r = (float)(a)/(float)(b); result = (int)(r); - if (r >= 0.000000 || (float)(result) == r) { + if (r >= 0.00000000000000000e+00 || (float)(result) == r) { _lpython_return_variable = result; return _lpython_return_variable; } diff --git a/tests/reference/cpp-expr9-48868e9.json b/tests/reference/cpp-expr9-48868e9.json index 47c23e6c84..5690ec43ac 100644 --- a/tests/reference/cpp-expr9-48868e9.json +++ b/tests/reference/cpp-expr9-48868e9.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-expr9-48868e9.stdout", - "stdout_hash": "648941d3372e81abfe380478bd013802a542f3891d4ef7f44dac97ba", + "stdout_hash": "2ec5400d453f21957358100a557a924a6adf39bcec446b8d6ba5167d", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-expr9-48868e9.stdout b/tests/reference/cpp-expr9-48868e9.stdout index d031ca3e91..475c4f861c 100644 --- a/tests/reference/cpp-expr9-48868e9.stdout +++ b/tests/reference/cpp-expr9-48868e9.stdout @@ -17,6 +17,22 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void main0(); +int32_t test_return_1(int a); +std::string test_return_2(int a); +int32_t test_return_3(int a); +void test_return_4(int a); +namespace { +} + +// Implementations void _lpython_main_program() { main0(); @@ -32,7 +48,7 @@ void main0() test_return_4(4); } -int test_return_1(int a) +int32_t test_return_1(int a) { int _lpython_return_variable; int x; @@ -50,7 +66,7 @@ std::string test_return_2(int a) return _lpython_return_variable; } -int test_return_3(int a) +int32_t test_return_3(int a) { int _lpython_return_variable; a = 3; @@ -67,7 +83,7 @@ void test_return_4(int a) namespace { void main2() { - _lpython_main_program(); + _lpython_main_program(); } } diff --git a/tests/reference/cpp-expr_11-422c839.json b/tests/reference/cpp-expr_11-422c839.json new file mode 100644 index 0000000000..d93de22007 --- /dev/null +++ b/tests/reference/cpp-expr_11-422c839.json @@ -0,0 +1,13 @@ +{ + "basename": "cpp-expr_11-422c839", + "cmd": "lpython --no-color --show-cpp {infile}", + "infile": "tests/../integration_tests/expr_11.py", + "infile_hash": "0519507fdfc01296c8161d8fae6706269bdb2d7b7da54512f5410fca", + "outfile": null, + "outfile_hash": null, + "stdout": "cpp-expr_11-422c839.stdout", + "stdout_hash": "0b56a8baf53c511c57ea1c5d33b0149b3284e71246a3e444fcbe6b4a", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/cpp-expr_11-422c839.stdout b/tests/reference/cpp-expr_11-422c839.stdout new file mode 100644 index 0000000000..c12948960b --- /dev/null +++ b/tests/reference/cpp-expr_11-422c839.stdout @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +template +Kokkos::View from_std_vector(const std::vector &v) +{ + Kokkos::View r("r", v.size()); + for (size_t i=0; i < v.size(); i++) { + r(i) = v[i]; + } + return r; +} + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void f(); +namespace { +} + +// Implementations +void _lpython_main_program() +{ + f(); +} + +void f() +{ + bool b; + int i; + i = 3; + b = (bool)(i); + assert (b); + std::cout << b << std::endl; +} + +namespace { + +void main2() { + _lpython_main_program(); +} + +} +int main(int argc, char* argv[]) +{ + Kokkos::initialize(argc, argv); + main2(); + Kokkos::finalize(); + return 0; +} diff --git a/tests/reference/cpp-loop1-0a8cf3b.json b/tests/reference/cpp-loop1-0a8cf3b.json index 964faa5b04..f3aa4f55cc 100644 --- a/tests/reference/cpp-loop1-0a8cf3b.json +++ b/tests/reference/cpp-loop1-0a8cf3b.json @@ -2,11 +2,11 @@ "basename": "cpp-loop1-0a8cf3b", "cmd": "lpython --no-color --show-cpp {infile}", "infile": "tests/loop1.py", - "infile_hash": "e50c7161122d599991fafb072d5db8fe7e54d017d56a5c1951a210ca", + "infile_hash": "c6799c859004650fdb3abca560c74e978e8f0d22d9f1e3466a074017", "outfile": null, "outfile_hash": null, "stdout": "cpp-loop1-0a8cf3b.stdout", - "stdout_hash": "79bcbb41c038ebb668a632a270d4ef7247bca02ceba219d7c9212b8f", + "stdout_hash": "c7c48ac70b150b4f6e4eef61d0cd32072512ee8fde7c6b4838152e08", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-loop1-0a8cf3b.stdout b/tests/reference/cpp-loop1-0a8cf3b.stdout index 754ec73bbc..90788b95f4 100644 --- a/tests/reference/cpp-loop1-0a8cf3b.stdout +++ b/tests/reference/cpp-loop1-0a8cf3b.stdout @@ -17,6 +17,21 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void main0(); +int32_t test_factorial_1(int x); +int32_t test_factorial_2(int x); +int64_t test_factorial_3(int x); +namespace { +} + +// Implementations void _lpython_main_program() { main0(); @@ -31,7 +46,7 @@ void main0() j = test_factorial_3(5); } -int test_factorial_1(int x) +int32_t test_factorial_1(int x) { int _lpython_return_variable; int result; @@ -48,7 +63,7 @@ int test_factorial_1(int x) return _lpython_return_variable; } -int test_factorial_2(int x) +int32_t test_factorial_2(int x) { int _lpython_return_variable; int i; @@ -61,12 +76,13 @@ int test_factorial_2(int x) return _lpython_return_variable; } -long long test_factorial_3(int x) +int64_t test_factorial_3(int x) { long long _lpython_return_variable; long long result; + result = 0; if (x < 0) { - _lpython_return_variable = 0; + _lpython_return_variable = result; return _lpython_return_variable; } result = 1; @@ -81,7 +97,7 @@ long long test_factorial_3(int x) namespace { void main2() { - _lpython_main_program(); + _lpython_main_program(); } } diff --git a/tests/reference/cpp-loop2-0686fc4.json b/tests/reference/cpp-loop2-0686fc4.json index 66d72799b9..221d9b69b6 100644 --- a/tests/reference/cpp-loop2-0686fc4.json +++ b/tests/reference/cpp-loop2-0686fc4.json @@ -2,11 +2,11 @@ "basename": "cpp-loop2-0686fc4", "cmd": "lpython --no-color --show-cpp {infile}", "infile": "tests/loop2.py", - "infile_hash": "0f1af9370fbae5de0ed9e612e933d7745598fc9c74b036496f4ae8ca", + "infile_hash": "7946c522ceb16f99810780d4aba7fa2593695a4b49fb35ea1f131f53", "outfile": null, "outfile_hash": null, "stdout": "cpp-loop2-0686fc4.stdout", - "stdout_hash": "b87452f2063487169d69762b0a4d9e35ef395c7c9aadd63bce60426c", + "stdout_hash": "42ea1370886d7b6af7c21ea91db667e76d6993662930d2e2925a53a4", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-loop2-0686fc4.stdout b/tests/reference/cpp-loop2-0686fc4.stdout index 1052ea3557..b773451b7c 100644 --- a/tests/reference/cpp-loop2-0686fc4.stdout +++ b/tests/reference/cpp-loop2-0686fc4.stdout @@ -17,6 +17,24 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void test_for(); +namespace { +} +void _xx_lcompilers_changed_exit_xx(int error_code); + +// Implementations +void _lpython_main_program() +{ + test_for(); +} + void test_for() { int i; @@ -31,17 +49,18 @@ void test_for() exit(0); } } - exit(0); + _xx_lcompilers_changed_exit_xx(2); } -void exit(int error_code) +void _xx_lcompilers_changed_exit_xx(int error_code) { - exit(0); + exit(error_code); } namespace { void main2() { + _lpython_main_program(); } } diff --git a/tests/reference/cpp-loop3-6020091.json b/tests/reference/cpp-loop3-6020091.json index bf9df9a8ed..d9e94a99d1 100644 --- a/tests/reference/cpp-loop3-6020091.json +++ b/tests/reference/cpp-loop3-6020091.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "cpp-loop3-6020091.stdout", - "stdout_hash": "208286689360b8924599c880527ecb42188b3318cd47b0f262df5e60", + "stdout_hash": "1ccf4ac5ceb7333112803f2a4033ca0ccdea763dc454df6f72ef1490", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/cpp-loop3-6020091.stdout b/tests/reference/cpp-loop3-6020091.stdout index 887a74e1a0..56674312b7 100644 --- a/tests/reference/cpp-loop3-6020091.stdout +++ b/tests/reference/cpp-loop3-6020091.stdout @@ -17,6 +17,17 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void test_pass(); +namespace { +} + +// Implementations void test_pass() { int a; diff --git a/tests/reference/cpp-print_01-026ef17.json b/tests/reference/cpp-print_01-026ef17.json new file mode 100644 index 0000000000..0044665d0c --- /dev/null +++ b/tests/reference/cpp-print_01-026ef17.json @@ -0,0 +1,13 @@ +{ + "basename": "cpp-print_01-026ef17", + "cmd": "lpython --no-color --show-cpp {infile}", + "infile": "tests/../integration_tests/print_01.py", + "infile_hash": "4755131262f8eb382c206da769880635ad00787824c37f788d1c3d44", + "outfile": null, + "outfile_hash": null, + "stdout": "cpp-print_01-026ef17.stdout", + "stdout_hash": "589c4df44d69c511799fc8d4c89c9c5063b5c058295584754304fc8d", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/cpp-print_01-026ef17.stdout b/tests/reference/cpp-print_01-026ef17.stdout new file mode 100644 index 0000000000..85f4cde0c5 --- /dev/null +++ b/tests/reference/cpp-print_01-026ef17.stdout @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +template +Kokkos::View from_std_vector(const std::vector &v) +{ + Kokkos::View r("r", v.size()); + for (size_t i=0; i < v.size(); i++) { + r(i) = v[i]; + } + return r; +} + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void f(); +namespace { +} + +// Implementations +void _lpython_main_program() +{ + f(); +} + +void f() +{ + std::string x; + std::string y; + std::cout << "Hello World!" << std::endl; + x = ","; + y = "!!"; + std::cout << "a" << x << "b" << std::endl; + x = "-+-+-"; + std::cout << "a" << x << "b" << x << "c" << std::endl; + std::cout << "d" << "=" << "e" << "=" << "f" << std::endl; + std::cout << "x" << "*\n" << "y" << "*\n" << "z" << std::endl; + std::cout << "1" << ":" << "2" << std::endl; + std::cout << "LCompilers" << " " << "LPython" << std::endl; +} + +namespace { + +void main2() { + _lpython_main_program(); +} + +} +int main(int argc, char* argv[]) +{ + Kokkos::initialize(argc, argv); + main2(); + Kokkos::finalize(); + return 0; +} diff --git a/tests/reference/cpp-test_builtin_pow-56b3f92.json b/tests/reference/cpp-test_builtin_pow-56b3f92.json index fee833cb44..5cc929b970 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": "cecc9373ec8ed7078ec19f4aea0ec169b2c35df6a34baa73627e3d7c", + "stdout_hash": "4b002051ba89d5289cb48a840d358270bff81a17b3dbac58a58737c9", "stderr": "cpp-test_builtin_pow-56b3f92.stderr", "stderr_hash": "180e1adfbb0d9c63a2fffa31951bbd629b3f1950cf0d97ca1389efe5", "returncode": 0 diff --git a/tests/reference/cpp-test_builtin_pow-56b3f92.stdout b/tests/reference/cpp-test_builtin_pow-56b3f92.stdout index 3d38287760..7bb11c8b1a 100644 --- a/tests/reference/cpp-test_builtin_pow-56b3f92.stdout +++ b/tests/reference/cpp-test_builtin_pow-56b3f92.stdout @@ -17,6 +17,32 @@ Kokkos::View from_std_vector(const std::vector &v) return r; } + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void test_pow(); +double __lpython_overloaded_0__abs(double x); +int32_t __lpython_overloaded_0__pow(int x, int y); +int64_t __lpython_overloaded_1__pow(long long x, long long y); +float __lpython_overloaded_2__pow(float x, float y); +double __lpython_overloaded_3__pow(double x, double y); +float __lpython_overloaded_4__pow(int x, float y); +float __lpython_overloaded_5__pow(float x, int y); +double __lpython_overloaded_6__pow(int x, double y); +double __lpython_overloaded_7__pow(double x, int y); +int32_t __lpython_overloaded_8__pow(bool x, bool y); +std::complex __lpython_overloaded_9__complex(int x, int y); +std::complex __lpython_overloaded_9__pow(std::complex c, int y); +float _lfortran_caimag(std::complex x); +double _lfortran_zaimag(std::complex x); +namespace { +} + +// Implementations void _lpython_main_program() { test_pow(); @@ -39,7 +65,7 @@ void test_pow() float p; int x; double y; - eps = 0.000000; + eps = 9.99999999999999980e-13; a = 2; b = 5; assert (__lpython_overloaded_0__pow(a, b) == 32); @@ -59,32 +85,38 @@ void test_pow() i1 = 6; i2 = -3; f1 = (float)(525346)/(float)(66456); - f2 = 3.000000; + f2 = 3.00000000000000000e+00; p = __lpython_overloaded_2__pow(f1, f2); f1 = __lpython_overloaded_4__pow(a, f2); f1 = __lpython_overloaded_5__pow(f2, a); + b1 = true; + b2 = false; assert (__lpython_overloaded_8__pow(b1, b2) == 1); assert (__lpython_overloaded_8__pow(b2, b1) == 0); assert (__lpython_overloaded_8__pow(b1, b2) == 1); assert (__lpython_overloaded_8__pow(false, false) == 1); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow(a1, a2) - 31.797193) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow(a2, a1) - 42.439989) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_6__pow(x, y) - 12.513503) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_7__pow(y, x) - 12.167000) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_6__pow(x, 5.500000) - 420.888346) < eps); - assert (__lpython_overloaded_0__abs((float)(__lpython_overloaded_0__pow(2, -1)) - 0.500000) < eps); - assert (__lpython_overloaded_0__abs((float)(__lpython_overloaded_0__pow(6, -4)) - 0.000772) < eps); - assert (__lpython_overloaded_0__abs((float)(__lpython_overloaded_0__pow(-3, -5)) + 0.004115) < eps); - assert (__lpython_overloaded_0__abs((float)(__lpython_overloaded_0__pow(6, -4)) - 0.000772) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow(4.500000, 2.300000) - 31.797193) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow(2.300000, 0.000000) - 1.000000) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow(2.300000, -1.500000) - 0.286687) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_6__pow(2, 3.400000) - 10.556063) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_6__pow(2, -3.400000) - 0.094732) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_7__pow(3.400000, 9) - 60716.992766) < eps); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_7__pow(0.000000, 53) - 0.000000) < eps); + a1 = 4.50000000000000000e+00; + a2 = 2.29999999999999982e+00; + assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow(a1, a2) - 3.17971929089206000e+01) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow(a2, a1) - 4.24399889427765871e+01) < eps); + x = 3; + y = 2.29999999999999982e+00; + assert (__lpython_overloaded_0__abs(__lpython_overloaded_6__pow(x, y) - 1.25135025328431819e+01) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_7__pow(y, x) - 1.21669999999999980e+01) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_6__pow(x, 5.50000000000000000e+00) - 4.20888346239237194e+02) < eps); + assert (__lpython_overloaded_0__abs((float)(__lpython_overloaded_0__pow(2, -1)) - 5.00000000000000000e-01) < eps); + assert (__lpython_overloaded_0__abs((float)(__lpython_overloaded_0__pow(6, -4)) - 7.71604938271604895e-04) < eps); + assert (__lpython_overloaded_0__abs((float)(__lpython_overloaded_0__pow(-3, -5)) + 4.11522633744856002e-03) < eps); + assert (__lpython_overloaded_0__abs((float)(__lpython_overloaded_0__pow(6, -4)) - 7.71604938271604895e-04) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow( 4.50000000000000000e+00, 2.29999999999999982e+00) - 3.17971929089206000e+01) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow( 2.29999999999999982e+00, 0.00000000000000000e+00) - 1.00000000000000000e+00) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_3__pow( 2.29999999999999982e+00, - 1.50000000000000000e+00) - 2.86687162345994395e-01) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_6__pow(2, 3.39999999999999991e+00) - 1.05560632861831536e+01) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_6__pow(2, - 3.39999999999999991e+00) - 9.47322854068998882e-02) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_7__pow( 3.39999999999999991e+00, 9) - 6.07169927664639836e+04) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_7__pow( 0.00000000000000000e+00, 53) - 0.00000000000000000e+00) < eps); assert (__lpython_overloaded_0__pow(4, 2) == 16); - assert (__lpython_overloaded_0__abs(__lpython_overloaded_7__pow(-4235.000000, 52) - 394800380598526378720936476336799774273305305904443955996320177992404102454228192853661558132283280490733920647962082901303487965679010854404517306573035287122910924343151116372519789002752.000000) < eps); + assert (__lpython_overloaded_0__abs(__lpython_overloaded_7__pow(- 4.23500000000000000e+03, 52) - 3.94800380598526379e+188) < eps); c1 = __lpython_overloaded_9__complex(4, 5); c1 = __lpython_overloaded_9__pow(c1, 4); } @@ -92,24 +124,24 @@ void test_pow() double __lpython_overloaded_0__abs(double x) { double _lpython_return_variable; - if (x >= 0.000000) { - _lpython_return_variable = x; - return _lpython_return_variable; + double result; + if (x >= 0.00000000000000000e+00) { + result = x; } else { - _lpython_return_variable = -x; - return _lpython_return_variable; + result = -x; } + _lpython_return_variable = result; return _lpython_return_variable; } -int __lpython_overloaded_0__pow(int x, int y) +int32_t __lpython_overloaded_0__pow(int x, int y) { int _lpython_return_variable; _lpython_return_variable = std::pow(x, y); return _lpython_return_variable; } -long long __lpython_overloaded_1__pow(long long x, long long y) +int64_t __lpython_overloaded_1__pow(long long x, long long y) { long long _lpython_return_variable; _lpython_return_variable = std::pow(x, y); @@ -158,7 +190,7 @@ double __lpython_overloaded_7__pow(double x, int y) return _lpython_return_variable; } -int __lpython_overloaded_8__pow(bool x, bool y) +int32_t __lpython_overloaded_8__pow(bool x, bool y) { int _lpython_return_variable; if (y && !x) { @@ -190,7 +222,7 @@ double _lfortran_zaimag(std::complex x); namespace { void main2() { - _lpython_main_program(); + _lpython_main_program(); } } diff --git a/tests/reference/cpp-test_integer_bitnot-20195fd.json b/tests/reference/cpp-test_integer_bitnot-20195fd.json new file mode 100644 index 0000000000..20011fdc99 --- /dev/null +++ b/tests/reference/cpp-test_integer_bitnot-20195fd.json @@ -0,0 +1,13 @@ +{ + "basename": "cpp-test_integer_bitnot-20195fd", + "cmd": "lpython --no-color --show-cpp {infile}", + "infile": "tests/../integration_tests/test_integer_bitnot.py", + "infile_hash": "dc976a358fbeebedead889f8e85b3eed4ac77ee20f68fcac58b81429", + "outfile": null, + "outfile_hash": null, + "stdout": "cpp-test_integer_bitnot-20195fd.stdout", + "stdout_hash": "82e212651792094aff69d44ff8c5ad7431b77b684fa312e6ece3fb83", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/cpp-test_integer_bitnot-20195fd.stdout b/tests/reference/cpp-test_integer_bitnot-20195fd.stdout new file mode 100644 index 0000000000..6abbcaf54e --- /dev/null +++ b/tests/reference/cpp-test_integer_bitnot-20195fd.stdout @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +template +Kokkos::View from_std_vector(const std::vector &v) +{ + Kokkos::View r("r", v.size()); + for (size_t i=0; i < v.size(); i++) { + r(i) = v[i]; + } + return r; +} + + +struct dimension_descriptor +{ + int32_t lower_bound, upper_bound; +}; +// Forward declarations +void _lpython_main_program(); +void f(); +namespace { +} + +// Implementations +void _lpython_main_program() +{ + f(); +} + +void f() +{ + int i; + int res; + i = 5; + res = ~i; + assert (res == -6); + i = -235346; + assert (~i == 235345); +} + +namespace { + +void main2() { + _lpython_main_program(); +} + +} +int main(int argc, char* argv[]) +{ + Kokkos::initialize(argc, argv); + main2(); + Kokkos::finalize(); + return 0; +} diff --git a/tests/reference/llvm-bindc_01-c984f09.json b/tests/reference/llvm-bindc_01-c984f09.json new file mode 100644 index 0000000000..af08f8dfc3 --- /dev/null +++ b/tests/reference/llvm-bindc_01-c984f09.json @@ -0,0 +1,13 @@ +{ + "basename": "llvm-bindc_01-c984f09", + "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", + "infile": "tests/../integration_tests/bindc_01.py", + "infile_hash": "d4690d665de9b941c2581ad02041822e1e322dba55485cf8534dfe0a", + "outfile": null, + "outfile_hash": null, + "stdout": "llvm-bindc_01-c984f09.stdout", + "stdout_hash": "dbaa991eb9f1ba65d9ec104cf8e1698c30b4750a2bc945f9d959d71e", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/llvm-bindc_01-c984f09.stdout b/tests/reference/llvm-bindc_01-c984f09.stdout new file mode 100644 index 0000000000..56200742e8 --- /dev/null +++ b/tests/reference/llvm-bindc_01-c984f09.stdout @@ -0,0 +1,32 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +@queries = global void* null +@x = global i16* null +@0 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@2 = private unnamed_addr constant [13 x i8] c"%lld%s%lld%s\00", align 1 + +define void @_lpython_main_program() { +.entry: + %0 = load void*, void** @queries, align 8 + %1 = bitcast void* %0 to i16* + store i16* %1, i16** @x, align 8 + %2 = load void*, void** @queries, align 8 + %3 = ptrtoint void* %2 to i64 + %4 = load i16*, i16** @x, align 8 + %5 = ptrtoint i16* %4 to i64 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @2, i32 0, i32 0), i64 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i64 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) + br label %return + +return: ; preds = %.entry + ret void +} + +declare void @_lfortran_printf(i8*, ...) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} diff --git a/tests/reference/llvm-bindc_02-3cf74e9.json b/tests/reference/llvm-bindc_02-3cf74e9.json new file mode 100644 index 0000000000..aef119ba11 --- /dev/null +++ b/tests/reference/llvm-bindc_02-3cf74e9.json @@ -0,0 +1,13 @@ +{ + "basename": "llvm-bindc_02-3cf74e9", + "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", + "infile": "tests/../integration_tests/bindc_02.py", + "infile_hash": "6cb36b53c00624e00b0457ee598e72dccd33d40b647a3bdc84949943", + "outfile": null, + "outfile_hash": null, + "stdout": "llvm-bindc_02-3cf74e9.stdout", + "stdout_hash": "6fc3777777053fb2f7a782dfe1f537a1eb08d0c10bef9c0ea62193a3", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/llvm-bindc_02-3cf74e9.stdout b/tests/reference/llvm-bindc_02-3cf74e9.stdout new file mode 100644 index 0000000000..3598e83837 --- /dev/null +++ b/tests/reference/llvm-bindc_02-3cf74e9.stdout @@ -0,0 +1,268 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +%array = type { i16*, i32, %dimension_descriptor*, i1, i32 } +%dimension_descriptor = type { i32, i32, i32, i32 } + +@queries = global void* null +@x = global %array* null +@0 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@2 = private unnamed_addr constant [13 x i8] c"%lld%s%lld%s\00", align 1 +@3 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@5 = private unnamed_addr constant [13 x i8] c"%lld%s%lld%s\00", align 1 +@6 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@7 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@8 = private unnamed_addr constant [9 x i8] c"%d%s%d%s\00", align 1 +@9 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1 +@10 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1 +@11 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@12 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@13 = private unnamed_addr constant [13 x i8] c"%lld%s%lld%s\00", align 1 + +define void @_lpython_main_program() { +.entry: + %0 = load void*, void** @queries, align 8 + %1 = alloca %array, align 8 + %2 = alloca %dimension_descriptor, align 8 + %3 = getelementptr %array, %array* %1, i32 0, i32 2 + store %dimension_descriptor* %2, %dimension_descriptor** %3, align 8 + %4 = getelementptr %array, %array* %1, i32 0, i32 4 + store i32 1, i32* %4, align 4 + store %array* %1, %array** @x, align 8 + %5 = getelementptr %array, %array* %1, i32 0, i32 0 + %6 = getelementptr %array, %array* %1, i32 0, i32 2 + %7 = load %dimension_descriptor*, %dimension_descriptor** %6, align 8 + %8 = bitcast void* %0 to i16* + store i16* %8, i16** %5, align 8 + %9 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %7, i32 0 + %10 = getelementptr %dimension_descriptor, %dimension_descriptor* %9, i32 0, i32 1 + %11 = getelementptr %dimension_descriptor, %dimension_descriptor* %9, i32 0, i32 2 + %12 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %7, i32 0 + %13 = getelementptr %dimension_descriptor, %dimension_descriptor* %12, i32 0, i32 3 + store i32 1, i32* %10, align 4 + store i32 1, i32* %11, align 4 + store i32 1, i32* %13, align 4 + %14 = load void*, void** @queries, align 8 + %15 = ptrtoint void* %14 to i64 + %16 = load %array*, %array** @x, align 8 + %17 = getelementptr %array, %array* %16, i32 0, i32 0 + %18 = load i16*, i16** %17, align 8 + %19 = ptrtoint i16* %18 to i64 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @2, i32 0, i32 0), i64 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i64 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) + call void @f() + br label %return + +return: ; preds = %.entry + ret void +} + +define void @f() { +.entry: + %y = alloca %array, align 8 + %0 = getelementptr %array, %array* %y, i32 0, i32 1 + store i32 0, i32* %0, align 4 + %1 = getelementptr %array, %array* %y, i32 0, i32 2 + %2 = alloca i32, align 4 + store i32 1, i32* %2, align 4 + %3 = load i32, i32* %2, align 4 + %4 = alloca %dimension_descriptor, i32 %3, align 8 + %5 = getelementptr %array, %array* %y, i32 0, i32 4 + store i32 1, i32* %5, align 4 + store %dimension_descriptor* %4, %dimension_descriptor** %1, align 8 + %6 = load %dimension_descriptor*, %dimension_descriptor** %1, align 8 + %7 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %6, i32 0 + %8 = getelementptr %dimension_descriptor, %dimension_descriptor* %7, i32 0, i32 0 + %9 = getelementptr %dimension_descriptor, %dimension_descriptor* %7, i32 0, i32 1 + %10 = getelementptr %dimension_descriptor, %dimension_descriptor* %7, i32 0, i32 2 + %11 = getelementptr %dimension_descriptor, %dimension_descriptor* %7, i32 0, i32 3 + store i32 1, i32* %8, align 4 + store i32 0, i32* %9, align 4 + store i32 1, i32* %10, align 4 + %12 = load i32, i32* %10, align 4 + %13 = load i32, i32* %9, align 4 + %14 = sub i32 %12, %13 + %15 = add i32 %14, 1 + store i32 %15, i32* %11, align 4 + %16 = alloca i32, align 4 + store i32 2, i32* %16, align 4 + %17 = getelementptr %array, %array* %y, i32 0, i32 0 + %18 = load i32, i32* %16, align 4 + %19 = alloca i16, i32 %18, align 2 + store i16* %19, i16** %17, align 8 + %yptr1 = alloca %array*, align 8 + %yq = alloca void*, align 8 + %20 = getelementptr %array, %array* %y, i32 0, i32 2 + %21 = load %dimension_descriptor*, %dimension_descriptor** %20, align 8 + %22 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %21, i32 0 + %23 = getelementptr %dimension_descriptor, %dimension_descriptor* %22, i32 0, i32 1 + %24 = load i32, i32* %23, align 4 + %25 = sub i32 0, %24 + %26 = mul i32 1, %25 + %27 = add i32 0, %26 + %28 = getelementptr %dimension_descriptor, %dimension_descriptor* %22, i32 0, i32 3 + %29 = load i32, i32* %28, align 4 + %30 = mul i32 1, %29 + %31 = getelementptr %array, %array* %y, i32 0, i32 0 + %32 = load i16*, i16** %31, align 8 + %33 = getelementptr inbounds i16, i16* %32, i32 %27 + store i16 1, i16* %33, align 2 + %34 = getelementptr %array, %array* %y, i32 0, i32 2 + %35 = load %dimension_descriptor*, %dimension_descriptor** %34, align 8 + %36 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %35, i32 0 + %37 = getelementptr %dimension_descriptor, %dimension_descriptor* %36, i32 0, i32 1 + %38 = load i32, i32* %37, align 4 + %39 = sub i32 1, %38 + %40 = mul i32 1, %39 + %41 = add i32 0, %40 + %42 = getelementptr %dimension_descriptor, %dimension_descriptor* %36, i32 0, i32 3 + %43 = load i32, i32* %42, align 4 + %44 = mul i32 1, %43 + %45 = getelementptr %array, %array* %y, i32 0, i32 0 + %46 = load i16*, i16** %45, align 8 + %47 = getelementptr inbounds i16, i16* %46, i32 %41 + store i16 2, i16* %47, align 2 + store %array* %y, %array** %yptr1, align 8 + %48 = getelementptr %array, %array* %y, i32 0, i32 0 + %49 = load i16*, i16** %48, align 8 + %50 = ptrtoint i16* %49 to i64 + %51 = load %array*, %array** %yptr1, align 8 + %52 = getelementptr %array, %array* %51, i32 0, i32 0 + %53 = load i16*, i16** %52, align 8 + %54 = ptrtoint i16* %53 to i64 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @5, i32 0, i32 0), i64 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @3, i32 0, i32 0), i64 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0)) + %55 = load %array*, %array** %yptr1, align 8 + %56 = getelementptr %array, %array* %55, i32 0, i32 2 + %57 = load %dimension_descriptor*, %dimension_descriptor** %56, align 8 + %58 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %57, i32 0 + %59 = getelementptr %dimension_descriptor, %dimension_descriptor* %58, i32 0, i32 1 + %60 = load i32, i32* %59, align 4 + %61 = sub i32 0, %60 + %62 = mul i32 1, %61 + %63 = add i32 0, %62 + %64 = getelementptr %dimension_descriptor, %dimension_descriptor* %58, i32 0, i32 3 + %65 = load i32, i32* %64, align 4 + %66 = mul i32 1, %65 + %67 = getelementptr %array, %array* %55, i32 0, i32 0 + %68 = load i16*, i16** %67, align 8 + %69 = getelementptr inbounds i16, i16* %68, i32 %63 + %70 = load i16, i16* %69, align 2 + %71 = load %array*, %array** %yptr1, align 8 + %72 = getelementptr %array, %array* %71, i32 0, i32 2 + %73 = load %dimension_descriptor*, %dimension_descriptor** %72, align 8 + %74 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %73, i32 0 + %75 = getelementptr %dimension_descriptor, %dimension_descriptor* %74, i32 0, i32 1 + %76 = load i32, i32* %75, align 4 + %77 = sub i32 1, %76 + %78 = mul i32 1, %77 + %79 = add i32 0, %78 + %80 = getelementptr %dimension_descriptor, %dimension_descriptor* %74, i32 0, i32 3 + %81 = load i32, i32* %80, align 4 + %82 = mul i32 1, %81 + %83 = getelementptr %array, %array* %71, i32 0, i32 0 + %84 = load i16*, i16** %83, align 8 + %85 = getelementptr inbounds i16, i16* %84, i32 %79 + %86 = load i16, i16* %85, align 2 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @8, i32 0, i32 0), i16 %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @6, i32 0, i32 0), i16 %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @7, i32 0, i32 0)) + %87 = load %array*, %array** %yptr1, align 8 + %88 = getelementptr %array, %array* %87, i32 0, i32 2 + %89 = load %dimension_descriptor*, %dimension_descriptor** %88, align 8 + %90 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %89, i32 0 + %91 = getelementptr %dimension_descriptor, %dimension_descriptor* %90, i32 0, i32 1 + %92 = load i32, i32* %91, align 4 + %93 = sub i32 0, %92 + %94 = mul i32 1, %93 + %95 = add i32 0, %94 + %96 = getelementptr %dimension_descriptor, %dimension_descriptor* %90, i32 0, i32 3 + %97 = load i32, i32* %96, align 4 + %98 = mul i32 1, %97 + %99 = getelementptr %array, %array* %87, i32 0, i32 0 + %100 = load i16*, i16** %99, align 8 + %101 = getelementptr inbounds i16, i16* %100, i32 %95 + %102 = load i16, i16* %101, align 2 + %103 = sext i16 %102 to i32 + %104 = icmp eq i32 %103, 1 + br i1 %104, label %then, label %else + +then: ; preds = %.entry + br label %ifcont + +else: ; preds = %.entry + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @9, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont + +ifcont: ; preds = %else, %then + %105 = load %array*, %array** %yptr1, align 8 + %106 = getelementptr %array, %array* %105, i32 0, i32 2 + %107 = load %dimension_descriptor*, %dimension_descriptor** %106, align 8 + %108 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %107, i32 0 + %109 = getelementptr %dimension_descriptor, %dimension_descriptor* %108, i32 0, i32 1 + %110 = load i32, i32* %109, align 4 + %111 = sub i32 1, %110 + %112 = mul i32 1, %111 + %113 = add i32 0, %112 + %114 = getelementptr %dimension_descriptor, %dimension_descriptor* %108, i32 0, i32 3 + %115 = load i32, i32* %114, align 4 + %116 = mul i32 1, %115 + %117 = getelementptr %array, %array* %105, i32 0, i32 0 + %118 = load i16*, i16** %117, align 8 + %119 = getelementptr inbounds i16, i16* %118, i32 %113 + %120 = load i16, i16* %119, align 2 + %121 = sext i16 %120 to i32 + %122 = icmp eq i32 %121, 2 + br i1 %122, label %then1, label %else2 + +then1: ; preds = %ifcont + br label %ifcont3 + +else2: ; preds = %ifcont + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @10, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont3 + +ifcont3: ; preds = %else2, %then1 + %123 = load void*, void** %yq, align 8 + %124 = alloca %array, align 8 + %125 = alloca %dimension_descriptor, align 8 + %126 = getelementptr %array, %array* %124, i32 0, i32 2 + store %dimension_descriptor* %125, %dimension_descriptor** %126, align 8 + %127 = getelementptr %array, %array* %124, i32 0, i32 4 + store i32 1, i32* %127, align 4 + store %array* %124, %array** %yptr1, align 8 + %128 = getelementptr %array, %array* %124, i32 0, i32 0 + %129 = getelementptr %array, %array* %124, i32 0, i32 2 + %130 = load %dimension_descriptor*, %dimension_descriptor** %129, align 8 + %131 = bitcast void* %123 to i16* + store i16* %131, i16** %128, align 8 + %132 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %130, i32 0 + %133 = getelementptr %dimension_descriptor, %dimension_descriptor* %132, i32 0, i32 1 + %134 = getelementptr %dimension_descriptor, %dimension_descriptor* %132, i32 0, i32 2 + %135 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %130, i32 0 + %136 = getelementptr %dimension_descriptor, %dimension_descriptor* %135, i32 0, i32 3 + store i32 1, i32* %133, align 4 + store i32 1, i32* %134, align 4 + store i32 1, i32* %136, align 4 + %137 = load void*, void** %yq, align 8 + %138 = ptrtoint void* %137 to i64 + %139 = load %array*, %array** %yptr1, align 8 + %140 = getelementptr %array, %array* %139, i32 0, i32 0 + %141 = load i16*, i16** %140, align 8 + %142 = ptrtoint i16* %141 to i64 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @13, i32 0, i32 0), i64 %138, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i64 %142, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @12, i32 0, i32 0)) + br label %return + +return: ; preds = %ifcont3 + ret void +} + +declare void @_lfortran_printf(i8*, ...) + +declare void @exit(i32) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} diff --git a/tests/reference/llvm-bool1-af4376b.json b/tests/reference/llvm-bool1-af4376b.json new file mode 100644 index 0000000000..ccaae202bd --- /dev/null +++ b/tests/reference/llvm-bool1-af4376b.json @@ -0,0 +1,13 @@ +{ + "basename": "llvm-bool1-af4376b", + "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", + "infile": "tests/bool1.py", + "infile_hash": "f61ed4d1f164753f9f78f63957d4faf040bcd6099e18dbf3e32cf7d5", + "outfile": null, + "outfile_hash": null, + "stdout": "llvm-bool1-af4376b.stdout", + "stdout_hash": "f579a7f973274a27f1542754a2b97a39c3df969d1f8e2330dfa786fe", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/llvm-bool1-af4376b.stdout b/tests/reference/llvm-bool1-af4376b.stdout new file mode 100644 index 0000000000..bb3c1becdf --- /dev/null +++ b/tests/reference/llvm-bool1-af4376b.stdout @@ -0,0 +1,65 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +@0 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@2 = private unnamed_addr constant [6 x i8] c"False\00", align 1 +@3 = private unnamed_addr constant [5 x i8] c"True\00", align 1 +@4 = private unnamed_addr constant [3 x i8] c"%s\00", align 1 +@5 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@6 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@7 = private unnamed_addr constant [6 x i8] c"False\00", align 1 +@8 = private unnamed_addr constant [5 x i8] c"True\00", align 1 +@9 = private unnamed_addr constant [3 x i8] c"%s\00", align 1 +@10 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@11 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@12 = private unnamed_addr constant [6 x i8] c"False\00", align 1 +@13 = private unnamed_addr constant [5 x i8] c"True\00", align 1 +@14 = private unnamed_addr constant [3 x i8] c"%s\00", align 1 +@15 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@16 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@17 = private unnamed_addr constant [6 x i8] c"False\00", align 1 +@18 = private unnamed_addr constant [5 x i8] c"True\00", align 1 +@19 = private unnamed_addr constant [3 x i8] c"%s\00", align 1 + +define void @_lpython_main_program() { +.entry: + call void @test_bool() + br label %return + +return: ; preds = %.entry + ret void +} + +define void @test_bool() { +.entry: + %b = alloca i1, align 1 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0)) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @4, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @7, i32 0, i32 0)) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @9, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @6, i32 0, i32 0)) + store i1 true, i1* %b, align 1 + %0 = load i1, i1* %b, align 1 + %1 = icmp eq i1 %0, false + %2 = select i1 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0) + call void (i8*, ...) @_lfortran_printf(i8* %2) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0)) + store i1 false, i1* %b, align 1 + %3 = load i1, i1* %b, align 1 + %4 = icmp eq i1 %3, false + %5 = select i1 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @18, i32 0, i32 0) + call void (i8*, ...) @_lfortran_printf(i8* %5) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @19, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @16, i32 0, i32 0)) + br label %return + +return: ; preds = %.entry + ret void +} + +declare void @_lfortran_printf(i8*, ...) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} diff --git a/tests/reference/llvm-expr_01-54467c1.json b/tests/reference/llvm-expr_01-54467c1.json index 00f2d43b0b..68d52dc622 100644 --- a/tests/reference/llvm-expr_01-54467c1.json +++ b/tests/reference/llvm-expr_01-54467c1.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-expr_01-54467c1.stdout", - "stdout_hash": "ba29f58d066d6e384585dde2c649ca46e1d0f5ad695795295d6d9b89", + "stdout_hash": "c01080bd1ef6708b8825ac43ce1cc8f69a8ff97eaf734325fb989516", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-expr_01-54467c1.stdout b/tests/reference/llvm-expr_01-54467c1.stdout index 654f94bac3..d31f31102e 100644 --- a/tests/reference/llvm-expr_01-54467c1.stdout +++ b/tests/reference/llvm-expr_01-54467c1.stdout @@ -1,7 +1,9 @@ ; ModuleID = 'LFortran' source_filename = "LFortran" -@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 +@0 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@2 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1 define void @_lpython_main_program() { .entry: @@ -20,7 +22,7 @@ define void @main0() { %y2 = alloca double, align 8 store i32 25, i32* %x, align 4 %0 = load i32, i32* %x, align 4 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @0, i32 0, i32 0), i32 %0) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) br label %return return: ; preds = %.entry diff --git a/tests/reference/llvm-func_inline_01-2d4583a.json b/tests/reference/llvm-func_inline_01-2d4583a.json new file mode 100644 index 0000000000..90a44508ad --- /dev/null +++ b/tests/reference/llvm-func_inline_01-2d4583a.json @@ -0,0 +1,13 @@ +{ + "basename": "llvm-func_inline_01-2d4583a", + "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", + "infile": "tests/../integration_tests/func_inline_01.py", + "infile_hash": "6875179ba40c59c22fc55606261bf2c84290b50932f956c1d8152502", + "outfile": null, + "outfile_hash": null, + "stdout": "llvm-func_inline_01-2d4583a.stdout", + "stdout_hash": "6608b20c9bf6c3efaabc8ac99a8323e2301bc71ba121395a6cfad326", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/llvm-func_inline_01-2d4583a.stdout b/tests/reference/llvm-func_inline_01-2d4583a.stdout new file mode 100644 index 0000000000..140821ffe8 --- /dev/null +++ b/tests/reference/llvm-func_inline_01-2d4583a.stdout @@ -0,0 +1,95 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +@0 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@2 = private unnamed_addr constant [7 x i8] c"%lld%s\00", align 1 +@3 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1 + +define void @_lpython_main_program() { +.entry: + call void @_xx_lcompilers_changed_main_xx() + br label %return + +return: ; preds = %.entry + ret void +} + +define i64 @fib(i64* %n) { +.entry: + %call_arg_value1 = alloca i64, align 8 + %call_arg_value = alloca i64, align 8 + %_lpython_return_variable = alloca i64, align 8 + %0 = load i64, i64* %n, align 4 + %1 = icmp slt i64 %0, 2 + br i1 %1, label %then, label %else + +then: ; preds = %.entry + %2 = load i64, i64* %n, align 4 + store i64 %2, i64* %_lpython_return_variable, align 4 + br label %return + +unreachable_after_return: ; No predecessors! + br label %ifcont + +else: ; preds = %.entry + br label %ifcont + +ifcont: ; preds = %else, %unreachable_after_return + %3 = load i64, i64* %n, align 4 + %4 = sub i64 %3, 1 + store i64 %4, i64* %call_arg_value, align 4 + %5 = call i64 @fib(i64* %call_arg_value) + %6 = load i64, i64* %n, align 4 + %7 = sub i64 %6, 2 + store i64 %7, i64* %call_arg_value1, align 4 + %8 = call i64 @fib(i64* %call_arg_value1) + %9 = add i64 %5, %8 + store i64 %9, i64* %_lpython_return_variable, align 4 + br label %return + +unreachable_after_return2: ; No predecessors! + br label %return + +return: ; preds = %unreachable_after_return2, %ifcont, %then + %10 = load i64, i64* %_lpython_return_variable, align 4 + ret i64 %10 +} + +define void @_xx_lcompilers_changed_main_xx() { +.entry: + %ans = alloca i64, align 8 + %x = alloca i64, align 8 + store i64 40, i64* %x, align 4 + %0 = call i64 @fib(i64* %x) + store i64 %0, i64* %ans, align 4 + %1 = load i64, i64* %ans, align 4 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @2, i32 0, i32 0), i64 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) + %2 = load i64, i64* %ans, align 4 + %3 = icmp eq i64 %2, 102334155 + br i1 %3, label %then, label %else + +then: ; preds = %.entry + br label %ifcont + +else: ; preds = %.entry + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @3, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont + +ifcont: ; preds = %else, %then + br label %return + +return: ; preds = %ifcont + ret void +} + +declare void @_lfortran_printf(i8*, ...) + +declare void @exit(i32) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} diff --git a/tests/reference/llvm-ltypes-1402bca.json b/tests/reference/llvm-ltypes1-dacf939.json similarity index 56% rename from tests/reference/llvm-ltypes-1402bca.json rename to tests/reference/llvm-ltypes1-dacf939.json index 4b650bd5fb..3e4b868ae4 100644 --- a/tests/reference/llvm-ltypes-1402bca.json +++ b/tests/reference/llvm-ltypes1-dacf939.json @@ -1,12 +1,12 @@ { - "basename": "llvm-ltypes-1402bca", + "basename": "llvm-ltypes1-dacf939", "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", - "infile": "tests/ltypes.py", + "infile": "tests/ltypes1.py", "infile_hash": "daac081f5e376233adabe24304126763178cfd3a6286c361b7955446", "outfile": null, "outfile_hash": null, - "stdout": "llvm-ltypes-1402bca.stdout", - "stdout_hash": "cafb6dc418ad5ddc1ef709741df5c2ee0a45fcdee41b49c50f121ffb", + "stdout": "llvm-ltypes1-dacf939.stdout", + "stdout_hash": "6bf240f208e3d2f3c9f0e5173b2b431f84123e56a293373b7327d7af", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-ltypes-1402bca.stdout b/tests/reference/llvm-ltypes1-dacf939.stdout similarity index 51% rename from tests/reference/llvm-ltypes-1402bca.stdout rename to tests/reference/llvm-ltypes1-dacf939.stdout index 0478da1b47..387f8bf401 100644 --- a/tests/reference/llvm-ltypes-1402bca.stdout +++ b/tests/reference/llvm-ltypes1-dacf939.stdout @@ -1,17 +1,25 @@ ; ModuleID = 'LFortran' source_filename = "LFortran" -@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 -@1 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 -@2 = private unnamed_addr constant [6 x i8] c"%lld\0A\00", align 1 -@3 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 +@0 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@2 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1 +@3 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@5 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1 +@6 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@7 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@8 = private unnamed_addr constant [7 x i8] c"%lld%s\00", align 1 +@9 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@10 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@11 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1 define void @test_i16() { .entry: %i = alloca i16, align 2 store i16 4, i16* %i, align 2 %0 = load i16, i16* %i, align 2 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @0, i32 0, i32 0), i16 %0) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i16 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) br label %return return: ; preds = %.entry @@ -23,7 +31,7 @@ define void @test_i32() { %i = alloca i32, align 4 store i32 3, i32* %i, align 4 %0 = load i32, i32* %i, align 4 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @1, i32 0, i32 0), i32 %0) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0)) br label %return return: ; preds = %.entry @@ -35,7 +43,7 @@ define void @test_i64() { %i = alloca i64, align 8 store i64 2, i64* %i, align 4 %0 = load i64, i64* %i, align 4 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @2, i32 0, i32 0), i64 %0) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @8, i32 0, i32 0), i64 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @7, i32 0, i32 0)) br label %return return: ; preds = %.entry @@ -47,7 +55,7 @@ define void @test_i8() { %i = alloca i8, align 1 store i8 5, i8* %i, align 1 %0 = load i8, i8* %i, align 1 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @3, i32 0, i32 0), i8 %0) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @10, i32 0, i32 0)) br label %return return: ; preds = %.entry diff --git a/tests/reference/llvm-test_integer_bitnot-6894b6d.json b/tests/reference/llvm-test_integer_bitnot-6894b6d.json new file mode 100644 index 0000000000..d68fe0a2a3 --- /dev/null +++ b/tests/reference/llvm-test_integer_bitnot-6894b6d.json @@ -0,0 +1,13 @@ +{ + "basename": "llvm-test_integer_bitnot-6894b6d", + "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_integer_bitnot.py", + "infile_hash": "dc976a358fbeebedead889f8e85b3eed4ac77ee20f68fcac58b81429", + "outfile": null, + "outfile_hash": null, + "stdout": "llvm-test_integer_bitnot-6894b6d.stdout", + "stdout_hash": "84524ea0d4e9137edf9f74b0d00095eadbd805b45a632882f646f330", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/llvm-test_integer_bitnot-6894b6d.stdout b/tests/reference/llvm-test_integer_bitnot-6894b6d.stdout new file mode 100644 index 0000000000..a8e86ed161 --- /dev/null +++ b/tests/reference/llvm-test_integer_bitnot-6894b6d.stdout @@ -0,0 +1,66 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +@0 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1 +@1 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1 + +define void @_lpython_main_program() { +.entry: + call void @f() + br label %return + +return: ; preds = %.entry + ret void +} + +define void @f() { +.entry: + %i = alloca i32, align 4 + %res = alloca i32, align 4 + store i32 5, i32* %i, align 4 + %0 = load i32, i32* %i, align 4 + %1 = xor i32 %0, -1 + store i32 %1, i32* %res, align 4 + %2 = load i32, i32* %res, align 4 + %3 = icmp eq i32 %2, -6 + br i1 %3, label %then, label %else + +then: ; preds = %.entry + br label %ifcont + +else: ; preds = %.entry + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @0, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont + +ifcont: ; preds = %else, %then + store i32 -235346, i32* %i, align 4 + %4 = load i32, i32* %i, align 4 + %5 = xor i32 %4, -1 + %6 = icmp eq i32 %5, 235345 + br i1 %6, label %then1, label %else2 + +then1: ; preds = %ifcont + br label %ifcont3 + +else2: ; preds = %ifcont + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @1, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont3 + +ifcont3: ; preds = %else2, %then1 + br label %return + +return: ; preds = %ifcont3 + ret void +} + +declare void @_lfortran_printf(i8*, ...) + +declare void @exit(i32) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} diff --git a/tests/reference/llvm-test_issue_518-cdb641a.json b/tests/reference/llvm-test_issue_518-cdb641a.json new file mode 100644 index 0000000000..dbc8730a65 --- /dev/null +++ b/tests/reference/llvm-test_issue_518-cdb641a.json @@ -0,0 +1,13 @@ +{ + "basename": "llvm-test_issue_518-cdb641a", + "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_issue_518.py", + "infile_hash": "20feb83ffed2a8042d4d41968c7efee5d0a57a2d1c8223fac81f3311", + "outfile": null, + "outfile_hash": null, + "stdout": "llvm-test_issue_518-cdb641a.stdout", + "stdout_hash": "7f041badffb53daaccccfa32e9ad66b4a10e7ffb7bfa583b0cb8b6c8", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/llvm-test_issue_518-cdb641a.stdout b/tests/reference/llvm-test_issue_518-cdb641a.stdout new file mode 100644 index 0000000000..c3f68fdafc --- /dev/null +++ b/tests/reference/llvm-test_issue_518-cdb641a.stdout @@ -0,0 +1,118 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +@0 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1 +@1 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1 + +define void @_lpython_main_program() { +.entry: + call void @main0() + call void @_xx_lcompilers_changed_main_xx() + br label %return + +return: ; preds = %.entry + ret void +} + +define i64 @fib(i64* %n) { +.entry: + %call_arg_value1 = alloca i64, align 8 + %call_arg_value = alloca i64, align 8 + %_lpython_return_variable = alloca i64, align 8 + %0 = load i64, i64* %n, align 4 + %1 = icmp slt i64 %0, 2 + br i1 %1, label %then, label %else + +then: ; preds = %.entry + %2 = load i64, i64* %n, align 4 + store i64 %2, i64* %_lpython_return_variable, align 4 + br label %return + +unreachable_after_return: ; No predecessors! + br label %ifcont + +else: ; preds = %.entry + %3 = load i64, i64* %n, align 4 + %4 = sub i64 %3, 1 + store i64 %4, i64* %call_arg_value, align 4 + %5 = call i64 @fib(i64* %call_arg_value) + %6 = load i64, i64* %n, align 4 + %7 = sub i64 %6, 2 + store i64 %7, i64* %call_arg_value1, align 4 + %8 = call i64 @fib(i64* %call_arg_value1) + %9 = add i64 %5, %8 + store i64 %9, i64* %_lpython_return_variable, align 4 + br label %return + +unreachable_after_return2: ; No predecessors! + br label %ifcont + +ifcont: ; preds = %unreachable_after_return2, %unreachable_after_return + br label %return + +return: ; preds = %ifcont, %else, %then + %10 = load i64, i64* %_lpython_return_variable, align 4 + ret i64 %10 +} + +define void @_xx_lcompilers_changed_main_xx() { +.entry: + %call_arg_value = alloca i64, align 8 + %ans = alloca i64, align 8 + store i64 10, i64* %call_arg_value, align 4 + %0 = call i64 @fib(i64* %call_arg_value) + store i64 %0, i64* %ans, align 4 + %1 = load i64, i64* %ans, align 4 + %2 = icmp eq i64 %1, 55 + br i1 %2, label %then, label %else + +then: ; preds = %.entry + br label %ifcont + +else: ; preds = %.entry + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @0, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont + +ifcont: ; preds = %else, %then + br label %return + +return: ; preds = %ifcont + ret void +} + +define void @main0() { +.entry: + %call_arg_value = alloca i64, align 8 + %ans = alloca i64, align 8 + store i64 15, i64* %call_arg_value, align 4 + %0 = call i64 @fib(i64* %call_arg_value) + store i64 %0, i64* %ans, align 4 + %1 = load i64, i64* %ans, align 4 + %2 = icmp eq i64 %1, 610 + br i1 %2, label %then, label %else + +then: ; preds = %.entry + br label %ifcont + +else: ; preds = %.entry + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @1, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont + +ifcont: ; preds = %else, %then + br label %return + +return: ; preds = %ifcont + ret void +} + +declare void @_lfortran_printf(i8*, ...) + +declare void @exit(i32) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} diff --git a/tests/reference/pass_inline_function_calls-func_inline_01-8b6a5da.json b/tests/reference/pass_inline_function_calls-func_inline_01-8b6a5da.json new file mode 100644 index 0000000000..472290de5a --- /dev/null +++ b/tests/reference/pass_inline_function_calls-func_inline_01-8b6a5da.json @@ -0,0 +1,13 @@ +{ + "basename": "pass_inline_function_calls-func_inline_01-8b6a5da", + "cmd": "lpython --pass=inline_function_calls --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/func_inline_01.py", + "infile_hash": "6875179ba40c59c22fc55606261bf2c84290b50932f956c1d8152502", + "outfile": null, + "outfile_hash": null, + "stdout": "pass_inline_function_calls-func_inline_01-8b6a5da.stdout", + "stdout_hash": "1fa7ebfa4fb68b73aebf58df8245bfe2e3b26faade55b0baaffa285e", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/pass_inline_function_calls-func_inline_01-8b6a5da.stdout b/tests/reference/pass_inline_function_calls-func_inline_01-8b6a5da.stdout new file mode 100644 index 0000000000..28c4615b5d --- /dev/null +++ b/tests/reference/pass_inline_function_calls-func_inline_01-8b6a5da.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 5 {}) _lpython_main_program [] [(SubroutineCall 1 main () [] ())] Source Public Implementation () .false. .false.), fib: (Function (SymbolTable 2 {_lpython_return_variable: (Variable 2 _lpython_return_variable ReturnVar () () Default (Integer 8 []) Source Public Required .false.), n: (Variable 2 n In () () Default (Integer 8 []) Source Public Required .false.)}) fib [(Var 2 n)] [(If (IntegerCompare (Var 2 n) Lt (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) [(= (Var 2 _lpython_return_variable) (Var 2 n) ()) (Return)] []) (= (Var 2 _lpython_return_variable) (IntegerBinOp (FunctionCall 1 fib () [((IntegerBinOp (Var 2 n) Sub (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) ()))] (Integer 8 []) () ()) Add (FunctionCall 1 fib () [((IntegerBinOp (Var 2 n) Sub (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) ()))] (Integer 8 []) () ()) (Integer 8 []) ()) ()) (Return)] (Var 2 _lpython_return_variable) Source Public Implementation ()), main: (Subroutine (SymbolTable 3 {_lpython_return_variable_fib: (Variable 3 _lpython_return_variable_fib Local () () Default (Integer 8 []) Source Public Required .false.), ans: (Variable 3 ans Local () () Default (Integer 8 []) Source Public Required .false.), n_fib: (Variable 3 n_fib Local () () Default (Integer 8 []) Source Public Required .false.), x: (Variable 3 x Local () () Default (Integer 8 []) Source Public Required .false.), ~empty_block: (Block (SymbolTable 6 {}) ~empty_block [])}) main [] [(= (Var 3 x) (Cast (IntegerConstant 40 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) ()) (= (Var 3 n_fib) (Var 3 x) ()) (If (IntegerCompare (Var 3 n_fib) Lt (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) [(= (Var 3 _lpython_return_variable_fib) (Var 3 n_fib) ()) (GoTo 1)] []) (= (Var 3 _lpython_return_variable_fib) (IntegerBinOp (FunctionCall 1 fib () [((IntegerBinOp (Var 3 n_fib) Sub (Cast (IntegerConstant 1 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) ()))] (Integer 8 []) () ()) Add (FunctionCall 1 fib () [((IntegerBinOp (Var 3 n_fib) Sub (Cast (IntegerConstant 2 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Integer 8 []) ()))] (Integer 8 []) () ()) (Integer 8 []) ()) ()) (GoTo 1) (BlockCall 1 3 ~empty_block) (= (Var 3 ans) (Var 3 _lpython_return_variable_fib) ()) (Print () [(Var 3 ans)] () ()) (Assert (IntegerCompare (Var 3 ans) Eq (Cast (IntegerConstant 102334155 (Integer 4 [])) IntegerToInteger (Integer 8 []) ()) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 4 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/pass_llvm_inline_function_calls-func_inline_01-4c2cde7.json b/tests/reference/pass_llvm_inline_function_calls-func_inline_01-4c2cde7.json new file mode 100644 index 0000000000..a37291deb2 --- /dev/null +++ b/tests/reference/pass_llvm_inline_function_calls-func_inline_01-4c2cde7.json @@ -0,0 +1,13 @@ +{ + "basename": "pass_llvm_inline_function_calls-func_inline_01-4c2cde7", + "cmd": "lpython --pass=inline_function_calls --show-llvm --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/func_inline_01.py", + "infile_hash": "6875179ba40c59c22fc55606261bf2c84290b50932f956c1d8152502", + "outfile": null, + "outfile_hash": null, + "stdout": "pass_llvm_inline_function_calls-func_inline_01-4c2cde7.stdout", + "stdout_hash": "d51fce03f9516966aa60a83502d588d5cdabaa343d6e6d03e193260e", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/pass_llvm_inline_function_calls-func_inline_01-4c2cde7.stdout b/tests/reference/pass_llvm_inline_function_calls-func_inline_01-4c2cde7.stdout new file mode 100644 index 0000000000..504f2953da --- /dev/null +++ b/tests/reference/pass_llvm_inline_function_calls-func_inline_01-4c2cde7.stdout @@ -0,0 +1,133 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +@0 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@2 = private unnamed_addr constant [7 x i8] c"%lld%s\00", align 1 +@3 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1 + +define void @_lpython_main_program() { +.entry: + call void @_xx_lcompilers_changed_main_xx() + br label %return + +return: ; preds = %.entry + ret void +} + +define i64 @fib(i64* %n) { +.entry: + %call_arg_value1 = alloca i64, align 8 + %call_arg_value = alloca i64, align 8 + %_lpython_return_variable = alloca i64, align 8 + %0 = load i64, i64* %n, align 4 + %1 = icmp slt i64 %0, 2 + br i1 %1, label %then, label %else + +then: ; preds = %.entry + %2 = load i64, i64* %n, align 4 + store i64 %2, i64* %_lpython_return_variable, align 4 + br label %return + +unreachable_after_return: ; No predecessors! + br label %ifcont + +else: ; preds = %.entry + br label %ifcont + +ifcont: ; preds = %else, %unreachable_after_return + %3 = load i64, i64* %n, align 4 + %4 = sub i64 %3, 1 + store i64 %4, i64* %call_arg_value, align 4 + %5 = call i64 @fib(i64* %call_arg_value) + %6 = load i64, i64* %n, align 4 + %7 = sub i64 %6, 2 + store i64 %7, i64* %call_arg_value1, align 4 + %8 = call i64 @fib(i64* %call_arg_value1) + %9 = add i64 %5, %8 + store i64 %9, i64* %_lpython_return_variable, align 4 + br label %return + +unreachable_after_return2: ; No predecessors! + br label %return + +return: ; preds = %unreachable_after_return2, %ifcont, %then + %10 = load i64, i64* %_lpython_return_variable, align 4 + ret i64 %10 +} + +define void @_xx_lcompilers_changed_main_xx() { +.entry: + %call_arg_value1 = alloca i64, align 8 + %call_arg_value = alloca i64, align 8 + %_lpython_return_variable_fib = alloca i64, align 8 + %ans = alloca i64, align 8 + %n_fib = alloca i64, align 8 + %x = alloca i64, align 8 + store i64 40, i64* %x, align 4 + %0 = load i64, i64* %x, align 4 + store i64 %0, i64* %n_fib, align 4 + %1 = load i64, i64* %n_fib, align 4 + %2 = icmp slt i64 %1, 2 + br i1 %2, label %then, label %else + +then: ; preds = %.entry + %3 = load i64, i64* %n_fib, align 4 + store i64 %3, i64* %_lpython_return_variable_fib, align 4 + br label %goto_target + +unreachable_after_goto: ; No predecessors! + br label %ifcont + +else: ; preds = %.entry + br label %ifcont + +ifcont: ; preds = %else, %unreachable_after_goto + %4 = load i64, i64* %n_fib, align 4 + %5 = sub i64 %4, 1 + store i64 %5, i64* %call_arg_value, align 4 + %6 = call i64 @fib(i64* %call_arg_value) + %7 = load i64, i64* %n_fib, align 4 + %8 = sub i64 %7, 2 + store i64 %8, i64* %call_arg_value1, align 4 + %9 = call i64 @fib(i64* %call_arg_value1) + %10 = add i64 %6, %9 + store i64 %10, i64* %_lpython_return_variable_fib, align 4 + br label %goto_target + +unreachable_after_goto2: ; No predecessors! + br label %goto_target + +goto_target: ; preds = %unreachable_after_goto2, %ifcont, %then + %11 = load i64, i64* %_lpython_return_variable_fib, align 4 + store i64 %11, i64* %ans, align 4 + %12 = load i64, i64* %ans, align 4 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @2, i32 0, i32 0), i64 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) + %13 = load i64, i64* %ans, align 4 + %14 = icmp eq i64 %13, 102334155 + br i1 %14, label %then3, label %else4 + +then3: ; preds = %goto_target + br label %ifcont5 + +else4: ; preds = %goto_target + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @3, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont5 + +ifcont5: ; preds = %else4, %then3 + br label %return + +return: ; preds = %ifcont5 + ret void +} + +declare void @_lfortran_printf(i8*, ...) + +declare void @exit(i32) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} diff --git a/tests/reference/pass_loop_vectorise-vec_01-be9985e.json b/tests/reference/pass_loop_vectorise-vec_01-be9985e.json new file mode 100644 index 0000000000..67d2ee2eeb --- /dev/null +++ b/tests/reference/pass_loop_vectorise-vec_01-be9985e.json @@ -0,0 +1,13 @@ +{ + "basename": "pass_loop_vectorise-vec_01-be9985e", + "cmd": "lpython --pass=loop_vectorise --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/vec_01.py", + "infile_hash": "eb012561316a4c1f1359bf7b5a0b9aee40944ece197a5bafd387a19f", + "outfile": null, + "outfile_hash": null, + "stdout": "pass_loop_vectorise-vec_01-be9985e.stdout", + "stdout_hash": "3a50b4505e1f92221266ab1c9db37d6638dd13b508664332afdf22a5", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/pass_loop_vectorise-vec_01-be9985e.stdout b/tests/reference/pass_loop_vectorise-vec_01-be9985e.stdout new file mode 100644 index 0000000000..3fb5b2a916 --- /dev/null +++ b/tests/reference/pass_loop_vectorise-vec_01-be9985e.stdout @@ -0,0 +1 @@ +(TranslationUnit (SymbolTable 1 {_lpython_main_program: (Subroutine (SymbolTable 4 {}) _lpython_main_program [] [(SubroutineCall 1 loop_vec () [] ())] Source Public Implementation () .false. .false.), loop_vec: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))))]) Source Public Required .false.), b: (Variable 2 b Local () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))))]) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), vector_copy_f64f64i32@IntrinsicOptimization: (Subroutine (SymbolTable 5 {1_k: (Variable 5 1_k Local () () Default (Integer 4 []) Source Public Required .false.), arg0: (Variable 5 arg0 In () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))))]) Source Public Required .false.), arg1: (Variable 5 arg1 In () () Default (Real 8 [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))))]) Source Public Required .false.), arg2: (Variable 5 arg2 In () () Default (Integer 4 []) Source Public Required .false.), arg3: (Variable 5 arg3 In () () Default (Integer 4 []) Source Public Required .false.), arg4: (Variable 5 arg4 In () () Default (Integer 4 []) Source Public Required .false.), arg5: (Variable 5 arg5 In () () Default (Integer 4 []) Source Public Required .false.)}) vector_copy_f64f64i32@IntrinsicOptimization [(Var 5 arg0) (Var 5 arg1) (Var 5 arg2) (Var 5 arg3) (Var 5 arg4) (Var 5 arg5)] [(= (Var 5 1_k) (IntegerBinOp (Var 5 arg2) Sub (Var 5 arg4) (Integer 4 []) ()) ()) (WhileLoop (IntegerCompare (IntegerBinOp (Var 5 1_k) Add (Var 5 arg4) (Integer 4 []) ()) Lt (Var 5 arg3) (Integer 4 []) ()) [(= (Var 5 1_k) (IntegerBinOp (Var 5 1_k) Add (Var 5 arg4) (Integer 4 []) ()) ()) (= (ArrayItem (Var 5 arg0) [(() (Var 5 1_k) ())] (Real 8 []) ()) (ArrayItem (Var 5 arg1) [(() (Var 5 1_k) ())] (Real 8 []) ()) ())])] Source Public Implementation () .false. .false.)}) loop_vec [] [(DoLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))) (IntegerConstant 1 (Integer 4 []))) [(= (ArrayItem (Var 2 b) [(() (Var 2 i) ())] (Real 8 []) ()) (RealConstant 5.00000000000000000e+00 (Real 8 [])) ())]) (DoLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (IntegerConstant 1151 (Integer 4 [])) (IntegerConstant 1 (Integer 4 []))) [(SubroutineCall 2 vector_copy_f64f64i32@IntrinsicOptimization () [((Var 2 a)) ((Var 2 b)) ((IntegerBinOp (Var 2 i) Mul (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) ())) ((IntegerBinOp (IntegerBinOp (Var 2 i) Add (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) ()) Mul (IntegerConstant 8 (Integer 4 [])) (Integer 4 []) ())) ((IntegerConstant 1 (Integer 4 []))) ((IntegerConstant 8 (Integer 4 [])))] ())]) (DoLoop ((Var 2 i) (IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 9216 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 9215 (Integer 4 []))) (IntegerConstant 1 (Integer 4 []))) [(Assert (RealCompare (ArrayItem (Var 2 a) [(() (Var 2 i) ())] (Real 8 []) ()) Eq (RealConstant 5.00000000000000000e+00 (Real 8 [])) (Logical 4 []) ()) ())])] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())])}) []) diff --git a/tests/reference/tokens-comment1-2f8ab90.json b/tests/reference/tokens-comment1-2f8ab90.json index ed57771f94..cea27f0740 100644 --- a/tests/reference/tokens-comment1-2f8ab90.json +++ b/tests/reference/tokens-comment1-2f8ab90.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "tokens-comment1-2f8ab90.stdout", - "stdout_hash": "1dd4691dd42cfd3ed3e6c7bfb783aa2b0977cf977bd68729f5264224", + "stdout_hash": "9e9a900b941381aadb0d8f29662fa337e918a769daba0c019d7ccdee", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/tokens-comment1-2f8ab90.stdout b/tests/reference/tokens-comment1-2f8ab90.stdout index e464770451..778edf2ad2 100644 --- a/tests/reference/tokens-comment1-2f8ab90.stdout +++ b/tests/reference/tokens-comment1-2f8ab90.stdout @@ -1,25 +1,34 @@ -(TOKEN "eolcomment") 0:10 +(TOKEN "comment") 0:9 +(NEWLINE) 10:10 (KEYWORD "def") 11:13 (TOKEN "identifier" test) 15:18 (TOKEN "(") 19:19 (TOKEN ")") 20:20 (TOKEN ":") 21:21 -(TOKEN "eolcomment") 23:34 -(TOKEN "comment") 39:50 +(TOKEN "eolcomment") 23:33 +(NEWLINE) 34:34 +(TOKEN "comment") 39:49 +(NEWLINE) 50:50 (TOKEN "indent") 51:54 (TOKEN "identifier" print) 55:59 (TOKEN "(") 60:60 (TOKEN ")") 61:61 (NEWLINE) 62:62 -(TOKEN "dedent") 62:62 -(TOKEN "comment") 63:74 +(TOKEN "comment") 63:73 +(NEWLINE) 74:74 +(TOKEN "dedent") 74:74 (TOKEN "identifier" test) 75:78 (TOKEN "(") 79:79 (TOKEN ")") 80:80 -(TOKEN "eolcomment") 82:93 -(TOKEN "comment") 94:105 +(TOKEN "eolcomment") 82:92 +(NEWLINE) 93:93 +(TOKEN "comment") 94:104 +(NEWLINE) 105:105 (NEWLINE) 106:106 -(TOKEN "comment") 107:110 -(TOKEN "comment") 111:123 -(TOKEN "comment") 124:134 +(TOKEN "comment") 107:109 +(NEWLINE) 110:110 +(TOKEN "comment") 111:122 +(NEWLINE) 123:123 +(TOKEN "comment") 124:133 +(NEWLINE) 134:134 (EOF) 135:135 diff --git a/tests/reference/tokens-comment2-b289dad.json b/tests/reference/tokens-comment2-b289dad.json new file mode 100644 index 0000000000..3f735118dc --- /dev/null +++ b/tests/reference/tokens-comment2-b289dad.json @@ -0,0 +1,13 @@ +{ + "basename": "tokens-comment2-b289dad", + "cmd": "lpython --no-color --show-tokens {infile} -o {outfile}", + "infile": "tests/tokens/comment2.py", + "infile_hash": "8bbf936b113be965ec25f99d010959c3d6551e0271fa70c76cff1693", + "outfile": null, + "outfile_hash": null, + "stdout": "tokens-comment2-b289dad.stdout", + "stdout_hash": "69a0edcb42300fd719c704671b6aa3f815691c7af05048cba629b84c", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/tokens-comment2-b289dad.stdout b/tests/reference/tokens-comment2-b289dad.stdout new file mode 100644 index 0000000000..e43272f8a9 --- /dev/null +++ b/tests/reference/tokens-comment2-b289dad.stdout @@ -0,0 +1,125 @@ +(KEYWORD "def") 0:2 +(TOKEN "identifier" main) 4:7 +(TOKEN "(") 8:8 +(TOKEN ")") 9:9 +(TOKEN ":") 10:10 +(NEWLINE) 11:11 +(TOKEN "comment") 12:14 +(NEWLINE) 15:15 +(TOKEN "comment") 20:22 +(NEWLINE) 23:23 +(TOKEN "indent") 24:27 +(KEYWORD "if") 28:29 +(TOKEN "identifier" foo) 31:33 +(TOKEN ":") 34:34 +(TOKEN "eolcomment") 36:38 +(NEWLINE) 39:39 +(TOKEN "comment") 48:50 +(NEWLINE) 51:51 +(TOKEN "comment") 56:58 +(NEWLINE) 59:59 +(TOKEN "comment") 60:61 +(NEWLINE) 62:62 +(TOKEN "indent") 63:70 +(KEYWORD "if") 71:72 +(TOKEN "identifier" bar) 74:76 +(TOKEN ":") 77:77 +(TOKEN "eolcomment") 79:81 +(NEWLINE) 82:82 +(TOKEN "indent") 83:94 +(KEYWORD "pass") 95:98 +(NEWLINE) 99:99 +(TOKEN "dedent") 100:103 +(TOKEN "dedent") 103:103 +(KEYWORD "else") 104:107 +(TOKEN ":") 108:108 +(NEWLINE) 109:109 +(TOKEN "indent") 110:117 +(KEYWORD "pass") 118:121 +(NEWLINE) 122:122 +(TOKEN "dedent") 123:126 +(KEYWORD "return") 127:132 +(NEWLINE) 133:133 +(NEWLINE) 134:134 +(TOKEN "dedent") 134:134 +(KEYWORD "def") 135:137 +(TOKEN "identifier" test) 139:142 +(TOKEN "(") 143:143 +(TOKEN ")") 144:144 +(TOKEN ":") 145:145 +(NEWLINE) 146:146 +(TOKEN "indent") 147:150 +(TOKEN "identifier" print) 151:155 +(TOKEN "(") 156:156 +(TOKEN ")") 157:157 +(NEWLINE) 158:158 +(NEWLINE) 159:159 +(TOKEN "comment") 160:168 +(NEWLINE) 169:169 +(NEWLINE) 170:170 +(TOKEN "dedent") 170:170 +(KEYWORD "def") 171:173 +(TOKEN "identifier" main) 175:178 +(TOKEN "(") 179:179 +(TOKEN ")") 180:180 +(TOKEN ":") 181:181 +(NEWLINE) 182:182 +(TOKEN "indent") 183:186 +(TOKEN "identifier" print) 187:191 +(TOKEN "(") 192:192 +(TOKEN ")") 193:193 +(NEWLINE) 194:194 +(TOKEN "comment") 199:207 +(NEWLINE) 208:208 +(NEWLINE) 209:209 +(TOKEN "dedent") 209:209 +(KEYWORD "def") 210:212 +(TOKEN "identifier" main) 214:217 +(TOKEN "(") 218:218 +(TOKEN ")") 219:219 +(TOKEN ":") 220:220 +(NEWLINE) 221:221 +(TOKEN "indent") 222:225 +(TOKEN "identifier" print) 226:230 +(TOKEN "(") 231:231 +(TOKEN ")") 232:232 +(NEWLINE) 233:233 +(TOKEN "comment") 234:242 +(NEWLINE) 243:243 +(KEYWORD "pass") 248:251 +(NEWLINE) 252:252 +(NEWLINE) 253:253 +(TOKEN "dedent") 253:253 +(KEYWORD "def") 254:256 +(TOKEN "identifier" main) 258:261 +(TOKEN "(") 262:262 +(TOKEN ")") 263:263 +(TOKEN ":") 264:264 +(NEWLINE) 265:265 +(TOKEN "indent") 266:269 +(KEYWORD "if") 270:271 +(TOKEN "identifier" foo) 273:275 +(TOKEN ":") 276:276 +(NEWLINE) 277:277 +(TOKEN "indent") 278:285 +(KEYWORD "pass") 286:289 +(NEWLINE) 290:290 +(TOKEN "comment") 291:299 +(NEWLINE) 300:300 +(KEYWORD "pass") 309:312 +(NEWLINE) 313:313 +(KEYWORD "if") 322:323 +(TOKEN "identifier" bar) 325:327 +(TOKEN ":") 328:328 +(NEWLINE) 329:329 +(TOKEN "indent") 330:341 +(KEYWORD "pass") 342:345 +(NEWLINE) 346:346 +(TOKEN "dedent") 347:354 +(KEYWORD "pass") 355:358 +(NEWLINE) 359:359 +(TOKEN "dedent") 360:363 +(KEYWORD "pass") 364:367 +(NEWLINE) 368:368 +(TOKEN "dedent") 368:368 +(EOF) 369:369 diff --git a/tests/tests.toml b/tests/tests.toml index e0f45a8a2a..ed9f8e8a9d 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -86,6 +86,7 @@ filename = "expr7.py" ast = true asr = true cpp = true +c = true [[test]] filename = "expr8.py" @@ -139,17 +140,61 @@ ast = true asr = true llvm = true +[[test]] +filename = "../integration_tests/array_01_decl.py" +asr = true + +[[test]] +filename = "../integration_tests/array_02_decl.py" +asr = true + +[[test]] +filename = "../integration_tests/expr_07.py" +asr = true + +[[test]] +filename = "../integration_tests/expr_09.py" +asr = true + +[[test]] +filename = "../integration_tests/expr_10.py" +asr = true + +[[test]] +filename = "../integration_tests/expr_11.py" +c = true +cpp = true + +[[test]] +filename = "../integration_tests/expr_12.py" +asr = true +c = true + +[[test]] +filename = "../integration_tests/vec_01.py" +asr = true +pass = "loop_vectorise" + +[[test]] +filename = "../integration_tests/func_inline_01.py" +asr = true +llvm = true +pass_with_llvm = true +pass = "inline_function_calls" + [[test]] filename = "loop1.py" ast = true asr = true cpp = true +c = true [[test]] filename = "loop2.py" ast = true asr = true cpp = true +c = true [[test]] filename = "loop3.py" @@ -178,21 +223,64 @@ filename = "set1.py" ast = true asr = true +[[test]] +filename = "bool1.py" +llvm = true + [[test]] filename = "global_scope1.py" ast = true asr = true +[[test]] +filename = "c_interop1.py" +asr = true +c = true + # integration_tests [[test]] -filename = "ltypes.py" +filename = "ltypes1.py" llvm = true [[test]] filename = "../integration_tests/test_builtin.py" asr = true +[[test]] +filename = "../integration_tests/test_complex.py" +asr = true + +[[test]] +filename = "../integration_tests/structs_01.py" +asr = true + +[[test]] +filename = "../integration_tests/structs_02.py" +asr = true + +[[test]] +filename = "../integration_tests/structs_03.py" +asr = true + +[[test]] +filename = "../integration_tests/structs_04.py" +asr = true + +[[test]] +filename = "../integration_tests/structs_05.py" +asr = true + +[[test]] +filename = "../integration_tests/bindc_01.py" +asr = true +llvm = true + +[[test]] +filename = "../integration_tests/bindc_02.py" +asr = true +llvm = true + [[test]] filename = "../integration_tests/test_builtin_abs.py" asr = true @@ -242,6 +330,34 @@ asr = true filename = "../integration_tests/test_max_min.py" asr = true +[[test]] +filename = "../integration_tests/expr_05.py" +asr = true + +[[test]] +filename = "../integration_tests/test_integer_bitnot.py" +asr = true +llvm = true +cpp = true + +[[test]] +filename = "../integration_tests/test_bool_binop.py" +asr = true + +[[test]] +filename = "../integration_tests/test_issue_518.py" +llvm = true +c = true + +[[test]] +filename = "../integration_tests/test_c_interop_01.py" +asr = true + +[[test]] +filename = "../integration_tests/print_01.py" +c = true +cpp = true + # tests/tokens [[test]] @@ -252,6 +368,11 @@ tokens = true filename = "tokens/comment1.py" tokens = true +[[test]] +filename = "tokens/comment2.py" +tokens = true +ast_new = true + [[test]] filename = "tokens/symbols1.py" tokens = true @@ -278,6 +399,10 @@ ast_new = true filename = "parser/statements1.py" ast_new = true +[[test]] +filename = "parser/statements2.py" +ast_new = true + [[test]] filename = "parser/if1.py" ast_new = true @@ -286,6 +411,10 @@ ast_new = true filename = "parser/for1.py" ast_new = true +[[test]] +filename = "parser/comprehension1.py" +ast_new = true + [[test]] filename = "parser/try1.py" ast_new = true @@ -318,6 +447,27 @@ ast_new = true filename = "parser/slice1.py" ast_new = true +[[test]] +filename = "parser/ellipsis1.py" +ast = true + +[[test]] +filename = "parser/ellipsis2.py" +ast_new = true + +[[test]] +filename = "parser/while1.py" +ast_new = true + +[[test]] +filename = "parser/string1.py" +ast_new = true + +[[test]] +filename = "parser/global1.py" +ast = true +ast_new = true + # tests/errors [[test]] @@ -332,10 +482,22 @@ asr = true filename = "errors/test_str_slicing.py" asr = true +[[test]] +filename = "errors/test_str_slicing2.py" +asr = true + +[[test]] +filename = "errors/test_str_slicing3.py" +asr = true + [[test]] filename = "errors/test_annassign_type_mismatch.py" asr = true +[[test]] +filename = "errors/test_annassign_type_mismatch2.py" +asr = true + [[test]] filename = "errors/test_append_type_mismatch.py" asr = true @@ -456,6 +618,42 @@ asr = true filename = "errors/test_dict6.py" asr = true +[[test]] +filename = "errors/test_dict7.py" +asr = true + +[[test]] +filename = "errors/test_func_args.py" +asr = true + +[[test]] +filename = "errors/test_str_to_int.py" +asr = true + +[[test]] +filename = "errors/test_bitwise_on_float.py" +asr = true + +[[test]] +filename = "errors/test_bitwise_on_complex.py" +asr = true + +[[test]] +filename = "errors/test_print1.py" +asr = true + +[[test]] +filename = "errors/test_print2.py" +asr = true + +[[test]] +filename = "errors/test_pointer_types.py" +asr = true + +[[test]] +filename = "errors/test_unsupported_type.py" +asr = true + # tests/tokens/errors [[test]] diff --git a/tests/tokens/comment2.py b/tests/tokens/comment2.py new file mode 100644 index 0000000000..cfef59cd4c --- /dev/null +++ b/tests/tokens/comment2.py @@ -0,0 +1,36 @@ +def main(): +# a + # b + if foo: # c + # d + # e +#f + if bar: # g + pass + else: + pass + return + +def test(): + print() + +# Comment + +def main(): + print() + # Comment + +def main(): + print() +# Comment + pass + +def main(): + if foo: + pass +# Comment + pass + if bar: + pass + pass + pass diff --git a/tests/tuple1.py b/tests/tuple1.py index 6ef12dedc4..26fe6c8d8c 100644 --- a/tests/tuple1.py +++ b/tests/tuple1.py @@ -7,13 +7,19 @@ def test_Tuple(): a2 = ("a", "b", "c") a3: tuple[i32, i32, f32, str] - a3 = (-2, -1, 0.45, "d") + float_mem: f32 + float_mem = 0.45 + a3 = (-2, -1, float_mem, "d") a4: tuple[tuple[i32, i32, i32], tuple[i32, i32, i32]] a4 = ((1, 2, 3), (4, 5, 6)) a5: tuple[tuple[str, str, f32], tuple[str, i32, f32]] - a5 = (("a", "b", 3.4), ("c", 3, 5.6)) + float_mem1: f32 + float_mem2: f32 + float_mem1 = 3.4 + float_mem2 = 5.6 + a5 = (("a", "b", float_mem1), ("c", 3, float_mem2)) b0: i32 b1: i32