Skip to content

Support C structs #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
certik opened this issue Jun 15, 2022 · 1 comment
Closed
2 tasks done

Support C structs #606

certik opened this issue Jun 15, 2022 · 1 comment

Comments

@certik
Copy link
Contributor

certik commented Jun 15, 2022

We want to be able to represent an equivalent of the following code in Python and generate the same C code using the C backend:

struct A {
    int32_t x;
    float y;
};

void f(struct A *a) {
    int32_t x = a->x;
    float y = a->y;
    ...
}

Here is one approach how the Python code could look like:

@dataclass
class A:
    x: i32
    y: f32

@ccallable
def f(a: CPtr) -> None:
    x: i32
    y: f32
    a2: Pointer[A]
    c_p_pointer(a, a2)
    x = a2.x
    y = a2.y

It looks like two prerequisites are needed before we can tackle this:

@certik
Copy link
Contributor Author

certik commented Jul 19, 2022

We can have pointer to structs at the C level. I keep the issue #608 open for a general solution using Pointer. Not a high priority right now.

@certik certik closed this as completed Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant