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

Implementing explicit casting #113

Open
endrix opened this issue Jun 30, 2014 · 8 comments
Open

Implementing explicit casting #113

endrix opened this issue Jun 30, 2014 · 8 comments

Comments

@endrix
Copy link
Member

endrix commented Jun 30, 2014

It is time to add explicit casting.

int t := ~5;

Having this as an example what is the value of t ?

For Orcc "5" is an uint of size 3 and "not" of 5, ~5 = 2.

So now if i want a not on 32 bits I need to :

int const = 5;
int t := ~const; 

Which is kind of limiting.

And now what about the programmer ! What a C programmer going to CAL think of

int t := ~5;

As a solution to this "casting" I propose to add to the frontend the possibility to cast expressions.

An example of casting can be written like that :

int t := ~( (int(size=4) 5);

can lead to t to have a value of 10.

Also in the IR we have already the cast instruction, we need to change the frontend and we can create rules on casting different types like e.g. boolean to integers.

What do you think ?

@hyviquel
Copy link
Contributor

That maybe "5" should not be an uint of size 3: The size could be related to its use.
Anyway, i don't like your explicit casting 👎

@endrix
Copy link
Member Author

endrix commented Jun 30, 2014

The "5" is just an example, it can be an general expression.

And why don't you like this explicit casting ? What is the problem with it ?

@hyviquel
Copy link
Contributor

int t := ~( (int(size=4) 5); is ugly, not in the standard, not really useful, etc. But, it is only my personal opinion 😉 .
However, we have to add specific cast instructions at some point for the translation between float and int. So, it is probably a good idea to debate about casting 👍

One question (which seems quite important): Do you plan to implement it yourself ?

@endrix
Copy link
Member Author

endrix commented Jun 30, 2014

There is nothing on the standard about explicit casting. Yes it is ugly but it follows the typing of CAL and you can specify the size of it.

This is future work, and we are planning to do quite a lot of stuff in the beginning of the next year(thesis defence in December ). So yes I am planning to implement that myself.

@mraulet
Copy link
Member

mraulet commented Jul 1, 2014

@endrix There are explicit castings from int to float and vice versa in the standard.

@endrix
Copy link
Member Author

endrix commented Jul 1, 2014

@mraulet, great for float to int. But what happens to int to int with different size and casting of bool to into and int to bool.

Now it depends what we want to do with the language and I think there is an interest on explicit casting in certain situations. Like for example to not use an if statement for converting a bool to int.

@hyviquel
Copy link
Contributor

hyviquel commented Jul 1, 2014

I'm agree with bool/int conversion... But, resizing an integer can always be done using a specific statement: It is not so painful to do...

@hyviquel
Copy link
Contributor

hyviquel commented Jul 1, 2014

After all, even bool/int conversion is not really useful: (i = 1) seems quite simple to convert them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants