Skip to content
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

Add C support for a class containing only scalar data #1439

Closed
4 tasks
EmilyBourne opened this issue Jul 12, 2023 · 0 comments · Fixed by #1472
Closed
4 tasks

Add C support for a class containing only scalar data #1439

EmilyBourne opened this issue Jul 12, 2023 · 0 comments · Fixed by #1472

Comments

@EmilyBourne
Copy link
Member

EmilyBourne commented Jul 12, 2023

Relevant Discussion

#1119

Describe the feature

Add support for classes as simple objects containing scalars. It may be a good idea to implement this issue after #1441 as functions will be useful for the constructor.

Test Code

Provide code which does not currently work but which should do when this issue is fixed:

# pylint: disable=missing-class-docstring,  missing-function-docstring, missing-module-docstring
#$ header class Point(public)
#$ header method __init__(Point, double, double)

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

if __name__ == '__main__':
    p = Point(0.0, 0.0)
    x=p.x
    p.x=4
    a = p.x
    a = p.x - 2
    a = 2 * p.x - 2
    a = 2 * (p.x + 6) - 2

    p.y = a + 5
    p.y = p.x + 5

    print(p.x, p.y)
    print(x)
    print(a)

Proposed Solution

The printing stage should generate the following header code:

#ifndef TEST_MOD_H
#define TEST_MOD_H

#include <stdlib.h>
#include "ndarrays.h"

struct Point {
    double x;
    double y;
};

void Point__init(struct Point self, double x, double y);
#endif // TEST_MOD_H

and the appropriate associated source code.

Target Language

C

Acceptance Criteria

To complete this issue the following should be done:

  • Add test(s) similar to the one above in tests/pyccel/scripts/classes
    • Ensure that the tests are run and work for Fortran in tests/pyccel/test_pyccel.py
    • Ensure that the test can also be run for C (should not pass yet)
  • Implement _print_ClassDef to handle the subset of classes described above
@EmilyBourne EmilyBourne changed the title Add C support for the simplest class possible Add C support for a class containing only scalar data Jul 14, 2023
@sboof911 sboof911 self-assigned this Jul 27, 2023
@sboof911 sboof911 linked a pull request Aug 1, 2023 that will close this issue
@EmilyBourne EmilyBourne mentioned this issue Aug 10, 2023
37 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants