
Bootstrapping a simple compiler from nothing (2001) - emersonrsantos
http://homepage.ntlworld.com/edmund.grimley-evans/bcompiler.html
======
neotek
This reminds me of an interesting question posed on reddit in /r/programming a
few years ago: if you were stuck in a room with a blank PC with only a floppy
drive and disk, what's the bare minimum that would need to be on the disk for
you to eventually write a full-fledged operating system[1]? The whole thread
is a fascinating read, and features a cameo from lutusp.

[1]
[http://www.reddit.com/r/programming/comments/9x15g/programmi...](http://www.reddit.com/r/programming/comments/9x15g/programming_thought_experiment_stuck_in_a_room/)

~~~
agumonkey
I bookmarked this[1] a dozen times. I wanna try that ASAP. The whole monitor >
forth > lisp is a nerd dream

[1] especially kragensitaker's comment
[http://www.reddit.com/r/programming/comments/9x15g/programmi...](http://www.reddit.com/r/programming/comments/9x15g/programming_thought_experiment_stuck_in_a_room/c0ewj2c)

~~~
kragen
I'm glad you enjoyed it! I'm interested to see what you come up with :)

~~~
jacquesm
Epic. Scary to recall how many of your 'steps' I've actually been through irl
and I wasn't even in a prison cell...

~~~
kragen
If I'm not mistaken, you've bootstrapped a substantial fraction of an
industrial economy. Now _that_ is epic. To me, a software development
environment is small potatoes compared to your windmill.

Here's a question I've often thought about that you might have insight on:
what would be the shortest path from raw materials and an unlimited amount of
information to, say, a reasonable bicycle?

For example: bronze, despite its scarcity, is easier to make from raw
materials than steel, but I don't know if it's hard enough for ball bearing
races, and I think you need ball bearings for a ridable bicycle. You can
probably make a tiny blast furnace with leather bellows and ceramic (or can
you?), but then you need to form the bearing balls and the races. Would you
cut grindstones from stone? Perhaps electrolyze seawater to get magnesium
oxychloride to bind together quartz sand?

~~~
jacquesm
The hard part I think would be the mining. Most if not all of the easily
accessible resources have been depleted, so bronze age people had an easier
time of it than we do!

Making a bicycle out of bronze would be an interesting exercise. I'd not use
ball bearings, but rather babbit bearings and instead of a chain drive I'd use
a belt drive (made from cloth).

Bamboo rather than steel or bronze for the frame to keep the amount of metal
to a minimum, spokes would be tricky, wheels could be made out of wood.

Inner tubes made out of intestine, outer tubes made out of cloth, bulky but
workable.

Something like that?

Now that you have me thinking about this I realize that I'm actually sorely
tempted to try this.

Another hard part would be to not (unwittingly) cheat and to work off existing
tools and/or raw materials that aren't truly raw.

edit: more thinking about this, the high stress points in the bike would be
the spot where the pedals attach (even on my regular bike I can see it flex
there), the joint where the tube from the handlebars goes through to the fork,
the fork itself and the saddle joint.

Those would probably have to be cast out of bronze and then filed (with
what?!) to their precise dimensions, or, alternatively you could first
bootstrap a primitive lathe (which would require at least one piece of
hardened steel for the bit).

Primitive blast furnaces are fairly easily constructed out of clay, I've seen
some in NL that were absolutely doable, depending on what ores you can get
your hands at in the end steel might even be easier than bronze.

~~~
kragen
The belt drive, intestine inner tubes, and bamboo frame are excellent ideas.

That's a good point about the bronze. I think there's still a basically
unlimited amount of small deposits of rich iron ore out there (e.g. magnetite
sands) and, of course, aluminum, but that's a lot harder to smelt.

I had the impression that Babbitt bearings were too inefficient to make
bicycles practical, which is why the bicycle boom didn't happen until the
invention of the ball bearing. But I could be mistaken about that. Certainly
you could do Babbitt bearings without particularly great metallurgy. (But you
need a wider variety of metals.)

I know some people here with bamboo bikes, except for the joints, of course.

Spokes could possibly be made of glass or bamboo, but I'm not sure how you'd
pull them tight without being able to thread them. Maybe you could lace the
wheel like a circular shoe instead.

I don't think cloth tires will wear for long enough to be useful. You'll
probably need at least buna reinforced with carbon black or fumed silica.

As for the working off existing tools: maybe you could make it an iterative
process, starting with Dave Gingery tools and materials and working your way
down with successive bikes?

Do you think you could do a lathe with a non-metal bit? Corundum, carborundum,
diamond, or maybe topaz? I've never turned anything on a lathe, so this might
be a stupid question.

I think you can grind some things to precise dimensions rather than filing
them, and that might require less materials technology. Knife sharpeners use a
particular kind of flint for some of their work.

I definitely, definitely want to know if you end up doing some of this!

~~~
jacquesm
Modern lathe bits are ceramic or sintered metal, so it should be possible to
use other materials.

Grinding / sanding are good ways to get near perfect shapes (it is typically
the last pass after the lathe has done its work if you want extreme
precision). Ball bearings are made using an interesting process (using a
vibrating drum with abrasive, the resulting minimal surface elements are
perfectly spherical by definition...).

Babbit bearings have a higher friction coefficient, but we're talking about
making a working bicycle, not the most efficient one, after that it is
incremental improvements and of course, ball bearings are better but they may
not be the shortest path to success.

You've really done a bad thing here, I can't get this out of my head... :)

------
PythonicAlpha
When you program with today's tools and all that we have, you forget very
fast, how it was in the beginning and how difficult it is to start from
scratch.

Today you always have some sort of compiler or cross compiler. Starting
totally with nil (not even an assembler) is really not so simple.

This little article shows nicely, how bootstrapping can work. Pulling myself
out of the mud on my own hair (like the Baron Muenchhausen from literature).

But don't forget: He still had the operating system not bootstrapped ... so
repeating the whole computer history would need some more bootstrapping to do
....

~~~
msvan
And even if he were to write the operating system from scratch, he would still
have "cheated" by not designing the hardware. I wonder how long it would take
in man-years to recreate the entire chain all the way up to a simple C-like
compiler. Still, fascinating work, and most of all a fascinating perspective.
I for one haven't the slightest clue about how to program by directly
inputting hexadecimal machine code.

~~~
marvin
Shouldn't take more than a couple of man-years if you got the right people
together. A C compiler is still pretty low down on the toolchain, and there is
a whole library of literature explaining how the technology below this level
works.

I think the big restriction is how much existing technology you'd be allowed
to use, and how functional/scalable the technology would have to be when
you're done. I/O is a big hurdle. Do you have to design the graphics hardware
yourself? Do you have access to modern photolitography? Are you required to
create the monitor/keyboard yourself? Other input devices, like disk drives?
Do you need presistent storage at all? Display? Etc.

~~~
userbinator
Here's someone who started with the hardware, although he only ported existing
software to it:

[http://www.homebrewcpu.com/](http://www.homebrewcpu.com/)

------
fiorix
In 2002 Fabrice Bellard (author of ffmpeg, kvm, etc) won The International
Obfuscated C Code Contest with a tiny obfuscated C compiler, which later
became tcc, the tiny c compiler:
[http://bellard.org/otcc/](http://bellard.org/otcc/)

------
userbinator
Going even "deeper", you could try starting with ROM BASIC on a PC and
building the beginnings of an OS from there (
[http://en.wikipedia.org/wiki/IBM_BASIC](http://en.wikipedia.org/wiki/IBM_BASIC)
).

I have written a simple assembler (that supported labels) using the DOS DEBUG
utility, but never had enough time to go through the levels of abstraction
beyond that. If I did, my next steps would've been a text editor, followed by
a simple C-like compiler.

Another interesting "bootstrapping" problem I've heard of is this: Suppose you
rm-rf'd a *nix system, and all that was left was the kernel and shell process
running in memory. How much of the system could you "rebuild" with only that?

------
mamcx
This was great.

Exist sometime like this but more high level? For example, I wonder how start
with python, lua or obj-c, create my own syntax and continue the development
with them after a while.

I think nimrod & julia (and certainly freepascal) do this but wonder how they
do that.

~~~
maaaats
You could read the dragon book for a detailed introduction to compilers, but
at a higher level since it's not about bootstrapping but using tools to do
some of the tedious work.

~~~
mamcx
Yeah I could do that (In fact I'm building resources around this) but I'm
thinking more about a simple sample like this, than a full of things before
get to the point. Like this post and
[http://journal.stuffwithstuff.com/2013/12/08/babys-first-
gar...](http://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-
collector/) that put things in a easy to get format.

------
dasmithii
Interesting. This is a great example of the power in abstraction. By
continually building upon available tools, we're able to develop new, higher
level toolkits that can be used to further the process.

Ironically, this project steps back, abandoning modern utilities in favor of a
more educational/interesting process (which is good, sometimes). I too enjoy
passion-projects such as this.

