浏览代码

Added new testsuite

Taddeus Kroes 12 年之前
父节点
当前提交
7dd8ec8281
共有 47 个文件被更改,包括 1416 次插入4 次删除
  1. 5 4
      Makefile
  2. 6 0
      test/arrays/check_success/global_arraydef.cvc
  3. 4 0
      test/arrays/check_success/init_arrayconst.cvc
  4. 8 0
      test/arrays/check_success/local_arraydef.cvc
  5. 53 0
      test/arrays/check_success/scan_vector_matrix.cvc
  6. 82 0
      test/arrays/functional/8_queen.cvc
  7. 27 0
      test/arrays/functional/array_init.cvc
  8. 73 0
      test/arrays/functional/array_single_eval.cvc
  9. 30 0
      test/arrays/functional/dimreduce.cvc
  10. 80 0
      test/arrays/functional/matrix_mult.cvc
  11. 41 0
      test/arrays/functional/matrix_print.cvc
  12. 85 0
      test/arrays/functional/quicksort.cvc
  13. 1 0
      test/arrays/functional/quicksort.out~
  14. 1 0
      test/basic/check_error/duplicate_dimension_name.cvc
  15. 3 0
      test/basic/check_error/export_extern_fun.cvc
  16. 10 0
      test/basic/check_error/integer_out_of_range.cvc
  17. 4 0
      test/basic/check_error/invalid_monop_type.cvc
  18. 4 0
      test/basic/check_error/invalid_return_type.cvc
  19. 10 0
      test/basic/check_error/invalid_statements.cvc
  20. 4 0
      test/basic/check_error/undefined_var.cvc
  21. 4 0
      test/basic/check_error/void_cast.cvc
  22. 8 0
      test/basic/check_success/binops.cvc
  23. 35 0
      test/basic/check_success/boolop.cvc
  24. 9 0
      test/basic/check_success/do_while.cvc
  25. 4 0
      test/basic/check_success/extern_var.cvc
  26. 4 0
      test/basic/check_success/globaldec.cvc
  27. 4 0
      test/basic/check_success/params_simple.cvc
  28. 8 0
      test/basic/check_success/vardec_init.cvc
  29. 1 0
      test/basic/combined_extern_var/defs.cvc
  30. 9 0
      test/basic/combined_extern_var/main.cvc
  31. 25 0
      test/basic/functional/array_init.cvc
  32. 73 0
      test/basic/functional/array_single_eval.cvc
  33. 70 0
      test/basic/functional/bool_op.cvc
  34. 26 0
      test/basic/functional/factorial.cvc
  35. 44 0
      test/basic/functional/for_to_while.cvc
  36. 40 0
      test/basic/functional/forloop.cvc
  37. 39 0
      test/basic/functional/nested_funs.cvc
  38. 24 0
      test/basic/functional/pi.cvc
  39. 30 0
      test/basic/functional/prime.cvc
  40. 54 0
      test/basic/functional/typecheck.cvc
  41. 8 0
      test/civic.h
  42. 13 0
      test/nested_funs/check_success/local_funs.cvc
  43. 14 0
      test/nested_funs/check_success/local_funs_with_body.cvc
  44. 33 0
      test/nested_funs/functional/euclid.cvc
  45. 37 0
      test/nested_funs/functional/nested_funs.cvc
  46. 113 0
      test/nested_funs/functional/scopes.cvc
  47. 156 0
      test/run.bash

+ 5 - 4
Makefile

@@ -15,9 +15,9 @@ OCAMLFLAGS := -g
 OCAMLYACC := menhir
 YFLAGS := --infer --explain
 
-CIVAS := ../bin32/civas
-CIVVM := ../bin32/civvm
-CIVCC := ../civicc
+CIVAS := bin32/civas
+CIVVM := bin32/civvm
+CIVCC := ./civicc
 
 DIST_TGT := civicaml.tgz
 DIST_FILES := $(RESULT) $(SOURCES) Makefile OCamlMakefile README.md test bin32 \
@@ -37,7 +37,8 @@ myclean:
 	rm -f a.out $(DIST_TGT)
 
 check: all
-	@cd test; CIVAS=$(CIVAS) CIVVM=$(CIVVM) CIVCC=$(CIVCC) bash run.bash
+	@cd test; CIVAS=../$(CIVAS) CIVVM=../$(CIVVM) CIVCC=../$(CIVCC) \
+		bash run.bash basic nested_funs arrays
 
 dist: $(DIST_TGT)
 

+ 6 - 0
test/arrays/check_success/global_arraydef.cvc

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

+ 4 - 0
test/arrays/check_success/init_arrayconst.cvc

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

+ 8 - 0
test/arrays/check_success/local_arraydef.cvc

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

+ 53 - 0
test/arrays/check_success/scan_vector_matrix.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;
+}
+

+ 82 - 0
test/arrays/functional/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;
+}

+ 27 - 0
test/arrays/functional/array_init.cvc

@@ -0,0 +1,27 @@
+extern void printInt(int val);
+extern void printSpaces(int num);
+extern void printNewlines(int num);
+
+void printArray2D(int[n, m] a) {
+    for (int i = 0, n) {
+        for (int j = 0, m) {
+            printInt(a[i, j]);
+            printSpaces(1);
+        }
+        printNewlines(1);
+    }
+}
+
+export int main() {
+    int[2,3] a = [[1, 2, 3], [4, 5, 6]];
+    int[2,3] b = 7;
+    int[2,3] c = [1, [2, 3, 4]];
+
+    printArray2D(a);
+    printNewlines(1);
+    printArray2D(b);
+    printNewlines(1);
+    printArray2D(c);
+
+    return 0;
+}

+ 73 - 0
test/arrays/functional/array_single_eval.cvc

@@ -0,0 +1,73 @@
+extern void printInt(int val);
+extern void printSpaces(int num);
+extern void printNewlines(int num);
+
+int ones = 0;
+int twos = 0;
+
+int one() {
+    ones = ones + 1;
+    return 1;
+}
+
+int two() {
+    twos = twos + 1;
+    return 2;
+}
+
+void printArray1D(int[n] a) {
+    for (int i = 0, n) {
+        printInt(a[i]);
+        if (i != n - 1) printSpaces(1);
+    }
+    printNewlines(1);
+}
+
+void printArray2D(int[n, m] a) {
+    for (int i = 0, n) {
+        for (int j = 0, m) {
+            printInt(a[i, j]);
+            if (j != m - 1) printSpaces(1);
+        }
+        printNewlines(1);
+    }
+}
+
+void printArray3D(int[n, m, o] a) {
+    for (int i = 0, n) {
+        for (int j = 0, m) {
+            for (int k = 0, o) {
+                printInt(a[i, j, k]);
+                if (k != o - 1) printSpaces(1);
+            }
+            if (j != m - 1) printSpaces(2);
+        }
+        printNewlines(1);
+    }
+}
+
+export int main() {
+    int[two()] a        = one();
+    int[two(), two()] b = [[1, one()], [2, two()]];
+    int[2, 3] c         = [one(), two()];
+    int[2, 3, 3] d      = [one(), two()];
+
+    printArray1D(a);
+    printNewlines(1);
+
+    printArray2D(b);
+    printNewlines(1);
+
+    printArray2D(c);
+    printNewlines(1);
+
+    printArray3D(d);
+    printNewlines(1);
+
+    printInt(ones);
+    printSpaces(1);
+    printInt(twos);
+    printNewlines(1);
+
+    return 0;
+}

+ 30 - 0
test/arrays/functional/dimreduce.cvc

@@ -0,0 +1,30 @@
+extern void printInt( int val);
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+//extern int[n] ext;  FIXME
+int[3] glob;
+
+void printArray(int[n] a)
+{
+    for(int i = 0, n) {
+		printInt(a[i]);
+		printSpaces(1);
+	}
+    printNewlines(1);
+}
+
+void foo(int[n] param) {
+    printArray(param);  // Pass array parameter
+}
+
+export int main() {
+    int[5] loc = 4;
+    glob[0] = 1;
+    glob[1] = 2;
+    glob[2] = 3;
+    foo(loc);           // Pass local array
+    printArray(glob);   // Pass global array
+    //printArray(ext);    // Pass external array
+    return 0;
+}

+ 80 - 0
test/arrays/functional/matrix_mult.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);
+		}
+        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);
+		}
+        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;
+}
+
+

+ 41 - 0
test/arrays/functional/matrix_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;
+}
+

+ 85 - 0
test/arrays/functional/quicksort.cvc

@@ -0,0 +1,85 @@
+extern void printInt( int val);
+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);
+	}
+    printNewlines(1);
+}
+
+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;
+}
+
+

+ 1 - 0
test/arrays/functional/quicksort.out~

@@ -0,0 +1 @@
+1   2   2   4   5   6   7   8   9   10

+ 1 - 0
test/basic/check_error/duplicate_dimension_name.cvc

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

+ 3 - 0
test/basic/check_error/export_extern_fun.cvc

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

+ 10 - 0
test/basic/check_error/integer_out_of_range.cvc

@@ -0,0 +1,10 @@
+int i = 4189369722369384960;
+
+extern void printInt(int i);
+
+export int main()
+{
+  printInt(i);
+  return 0;
+}
+

+ 4 - 0
test/basic/check_error/invalid_monop_type.cvc

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

+ 4 - 0
test/basic/check_error/invalid_return_type.cvc

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

+ 10 - 0
test/basic/check_error/invalid_statements.cvc

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

+ 4 - 0
test/basic/check_error/undefined_var.cvc

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

+ 4 - 0
test/basic/check_error/void_cast.cvc

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

+ 8 - 0
test/basic/check_success/binops.cvc

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

+ 35 - 0
test/basic/check_success/boolop.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;
+
+}

+ 9 - 0
test/basic/check_success/do_while.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);
+}

+ 4 - 0
test/basic/check_success/extern_var.cvc

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

+ 4 - 0
test/basic/check_success/globaldec.cvc

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

+ 4 - 0
test/basic/check_success/params_simple.cvc

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

+ 8 - 0
test/basic/check_success/vardec_init.cvc

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

+ 1 - 0
test/basic/combined_extern_var/defs.cvc

@@ -0,0 +1 @@
+export int foo = 222;

+ 9 - 0
test/basic/combined_extern_var/main.cvc

@@ -0,0 +1,9 @@
+extern void printInt(int val);
+extern void printNewlines(int num);
+
+extern int foo;
+
+export int main() {
+    printInt(foo);
+    return 0;
+}

+ 25 - 0
test/basic/functional/array_init.cvc

@@ -0,0 +1,25 @@
+extern void printInt(int val);
+extern void printNewlines(int num);
+
+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;
+}

+ 73 - 0
test/basic/functional/array_single_eval.cvc

@@ -0,0 +1,73 @@
+extern void printInt(int val);
+extern void printSpaces(int num);
+extern void printNewlines(int num);
+
+int ones = 0;
+int twos = 0;
+
+int one() {
+    ones = ones + 1;
+    return 1;
+}
+
+int two() {
+    twos = twos + 1;
+    return 2;
+}
+
+void printArray1D(int[n] a) {
+    for (int i = 0, n) {
+        printInt(a[i]);
+        if (i != n - 1) printSpaces(1);
+    }
+    printNewlines(1);
+}
+
+void printArray2D(int[n, m] a) {
+    for (int i = 0, n) {
+        for (int j = 0, m) {
+            printInt(a[i, j]);
+            if (j != m - 1) printSpaces(1);
+        }
+        printNewlines(1);
+    }
+}
+
+void printArray3D(int[n, m, o] a) {
+    for (int i = 0, n) {
+        for (int j = 0, m) {
+            for (int k = 0, o) {
+                printInt(a[i, j, k]);
+                if (k != o - 1) printSpaces(1);
+            }
+            if (j != m - 1) printSpaces(2);
+        }
+        printNewlines(1);
+    }
+}
+
+export int main() {
+    int[two()] a        = one();
+    int[two(), two()] b = [[1, one()], [2, two()]];
+    int[2, 3] c         = [one(), two()];
+    int[2, 3, 3] d      = [one(), two()];
+
+    printArray1D(a);
+    printNewlines(1);
+
+    printArray2D(b);
+    printNewlines(1);
+
+    printArray2D(c);
+    printNewlines(1);
+
+    printArray3D(d);
+    printNewlines(1);
+
+    printInt(ones);
+    printSpaces(1);
+    printInt(twos);
+    printNewlines(1);
+
+    return 0;
+}

+ 70 - 0
test/basic/functional/bool_op.cvc

@@ -0,0 +1,70 @@
+extern void printInt(int val);
+extern void printNewlines(int num);
+
+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;
+}

+ 26 - 0
test/basic/functional/factorial.cvc

@@ -0,0 +1,26 @@
+extern void printInt(int val);
+extern void printNewlines(int num);
+
+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() {
+    printInt(fac(3));  printNewlines(1);
+    printInt(fac(5));  printNewlines(1);
+    printInt(fac(10)); printNewlines(1);
+	return 0;
+}
+

+ 44 - 0
test/basic/functional/for_to_while.cvc

@@ -0,0 +1,44 @@
+extern void printInt(int val);
+extern void printSpaces(int num);
+extern void printNewlines(int num);
+
+export int main() {
+    for(int i=0, 10) {
+        printInt(i);
+        printSpaces(1);
+    }
+
+    printNewlines(1);
+
+    for(int i=10, 0,-1) {
+        printInt(i);
+        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);
+    }
+
+    return 0;
+}

+ 40 - 0
test/basic/functional/forloop.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)
+	{
+			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;
+}

+ 39 - 0
test/basic/functional/nested_funs.cvc

@@ -0,0 +1,39 @@
+extern void printInt(int val);
+extern void printNewlines(int num);
+
+void foo() {
+    void bar() {
+        void bar() {
+            printInt(1);
+            foobar();  // isrn 1
+        }
+
+        printInt(2);
+        bar();     // isrl
+        baz();     // isrg
+        foobar();  // isr
+    }
+
+    void foobar() {}
+
+    printInt(3);    // isrg
+    bar();          // isrl
+    baz();          // isrg
+}
+
+void bar() {
+    printInt(4);
+}
+
+void baz() {
+    printInt(5);
+    bar();
+}
+
+export int main() {
+    foo();
+    bar();
+    baz();
+    printNewlines(1);
+    return 0;
+}

+ 24 - 0
test/basic/functional/pi.cvc

@@ -0,0 +1,24 @@
+extern void printFloat(float val);
+extern void printNewlines(int num);
+
+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;
+}

+ 30 - 0
test/basic/functional/prime.cvc

@@ -0,0 +1,30 @@
+extern void printInt(int val);
+extern void printNewlines(int num);
+
+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;
+}

+ 54 - 0
test/basic/functional/typecheck.cvc

@@ -0,0 +1,54 @@
+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;
+}
+
+void bar() {
+	int a = 5;
+	float b = 6.0;
+	int c = a + ((int)(b))* a;
+	printInt(c);
+	printNewlines(1);
+}
+
+export int main() {
+	fun();
+	bar();
+	return 0;
+}

+ 8 - 0
test/civic.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); 

+ 13 - 0
test/nested_funs/check_success/local_funs.cvc

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

+ 14 - 0
test/nested_funs/check_success/local_funs_with_body.cvc

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

+ 33 - 0
test/nested_funs/functional/euclid.cvc

@@ -0,0 +1,33 @@
+extern void printInt( int val);
+extern void printNewlines(int num);
+
+export int main() {
+    printInt(euclid(45, 10));           printNewlines(1);
+    printInt(euclid(13, 13));           printNewlines(1);
+    printInt(euclid(37, 600));          printNewlines(1);
+    printInt(euclid(20, 100));          printNewlines(1);
+    printInt(euclid(624129, 2061517));  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;
+}

+ 37 - 0
test/nested_funs/functional/nested_funs.cvc

@@ -0,0 +1,37 @@
+extern void printInt(int val);
+
+void foo() {
+    void bar() {
+        void bar() {
+            printInt(1);
+            foobar();  // isrn 1
+        }
+
+        printInt(2);
+        bar();     // isrl
+        baz();     // isrg
+        foobar();  // isr
+    }
+
+    void foobar() {}
+
+    printInt(3);    // isrg
+    bar();          // isrl
+    baz();          // isrg
+}
+
+void bar() {
+    printInt(4);
+}
+
+void baz() {
+    printInt(5);
+    bar();
+}
+
+export int main() {
+    foo();
+    bar();
+    baz();
+    return 0;
+}

+ 113 - 0
test/nested_funs/functional/scopes.cvc

@@ -0,0 +1,113 @@
+/*
+ * Different shadowing concepts illustrated
+ */
+
+extern void printInt( int val);
+extern void printSpaces( int num);
+extern void printNewlines( int num);
+
+
+export int main()
+{
+
+    // this variable is going will be escaping below
+    int a = 123;
+
+    // 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);
+
+}

+ 156 - 0
test/run.bash

@@ -0,0 +1,156 @@
+#!/usr/bin/env bash
+CIVAS=${CIVAS-../bin32/civas}
+CIVVM=${CIVVM-../bin32/civvm}
+CIVCC=${CIVCC-../civicc}
+CFLAGS="-v 1"
+
+ALIGN=52
+
+total_tests=0
+failed_tests=0
+
+# The real tests: compile a file, run it, and compare the output to the
+# expected output.
+function check_output {
+    file=$1
+    expect_file=${file%.*}.out
+
+    if [ ! -f $file ]; then return; fi
+
+    total_tests=$((total_tests+1))
+    printf "%-${ALIGN}s " $file:
+
+    if $CIVCC $CGLAGS -o tmp.s $file > 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 $expect_file --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
+}
+
+# Special case: multiple files must be compiled and run together (e.g., for
+# extern variables). Compile all the *.cvc files in the given directory, run
+# them, and compare the output to the content of expected.out.
+function check_combined {
+    dir=$1
+    expect_file=$dir/expected.out
+
+    if [ ! -d $dir ]; then return; fi
+    if [ ! -f $expect_file ]; then return; fi
+
+    files=`find $dir -maxdepth 1 -name \*.cvc`
+    total_tests=$((total_tests+1))
+    compiled=1
+    ofiles=""
+    compiled_files=""
+
+    printf "%-${ALIGN}s " $dir:
+
+    for file in $files
+    do
+        asfile=${file%.*}.s
+        ofile=${file%.*}.o
+        ofiles="$ofiles $ofile"
+
+        if $CIVCC $CGLAGS -o $asfile $file &&
+           $CIVAS -o $ofile $asfile
+        then
+            compiled_files="$compiled_files `basename $file`"
+        else
+            compiled=0
+        fi
+    done
+
+    if [ $compiled -eq 1 ]
+    then
+        if $CIVVM $ofiles > tmp.out 2>&1 &&
+           mv tmp.out tmp.res &&
+           diff tmp.res $expect_file --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
+    else
+        echo "failed, only compiled$compiled_files"
+        failed_tests=$((failed_tests+1))
+    fi
+
+    rm -f $d/*.s $d/*.o tmp.out tmp.res
+}
+
+# Easy tests, check if the parser, context analysis and typechecking work
+# properly by checking if the compiler returns 0 (or non-zero when expected to
+# fail)
+function check_return {
+    file=$1
+    expect_failure=$2
+
+    if [ ! -f $file ]; then return; fi
+
+    total_tests=$((total_tests+1))
+    printf "%-${ALIGN}s " $file:
+
+    if $CIVCC $CFLAGS $file -o tmp.s > /dev/null 2>&1
+    then
+        if [ $expect_failure -eq 1 ]; then
+            echo failed
+            failed_tests=$((failed_tests+1))
+        else
+            echo success
+        fi
+    else
+        if [ $expect_failure -eq 1 ]; then
+            echo success
+        else
+            echo failed
+            failed_tests=$((failed_tests+1))
+        fi
+    fi
+
+    rm -f tmp.s
+}
+
+function run_dir {
+    BASE=$1
+
+    for f in $BASE/check_success/*.cvc; do
+        check_return $f 0
+    done
+
+    for f in $BASE/check_error/*.cvc; do
+        check_return $f 1
+    done
+
+    for f in $BASE/functional/*.cvc; do
+        check_output $f
+    done
+
+    for d in $BASE/combined_*; do
+        check_combined $d
+    done
+
+    echo
+}
+
+for arg in $@; do
+    run_dir $arg
+done
+
+echo $total_tests tests, $failed_tests failures