Version 45 of tcc

Updated 2013-11-02 13:39:35 by AMG

The Tiny C Compiler

http://bellard.org/tcc/ (was http://fabrice.bellard.free.fr/tcc )

The actually maintained fork of tcc is TinyCC

AMG: As of 4 Oct 2007, said to be abandoned.

LV I don't know that I agree with that analysis. What you point to is a blog by one tinycc developer. His blog points to a post to the tinycc mailing list, asking him to go play with his fork of tinycc if he was going to reject input from users of his fork.

I don't see any indication that the primary tinycc developers are abandoning the work - just landley and his branch at landley.net. - RS 2007-10-09: The mailing list [L1 ] has a few daily posts in recent days... but for us Tclers, hanging on MJs tcltcc branch (with VFS i/o, see below) may be better-fitting.

cjl - As of 7 Dec 2009, the most recent news item on the site is from May of this year, announcing x86-64 compatibility. The source code repository at [L2 ] has recent updates (Dec. 2009). Project page: [L3 ], mailing list archive: [L4 ]


Features (from the tcc homepage)

  • SMALL! You can compile and execute C code everywhere, for example on rescue disks (80KB for x86 TCC executable Larry Smith Compress it with upx [L5 ] and it drops to 56K.)
  • FAST! tcc generates optimized x86 code. No byte code overhead. Compile, assemble and link several times faster than GCC.
  • UNLIMITED! Any C dynamic library can be used directly. TCC is heading torward full ISOC99 compliance. TCC can of course compile itself.
  • SAFE! tcc includes an optional memory and bound checker. Bound checked code can be mixed freely with standard code.
  • Compile and execute C source directly. No linking or assembly necessary. Full C preprocessor included.
  • C script supported : just add '#!/usr/local/bin/tcc' at the first line of your C source, and execute it directly from the command line.
  • With libtcc, you can use TCC as a backend for dynamic code generation.

Reinhard Max has tried to Compile Tcl with tcc on SuSE Linux.

LGPL.

CMcC has written a tcc tcl extension - generate dlls and even dynamically compile C into memory.


Is there a way to combine critcl and one of these small c compilers? - RS: Odyce (tcc wrapper in eTcl) contains a partial Critcl emulation - the difference being that no external compiler, linker etc. is needed.


[Of possible interest to the same readers is this [L6 ] small compiler.]

LES: Are you sure it's for i386 only? What about this? [L7 ]

SDCC can generate code only for Intel 8051, Maxim 80DS390 and Zilog Z80, with Motorola 68HC08 and Microchip PIC16 and PIC18 in the works. Tcl runs on none of these, AFAIK.


See also: Small is beautiful


October 27, 2004 [email protected]:

I have a working version for windows, and have written a couple examples using Tcl C API's...Works pretty good... Still needs some work....

CMcC - Excellent. The latest version is supposed to work for windows too, the big question is: can your version create .dll files?

[email protected]:

No, what you get is a compiled memory resident code. I use it mainly to quickly test new 'C' code segments or just needed a quick fast function call to perform something (math routine)...

I've compiled the tcc into a DLL and load it into tcl, then load/unload my 'C' scripts...I have put in hooks to call the tcl API so I can create new commands...The main difference is that you use the "main" function the same as the "init" call to initialize the code...

example 'C' script:

AMG 8 Dec 2005: I removed the example script because it's horribly corrupted. Look in the revision history if you want to try and salvage it. And remember, when pasting blocks of code in the Tcl wiki, prefix each line with a space character. Also proofread the result of your edit to see that it looks the way you intend.

PWQ 6 Jan 2005, I have used tcc 0.9.22 and I have found there are some differences in execution between compiling with gcc and tcc.

One opengl program does not display any opengl renderings even though the glut menu displays.

I think tcc has some way to go before becoming a contender for a JIT type of extension to TCL.

HJG 2005-12-08: Link appears dead "Server not found" - RS 2007-10-01: Link is alive, but latest news is of Jun 17, 2005, so tcc may be, umm, dormant. It could also have begun a new life in odyce ... :^)


RS 2007-10-06: Another tcc adaption to Tcl, as a regular loadable package, is currently in the making - contact MJ. I'm testing it on W95/Tcl 8.4.5, and it looks nice so far :^)

MJ - Source code is now hosted at GoogleCode [L8 ]

So tcltcc (MJ's code over at GoogleCode) is a Tcl extension, or a modified version of Tcc, or both? - RS 2007-10-09: Both - a Tcl extension package wrapping tcc, modified so that it does file I/O via VFS (so you can mount ZIP files to read from, etc.)


RS 2013-11-02 - Six years later. The latest download at GoogleCode [L9 ] is still tcltcc0.4.zip dated Nov. 2007, so time has stood still there...

I downloaded it to my x86 Lubuntu netbook and got it to work after some tweaking.

suchenwi@suchenwi-NC10:~/tcltcc$ sudo ./configure
checking for correct TEA configuration... ok (TEA 3.6)
checking for Tcl configuration... configure: WARNING: Can't find Tcl configuration definitions

suchenwi@suchenwi-NC10:~/tcltcc$ sudo ./configure --with-tcl=/usr/lib/tcl8.5
(((lots of output...)))
$ make
(((lots of output...)))
$ make test
(((some output, then: )))
---- errorInfo: In file included from <string>:2:
In file included from /home/suchenwi/tcltcc/tests/../include/tcl.h:141:
In file included from /usr/include/stdio.h:27:
In file included from /usr/include/features.h:341:
/usr/include/stdc-predef.h:30: include file 'bits/predefs.h' not found

 # So I did (quoting from history)
  734  sudo ln -s /usr/include/i386-linux-gnu/bits /usr/include/
  737  sudo ln -s /usr/include/i386-linux-gnu/sys /usr/include/
  740  sudo ln -s /usr/include/i386-linux-gnu/gnu /usr/include/

$ make test
...
Tests ended at Sat Nov 02 11:49:26 CET 2013
all.tcl:        Total        21        Passed        18        Skipped        3        Failed        0

 # Good, but in a tclsh, "tcl.h" cannot be found. tcc::dir already points at /usr/lib/tcc0.4. So:
suchenwi@suchenwi-NC10:~/tcltcc$ sudo cp -r include/ /usr/lib/tcc0.4/
suchenwi@suchenwi-NC10:~/tcltcc$ sudo cp -r lib /usr/lib/tcc0.4/

suchenwi@suchenwi-NC10:~/tcltcc$ rlwrap -c tclsh
% package require tcc
0.4
% # There must be a compiler instance
% tcc $tcc::dir tcc1
% # And now, finally...
% tcc::cproc mul {int a int b} int {return a*b;}
% mul 6 7
42

Phew! :^D