R.O.S.S
R.O.S.S

Reputation: 625

Bootstrapping from nothing

I'm interested in the Crystal programming language but I'm a bit confused:
The compiler is written in Crystal.
I know that you can bootstrap a language (write it in itself), but you still need some code in another language so you can run the compiler/interpreter. I've also searched for some code that is not Crystal source on the Crystal repository, but I have found only the llvm-ext.cc file, which doesn't seems to handle the whole language.
So, my question: Is Crystal only a language spec and does it require you to have some other (non-official) compiler?

Upvotes: 3

Views: 363

Answers (1)

S.D.E.
S.D.E.

Reputation: 31

No other compiler is required than the compiler recommended by Crystal documentation, which is a compiled binary of the Crystal front end to LLVM and a binary of LLVM, in order to compile programs from Crystal source, including a Crystal front end. Crystal is not only a language specification; it's a running compiled language, with a self-hosting front end.

It would be possible, but difficult and not necessarily practical, to write a new compiler front end for Crystal or for any compiled language, in order to provide the language by a different method. The evidence that's difficult and often impractical is that many languages have only one current implementation, and popular languages that have several implementations still usually have at most one front end per compiler suite.

To provide a language "from nothing" rather than relying on an existing compiler or interpreter, one could write a compiler by the method of looking up machine code instructions in a table and entering them into a computer byte by byte. That's an extremely difficult method of programming, and my evidence for that is personal experience, where I've written programs about ten bytes long by that method, and those programs didn't do very much. I've written much longer programs by other methods, with more choice of what the programs did and without as much difficulty.

Since November 2013 and continuing as of 2017, Crystal has had only a self-hosting compiler front end for its implementation. Before that, Crystal was implemented by a front end written in Ruby. The front end in Ruby was rewritten in Crystal, then the front end in Ruby was used to compile the front end from Crystal source. That was the bootstrapping process that resulted in Crystal having a self-hosting front end.

references:

Crystal site: DOCS: Installation: From source

Good bye Ruby Thursday — the announcement of the bootstrapping of Crystal

Upvotes: 3

Related Questions