News for hackers. Stuff that matters.
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...