C//

C// (pronounced "C divided-by divided-by") is a simplified version of the C programming language that I made for a class project in university in 2014. The class was about programming language implementation, and the project was an open-ended "do something related to the topic of the class"-type project. The topic I chose was:

Is having pass-by-reference semantics (or Java's pass-a-reference-by-value semantics) for non-primitive data types necessary for performance?

In a lot of programming languages that I know or know about (e.g., Java, JavaScript, Python, Scheme, Objective-C (mostly)), complex data types like objects and arrays are always treated as references, so if, for example, some code passes an array into a function and the function modifies an element of the array, the change is visible to the caller. This has the performance benefit that potentially-large values aren't copied. However, it seems like if a language has pass-by-value, a sufficiently smart compiler or interpreter could optimize the code by using pass-by-reference internally when it can guarantee that it doesn't affect the program's result (e.g., if the function doesn't modify the object), while still behaving as if it had true pass-by-value. My goal was to try to make such a compiler.

For this project, I made the C// language, which is a simplified version of C that only has ints (which stand in for primitive types in general) and structs (which stand in for complex types that might be passed by reference), and a transpiler from C// to C that applies the optimizations I was thinking of. The language was made to have just enough features to demonstrate this optimization, and is not intended to be used as-is for actual programming tasks.

I was recently reminded of this language because I came across an article about mutable value semantics; I think that's the same thing I was trying to do, although it looks like they did it with reference counting (which I did think of at the time), whereas I was interested in whether it could be done with static analysis alone. (It also looks like they went into more depth on various things.)

This is also in general something I've thought and learned more about since I did the project; there are issues with my idea that I have thought of since then and haven't really addressed here.

Contents