Fix some issues with arithmetic operations on enums

These commits fix issue described in redmine issue#44; they also add some unit tests and fixes for a number of different issues I found using these tests.
Note: I didn't actually run those unit tests (for some reason I didn't had much luck running any of xUnit tests), I put them into one of the kernels instead and made sure they all compile and run successfully