Write your own retro compiler
t3x.org
t3x.org
How much complexity do you need to self-compile a compiler in 10 minutes on a 4MHz Z80 system? Take a look and find out! The code is free (but the book is not).
Edit: I'd also love to see you do a no-nonsense book on Forth and your take on it.
Books are my biggest source of income, but "big" is relative here: I am earning about $500 per month in revenues. This is mostly a problem visibility, I think. Most people stumble across my books by accident. Reviews, presence on the front page of HN, etc. usually increase revenues significantly for one month.
Regarding FORTH, lets see. The code is already there: http://t3x.org/t3xforth/
Long story short, I'd love to see you advertise some more. I'm not sure how you'd reach your typical audience though.
Let's see. I have had a look at Mastodon and all I see at the moment is a wall of random distractions. Maybe I am missing something, though. I will investigate further. On HN, for example, there are just headlines and it takes me maybe a minute to scan the front page. Mastodon looks pretty chaotic and time-consuming compared to that.
Regarding advertising...idk, but there should be some kind of option for you out there. HN is of course a good place for this kind of thing. Is that lambda the ultimate blog still a thing? Not sure how many people listen to the arraycast podcast, or if you're comfortable with that format...but I'm sure they'd be interested in your work on Klong and the implementation choices.
The only software you need to get started is a web browser to use a web client, which is typically the Mastodon server you create an account on. Picking a server is the only potentially confusing choice, so for retrocomputing enthusiasts I recommend creating an account at https://bitbang.social or https://oldbytes.space Once you have an account on a server you can migrate to another one if needed.
For more on Mastodon see https://joinmastodon.org For any other questions feel free to ask here or follow me on Mastodon at @amoroso@fosstodon.org and ask there.
So when adding an account, I would just add to that wall of postings? How would people interact on such a platform? I am coming from Usenet, which had the greatest user interface ever (IMHO): you just follow-up on a posting and replies will pop up in your stream of unread messages. How would this work on Mastodon?
You set up your "wall of postings" (the "feed" or "timeline" in the jargon of socials) by following (subscribing to) the people you're interested in. On Mastodon you can also follow topics by following "hashtags", which are the sets of posts by any user tagged with a string preceeded by a hash character. For example, following the hashtag #retrocomputing will bring in your timeline the posts about that topic.
So, on socials, you typically scan your feed and the feeds of any additional hashtags you're interested in. For each post you can reshare it, reply (comment), or like it.
Some additional resources: 1) https://opensource.com/article/23/1/mastodon-beginners-guide 2) https://github.com/joyeusenoelle/GuideToMastodon
The one in the book is for the Z80, which is a bit older and does not even have multiply or divide instructions. The compiler can also output code for the 8086, though. And the 386.
EDIT: should have taken a look on the rest of your website first. Clearly you do, hahaha
If you already have some base knowledge, you might like this:
https://www.cs.cmu.edu/~janh/courses/411/18/schedule.html
I particularly liked how they introduced SSA form.
More advanced topics:
FYI: replacing the 18 with 23 in your link to 411 gets you a slightly updated version.
Tis one of those things, I guess.
Not just that, but the theory that drives modern compilers, like graph coloring register allocation and static single assignment form, weren't conceived until the mid 1980s (1984 and 1986 each), and better implementations of those theories were written about in the 90s. Linear scan register allocation was first written about in 1999.
You can compare these books:
Engineering a compiler: VAX-11 code generation and optimization, which was published in 1982, talks about the design and implementation of the PL/I compiler for the DEC VAX-11.
You can compare it to Bob Morgan's Building an Optimizing Compiler, which was published in 1997. The techniques he discusses there are a lot closer to how LLVM works today than the 1982 book.
Static Program Analysis[1] also seems helpful to someone trying to write a compiler that does optimizations that require advanced analyses: https://cs.au.dk/~amoeller/spa/
For garbage collection, there's the Garbage Collection handbook[2]. I'm not aware of better additional resources, though.
This is a good point, and I have thought about it a lot before starting the book. What finally made my choose T3X is that its compiler is much smaller[1] than my smallest C-subset compiler and (IMHO) T3X is easier to learn or understand.
[1] SubC: 3815 lines, T3X/0: 2330 lines.
Of course you could start on CP/M without any outside tools, but then you would have to write your bootstrapping compiler in assembly language. Time-consuming, but certainly manageable. I doubt that it would be an interesting reading, though.
I'm -slightly- surprised it isn't using a C-like syntax rather than ALGOL-like but that's probably my own biases, and mentally mapping 'DO' and 'END' to '{' and '}' isn't much of a hardship.
Though if you'd care to share a link or something, I'm now curious how it -did- come to exist.
I kid, but it is a common stopping point. Gonna pick this up.
Now, yes, that shows you how to write a Unix-like microkernel OS; just skip everything except the file system chapter. And don't follow the advice about tree data structures. Just use flat tables, and don't bother to implement exact file sizes. Presto: CP/M.
(I prefer the 2nd edition. The 3rd edition needlessly complicates IMO, mostly so the demo Minix code will work on a late 1990s PC instead of a 1980s PC.)
I read the free chapter. One thing I noticed right away was that I think some things can be hard for people with not so much knowledge about the topic: under each headline, it explains a concept from the ground up, no knowledge required. Like "the syntax of a language is...". But just a few sentences in, advanced topics are touched, like assembly instructions, not explained. It feels a bit like "the curse of knowledge", where it's hard to know what the other party knows. But if the reader needs to learn what syntax means, they will probably not understand the next sentences.
So, I think more consistency could improve the product.
This is of course just my meaning and interpretation of the text, it might not be relevant. But maybe something to have in mind for your next masterpiece :)
As the blurb of the book states: no prior knowledge in the field of compiler construction is required, but the reader should be familiar with at least one procedural language and one assembly language. So I thought it would be OK to assume that the reader knows about things like assembly instructions.
Then the appendix of the book has a short introduction to Z80 assembly (which still assumes that you know the basics of assembly language).
Every books starts somewhere. It would be hard to write a compiler construction book and assuming zero knowledge about computer programming.
I am not saying that the curse of knowledge is not a thing, though, so I will definitely keep this in mind!
It is all fun until you want to apply global changes to some 1500 static pages. :) So far the pain is not sufficiently intense to make me write a CMS, though. And even then the design would stay the same!
To be clear, I'm not attempting to criticize with this question (my personal opinion is write about what interests you, even if nobody else will care), I'm assuming you choose older targets for a reason, and would like to undestand those reasons :-)
I.e. Do you believe the retro targets to be a lot simpler and easier to understand, so people can iterate/build in layers? Or do you just know the retro stuff better so it makes for a better book?
So for this book I chose a platform that is easy to understand and does not make you wade through tons of abstractions that are only loosely related to compiler construction (e.g. ELF object file format).
"(nearly) constant" means you can pick either (a) a constant blob, at the cost of a fixed image size, à la COM, or (b) patch up length (one or two places, iirc) if you're feeling fancy.
fwiw, I think you commented it very nicely; de gustibus!
Did you come up with if vs. ie ... else ... independently or inherit it from BCPL?
Thanks, I thought so, too, but I can also understand that the comments are not very helpful, if you know nothing about linkers, paging, and object files.
I think I adopted IE/ELSE from BCPL, but thought that IE is nicer than TEST, because it is itself short for If/Else and because it looks almost like IF.
> de gustibus!
Funny, I just started to brush up my Latin! :)
I doubt I'll ever get around to it but I'm sort of tempted to see if I can remember enough arm26 assembler to try and get it to compile to that (arm26 does have multiply but not divide, I'd have to dig out the 'standard' fast division asm block that was passed around amongst Archimedes authors back when that was my primary platform).
Just bought a copy so I should at least get as far as "I've read the book but not got around to the arm26 part" though :D
The entire retro-computing field is interesting and a bit surprising in it's strength. I would not have guessed that in 2023 an IMSAI 8080 would be selling for ~$3-5k, and that there would be such an active community of people doing things in CP/M. Nor would I guess that I would be working on either of these!
One of the most enjoyable personal projects that I have worked on was the creation and implementation of a CPU, starting with the concept ISA and building the microarchitecture, making lots of cool mistakes that require rework, and eventually having a booting CPU running code in an assembly language of my own. While the performance of a CPU like this is closer to the computational power of my coffee maker, it is still an excellent experience.
I ordered my copy of your book and am looking forward to reading it!
Another thing to love about retro computers is how transferrable the knowledge is to modern machines. Once you know the essence of assembly language on a retro computer, you have a good basis for learning RISC-V or something else modern.
Depending on where your son is at, he might enjoy this video where I explain the essence of assembly language-- it's the video I wished someone had shown to me when I was a kid and thought I wasn't smart enough to learn it.
Retro stuff also presents a challenge. There is a guy who writes some crazy software for I believe the Mac-II. It can be a great test of skill to take an old machine have it capable of doing modern things, because it requires getting knee deep in the weeds on optimization and such. One issue I think we have in software is, modern machines are really powerful. To the point of even shitty un-optimized code in average use cases can run decently well. Targeting these kinds of machines can help build those skills in learning how to optimize because, well, you would actually have to optimize to get these older machines to do modern things.