[Media] Rust, compiled to Holly C, running on TempleOS

818 points FractalFir 68 comments
[Media] Rust, compiled to Holly C, running on TempleOS

In the spirit of April Fools, I decided to do something silly, and run some Rust code on obscure software.

I am a fan of history of Computer Sience, and language / OS development. Despite its obscurity, and tragic backstory(the author of Temple OS, Terry Davis, suffered from mental illness), Temple OS is a truly fascinating and inspiring piece of software.

Equipped with a C-like language(Holly C), a JIT compiler, and a revolutionary text format(which could embed 3D models, sounds, and much more) there is always something new to discover.

By modifying my Rust to C compiler, I have been able to make it output Holly C. There is a surprising amount of odd syntax differences between C and Holly C. Still, in spite of all that, I managed to get a simple Rust iterator benchmark to compile and run on TempleOS(after some manual tweaks).

I don't plan to do much more with this - I mostly wanted to do something silly - and show it to the world :D.

Here is a sample of Rust compiled to HollyC(names de-mangled for readability):

U0 iter_fold(
    Range self, RustU0 init, Closure2n23Closure1n12Closure1pu32v *f) {
  Option L0;
  I64 L1;
  U32 x;
  RustU0 L3;
bb1:
  spec_next(&self, &L0);
  L1 = ((L0).v)(I64)(U64);
  if ((((L0).v)(I64)(U64)) == (0x1(I64)))
    goto bb3;
  if (!(L1))
    goto bb5;
  goto bb14;
bb3:
  x = (L0).Some_m_0;
  fn_call_mut(
      (&f), (L3), (x));
  goto bb1;
bb5:
  return;
bb14:
 	"Unreachable reached at ";
         "/home/michal/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/";
         "rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2548:5: ";
         "2558:6 (#0)!";
  abort();
}