Commit f3744b6d authored by POTTIER Francois's avatar POTTIER Francois

Programming project: publish LICENSE, AUTHORS, and new test files.

parent 8485cc50
The authors of this programming project are:
Assignment (sujet.pdf) François Pottier.
Source code (src) François Pottier.
Source code (src/kremlin) Jonathan Protzenko.
Test files (src/tests) The students of the course MPRI 2.4, 2017-2018.
This programming project is distributed under an Apache 2.0 license.
This diff is collapsed.
......@@ -18,9 +18,19 @@ let verbosity =
let usage =
sprintf "Usage: %s\n" argv.(0)
let good =
ref None
let root =
ref None
let spec = Arg.align [
"--create-expected", Arg.Set create_expected,
" recreate the expected-output files";
"--test", Arg.String (fun d -> good := Some d),
"<directory> set test directory (default: $root/tests)";
"--root", Arg.String (fun d -> root := Some d),
"<directory> set root directory (default: ..)";
"--verbosity", Arg.Int ((:=) verbosity),
" set the verbosity level (0-2)";
]
......@@ -68,13 +78,21 @@ let command cmd =
(* Paths. *)
let root =
absolute_directory ".."
match !root with
| Some root ->
root
| None ->
absolute_directory ".."
let src =
root
let good =
root ^ "/tests"
match !good with
| Some good ->
good
| None ->
root ^ "/tests"
let good_slash filename =
good ^ "/" ^ filename
......
let double = fun f -> fun x -> f (f x) in
let succ = fun x -> x + 1 in
print (double double double succ 0)
\ No newline at end of file
1000000000
1100000000
1110000000
1111000000
1111100000
1111110000
1111111000
1111111100
1111111110
1111111111
let rec exp = fun e -> fun n -> ifzero n then 1 else e * exp e (n-1) in
let rec lots_digit = fun d -> fun n -> ifzero (n-1) then d else d + 10 * lots_digit d (n-1) in
let line = fun i -> fun n -> lots_digit 1 i * exp 10 (n-i) in
let rec triangle = fun i -> fun n ->
ifzero (n-i)
then print (line n n)
else (let _ = print (line i n) in triangle (i+1) n) in
triangle 1 10
let id = fun x -> x in
print( id 42 )
(* Thunks. *)
(* Church naturals. *)
let zero = fun f -> fun x -> x in
let one = fun f -> fun x -> let _ = print 422 in f x in
let plus = fun m -> fun n -> fun f -> fun x -> m f (n f x) in
let two = plus one one in
let three = plus one two in
let convert = fun n -> let _ = print 21 in n (fun x -> x + 1) 0 in
let _ = print (convert three) in
print 42
let x=1 in let y = x+1 in let z = y in print z
let x = 1 in let y = x in let z = y in print (z + y)
let f = fun x -> x in
print (f 42)
let print_fun = fun y -> print y in
(fun f -> fun x -> f x) print_fun 10
let print_fun = fun a -> fun b -> print (print (a + b)) in
let fonction = fun f -> fun x -> fun y -> (f y) x in
fonction print_fun 13 7
let x = 5 in
let print_fun = fun y -> print y in
let ma_fonction = fun f -> f x in
ma_fonction print_fun
let f = fun x -> x + 2 in
print(f 3 + f 4)
\ No newline at end of file
let r = 1 in
let f = fun x -> print r in
let r = 2 in
f 1
let rec f = fun x -> 0 in
let rec g = fun x ->
(fun y -> x + y)
in
let rec h = fun x ->
print x
in
let _ = print (f 53) in
let _ = print (g 63 37) in
let _ = print (h 88888) in
print 1
let test1 = 2 in
let _ = print test1 in
let test2 = fun y -> ( fun x -> x + y + 3) in
let _ = print ((test2 test1) test1) in
let rec test_f1 = fun y -> ((y - 2)*3)/3 in
let _ = print (test_f1 4) in
let _ = ifzero 0 then print 5 else print 1 in
let test_if = ifzero 1 then fun x -> x +1 else fun y -> y+2
in
let _ = print (test_if 3) in
let rec test_frec1 = fun x ->
(ifzero x then test_frec1 (x-1) else print 2)
in
let _ = print (test_frec1 5) in
print (print 5)
0
0
0
1
7
5
4
3
5
0
82
(* Pairs *)
let pair = fun x -> fun y -> fun p -> p x y in
let fst = fun p -> p (fun x -> fun y -> x) in
let snd = fun p -> p (fun x -> fun y -> y) in
(* Euclidian Division *)
let rec diveuclid = fun a -> fun b ->
ifzero a
then pair 0 0
else
let p = diveuclid (a-1) b in
let q = fst p in
let r = snd p in
ifzero (r+1 - b)
then pair (q+1) 0
else pair q (r+1)
in
let p = diveuclid 0 999 in
let _ = print (fst p) in
let _ = print (snd p) in
let p = diveuclid 1 2 in
let _ = print (fst p) in
let _ = print (snd p) in
let p = diveuclid 54 7 in
let _ = print (fst p) in
let _ = print (snd p) in
let p = diveuclid 35 8 in
let _ = print (fst p) in
let _ = print (snd p) in
let p = diveuclid 10 2 in
let _ = print (fst p) in
let _ = print (snd p) in
print 82
let r =
ifzero ((fun x -> fun y -> 2 * x - y) 5 10)
then ((fun x -> 6 * x) 111)
else 0
in
print r
let rec fact2 = fun n -> fun r ->
ifzero n then
r
else
fact2 (n - 1) (n * r)
in
print (fact2 7 1)
let rec fib = fun n ->
ifzero n then 0
else ifzero (n - 1) then 1
else (fib (n - 1) + fib (n - 2)) in
print(fib 5)
let fst = fun x -> fun y -> x in
print (fst 1 2)
let f = fun x -> x + 1 in
let g = f in
print (g 4)
let f = fun x -> x in
let g = fun f -> f in
print(g (f 0))
print ((print 12) + (print 30))
let x = 1 + 1 in
let y = ifzero (x - 2) then 36 else 0 in
print y
let x = ifzero 1 then 2 else print 21 in
let y = ifzero 0 then 20 + 1 else 0 in
print (x+y)
let rec fib = fun n ->
ifzero n then
0
else ifzero (n-1) then
1
else
fib (n-1) + fib (n-2)
in
print (fib 10)
let i = fun x -> x in
let k = fun x -> fun y -> x in
let zero = fun f -> i in
let one = fun f -> fun x -> f x in
let plus = fun m -> fun n -> fun f -> fun x -> m f (n f x) in
let succ = plus one in
let mult = fun m -> fun n -> fun f -> m (n f) in
let exp = fun m -> fun n -> n m in
let two = succ one in
let three = succ two in
let six = mult two three in
let seven = succ six in
let twenty_one = mult three seven in
let forty_two = mult two twenty_one in
let convert = fun n -> n (fun x -> x + 1) 0 in
let nothing =
ifzero convert forty_two then
print 0
else
print 1
in
ifzero convert zero then
print 1
else
print 0
let succeed = fun x -> print 1 in
let fail = fun x -> print 0 in
let true = fun x -> 0 in
let false = fun x -> 1 in
let nothing = ifzero true 0 then succeed 0 else fail 0 in
ifzero false 0 then fail 0 else succeed 0
let _ = print ((ifzero 0 then fun x -> x else fun x -> x + 1) 3) in
let _ = print ((ifzero 1 then fun x -> x else fun x -> x + 1) 3) in
let ifprint = fun x -> print (ifzero x then 3 else 4) in
let _ = ifprint 0 in
ifprint 1
\ No newline at end of file
let test = fun x -> fun y ->
ifzero x then
ifzero y then
fun z -> z+13
else
fun z -> z+37
else
ifzero y then
fun z -> z+42
else
fun z -> z+57
in
let _ = print (test 0 0 100) in
let _ = print (test 0 7 100) in
let _ = print (test 4 0 100) in
let _ = print (test 9 (0-1) 100) in
print (0-1)
let _ = print (ifzero 1 then 3 else 4) in
let _ = print (ifzero 0 then 3 else 4) in
let _ = print (ifzero (fun x -> x) 0 then 3 else 4) in
let succ = fun x -> x + 1 in print (ifzero 0 then succ 2 else succ 3)
print(ifzero (fun x -> x)0 then 3 + 5 else 9 + 10)
\ No newline at end of file
print(ifzero (fun x -> x)2 then 3 + 5 else 9 + 10)
\ No newline at end of file
ifzero 2 then print(2) else print(3)
\ No newline at end of file
ifzero 0 then print(2) else print(3)
let x = 0 in
ifzero x then print(x+1) else print(x)
\ No newline at end of file
let x = 2 in
ifzero x then print(x+1) else print(x-1)
\ No newline at end of file
let x =
let f = fun x -> x + x in
let y = f 5 in
let g = fun x ->
let h = fun x -> fun y -> x - 3 * y in
let k = h 3 in
let z = k y in
z / 2
in
f (let z = g 4 in z - 1)
in
print x
(* The CPS translation optimizes an identity
* let expression here. *)
let a = (fun x -> x + x) 45 in
print a
(* A CPS translation without renaming would capture
* the variable x in a continuation context. *)
let f = fun x -> x + (let x = 3 in x) in
print (f 5)
let sum = fun x -> fun y -> x + y in
print(sum 40 2)
let rec print_n = fun cur -> fun n ->
ifzero n - cur then
0
else
let x = print 0 in
print_n (cur + 1) n
in
print_n 0 10
let x = 3 in let y = x in let z = y in print(z)
\ No newline at end of file
let id = fun x -> x in
print (id id 42)
let id = fun x -> x in
print (id id 42)
\ No newline at end of file
let pair = fun x -> fun y -> fun p -> p x y in
let fst = fun p -> p (fun x -> fun y -> x) in
let snd = fun p -> p (fun x -> fun y -> y) in
let _ = print (fst (pair 183 0)) in
let _ = print (snd (pair 0 681)) in
let _ = print ((fst (pair 9 3)) / (snd (pair 9 3))) in
print 2
let f = fun x -> fun y -> fun z -> x z
in
let g = f (fun c -> c + 1) in
print (g 4 7)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment