Handmade Network»Forums»Work-in-Progress
anaël seghezzi
23 posts / 1 project
CToy: interactive C programming
Edited by anaël seghezzi on
Hi all,

my name is Anaël, I'm an artist and programmer working mainly as a technical art director for animation films.
I like to publish parts of my work in open-source, I released the 3d game environment 'Maratis' 6 years ago (after a decade of work).

Recently I felt more and more dissatisfied with c++, I tented to avoid c++ libraries in favor or c ones and decided, what the hell, lets just go back to c. At the same time I was also looking for effective ways to optimise my work, and interactive programming was the best candidate.

Introducing CToy, a small interactive C environment, based on TCC (Tiny C Compiler from Fabrice Bellard):
https://github.com/anael-seghezzi/CToy

- small (around 2mb zip) and no installation required
- write standard c code interactively with any text editor
- realtime feedbacks (OpenGL-ES / OpenAL)
- helpers to compile with traditional compilers or generate project files (via shell scripts and CMake)

There is still some opened questions I didn't find answers (there is only one entry point for now 'main.c').
And I'm still working on the C standard library (it's not complete and there may be some inconsistencies with gcc or visual).
TCC code runs 1.5 to 3 times slower than optimized code (no SIMD except with ASM).

It really improved my work, specially for prototyping, maybe you will find it useful too ? What do you think ?
25 posts
None
CToy: interactive C programming
Edited by hugo on
I don't know exactly when it would be useful, but it worked flawlessly and its very fun to play! Thanks for making it free!
Jesse
64 posts
Programmer at NASA GSFC
CToy: interactive C programming
Reminds me of Processing.org! Thanks for sharing!
anaël seghezzi
23 posts / 1 project
CToy: interactive C programming
Edited by anaël seghezzi on
hugo > tcc is actually a full c compiler, so you can do everything gcc can do.
The only thing missing is SIMD intrinsic, though it could be simulated or just avoided by using a '#ifdef __TINYC__' and debugging (which I don't use often, but you can still debug using other compilers anyway, it's normal C code).

I guess it is specially useful when writing graphical code, small programs or small one-shot libraries. In my case the productivity of re-usable code exploded and balanced the short-term benefit of C++ compare to C (not talking about long-term).
25 posts
None
CToy: interactive C programming
Edited by hugo on
I've been doing embedded these days, and sometimes I copy single functions from the big project to a single file, to test on the "desktop" environment which is much faster to compile and run - say for testing bit masks and simple algorithms - ctoy can make that even faster, I'll try to use it.
3 posts
My vision is augmented.
CToy: interactive C programming
Hello Anaël,

Thank you for sharing this!
I downloaded the file from github, but it seems I have an error while trying to run it (CToy is samaged) on El Capitan, 10.11.6.
Please see the attached image.


Am I doing something wrong?
Please advise.

Thank you.
5 posts
CToy: interactive C programming
Edited by argontus on
To JC_Denton, I just downloaded it and it works on my macOS Sierra 10.12. Maybe the .app got corrupted while downloading?

Also, check that your security settings allow .apps from unknown sources to be run on the computer. I guess that option might have changed to default if you've upgraded your OSX recently or something. System Preferences - Security & Privacy - Allow apps downloaded from: -> Anywhere

To anael, thank you so so much for sharing this! It is exactly the remedy for what usually keeps me from doodling quick ideas with compiled languages. Fast, out of my way, just works beautifully! I'm not very knowledgeable about compilers and always sticked to system defaults, visual c or gcc. Using tcc in your project is inspirational, makes me want to toy around with compilers more... Thanks, hehe!
anaël seghezzi
23 posts / 1 project
CToy: interactive C programming
Edited by anaël seghezzi on
Hi,

JC_Denton: Try to download it again in case the zip got corrupted.
I'm myself on Yosemite 10.10.3.

argontus: Thanks, you should read more about tcc, it's an amazing piece of software. Fabrice Bellard also wrote a small c-subset compiler in less than 500 lines (similar to c4) (he is also the creator of FFmpeg and Qemu). It made me curious about assembly and just-in-time compilation (I'm writing a small JIT assembler right now as a result).
5 posts
CToy: interactive C programming
anael
It made me curious about assembly and just-in-time compilation (I'm writing a small JIT assembler right now as a result).


Crazy inspirational! Lately I've thought a lot about getting more familiar with x86 assembly, but I've lacked a focus point. Maybe tcc could be a nice gateway to that world :)
anaël seghezzi
23 posts / 1 project
CToy: interactive C programming
Edited by anaël seghezzi on
Here is my ongoing experiment with X86-64 JIT (+ MIPS-like top layer) :
https://gist.github.com/anael-seg.../dd89fc64474393b0feec9c0e0de3cb4d
(it's a very rough, CToy code, but it can give you a starting point) TESTED ONLY ON OSX
5 posts
CToy: interactive C programming
anael
Here is my ongoing experiment with X86-64 JIT (+ MIPS-like top layer) :
https://gist.github.com/anael-seg.../dd89fc64474393b0feec9c0e0de3cb4d
(it's a very rough, CToy code, but it can give you a starting point) TESTED ONLY ON OSX


Thanks for sharing! That definitely is a great starting point! I prefer to learn in a very practical, hands-on, "what does it do if I flip this switch" kinda way, and your code in ctoy is a perfect learning tool :)