Implementing Tuples Inside the Compiler of the Pyret Programming Language
Sarah Fischmann, Joe Politz
Pyret (http://code.pyret.org) is a programming language designed for programming education. Before summer 2016, Pyret did not have tuples as an existing feature in the language, so I have been directly editing the source code of Pyret to make this available. Pyret's compiler, implemented in mostly Pyret and some JavaScript, converts code written in Pyret to code written in JavaScript, which can then be run directly in a browser. Therefore, the goal of my work this summer was to write code in both Pyret and JavaScript in order to build a representation of tuples.
There were many steps necessary in order for this new feature to be available. I first had to change the grammar of Pyret so Pyret's parser would recognize the syntax of tuples. I then had to push tuples through the many other steps that the compiler takes--well-formedness checking, conversion to A-Normal Form, type-checking, etc.--before choosing the final representation of tuples in JavaScript. This same process then also had to be carried out for indexing and allowing for deconstruction and annotations. I also checked for when tuples were used incorrectly (for example, index out of bounds, an annotation was not satisfied, etc.). Along the way, I wrote many tests to ensure that my work was implemented properly and could not be broken by a programmer--whether that programmer be me or someone else coding in Pyret. I also wrote several performance tests to compare the speed of tuples to other already existing features. In doing this, my mentor and I learned that Pyret was spending a lot of time with its stack management during recursive iterations; consequently, we came up with a way to change the way stack management is done, which greatly increased the speed of the compiler. This is an example of the many ways in which we attempted to approach this new feature; since our work was essentially a vertical slice of Pyret's compiler, we ultimately thought not just about tuples themselves, but also about the ways in which the other parts of Pyret's compiler affects tuples.