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

Unify backend for enums/sum types #38

Open
wegendt-bosch opened this issue Apr 25, 2018 · 2 comments
Open

Unify backend for enums/sum types #38

wegendt-bosch opened this issue Apr 25, 2018 · 2 comments
Labels

Comments

@wegendt-bosch
Copy link
Contributor

We support enums in Mita. Since enums can be implemented with sum types, this is redundant. Since some people might prefer enums, I propose keeping them in the language, but implementing them by just parsing them as sum types. This allows us to reuse code in the model and generator, while not changing the language itself. Furthermore, one can then use enums in where-is statements.

The only drawback I see with this is that the C code is slightly more than just enum as we would generate the following instead of a bare C enum:

enum Foo {
  X, 
  Y,
  Z
}
typedef enum {
	X_e,
	Y_e,
	Z_e
} Foo_enum;

typedef struct {
	Foo_enum tag;
	union Data {
	} data;
} Foo;

However this imposes no runtime overhead since empty unions have a sizeof 0.

@sawtschuk-appropos
Copy link

sawtschuk-appropos commented May 24, 2018

Unifying the C code so that Sum Generators can be reused is nice

But, if Sum Types and Enum Types end up having the same basic functionality, except that Enum can not hold Data, I would prefer that Enum Types are completely removed from the language.

It does not make sense to me to have two language constructs, where one is just a less powerful version of the other, but otherwise they behave exactly the same and have exactly the same usage.

This would seem especially true in regards to the fact that Eclipse Mita's intended purpose is to abstract the C language into something higher level, so that people do not have to learn, know, and understand C. Enums therefore would become obsolete in light of Sum Types.

Edit: If Enum is a Subset of Sum Types, and this makes Enum obsolete, then Enum would not be obsolete if Enum had syntactic use that Sum Types do not have.

@csweichel
Copy link

Mita should have enums - at least on a syntactic level as that's what many people expect. Name a language without enum support, or people complaining of the lack thereof. It just feels natural* to be able to write something like

enum Foobar { 
    foo,
    bar 
}

,* natural in the sense that this construct looks like something I've seen in many different languages, such as Java or Typescript to name two.

Also, our enums differ from C enums in that they cannot be cast to integers, i.e. are symbols "only".

All that said, I'm all for unifying enums with sum types on the backend but keeping the enum syntax.

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

No branches or pull requests

3 participants