Commits

Paweł Wieczorek committed 54e5054

samples -> examples

Comments (0)

Files changed (62)

examples/CWCPS/Parsing/000_samples.ml

+let a = f x
+
+let fix f a = g x
+
+let fix f a = g a
+and g b = f b
+
+let fix f x = 
+    let fix g y = h y 
+        and h y = g y in
+    g a
+
+let fix f c a = 
+    let primop v = a + a in
+    c v

examples/CWCPS/Transformation/closure_record_fields.cwcps

+
+let fix f a k = k a in
+
+
+let record r = (f at 0) in
+
+f r TOPCONT 

examples/CWCPS/Transformation/frac.cwcps

+let 
+    fix f x y = 
+        if primop x = 0 
+            then 
+                y 1 
+            else 
+                let primop j = x - 1 in 
+                let 
+                    fix h z = 
+                        let primop v = x * z in 
+                        y v 
+                in 
+                f j h
+    in 
+f 3 TOPCONT 

examples/CWCPS/Transformation/simple_adder.cwcps

+
+let fix f x fk =
+    let fix g y gk =
+        let fix h z hk = 
+            let primop r1 = x + y in
+            let primop r2 = r1 + z in
+            hk r2
+            in
+        gk h
+        in
+    fk g
+    in
+
+let fix kont2 res2 = res2 1 TOPCONT in
+
+let fix kont1 res1 = res1 1 kont2 in
+
+
+f 1 kont1
+
+
+
+

examples/CWCPS/a.cwcps

+
+let fix f x fk =
+    let fix g y gk =
+        let fix h z hk = 
+            let primop r1 = x + y in
+            let primop r2 = r1 + z in
+            hk r2
+            in
+        gk h
+        in
+    fk g
+    in
+
+let fix kont2 res2 = res2 1 TOPCONT in
+
+let fix kont1 res1 = res1 1 kont2 in
+
+
+f 1 kont1
+
+
+
+

examples/CWCPS/b.cwcps

+let 
+    fix f x y = 
+        if primop x = 0 
+            then 
+                y 1 
+            else 
+                let primop j = x - 1 in 
+                let 
+                    fix h z = 
+                        let primop v = x * z in 
+                        y v 
+                in 
+                f j h
+    in 
+f 3 TOPCONT 

examples/MiniML/Parsing/000_simple.ml

+let main = false
+
+let test002 = true + 0
+
+let test003 = throw EXC
+
+let test004 = x
+
+let test005 = if a then b else c
+
+let test006 = a ; b ;c
+
+let test007 =
+    if a then b ;c ; d else e
+
+let test008 = ()
+
+let test009 = a * b
+let test010 = a / b
+let test011 = a - b
+let test012 = a % b
+
+let test013 =
+    if cond1
+        then 
+            if cond2
+                then a1
+                else a2
+        else if cond3
+            then b1
+            else b2
+
+let test014 = fun a -> b
+let test015 a = b
+let test016 a b = fun c -> d
+let test017 a b = fun c -> fun d -> e
+let test018 a b = fun c d -> fun e f -> g
+
+let test019 = let f x = x in f
+
+let test020 = let rec g x = g x in g
+
+let test021 = let f x y = x + y in 4
+
+let test022 = let rec f x y = x + y in 4
+
+
+let rec f a b c = fun d e f -> g
+and g a b c = fun d e f -> g
+
+(*
+Nested comments are not supported currently :-)
+
+sequence of let-and is not supported
+let test023 = 1
+and test024 = 2
+
+only sequence of let-rec-ands, where each and is a function
+*)
+
+(*
+let rec test025 x = 3
+and test026 y = 4
+*)
+
+let test027 =
+    let rec test028 x = x
+    and test029 x = x
+    in a

examples/MiniML/Parsing/001_if.ml

+
+let main =
+    if true then 1 else 0
+;;
+
+main + 10

examples/MiniML/Parsing/002_let.ml

+let main =
+    let a = 1 in
+    let b = 2 in
+    a + b
+

examples/MiniML/Parsing/003_fun.ml

+
+let succ = fun n -> n + 1
+
+let main = succ 1

examples/MiniML/Parsing/004_ref.ml

+let main = ref 0

examples/MiniML/Parsing/005_unitseq.ml

+let f = fun u -> ()
+let main = (); f ; f (); 1; 1+2;  ()

examples/MiniML/Parsing/006_retseq.ml

+
+let succ = fun a ->
+    ();
+    a;
+    a + 1
+
+let main =
+    let a = 5 in
+    let f = fun a -> succ (succ a) in
+    f a

examples/MiniML/Parsing/007_impseq.ml

+
+let succ = fun n ->
+    n+1
+
+let main =
+    let loc = ref 0 in
+    let f = ref succ in
+    loc := 1;
+    f   := (fun x -> succ (succ x));
+    loc := 2;
+    loc := (3 + !loc);
+    loc := (!f !loc);
+    !loc

examples/MiniML/Parsing/008_imprecfib.ml

+let pred = fun n -> n - 1
+
+let fib =
+    let aux = ref (fun f1 -> fun f2 -> fun n -> 0 ) in
+    aux := (fun f1 -> fun f2 -> fun n -> 
+        if n = 0
+            then f2
+            else let tmp = f1 + f2 in
+            (!aux) tmp f1 (pred n)
+        );
+    (!aux) 1 0
+
+let main = 
+    fib 20
+
+;;
+
+main

examples/MiniML/Parsing/009_imprecfrac.ml

+let pred = fun n -> n - 1
+
+let frac =
+    let aux = ref (fun n -> 0) in
+    aux := (fun n -> 
+            if n = 0
+                then 1
+                else n * (!aux) (pred n)
+            );
+    !aux
+
+let main = frac 5

examples/MiniML/Parsing/010_letrecin_frac.ml

+let pred = fun n -> n - 1
+
+let frac =
+    let rec f n = 
+        if n = 0 then 1 else n * f (pred n)
+        in
+    f
+
+
+let main = frac 5

examples/MiniML/Parsing/011_letrec_frac.ml

+let pred = fun n -> n - 1
+
+let rec frac n = 
+    if n = 0 then 1 else n * frac (pred n)
+
+(*
+let g a = a
+
+let main = 
+    let f = ref frac in 
+    !f 5
+    *)

examples/MiniML/Parsing/012_impmutrec.ml

+let pred n = n - 1
+
+let f = ref (fun n -> 0)
+
+let g = ref (fun n -> 0)
+
+
+let implf = (fun n ->
+        if n = 0
+            then 1
+            else n * !g (pred n)
+            )
+
+
+let setup =
+    f := (fun n ->
+        if n = 0
+            then 1
+            else n * !g (pred n)
+            );
+
+    g := (fun n ->
+        if n = 0
+            then 1
+            else n * !f (pred n)
+            )
+
+let main = 
+    setup;
+    !f 5
+

examples/MiniML/Parsing/013_weirdmutrec.ml

+let pred n = n - 1
+
+let pair a b f = f a b
+
+let fst p = p (fun a b -> a)
+let snd p = p (fun a b -> b)
+
+let rec build u =
+        let f n = 
+            let recg = snd (build u) in
+            if n = 0
+            then 1
+            else n * recg (pred n) in
+        let g n = 
+            let recf = fst (build u) in
+            if n = 0
+            then 1
+            else n * recf (pred n) in
+        pair f g
+
+let p = build ()
+
+let f = fst p
+
+let g = snd p
+            
+let main = f 5

examples/MiniML/Parsing/014_mutrecin.ml

+let pred n = n - 1
+
+let main =
+    let rec f n = 
+        if n = 0 then 1
+            else n * g (pred n)
+    and g n = 
+        if n = 0 then 1
+            else n * f (pred n)
+    in f 5

examples/MiniML/Parsing/015_mutrec.ml

+let pred n = n - 1
+
+let rec f n = 
+    if n = 0 then 1
+        else n * g (pred n)
+and g n = 
+    if n = 0 then 1
+        else n * f (pred n)
+
+let main = f 5

examples/MiniML/Parsing/016_encoded_lists.ml

+
+
+let pair x y rc = rc x y
+
+let fst p = p (fun a b -> a)
+
+let snd p = p (fun a b -> b)
+
+let nil rcnil rccons = rcnil
+
+let cons hd tl rcnil rccons = rccons hd tl (tl rcnil rccons)
+
+let head xs = xs 41 (fun hd tl aux -> hd)
+
+let tail xs = xs 42 (fun hd tl aux -> tl)
+
+let empty xs = xs true (fun hd tl aux -> false)
+
+let map f xs =
+    xs nil (fun hd tl aux -> cons (f hd) aux)
+
+let length xs =
+    xs 0 (fun hd tl aux -> 1 + aux)
+
+let concat xs ys =
+    xs ys (fun hd tl aux -> cons hd aux)
+
+let list0 = nil
+
+let list1 = cons 1 nil
+
+let list2 = cons 1 (cons 2 nil)
+
+let test000 = empty list0
+
+let test001 = empty list1
+
+let test002 = head list1
+
+let test003 = head list2
+
+let test004 = tail list2
+
+let test005 = head (tail list2)
+
+let list3 = map (fun a -> a * 10) list2
+
+let test006 = head list3
+
+let test007 = length list3
+
+let list4 = concat list2 list3
+
+let test009 = length list4

examples/MiniML/Parsing/017_fixpoint.ml

+let rec fix f x = f (fix f) x
+
+
+let fracbody f n = 
+    if n = 0
+    then 1
+    else n * f (n - 1)
+
+let frac = fix fracbody
+
+let main = frac 5

examples/MiniML/Parsing/Typing/001_nolet.ml

+
+(*
+ * No ML-polymorphism
+ *)
+
+let id a = a
+
+let f = id 1
+
+let g = (fun a -> a) true

examples/MiniML/Typing/001_nolet.ml

+
+(*
+ * No ML-polymorphism
+ *)
+
+let id a = a
+
+let f = id 1
+
+let g = (fun a -> a) true

examples/WHILE/001_simple.while

+procedure main()
+{
+    read x;
+    read y;
+    if (x < 5*(y-1) && b || c && d || e  ) {
+        x := 4+4+4;
+    }
+
+    skip;
+}

examples/WHILE/002_frac.while

+procedure main()
+{
+    read n;
+    s := 1;
+    while (n > 0) {
+        s := s * n;
+        n := n - 1;
+    }
+    write s;
+}

examples/WHILE/003_fib.while

+procedure main()
+{
+    Int n;
+
+    read n;
+    Int fib1 := 1;
+    Int fib2 := 1;
+
+    while (n > 0) {
+        write fib1;
+        Int tmp := fib1 + fib2;
+
+        fib2 := fib1;
+        fib1 := tmp;
+
+        n := n - 1;
+    }
+}

examples/WHILE/004_exception.while

+procedure main()
+{
+    Int n;
+    Int result;
+
+    result := 1;
+    try {
+        result := 2;
+        read n;
+        if (n > 20) {
+            result := 3;
+            throw EXIT;
+        }
+    } catch EXIT {
+        result := 4;
+        throw EXIT2;
+    }
+
+    write result;
+}

examples/WHILE/005_elif.while

+procedure main()
+{
+    Int n;
+    Int tmp;
+
+    read n;
+
+    if (n = 1) {
+        tmp := 1;
+    } elif (n = 2) {
+        tmp := 2;
+    } else {
+        tmp := 0;
+    }
+    write tmp;
+}

samples/CWCPS/Parsing/000_samples.ml

-let a = f x
-
-let fix f a = g x
-
-let fix f a = g a
-and g b = f b
-
-let fix f x = 
-    let fix g y = h y 
-        and h y = g y in
-    g a
-
-let fix f c a = 
-    let primop v = a + a in
-    c v

samples/CWCPS/Transformation/closure_record_fields.cwcps

-
-let fix f a k = k a in
-
-
-let record r = (f at 0) in
-
-f r TOPCONT 

samples/CWCPS/Transformation/frac.cwcps

-let 
-    fix f x y = 
-        if primop x = 0 
-            then 
-                y 1 
-            else 
-                let primop j = x - 1 in 
-                let 
-                    fix h z = 
-                        let primop v = x * z in 
-                        y v 
-                in 
-                f j h
-    in 
-f 3 TOPCONT 

samples/CWCPS/Transformation/simple_adder.cwcps

-
-let fix f x fk =
-    let fix g y gk =
-        let fix h z hk = 
-            let primop r1 = x + y in
-            let primop r2 = r1 + z in
-            hk r2
-            in
-        gk h
-        in
-    fk g
-    in
-
-let fix kont2 res2 = res2 1 TOPCONT in
-
-let fix kont1 res1 = res1 1 kont2 in
-
-
-f 1 kont1
-
-
-
-

samples/CWCPS/a.cwcps

-
-let fix f x fk =
-    let fix g y gk =
-        let fix h z hk = 
-            let primop r1 = x + y in
-            let primop r2 = r1 + z in
-            hk r2
-            in
-        gk h
-        in
-    fk g
-    in
-
-let fix kont2 res2 = res2 1 TOPCONT in
-
-let fix kont1 res1 = res1 1 kont2 in
-
-
-f 1 kont1
-
-
-
-

samples/CWCPS/b.cwcps

-let 
-    fix f x y = 
-        if primop x = 0 
-            then 
-                y 1 
-            else 
-                let primop j = x - 1 in 
-                let 
-                    fix h z = 
-                        let primop v = x * z in 
-                        y v 
-                in 
-                f j h
-    in 
-f 3 TOPCONT 

samples/MiniML/Parsing/000_simple.ml

-let main = false
-
-let test002 = true + 0
-
-let test003 = throw EXC
-
-let test004 = x
-
-let test005 = if a then b else c
-
-let test006 = a ; b ;c
-
-let test007 =
-    if a then b ;c ; d else e
-
-let test008 = ()
-
-let test009 = a * b
-let test010 = a / b
-let test011 = a - b
-let test012 = a % b
-
-let test013 =
-    if cond1
-        then 
-            if cond2
-                then a1
-                else a2
-        else if cond3
-            then b1
-            else b2
-
-let test014 = fun a -> b
-let test015 a = b
-let test016 a b = fun c -> d
-let test017 a b = fun c -> fun d -> e
-let test018 a b = fun c d -> fun e f -> g
-
-let test019 = let f x = x in f
-
-let test020 = let rec g x = g x in g
-
-let test021 = let f x y = x + y in 4
-
-let test022 = let rec f x y = x + y in 4
-
-
-let rec f a b c = fun d e f -> g
-and g a b c = fun d e f -> g
-
-(*
-Nested comments are not supported currently :-)
-
-sequence of let-and is not supported
-let test023 = 1
-and test024 = 2
-
-only sequence of let-rec-ands, where each and is a function
-*)
-
-(*
-let rec test025 x = 3
-and test026 y = 4
-*)
-
-let test027 =
-    let rec test028 x = x
-    and test029 x = x
-    in a

samples/MiniML/Parsing/001_if.ml

-
-let main =
-    if true then 1 else 0
-;;
-
-main + 10

samples/MiniML/Parsing/002_let.ml

-let main =
-    let a = 1 in
-    let b = 2 in
-    a + b
-

samples/MiniML/Parsing/003_fun.ml

-
-let succ = fun n -> n + 1
-
-let main = succ 1

samples/MiniML/Parsing/004_ref.ml

-let main = ref 0

samples/MiniML/Parsing/005_unitseq.ml

-let f = fun u -> ()
-let main = (); f ; f (); 1; 1+2;  ()

samples/MiniML/Parsing/006_retseq.ml

-
-let succ = fun a ->
-    ();
-    a;
-    a + 1
-
-let main =
-    let a = 5 in
-    let f = fun a -> succ (succ a) in
-    f a

samples/MiniML/Parsing/007_impseq.ml

-
-let succ = fun n ->
-    n+1
-
-let main =
-    let loc = ref 0 in
-    let f = ref succ in
-    loc := 1;
-    f   := (fun x -> succ (succ x));
-    loc := 2;
-    loc := (3 + !loc);
-    loc := (!f !loc);
-    !loc

samples/MiniML/Parsing/008_imprecfib.ml

-let pred = fun n -> n - 1
-
-let fib =
-    let aux = ref (fun f1 -> fun f2 -> fun n -> 0 ) in
-    aux := (fun f1 -> fun f2 -> fun n -> 
-        if n = 0
-            then f2
-            else let tmp = f1 + f2 in
-            (!aux) tmp f1 (pred n)
-        );
-    (!aux) 1 0
-
-let main = 
-    fib 20
-
-;;
-
-main

samples/MiniML/Parsing/009_imprecfrac.ml

-let pred = fun n -> n - 1
-
-let frac =
-    let aux = ref (fun n -> 0) in
-    aux := (fun n -> 
-            if n = 0
-                then 1
-                else n * (!aux) (pred n)
-            );
-    !aux
-
-let main = frac 5

samples/MiniML/Parsing/010_letrecin_frac.ml

-let pred = fun n -> n - 1
-
-let frac =
-    let rec f n = 
-        if n = 0 then 1 else n * f (pred n)
-        in
-    f
-
-
-let main = frac 5

samples/MiniML/Parsing/011_letrec_frac.ml

-let pred = fun n -> n - 1
-
-let rec frac n = 
-    if n = 0 then 1 else n * frac (pred n)
-
-(*
-let g a = a
-
-let main = 
-    let f = ref frac in 
-    !f 5
-    *)

samples/MiniML/Parsing/012_impmutrec.ml

-let pred n = n - 1
-
-let f = ref (fun n -> 0)
-
-let g = ref (fun n -> 0)
-
-
-let implf = (fun n ->
-        if n = 0
-            then 1
-            else n * !g (pred n)
-            )
-
-
-let setup =
-    f := (fun n ->
-        if n = 0
-            then 1
-            else n * !g (pred n)
-            );
-
-    g := (fun n ->
-        if n = 0
-            then 1
-            else n * !f (pred n)
-            )
-
-let main = 
-    setup;
-    !f 5
-

samples/MiniML/Parsing/013_weirdmutrec.ml

-let pred n = n - 1
-
-let pair a b f = f a b
-
-let fst p = p (fun a b -> a)
-let snd p = p (fun a b -> b)
-
-let rec build u =
-        let f n = 
-            let recg = snd (build u) in
-            if n = 0
-            then 1
-            else n * recg (pred n) in
-        let g n = 
-            let recf = fst (build u) in
-            if n = 0
-            then 1
-            else n * recf (pred n) in
-        pair f g
-
-let p = build ()
-
-let f = fst p
-
-let g = snd p
-            
-let main = f 5

samples/MiniML/Parsing/014_mutrecin.ml

-let pred n = n - 1
-
-let main =
-    let rec f n = 
-        if n = 0 then 1
-            else n * g (pred n)
-    and g n = 
-        if n = 0 then 1
-            else n * f (pred n)
-    in f 5

samples/MiniML/Parsing/015_mutrec.ml

-let pred n = n - 1
-
-let rec f n = 
-    if n = 0 then 1
-        else n * g (pred n)
-and g n = 
-    if n = 0 then 1
-        else n * f (pred n)
-
-let main = f 5

samples/MiniML/Parsing/016_encoded_lists.ml

-
-
-let pair x y rc = rc x y
-
-let fst p = p (fun a b -> a)
-
-let snd p = p (fun a b -> b)
-
-let nil rcnil rccons = rcnil
-
-let cons hd tl rcnil rccons = rccons hd tl (tl rcnil rccons)
-
-let head xs = xs 41 (fun hd tl aux -> hd)
-
-let tail xs = xs 42 (fun hd tl aux -> tl)
-
-let empty xs = xs true (fun hd tl aux -> false)
-
-let map f xs =
-    xs nil (fun hd tl aux -> cons (f hd) aux)
-
-let length xs =
-    xs 0 (fun hd tl aux -> 1 + aux)
-
-let concat xs ys =
-    xs ys (fun hd tl aux -> cons hd aux)
-
-let list0 = nil
-
-let list1 = cons 1 nil
-
-let list2 = cons 1 (cons 2 nil)
-
-let test000 = empty list0
-
-let test001 = empty list1
-
-let test002 = head list1
-
-let test003 = head list2
-
-let test004 = tail list2
-
-let test005 = head (tail list2)
-
-let list3 = map (fun a -> a * 10) list2
-
-let test006 = head list3
-
-let test007 = length list3
-
-let list4 = concat list2 list3
-
-let test009 = length list4

samples/MiniML/Parsing/017_fixpoint.ml

-let rec fix f x = f (fix f) x
-
-
-let fracbody f n = 
-    if n = 0
-    then 1
-    else n * f (n - 1)
-
-let frac = fix fracbody
-
-let main = frac 5

samples/MiniML/Parsing/Typing/001_nolet.ml

-
-(*
- * No ML-polymorphism
- *)
-
-let id a = a
-
-let f = id 1
-
-let g = (fun a -> a) true

samples/MiniML/Typing/001_nolet.ml

-
-(*
- * No ML-polymorphism
- *)
-
-let id a = a
-
-let f = id 1
-
-let g = (fun a -> a) true

samples/WHILE/001_simple.while

-procedure main()
-{
-    read x;
-    read y;
-    if (x < 5*(y-1) && b || c && d || e  ) {
-        x := 4+4+4;
-    }
-
-    skip;
-}

samples/WHILE/002_frac.while

-procedure main()
-{
-    read n;
-    s := 1;
-    while (n > 0) {
-        s := s * n;
-        n := n - 1;
-    }
-    write s;
-}

samples/WHILE/003_fib.while

-procedure main()
-{
-    Int n;
-
-    read n;
-    Int fib1 := 1;
-    Int fib2 := 1;
-
-    while (n > 0) {
-        write fib1;
-        Int tmp := fib1 + fib2;
-
-        fib2 := fib1;
-        fib1 := tmp;
-
-        n := n - 1;
-    }
-}

samples/WHILE/004_exception.while

-procedure main()
-{
-    Int n;
-    Int result;
-
-    result := 1;
-    try {
-        result := 2;
-        read n;
-        if (n > 20) {
-            result := 3;
-            throw EXIT;
-        }
-    } catch EXIT {
-        result := 4;
-        throw EXIT2;
-    }
-
-    write result;
-}

samples/WHILE/005_elif.while

-procedure main()
-{
-    Int n;
-    Int tmp;
-
-    read n;
-
-    if (n = 1) {
-        tmp := 1;
-    } elif (n = 2) {
-        tmp := 2;
-    } else {
-        tmp := 0;
-    }
-    write tmp;
-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.