3 ms·
It’s not obvious from the text, but the compiler was previously written in TypeScript (which was kind of a strange choice for the language to write a compiler i
by eapriv 2y ago
It’s not obvious from the text, but the compiler was previously written in TypeScript (which was kind of a strange choice for the language to write a compiler in).
- akmittal 2y agoTypeScript compiler is more of a transpiler, not a typical compiler that creates a binary. I don't think it was weird choice.
- pjmlp 2y agoBootstraping compilers is a common activity and TypeScript is a nice language.
- nailer 2y agoYep. I remember years ago when they celebrating getting the C# compiler working in C#.
- atonse 2y agoThat was the Roslyn project! Yes they were also excited that it would allow more devs to hook into the computer and also enhance it.
- eapriv 2y ago“Nice” doesn’t mean “well suitable for writing a compiler in”. It’s strange to think that all languages should be equally good for writing all kinds of things, and choosing a web language for a non-web task is doubly strange.
- ivanjermakov 2y agoI don't consider it strange, and I'm not alone: https://news.ycombinator.com/item?id=37171801 https://news.ycombinator.com/item?id=37171801
- uncenter 2y agois it not common to write compilers for languages in the language being compiled itself? rust does this i think?
- uncenter 2y agonote that as others have said, "compiled" is a stretch, but nevertheless...
- kazinator 2y agoPrograms that are less than full compilers in some sense can be bootstrapped. For instance, this compiler for a pattern matching notation has parts of it implementation using the notation itself: https://www.kylheku.com/cgit/txr/tree/stdlib/match.tl https://www.kylheku.com/cgit/txr/tree/stdlib/match.tl Some pattern matching occurs in the function match-case-to-casequal. This is why it is preceded by a dummy implementation of non-triv-pat-p, a function needed by the pattern matching logic for classifying whether a pattern is trivial or not; it has to be defined so that the if-match and other macros in the following function can expand. The sub just says every pattern is nontrivial, a conservative guess. non-triv-pat-p is later redefined. And it uses match-case! So the pattern matcher has bootstrapped this function: a fundamental pattern classification function in the pattern matcher is written using pattern matching. Because of the way the file is staged, with the stub initial implementation of that function, this is all boostrapped in a single pass.
- steveklabnik 2y agoIt is fairly common, yes. Sometimes those compilers (or interpreters) aren't the primary implementation, but it's certainly a thing that happens often. Most of the Rust compiler is in Rust, that's correct, but it does by default use LLVM to do code generation, which is in C++.
- styfle 2y agoIts not strange, its very common. Its called "bootstrapping". > Bootstrapping is a fairly common practice when creating a programming language. Many compilers for many programming languages are bootstrapped, including compilers for ALGOL, BASIC, C, C#, Common Lisp, D, Eiffel, Elixir, Go, Haskell, Java, Modula-2, Nim, Oberon, OCaml, Pascal, PL/I, Python, Rust, Scala, Scheme, TypeScript, Vala, Zig and more. https://en.wikipedia.org/wiki/Bootstrapping_(compilers) https://en.wikipedia.org/wiki/Bootstrapping_(compilers)
- eapriv 2y agoYet people wouldn’t write a Fortran compiler in Fortran, or a MATLAB compiler in MATLAB.