I wrote a Brainfuck to Go compiler(kabirgoel.com) |
I wrote a Brainfuck to Go compiler(kabirgoel.com) |
(If you are genuinely curious, there is already a BASIC-to-Brainfuck compiler [1] and a C-to-Brainfuck compiler [2].)
[1] https://esolangs.org/wiki/BFBASIC
[2] https://esolangs.org/wiki/C2BF (and I think I've seen at least two more)
Not at all... Just compile your Go code to WebAssembly [1], then to C [2], and finally to BF [3].
[1] https://binx.io/2022/04/22/golang-webassembly/
That was a fun project I challenged myself to complete in a weekend.
I don't know if there's any actual good distinction to draw that won't have problems. I'd be interested to listen to people theorize on what the distinction is.
The textbook definition of a compiler from A to B is any program that takes as input a program PA written in A and gives as output a program PB written in B, such that for all valid inputs I and modulo the undefined behaviors of A and B, it holds that PA(I) = PB(I).
So you could write a Java program that turns C++ into Python and it would technically qualify as a compiler.
If the code is transformed fully down into intermediate representation (such as LLVM-IR or graph form), processed in that form and then transformed from that into a target language (be it machine language or something else), then it is "compilation".
[1] https://blog.codinghorror.com/cobol-everywhere-and-nowhere/
Transpilers aren't limited to JS nor web dev. There are various other transpilers/compilers such as nimlangs compiler that can target C.
(Parts of the Nim community are famously insistent that they have a compiler, not a transpiler!)
The distinction is almost arbitrary and rarely used until recently I think. It would be more useful if "transpiler" had some well defined property (like isomorphism) that distinguishes it from a compiler other than targeting a "high level" language. Are C, JVM bytecode, WASM, LLVM IR etc "high level" or not?
It gets even more confusing. In the JS world "transpiling" is for example used to describe the process of rewriting code from one version of the spec to another for compatibility reasons. What does that say about "npm fix" or "go fix"? Are those transpilers too? Does that mean they are compilers? What about a Lisp macro? An SQL query builder? Some of these do more involved things than what is called "transpiling" in the JS world.
CIL, or JVM bytecode, or LLVM IR is just one more step in the compilation chain.