handmade.network » Forums » Work-in-Progress » CToy: interactive C programming
anael
anaël seghezzi
15 posts
1 project
#8806 CToy: interactive C programming
5 months, 3 weeks ago Edited by anaël seghezzi on Oct. 5, 2016, 10:48 a.m.

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 ?
hugo
25 posts

None

#8807 CToy: interactive C programming
5 months, 3 weeks ago Edited by on Oct. 5, 2016, 11:46 a.m.

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!

None
JesseMeyer
Jesse
47 posts

None

#8810 CToy: interactive C programming
5 months, 3 weeks ago

Reminds me of Processing.org! Thanks for sharing!

The meaning of life is to dance and sing while the music is being played.
anael
anaël seghezzi
15 posts
1 project
#8863 CToy: interactive C programming
5 months, 2 weeks ago Edited by anaël seghezzi on Oct. 7, 2016, 10:03 a.m.

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).
hugo
25 posts

None

#8872 CToy: interactive C programming
5 months, 2 weeks ago Edited by on Oct. 7, 2016, 2:49 p.m.

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.

None
JC_Denton
3 posts

My vision is augmented.

#9026 CToy: interactive C programming
5 months, 1 week ago

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.

One sure mark of a fool is to dismiss anything that falls outside his experience as being impossible.
argontus
5 posts
#9045 CToy: interactive C programming
5 months ago Edited by on Oct. 21, 2016, 10:16 a.m.

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!
anael
anaël seghezzi
15 posts
1 project
#9046 CToy: interactive C programming
5 months ago Edited by anaël seghezzi on Oct. 21, 2016, 2:12 p.m.

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).
argontus
5 posts
#9071 CToy: interactive C programming
5 months ago

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 :)
anael
anaël seghezzi
15 posts
1 project
#9072 CToy: interactive C programming
5 months ago Edited by anaël seghezzi on Oct. 24, 2016, 7:12 a.m.

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
argontus
5 posts
#9073 CToy: interactive C programming
5 months ago

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 :)