My honors thesis is complete! I spent the last two semesters working on a functional language compiler in a guided independent study course so I could graduate with honors in computer science. This is the last requirement that I needed to complete.
Category Archives: Dr. Stump
Last Honors Requirement
I’m on my way to finishing the second requirement to graduate with honors; last week I started to write my honors thesis. One of the goals I set as a freshman was to graduate with honors. I started my honors project last semester with my first guided independent study in compiler development and, as scheduled, I continued to work on the same project this spring. I’m well on my way to acquiring 6 hours of honors course credit so all I have left to do is finish my Honors thesis.
At first I thought writing my thesis would be an impossible task, especially when I got off to a very slow, unmotivated start. However, after I finished my introduction I found that writing about an enjoyable project is fun. This paper gives me a nostalgic feeling because I get to look back and review all of my progress. It’s even more exciting to know that I’ve contributed to a project that will live on well after I leave the U. of Iowa.
Foreign Function Interface
I updated the Blaise compiler so it has a Foreign Function Interace (FFI). Earlier this month I modified the compiler so arrays could be made in Blaise, the support I added was more like a hack where the compiler looked for predefined function names. I re-factored the compiler so now it supports a FFI where the compiler now looks for external function declarations. Every time a Blaise programmer uses and function that is declared externally the compiler trusts that the programmer is calling a supported external function.
Here is a snippet of blaise code:
# Here are the external declarations, these tell the compiler which # functions will be used from an existing library external Array_make [ typeInfo ] : [ typeInfo ] external Array_get [ typeInfo ] : [ typeInfo ] define mn = var arr = Array_make(5,1); print_int(Array_get(arr, 0))
Blaise Arrays
I added support for arrays inside of Blaise. Instead of modifying the grammar I modified the compiler to look for foreign function interface constructs. Since Blaise compiles to C I have to make sure all Blaise code compiles to compliable C. Supporting arrays in Blaise wasn’t too hard, but there was one obstacle I didn’t expect to run into. Due to little experience with C I found out that creating arrays dynamically in C isn’t as easy as I first thought.
For example, the following createArray function does not work in C:
void* createArray(int length, void* initialValueForEachElement){ void* arr[length]; int i; for(i = 0;i< length; i++){ arr[i] =Â initialValueForEachElement; } }
I did come up with a solution to my problem. Anytime I call the createArray function I know the length of an array specified by the Blaise programmer so I declare the array before the function call and pass it in.
void* createArray(void* arr[], int length, void* initialValueForEachElement){ int i; for(i = 0;i< length; i++){ arr[i] =Â initialValueForEachElement; } } int main(){ int length = 5; void* arr[length]; createArray(arr, length, 3); // arr was successfully created }
After talking to a postdoc I discovered an even better solution so I don’t have to declare the array before the call.
void **Array_make(int size) { void **arr = malloc(size*sizeof(void *)); return arr; }