Recently I'm working on toy C compiler and x86 Assembler in TypeScript[1] and I can confirm that the amount of work that have to be done to compile and print simple Hello World is astronomically huge (as the satisfaction) [1] https://github.com/Mati365/ts-c-compiler
Tiny-C Compiler (2001)
31–40 of 82 posts
Re: Tiny-C Compiler (2001)
#32Recently I'm working on toy C compiler and x86 Assembler in TypeScript[1] and I can confirm that the amount of work that have to be done to compile and print simple Hello World is astronomically huge (as the satisfaction) [1] https://github.com/Mati365/ts-c-compiler
This isn't a C compiler though. It's a compiler for a language called Tiny-C.
Re: Tiny-C Compiler (2001)
#33first assignment would be to add the multiply and divide operators... I admit I have trouble understanding how the VM run() function works... anybody can give some insight?
Re: Tiny-C Compiler (2001)
#34Earlier quoted context omitted.
I'm quite confused, not the same project at all? To me tiny c compiler always meant the bellard page. Super useful stuff for micro hacky projects.
I understand the confusion: it is more about "syntax associativity" (tiny C) compiler --> "This is a compiler for the Tiny-C language" vs Tiny (C compiler) --> "TinyCC [...] is a small but hyper fast C compiler" That's it! ;-)
Re: Tiny-C Compiler (2001)
#35I hacked in support for ">", ">=", and "<=" to match the "<" support, but I just noticed that ints are truncated, so the maximum value stored in a variable is 127.
Re: Tiny-C Compiler (2001)
#36This is an interpreter for a super restricted subset of C and it looks well written from a pedagogical standpoint (keeps thing pretty simple, fairly easy to read). But it's slightly awk to strip-down a language (what features do you keep, what do you lose?). I think it's more fun to build an interpreter for an actual tiny language. In my next book I have interpreters for Brainfuck [0], an obfuscated kind of joke of a…
Also related to small language implementations I find notable PicoC [3] which is a C interpreter written in around 3k LOC of C. Past discussion about it here 13 years ago [4].
[0]: https://www.lua.org/about.html
[1]: https://www.lua.org/spe.html
[2]: https://en.wikipedia.org/wiki/Lua_(programming_language)
Re: Tiny-C Compiler (2001)
#37Not to be confused with https://bellard.org/tcc/ , which is a tiny compiler for the C language.
Re: Tiny-C Compiler (2001)
#38This is an interpreter for a super restricted subset of C and it looks well written from a pedagogical standpoint (keeps thing pretty simple, fairly easy to read). But it's slightly awk to strip-down a language (what features do you keep, what do you lose?). I think it's more fun to build an interpreter for an actual tiny language. In my next book I have interpreters for Brainfuck [0], an obfuscated kind of joke of a…
1. You use the example of a tiny basic of a 'real language' and I don't see how tiny basic is a 'real language', but tiny C is a stripped down language.
2. You can build on this to make a full c implementation. A minimal c implementation that can potentially bootstrap a full c environment is more useful than a brainfuck interpreter.
Re: Tiny-C Compiler (2001)
#39Not to be confused with https://bellard.org/tcc/ , which is a tiny compiler for the C language.
It is sad that tcc is unmaintained as it would be really useful in small embedded systems. I just tried it on Debian and compilation fails without #undefining CONFIG_TCC_MALLOC_HOOKS in lib/bcheck.c. After compilation it passes tests, but they warn that it could be unreliable.