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

Floating point constant expression #189

Merged
merged 11 commits into from
Aug 17, 2022
Merged

Conversation

Fantoom
Copy link
Contributor

@Fantoom Fantoom commented Aug 12, 2022

  1. closes Add support for floating constant #187
  2. Adds DoubleConstant for future use

TODO[F]:

  • create an issue for float

@Fantoom Fantoom marked this pull request as ready for review August 12, 2022 21:15
@@ -10,6 +10,7 @@

namespace Cesium.CodeGen.Tests;

[UseCulture("")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious why explicit control of the culture is needed here? Isn't we should write code which runs on all cultures in same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instruction.ToString() uses the culture of the thread, which can lead to different results on different machines and fail tests

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool that you submit jbevain/cecil#870 to fix underlying root cause. Would be interesting to know how it would be responded.

@Fantoom Fantoom changed the title Floatingpointconst Floating point constant expression Aug 13, 2022
@Fantoom Fantoom requested a review from kant2002 August 13, 2022 09:59
@@ -34,6 +34,7 @@ private static IConstant GetConstant(Ast.ConstantExpression expression)
CTokenType.IntLiteral => new IntegerConstant(constant.Text),
CTokenType.CharLiteral => new CharConstant(constant.Text),
CTokenType.StringLiteral => new StringConstant(constant),
CTokenType.FloatLiteral => new FloatConstant(constant.Text), //TODO: Add DoubleConstant
Copy link
Collaborator

Choose a reason for hiding this comment

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

As per C11 clause 6.4.4.2, “An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has type float. If suffixed by the letter l or L, it has type long double.“

So I think we can distinguish between float, double and long double trivially.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In current implementation we don't have suffix support. I have added a todo comment to get back to it when it is supported

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then probably would be good to have Double by default, at least that would be correct C behaviour, and if we miss float support, because of f suffix missing, then let's add float support later one.
Regarding missing suffix support, is this on us or on Yoakke?

Copy link
Owner

Choose a reason for hiding this comment

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

Suffix support is on us, because I want us to have a separate lexer eventually. Not sure if Yoakke already supports the suffices.

@@ -71,6 +71,7 @@ int main()
[Fact] public Task Parameter1Get() => DoTest("int foo(int x){ return x + 1; }");
[Fact] public Task Parameter5Get() => DoTest("int foo(int a, int b, int c, int d, int e){ return e + 1; }");
[Fact] public Task CharConstTest() => DoTest("int main() { char x = '\\t'; return 42; }");
[Fact] public Task FloatConstTest() => DoTest("int main() { float x = 1.5; return 42; }");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think here would be good to have

[Fact] public Task DoubleConstTest() => DoTest("int main() { double x = 1.5; return 42; }");

I think naming is from when Float was default. When we really implement float we need to change name anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I forgot about it

Cesium.CodeGen/Ir/Expressions/Constants/FloatConstant .cs Outdated Show resolved Hide resolved
Cesium.CodeGen.Tests/UseCultureAttribute.cs Outdated Show resolved Hide resolved
@@ -34,6 +34,7 @@ private static IConstant GetConstant(Ast.ConstantExpression expression)
CTokenType.IntLiteral => new IntegerConstant(constant.Text),
CTokenType.CharLiteral => new CharConstant(constant.Text),
CTokenType.StringLiteral => new StringConstant(constant),
CTokenType.FloatLiteral => new FloatConstant(constant.Text), //TODO: Add DoubleConstant
Copy link
Owner

Choose a reason for hiding this comment

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

Suffix support is on us, because I want us to have a separate lexer eventually. Not sure if Yoakke already supports the suffices.

@Fantoom Fantoom force-pushed the floatingpointconst branch from eced66e to 70ca721 Compare August 16, 2022 21:09
@kant2002 kant2002 mentioned this pull request Aug 17, 2022
Copy link
Owner

@ForNeVeR ForNeVeR left a comment

Choose a reason for hiding this comment

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

Thanks!

@ForNeVeR ForNeVeR mentioned this pull request Aug 17, 2022
@ForNeVeR
Copy link
Owner

I've made an improvement of removing FloatConstant (it was of no use anyway) and replaced the DoubleConstant with a new FloatingPointConstant. My vision is that it is likely that it'll serve for both double and float, depending on the expression type, though I'm not 100% sure on that.

The follow-up issue is #243.

@ForNeVeR ForNeVeR merged commit 8f22da7 into ForNeVeR:main Aug 17, 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

Successfully merging this pull request may close these issues.

Add support for floating constant
3 participants