Spherical forums

General Discussion => Off-Topic Discussions => Topic started by: FBnil on June 09, 2015, 06:30:06 pm

Title: TCC Toy C languages, run C as a script
Post by: FBnil on June 09, 2015, 06:30:06 pm
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...

Title: Re: TCC Toy C languages, run C as a script
Post by: DaVince on June 09, 2015, 06:38:07 pm
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.
Title: Re: TCC Toy C languages, run C as a script
Post by: FBnil on June 09, 2015, 09:12:04 pm
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:
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


Drawbacks:  -o1 only (no ultra optimizations gcc's o3 does), thus a bit slower at execution (however, faster than Python or java)