Skip to content

zz note: self brain surgery

Sam Rushing edited this page May 11, 2017 · 2 revisions

If you're making significant changes to the compiler design, especially ones that impact the code in header.c, gc.c, etc... it can be pretty tricky to bootstrap your new design using the old one.

Here's one way to do it:

  1. make a 'tmphead' directory
  2. copy header.c, gc.c, pxll.h, rdtsc.h into it
  3. in tmphead, make a symbolic link to ../self
  4. in the top, build your new compiler using the old one: $ self/compile.o3 self/compile.scm
  5. cd tmphead
  6. ../self/compile ../self/compile.scm -c
  7. cd ..
  8. $ /usr/local/bin/clang -Itmphead/ self/compile.c -o self/compile.new

Using the VM

Now that there's a VM, self-neurosurgery can be done a little more safely by switching between the C and bytecode compilers. (Unless you're messing with the runtime, if so see the above).

$ self/compile self/compile.scm -b
$ vm/irkvm self/compile.byc self/compile.scm -b

You can continue to make 'dangerous' changes to the bytecode-compiled compiler, and then when you're feeling lucky, compile to C.

Also note that the Makefile target 'make safe' is careful to keep the last ten copies of the C binary.