source: Deliverables/Dissemination/final-review/wp5/Pics/summul_result_c.ml @ 3282

Last change on this file since 3282 was 3282, checked in by regisgia, 7 years ago
  • WP5 slides for the final review.
File size: 2.7 KB
Line 
1
2open Mlpost;;
3open Box;;
4open Arrow;;
5open Path;;
6open Command;;
7open Num;;
8open Dash;;
9open Color;;
10open Pen;;
11open Point;;
12open Picture;;
13
14
15let box = Box.box ~stroke:None ~dx:zero ~dy:zero
16let path = Box.path ~stroke:None ~dx:zero ~dy:zero
17let pic = Box.pic ~stroke:None ~dx:zero ~dy:zero
18
19(* Helpers *)
20
21let string_of_list sep f =
22  let rec aux = function
23    | [] -> ""
24    | [e] -> f e
25    | e :: l -> (f e) ^ sep ^ (aux l)
26  in
27  aux
28
29
30(* Text *)
31
32let color_text color text = "\\textcolor{" ^ color ^ "}{" ^ text ^ "}"
33let color_bftext color text = "\\textcolor{" ^ color ^ "}{\\bf " ^ text ^ "}"
34let texttt text = "\\texttt{" ^ text ^ "}"
35
36let line lexs =
37  Box.tex (texttt (string_of_list " " (fun s -> s) lexs))
38
39let lines l =
40  let f (b_prev, b_res) (indent, lexs) =
41    let b_line = line lexs in
42    let b_line = Box.place `Southwest ~pos:`Northwest b_prev b_line in
43    let indent = float_of_int indent in
44    let shft = Point.pt (Num.multf indent (cm 0.4), zero) in
45    let b_line = Box.shift shft b_line in
46    (b_line, b_res @ [b_line])
47  in
48  let (_, b_res) = List.fold_left f (Box.empty (), []) l in
49  Box.group b_res
50
51let typ = color_bftext "black"
52let funct = color_text "blue"
53let keyword = color_bftext "black"
54let var = color_text "black"
55let label s = color_text "magenta" s
56
57let kwhile = keyword "while"
58let kif = keyword "if"
59let kreturn = keyword "return"
60
61let typ_int = typ "int"
62
63let args l =
64  let f (t, x) = (typ t) ^ " " ^ (var x) in
65  "(" ^ (string_of_list ", " f l) ^ ")"
66
67let line1 = [typ_int ; funct "summul" ; args [("int", "n")] ; "\\{"]
68let line2 = [typ_int ; (var "accu") ^ " = 1;"]
69let line3 = [typ_int ; (var "stop") ^ " = 1;"]
70let line4 = [typ_int ; (var "k") ^ " = n;"]
71let line41 = [label "\\_cost2:"]
72let line42 = ["accu = 1;"]
73let line43 = ["stop = 1;"]
74let line44 = ["k = n;"]
75let line5 = [kwhile ; "(k >= stop)" ; "\\{"]
76let line51 = [label "\\_cost3:"]
77let line6 = ["accu += accu * k;"]
78let line7 = ["k -= 1;" ; "\\}"]
79let line71 = [label "\\_cost4:"]
80let line8 = [kreturn ; "(accu);"]
81let line81 = ["\\}"]
82let line9 = [typ "void" ; funct "main" ; args [] ; "\\{"]
83let line10 = [typ_int ; (var "i") ^ ";"]
84let line11 = [label "\\_cost1:"]
85let line12 = ["i = summul(5);" ; "\\}"]
86
87let summul = lines [(0, line1) ; (0, line41); (1, line2) ; (0, line3) ; (0, line4) ;
88(*                  (0, line41) ; (0, line42) ; (0, line43) ; (0, line44) ; *)
89                    (0, line5) ; (1, line51) ; (0, line6) ; (0, line7) ;
90                    (-1, line71) ; (0, line8); (-1, line81)]
91
92let main = lines [(0, line9) ; (1, line10) ; (0, line11) ; (0, line12)]
93
94
95(* Place Text *)
96
97
98(* Strokes and arrows *)
99
100
101(* Main *)
102
103let summul_result_c = Box.hbox ~pos:`Top ~padding:(cm 1.) [summul]
104
105let summul_result_c = Box.draw summul_result_c
106
107let _ = Metapost.emit "summul_result_c" summul_result_c
Note: See TracBrowser for help on using the repository browser.