Live data from Hacker News

Creating a language using only assembly language

speakerdeck.com

1–10 of 67 posts

Re: Creating a language using only assembly language

#5
post #2

This is the coolest thing I've seen posted on HN in awhile. The title might not do it justice; the point is: there's very little assembly language involved, if you're careful.

I smell bootstrap. #onto-reading

ps: I remember an article with a similar structure but using lambda calculus. Starting with very poor subset and gradually expanding features... Too bad I can't find it again.

Re: Creating a language using only assembly language

#6

Very neat. If you find this interesting you may also like jonesforth, another project developing a language starting from assembly. http://git.annexia.org/?p=jonesforth.git;a=summary

I second that; Forth is extremely well suited to bootstrap from asm too.

Re: Creating a language using only assembly language

#7
post #2

This is the coolest thing I've seen posted on HN in awhile. The title might not do it justice; the point is: there's very little assembly language involved, if you're careful.

I smell bootstrap. #onto-reading ps: I remember an article with a similar structure but using lambda calculus. Starting with very poor subset and gradually expanding features... Too bad I can't find it again.

Is it this project? http://matt.might.net/articles/implementing-a-programming-la...

Re: Creating a language using only assembly language

#8
post #7

Earlier quoted context omitted.

I smell bootstrap. #onto-reading ps: I remember an article with a similar structure but using lambda calculus. Starting with very poor subset and gradually expanding features... Too bad I can't find it again.

Is it this project? http://matt.might.net/articles/implementing-a-programming-la...

Nope, I remember numbered evaluators like lc-0 lc-1. Thanks anyway.

Re: Creating a language using only assembly language

#9
Speaking of languages in assembly. Here is a Java virtual machine in assembly language:

https://github.com/k1w1/javelin-stamp/blob/master/asm/javeli...

Until I looked at it again now I had forgotten my favorite instruction, a nop to avoid a bug in the silicon:

https://github.com/k1w1/javelin-stamp/blob/master/asm/javeli...

Re: Creating a language using only assembly language

#10
I love this. My first (toy) compiler was bootstrapped a similar way, though much more ad-hoc (I didn't write a formal grammar until I was well into it). Back then a lot of compilers were written in assembler, so it wasn't such an unusual starting point - I assume I was drawing inspiration from e.g. PDQ (a public domain Pascal implementation for the Amiga) and others that I think I would have seen first.

I started basically by having the compiler do very basic parsing of M68k assembler and just pass everything that looked like assembler straight through.

Then I added support for defining functions, but all the content of functions was still assembler. Then I started adding expression support and things like local variable and types.

I wish I still had the source (lost in a move, long after I stopped doing anything on it) - one of the fun things about it was that I kept the ability to intersperse assembler instructions everywhere - they were treated as normal statements. And the M68k registers were first class variables in the language that could occur in any expression. So e.g. you could write "D0.w = D1.w + a", where D0.w would refer to the low 16 bits of the D0 register, and D1.w the low 16 bits of the D1 register, and "a" would be a variable allocated on the stack.

Basically the features I added were largely guided by what seemed like it'd let me shave more lines off the compiler itself...

You learn a lot about the language you're writing when you bootstrap from asm or try to condence everything into a tiny core - a lot dependencies in the language that are non-obvious becomes a lot clearer.

Post reply on HN