Am 18.05.17 um 00:21 schrieb Chris Angelico:
On Thu, May 18, 2017 at 8:06 AM, Christian Gollwitzer <aurio...@gmx.de> wrote:
tcc even has a "JIT-mode" of operation (libtcc). For Tcl, there exists an
extension which compiles C code to memory and executes directly from there.
The same thing could be done for Python, too.
One of the complaints that bartc raised against clang was that it's
not self-contained - that it depends on some other stdlib. Yet he
espouses a tiny C compiler that obviously has the same limitation. On
my Linux boxes, I can grab GNU libc; but on Windows, where are you
going to get the header files and link-time libraries from? Oh right.
MSVC.
It was me who brought up tcc as a possible useful enhancement of Python.
I have been using it without external library files to compile
extensions for Tcl, and have proposed that it could be equally useful
for Python.
The whole discussion reminds me of the "bumblebees can't fly" thing.
Please have a look here:
https://chiselapp.com/user/rkeene/repository/tcc4tcl/index
and more examples here:
https://chiselapp.com/user/rkeene/repository/tcc4tcl/wiki/Examples
This shows how to embed some C code within a Tcl program, which is
compiled by tcc at runtime and then called as regular Tcl functions.
How it works
=============
tcc is a very small compiler (some 100kb) which supports most of C99. In
order to call library functions, the compiler must know the function
prototypes, i.e. "void printf(const char* fmt, ...)", which are
contained in the C library headers. These headers are indeed scraped
from a working gcc setup, but they weigh in ~1 MB only, and can be
installed together with tcc4tcl.
The library files for the C library (MSVCRT.lib, .dll) are NOT needed,
because tcc can link directly to the running executable. Python already
comes with libc/MSCVRT (or loads it from the OS) on startup. tcc then
finds the entry point to malloc, free etc. and "links" the code to them.
If somebody would develop "tcc4python" and ship that with Python or pip,
then pip could install a C library from source.
tcc is a very impressive piece of compiler, it emenated from an
obfuscated C code competition, where a C-like compiler was implemented
in <1kB. It then was developed into a full-blown compiler, which is/was
used to compile the Linux kernel upon boot from source:
https://bellard.org/tcc/tccboot.html
The speed of tcc executables cannot compete with other optimizing
compilers, because it compiles every line separately. However, typically
it's within a factor of 2 or 3 with gcc (unless you have vectorizable
numerical code) and therefore still 3 orders of magnitude faster than
Python, if you can express the code in C.
Christian
--
https://mail.python.org/mailman/listinfo/python-list