source: Deliverables/Dissemination/final-review/wp5/Pics/summul_clight.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.2 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_res (indent, lexs) =
41    let b_line = line lexs in
42    let b_line = Box.place `Southwest ~pos:`Northwest b_res 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    Box.group [b_res ; b_line]
47  in
48  List.fold_left f (Box.empty ()) l
49
50let typ = color_bftext "black"
51let funct = color_text "blue"
52let keyword = color_bftext "black"
53let var = color_text "black"
54
55let kwhile = keyword "while"
56let kif = keyword "if"
57let kreturn = keyword "return"
58
59let typ_int = typ "int"
60
61let args l =
62  let f (t, x) = (typ t) ^ " " ^ (var x) in
63  "(" ^ (string_of_list ", " f l) ^ ")"
64
65let line1 = [typ_int ; funct "summul" ; args [("int", "n")] ; "\\{"]
66let line2 = [typ_int ; var "accu" ; "= 1;"]
67let line3 = [typ_int ; var "stop" ; "= 1;"]
68let line4 = [typ_int ; var "k" ; "= n;"]
69let line5 = [kwhile ; "(k >= stop)" ; "\\{"]
70let line6 = ["accu += accu * k;"]
71let line7 = ["k -= 1;"]
72let line71 = [ "\\}" ]
73let line8 = [kreturn ; "(accu);" ]
74let line81 = [ "\\}" ]
75let line9 = [typ "void" ; funct "main" ; args [] ; "\\{"]
76let line10 = [typ_int ; var "i" ; " = summul(5);"]
77let line12 = ["\\}"]
78
79let program = lines [
80  (0, line1) ; (1, line2) ; (1, line3) ; (1, line4) ;
81  (1, line5) ; (2, line6) ; (2, line7) ; (1, line71) ;
82  (1, line8) ; (0, line81); 
83]
84
85(* Place Text *)
86
87
88(* Strokes and arrows *)
89
90
91(* Main *)
92
93let summul_clight = program
94
95let summul_clight = Box.draw summul_clight
96
97let _ = Metapost.emit "summul_clight" summul_clight
Note: See TracBrowser for help on using the repository browser.