diff --git a/regression/orig/test040.log b/regression/orig/test040.log new file mode 100644 index 000000000..90e44a83b --- /dev/null +++ b/regression/orig/test040.log @@ -0,0 +1,4 @@ +> 1 +2 +3 +4 diff --git a/regression/orig/test041.log b/regression/orig/test041.log new file mode 100644 index 000000000..99e508a22 --- /dev/null +++ b/regression/orig/test041.log @@ -0,0 +1,2 @@ +> 600 +1800 diff --git a/regression/orig/test042.log b/regression/orig/test042.log new file mode 100644 index 000000000..ef20969cc --- /dev/null +++ b/regression/orig/test042.log @@ -0,0 +1,10 @@ +> 0 +1 +2 +3 +4 +4 +4 +4 +4 +4 diff --git a/regression/orig/test043.log b/regression/orig/test043.log new file mode 100644 index 000000000..c3c21fc91 --- /dev/null +++ b/regression/orig/test043.log @@ -0,0 +1,3 @@ +> 0 +100 +300 diff --git a/regression/orig/test044.log b/regression/orig/test044.log new file mode 100644 index 000000000..3484555d5 --- /dev/null +++ b/regression/orig/test044.log @@ -0,0 +1,6 @@ +> 1 +2 +3 +100 +200 +300 diff --git a/regression/test038.expr b/regression/test038.expr new file mode 100644 index 000000000..e13e88c87 --- /dev/null +++ b/regression/test038.expr @@ -0,0 +1,23 @@ +fun append (x, y) { + case x of + `nil -> return y + | `cons (h, t) -> return `cons (h, append (t, y)) + esac +} + +fun printList (x) { + case x of + `nil -> skip + | `cons (h, t) -> write (h); printList (t) + esac +} + +n := read (); + +x := `cons (1, `cons (2, `nil)); +y := `cons (3, `cons (4, `nil)); + +printList (x); +printList (y); +printList (append (x, y)); +printList (append (y, x)) diff --git a/regression/test039.expr b/regression/test039.expr new file mode 100644 index 000000000..1eaff0a70 --- /dev/null +++ b/regression/test039.expr @@ -0,0 +1,31 @@ +fun insert (t, x) { + case t of + `leaf -> return `node (x, `leaf, `leaf) + | `node (y, l, r) -> if x > y + then return `node (y, insert (l, x), r) + else return `node (y, l, insert (r, x)) + fi + esac +} + +fun find (t, x) { + case t of + `leaf -> return 0 + | `node (y, l, r) -> if x == y then return 1 + elif x > y then return find (l, x) + else return find (r, x) + fi + esac +} + +n := read (); + +t := insert (insert (insert (insert (`leaf, 5), 4), 6), 3); + +write (find (t, 5)); +write (find (t, 4)); +write (find (t, 6)); +write (find (t, 3)); +write (find (t, 2)); +write (find (t, 1)) + diff --git a/regression/test040.expr b/regression/test040.expr new file mode 100644 index 000000000..766857331 --- /dev/null +++ b/regression/test040.expr @@ -0,0 +1,15 @@ +fun f (x) { + case x of + `a -> write (1) + | `b -> write (2) + | `c -> write (3) + | _ -> write (4) + esac +} + +x := read (); + +f (`a); +f (`b); +f (`c); +f (`d) \ No newline at end of file diff --git a/regression/test040.input b/regression/test040.input new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/regression/test040.input @@ -0,0 +1 @@ +0 diff --git a/regression/test041.expr b/regression/test041.expr new file mode 100644 index 000000000..36d947f35 --- /dev/null +++ b/regression/test041.expr @@ -0,0 +1,11 @@ +fun f (a) { + case a of + `a (x, y, z) -> write (x + y + z) + | `b (x, y, z) -> write (x + y + z) + esac +} + +x := read (); + +f (`a (100, 200, 300)); +f (`b (500, 600, 700)) \ No newline at end of file diff --git a/regression/test041.input b/regression/test041.input new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/regression/test041.input @@ -0,0 +1 @@ +0 diff --git a/regression/test042.expr b/regression/test042.expr new file mode 100644 index 000000000..1029c9eb9 --- /dev/null +++ b/regression/test042.expr @@ -0,0 +1,17 @@ +fun f (x) { + case x of + `nil -> write (0) + | `cons (_, `nil) -> write (1) + | `cons (_, `cons (_, `nil)) -> write (2) + | `cons (_, `cons (_, `cons (_, `nil))) -> write (3) + | _ -> write (4) + esac +} + +x := read (); +y := `nil; + +for i := 0, i < 10, i := i + 1 do + f (y); + y := `cons (i, y) +od \ No newline at end of file diff --git a/regression/test042.input b/regression/test042.input new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/regression/test042.input @@ -0,0 +1 @@ +0 diff --git a/regression/test043.expr b/regression/test043.expr new file mode 100644 index 000000000..88bab7941 --- /dev/null +++ b/regression/test043.expr @@ -0,0 +1,12 @@ +fun sum (x) { + case x of + `nil -> return 0 + | `cons (x, tl) -> return x + sum (tl) + esac +} + +x := read (); + +write (sum (`nil)); +write (sum (`cons (100, `nil))); +write (sum (`cons (100, `cons (200, `nil)))) \ No newline at end of file diff --git a/regression/test043.input b/regression/test043.input new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/regression/test043.input @@ -0,0 +1 @@ +0 diff --git a/regression/test044.expr b/regression/test044.expr new file mode 100644 index 000000000..78bc10dfd --- /dev/null +++ b/regression/test044.expr @@ -0,0 +1,37 @@ +fun zip (x) { + case x of `pair (x, y) -> + case x of + `nil -> return `nil + | `cons (x, xs) -> case y of + `nil -> return `nil + | `cons (y, ys) -> return `cons (`pair (x, y), zip (`pair (xs, ys))) + esac + esac + esac +} + +fun unzip (x) { + case x of + `nil -> return `pair (`nil, `nil) + | `cons (`pair (x, y), tl) -> + case unzip (tl) of + `pair (xs, ys) -> return `pair (`cons (x, xs), `cons (y, ys)) + esac + esac +} + +fun printList (l) { + case l of + `nil -> skip + | `cons (x, xs) -> write (x); printList (xs) + esac +} + +z := read (); + +x := `cons (1, `cons (2, `cons (3, `nil))); +y := `cons (100, `cons (200, `cons (300, `nil))); + +case unzip (zip (`pair (x, y))) of + `pair (x, y) -> printList (x); printList (y) +esac \ No newline at end of file diff --git a/regression/test044.input b/regression/test044.input new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/regression/test044.input @@ -0,0 +1 @@ +0 diff --git a/src/X86.ml b/src/X86.ml index 7157d6e56..9dd20f23e 100644 --- a/src/X86.ml +++ b/src/X86.ml @@ -94,7 +94,7 @@ open SM of x86 instructions *) let compile env code = - SM.print_prg code; + (*SM.print_prg code;*) flush stdout; let suffix = function | "<" -> "l" @@ -351,10 +351,10 @@ class env = method drop_barrier = {< barrier = false >} (* associates a stack to a label *) - method set_stack l = Printf.printf "Setting stack for %s\n" l; {< stackmap = M.add l stack stackmap >} + method set_stack l = (*Printf.printf "Setting stack for %s\n" l;*) {< stackmap = M.add l stack stackmap >} (* retrieves a stack for a label *) - method retrieve_stack l = Printf.printf "Retrieving stack for %s\n" l; + method retrieve_stack l = (*Printf.printf "Retrieving stack for %s\n" l;*) try {< stack = M.find l stackmap >} with Not_found -> self (* gets a name for a global variable *)