Live data from Hacker News

Creating a language using only assembly language

speakerdeck.com

21–30 of 67 posts

Re: Creating a language using only assembly language

#21
post #17

This is really great. I agree with comments about Forth. In this kind of projects, there is also Urbit ( https://github.com/urbit ).

This is the first time I see Urbit, looks interesting. Do you have some context about the project? Project homepage ( http://urbit.org/ ) doesn't seem to explain anything and Github page just describes the language.

The author is Curtis Yarvin (https://vimeo.com/75312418).

You can search also for "Moldbug". He has an old blog.

He is also a very controversial guy with libertarian ideas.

His project is very neat with distributed processes called "ships" or "submarines" with rights based on reputation.

It's a little bit like Erlang processes but with an anti-spam security model.

Re: Creating a language using only assembly language

#22
post #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 bas…

> 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.

That sounds like so much horror and so much fun at the same time.

Re: Creating a language using only assembly language

#23

Ok. I'll toot my own horn. In ~1983 I wrote the first iteration of Sensible Solutions for O'Hanlon Computer Systems using MASM. Of course, it had to run in less than 64k. Basically, it was a VM that would run pseudo code. And, the compiler was written in ASM also. In 1985 I wrote TAS, again using MASM. Again, a VM. The language it compiled (in both cases) was written to create business accounting applications, which…

I used to do some assembly on 68000, 6502 and some Z80. It's nice to have those simpler CPUs and the simpler hardware to learn an assembly language on.

Re: Creating a language using only assembly language

#24
post #11

Step 1: Make a language high-level enough to build a parser without being a masochist. Step 2: Make a lisp. Step 3: Do it all in lisp. Step 4: Profit. Even Amber( https://github.com/nineties/amber ) and its syntax looks a lot like lisp concept of grammar. But instead of (s expressions) you've got what is very similar to M[expressions] ( https://en.wikipedia.org/wiki/M-expression ). It's amazing what you can with Lisp…

Parsing LISP in assembly isn't even so hard. Without a lot of syntactic symbols, you're just finding whitespace and parens. Even syntactic sugar like ' for quote and , or @ in macros are pretty simple to parse compared to C or -- code gods forbid -- C++.

What I'd dread is writing the garbage collector in assembly. Maybe you could rely on reference counting, but that could still be a mess.

Re: Creating a language using only assembly language

#25
post #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 bas…

> 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. That sounds like so much horror and so much fun at the same time.

It was awesome for slowly migrating the compiler itself from assembler, and also for things like interfacing with the OS - I could write all the glue code inline.

But yes, it was easy to shoot your foot off with it. The main saving grace was that compared to i386, the M68k architecture has plenty of general purpose registers - 8 data registers and 8 address registers (including the stack pointer), so it was reasonably easy to avoid clobbering registers by having some strict rules about which registers were used for what combined with a very simple extra pass to the register allocator that'd mark any registers that were mentioned by name in a function as off limits.

It actually let me defer adding "real" local variables for quite some time since I could simply use the registers.

Re: Creating a language using only assembly language

#26
post #11

Step 1: Make a language high-level enough to build a parser without being a masochist. Step 2: Make a lisp. Step 3: Do it all in lisp. Step 4: Profit. Even Amber( https://github.com/nineties/amber ) and its syntax looks a lot like lisp concept of grammar. But instead of (s expressions) you've got what is very similar to M[expressions] ( https://en.wikipedia.org/wiki/M-expression ). It's amazing what you can with Lisp…

Parsing LISP in assembly isn't even so hard. Without a lot of syntactic symbols, you're just finding whitespace and parens. Even syntactic sugar like ' for quote and , or @ in macros are pretty simple to parse compared to C or -- code gods forbid -- C++. What I'd dread is writing the garbage collector in assembly. Maybe you could rely on reference counting, but that could still be a mess.

> What I'd dread is writing the garbage collector in assembly.

Then don't. If you're just building a lisp just so you can bootstrap your lisp compiler in lisp, the free-everything-and-quit should be a good enough GC strategy, and quite quick too.

Re: Creating a language using only assembly language

#27
post #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 bas…

> 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. That sounds like so much horror and so much fun at the same time.

BBC Micro Basic let you interpose assembler in the middle of the program - although it was a two-pass assembler and you had to call both passes seperately with a small FOR loop if you wanted labels to work.

Re: Creating a language using only assembly language

#28

I wrote BASIC in VAX assembly as a freshman. It compiled each line to byte-code (like Atari BASIC), and used a hand-written recursive descent parser. I remember using the VAX SKIP and SPAN instructions when dealing with strings. Sadly my only record of it was a fading fan-fold listing which is now gone. Looking at the presentation: I really should have learned LISP earlier than I did..

Programming in MACRO-32 was more like using a high-level language, did not feel like an assembly at all.

Re: Creating a language using only assembly language

#29

Ok. I'll toot my own horn. In ~1983 I wrote the first iteration of Sensible Solutions for O'Hanlon Computer Systems using MASM. Of course, it had to run in less than 64k. Basically, it was a VM that would run pseudo code. And, the compiler was written in ASM also. In 1985 I wrote TAS, again using MASM. Again, a VM. The language it compiled (in both cases) was written to create business accounting applications, which…

> If you've never programmed in assembler I recommend it to anyone. Just try something simple. Until you do, you won't appreciate what we have today. Especially if you're running on CP/M or early DOS!

I found very pleasant write a clone of Wozniak's machine code for my toy CPU/Computer

Re: Creating a language using only assembly language

#30
post #11

Step 1: Make a language high-level enough to build a parser without being a masochist. Step 2: Make a lisp. Step 3: Do it all in lisp. Step 4: Profit. Even Amber( https://github.com/nineties/amber ) and its syntax looks a lot like lisp concept of grammar. But instead of (s expressions) you've got what is very similar to M[expressions] ( https://en.wikipedia.org/wiki/M-expression ). It's amazing what you can with Lisp…

Parsing LISP in assembly isn't even so hard. Without a lot of syntactic symbols, you're just finding whitespace and parens. Even syntactic sugar like ' for quote and , or @ in macros are pretty simple to parse compared to C or -- code gods forbid -- C++. What I'd dread is writing the garbage collector in assembly. Maybe you could rely on reference counting, but that could still be a mess.

> What I'd dread is writing the garbage collector in assembly. Maybe you could rely on reference counting, but that could still be a mess.

You don't have to write the final Lisp in assembly; you write the first Lisp in assembly, and the final Lisp in Lisp.

Post reply on HN