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 type declarations to C code printer #10452

Closed
wants to merge 1 commit into from
Closed

add type declarations to C code printer #10452

wants to merge 1 commit into from

Conversation

AnishShah
Copy link
Contributor

Fixes #10446

a, b = symbols("a, b")

assert ccode(a**2, b, declare="double") == "double b = pow(a, 2);"
assert ccode(a, declare="double") == "double a;"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Press enter at end of the line.

@AnishShah
Copy link
Contributor Author

Can anyone review this PR?

@moorepants
Copy link
Member

@asmeurer @jcrist Do you all think this is a reasonable addition?

@@ -298,6 +303,8 @@ def ccode(expr, assign_to=None, **settings):
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].
declare: string, optional
When given, it specifies the data type of `assign_to` variable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above isn't true for this case: ccode(a, declare="double"). Please make it generalize to what it actually does.

@AnishShah
Copy link
Contributor Author

@moorepants I made the changes! :) Let me know if you require any other changes.

@moorepants
Copy link
Member

I'd like to get @asmeurer feedback as we recently decided not to support summation in C. We may not want to extend this too far away from printing simple expressions.

@asmeurer
Copy link
Member

There is some typing stuff inherited from symcc at #10486 (I haven't ported the code printers yet). I haven't really decided what to do with it, though. Personally type declarations are a lower priority for me. I am afraid of not doing them correctly, so I am a little hesitant on this change.

@AnishShah
Copy link
Contributor Author

No problem @asmeurer . Should I close this PR?

@asmeurer
Copy link
Member

FYI I removed the datatype stuff from my PR. I'm unclear what the best way to deal with types is in the codegen module, and it's not a top priority for me to fix it out at the moment.

@moorepants how useful would the change here be for you? I guess the alternative is to keep track of your variables and declare them separately.

@moorepants
Copy link
Member

Right now I have to specify these like:

'double {}'.format(ccode(a**2 + b, assign=z))

Or make a template. I suppose I could subclass the C printer too. This is just a convenience, but in C this is such a common thing to do, it seems like it should be available somehow.

@AnishShah AnishShah closed this Jan 4, 2017
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

Successfully merging this pull request may close these issues.

4 participants