← 输入框|github.com|刷新
Skip to content

Get test_math_02 working with the C backend #2076

Open

Description

@certik
$ lpython integration_tests/test_math_02.py --backend=c
test_math_02__tmp__generated__.c:186:8: error: conflicting types for 'hypot'
double hypot(int32_t x, int32_t y)
       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:425:15: note: previous declaration is here
extern double hypot(double, double);
              ^
1 error generated.
The command 'gcc -o test_math_02.out test_math_02__tmp__generated__.c  -I /Users/ondrej/repos/lpython/src/bin/../libasr/runtime -L"/Users/ondrej/repos/lpython/src/bin/../runtime" -Wl,-rpath,"/Users/ondrej/repos/lpython/src/bin/../runtime" -llpython_runtime -lm' failed.

Activity

  1. Smit-create commented on Jul 3, 2023

    @Smit-create
    Collaborator

    That's because of the re-declaration errors. We define hypot in runtime/math.py which is given by:

    def hypot(x: i32, y: i32) -> f64:
        """
        Returns the hypotenuse of the right triangle with sides `x` and `y`.
        """
        return sqrt(f64(1.0)*f64(x**2 + y**2))

    One thing, we can do is to internally change those names during code-gen to let's say __module__name + __func_name__ to avoid such name conflicts.

  2. Thirumalai-Shaktivel commented on Jul 3, 2023

    @Thirumalai-Shaktivel
    Collaborator

    I think, we can also mangle the name in the ASR itself.
    So, say we have an ExternalSymbol: hypot, we can change that to math@hypot or __math_hypo__ or something similar

  3. Thirumalai-Shaktivel commented on Jul 3, 2023

    @Thirumalai-Shaktivel
    Collaborator

    @Smit-create let me know would be better? Handle this in ASR or backend?

  4. Smit-create commented on Jul 3, 2023

    @Smit-create
    Collaborator

    We already have that possibility in ASR, so let's do that on ASR level. I think just changing this a bit get_mangled_name should be fine, with no major changes. I'll try that ASR first.

  5. certik commented on Jul 3, 2023

    @certik
    ContributorAuthor

    I think every function in a module should be prefixed with the module name in ASR, like we do in LFortran.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions