(* 
 File: Pepa.sml

 Datatypes of the PEPA Workbench.
*)

structure Pepa :> Pepa =
struct
  type Identifier = HashTable.hashedstring 

  type Name = int

  datatype Component =  
	  PREFIX of (Identifier * Expressions.Aexp) * Component
(* 	  PREFIX of (Identifier * Identifier) * Component *)
	| CHOICE of Component * Component
	(* gcla - remove later *)
	| COOP   of Component list * Identifier list
(* 	| COOP   of Component * Component * Identifier list *)
	| HIDING of Component * Identifier list
	| VAR    of Identifier
	| CONSTS of Identifier * Component * Component

  type State = Component

  type Environment = (Identifier * Component) list

  fun pequals ((PREFIX((i1,e1),p1)),(PREFIX((i2,e2),p2))) =
     (i1=i2) andalso (Expressions.aequals(e1,e2)) andalso (pequals(p1,p2))
    | pequals ((CHOICE(p1,q1)),(CHOICE(p2,q2))) =
      (pequals(p1,p2)) andalso (pequals(q1,q2))
    | pequals ((COOP([],i1)),(COOP([],i2))) =
      (i1=i2)
    | pequals ((COOP((h1::t1),i1)),(COOP((h2::t2),i2))) =
      (pequals(h1,h2)) andalso (pequals((COOP(t1,i1)), (COOP(t2,i2))))
    | pequals ((HIDING(p1,i1)),(HIDING(p2,i2))) =
      (pequals(p1,p2)) andalso (i1=i2)
    | pequals ((VAR(i1)), (VAR(i2))) =
      (i1=i2)
    | pequals ((CONSTS(i1,p1,q1)),(CONSTS(i2,p2,q2))) =
      (i1=i2) andalso (pequals(p1,p2)) andalso (pequals(q1,q2))
    | pequals (_,_) = false;

     
(*   type Transition = Component *  *)
(*        ((Identifier * Identifier) * Name) option * Component *)

(*   type MultiTransition = Component *  *)
(*        ((Identifier * string) * Name) option * Component *)

  type Transition = Component * 
       ((Identifier * Expressions.Aexp) * Name) option * Component

  type MultiTransition = Component * 
       ((Identifier * Expressions.Aexp) * Name) option * Component

(* 
   Identifiers and Names 
   =====================
   An identifier is an alphanumeric descriptor assigned by the PEPA modeller
   whereas a name is a numeric stamp computed by the PEPA Workbench to allow
   the workbench to distinguish between repeated occurrences of a component.
   Names are assigned by the `derivative' function on traversing the tree
   of the abstract syntax of the PEPA model.  Names are assigned thus:

                               0
                              / \
                             1   2
                            / \ / \
                           3  4 5  6
   
   doubling as we go down the tree and adding 1 if we go left and 2 if we go 
   right.  This will make a distinction between P <> P <> P <> P, numbering the
   copies 1, 5, 13 and 14 and a bushier tree, (P <> P) <> (P <> P), numbering
   these copies 3, 4, 5, 6.  In either case the effect is the same: to have
   unique numbers for the leaves of the tree (the sequential components) and 
   the nodes (the cooperations).
*)

end;
