summaryrefslogtreecommitdiff
path: root/riscv
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-01-30 02:33:54 +0000
committerAlasdair Armstrong2018-01-30 02:33:54 +0000
commit2eafe7b1c5e93c375ffc42f0a9e8efbd64b69f54 (patch)
tree3e600402cb1d582f0455cbc52b6c60d964273fba /riscv
parent5efec36cf2fe90d9c525e2d233f0e9c1d7c85b40 (diff)
Generate functions from enums to numbers and vice versa
For an enumeration type T, we can create a function T_of_num and num_of_T which convert from the enum to and from a numeric type. The numeric type is range(0, n) where n is the number of constructors in the enum minus one. This makes sure the conversion is type safe, but maybe this is too much of a hassle. It would be possible to automatically overload all these functions into generic to_enum and from_enum as in Haskell's Enum typeclass, but we don't do this yet. Currently these functions affect a few lem test cases, but I think that is only because they are tested without any prelude functions and pattern rewrites require a few functions to be defined What is really broken is if one tries to generate these functions like enum x = A | B | C function f A = 0 function f B = 1 function f C = 2 the rewriter really doesn't like function clauses like this, and it seems really hard to fix properly (I tried and gave up), this is a shame as the generation code is much more succinct with definitions like above
Diffstat (limited to 'riscv')
0 files changed, 0 insertions, 0 deletions