Rationale: Currently, a lot of the serialisation code is built manually, since in Haskell one doesn't have the runtime reflection facilities that Python has. This is unfortunate, and prevents wider usage of OpCodes and other structures.
This patch adds TemplateHaskell use (http://www.haskell.org/haskellwiki/Template_Haskell) so that such repetitive structures can be automatically generated. The TH support in GHC 6.12 (Lucid, Squeeze) works, but it generates some invalid compile-time warnings (at least I think are invalid). With GHC 7.0 it works even better, no extra warnings. Debugging of TH code: it is very easy to actually see the generated code; a simple "make HEXTRA=-ddebug-splices" will dump the generated code to stdout. Extra libraries needed: none. Template Haskell is shipped with GHC itself. Patch series: - patch 1 is cleanup, and unrelated - patches 2-6 are TH-related - patch 7 is some more cleanup in unittests, as I realised we can improve some asserts while doing TH for the unittests Iustin Pop (7): Split part of Utils.hs into JSON.hs Rename some helper functions for consistency Use TemplateHaskell instead of hand-coded instances Use TemplateHaskell to build the opID function Use TemplateHaskell to generate opcode serialisation Use TemplateHaskell to decorate tests with names A few minor test improvements Makefile.am | 4 +- htools/Ganeti/HTools/CLI.hs | 2 +- htools/Ganeti/HTools/Cluster.hs | 4 +- htools/Ganeti/HTools/JSON.hs | 115 ++++++++++ htools/Ganeti/HTools/Program/Hspace.hs | 5 +- htools/Ganeti/HTools/QC.hs | 285 ++++++++++++----------- htools/Ganeti/HTools/QCHelper.hs | 47 ++++ htools/Ganeti/HTools/Simu.hs | 2 +- htools/Ganeti/HTools/Text.hs | 9 +- htools/Ganeti/HTools/Types.hs | 115 +++------- htools/Ganeti/HTools/Utils.hs | 76 +------ htools/Ganeti/Jobs.hs | 81 ++----- htools/Ganeti/OpCodes.hs | 150 ++++--------- htools/Ganeti/THH.hs | 391 ++++++++++++++++++++++++++++++++ htools/test.hs | 88 +++++--- 15 files changed, 864 insertions(+), 510 deletions(-) create mode 100644 htools/Ganeti/HTools/JSON.hs create mode 100644 htools/Ganeti/HTools/QCHelper.hs create mode 100644 htools/Ganeti/THH.hs -- 1.7.3.1
