Live data from Hacker News

PicoC: a very small C interpreter for scripting

code.google.com

41–47 of 47 posts

Re: PicoC: a very small C interpreter for scripting

#41
post #13

Would this be allowed in an iPhone application, since it's all C?

AFAIK no programs are allowed which interpret code.

But in theory you could use it to script C in debug mode, then hard compile the script before you send it to Apple.

Re: PicoC: a very small C interpreter for scripting

#42
post #36
post #32

Personally I would use Forth for this. PicoC looks interesting but if I were to weigh my options (i.e. PicoC vs Forth in his example app UAV-onboard system, I would definitely go Forth).

Care to explain your reasoning behind this? As I understand, the main appeal of using C as a scripting language is the fact that you use the same language in compiled and interpreted part of your application. Drawbacks of using C interpreter for scripting could include large footprint and external dependencies, but as far as I can understand, they are not the case here. So what is your reasoning for Forth?

In the case of embedded programming, Forth is often made for the job. C is great for embedded programming too, and you can always mix the two languages. C isn't made for scripting, and hacks like PicoC don't appeal to me since it will always remain a hack.

While not exactly a scripting language per se, Forth does have amazing interactive capabilities. It's extremely light-weight and it's easy to implement a new Forth on a new hardware architecture. Footprint issues aside, development time in Forth is usually shorter, and the ability to connect directly to a device's Forth "shell" and try out Forth words (functions), create new words, play around with hardware in real-time is invaluable.

Forth code is less readable if you don't know Forth, and occasionally Forth programmers write ugly code, but that is definitely the case for embedded C programmers too.

Re: PicoC: a very small C interpreter for scripting

#43

Earlier quoted context omitted.

I was wondering if you really meant that, given that this is intended to be useful in embedded applications. To try to get a feel for the sort of programming you do and the sort of opinions you hold, I checked your profile - Bang - there's the answer right there: > I'm not trolling: > I actually think that. Is it really the case that you don't see the point in writing a minimal, small, clean, self-contained system th…

Just curious: Is it trolling, if I write out a strong opinion, that I don't necessarily believe, but that sounds reasonable to me, on a topic I'm trying to figure out what to believe, and then, when my sentiments get refuted, I say to myself, "Okay, now there's a reasonable way to think."

No, because you're interested in honest communication. But it would be more honest to phrase the strong opinion as "I don't necessarily believe X, but it sounds reasonable to me. Is there anything wrong with that reasoning?"

Re: PicoC: a very small C interpreter for scripting

#44
post #17

See also: http://bellard.org/tcc/ a compiler, but small and #!tcc can be put at the top of .c files to make them scripts. Also see: http://root.cern.ch/drupal/content/cint — an interpretor, but large.

An interesting thing about tcc is how fast it is compared to gcc. If you can use it, that might be a great advantage in development times.

Re: PicoC: a very small C interpreter for scripting

#45
post #17

See also: http://bellard.org/tcc/ a compiler, but small and #!tcc can be put at the top of .c files to make them scripts. Also see: http://root.cern.ch/drupal/content/cint — an interpretor, but large.

An interesting thing about tcc is how fast it is compared to gcc. If you can use it, that might be a great advantage in development times.

That's precisely why I sometimes use it. And that running code through another compiler can sometimes highlight issues that went previously unnoticed.

Re: PicoC: a very small C interpreter for scripting

#46
post #27
post #21

Earlier quoted context omitted.

TCC has two even more cool things: 1) a library that lets you compile C code within a process, relocate it and execute it. This is rather faster than shelling out to run gcc to create a shared object and open it using dlopen. 2) an awesome 2004 demonstration where TCC was used as a boot loader. Take the Linux kernel source (slightly modified to remove some of the gccisms), add TCCBOOT and reboot the machine: as part…

I really love Fabrice, but "TCC" will, forever, remain Turbo C, not Tiny C. DOS weenie pride!

Ctrl+F9 ftw.

Re: PicoC: a very small C interpreter for scripting

#47
post #22
post #15

Earlier quoted context omitted.

Hey David, what I think it's cool about picoC is that you can use it in places where you need to script at "hardware" level, like in robotics, embedded systems, and alike. Otherwise it is probably better to use Lua for instance, since I bet it is much faster (I just read part of the PicoC implementation and it is a pretty straightforward interpreter, very cool to read but hardly the faster) and safer.

Presumably, it wouldn't be that hard to create some Lua functions to interface with memory addresses, I would think.

Yes but it's a pain to write complex code accessing memory when you need high level functions, can't simply cast pointers to C structures and alike.
Post reply on HN