package lutin

  1. Overview
  2. Docs
Lutin: modeling stochastic reactive systems

Install

Dune Dependency

Authors

Maintainers

Sources

lutin.2.71.10.tgz
md5=4d07d1263dbc90ab18cbaec55a57dcfe
sha512=2e899aee5e44826827b3626771f7ce01241b1745d48f30b60404cc5cbaa44ac608920e9af3bf171275c429a8b823b3cee7542199b7c4c32919b6bb37e33bf8de

doc/src/lutin/type.ml.html

Source file type.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
(*-----------------------------------------------------------------------
** Copyright (C) - Verimag.
** This file may only be copied under the terms of the CeCill
** Public License
**-----------------------------------------------------------------------
**
** File: type.ml
** Author: erwan.jahier@univ-grenoble-alpes.fr
*)



type enum_value = string
type field = string

type t =
  | BoolT
  | IntT
  | FloatT
  | UT of structured
and
  structured =
  | ArrayT  of int * t
  | StructT of (field * t) list
  | EnumT   of enum_value list


let rec (typ_to_string_param : string -> t -> string) =
  fun float vt ->
    match vt with
	BoolT -> "bool"
      | IntT -> "int"
      | FloatT -> float

      | UT(ut) -> structured_to_string_param float ut
and
  (structured_to_string_param : string -> structured -> string) =
  fun float ut ->
    match ut with
      | ArrayT(i, t) ->
	  ((typ_to_string_param float t) ^ "^" ^ (string_of_int i))
      | StructT(fl) -> (
	  (List.fold_left
	     (fun acc (fn, ft) ->
		(acc ^ fn ^":"^ (typ_to_string_param float ft) ^ "; ")
	     )
	     "{"
	     fl)
	  ^ "}")
      | EnumT(el) -> (
	  let _ = assert (el <> []) in
	    ( List.fold_left
		(fun acc e -> (acc ^ ", " ^ e))
		("(" ^ (List.hd el) )
		(List.tl el)
	    ) ^ ")")


let to_string = typ_to_string_param "float"
let to_string2 = typ_to_string_param "real"
let to_string3 = typ_to_string_param "double"

let structured_to_string = structured_to_string_param "real"


(****************************************************************************)

(* exported  *)
let rec (to_cstring : t -> string) =
  fun vt ->
    match vt with
	BoolT -> "_bool"
      | IntT -> "_int"
      | FloatT -> "_real"

      | UT(ut) -> structured_to_cstring ut
and

  (structured_to_cstring : structured -> string) =
  fun  ut ->
    match ut with
      | ArrayT(i, t) ->
	  ((to_cstring t) ^ "^" ^ (string_of_int i))
      | StructT(fl) -> (
	  (List.fold_left
	     (fun acc (fn, ft) ->
		(acc ^ fn ^":"^ (to_cstring ft) ^ "; ")
	     )
	     "{"
	     fl)
	  ^ "}")
      | EnumT(el) -> (
	  let _ = assert (el <> []) in
	    ( List.fold_left
		(fun acc e -> (acc ^ ", " ^ e))
		("(" ^ (List.hd el) )
		(List.tl el)
	    ) ^ ")")


(* exported  *)
let rec (to_cstring_bis : t -> string) =
  fun vt ->
    match vt with
	BoolT -> "bool"
      | IntT -> "int"
      | FloatT -> "real"
      | UT(ut) -> structured_to_cstring_bis ut
and
  (structured_to_cstring_bis : structured -> string) =
  fun  ut ->
    match ut with
      | ArrayT(i, t) ->
	  ((to_cstring_bis t) ^ "^" ^ (string_of_int i))
      | StructT(fl) -> (
	  (List.fold_left
	     (fun acc (fn, ft) ->
		(acc ^ fn ^":"^ (to_cstring_bis ft) ^ "; ")
	     )
	     "{"
	     fl)
	  ^ "}")
      | EnumT(el) -> (
	  let _ = assert (el <> []) in
	    ( List.fold_left
		(fun acc e -> (acc ^ ", " ^ e))
		("(" ^ (List.hd el) )
		(List.tl el)
	    ) ^ ")")

let rec (to_data_t : t -> Data.t) = 
  function
    | BoolT  -> Data.Bool
    | IntT   -> Data.Int
    | FloatT -> Data.Real
    | UT (ArrayT(n,a)) -> Data.Array(to_data_t a,n)
    | UT (StructT fl) -> Data.Struct ("struct", (List.map (fun (id,t) -> id, to_data_t t) fl))
    | UT (EnumT el) -> Data.Enum ("enum", el)


OCaml

Innovation. Community. Security.