4 ms·
A quick google search pulls up: https://gist.github.com/r-lyeh/0af42b2788bb75219061 https://gist.github.com/r-lyeh/0af42b2788bb75219061 http://scara.com/~schir
by emeraldd 10y ago
A quick google search pulls up:
https://gist.github.com/r-lyeh/0af42b2788bb75219061 https://gist.github.com/r-lyeh/0af42b2788bb75219061
http://scara.com/~schirmer/o/pcodevm/ http://scara.com/~schirmer/o/pcodevm/
Here's another ref: http://homepages.cwi.nl/~steven/pascal/book/pascalimplementation.html 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/insomniac_as https://github.com/arlaneenalra/insomniac/blob/master/insomn... ( a little FORTH happy ...)
Assembler Core: https://github.com/arlaneenalra/insomniac/tree/master/src/libinsomniac_asm https://github.com/arlaneenalra/insomniac/tree/master/src/li...
VM eval loop:
https://github.com/arlaneenalra/insomniac/blob/master/src/libinsomniac_vm/vm_eval.c https://github.com/arlaneenalra/insomniac/blob/master/src/li...
and Instructions:
https://github.com/arlaneenalra/insomniac/tree/master/src/libinsomniac_vm/libinsomniac_vm_instructions https://github.com/arlaneenalra/insomniac/tree/master/src/li...
https://github.com/arlaneenalra/insomniac/blob/master/src/libinsomniac_vm/libinsomniac_vm_instructions/vm_ops.c 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..)