That was a fun project I challenged myself to complete in a weekend.
I wrote a Brainfuck to Go compiler
11–20 of 23 posts
Re: I wrote a Brainfuck to Go compiler
#12Earlier quoted context omitted.
Back in University, I had a Programming Languages professor who spent an entire lecture ranting about the term transpiler and how ridiculous he thought it was. Although I never shared his distaste for the term to the same degree, I anyways felt somewhat kindred with him on it. It's a useful term if you want to draw a distinction (for whatever reason), between moving from a human-readable language to a computer-readab…
Well technically you can read those computer-readable ones too. And even become somewhat proficient. It's just that it's "harder". And as a second trick, a computer can even "read" the human-readable languages as well :) 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.
Re: I wrote a Brainfuck to Go compiler
#13Meanwhile, a Go to Brainfuck compiler remains uncharted territory. (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)
> a Go to Brainfuck compiler remains uncharted territory. 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/ [2] https://webassembly.github.io/wabt/doc/wasm2c.1.html [3] https://esolangs.org/wiki/C2BF
Re: I wrote a Brainfuck to Go compiler
#14Earlier quoted context omitted.
Well technically you can read those computer-readable ones too. And even become somewhat proficient. It's just that it's "harder". And as a second trick, a computer can even "read" the human-readable languages as well :) 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.
Would LLVM IR be something you compile or transpile to?
CIL, or JVM bytecode, or LLVM IR is just one more step in the compilation chain.
Re: I wrote a Brainfuck to Go compiler
#15I might be wrong, but is this not a transpiler instead of 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".
Re: I wrote a Brainfuck to Go compiler
#16Re: I wrote a Brainfuck to Go compiler
#17I might be wrong, but is this not a transpiler instead of a compiler?
Re: I wrote a Brainfuck to Go compiler
#18I might be wrong, but is this not a transpiler instead of a compiler?
Well I must be wrong then, I was going to ask if it is not called a cross compiler? [1] [1] https://en.wikipedia.org/wiki/Cross_compiler
[1] https://blog.codinghorror.com/cobol-everywhere-and-nowhere/
Re: I wrote a Brainfuck to Go compiler
#19I can never take Brainfuck seriously because it has such a juvenile name.
Re: I wrote a Brainfuck to Go compiler
#20Earlier quoted context omitted.
Neither the source nor the target language are JS, the project isn't webdev-adjacent, and the author isn't trying to make up a cool-sounding title for an early-computing magazine, so I'm not sure why it would be!
A transpiler is just a piece of software that translates code to code. A compiler is a transpiler that targets machine code and usually builds an executable through various pipelines, e.g. optimization passes etc. Transpilers aren't limited to JS nor web dev. There are various other transpilers/compilers such as nimlangs compiler that can target C.
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.