news
Programming Leftovers
-
Abhinav Sarkar ☛ A Short Survey of Compiler Targets
As an amateur compiler developer, one of the decisions I struggle with is choosing the right compiler target. Unlike the 80’s when people had to target various machine architectures directly, now there are many mature options available. This is a short and very incomplete survey of some of the popular and interesting options.
-
[Old] Stanford University ☛ My tutorial and take on C++20 coroutines
Over the last 25 years, I’ve written a lot of event-driven code in C++. A typical example of event-driven code is registering a callback that gets invoked every time a socket has data to be read. Once you have read an entire message, possibly after many invocations, you parse the message and invoke another callback from a higher layer of abstraction, and so forth. This kind of code is painful to write because you have to break your code up into a bunch of different functions that, because they are different functions, don’t share local variables.
-
[Old] Serge Zaitsev ☛ Tiny Great Languages: Assembly
I once read a discussion on Hacker News where someone suggested that every programmer, over their lifetime, should implement six programming languages: an assembler, a version of BASIC, a flavour of Lisp, a Forth, and a subset of C. The specific languages aren’t as important as the families they represent. These are the Great Languages – each with a rich history that has fundamentally shaped modern programming in one way or another.
In this post I hope to re-implement these languages once more, keeping each implementation to around 50 lines of code. My goal is to highlight the unique characteristics of each language family while keeping the approach simple.
I’ll be using Python for these implementations, for a good balance between code density and readability. The only test program our interpreters would need to run is a factorial calculator, something we’ve all written many times (and something that can be implemented in different ways).
-
[Old] Serge Zaitsev ☛ Tiny Great Languages: BASIC
Meet BASIC, the king of home computing in the late 1970s. Originally designed to promote computer literacy in schools, BASIC inspired a whole generation of professional software engineers.
BASIC typically combined a simple text editor with a command shell and interpreter. Lines starting with a number were added, deleted, or edited in the program space, while lines without numbers were executed immediately. For example: [...]
-
[Old] Serge Zaitsev ☛ Tiny Great Languages: MOUSE
I’ve already covered building a proper Forth from the ground up in an earlier post. Now, let’s explore a much smaller Forth-like language: MOUSE.
MOUSE, created in 1976, is often recommended as a good starting point for writing your first interpreter. It uses reverse Polish notation with single-letter operators and variables for its syntax. Like most languages from the 70s, MOUSE is compact, small enough to fit into just a few kilobytes of memory. But could the implementation be shorter than 50 lines of code?
-
[Old] Serge Zaitsev ☛ Tiny Great Languages: Lisp
Interestingly, the original Lisp syntax wasn’t the parentheses-heavy version we know today. It started with M-expressions: car[cons[A,B]], which looks more like how modern languages call functions. However, S-expressions – a simpler and more uniform syntax – quickly took over. That’s the Lisp syntax we use today, with all those parentheses.
S-expressions fit beautifully with Lisp’s core idea that “code is data”. In Lisp, everything follows the same structure and can be processed in the same way. This flexibility is why macros in Lisp can manipulate code just like any other data.
To build a Lisp, all you need is a parser for S-expressions and an eval() function to evaluate the resulting syntax tree (or list of lists).
-
[Old] Serge Zaitsev ☛ Tiny Great Languages: APL
This would be a controversial language, but it fits perfectly into the 50-lines-of-less code category. Let’s talk about APL family, and specifically – K.
Created by Arthur Whitney the language is known for its terse and cryptic syntax. But it fixes one “issue” with APL – K uses ASCII symbols. It may sound unsurprising, since most programming languages do that, but APL required a special keyboard since most of the language operators were mathematical symbols and Greek letters, such as Pascal←{0~¨⍨a⌽⊃⌽∊¨0,¨¨a∘!¨a←⌽⍳⍵}, which is a program in APL to render Pascal triangle.
-
[Old] Serge Zaitsev ☛ Tiny Great Languages: PL/0
Back in 1976 (around the same time most of the languages in this series were born), Wirth wrote a book titled Algorithms + Data Structures = Programs. This was one of the most influential books in computer science, inspiring Anders Hejlsberg to create the famous Turbo Pascal compiler. At the end of the book, there were chapters on language structures and compilers, explaining how to build a compiler with code generation for a small subset of Pascal known as PL/0.
-
R / R-Script
-
Rlang ☛ Inaccessibility
Well, let us be rebellious and instead seek inaccessibility; more precisely the pole of inaccessibility of France (the Hexagon): the farthest location from the boundary. Not to be confused with the centroid.
-
-
Java/Golang
-
University of Toronto ☛ Go's runtime may someday start explicitly freeing some internal memory
The proposal that led to this doesn't seem to currently be visible in a mainline commit in the Go proposal repository, but until it surfaces you can access Directly freeing user memory to reduce GC work from the (proposed?) change, and also Go issue 74299: runtime, cmd/compile: add runtime.free, runtime.freetracked and GOEXPERIMENT=runtimefree and the commit itself, which only adds the Go experiment flag. A preview of performance results (from a link in issue 74299) is in the message of slices: free intermediate memory in Collect via runtime.freeSlice.
-