Skip to content

feat: added static type casting #19

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

morpheuschoo
Copy link

Added:

  • Implemented support for C-style cast expressions (type) expression
  • Support all numeric conversions between integral and floating-point types

To add:

  • Validation for legal type conversions with appropriate warnings for potentially unsafe casts

Copy link
Contributor

@benmurphyy benmurphyy left a comment

Choose a reason for hiding this comment

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

Have you tested Support all numeric conversions between integral and floating-point types ? From what I can see this won't actually work. I just ran a simple test:

#include <source_stdlib>

int main() {
  float x = (int) 10.5;
  print_float(x);
}

what we print is 10.5, what it should be printing is 10 because of the conversion float -> int -> float.

Please ensure that your code does as it claims before putting it up for review, if not leave it in draft.

const targetDataType = expr.targetDataType;

return {
originalDataType: targetDataType,
Copy link
Contributor

Choose a reason for hiding this comment

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

the originalDataType type here does not seem to be used anywhere. How does the type conversion (e.g. int-> float) actually work in that case?

Comment on lines +45 to +52
const translatedStatements = expr.statements.map((statement) =>
translateStatement(statement, enclosingLoopDetails),
);
const translatedExpr = translateExpression(
expr.expr,
expr.expr.dataType,
enclosingLoopDetails,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

These variables do not seem to be used anywhere. What is their purpose?

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.

2 participants