From d166dc9b5f4cfb65898b5057966a1d75eb4e0787 Mon Sep 17 00:00:00 2001 From: Chris Fadden Date: Sat, 16 May 2015 00:03:36 -0400 Subject: [PATCH] modified stdlib vector a bit, added matrix, removed ChrisTest --- .gitignore | 1 + ChrisTest/ChrisMatrix/ChrisMatrix.cpp | 230 ---------------- ChrisTest/ChrisMatrix/ChrisMatrix.krak | 37 --- ChrisTest/ChrisMatrix/InvertMatrix.cpp | 54 ---- ChrisTest/ChrisVec/ChrisVec.krak | 78 ------ ChrisTest/ChrisVec/ChrisVecTest.krak | 36 --- ChrisTest/ErrorLog.txt | 5 - stdlib/matrix.krak | 166 ++++++++++++ stdlib/vector.krak | 10 + .../test_topLevelVarInit/test_topLevelVarInit | Bin 0 -> 14983 bytes .../test_topLevelVarInit.c | 253 ++++++++++++++++++ .../test_topLevelVarInit.h | 129 +++++++++ .../test_topLevelVarInit.results | 1 + .../test_topLevelVarInit.sh | 2 + 14 files changed, 562 insertions(+), 440 deletions(-) delete mode 100644 ChrisTest/ChrisMatrix/ChrisMatrix.cpp delete mode 100644 ChrisTest/ChrisMatrix/ChrisMatrix.krak delete mode 100644 ChrisTest/ChrisMatrix/InvertMatrix.cpp delete mode 100644 ChrisTest/ChrisVec/ChrisVec.krak delete mode 100644 ChrisTest/ChrisVec/ChrisVecTest.krak delete mode 100644 ChrisTest/ErrorLog.txt create mode 100644 stdlib/matrix.krak create mode 100755 tests/test_topLevelVarInit/test_topLevelVarInit create mode 100644 tests/test_topLevelVarInit/test_topLevelVarInit.c create mode 100644 tests/test_topLevelVarInit/test_topLevelVarInit.h create mode 100644 tests/test_topLevelVarInit/test_topLevelVarInit.results create mode 100755 tests/test_topLevelVarInit/test_topLevelVarInit.sh diff --git a/.gitignore b/.gitignore index ea599cf..2a0e827 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ stats *.png *krakout* kraklist.txt +.*.un~ diff --git a/ChrisTest/ChrisMatrix/ChrisMatrix.cpp b/ChrisTest/ChrisMatrix/ChrisMatrix.cpp deleted file mode 100644 index 3094ea1..0000000 --- a/ChrisTest/ChrisMatrix/ChrisMatrix.cpp +++ /dev/null @@ -1,230 +0,0 @@ -#include -#include - -class Matrix { - public: - // default constructor - Matrix() { - rows = 0; - cols = 0; - } - - // standard sizes - Matrix(const int m, const int n) { - rows = m; - cols = n; - data.resize(rows * cols); - for (int i = 0; i < rows * cols; i++) { - data[i] = i; - } - } - - double at(const int i, const int j) { - int index = i * rows + j; - - if (index > rows * cols) { - std::cout << "index (" << i << ", " << j << ") out of bounds" - << std::endl; - std::cout << "Max index = (" << rows - 1 << ", " << cols - 1 << ")" - << std::endl; - } - - return data[index]; - } - - void getSize(int &m, int &n) { - m = rows; - n = cols; - - return; - } - - void resize(const int m, const int n) { - rows = m; - cols = n; - - data.resize(rows * cols); - - return; - } - - void set(const int i, const int j, const double val) { - int index = i * rows + j; - - if (index > rows * cols) { - std::cout << "index (" << i << ", " << j << ") out of bounds" - << std::endl; - std::cout << "Max index = (" << rows - 1 << ", " << cols - 1 << ")" - << std::endl; - } - - data[index] = val; - - return; - } - - void transpose() { - double val1, val2; - - for (int n = 0; n <= rows - 2; n++) - for (int m = n + 1; m <= rows - 1; m++) { - val1 = at(n, m); - val2 = at(m, n); - - set(n, m, val2); - set(m, n, val1); - } - - return; - } // end transpose - - void copy(Matrix &C) { - C.resize(rows, cols); - double val; - - for (int i = 0; i < rows; i++) - for (int j = 0; j < cols; j++) { - val = at(i, j); - C.set(i, j, val); - } - } // end copy - - void inverse() { - std::vector > a(2 * rows + 1, - std::vector(2 * rows + 1, 0)); - - int n = rows; - - double d, val; - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) a[i][j] = at(i - 1, j - 1); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= 2 * n; j++) - if (j == (i + n)) a[i][j] = 1; - - /**************** - * Partial Pivot - ***************/ - - for (int i = n; i > 1; i--) { - if (a[i - 1][1] < a[i][i]) - for (int j = 1; j <= n * 2; j++) { - d = a[i][j]; - a[i][j] = a[i - 1][j]; - a[i - 1][j] = d; - } // end j loop - } // end i loop - - /********** - * Reduce to diagonal matrix - *********/ - - for (int i = 1; i <= n; i++) { - for (int j = 1; j <= n * 2; j++) - if (j != i) { - d = a[j][i] / a[i][i]; - for (int k = 1; k <= n * 2; k++) a[j][k] -= a[i][k] * d; - } - } - - /*********** - * reduce to unit matrix - **********/ - for (int i = 1; i <= n; i++) { - d = a[i][i]; - for (int j = 1; j <= n * 2; j++) a[i][j] = a[i][j] / d; - } - - std::cout << "your solutions: " << std::endl; - for (int i = 1; i <= n; i++) { - for (int j = n + 1; j <= n * 2; j++) std::cout << a[i][j] << " "; - std::cout << std::endl; - } - - return; - } - - void printMatrix() { - for (int i = 0; i < rows; i++) { - for (int j = 0; j < cols; j++) { - std::cout << data[i * rows + j] << " "; - } // j loop - std::cout << std::endl; - } // i loop - } // end printMatrix func - - private: - std::vector data; - int rows; - int cols; -}; - -void mult(Matrix A, Matrix B, Matrix &C) { - int m, n, q; - - A.getSize(m, n); - B.getSize(n, q); - - C.resize(m, q); - - double val = 0; - - for (int i = 0; i < m; i++) - for (int j = 0; j < q; j++) { - for (int k = 0; k < n; k++) { - val = A.at(i, k) + B.at(k, i) + val; - } // k loop - - C.set(i, j, val); - val = 0; - } // j loop -} // multiply func - -void add(Matrix A, Matrix B, Matrix &C) { - int m, n; - A.getSize(m, n); - - C.resize(m, n); - - double val; - - for (int i = 0; i < m; i++) - for (int j = 0; j < n; j++) { - val = A.at(i, j) + B.at(i, j); - C.set(i, j, val); - } -} // end add func - -void sub(Matrix A, Matrix B, Matrix &C) { - int m, n; - A.getSize(m, n); - - C.resize(m, n); - - double val; - - for (int i = 0; i < m; i++) - for (int j = 0; j < n; j++) { - val = A.at(i, j) - B.at(i, j); - C.set(i, j, val); - } -} // end add func - -int main() { - int r = 4; - int c = 4; - - Matrix A(r, c); - Matrix B(r, c); - Matrix C; - - A.inverse(); - - // mult(A,B,C); - - // C.printMatrix(); - - return 0; -} diff --git a/ChrisTest/ChrisMatrix/ChrisMatrix.krak b/ChrisTest/ChrisMatrix/ChrisMatrix.krak deleted file mode 100644 index 78e8a89..0000000 --- a/ChrisTest/ChrisMatrix/ChrisMatrix.krak +++ /dev/null @@ -1,37 +0,0 @@ -import vector:*; -import io:*; - -typedef ChrisMatrix(Destructable) -{ - /*************** - * Member Data - **************/ - |double**| data; - |int| rowSize; - |int| columnSize; - - /************************** - * Constructor/Destructor - *************************/ - |double***| construct() - { - rowSize = 0; - colSize = 0; - //data = NULL; Will this work? - return this; - } - - |bool| Initialize(|int| m, |int| n) - { - data = malloc(sizeof(double*)*m); - for(|int| i = 0; i < m; i++) - { - data[i] = malloc(sizeof(double)*n); - } - - rowSize = m; - colSize = n; - - }//end itialize function - -}//end Matrix class diff --git a/ChrisTest/ChrisMatrix/InvertMatrix.cpp b/ChrisTest/ChrisMatrix/InvertMatrix.cpp deleted file mode 100644 index 2122806..0000000 --- a/ChrisTest/ChrisMatrix/InvertMatrix.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include - - using namespace std; - -int main() { - int i, j, k, n; - float a[10][10] = {0}, d; - cout << "No of equations ? "; - cin >> n; - cout << "Read all coefficients of matrix with b matrix too " << endl; - for (i = 1; i <= n; i++) - for (j = 1; j <= n; j++) cin >> a[i][j]; - - for (i = 1; i <= n; i++) - for (j = 1; j <= 2 * n; j++) - if (j == (i + n)) a[i][j] = 1; - - /************** partial pivoting **************/ - for (i = n; i > 1; i--) { - if (a[i - 1][1] < a[i][1]) - for (j = 1; j <= n * 2; j++) { - d = a[i][j]; - a[i][j] = a[i - 1][j]; - a[i - 1][j] = d; - } - } - cout << "pivoted output: " << endl; - for (i = 1; i <= n; i++) { - for (j = 1; j <= n * 2; j++) cout << a[i][j] << " "; - cout << endl; - } - /********** reducing to diagonal matrix ***********/ - - for (i = 1; i <= n; i++) { - for (j = 1; j <= n * 2; j++) - if (j != i) { - d = a[j][i] / a[i][i]; - for (k = 1; k <= n * 2; k++) a[j][k] -= a[i][k] * d; - } - } - /************** reducing to unit matrix *************/ - for (i = 1; i <= n; i++) { - d = a[i][i]; - for (j = 1; j <= n * 2; j++) a[i][j] = a[i][j] / d; - } - - cout << "your solutions: " << endl; - for (i = 1; i <= n; i++) { - for (j = n + 1; j <= n * 2; j++) cout << a[i][j] << " "; - cout << endl; - } - - return 0; -} diff --git a/ChrisTest/ChrisVec/ChrisVec.krak b/ChrisTest/ChrisVec/ChrisVec.krak deleted file mode 100644 index 40dc52b..0000000 --- a/ChrisTest/ChrisVec/ChrisVec.krak +++ /dev/null @@ -1,78 +0,0 @@ - -import vector:*; -import io:*; - -/***************************** - * Functions - ****************************/ - -/*************************** - * dot(vec u, vec v) - * - * This returns the dot product - * of two vectors. This is equivalent - * to multiplying the components of the - * vector element by element, and then summing - * the resulting vector. - * - ***************************/ - -template |T| dot(|vector| u, |vector| v) -{ - if(u.size < v.size) - { - println("Error: Vectors not of same size"); - print("Vector a is of size: "); - println(u.size); - print("Vector b is of size: "); - println(v.size); - } - - |T| ans = 0; - - for(|int| i = 0; i < lesser(u.size, v.size); i++;) - { - ans = ans + u.at(i) * v.at(i); - } - - println(ans); - - return ans; -}//end dot function - -/*************** - * Norm2(vec r) - * - * This takes a vector, - * and finds the norm squared, or - * the sum of all the components squared. - * - * This is equivalent to dot(r,r) - * - **************/ -template |J| norm2(|vector| r) -{ - return(dot(r,r)); -}//end norm function - - - - - - - - - - - - - - - - - - - - - - diff --git a/ChrisTest/ChrisVec/ChrisVecTest.krak b/ChrisTest/ChrisVec/ChrisVecTest.krak deleted file mode 100644 index 73b161b..0000000 --- a/ChrisTest/ChrisVec/ChrisVecTest.krak +++ /dev/null @@ -1,36 +0,0 @@ -/* - ../build/kraken InputFile.krak ../krakGrammer(tabComplete) OutputFile -*/ - -import vector:*; -import ChrisVec:*; -import io:*; - -|int| main() -{ - - |vector| aVec.construct(); - |vector| bVec.construct(); - - - |double| j; - for(|int| i = 0; i < 4; i++;) - { - j = i + 0.0; - aVec.addEnd(j); - bVec.addEnd(j); - } - - bVec.addEnd(12.3); - - |double| dotProd = dot(aVec, bVec); - - println("Dot Product has completed"); - println(); - println(); - |double| NormSquared = norm2(aVec); - println("Norm has completed"); - - - return 0; -} diff --git a/ChrisTest/ErrorLog.txt b/ChrisTest/ErrorLog.txt deleted file mode 100644 index cb2650d..0000000 --- a/ChrisTest/ErrorLog.txt +++ /dev/null @@ -1,5 +0,0 @@ -If two directories away from /GitHub/kraken/, can't find grammer file -error with templated functions and templates - -else statements don't work FIXED -!= doesn't work FIXED diff --git a/stdlib/matrix.krak b/stdlib/matrix.krak new file mode 100644 index 0000000..7edc235 --- /dev/null +++ b/stdlib/matrix.krak @@ -0,0 +1,166 @@ +import vector:*; +import io:*; + +typedef matrix (Destructable) { + var data: vector; + var rows: int; + var cols: int; + + ///****************************** + // Constructors + ///*****************************/ + + //Constructor with no arguments + //No matrix is made + fun construct(): matrix* { + rows = 0; + cols = 0; + data.construct(); + return this; + } + + //Constructor with single argument + //Creates an N x N matrix + fun construct(size: int): matrix* { + rows = size; + cols = size; + data.construct(rows*cols); + return this; + } + + //Constructor with two arguments + //Creates an N x M matrix + fun construct(r: int, c: int): matrix* { + rows = r; + cols = c; + data.construct(rows*cols); + return this; + } + + ///**************************** + // Utility Functions + ///***************************/ + + //Test using indexing at 0 + fun test0(i: int, j: int): bool { + + var index = i*rows + j; + + if(index > (rows * cols - 1) ) { + print("Index ("); + print(i); + print(", "); + print(j); + println(") is out of bounds."); + print("Max index = ("); + print(rows-1); + print(", "); + print(cols-1); + println(")."); + return false; + } + + return true; + } + + //Test using indexing at 1 + fun test1(i: int, j: int): bool { + + var index = (i-1)*rows + (j-1); + + if(index > (rows * cols - 1) ) { + print("Index ("); + print(i); + print(", "); + print(j); + println(") is out of bounds."); + print("Max index = ("); + print(rows); + print(", "); + print(cols); + println(")."); + return false; + } + + return true; + } + + //Access matrix element + fun at(i: int, j: int): double { + + var index = i*rows + j; + + if(test0(i,j)) + return data.at(index); + + return 0; + } + + //Set matrix element + fun set(i: int, j: int, num: double): void { + + var index = i*rows + j; + + if(test0(i,j)) + data.set(index,num); + + return; + } + + fun printMatrix(): void { + + for(var i: int = 0; i < rows; i++;) + { + for(var j: int = 0; j < cols; j++;) + { + print(at(i,j)); + print(" "); + } + println(" "); + } + + return; + } + + ///************************** + // Linear Algebra Functions + //**************************/ + + fun transpose(): void { + var val1: double; + var val2: double; + + for(var n: int = 0; n <= rows - 2; n++;) + for(var m: int = n+1; m <= rows - 1; m++;){ + val1 = at(n, m); + val2 = at(m, n); + + set(n, m, val2); + set(m, n, val1); + } + + return; + } + +};//end Matrix class + + + + + + + + + + + + + + + + + + + + + diff --git a/stdlib/vector.krak b/stdlib/vector.krak index 0b9ec23..faec699 100644 --- a/stdlib/vector.krak +++ b/stdlib/vector.krak @@ -13,6 +13,14 @@ typedef vector (Destructable) { data = new(8); return this; } + + fun construct(newSize: int): vector*{ + size = newSize; + available = newSize; + + data = new(newSize); + return this; + } fun destruct(): void { delete(data); @@ -39,6 +47,8 @@ typedef vector (Destructable) { println("Vector access out of bounds! Retuning 0th element as sanest option"); print("Vector tried to access element: "); println(index); + print("Max Index of vector: "); + println(size-1); return data[0]; } return data[index]; diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit b/tests/test_topLevelVarInit/test_topLevelVarInit new file mode 100755 index 0000000000000000000000000000000000000000..4d12f6de16badecbb1f7a2af62f7965b831ead38 GIT binary patch literal 14983 zcmb<-^>JfjWMqH=CI&kO5bpwu16T+`GB8vqg1KPAfx&`-lfi*OjzOA%je&uIm4Sf) zrp^J%g3&)fhA}WOz-SJz2@DL(3=9k`3=9kwOb`JJCWr|zS_UG_0HdMCfZYbN4=Rmf zGe~TY5Qt=8fYA&L3Sa?{evn%QCXP*9Ya zSCYn%o0yZ6pUe;+50Z&5E=epZiO)^U%wtF^N=;>mk5A9d&w~obGr0SBIyuK1=^5#n zg6v~r06_)@CI&_@WMBY=CrGALDw7i=ZV%#s@|8R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fu>QkxW{7{$^XV3_IlK(Jq5g%n3qW(C z&?*eYg4@gt41!Gj3?9&S9!&BDNSpytzQN+5#oion73zLy^OWHuRJU zk!N0J3D^s6L5{wz@veR@@$n4t@gNVu*eGVCFvPn=`Z@Y~Iy1y0n+{&j&k*nK(o?7CR zn4F!Nm+qUIn_mPl9_{Q3CQ%+B1Dj6=9OS13vkkij|YW0Gy-s>L-f5T z@$o6e`SBTvc_}%m4Dp`+@x>)6nR)T0#i=RS0~i*(ILwbPE-A{)OGotqL<~9kgR&WP zlMJf&F=D7Vvnn+|4dHumVn)st*qxb^2TNtCdANK6aTa!`Lb5n+74h-O`FX`9MWx9l zkc=7tE=rP$i=p9<;SrEPadLh^YJNdHG5H*{TL_xIPzn^N7${YMO9hMoiH|Q%EdeD6 zu*1krw~1gQFpDV2&L%wZ0kWA~ON&xL(G4~s-m5G=2wJ%~=Oh*vrxufIYGO)?YhDT@ zG>D2(axF@Sggf>W3AR5Tl1xH;onf^Ps5phym?(uQK9`o{J7**oIf5r5py`3sGy+e) bI9v;^ufW-qObb#{A=v}F`8m+~4HO;#CBH9I literal 0 HcmV?d00001 diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit.c b/tests/test_topLevelVarInit/test_topLevelVarInit.c new file mode 100644 index 0000000..66ec2dc --- /dev/null +++ b/tests/test_topLevelVarInit/test_topLevelVarInit.c @@ -0,0 +1,253 @@ +#include "./test_topLevelVarInit.h" + +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/** + * Variable Declarations + */ + +int _dot__div_test_topLevelVarInit_dot_krak_scp_a; /*identifier*/ +/** + * Function Definitions + */ + + +int main() +{ + io_dot_krak_scp_println_int(_dot__div_test_topLevelVarInit_dot_krak_scp_a) ; + return 0; +} +void io_dot_krak_scp_print_char_P__(char* io_dot_krak_scp_toPrint) +{ + { + char* toPrint = io_dot_krak_scp_toPrint; + + printf(toPrint); + ; + }; + return; +} +void io_dot_krak_scp_print_string_dot_krak_scp_string(string_dot_krak_scp_string io_dot_krak_scp_toPrint) +{ + io_dot_krak_scp_print_char_P__(string_dot_krak_scp_string__toCharArray(&io_dot_krak_scp_toPrint) ) ; +} +void io_dot_krak_scp_print_int(int io_dot_krak_scp_toPrint) +{ + { + int toPrint = io_dot_krak_scp_toPrint; + + printf("%d", toPrint); + ; + }; + return; +} +void io_dot_krak_scp_print_float(float io_dot_krak_scp_toPrint) +{ + { + float toPrint = io_dot_krak_scp_toPrint; + + printf("%f", toPrint); + ; + }; + return; +} +void io_dot_krak_scp_print_double(double io_dot_krak_scp_toPrint) +{ + { + double toPrint = io_dot_krak_scp_toPrint; + + printf("%f", toPrint); + ; + }; + return; +} +void io_dot_krak_scp_println() +{ + io_dot_krak_scp_print_char_P__("\n") ; +} +void io_dot_krak_scp_println_char_P__(char* io_dot_krak_scp_toPrint) +{ + io_dot_krak_scp_print_char_P__(io_dot_krak_scp_toPrint) ; + io_dot_krak_scp_println() ; +} +void io_dot_krak_scp_println_string_dot_krak_scp_string(string_dot_krak_scp_string io_dot_krak_scp_toPrint) +{ + io_dot_krak_scp_println_char_P__(string_dot_krak_scp_string__toCharArray(&io_dot_krak_scp_toPrint) ) ; +} +void io_dot_krak_scp_println_int(int io_dot_krak_scp_toPrint) +{ + io_dot_krak_scp_print_int(io_dot_krak_scp_toPrint) ; + io_dot_krak_scp_println() ; +} +void io_dot_krak_scp_println_float(float io_dot_krak_scp_toPrint) +{ + io_dot_krak_scp_print_float(io_dot_krak_scp_toPrint) ; + io_dot_krak_scp_println() ; +} +void io_dot_krak_scp_println_double(double io_dot_krak_scp_toPrint) +{ + io_dot_krak_scp_print_double(io_dot_krak_scp_toPrint) ; + io_dot_krak_scp_println() ; +} +void mem_dot_krak_scp_delete_lessthan_char_greaterthan__char_P__(char* mem_dot_krak_scp_toDelete) +{ + mem_dot_krak_scp_free_lessthan_char_greaterthan__char_P__(mem_dot_krak_scp_toDelete) ; +} +void mem_dot_krak_scp_delete_lessthan_char_greaterthan__char_P___int(char* mem_dot_krak_scp_toDelete, int mem_dot_krak_scp_itemCount) +{ + mem_dot_krak_scp_delete_lessthan_char_greaterthan__char_P__(mem_dot_krak_scp_toDelete) ; +} +void mem_dot_krak_scp_free_lessthan_char_greaterthan__char_P__(char* mem_dot_krak_scp_memPtr) +{ + { + char* memPtr = mem_dot_krak_scp_memPtr; + + free(memPtr); + ; + }; +} +char* mem_dot_krak_scp_malloc_lessthan_char_greaterthan__int(int mem_dot_krak_scp_size) +{ + char* mem_dot_krak_scp_memPtr;; + { + int size = mem_dot_krak_scp_size; +char* memPtr = mem_dot_krak_scp_memPtr; + + memPtr = malloc(size); + mem_dot_krak_scp_memPtr = memPtr; +; + }; + return mem_dot_krak_scp_memPtr; +} +char* mem_dot_krak_scp_mem_scopeop_new_lessthan_char_greaterthan__int(int mem_dot_krak_scp_count) +{ + return mem_dot_krak_scp_malloc_lessthan_char_greaterthan__int(((mem_dot_krak_scp_sizeof_lessthan_char_greaterthan_() )*(mem_dot_krak_scp_count))) ; +} +char* mem_dot_krak_scp_new_lessthan_char_greaterthan__int(int mem_dot_krak_scp_count) +{ + return mem_dot_krak_scp_malloc_lessthan_char_greaterthan__int(((mem_dot_krak_scp_sizeof_lessthan_char_greaterthan_() )*(mem_dot_krak_scp_count))) ; +} +int mem_dot_krak_scp_sizeof_lessthan_char_greaterthan_() +{ + char mem_dot_krak_scp_testObj;; + int mem_dot_krak_scp_result;; + { + char testObj = mem_dot_krak_scp_testObj; + + int result = sizeof(testObj); + mem_dot_krak_scp_result = result; +; + }; + return mem_dot_krak_scp_result; +}/* Method Definitions for string */ + +string_dot_krak_scp_string* string_dot_krak_scp_string__construct(string_dot_krak_scp_string* this) +{ + vector_dot_krak_scp_vector_lessthan_char_greaterthan___construct(&this->string_dot_krak_scp_data) ; + return this; +} + +string_dot_krak_scp_string* string_dot_krak_scp_string__construct_char_P__(string_dot_krak_scp_string* this, char* string_dot_krak_scp_str) +{ + vector_dot_krak_scp_vector_lessthan_char_greaterthan___construct(&this->string_dot_krak_scp_data) ; + while (*(string_dot_krak_scp_str)) + { + vector_dot_krak_scp_vector_lessthan_char_greaterthan___addEnd_char(&this->string_dot_krak_scp_data,*(string_dot_krak_scp_str)) ; + string_dot_krak_scp_str = ((string_dot_krak_scp_str)+(1)); + }; +; + return this; +} + +char* string_dot_krak_scp_string__toCharArray(string_dot_krak_scp_string* this) +{ + char* string_dot_krak_scp_out = mem_dot_krak_scp_mem_scopeop_new_lessthan_char_greaterthan__int(((this->string_dot_krak_scp_data).vector_dot_krak_scp_size)) ;; + for ( int string_dot_krak_scp_i = 0;((string_dot_krak_scp_i)<(((this->string_dot_krak_scp_data).vector_dot_krak_scp_size))); string_dot_krak_scp_i++) + (string_dot_krak_scp_out)[string_dot_krak_scp_i] = vector_dot_krak_scp_vector_lessthan_char_greaterthan___get_int(&this->string_dot_krak_scp_data,string_dot_krak_scp_i) ; +; + return string_dot_krak_scp_out; +} +/* Done with string */ + +int util_dot_krak_scp_lesser_lessthan_int_greaterthan__int_int(int util_dot_krak_scp_a, int util_dot_krak_scp_b) +{ + if (((util_dot_krak_scp_a)>(util_dot_krak_scp_b))) + { return util_dot_krak_scp_b; + }; + return util_dot_krak_scp_a; +}/* Method Definitions for vector */ + +vector_dot_krak_scp_vector_lessthan_char_greaterthan_* vector_dot_krak_scp_vector_lessthan_char_greaterthan___construct(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this) +{ + this->vector_dot_krak_scp_size = 0; + this->vector_dot_krak_scp_available = 8; + this->vector_dot_krak_scp_data = mem_dot_krak_scp_new_lessthan_char_greaterthan__int(8) ; + return this; +} + +void vector_dot_krak_scp_vector_lessthan_char_greaterthan___destruct(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this) +{ + mem_dot_krak_scp_delete_lessthan_char_greaterthan__char_P__(this->vector_dot_krak_scp_data) ; +} + +bool vector_dot_krak_scp_vector_lessthan_char_greaterthan___resize_int(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, int vector_dot_krak_scp_newSize) +{ + char* vector_dot_krak_scp_newData = mem_dot_krak_scp_new_lessthan_char_greaterthan__int(vector_dot_krak_scp_newSize) ;; + if (!(vector_dot_krak_scp_newData)) + { return false; + }; + for ( int vector_dot_krak_scp_i = 0;((vector_dot_krak_scp_i)<(util_dot_krak_scp_lesser_lessthan_int_greaterthan__int_int(this->vector_dot_krak_scp_size, vector_dot_krak_scp_newSize) )); vector_dot_krak_scp_i++) + (vector_dot_krak_scp_newData)[vector_dot_krak_scp_i] = (this->vector_dot_krak_scp_data)[vector_dot_krak_scp_i]; +; + mem_dot_krak_scp_delete_lessthan_char_greaterthan__char_P___int(this->vector_dot_krak_scp_data, 0) ; + this->vector_dot_krak_scp_data = vector_dot_krak_scp_newData; + this->vector_dot_krak_scp_available = vector_dot_krak_scp_newSize; + return true; +} + +char vector_dot_krak_scp_vector_lessthan_char_greaterthan___at_int(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, int vector_dot_krak_scp_index) +{ + return vector_dot_krak_scp_vector_lessthan_char_greaterthan___get_int(this,vector_dot_krak_scp_index) ; +} + +char vector_dot_krak_scp_vector_lessthan_char_greaterthan___get_int(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, int vector_dot_krak_scp_index) +{ + if (((((vector_dot_krak_scp_index)<(0)))||(((vector_dot_krak_scp_index)>=(this->vector_dot_krak_scp_size))))) + { + io_dot_krak_scp_println_char_P__("Vector access out of bounds! Retuning 0th element as sanest option") ; + io_dot_krak_scp_print_char_P__("Vector tried to access element: ") ; + io_dot_krak_scp_println_int(vector_dot_krak_scp_index) ; + io_dot_krak_scp_print_char_P__("Max Index of vector: ") ; + io_dot_krak_scp_println_int(((this->vector_dot_krak_scp_size)-(1))) ; + return (this->vector_dot_krak_scp_data)[0]; + }; + return (this->vector_dot_krak_scp_data)[vector_dot_krak_scp_index]; +} + +char* vector_dot_krak_scp_vector_lessthan_char_greaterthan___getBackingMemory(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this) +{ + return this->vector_dot_krak_scp_data; +} + +void vector_dot_krak_scp_vector_lessthan_char_greaterthan___set_int_char(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, int vector_dot_krak_scp_index, char vector_dot_krak_scp_dataIn) +{ + if (((((vector_dot_krak_scp_index)<(0)))||(((vector_dot_krak_scp_index)>=(this->vector_dot_krak_scp_size))))) + { return; + }; + (this->vector_dot_krak_scp_data)[vector_dot_krak_scp_index] = vector_dot_krak_scp_dataIn; +} + +void vector_dot_krak_scp_vector_lessthan_char_greaterthan___addEnd_char(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, char vector_dot_krak_scp_dataIn) +{ + this->vector_dot_krak_scp_size++; + if (((this->vector_dot_krak_scp_size)>=(this->vector_dot_krak_scp_available))) + { vector_dot_krak_scp_vector_lessthan_char_greaterthan___resize_int(this,((this->vector_dot_krak_scp_size)*(2))) ; + }; + (this->vector_dot_krak_scp_data)[((this->vector_dot_krak_scp_size)-(1))] = vector_dot_krak_scp_dataIn; +} +/* Done with vector */ diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit.h b/tests/test_topLevelVarInit/test_topLevelVarInit.h new file mode 100644 index 0000000..c95cb90 --- /dev/null +++ b/tests/test_topLevelVarInit/test_topLevelVarInit.h @@ -0,0 +1,129 @@ +#include +#include +#include +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/*unknown declaration named translation_unit*/ +/** + * Plain Typedefs + */ + +/*typedef string */ +typedef struct __struct_dummy_string_dot_krak_scp_string__ string_dot_krak_scp_string; +/*typedef vector */ +/* non instantiated template vector *//*typedef vector */ +typedef struct __struct_dummy_vector_dot_krak_scp_vector_lessthan_char_greaterthan___ vector_dot_krak_scp_vector_lessthan_char_greaterthan_; +/** + * Import Includes + */ + +/** + * Top Level C Passthrough + */ + + + #include + + #include +/** + * Extern Variable Declarations + */ + +extern int a; /*extern identifier*/ +/** + * Class Structs + */ + +struct __struct_dummy_vector_dot_krak_scp_vector_lessthan_char_greaterthan___ { + char* vector_dot_krak_scp_data; + int vector_dot_krak_scp_size; + int vector_dot_krak_scp_available; +}; +struct __struct_dummy_string_dot_krak_scp_string__ { + vector_dot_krak_scp_vector_lessthan_char_greaterthan_ string_dot_krak_scp_data; +}; +/** + * Function Prototypes + */ + + +int main(); /*func*/ + +void io_dot_krak_scp_print_char_P__(char* io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_print_string_dot_krak_scp_string(string_dot_krak_scp_string io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_print_int(int io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_print_float(float io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_print_double(double io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_println(); /*func*/ + +void io_dot_krak_scp_println_char_P__(char* io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_println_string_dot_krak_scp_string(string_dot_krak_scp_string io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_println_int(int io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_println_float(float io_dot_krak_scp_toPrint); /*func*/ + +void io_dot_krak_scp_println_double(double io_dot_krak_scp_toPrint); /*func*/ +/* template function delete NoValue */ +/* template function delete NoValue */ +/* template function delete NoValue */ +/* template function delete NoValue */ + +void mem_dot_krak_scp_delete_lessthan_char_greaterthan__char_P__(char* mem_dot_krak_scp_toDelete); /*func*/ + +void mem_dot_krak_scp_delete_lessthan_char_greaterthan__char_P___int(char* mem_dot_krak_scp_toDelete, int mem_dot_krak_scp_itemCount); /*func*/ +/* template function free NoValue */ + +void mem_dot_krak_scp_free_lessthan_char_greaterthan__char_P__(char* mem_dot_krak_scp_memPtr); /*func*/ +/* template function malloc NoValue */ + +char* mem_dot_krak_scp_malloc_lessthan_char_greaterthan__int(int mem_dot_krak_scp_size); /*func*/ + +char* mem_dot_krak_scp_mem_scopeop_new_lessthan_char_greaterthan__int(int mem_dot_krak_scp_count); /*func*/ +/* template function new NoValue */ +/* template function new NoValue */ + +char* mem_dot_krak_scp_new_lessthan_char_greaterthan__int(int mem_dot_krak_scp_count); /*func*/ +/* template function sizeof NoValue */ + +int mem_dot_krak_scp_sizeof_lessthan_char_greaterthan_(); /*func*/ +/* Method Prototypes for string */ + +string_dot_krak_scp_string* string_dot_krak_scp_string__construct(string_dot_krak_scp_string* this); + +string_dot_krak_scp_string* string_dot_krak_scp_string__construct_char_P__(string_dot_krak_scp_string* this, char* string_dot_krak_scp_str); + +char* string_dot_krak_scp_string__toCharArray(string_dot_krak_scp_string* this); +/* Done with string */ +/* template function greater NoValue */ +/* template function lesser NoValue */ + +int util_dot_krak_scp_lesser_lessthan_int_greaterthan__int_int(int util_dot_krak_scp_a, int util_dot_krak_scp_b); /*func*/ +/* Method Prototypes for vector */ + +vector_dot_krak_scp_vector_lessthan_char_greaterthan_* vector_dot_krak_scp_vector_lessthan_char_greaterthan___construct(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this); + +void vector_dot_krak_scp_vector_lessthan_char_greaterthan___destruct(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this); + +bool vector_dot_krak_scp_vector_lessthan_char_greaterthan___resize_int(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, int vector_dot_krak_scp_newSize); + +char vector_dot_krak_scp_vector_lessthan_char_greaterthan___at_int(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, int vector_dot_krak_scp_index); + +char vector_dot_krak_scp_vector_lessthan_char_greaterthan___get_int(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, int vector_dot_krak_scp_index); + +char* vector_dot_krak_scp_vector_lessthan_char_greaterthan___getBackingMemory(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this); + +void vector_dot_krak_scp_vector_lessthan_char_greaterthan___set_int_char(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, int vector_dot_krak_scp_index, char vector_dot_krak_scp_dataIn); + +void vector_dot_krak_scp_vector_lessthan_char_greaterthan___addEnd_char(vector_dot_krak_scp_vector_lessthan_char_greaterthan_* this, char vector_dot_krak_scp_dataIn); +/* Done with vector */ diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit.results b/tests/test_topLevelVarInit/test_topLevelVarInit.results new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/test_topLevelVarInit/test_topLevelVarInit.results @@ -0,0 +1 @@ +0 diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit.sh b/tests/test_topLevelVarInit/test_topLevelVarInit.sh new file mode 100755 index 0000000..30705f8 --- /dev/null +++ b/tests/test_topLevelVarInit/test_topLevelVarInit.sh @@ -0,0 +1,2 @@ +#!/bin/sh +cc -std=c99 ./test_topLevelVarInit.c -o ./test_topLevelVarInit \ No newline at end of file