News for hackers. Stuff that matters.
Re:Best of show – abuse of libc by badsectoracula on Friday January 08, 2021 @05:25PM (#25691331)
Up next: a C compiler that compiles to printf statements :-P
Re:Best of show – abuse of libc by hahajk on Friday January 08, 2021 @05:32PM (#25691394)
https://github.com/HexHive/printbf

well this is a brainfuck interpreter inside printf. I’m pretty sure there are plenty of c-to-bf transpilers.

Re:Best of show – abuse of libc by felixr on Friday January 08, 2021 @06:06PM (#25691683)
This is by the same author as the ioccc entry and also one of authors of the paper showing the turing completeness of printf http://nebelwelt.net/publications/#15SEC
Re:Best of show – abuse of libc by lifthrasiir on Friday January 08, 2021 @08:33PM (#25694771)
Ah, that explains everything. I have already seen this technique before and wondered why this entry has to be the best of show---I don't doubt it is worth the prize, just that it didn't sound very novel. But it all makes sense if the technique is not well known and authors tried to revitalize that.
Re:Best of show – abuse of libc by klyrs on Friday January 08, 2021 @06:10PM (#25691718)
That's fun, but esoteric languages in general and brainfuck in specific tend to lack things you'd want out of c: file system access, system calls, etc.
Re:Best of show – abuse of libc by archi42 on Friday January 08, 2021 @07:03PM (#25692856)
Hm, I think you could add numeric syscalls, similar to what happens at the asm level. E.g. put the syscall id and some parameters on the "stack", then let the interpreter run the syscall with a new "instruction" e.g. '!'. This could even substitute '.' (putchar) and ',' (getchar), since these are very much just syscalls. So that would reduce the number of instructions by one (to 7).

Oh, getting to 6 would also be fun: One might replace '[' and ']' with a conditional branch '?'. It just needs two parameters: condition and (signed) number of instructions to jump. Adds the bonus (much like normal asm) to write moch more ~~horribly abusive~~ flexible control flow than a structured "while(*ptr)".

Re:Best of show – abuse of libc by enedil on Friday January 08, 2021 @08:36PM (#25694823)
It's already implemented: https://github.com/ajyoon/systemf There is even an HTTP server built with it.
Re:Best of show – abuse of libc by archi42 on Friday January 08, 2021 @08:44PM (#25694950)
Why am I not even surprised...? I thought about writing a sentence about how (relatively) easy it would be to build a verified compiler (think CompCert-for-brainfuck); I'd guess the outcome is one of (a) "someone already did that as well, here is the link" or (b) "I spent the weekend with that, here is the project on github". The Internet is awesome, as are people :)
Re:Best of show – abuse of libc by jcande on Friday January 08, 2021 @08:07PM (#25694138)
That was my approach for an analogous program that uses memcpy instead of printf. I didn't go with the jit-style you describe, however. If you're curious here's how I setup the syscalls https://github.com/jcande/xenocryst/blob/master/src/gadgets.... and here's the main loop https://github.com/jcande/xenocryst/blob/master/src/exec.c#L...
Re:Best of show – abuse of libc by lathiat on Friday January 08, 2021 @08:43PM (#25694929)
There is somewhere a compiler that outputs to all sorts of crazy languages including awk, sed, printf, etc.. but I can't find it right now. Hopefully someone knows what I'm talking about.

I feel like it did LLVM IR to a bunch of languages or something like that.. but my memory is faulty.

Re:Best of show – abuse of libc by lifthrasiir on Friday January 08, 2021 @08:46PM (#25694986)
You are looking for ELVM: https://github.com/shinh/elvm/ (I have seen many others, but in terms of activity it seems the most maintained one.)
Re:Best of show – abuse of libc by lathiat on Friday January 08, 2021 @10:56PM (#25696665)
Thankyou, that is the one! :) I love projects like that.