[bootstrappable] Re: Bootstrapping from a hex editor

  • From: Ondřej Čertík <ondrej@xxxxxxxxx>
  • To: bootstrappable@xxxxxxxxxxxxx
  • Date: Wed, 08 Nov 2017 14:14:35 -0700



On Wed, Nov 8, 2017, at 07:15 AM, Orians, Jeremiah (DTMB) wrote:

Can you post your 3 Lisp implementations in Forth online? I would like 
to have a look.
Yes, but it'll take me a bit to dig those out
If you find it, I would appreciate it.

Sorry for the delay but sadly the 3rd is currently locked behind a
paywall (https://dl.acm.org/citation.cfm?id=59413.59435
Here are the 2 that still are available:
https://github.com/eiselekd/MinimalLisp
http://www.complang.tuwien.ac.at/schani/oldstuff/scheme_in_forth.tar.gz

Thanks for the links.


Currently, I am exploring an alternative option to bootstrapping:
https://github.com/oriansj/M2-Planet

At its current level of complexity, it is only about 90 hours of work to
hand convert to M1 assembly.
Once it becomes self-hosting it should be able to compile Janneke's mes.c
and thus close our remaining gap

Is your idea with M2-Planet that you write a simple C compile, and then
implement it in assembly? How many lines of assembly do you estimate
that would be to maintain?

One thing is that we can use gcc to generate the assembly and take it as
our "implementation" and maintain that. But the assembly will be long,
and not really maintainable for me. 

One idea that I got is that the Forth implementation in assembly is only
about ~1000 lines, so that's maintainable. One could then compile C code
to Forth, here is a proof of concept:

https://github.com/dmedinag/C-to-Forth-compiler

As an example, this:

#include <stdio.h>
int b;
main()
{
        int a;
        a = 10;
        do {
                printf("%d", a);
                if (a % 2) {
                        puts("then block");
                } else {
                        puts("else block");
                }
                a = a - 1;
        } while (a > 0);
}


Gets translated to this:

variable b_global
variable a_main
: main 
10 a_main ! 
begin
a_main @ .
a_main @ 2 mod if
." then block "
 else ." else block "
 then
a_main @ 1 - a_main ! 
a_main @ 0 > while repeat
 ;


I don't know what version of Forth that is using, and how hard it would
be to target your assembly Forth implementation.  I also don't know if
all the C constructs that are needed for a C compiler can actually be
directly translated to Forth.

But I am thinking that it might be possible to design some Forth
primitives to make this translation pretty short and readable. Perhaps
using some indentation to make it look almost like the original C code.

Then one can maintain the C code as the implementation, and the Forth
code will be generated from it. For bootstrapping only the Forth code
will be used of course, but if it's readable and not much longer than
the C code, then I think that would serve the purpose, wouldn't it?

Ondrej

Other related posts: