News for hackers. Stuff that matters.
Re:C4: C in Four Functions (2014) by hereisdx on Tuesday February 18, 2020 @07:54AM (#22355628)
Can someone please explain to me what this code does? I know some C, but I couldn't understand this.
Re:C4: C in Four Functions (2014) by bluetomcat on Tuesday February 18, 2020 @08:36AM (#22355907)
A one-pass compiler for a subset of C, relying on a recursive-descent parser, doing the lexing, parsing and code generation in lockstep. The generated code, consisting of abstract machine instructions, is then executed by an instruction fetch and execute loop.

BTW, the code looks relatively short because many semicolon-separated statements are crammed on a single line, and short variable names make that somewhat manageable and even visually symmetric. If you were to unfold it with each statement on its own line, I guess it would be at least 3 times the size.

Re:C4: C in Four Functions (2014) by epicide on Tuesday February 18, 2020 @12:48PM (#22358146)
> A one-pass compiler for a subset of C, relying on a recursive-descent parser, doing the lexing, parsing and code generation in lockstep. The generated code, consisting of abstract machine instructions, is then executed by an instruction fetch and execute loop.

This should be added to the README.

Re:C4: C in Four Functions (2014) by hereisdx on Wednesday February 19, 2020 @01:44AM (#22363548)
Thanks a lot for the explanation!
Re:C4: C in Four Functions (2014) by vfinn on Tuesday February 18, 2020 @08:26AM (#22355841)
AFAIK after taking a quick glance, it takes c code as input, then translates it to internal format by doing tokenization and parsing, and then executes the code. So, it's an interpreter. You could call it with other names as well. You can also have the program itself as an input, and have many layers of execution.
Re:C4: C in Four Functions (2014) by Iv on Tuesday February 18, 2020 @08:42AM (#22355959)
considering the code is translated into a kind of simple, non-native opcode, I think it is also correct to call it a VM.