-
Notifications
You must be signed in to change notification settings - Fork 84
/
timeLangScript.sml
189 lines (141 loc) · 3.35 KB
/
timeLangScript.sml
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
(*
Abstract syntax for timeLang
*)
open preamble
stringTheory mlstringTheory mlintTheory
val _ = new_theory "timeLang";
Overload CVar[inferior] = “strlit”
val _ = set_grammar_ancestry
["mlint"];
(* location identifies TA-states *)
Type loc = ``:num``
(* state specific input and output *)
Type in_signal = ``:num``
Type out_signal = ``:num``
Datatype:
ioAction = Input in_signal
| Output out_signal
End
(*
IMP:
time:rat in the Coq formalism,
Pancake has discrete time:num *)
Type time = ``:num``
(* clock variables *)
Type clock = ``:mlstring``
Type clocks = ``:clock list``
(* time expression *)
Datatype:
expr = ELit time
| EClock clock
| ESub expr expr
End
(* relational time expression *)
Datatype:
cond = CndLe expr expr (* e <= e *)
| CndLt expr expr (* e < e *)
End
Datatype:
term = Tm ioAction
(cond list)
clocks
loc
((time # clock) list) (* to calculate wait time *)
End
(*
Type program = ``:(loc # term list) list``
*)
Type program = ``:(loc # term list) list # time option``
(* functions for compiler *)
Definition termConditions_def:
(termConditions (Tm _ cs _ _ _) = cs)
End
Definition termWaitTimes_def:
(termWaitTimes (Tm _ _ _ _ wt) = wt)
End
Definition termDest_def:
(termDest (Tm _ _ _ loc _) = loc)
End
Definition termAction_def:
(termAction (Tm io _ _ _ _) = io)
End
Definition terms_out_signals_def:
(terms_out_signals [] = []) ∧
(terms_out_signals (Tm (Output out) _ _ _ _::tms) =
out :: terms_out_signals tms) ∧
(terms_out_signals (Tm (Input _) _ _ _ _::tms) =
terms_out_signals tms)
End
Definition terms_in_signals_def:
(terms_in_signals [] = []) ∧
(terms_in_signals (Tm (Input i) _ _ _ _::tms) =
i :: terms_in_signals tms) ∧
(terms_in_signals (Tm (Output _) _ _ _ _::tms) =
terms_in_signals tms)
End
Definition accumClks_def:
(accumClks ac [] = ac) ∧
(accumClks ac (clk::clks) =
if MEM clk ac
then accumClks ac clks
else accumClks (clk::ac) clks)
End
Definition exprClks_def:
exprClks clks e =
case e of
| ELit t => clks
| EClock clk =>
if MEM clk clks then clks else clk::clks
| ESub e1 e2 =>
exprClks (exprClks clks e1) e2
End
Definition clksOfExprs_def:
clksOfExprs es = FOLDL exprClks [] es
End
Definition destCond_def:
(destCond (CndLe e1 e2) = [e1; e2]) ∧
(destCond (CndLt e1 e2) = [e1; e2])
End
Definition condClks_def:
condClks cd = clksOfExprs (destCond cd)
End
Definition condsClks_def:
condsClks cds = clksOfExprs (FLAT (MAP destCond cds))
End
Definition termClks_def:
termClks (Tm _ _ clks _ _) = clks
End
Definition clksOf_def:
clksOf prog =
let tms = FLAT (MAP SND prog) in
accumClks [] (FLAT (MAP termClks tms))
End
Definition nClks_def:
nClks prog = LENGTH (clksOf prog)
End
Definition termInvs_def:
termInvs (Tm _ _ _ _ tes) = MAP FST tes
End
Definition initTerm_def:
(initTerm (t::ts) = t) ∧
(initTerm [] = [])
End
Definition initLoc_def:
initLoc = 0:num
End
Definition waitSet_def:
(waitSet (Tm _ _ _ _ []) = 0:num) ∧
(waitSet _ = 1:num)
End
Definition inputSet_def:
(inputSet (Tm _ _ _ _ []) = 1:num) ∧
(inputSet _ = 0:num)
End
Definition out_signals_def:
out_signals prog =
let
tms = FLAT (MAP SND prog)
in
MAP num_to_str (terms_out_signals tms)
End
val _ = export_theory();