diff --git a/src/data/CCBitField.ml b/src/data/CCBitField.ml index 99c46ef2..873e4ede 100644 --- a/src/data/CCBitField.ml +++ b/src/data/CCBitField.ml @@ -186,15 +186,17 @@ module Make(X : EMPTY) : BITFIELD = struct let pp out x = let ppf = Format.fprintf in ppf out "{@["; + let first=ref true in Queue.iter (fun (AnyField f) -> + if !first then first := false else ppf out ",@ "; match f.kind with | Bool -> let b = get f x in - ppf out "%s: %b,@ " f.name b + ppf out "%s=%b" f.name b | Int -> let i = get f x in - ppf out "%s: %ui@, " f.name i + ppf out "%s=%u" f.name i ) fields_; ppf out "@]}" end diff --git a/src/data/CCBitField.mli b/src/data/CCBitField.mli index 3c441afe..0e63a05e 100644 --- a/src/data/CCBitField.mli +++ b/src/data/CCBitField.mli @@ -75,7 +75,27 @@ module type BITFIELD = sig (** Print the bitfield using the current list of fields *) end -(** Create a new bitfield type *) +(** Create a new bitfield type, + +{[ +module B = CCBitField.Make(struct end);; + +#install_printer B.pp;; + +let x = B.int ~name:"x" ~width:3;; +let y = B.int ~name:"y" ~width:2;; +let z = B.bool ~name:"z" ();; + +let f = B.(empty |> set x 3 |> set y 1);; + +B.get z f ;; + +B.(f |> set z true |> get z) ;; + +]} + + +*) module Make(X : EMPTY) : BITFIELD (*$R