- Joined
- Aug 27, 2017
- Messages
- 110
I think there should exist some way to enumerate constants so I had a look at the compiler source code but it seems like it would be very complicated to add enums. However in C for example there are different ways to enumerate stuff:
or using typedef:
or:
Since the last one looks like it could be implemented I experimented with the compiler code and added an 'Enumerate' keyword.
So instead of writing
… you can now write:
(the resulting code should be the same)
It also works with all attributes (private, public, …) and line breaks behave like they should (they are allowed after operators and after commas). The generated code is the same since in the end it does nothing other than creating integer constants. Enumerations are possible within classes, interfaces, functions, methods And in global space.
Here is the source code for the custom trans tool:
Code:
enum foo{a, b, c=123};
Code:
typedef enum {a, b, c=123} foo;
Code:
enum {a, b, c=123};
Since the last one looks like it could be implemented I experimented with the compiler code and added an 'Enumerate' keyword.
So instead of writing
Code:
Const A:Int = 0
Const B:Int = 1
Const C:Int = 3
Const D:Int = F+100
Const E:Int = 22
Const F:Int = 23
Code:
Enumerate A, B, C, D=F+100, E=22, F
It also works with all attributes (private, public, …) and line breaks behave like they should (they are allowed after operators and after commas). The generated code is the same since in the end it does nothing other than creating integer constants. Enumerations are possible within classes, interfaces, functions, methods And in global space.
Here is the source code for the custom trans tool: