Live data from Hacker News

Tiny-C Compiler (2001)

iro.umontreal.ca

51–60 of 82 posts

Re: Tiny-C Compiler (2001)

#51
post #20

Earlier quoted context omitted.

> Performance isn't that important in most cases. Optimizing for storage space is…better?

Since they say "scripts", note that tcc supports being invoked in the shebang line. E.g. #!/usr/bin/tcc -run You can do that with gcc/clang too (e.g. #if 0, #endif to wrap a block of shell script to compile the current file and execute the result) but a primary value of tcc is that it compiles fast . On a more philosophical note, the suckless approach is to optimise for simplicity not storage. It's perfectly valid to…

You can only sort of do that with gcc/clang. The #if 0 trick relies on funny behavior that is in a few common shells. When you try to execve(2) a script without a proper #! shebang, the kernel will return ENOEXEC. Bash will check for ENOEXEC then check a few heuristics to see if it looks like a text file, and if it does, then it will try to run it as a shell script.

This means that your script will work when run from a shell, but won't work when exec()ed from a non-shell program, which is a weird foot-gun.

Re: Tiny-C Compiler (2001)

#52
post #17

Not to be confused with https://bellard.org/tcc/ , which is a tiny compiler for the C language.

I use tcc for all of my small C "scripts" for doing ioctls, etc. Less bloat, suckless. I imagine most software would be better off using tcc than gcc/clang. Performance isn't that important in most cases.

I feel like a lot of software written in C is written in C for performance reasons. Obviously that’s not always the case and TCC is useful but I wouldn’t say that that most software should use it

Re: Tiny-C Compiler (2001)

#53
post #40

Author here. Just for context tinyc.c was created in 2000 (I found the file in my archives and the last modification date is January 12, 2001). I was not aware at the time of Fabrice Bellard's work which after all won the IOCCC in 2001, so the confusion with TCC was not intentional. My tinyc.c was meant to teach the basics of compilers in a relatively accessible way, from parsing to AST to code generation to bytecode…

I wish I had time to make a list what would be required to bootstrap this.

Either by adding complexity (more features to the compiler) or dropping complexity (fewer C features in the implementation).

Did you ever look at that?

Edit: functions, enum, struct, arrays and maybe make all variables/functions a-z?

Edit2: https://joyofsource.com/projects/bootstrappable-tcc.html

Edit3: https://news.ycombinator.com/item?id=35135384

Re: Tiny-C Compiler (2001)

#54
Um, excuse me, but there existed a Tiny-C in 1979. Whatever you are talking about creating in 2000 is in no way an original idea.

References:

Dr. Dobb's Journal #32 (Feb 1979) page 41, review of Tiny-C User Manual by Ted Shapin [0]

Dr. Dobb's Journal #35 (May 1979) page 37, "Tiny-C Interpreter on C-Dos" by Ray Duncan[1]

Tiny-C Associates incorporated in Holmdel, NJ, March 1978 [2]

"Tiny C" trademark application filed 1979, cancelled 1987 [3]

There was also a "Small C", see DDJ #45 (May 1980), "A Small C Compiler for the 8080s" by Ron Cain[4]. Cain references buying a copy of "the Tiny-C interpreter from Tiny-C Associates" and finding it too slow, so he bootstraps his own C compiler, writing it in C, compiles it on a UNIX system, then using it to compile itself to get the 8080 machine code.

See also DDJ #69 (July 1982) p. 66, "Small C for the 9900" by Matthew Halfant[5], porting Cain's compiler to another platform.

[0] https://archive.org/details/dr_dobbs_journal_vol_04_201803/p...

[1] https://archive.org/details/dr_dobbs_journal_vol_04_201803/p...

[2] https://www.bizapedia.com/nj/tiny-c-associates.html

[3] https://alter.com/trademarks/tiny-c-73219160

[4]https://archive.org/details/dr_dobbs_journal_vol_05_201803/p...

[5] https://archive.org/details/dr_dobbs_journal_vol_07_201803/p...

Re: Tiny-C Compiler (2001)

#55

It's unfortunately not self-compiling, but has a structure which is very reminiscent of C4 --- another tiny C-subset compiler + stack-based VM which is self-compiling: https://news.ycombinator.com/item?id=8558822 The 26 predefined integer variables make this look like a variant of minimal BASIC, except with structured control flow instead of only GOTO.

Aha, this is interesting!

Re: Tiny-C Compiler (2001)

#56
post #54

Um, excuse me, but there existed a Tiny-C in 1979. Whatever you are talking about creating in 2000 is in no way an original idea. References: Dr. Dobb's Journal #32 (Feb 1979) page 41, review of Tiny-C User Manual by Ted Shapin [0] Dr. Dobb's Journal #35 (May 1979) page 37, "Tiny-C Interpreter on C-Dos" by Ray Duncan[1] Tiny-C Associates incorporated in Holmdel, NJ, March 1978 [2] "Tiny C" trademark application filed…

To be clear, I'm not claiming to be the first to have used the name Tiny-C, just that the confusion with TCC is not intentional. Your links to DDJ are great an bring back memories of the good old days when there was much to learn from reading DDJ and Byte magazine!

Re: Tiny-C Compiler (2001)

#57
post #53
post #40

Author here. Just for context tinyc.c was created in 2000 (I found the file in my archives and the last modification date is January 12, 2001). I was not aware at the time of Fabrice Bellard's work which after all won the IOCCC in 2001, so the confusion with TCC was not intentional. My tinyc.c was meant to teach the basics of compilers in a relatively accessible way, from parsing to AST to code generation to bytecode…

I wish I had time to make a list what would be required to bootstrap this. Either by adding complexity (more features to the compiler) or dropping complexity (fewer C features in the implementation). Did you ever look at that? Edit: functions, enum, struct, arrays and maybe make all variables/functions a-z? Edit2: https://joyofsource.com/projects/bootstrappable-tcc.html Edit3: https://news.ycombinator.com/item?id=351…

Haven't looked at what it would take to support C89 (or other) fully. Certainly it is possible to extend the compiler in small increments to implement more stuff: all the operators, local variables, arrays, pointers, functions, etc. The hardest part I would say is implementing types (starting with the C syntax for types!) and also handling the memory allocation for them. Nothing too complex when you know what you are doing. My personal interest is with higher-level languages and I have worked on various Scheme systems over the last 30 years. If you like small language implementations then take a look at Ribbit which is feature-full with a tiny VM. Also check out sectorlisp (not my work) which is a fascinating tour de force.

Re: Tiny-C Compiler (2001)

#58
post #40

Author here. Just for context tinyc.c was created in 2000 (I found the file in my archives and the last modification date is January 12, 2001). I was not aware at the time of Fabrice Bellard's work which after all won the IOCCC in 2001, so the confusion with TCC was not intentional. My tinyc.c was meant to teach the basics of compilers in a relatively accessible way, from parsing to AST to code generation to bytecode…

Would you think rewriting this to generate a minimal set of instructions could be benefitial to the compiler bootstrapping?
Post reply on HN