Skip to content

Commit

Permalink
Prefix runtime module with "Deriving_".
Browse files Browse the repository at this point in the history
The runtime module name is parametrized in class description.
  • Loading branch information
hnrgrgr committed Jan 7, 2011
1 parent b4319a5 commit dfbc666
Show file tree
Hide file tree
Showing 40 changed files with 305 additions and 159 deletions.
22 changes: 11 additions & 11 deletions lib/Makefile
Expand Up @@ -8,17 +8,17 @@ OCAMLDEP = ocamldep.opt
OCAMLFLAGS =-w ae
LIBS = nums str unix

SOURCES = show.ml show.mli \
interned.mli interned.ml \
eq.ml eq.mli \
bounded.ml bounded.mli \
enum.ml enum.mli \
monad.ml monad.mli \
dump.ml dump.mli \
typeable.ml typeable.mli \
dynmap.ml dynmap.mli \
pickle.ml pickle.mli \
functor.ml functor.mli \
SOURCES = deriving_Show.ml deriving_Show.mli \
deriving_interned.mli deriving_interned.ml \
deriving_Eq.ml deriving_Eq.mli \
deriving_Bounded.ml deriving_Bounded.mli \
deriving_Enum.ml deriving_Enum.mli \
deriving_monad.ml deriving_monad.mli \
deriving_Dump.ml deriving_Dump.mli \
deriving_Typeable.ml deriving_Typeable.mli \
deriving_dynmap.ml deriving_dynmap.mli \
deriving_Pickle.ml deriving_Pickle.mli \
deriving_Functor.ml deriving_Functor.mli \


RESULT = deriving
Expand Down
4 changes: 2 additions & 2 deletions lib/bounded.ml → lib/deriving_Bounded.ml
Expand Up @@ -5,7 +5,7 @@
*)

(** Primitive instanecs for bounded **)
module Bounded = struct
module Deriving_Bounded = struct
module type Bounded = sig
type a
val min_bound : a
Expand Down Expand Up @@ -45,7 +45,7 @@ module Bounded_unit = struct
let max_bound = ()
end
end
include Bounded
include Deriving_Bounded
type open_flag = Pervasives.open_flag =
| Open_rdonly
| Open_wronly
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions lib/enum.ml → lib/deriving_Enum.ml
Expand Up @@ -5,7 +5,7 @@
See the file COPYING for details.
*)

open Bounded
open Deriving_Bounded

let rec rassoc (rkey : 'b) : ('a * 'b) list -> 'a = function
| [] -> raise Not_found
Expand All @@ -17,7 +17,7 @@ let rec last : 'a list -> 'a = function
| [x] -> x
| _::xs -> last xs

module Enum =
module Deriving_Enum =
struct
(** Enum **)
module type Enum = sig
Expand Down Expand Up @@ -121,7 +121,7 @@ module Enum_unit = Defaults' (struct
| _ -> raise (Invalid_argument "to_enum")
end) (Bounded_unit)
end
include Enum
include Deriving_Enum

type open_flag = Pervasives.open_flag =
| Open_rdonly
Expand All @@ -133,12 +133,12 @@ type open_flag = Pervasives.open_flag =
| Open_binary
| Open_text
| Open_nonblock
deriving (Enum)
deriving (Bounded,Enum)

type fpclass = Pervasives.fpclass =
| FP_normal
| FP_subnormal
| FP_zero
| FP_infinite
| FP_nan
deriving (Enum)
deriving (Bounded,Enum)
2 changes: 1 addition & 1 deletion lib/enum.mli → lib/deriving_Enum.mli
Expand Up @@ -17,7 +17,7 @@ module Defaults

module Defaults'
(E : sig type a val from_enum : a -> int val to_enum : int -> a end)
(B : Bounded.Bounded with type a = E.a)
(B : Deriving_Bounded.Bounded with type a = E.a)
: Enum with type a = B.a

module Enum_bool : Enum with type a = bool
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions lib/functor.ml → lib/deriving_Functor.ml
@@ -1,4 +1,4 @@
open Monad
open Deriving_monad

(* Copyright Jeremy Yallop 2007.
This file is free software, distributed under the MIT license.
Expand All @@ -21,8 +21,8 @@ struct
end


module Functor_option = MonadFunctor(Monad.Monad_option)
module Functor_list = MonadFunctor(Monad.Monad_list)
module Functor_option = MonadFunctor(Monad_option)
module Functor_list = MonadFunctor(Monad_list)

module Functor_map (O : Map.OrderedType)
: Functor with type 'a f = 'a Map.Make(O).t =
Expand Down
2 changes: 1 addition & 1 deletion lib/functor.mli → lib/deriving_Functor.mli
Expand Up @@ -3,7 +3,7 @@ sig
type 'a f
val map : ('a -> 'b) -> 'a f -> 'b f
end
module MonadFunctor (M : Monad.Monad) : Functor with type 'a f = 'a M.m
module MonadFunctor (M : Deriving_monad.Monad) : Functor with type 'a f = 'a M.m
module Functor_option : Functor with type 'a f = 'a option
module Functor_list : Functor with type 'a f = 'a list
module Functor_map (O : Map.OrderedType) : Functor with type 'a f = 'a Map.Make(O).t
87 changes: 46 additions & 41 deletions lib/pickle.ml → lib/deriving_Pickle.ml
Expand Up @@ -10,7 +10,12 @@
1. every object receives a serializable id.
2. an object is serialized using the ids of its subobjects
*)
module Pickle =

open Deriving_Typeable
open Deriving_Eq
open Deriving_Dump

module Deriving_Pickle =
struct
exception UnknownTag of int * string
exception UnpicklingError of string
Expand Down Expand Up @@ -58,43 +63,43 @@ type repr = Repr.t
module Write : sig
type s = {
nextid : Id.t;
obj2id : Id.t Dynmap.DynMap.t;
obj2id : Id.t Deriving_dynmap.DynMap.t;
id2rep : repr IdMap.t;
}
val initial_output_state : s
include Monad.Monad_state_type with type state = s
include Deriving_monad.Monad_state_type with type state = s

module Utils (T : Typeable.Typeable) (E : Eq.Eq with type a = T.a) : sig
module Utils (T : Typeable) (E : Eq with type a = T.a) : sig
val allocate : T.a -> (id -> unit m) -> id m
val store_repr : id -> Repr.t -> unit m
end
end =
struct
type s = {
nextid : Id.t; (* the next id to be allocated *)
obj2id : Id.t Dynmap.DynMap.t; (* map from typerep to id cache for the corresponding type *)
obj2id : Id.t Deriving_dynmap.DynMap.t; (* map from typerep to id cache for the corresponding type *)
id2rep : repr IdMap.t;
}
let initial_output_state = {
nextid = Id.initial;
obj2id = Dynmap.DynMap.empty;
obj2id = Deriving_dynmap.DynMap.empty;
id2rep = IdMap.empty;
}
include Monad.Monad_state (struct type state = s end)
module Utils (T : Typeable.Typeable) (E : Eq.Eq with type a = T.a) =
include Deriving_monad.Monad_state (struct type state = s end)
module Utils (T : Typeable) (E : Eq with type a = T.a) =
struct
module C = Dynmap.Comp(T)(E)
module C = Deriving_dynmap.Comp(T)(E)
let comparator = C.eq

let allocate o f =
let obj = T.make_dynamic o in
get >>= fun ({nextid=nextid;obj2id=obj2id} as t) ->
match Dynmap.DynMap.find obj obj2id with
match Deriving_dynmap.DynMap.find obj obj2id with
| Some id -> return id
| None ->
let id, nextid = nextid, Id.next nextid in
put {t with
obj2id=Dynmap.DynMap.add obj id comparator obj2id;
obj2id=Deriving_dynmap.DynMap.add obj id comparator obj2id;
nextid=nextid} >>
f id >> return id

Expand All @@ -105,25 +110,25 @@ struct
end

module Read : sig
type s = (repr * (Typeable.dynamic option)) IdMap.t
include Monad.Monad_state_type with type state = s
val find_by_id : id -> (Repr.t * Typeable.dynamic option) m
module Utils (T : Typeable.Typeable) : sig
type s = (repr * (dynamic option)) IdMap.t
include Deriving_monad.Monad_state_type with type state = s
val find_by_id : id -> (Repr.t * dynamic option) m
module Utils (T : Typeable) : sig
val sum : (int * id list -> T.a m) -> id -> T.a m
val tuple : (id list -> T.a m) -> id -> T.a m
val record : (T.a -> id list -> T.a m) -> int -> id -> T.a m
val update_map : id -> (T.a -> unit m)
end
end =
struct
type s = (repr * (Typeable.dynamic option)) IdMap.t
include Monad.Monad_state (struct type state = s end)
type s = (repr * (dynamic option)) IdMap.t
include Deriving_monad.Monad_state (struct type state = s end)

let find_by_id id =
get >>= fun state ->
return (IdMap.find id state)

module Utils (T : Typeable.Typeable) = struct
module Utils (T : Typeable) = struct
let decode_repr_ctor c = match Repr.unpack_ctor c with
| (Some c, ids) -> (c, ids)
| _ -> invalid_arg "decode_repr_ctor"
Expand Down Expand Up @@ -200,8 +205,8 @@ end
module type Pickle =
sig
type a
module T : Typeable.Typeable with type a = a
module E : Eq.Eq with type a = a
module T : Typeable with type a = a
module E : Eq with type a = a
val pickle : a -> id Write.m
val unpickle : id -> a Read.m
val to_buffer : Buffer.t -> a -> unit
Expand All @@ -215,8 +220,8 @@ end
module Defaults
(S : sig
type a
module T : Typeable.Typeable with type a = a
module E : Eq.Eq with type a = a
module T : Typeable with type a = a
module E : Eq with type a = a
val pickle : a -> id Write.m
val unpickle : id -> a Read.m
end) : Pickle with type a = S.a =
Expand Down Expand Up @@ -372,16 +377,16 @@ struct
end

module Pickle_from_dump
(P : Dump.Dump)
(E : Eq.Eq with type a = P.a)
(T : Typeable.Typeable with type a = P.a)
(P : Dump)
(E : Eq with type a = P.a)
(T : Typeable with type a = P.a)
: Pickle with type a = P.a
and type a = T.a = Defaults
(struct
type a = T.a
module T = T
module E = E
module Comp = Dynmap.Comp(T)(E)
module Comp = Deriving_dynmap.Comp(T)(E)
open Write
module W = Utils(T)(E)
let pickle obj =
Expand All @@ -399,19 +404,19 @@ module Pickle_from_dump
| Some obj -> return (T.throwing_cast obj)
end)

module Pickle_unit : Pickle with type a = unit = Pickle_from_dump(Dump.Dump_unit)(Eq.Eq_unit)(Typeable.Typeable_unit)
module Pickle_bool = Pickle_from_dump(Dump.Dump_bool)(Eq.Eq_bool)(Typeable.Typeable_bool)
module Pickle_int = Pickle_from_dump(Dump.Dump_int)(Eq.Eq_int)(Typeable.Typeable_int)
module Pickle_char = Pickle_from_dump(Dump.Dump_char)(Eq.Eq_char)(Typeable.Typeable_char)
module Pickle_float = Pickle_from_dump(Dump.Dump_float)(Eq.Eq_float)(Typeable.Typeable_float)
module Pickle_num = Pickle_from_dump(Dump.Dump_num)(Eq.Eq_num)(Typeable.Typeable_num)
module Pickle_string = Pickle_from_dump(Dump.Dump_string)(Eq.Eq_string)(Typeable.Typeable_string)
module Pickle_unit : Pickle with type a = unit = Pickle_from_dump(Dump_unit)(Eq_unit)(Typeable_unit)
module Pickle_bool = Pickle_from_dump(Dump_bool)(Eq_bool)(Typeable_bool)
module Pickle_int = Pickle_from_dump(Dump_int)(Eq_int)(Typeable_int)
module Pickle_char = Pickle_from_dump(Dump_char)(Eq_char)(Typeable_char)
module Pickle_float = Pickle_from_dump(Dump_float)(Eq_float)(Typeable_float)
module Pickle_num = Pickle_from_dump(Dump_num)(Eq_num)(Typeable_num)
module Pickle_string = Pickle_from_dump(Dump_string)(Eq_string)(Typeable_string)

module Pickle_option (V0 : Pickle) : Pickle with type a = V0.a option = Defaults(
struct
module T = Typeable.Typeable_option (V0.T)
module E = Eq.Eq_option (V0.E)
module Comp = Dynmap.Comp (T) (E)
module T = Typeable_option (V0.T)
module E = Eq_option (V0.E)
module Comp = Deriving_dynmap.Comp (T) (E)
open Write
type a = V0.a option
let rec pickle =
Expand Down Expand Up @@ -441,9 +446,9 @@ module Pickle_option (V0 : Pickle) : Pickle with type a = V0.a option = Defaults
module Pickle_list (V0 : Pickle)
: Pickle with type a = V0.a list = Defaults (
struct
module T = Typeable.Typeable_list (V0.T)
module E = Eq.Eq_list (V0.E)
module Comp = Dynmap.Comp (T) (E)
module T = Typeable_list (V0.T)
module E = Eq_list (V0.E)
module Comp = Deriving_dynmap.Comp (T) (E)
type a = V0.a list
open Write
module U = Utils(T)(E)
Expand Down Expand Up @@ -471,10 +476,10 @@ struct
W.sum f id
end)
end
include Pickle
include Deriving_Pickle

type 'a ref = 'a Pervasives.ref = { mutable contents : 'a }
deriving (Pickle)
deriving (Eq,Typeable,Pickle)

(* Idea: keep pointers to values that we've serialized in a global
weak hash table so that we can share structure with them if we
Expand Down
26 changes: 15 additions & 11 deletions lib/pickle.mli → lib/deriving_Pickle.mli
@@ -1,3 +1,7 @@
open Deriving_Typeable
open Deriving_Eq
open Deriving_Dump

type id

(* representation of values of user-defined types *)
Expand All @@ -9,8 +13,8 @@ end
(* Utilities for serialization *)
module Write : sig
type s
include Monad.Monad_state_type with type state = s
module Utils (T : Typeable.Typeable) (E : Eq.Eq with type a = T.a) : sig
include Deriving_monad.Monad_state_type with type state = s
module Utils (T : Typeable) (E : Eq with type a = T.a) : sig
val allocate : T.a -> (id -> unit m) -> id m
val store_repr : id -> Repr.t -> unit m
end
Expand All @@ -19,8 +23,8 @@ end
(* Utilities for deserialization *)
module Read : sig
type s
include Monad.Monad_state_type with type state = s
module Utils (T : Typeable.Typeable) : sig
include Deriving_monad.Monad_state_type with type state = s
module Utils (T : Typeable) : sig
val sum : (int * id list -> T.a m) -> (id -> T.a m)
val tuple : (id list -> T.a m) -> (id -> T.a m)
val record : (T.a -> id list -> T.a m) -> int -> (id -> T.a m)
Expand All @@ -33,8 +37,8 @@ exception UnknownTag of int * string
module type Pickle =
sig
type a
module T : Typeable.Typeable with type a = a
module E : Eq.Eq with type a = a
module T : Typeable with type a = a
module E : Eq with type a = a
val pickle : a -> id Write.m
val unpickle : id -> a Read.m
val to_buffer : Buffer.t -> a -> unit
Expand All @@ -48,8 +52,8 @@ end
module Defaults
(S : sig
type a
module T : Typeable.Typeable with type a = a
module E : Eq.Eq with type a = a
module T : Typeable with type a = a
module E : Eq with type a = a
val pickle : a -> id Write.m
val unpickle : id -> a Read.m
end) : Pickle with type a = S.a
Expand All @@ -66,7 +70,7 @@ module Pickle_list (V0 : Pickle) : Pickle with type a = V0.a list
module Pickle_ref (S : Pickle) : Pickle with type a = S.a ref

module Pickle_from_dump
(P : Dump.Dump)
(E : Eq.Eq with type a = P.a)
(T : Typeable.Typeable with type a = P.a)
(P : Dump)
(E : Eq with type a = P.a)
(T : Typeable with type a = P.a)
: Pickle with type a = P.a

0 comments on commit dfbc666

Please sign in to comment.