267 points · by kick · 6y ago · 84 comments
further back, I wrote a compiler for part of the language described in Dijkstra's A Discipline of Programming in a dialect of forth[1].
one of my colleagues, Stevan Apter, has a number of interesting toy interpreters on his site[2], particularly concatenative languages.
[0] https://github.com/JohnEarnest/ok/blob/gh-pages/oK.js
[1] https://github.com/JohnEarnest/Mako/blob/master/demos/FiDo.f...
[2] http://nsl.com
I wish exist more information on the array family (and with less "condensed" syntax :)).
I'm building a relational language and have tried to borrow some ideas, but apart from the very basics is not much info out (and most are about numerics). For example, how about crud operations.? Lazy evaluation?
What would you do?
Mini-C is even more amazing if you look at its description:
I set myself a challenge: write a self-hosting C compiler in 10 hours.
Although the language it accepts, being untyped, is closer to B.
Also nice to see my personal favourite, C4, in the list.
Recently did this myself (https://github.com/mras0/scc/blob/master/scc.c) but it took waaaaay more than 10 hours and I had many previous failed attempts before that.
How?! That is straight up sorcery.
Very good video.
OpenFirmware is based on forth, and was used instead of BIOS for Sun workstations, some Powermacs, and the OLPC, among other devices. On the OLPC it offers a nice debugging interface and educational opportunity.[0]
The Wikireader "wikipedia appliance" used forth for their testing harness during manufacturing, and it's possible to write your own applications for the device using it.[1]
Forth has been used for control software for a variety of aerospace applications.[2]
I have personally used Forth as an interactive testing environment for bringing up new hardware. In one case, I prototyped software for the power management chip in an embedded linux device.
I've also written games and programming environments in Forth, both for fun and for use in educational after-school programs I helped organize. For example, a logo environment[3,4] and a rewrite of Yar's Revenge[5,6].
Is any of this software "real"?
[0] http://wiki.laptop.org/go/Open_Firmware
[1] https://github.com/JohnEarnest/Wikireader-Adventures
[2] https://www.forth.com/resources/space-applications/
[3] http://johnearnest.github.io/Mako.js/?rom=Loko
[4] https://github.com/JohnEarnest/Mako/tree/master/demos/Loko
[5] http://johnearnest.github.io/Mako.js/?rom=Yar
[6] https://github.com/JohnEarnest/Mako/blob/master/games/Yar/Ya...
Created by Jef Raskin, creator of the Macintosh, only perhaps the most influential UI designer in the entire world.
Whether it's used or not wasn't really my point but it's hard to deny that such a simple syntax so close to the metal is quite amazing and elegant :)
[0] https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/index...
[1] https://g.solidity.cc/submissions/wicketh.eth/9a5cb12b504b81...
Now you can duck out of implementing solid semantics, without changing what a language looks like. For instance, programs language with broken scope can look superficially like programs in a language with working lexical scope. Or, a language that works by interpreting a syntax tree using a few lines of code looks and works just as well as a compiled one, just slower.
But if you don't negotiate about what a language looks like, there is only so much simplification you can do while still correctly handling the syntax which allows the language to look like that.
Further reductions in complexity require simplifications in syntax (how the language looks), which leads toward one of several existing well-understood design families for minimal syntax: Lisp-like, Forth-like, APL-like.
Nowadays I usually bite the bullet and just use JSON or something, but if you want to implement an interpreter starting just from bare minimum string functions pretending you're in 1980 and can't just grab half-a-dozen serialization formats out of your language's package manager (not a bad thing to practice!), Lisp-non-syntax is still a pretty good choice.
I guess if you couldn't write a C compiler in a single small file (by modern standards) you wouldn't have been able to run a C compiler on an 8-bit machine.
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/...
The language was quite a bit smaller, though, and much less complex. A C2X compiler will be drastically more tedious to make than this was.
Many years ago I worked on a C++ compiler, and this was during the C++03 days. The language and standard (now C++20) is // so much larger // than it was even 15-20 years ago.
I will say, however, that when I'm brave enough to peek into the clang code (I work up the courage maybe a couple times a year), at least for someone who understands the language, it's very clean. But it's big. Very big.
(Brainfuck was a direct response to it, trying to make a compiler that was significantly smaller - the original compiler was 240 bytes.)