Skip to content

Imports Too Many When Importing From File #1611

Closed
@ronnuriel

Description

@ronnuriel

Imports too many from import file

Lets create bar.py (bar.py is in the same directory as expr7)

from expr7 import test_pow

def main():
	test_pow()
 
main()

expr7:

from ltypes import i32

def test_pow():
    a: i32
    a = i32(pow(2, 2))

def test_pow_1(a: i32, b: i32) -> i32:
    res: i32
    res = i32(pow(a, b))
    return res

def main0():
    test_pow()
    c: i32
    c = test_pow_1(1, 2)

Run:
lpython --show-c -I . bar.py

C generated code output:

#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, length;
};

// Implementations
double __lpython_overloaded_0__pow(int32_t x, int32_t y)
{
    double _lpython_return_variable;
    _lpython_return_variable = (double)(pow(x, y));
    return _lpython_return_variable;
}

float _lfortran_caimag(float complex x);

double _lfortran_zaimag(double complex x);

void test_pow()
{
    int32_t a;
    a = (int32_t)(__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 = (int32_t)(__lpython_overloaded_0__pow(a, b));
    _lpython_return_variable = res;
    return _lpython_return_variable;
}

void main0()
{
    int32_t c;
    test_pow();
    c = test_pow_1(1, 2);
}

void _xx_lcompilers_changed_main_xx()
{
    test_pow();
}

void _lpython_main_program()
{
    _xx_lcompilers_changed_main_xx();
}

int main(int argc, char* argv[])
{
    _lpython_main_program();
    return 0;
}

As you can see it generates more then test_pow (main0, test_pow_1)
while it is wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    asrASR related changescLabel for C language related changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions