Commit 8ee2994a authored by Iustin Pop's avatar Iustin Pop
Browse files

Switch opcode data type from normal to record constructors

Currently, the OpCode definitions are using normal constructors:

  data OpCode = OpTestDelay Double Bool [String]
              | OpInstanceFailover String Bool (Maybe String)

While this works for a few opcodes, it becomes unwieldy when dealing
with a bigger number of opcode definitions and/or with opcodes having
many fields.

This patch changes the opcodes to record-based constructors, so that
we get for free accessor functions:

  data OpCode
    = OpTestDelay {
        opDuration :: Double,
        opOnMaster :: Bool,
        opOnNodes :: [String]
      | OpInstanceFailover {
         opInstanceName :: String,
         opIgnoreConsistency :: Bool,
         opTargetNode :: Maybe String
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarAdeodato Simo <>
parent 51d991d7
......@@ -526,9 +526,8 @@ genOpCode name cons = do
let tname = mkName name
decl_d <- mapM (\(cname, fields) -> do
-- we only need the type of the field, without Q
fields' <- mapM actualFieldType fields
let fields'' = zip (repeat NotStrict) fields'
return $ NormalC (mkName cname) fields'')
fields' <- mapM (fieldTypeInfo "op") fields
return $ RecC (mkName cname) fields')
let declD = DataD [] tname [] decl_d [''Show, ''Read, ''Eq]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment