-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdromd.ml
More file actions
217 lines (204 loc) · 6.07 KB
/
dromd.ml
File metadata and controls
217 lines (204 loc) · 6.07 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
(*
* dromd.ml
* This file is part of dromd
*
* Copyright (C) 2013 - Enrico Polesel and Alessadro Achille
*
* dromd is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* dromd is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dromd. If not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc., 51 Franklin Street,
* Fifth Floor, Boston, MA 02110-1301 USA.
*)
#use "semantic.ml"
let env = function
| name -> raise (Failure (String.concat "" [ "Name not found: " ; name ]))
;;
let sto =
1 ,
(
function
| _ -> raise (Failure "Segmentation Fault")
)
;;
let test1 =
Ssequence (
Svar ( "f" , Fexp (Fdefine ( "variabilePnt" ,
Ssequence (
SassignPnt (Avar "variabilePnt" , Aexp (Aplus (Apnt2val (Avar "variabilePnt"), Anum 1))),
Sprint ( Aexp (Apnt2val (Avar "variabilePnt")))
),
Aexp (Aplus ( Apnt2val (Avar "variabilePnt") , Anum 10 ))))),
Ssequence (
Slet ("costante", Aexp (Anum 5)),
Ssequence (
Svar ( "variabile" , Aexp (Aneg (Avar "costante"))),
Ssequence (
Svar ( "result" , Aexp (Anum 9999)),
Ssequence (
Scall ("result", Fvar "f", Aexp (Avar2pnt "variabile")),
Ssequence (
Sprint (Aexp (Avar "result")),
Ssequence (
Sblock (
Ssequence (
Svar ( "lambda" , Aexp (Anum 10 )),
Sassign ( "f" , Fexp ( Fdefine ( "t" , Sprint ( Aexp (Aprod (Avar "t", Avar "lambda"))) , Aexp (Aprod (Avar "t", Avar "lambda")) )))
)
),
Ssequence (
SvarArray ( "array" , Anum 5 , Anum 0 ),
Ssequence (
Sblock (
Ssequence (
Svar ( "i" , Aexp (Anum 0)),
Swhile ( Band (Bleq ( Avar "i" , Anum 5 ) , Bnot ( Bequal ( Avar "i" , Anum 5))) ,
Ssequence (
SassignArray ( "array" , Avar "i" , Avar "i"),
Sassign ("i" , Aexp (Aplus (Avar "i", Anum 1 )))
)
)
)
),
Ssequence (
SmapArray ("array", Fvar "f"),
SiterArray ("array", Fvar "f")
)
)
)
)
)
)
)
)
)
)
;;
Printf.printf "%s\n" "---- Code ----";;
Printf.printf "%s\n" (stm_to_str test1 0);;
Printf.printf "%s\n" "---- Result ----";;
let (env1, sto1) = sem test1 env sto;;
let test2 =
Ssequence (
Slet("l",Lexp (LpushFront (Anum 5, LpushFront (Anum 7, (LpushFront (Anum 4, Lempty)))))),
Ssequence (
Slet("f", Fexp ( Fdefine ("x", (Sprint (Aexp (Aplus(Avar "x",Anum 1)))),Aexp (Avar "x")))),
SiterList(Lvar "l", Fvar "f");
)
)
;;
Printf.printf "%s\n" "---- Code ----";;
Printf.printf "%s\n" (stm_to_str test2 0);;
Printf.printf "%s\n" "---- Result ----";;
let (env1, sto1) = sem test2 env sto;;
(*
let test3 =
Ssequence (
Slet("l",Lexp (LpushFront (Anum 5, LpushFront (Anum 7, (LpushFront (Anum 4, Lempty)))))),
Ssequence (
Slet("f", Fexp ( Fdefine ("x", (Sskip),Aexp (Aplus(Avar "x",Anum 1))))),
Ssequence(
Slet("map", Fexp ( Fdefine ("arg", (
Ssequence (
Slet("res", Lexp Lempty),
Ssequence (
Svar ("y", Aexp (Anum 0)),
Swhile (BisListEmpty (Lvar "l"),
Ssequence (
Scall ("y", Fpair2fun (Pproj1(Pvar "arg")), Aexp (AlistHead (Lpair2list (Pproj2 (Pvar "arg"))))),
Ssequence (
Sassign("res", Lexp (LpushFront (Avar "y", Lvar "res"))),
Slet ("l", Lexp (Ltail (Lvar "l")))
))
)
))),
Lexp (Lvar "res")
))
),
Ssequence(
Svar("z", Lexp Lempty),
Ssequence(
Scall ("z",Fvar "map", Pexp (Pexpexp(Fexp (Fvar "f"), Lexp (Lvar "l")))),
Sprint (Lexp (Lvar "l"))
)))))
;;
Printf.printf "%s\n" "---- Code ----";;
Printf.printf "%s\n" (stm_to_str test3 0);;
Printf.printf "%s\n" "---- Result ----";;
let (env1, sto1) = sem test3 env sto;;
*)
let test4 =
Ssequence (
Slet("l",Lexp (LpushFront (Anum 5, LpushFront (Anum 7, (LpushFront (Anum 4, Lempty)))))),
Ssequence (
Slet("f", Fexp ( Fdefine ("x", (Sprint (Aexp (Aplus(Avar "x",Anum 1)))),Aexp (Anum 0)))),
Ssequence(
Slet("iter", Fexp ( Fdefine ("arg", (
Ssequence (
Slet ("l", Lexp (Lpair2list (Pproj2 (Pvar "arg")))),
Ssequence (
Svar ("y", Aexp (Anum 0)),
Swhile (Bnot (BisListEmpty (Lvar "l")),
Ssequence (
Scall ("y", Fpair2fun (Pproj1(Pvar "arg")), Aexp (AlistHead (Lvar "l"))),
Slet ("l", Lexp (Ltail (Lvar "l")))
)
)
))),
Aexp (Anum 0)
))
),
Ssequence(
Svar("z", Aexp (Anum 0)),
Scall ("z",Fvar "iter", Pexp (Pexpexp(Fexp (Fvar "f"), Lexp (Lvar "l"))))
))))
;;
Printf.printf "%s\n" "---- Code ----";;
Printf.printf "%s\n" (stm_to_str test4 0);;
Printf.printf "%s\n" "---- Result ----";;
let (env1, sto1) = sem test4 env sto;;
let test5 =
Ssequence (
Svar ("f", Fexp (Fdefine ("n", Sskip, Aexp (Anum 0)))),
Ssequence (
Sassign("f", Fexp (
Fdefine ("n",
Ssequence (
Svar ("r",Aexp (Anum 0)),
Ssequence (
Svar ("r1",Aexp (Anum 0)),
Ssequence (
Svar ("r2",Aexp (Anum 0)),
Sifthenelse (
Bor (Bequal (Avar "n", Anum 0), Bequal (Avar "n", Anum 1)),
Sassign ("r", Aexp (Anum 1)),
Ssequence (
Scall("r1",Fvar "f",Aexp (Aminus (Avar "n", Anum 1))),
Ssequence (
Scall("r2",Fvar "f",Aexp (Aminus (Avar "n", Anum 2))),
Sassign ("r", Aexp (Aplus (Avar "r1", Avar "r2")))
))
))))
,
Aexp (Avar "r")))
),
Ssequence(
Svar("z", Aexp (Anum (-10))),
Ssequence(
Scall ("z",Fvar "f", Aexp (Anum 6)),
Sprint (Aexp (Avar "z"))
))))
;;
Printf.printf "%s\n" "---- Code ----";;
Printf.printf "%s\n" (stm_to_str test5 0);;
Printf.printf "%s\n" "---- Result ----";;
let (env1, sto1) = sem test5 env sto;;