load :: G.Get [Instructions.InstructionWord]
load = do
  empty <- G.isEmpty
  if empty then
    return []
  else do
    opcode <- G.getWord8
    let inst = toEnum $ fromIntegral $ fromEnum $ opcode
    let arity = Instructions.arguments inst
    case arity of
      0 -> do
        rest <- load
        return ((Instructions.Nullary inst) : rest)

      1 -> do
        arg <- G.getWord16be
        rest <- load
        return ((Instructions.Unary inst
                (toEnum $ fromIntegral $ fromEnum $ arg)) : rest)

      2 -> do
        arg0 <- G.getWord16be
        arg1 <- G.getWord16be
        rest <- load
        return ((Instructions.Binary inst
                (toEnum $ fromIntegral $ fromEnum $ arg0)
                (toEnum $ fromIntegral $ fromEnum $ arg1)) : rest)
load :: G.Get [Instructions.InstructionWord]
load = do
  empty <- G.isEmpty
  if empty then
    return []
  else do
    opcode <- G.getWord8
    let inst = toEnum $ fromIntegral $ fromEnum $ opcode
    let arity = Instructions.arguments inst
    case arity of
      0 -> do
        rest <- load
        return ((Instructions.Nullary inst) : rest)

      1 -> do
        arg <- G.getWord16be
        rest <- load
        return ((Instructions.Unary inst
                (toEnum $ fromIntegral $ fromEnum $ arg)) : rest)

      2 -> do
        arg0 <- G.getWord16be
        arg1 <- G.getWord16be
        rest <- load
        return ((Instructions.Binary inst
                (toEnum $ fromIntegral $ fromEnum $ arg0)
                (toEnum $ fromIntegral $ fromEnum $ arg1)) : rest)
load = do
  empty <- G.isEmpty
  if empty then
    return []
  else do
    opcode <- G.getWord8
    let inst = toEnum $ fromIntegral $ fromEnum $ opcode
    let arity = Instructions.arguments inst
    case arity of
      0 -> do
        rest <- load
        return ((Instructions.Nullary inst) : rest)

      1 -> do
        arg <- G.getWord16be
        rest <- load
        return ((Instructions.Unary inst
                (toEnum $ fromIntegral $ fromEnum $ arg)) : rest)

      2 -> do
        arg0 <- G.getWord16be
        arg1 <- G.getWord16be
        rest <- load
        return ((Instructions.Binary inst
                (toEnum $ fromIntegral $ fromEnum $ arg0)
                (toEnum $ fromIntegral $ fromEnum $ arg1)) : rest)