Explorar o código

Added test suite from the Pycivicc project

Taddeus Kroes %!s(int64=12) %!d(string=hai) anos
pai
achega
47fd9def6c
Modificáronse 60 ficheiros con 1564 adicións e 41 borrados
  1. 7 0
      Makefile
  2. 4 11
      test/array_init.cvc
  3. 67 16
      test/bool_op.cvc
  4. 36 14
      test/for_to_while.cvc
  5. 33 0
      test/nested_funs.cvc
  6. 31 0
      test/old/array_init.cvc
  7. 0 0
      test/old/array_scope.cvc
  8. 18 0
      test/old/bool_op.cvc
  9. 0 0
      test/old/civic.h
  10. 0 0
      test/old/constant_propagation.cvc
  11. 0 0
      test/old/context.cvc
  12. 0 0
      test/old/dim_reduce.cvc
  13. 0 0
      test/old/extern_vars.cvc
  14. 20 0
      test/old/for_to_while.cvc
  15. 0 0
      test/old/scope.cvc
  16. 0 0
      test/old/test.cvc
  17. 0 0
      test/old/var_init.cvc
  18. 9 0
      test/parsetab.py
  19. 23 0
      test/pi.cvc
  20. 29 0
      test/prime.cvc
  21. 77 0
      test/run.bash
  22. 8 0
      test/stdlib.h
  23. 60 0
      test/testsuite/assignment/12_gcd.cvc
  24. 80 0
      test/testsuite/assignment/15_matrixMult.cvc
  25. 44 0
      test/testsuite/assignment/19_prime.cvc
  26. 82 0
      test/testsuite/assignment/1_8_queen.cvc
  27. 41 0
      test/testsuite/assignment/21_print.cvc
  28. 91 0
      test/testsuite/assignment/25_quicksort.cvc
  29. 40 0
      test/testsuite/assignment/28_testfor.cvc
  30. 52 0
      test/testsuite/assignment/2_euclid_f.cvc
  31. 40 0
      test/testsuite/assignment/5_factorial.cvc
  32. 4 0
      test/testsuite/easy_test/test14.cvc
  33. 12 0
      test/testsuite/easy_test/test20.cvc
  34. 9 0
      test/testsuite/easy_test/test30.cvc
  35. 6 0
      test/testsuite/easy_test/test36.cvc
  36. 8 0
      test/testsuite/easy_test/test40.cvc
  37. 13 0
      test/testsuite/easy_test/test46.cvc
  38. 4 0
      test/testsuite/easy_test/test5.cvc
  39. 53 0
      test/testsuite/easy_test/test52.cvc
  40. 8 0
      test/testsuite/easy_test/test59.cvc
  41. 15 0
      test/testsuite/easy_test/test61.cvc
  42. 33 0
      test/testsuite/easy_test/test75.cvc
  43. 4 0
      test/testsuite/easy_test/test78.cvc
  44. 35 0
      test/testsuite/easy_test/test83.cvc
  45. 4 0
      test/testsuite/easy_test/test9.cvc
  46. 3 0
      test/testsuite/error_test/fail11.cvc
  47. 1 0
      test/testsuite/error_test/fail19.cvc
  48. 4 0
      test/testsuite/error_test/fail28.cvc
  49. 4 0
      test/testsuite/error_test/fail34.cvc
  50. 4 0
      test/testsuite/error_test/fail42.cvc
  51. 4 0
      test/testsuite/error_test/fail48.cvc
  52. 10 0
      test/testsuite/error_test/fail55.cvc
  53. 15 0
      test/testsuite/error_test/fail62.cvc
  54. 47 0
      test/testsuite/functional_test/11_mul_add_bool.cvc
  55. 47 0
      test/testsuite/functional_test/14_type_checking_cast.cvc
  56. 119 0
      test/testsuite/functional_test/14_type_checking_cast.s
  57. 42 0
      test/testsuite/functional_test/1_array.cvc
  58. 18 0
      test/testsuite/functional_test/4_arth2.cvc
  59. 28 0
      test/testsuite/functional_test/7_euclides.cvc
  60. 118 0
      test/testsuite/functional_test/9_inner_fun.cvc

+ 7 - 0
Makefile

@@ -6,6 +6,10 @@ SOURCES := ast.ml stringify.mli stringify.ml util.mli util.ml lexer.mll \
 PRE_TARGETS := ast.cmi ast.o stringify.cmi stringify.o util.cmi util.o
 LIBS := str unix
 
+CIVAS := ../bin32/civas
+CIVVM := ../bin32/civvm
+CIVCC := ../civicc
+
 OCAMLFLAGS := -g
 
 OCAMLYACC := menhir
@@ -19,4 +23,7 @@ clean:: myclean
 myclean:
 	rm -f a.out
 
+check:
+	@cd test; CIVAS=$(CIVAS) CIVVM=$(CIVVM) CIVCC=$(CIVCC) bash run.bash
+
 include OCamlMakefile

+ 4 - 11
test/array_init.cvc

@@ -1,19 +1,18 @@
-extern void printInt(int i);
-extern void printNewlines(int i);
+#include "stdlib.h"
 
 export int main() {
     int[2,3] a = [[1,2,3], [4,5,6]];
     int[2,3] b = 7;
-
+    
     for(int i=0,2) {
         for(int j=0,3) {
             printInt(a[i,j]);
             printNewlines(1);
         }
     }
-
+    
     printNewlines(1);
-
+    
     for(int i=0,2) {
         for(int j=0,3) {
             printInt(b[i,j]);
@@ -23,9 +22,3 @@ export int main() {
 
     return 0;
 }
-
-void foo() {
-    void bar() {
-        int[4, 5] arr = 1;
-    }
-}

+ 67 - 16
test/bool_op.cvc

@@ -1,18 +1,69 @@
-extern void printBool(bool val);
+#include "stdlib.h"
 
-void foo() {
-    bool b1;
-    bool b2;
-    int i;
-    float f;
-    printBool(b1 == b2);   // (int)b1 == (int)b2
-    printBool(b1 != b2);   // (int)b1 != (int)b2
-    printBool(b1 && b2);   // b1 ? b2 : false
-    printBool(b1 || b2);   // b1 ? true : b2
-    printBool(b1 + b2);    // (bool)((int)b1 + (int)b2)
-    printBool(b1 * b2);    // (bool)((int)b1 * (int)b2)
-    printBool((bool)i);    // i != 0
-    printBool((bool)f);    // f != 0.0
-    printBool((int)b1);    // b1 ? 1 : 0
-    printBool((float)b1);  // b1 ? 1.0 : 0.0
+void printBool(bool b) {
+    if(b) {
+        printInt(1);
+    } else {
+        printInt(0);
+    }
+    
+    printNewlines(1);
+}
+
+bool t() {
+    printInt(1);
+    return true;
+}
+
+bool f() {
+    printInt(0);
+    return false;
+}
+
+export int main() {
+    printBool(t() == f());
+    printBool(f() == t());
+    printBool(t() == t());
+    printBool(f() == f());
+    printNewlines(1);
+    
+    printBool(t() != f());
+    printBool(f() != t());
+    printBool(t() != t());
+    printBool(f() != f());
+    printNewlines(1);
+    
+    printBool(t() && f());
+    printBool(f() && t());
+    printBool(t() && t());
+    printBool(f() && f());
+    printNewlines(1);
+    
+    printBool(t() || f());
+    printBool(f() || t());
+    printBool(t() || t());
+    printBool(f() || f());
+    printNewlines(1);
+    
+    printBool(t() * f());
+    printBool(f() * t());
+    printBool(t() * t());
+    printBool(f() * f());
+    printNewlines(1);
+    
+    printBool(t() + f());
+    printBool(f() + t());
+    printBool(t() + t());
+    printBool(f() + f());
+    printNewlines(1);
+    
+    printBool((bool)5);
+    printBool((bool)0);
+    printNewlines(1);
+    
+    printBool((bool)5.0);
+    printBool((bool)0.0);
+    printNewlines(1);
+    
+    return 0;
 }

+ 36 - 14
test/for_to_while.cvc

@@ -1,20 +1,42 @@
-extern int printInt(int n);
+#include "stdlib.h"
 
-void foo() {
-    void bar() {
-        for (int i = 0, 10)
-            printInt(i);
+export int main() {
+    for(int i=0, 10) {
+        printInt(i);
+        printSpaces(1);
     }
-}
-
-export void main() {
-    for (int i = 0, 10)
+    
+    printNewlines(1);
+    
+    for(int i=10, 0,-1) {
         printInt(i);
-
-    for (int i = 0, 10, -1)
+        printSpaces(1);
+    }
+    
+    printNewlines(1);
+    
+    for(int i=0, 10, 2) {
         printInt(i);
+        printSpaces(1);
+    }
+    
+    printNewlines(1);
+    
+    for(int i=7, 0, -3) {
+        printInt(i);
+        printSpaces(1);
+    }
+    
+    for(int i=0, 5) {
+        for(int j=0, 4) {
+            printInt(i);
+            printSpaces(1);
+            printInt(j);
+            printSpaces(1);
+        }
+        
+        printNewlines(1);
+    }
 
-    for (int i = 0, 10)
-        for (int j = 10, 20)
-            printInt(i + j);
+    return 0;
 }

+ 33 - 0
test/nested_funs.cvc

@@ -0,0 +1,33 @@
+#include "stdlib.h"
+
+void foo() {
+    void bar() {
+        void bar() {
+            printInt(1);
+        }
+
+        printInt(2);
+        bar();
+        baz();
+    }
+
+    printInt(3);
+    bar();
+    baz();
+}
+
+void bar() {
+    printInt(4);
+}
+
+void baz() {
+    printInt(5);
+    bar();
+}
+
+export int main() {
+    foo();
+    bar();
+    baz();
+    return 0;
+}

+ 31 - 0
test/old/array_init.cvc

@@ -0,0 +1,31 @@
+extern void printInt(int i);
+extern void printNewlines(int i);
+
+export int main() {
+    int[2,3] a = [[1,2,3], [4,5,6]];
+    int[2,3] b = 7;
+
+    for(int i=0,2) {
+        for(int j=0,3) {
+            printInt(a[i,j]);
+            printNewlines(1);
+        }
+    }
+
+    printNewlines(1);
+
+    for(int i=0,2) {
+        for(int j=0,3) {
+            printInt(b[i,j]);
+            printNewlines(1);
+        }
+    }
+
+    return 0;
+}
+
+void foo() {
+    void bar() {
+        int[4, 5] arr = 1;
+    }
+}

+ 0 - 0
test/array_scope.cvc → test/old/array_scope.cvc


+ 18 - 0
test/old/bool_op.cvc

@@ -0,0 +1,18 @@
+extern void printBool(bool val);
+
+void foo() {
+    bool b1;
+    bool b2;
+    int i;
+    float f;
+    printBool(b1 == b2);   // (int)b1 == (int)b2
+    printBool(b1 != b2);   // (int)b1 != (int)b2
+    printBool(b1 && b2);   // b1 ? b2 : false
+    printBool(b1 || b2);   // b1 ? true : b2
+    printBool(b1 + b2);    // (bool)((int)b1 + (int)b2)
+    printBool(b1 * b2);    // (bool)((int)b1 * (int)b2)
+    printBool((bool)i);    // i != 0
+    printBool((bool)f);    // f != 0.0
+    printBool((int)b1);    // b1 ? 1 : 0
+    printBool((float)b1);  // b1 ? 1.0 : 0.0
+}

+ 0 - 0
test/civic.h → test/old/civic.h


+ 0 - 0
test/constant_propagation.cvc → test/old/constant_propagation.cvc


+ 0 - 0
test/context.cvc → test/old/context.cvc


+ 0 - 0
test/dim_reduce.cvc → test/old/dim_reduce.cvc


+ 0 - 0
test/extern_vars.cvc → test/old/extern_vars.cvc


+ 20 - 0
test/old/for_to_while.cvc

@@ -0,0 +1,20 @@
+extern int printInt(int n);
+
+void foo() {
+    void bar() {
+        for (int i = 0, 10)
+            printInt(i);
+    }
+}
+
+export void main() {
+    for (int i = 0, 10)
+        printInt(i);
+
+    for (int i = 0, 10, -1)
+        printInt(i);
+
+    for (int i = 0, 10)
+        for (int j = 10, 20)
+            printInt(i + j);
+}

+ 0 - 0
test/scope.cvc → test/old/scope.cvc


+ 0 - 0
test/test.cvc → test/old/test.cvc


+ 0 - 0
test/var_init.cvc → test/old/var_init.cvc


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 9 - 0
test/parsetab.py


+ 23 - 0
test/pi.cvc

@@ -0,0 +1,23 @@
+#include "stdlib.h"
+
+float computePi() {
+    float pi = 0.0;
+    int n = 75;
+    
+    for(int x=-n, n+1) {
+        for(int y=-n, n+1) {
+            if(x*x + y*y <= n*n) {
+                pi = pi + 1.0/(float)(n*n);
+            }
+        }
+    }
+    
+    return pi;
+}
+
+export int main() {
+    printFloat(computePi());
+    printNewlines(1);
+    
+    return 0;
+}

+ 29 - 0
test/prime.cvc

@@ -0,0 +1,29 @@
+#include "stdlib.h"
+
+int next_prime(int p) {
+    bool is_prime;
+
+    do {
+        p = p + 1;
+        is_prime = true;
+
+        for (int i = 2, p) {
+            if (p % i == 0)
+                is_prime = false;
+        }
+    } while(!is_prime);
+
+    return p;
+}
+
+export int main() {
+    int p = 2;
+
+    for (int i = 0, 25) {
+        printInt(p);
+        printNewlines(1);
+        p = next_prime(p);
+    }
+
+    return 0;
+}

+ 77 - 0
test/run.bash

@@ -0,0 +1,77 @@
+#!/usr/bin/env bash
+CIVAS=${CIVAS-../bin32/civas}
+CIVVM=${CIVVM-../bin32/civvm}
+CIVCC=${CIVVM-../bin32/civcc}
+REAL_CFLAGS=
+TESTSUITE_CFLAGS=
+
+total_tests=0
+failed_tests=0
+
+
+# The real tests: compile a file, run it and compare the output to the
+# output of the reference compiler.
+for f in *.cvc
+do
+    total_tests=$((total_tests+1))
+    echo -n $f:" "
+
+    if $CIVCC $REAL_CFLAGS -o tmp.s $f > tmp.out 2>&1 &&
+       $CIVAS tmp.s -o tmp.o > tmp.out 2>&1 &&
+       $CIVVM tmp.o > tmp.out 2>&1 &&
+       mv tmp.out tmp.res &&
+       diff tmp.res ${f%.*}.out --side-by-side --ignore-space-change > tmp.out 2>&1
+    then
+        echo success
+    else
+        echo failed
+        echo -------------------------------
+        cat tmp.out
+        echo -------------------------------
+        echo
+        failed_tests=$((failed_tests+1))
+    fi
+
+    rm -f tmp.res tmp.s tmp.o tmp.out
+done
+
+
+# Tests from the testsuite. Only check if exit code of compiler equals 0.
+for f in testsuite/assignment/*.cvc testsuite/easy_test/*.cvc testsuite/functional_test/*.cvc
+do
+    total_tests=$((total_tests+1))
+    echo -n $f:" "
+
+    if $CIVCC $TESTSUITE_CFLAGS $f -o tmp.s > /dev/null 2>&1
+    then
+        echo success
+    else
+        echo failed
+        failed_tests=$((failed_tests+1))
+    fi
+
+    rm -f tmp.s
+done
+
+
+# Tests from the testsuite that must fail. Only check if exit code
+# of compiler does not equal 0.
+for f in testsuite/error_test/*.cvc
+do
+    total_tests=$((total_tests+1))
+    echo -n $f:" "
+
+    if $CIVCC $TESTSUITE_CFLAGS $f -o tmp.s > /dev/null 2>&1
+    then
+        echo failed
+        failed_tests=$((failed_tests+1))
+    else
+        echo success
+    fi
+
+    rm -f tmp.s
+done
+
+
+echo
+echo $total_tests tests, $failed_tests failures

+ 8 - 0
test/stdlib.h

@@ -0,0 +1,8 @@
+extern void printInt(int val);
+extern void printFloat(float val);
+
+extern int scanInt(); 
+extern float scanFloat();
+
+extern void printSpaces(int num);
+extern void printNewlines(int num); 

+ 60 - 0
test/testsuite/assignment/12_gcd.cvc

@@ -0,0 +1,60 @@
+/*
+ *  gcd.c
+ *  
+ *
+ *  Created by Andrew on 2/5/11.
+ *  Copyright 2011 UvA. All rights reserved.
+ *
+ */
+
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+
+int gcd_cal(int min,int max)
+{
+	int media;
+	if(min>max)
+	{
+		media=min;
+		min=max;
+		max=media;
+	}
+	
+	while(min>0)
+	{
+		max=max-min;
+		if(min>max)
+		{
+			media=min;
+			min=max;
+			max=media;
+		}
+	}
+	return max;
+	
+}
+
+export int main()
+{
+	int max=scanInt();
+	int min=scanInt();
+	
+	int gcd=0;
+	
+	if(max==0||min==0)
+		printInt(gcd);
+	else
+	{
+		gcd=gcd_cal(max,min);	
+		printInt(gcd);
+	}	
+	printNewlines(1);
+	return 0;
+}

+ 80 - 0
test/testsuite/assignment/15_matrixMult.cvc

@@ -0,0 +1,80 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+
+export int main()
+{
+	//Read dimensions of matrix from input
+	int rowsMatrixA =5;
+	int colMatrixA = 5;
+	
+	int rowsMatrixB =5;
+	int colMatrixB = 5;
+	
+	int[rowsMatrixA, colMatrixA] matrixA;
+	int[rowsMatrixB, colMatrixB] matrixB;
+	int[rowsMatrixA, colMatrixB] matrixProduct;
+	
+	//Product cannot be done if the following condition does not stand
+	if (colMatrixA == rowsMatrixB)
+	{
+		//Fill in Matrix A
+		for (int i = 0, rowsMatrixA)
+		{
+			for (int j = 0, colMatrixA)
+			{
+				matrixA[i, j] = i + j;
+				printInt(matrixA[i, j]);
+				printSpaces(3);
+			}
+			printNewlines(1);
+		}
+		
+		//Fill in Matrix B
+		for (int i = 0, rowsMatrixB)
+		{
+			for (int j = 0, colMatrixB)
+			{
+				matrixB[i, j] = i + j;
+				printInt(matrixB[i, j]);
+				printSpaces(3);
+			}
+			printNewlines(1);
+		}
+		
+		//Do Multiplication
+		for (int i = 0, rowsMatrixA)
+		{
+			for (int j = 0, colMatrixB)
+			{
+				matrixProduct[i, j] = 0;
+				for (int m = 0, colMatrixA)
+				{
+					matrixProduct[i, j] = matrixProduct[i, j] + (matrixA[i, m] * matrixB[m,j]);
+				}
+			}
+		}
+
+
+		for (int i = 0, rowsMatrixA)
+		{
+			for (int j = 0, colMatrixB)
+			{
+				printInt(matrixProduct[i, j]);
+						printSpaces(3);
+			}
+			printNewlines(1);
+		}
+
+		
+	}
+	return 0;
+}
+
+

+ 44 - 0
test/testsuite/assignment/19_prime.cvc

@@ -0,0 +1,44 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+export int main() 
+{
+	int num = scanInt();
+	int i;
+	int j;
+	//int sqRoot;
+	bool isPrime;
+	
+	i = 2;
+ 	
+	while (i <= num + 1)
+	{
+		j = 2;
+		isPrime = true;
+		
+		while ((j < i-1) && isPrime)
+		{
+			if ((i % j) == 0)
+				isPrime = false;
+			
+			j = j + 1;
+		}
+		
+		if (isPrime)
+		{
+			printInt(i);
+			printNewlines(1);
+		}			
+		else
+			num = num + 1;
+		i= i + 1;
+	}
+	
+	return 0;
+}

+ 82 - 0
test/testsuite/assignment/1_8_queen.cvc

@@ -0,0 +1,82 @@
+/*
+ *  quene.c
+ *  
+ *
+ *  Created by Andrew on 2/5/11.
+ *  Copyright 2011 UvA. All rights reserved.
+ *
+ */
+
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+int[8] x;
+
+int abs_sub(int i,int j)
+{
+	int k;
+	if(i>=j)
+		k=i-j;
+	else 
+		k=j-i;
+	return k;
+}
+
+void print ()
+{
+	int i;
+	int j;
+	for (int i=0,8) 
+	{
+		for (int j=0,8)
+		{
+			if (j==x[i]) 
+			{
+				printInt(i*10+j);
+				printSpaces(3);			
+			}
+		}
+	}
+		printNewlines(1);
+    
+}
+
+/* tests, whether (ix, iy) is beaten by queens 0...(iy-1) */
+int is_free (int ix, int iy)
+{
+	int i;
+	int flag=1;
+	for (int i=0,iy)
+		if ((x[i]==ix) || (abs_sub(x[i],ix)==abs_sub(i,iy))) 
+			flag= 0;
+	return flag;
+}
+
+/* tries to place queen n on row n */
+void try (int n)
+{
+	int i;
+	if (n==8) print();
+	else
+	{
+		for (int i=0,8)
+			if (is_free(i,n)==1) 
+			{
+				x[n]=i;
+				try (n+1);
+			}
+	}
+}
+
+export int main() 
+{
+	
+	try(0);
+	return 0;	
+}

+ 41 - 0
test/testsuite/assignment/21_print.cvc

@@ -0,0 +1,41 @@
+/*
+ *  matrix.c
+ *  
+ *
+ *  Created by Andrew on 2/5/11.
+ *  Copyright 2011 UvA. All rights reserved.
+ *
+ */
+
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+export int main()
+{
+	int[5,5] matrix;
+
+	for (int i = 0, 5) 
+	{
+		for (int j = 0, 5)
+			matrix[i,j]=j;
+	}
+	
+	for (int i = 0, 5) 
+	{
+		for (int j = 0, 5)
+        {
+			printInt(matrix[i,j]);
+            printSpaces(3);
+        }
+        printNewlines(1);
+	}
+		
+	return 0;
+}
+

+ 91 - 0
test/testsuite/assignment/25_quicksort.cvc

@@ -0,0 +1,91 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+void printvector(int[m] a)
+{        
+	for(int i=0,m)
+	{
+		printInt(a[i]);
+		printSpaces(3);
+		
+	}
+	
+}
+
+void quicksort(int[N] list,int m,int n)
+{
+	int key;
+	int i;
+	int j;
+	int k;
+	int temp;
+	
+	if( m < n)
+	{
+		
+		k = (m+n)/2;
+		
+		//swap
+		temp=list[m];
+		list[m]=list[k];
+		list[k]=temp;      
+		
+		key = list[m];
+		
+		i = m+1;
+		
+		j = n;
+		
+		while(i <= j)
+		{
+			
+			while((i <= n) && (list[i] <= key))
+			{
+                i=i+1;
+			}
+			while((j >= m) && (list[j] > key))
+			{
+                j=j-1;
+			}
+			if( i < j)
+			{
+				
+                temp=list[i];
+				list[i]=list[j];
+				list[j]=temp;
+			}
+			
+		}
+		
+		// swap two elements
+		
+		temp=list[m];
+		list[m]=list[j];
+		list[j]=temp;
+		
+		// recursively sort the lesser list
+		
+		quicksort(list,m,j-1);
+		
+		quicksort(list,j+1,n);
+		
+	}
+	
+}
+
+export int main()
+{
+	int[10] a = [2,10,5,4,9,7,8,6,1,2];
+	
+	quicksort(a,0,9);
+	printvector(a);
+	return 0;
+}
+
+

+ 40 - 0
test/testsuite/assignment/28_testfor.cvc

@@ -0,0 +1,40 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+
+export int main()
+{
+    int a;
+	int m=10;
+	int n=5;
+	
+	a=10;
+    m=5;
+	
+	for(int i=0,m,-1)
+	{
+			a=a-1;
+            printInt(a);
+			printSpaces(3);
+	}	
+	printNewlines(1);
+
+    m=5;
+    for(int i=10,m,-1)
+	{
+			a=a-1;
+            printInt(a);
+			printSpaces(3);
+			
+	}
+	printNewlines(1);
+	
+	
+	return 0;
+}

+ 52 - 0
test/testsuite/assignment/2_euclid_f.cvc

@@ -0,0 +1,52 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+
+export int main() 
+{
+    int num1 = scanInt();
+    int num2 = scanInt();
+    
+    //Print gcd
+    printInt(euclid(num1, num2));
+	printNewlines(1);
+    return 0;
+}
+
+int euclid(int num1, int num2)
+{
+	int gcd;
+
+	void findNextPair()
+	{
+		if (num1 > num2)
+		{
+			num1 = num1 % num2;
+		}
+		else
+		{
+			num2 = num2 % num1;
+		}
+	}
+	
+	do
+	{
+		findNextPair();
+  
+	} while (num1 != 0 && num2 != 0);
+	
+
+        
+	if (num1 == 0)
+		gcd = num2;
+	else
+		gcd = num1;
+    
+    return gcd;
+}

+ 40 - 0
test/testsuite/assignment/5_factorial.cvc

@@ -0,0 +1,40 @@
+/*
+ *  factorial.c
+ *  
+ *
+ *  Created by Andrew on 2/5/11.
+ *  Copyright 2011 UvA. All rights reserved.
+ *
+ */
+
+//5!=5*4*3*2*1;
+
+extern void printInt(int i);
+extern int scanInt();
+int fac(int num)
+{
+	int input=num;
+	int output=1;
+	int i=1;
+	
+	if(input==0)
+		output=1;
+	else 
+	{
+		while(i<=input)
+		{
+			output=output*i;
+			i=i+1;
+		}
+	}
+	return output;
+}
+
+export int main()
+{
+	int N=scanInt();
+	int output=	fac(N);	
+	printInt(output);
+	return 0;	
+}
+

+ 4 - 0
test/testsuite/easy_test/test14.cvc

@@ -0,0 +1,4 @@
+
+void func(float b, bool c)
+{
+}

+ 12 - 0
test/testsuite/easy_test/test20.cvc

@@ -0,0 +1,12 @@
+
+int func()
+{
+    int a;
+    int b = 2;
+    int c = 3 + 4;
+    int d = 5 * 6;
+    int e = 7 % 8;
+    int f = c + d - e * b;
+    return 0;
+}
+

+ 9 - 0
test/testsuite/easy_test/test30.cvc

@@ -0,0 +1,9 @@
+void test_do_while2()
+{
+    int x = 0;
+    int y = 10;
+    do {
+        x = x + 1;
+        y = y - 1;
+    } while (x <= y);
+}

+ 6 - 0
test/testsuite/easy_test/test36.cvc

@@ -0,0 +1,6 @@
+
+extern int n;
+extern int m;
+extern int k;
+
+int [n,m,k] global_int_array_def;

+ 8 - 0
test/testsuite/easy_test/test40.cvc

@@ -0,0 +1,8 @@
+
+void func()
+{
+    int [10] i;
+    int [20,30] j;
+    int [4,5,6] k;
+}
+

+ 13 - 0
test/testsuite/easy_test/test46.cvc

@@ -0,0 +1,13 @@
+
+void func()
+{
+    int a = -2+10;
+    int b = 2-10;
+    void f()
+    {
+    } 
+    void g()
+    {
+    } 
+}
+

+ 4 - 0
test/testsuite/easy_test/test5.cvc

@@ -0,0 +1,4 @@
+// test parsing of one global variable definition.
+
+extern float pi ;
+

+ 53 - 0
test/testsuite/easy_test/test52.cvc

@@ -0,0 +1,53 @@
+// 3.b: Scan vector / maxtrix
+
+extern int scanInt();
+extern float scanFloat();
+extern void printInt(int c);
+extern void printFloat(float c);
+
+
+void scan_vector(float [m] a)
+{
+    for (int i = 0, m) {
+	a[i] = scanFloat();
+    }
+}
+
+void scan_matrix(float [m,n] a)
+{
+    for (int i = 0, m) {
+	for (int j = 0, n) {
+	    a[i,j] = scanFloat();
+	}
+    }
+}
+
+export int main()
+{
+    int m = 3;
+    int n = 3;
+
+    void do_vector()
+    {
+	float [m] v;
+
+	scan_vector(v);
+    }
+
+    void do_matrix()
+    {
+	float [m,n] M;
+
+	scan_matrix(M);
+    }
+
+    if (n == 1 && m >= 1) {
+	do_vector();
+    }
+    else if (n > 1 && m >= 1) {
+	do_matrix();
+    }
+
+    return 0;
+}
+

+ 8 - 0
test/testsuite/easy_test/test59.cvc

@@ -0,0 +1,8 @@
+void testFunDecs()
+{
+  int a = 3;
+  int c = 5;
+  int d = a + c;
+  int b;
+  b = a+2;
+}

+ 15 - 0
test/testsuite/easy_test/test61.cvc

@@ -0,0 +1,15 @@
+void testFunDecs()
+{
+  int[2] a = [3,1];
+  int c = 5;
+  int d = 2 + c;
+  int b;
+  int r;
+
+  void foo() {
+    int c = 3;
+    int p;
+  }
+
+  r = 3;
+}

+ 33 - 0
test/testsuite/easy_test/test75.cvc

@@ -0,0 +1,33 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+
+void f(int [n] a)
+{
+  a = 2;
+}
+
+void init_single_array()
+{
+  int [12] a;
+
+  f(a);
+
+  for (int i = 0, 12) {
+    printInt(a[i]);
+    printNewlines(1);
+  }
+}
+
+export int main()
+{
+  init_single_array();
+
+  return 0;
+}

+ 4 - 0
test/testsuite/easy_test/test78.cvc

@@ -0,0 +1,4 @@
+void bool_float_arrays(){
+  bool[2] b = [true,false];
+  float[3] f = [1.0, 2.2, 3.14];
+}

+ 35 - 0
test/testsuite/easy_test/test83.cvc

@@ -0,0 +1,35 @@
+void f()
+{
+  int a = 2 + 3 + 4 + 5;
+  float b = 39.0 + 3.0 + 21.0;
+  bool c = false + false;
+
+  int d = 2 - 3 - 4 - 5;
+  float e = 39.0 - 3.0 - 21.0;
+
+  int f = 2 * 3 * 1;
+  float g = 3.14 * 2.0;
+  bool h = true * false;
+
+  int i = 4/3;
+  int j = 6/0;
+  float k = 5.0/2.0;
+  float l = 9.0/0.00;
+
+  int m = 12 % 8 % 3;
+
+  bool n = 20 < 20;
+  bool o = 3.0 < 6.1;
+
+  bool p = 20 <= 20;
+  bool q = 3.0 <= 6.1;
+
+  bool r = 60 < 50 || 30 > 10;
+  bool s = 3.0 > 2.0;
+
+  bool t = 8 != 8;
+  bool u = 8 == 8;
+  bool v = 1.2 != 2.1;
+  bool w = true != false;
+
+}

+ 4 - 0
test/testsuite/easy_test/test9.cvc

@@ -0,0 +1,4 @@
+// test parsing of one global function declaration with parameter.
+
+extern float calculate();
+

+ 3 - 0
test/testsuite/error_test/fail11.cvc

@@ -0,0 +1,3 @@
+extern void f(int a);
+export void f(bool a) { }
+

+ 1 - 0
test/testsuite/error_test/fail19.cvc

@@ -0,0 +1 @@
+void p(int [n,n] a) { }

+ 4 - 0
test/testsuite/error_test/fail28.cvc

@@ -0,0 +1,4 @@
+void f()
+{
+  int a = notdef;
+}

+ 4 - 0
test/testsuite/error_test/fail34.cvc

@@ -0,0 +1,4 @@
+int f()
+{
+  return true;
+}

+ 4 - 0
test/testsuite/error_test/fail42.cvc

@@ -0,0 +1,4 @@
+void f()
+{
+  int i = (void) 0;
+}

+ 4 - 0
test/testsuite/error_test/fail48.cvc

@@ -0,0 +1,4 @@
+void f()
+{
+  int i = !0;
+}

+ 10 - 0
test/testsuite/error_test/fail55.cvc

@@ -0,0 +1,10 @@
+void sum_arrayexp()
+{
+  int i = 1 + [0];
+  1 + 2;
+}
+
+void empty()
+{
+  ;
+}

+ 15 - 0
test/testsuite/error_test/fail62.cvc

@@ -0,0 +1,15 @@
+int i = 4189369722369384960;
+
+extern void printInt(int i);
+extern void printFloat(float i);
+extern int scanInt();
+extern float scanFloat();
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+export int main()
+{
+  printInt(i);
+  return 0;
+}
+

+ 47 - 0
test/testsuite/functional_test/11_mul_add_bool.cvc

@@ -0,0 +1,47 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+extern int scanInt( );
+extern float scanFloat( );
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+//export int[2,2] arr = [[3,4]]; //[[0,1],[3,4]];
+//bool[2,2] barr = [[false,false],[false,false]];
+
+
+
+export int main()
+{
+	int  m;
+	checkStatem();
+    return 0;//true;
+}
+
+void checkStatem()
+{
+	bool a = false;
+	bool b = true;
+	bool c= true;
+	    
+    //Boolean expr
+    c = a&&b;
+    c = a*b;
+    if(c)
+    	printInt(1);
+    else
+    	printInt(0);
+    	
+	printNewlines(1);
+    c = a+b;
+    if(c)
+    	printInt(1);
+    else
+    	printInt(0);    
+ 
+	c = a*b;
+	if(c)
+    	printInt(1);
+    else
+    	printInt(0);   
+
+}

+ 47 - 0
test/testsuite/functional_test/14_type_checking_cast.cvc

@@ -0,0 +1,47 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+int foo(int a, float b,int c)
+{
+	return a+(int)b+c;
+}
+
+
+int fun()
+{
+	int a=1;
+	int b=2;
+	int c=3;
+	int d=4;
+	float w=1.0;
+	float x=2.0;
+	//bool q = TRUE;  This is the original line, which has a typo
+	bool q = true;
+
+	d = (int)(a<b&&c>d);
+	printInt(d);//0
+	printNewlines(1);
+
+	d = foo((int)(a<c),w+x,(int)(b<d));//4
+	printInt(d);//5
+	printNewlines(1);
+
+
+	if(b<d||a>c)
+		a=7;
+
+	return 1;
+}
+
+int main()
+{
+	fun();
+
+	return fun();
+}

+ 119 - 0
test/testsuite/functional_test/14_type_checking_cast.s

@@ -0,0 +1,119 @@
+foo:
+	esr 0
+	iload_0
+	fload_1
+	f2i
+	iadd
+	iload_2
+	iadd
+	ireturn
+fun:
+	esr 7
+	iloadc_1
+	istore 0
+	iloadc 0
+	istore 1
+	iloadc 1
+	istore 2
+	iloadc 2
+	istore 3
+	floadc_1
+	fstore 4
+	floadc 3
+	fstore 5
+	bloadc_f
+	bstore 6
+	iload_0
+	iload_1
+	ilt
+	branch_f false$4
+	iload_2
+	iload_3
+	igt
+	jump end$5
+false$4:
+	bloadc_f
+end$5:
+	branch_f false$2
+	iloadc_1
+	jump end$3
+false$2:
+	iloadc_0
+end$3:
+	istore 3
+	isrg
+	iload_3
+	jsre 0
+	isrg
+	iloadc_1
+	jsre 5
+	isrg
+	iload_0
+	iload_2
+	ilt
+	branch_f false$6
+	iloadc_1
+	jump end$7
+false$6:
+	iloadc_0
+end$7:
+	fload 4
+	fload 5
+	fadd
+	iload_1
+	iload_3
+	ilt
+	branch_f false$8
+	iloadc_1
+	jump end$9
+false$8:
+	iloadc_0
+end$9:
+	jsr 3 foo
+	istore 3
+	isrg
+	iload_3
+	jsre 0
+	isrg
+	iloadc_1
+	jsre 5
+	iload_1
+	iload_3
+	ilt
+	branch_f false$10
+	bloadc_t
+	jump end$11
+false$10:
+	iload_0
+	iload_2
+	igt
+end$11:
+	branch_f end$1
+	iloadc 4
+	istore 0
+end$1:
+	iloadc_1
+	ireturn
+main:
+	esr 0
+	isrg
+	jsr 0 fun
+	ipop
+	isrg
+	jsr 0 fun
+	ireturn
+__init:
+	esr 0
+	return
+.import "printInt" void int
+.import "printFloat" void float
+.import "scanInt" int
+.import "scanFloat" float
+.import "printSpaces" void int
+.import "printNewlines" void int
+.export "__init" void __init
+.const int 2
+.const int 3
+.const int 4
+.const float 2.0
+.const int 7

+ 42 - 0
test/testsuite/functional_test/1_array.cvc

@@ -0,0 +1,42 @@
+extern void printInt(int i);
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+export int main()
+{
+    int a;
+    int b;
+	int [5,3]t =1;
+	
+    int [5,3]c =[[1,2,300],
+				 1,
+				 3,
+				 [3,4],
+				 6
+				];
+
+
+	c[4-2,2] = 2;
+	for(int q=0,5)
+	{
+		for(int p=0,3)
+		{	printInt(c[q,p]);
+			printSpaces(3);
+		}
+		printNewlines(1);
+		
+	}
+	printNewlines(3);
+	
+	for(int q=0,5)
+	{
+		for(int p=0,3)
+		{	printInt(t[q,p]);
+			printSpaces(3);
+		}
+		printNewlines(1);
+	}
+	
+    return 1;
+}
+

+ 18 - 0
test/testsuite/functional_test/4_arth2.cvc

@@ -0,0 +1,18 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+export int main(){
+	int a = 5;
+	float b = 6.0;
+	int c = a + ((int)(b))* a;
+	printInt(c);
+	printNewlines(1);
+	// it should print 35
+	return 0;
+}

+ 28 - 0
test/testsuite/functional_test/7_euclides.cvc

@@ -0,0 +1,28 @@
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+export int main() {
+    int a = scanInt();
+    int b = scanInt();
+    int gcd() 
+	{
+        int t;
+        while(b != 0) 
+		{
+            t = b;
+            b = a % b;
+            a = t;
+        }
+        return a;
+    }
+
+	printInt(gcd());
+	printNewlines(1);
+	return 0;
+}

+ 118 - 0
test/testsuite/functional_test/9_inner_fun.cvc

@@ -0,0 +1,118 @@
+/*
+ * Different shadowing concepts illustrated
+ */
+
+extern void printInt( int val);
+extern void printFloat( float val);
+
+extern int scanInt( );
+extern float scanFloat( );
+
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+
+export int main()
+{
+
+    // this variable is going will be escaping below
+    int a = scanInt();
+
+    // The bir variable is an example of a local (ie non-escaped) variable
+    int bir = a;
+
+    /* A variable shadowed by an argument */
+    void bar (int a)
+    {
+        a = 11111;
+        printInt(a);
+		printNewlines(1);
+    }
+
+    /* A variable initalized by a variable of the same name */
+    void boz ()
+    {
+        int a = a;
+        a = a + 11111;
+        printInt(a);
+		printNewlines(1);		
+    }
+
+    /* using a in the inner function makes it an escaped variable */
+    void biz ()
+    {
+        a = 55555;
+    }
+
+
+
+    bar(a);
+    printNewlines(1);
+    printInt(a);
+    printNewlines(2);
+
+    baz(a);
+    printNewlines(1);
+    printInt(a);
+    printNewlines(2);
+
+    bor(a);
+    printNewlines(1);
+    printInt(a);
+    printNewlines(2);
+
+    boz();
+    printNewlines(1);
+    printInt(a);
+    printNewlines(2);
+
+    printInt(bir);
+    printNewlines(2);
+
+    biz();
+    printInt(a);
+    printNewlines(2);
+    printInt(bir);
+    printNewlines(2);
+
+    return 0;
+
+}
+
+ /* An argument shadowed by a variable */
+void baz(int b){
+
+    // The variable b cannot be defined in the same scope hence it is in an inner function
+    void baz_inner(){
+        int b = 22222;
+        printInt(b);
+    }
+
+    baz_inner();
+
+}
+
+
+ /* An argument shadowed by a variable */
+void bor(int b){
+
+    // The function b cannot be defined in the same scope hence it is in an inner function
+    void baz_inner(){
+
+        void b() {
+            printInt(33333);
+        }
+        b();
+    }
+
+    baz_inner();
+
+}
+
+
+ /* This function is going to be shadowed by a variable in main */
+void bir(){
+
+    printInt(3333);
+
+}

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio