user14431718
user14431718

Reputation:

How exactly is Rust programming language implemented?

If you check languages percentage in github rust lang compiler repository it says that 97.6% of the rust lang compiler is written in rust. So how does this exactly works?. How you can create a programming language (I think this is related to a compiler, since it's whom read the code, doesn't it?) written in itself.

Upvotes: 4

Views: 952

Answers (1)

templatetypedef
templatetypedef

Reputation: 373042

This is called self-hosting or bootstrapping. The basic idea goes like this:

  1. Write an initial compiler for a small subset of Rust using your Other Programming Language of Choice. You now have compiler C0.
  2. Using the subset of Rust you have a compiler for, rewrite the source for C0 purely in Rust. Compile that program using compiler C0 to form compiler C1.
  3. Add features to Rust by adding code to the compiler you just wrote to properly parse and implement those features. Compile that Rust program with C1 to form compiler C2.

By repeating step (3) as many times as you’d like, you can add progressively more and more features to the Rust language, with the Rust compiler always being written in Rust itself.

There’s a famous talk called Reflections on Trusting Trust that talks about how this process works, as well as how you can use this process to do Nefarious Things.

Upvotes: 9

Related Questions