News for hackers. Stuff that matters.
Re:Show HN: How to write a tiny compiler by emeraldd on Thursday February 09, 2017 @04:13PM (#13611043)
A quick google search pulls up:

https://gist.github.com/r-lyeh/0af42b2788bb75219061 http://scara.com/~schirmer/o/pcodevm/ Here's another ref: http://homepages.cwi.nl/~steven/pascal/book/pascalimplementa...

But really, all you need is an understanding of the ISA (i.e. the instruction set and the machine it runs on), and have a file format in mind for a middle layer and you can build a runtime. (Basically P-code one form of ISA that's supposed to be portable.) That's kind of what insomniac with a custom isa does:

ISA: https://github.com/arlaneenalra/insomniac/blob/master/insomn... ( a little FORTH happy ...)

Assembler Core: https://github.com/arlaneenalra/insomniac/tree/master/src/li...

VM eval loop: https://github.com/arlaneenalra/insomniac/blob/master/src/li...

and Instructions: https://github.com/arlaneenalra/insomniac/tree/master/src/li...

https://github.com/arlaneenalra/insomniac/blob/master/src/li...

It helps to build the assembler and vm backend first so you have a pipeline in play that you can use to add in ops as you discover they are needed.

(keep in mind all my code is toy stuff..)

There are no comments on this comment yet.