Skip to content

Implement calling into C #3

Closed
Closed

Description

@certik

This is supported well at the ASR level, but we need to figure out a Python syntax. Whether via the ctypes FFI, or some other syntax.

Activity

  1. certik commented on Dec 29, 2021

    @certik
    ContributorAuthor

    One idea:

    from ctypes import c_float, c_double
    def c_sin_f32(x: c_float) -> c_float:
        pass
    
    def c_sin_f64(x: c_double) -> c_double:
        pass
  2. certik commented on Dec 30, 2021

    @certik
    ContributorAuthor

    CPython does not have 32bit floats, so we simply declare in math.py:

    def sin(x: f64) -> f64:
        return c_sin_f64(x)
  3. certik commented on Feb 24, 2022

    @certik
    ContributorAuthor

    I like this approach: https://code.activestate.com/recipes/576731-c-function-decorator/, that might be almost exactly what we need. An example how to use ctypes with types is, e.g., here: https://www.linkedin.com/pulse/calling-c-from-python-using-ctypes-warren-jitsing

  4. certik commented on Feb 26, 2022

    @certik
    ContributorAuthor

    Initial implementation was done in #167, #171, #172. Here is a test:

    It works with CPython. Now we need to get this test working with LPython.

  5. certik commented on Mar 2, 2022

    @certik
    ContributorAuthor

    The LPython part was implemented in: #179, #181 and used in #184, #186. This issue is fixed. We need to extend this C interop to other types, but that will be an ongoing work as we need it.

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