Live data from Hacker News

I wrote a Brainfuck to Go compiler

kabirgoel.com

11–20 of 23 posts

Re: I wrote a Brainfuck to Go compiler

#12
post #8

Earlier 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.

Would LLVM IR be something you compile or transpile to?

Re: I wrote a Brainfuck to Go compiler

#13
post #10

Meanwhile, 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

The real brainfuck is in the toolchain.

Re: I wrote a Brainfuck to Go compiler

#14

Earlier 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?

It's compilation all the way down. I write C#, and it is compiled to CIL, which gets further compiled via the JIT into asm.

CIL, or JVM bytecode, or LLVM IR is just one more step in the compilation chain.

Re: I wrote a Brainfuck to Go compiler

#15

I might be wrong, but is this not a transpiler instead of a compiler?

For me, the word "transpiler" has the connotation that it would translate more or less directly from one language to another, without going very deep.

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

#18

I 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

... and wouldn't the most useful cross compiler to the world be COBOL to Python (or whatever)? "There are over 220 billion lines of COBOL in existence, a figure which equates to around 80% of the world's actively used code. There are estimated to be over a million COBOL programmers in the world today." [1]

[1] https://blog.codinghorror.com/cobol-everywhere-and-nowhere/

Re: I wrote a Brainfuck to Go compiler

#20
post #6

Earlier 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.

It's the other way around. A transpiler is a compiler that compiles code from one to another high level language. Compiler is the more general term here.

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.

Post reply on HN