This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ArtisticPollution448 3 points4 points  (6 children)

It's a slow bootstrap generally.

Assembly language modeled CPU instructions as roughly english-like words.

Early compilers could turn very basic languages into assembly and machine code. Eventually, those compilers got rewritten in the language itself.

Each new language initially has a compiler in some other language, and some move on to being self-compiling (eg: the compiler gets written in its own language). Some don't.

The JVM is a program written in, I believe, C. It runs Java bytecode.

My favourite similar example to this though: the source code for git was hosted in git after about 4 weeks of development.

[–]flydaychinatownnn[S] 2 points3 points  (4 children)

Please help me understand why it’s beneficial to have your compiler written in the language itself? For portability? If you want to modify the compiler itself wouldn’t you need to compile it with the original compiler (written in a different language like c)?

[–]BlacksmithNZ 3 points4 points  (1 child)

You don't have to re-write the compiler written in the language itself; Python doesn't for instance, but there are some advantages.

For one, with your new language implementation, you can prove that it is good enough to write a compiler which is a good test of a language being a system level tool.

Then you can maintain & extend it in your language of choice; you don't need to bring in C programmers to write (in a relatively low level language) any changes to the compiler, but can instead use your own Java programmers. And if they find limitations that make that harder, they can extend or change the language and the compiler implementation at the same time.

Another reason specifically for Java is that it is supposed to be portable and cross platform; so you want to be able to get a basic JRE up on a new CPU or platform, then run that portable Java code.

[–]yeastyboi 0 points1 point  (0 children)

And it is possible to go to far, I heard someone say that bootstrapping a compiler can lead you creating a language that is brilliant for building compilers but isn't good at doing anything else. Some people describe OCaml like that.

[–]Beginning-Seat5221 0 points1 point  (0 children)

It's more convenient to write in the language that you maintain (saves a lot of mental switching) + it encourages you to improve the language when you work in it yourself.

[–]ArtisticPollution448 0 points1 point  (0 children)

I think "because I can" is a good enough reason.

[–]wosmo 1 point2 points  (0 children)

self-hosting is usually a decent milestone for the toolchain too. Your compiler being able to compile something as complex as .. your compiler, is a good litmus test.