Skip to main content

News

Topic: TCC Toy C languages, run C as a script (Read 3937 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • FBnil
  • [*][*]
TCC Toy C languages, run C as a script
I re-found this on the web, a Unix system written in Javascript, straight from the browser: http://bellard.org/jslinux/

It contains busybox, and tcc

TCC is a weird little C compiler:
Code: [Select]
fbnil@tortuga:~/CODE/TCC$ ./helloworld.c
Hello world!
fbnil@tortuga:~/CODE/TCC$ cat ./helloworld.c
#!/usr/bin/tcc -run
#include <stdio.h>
main() {
   printf("Hello Sphere Community!\n");
}


It supports inline ASM, runs everywhere, even your toaster. Does not produce very optimized C, so GCC binaries should be faster. But it does compile faster...

http://www.herongyang.com/Computer-History/C-TCC-Tiny-C-Compiler.html
http://bellard.org/tcc/tcc-doc.html

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: TCC Toy C languages, run C as a script
Reply #1
I remember seeing this a few years ago. It's cool and impressive. :) Wonder what practical uses it can have (useful for teaching I suppose), and if it's in actual use anywhere.

  • FBnil
  • [*][*]
Re: TCC Toy C languages, run C as a script
Reply #2
From the wiki:  https://en.wikipedia.org/wiki/Tiny_C_Compiler

Cinpy is (was?) a Python library that allows you to implement functions with C in Python modules. The functions are compiled with TCC at runtime. The results are made callable in Python through the ctypes library. However, the homepage is gone now... so its probably not maintained anymore. Here is an example though:
http://amundblog.blogspot.nl/2008/12/cinpy-or-c-in-python.html
http://stackoverflow.com/questions/4376397/executing-a-c-script-in-python
Although its just plain silly, just compile, and then call it...
There is also a perl binding... but the same here, things like module libraries with c code are compiled before you can use them.

however LCC has been used in Matlab and Quake.  https://en.wikipedia.org/wiki/LCC_%28compiler%29

Still like TCC though... I can finally run C scripts! lol

Uses:

  • Auditable code

  • Dynamic re-compilation



Drawbacks:  -o1 only (no ultra optimizations gcc's o3 does), thus a bit slower at execution (however, faster than Python or java)
  • Last Edit: June 10, 2015, 04:52:01 pm by FBnil