[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Use tcc to make embedded just-in-time compile/interpreter

From: Benoit Gschwind
Subject: [Tinycc-devel] Use tcc to make embedded just-in-time compile/interpreter
Date: Fri, 16 Dec 2011 14:31:31 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111211 Thunderbird/8.0


I would like to create an embedded C interpreter/compiler.

The idea is to allow user to write plugin/add-on in C plain text in and
be able to load this code and execute it inside program. Actualy, if you
want add script capability into program you have to use lua or python or
other interpreted language. This project want to be an alternative.

The project would like to be as simple as possible, since this project
want make a C interpreter, there is no need in complex memory object
management, and should be able to run the following code :

/* at this step we open the file and compile it */
cscript * c = copen("modules.so.c");

/* here we get a pointer to foo
 * it is possible that there is a need to prepare some
 * environment before */
int (*foo)(int, int);
foo = csym(c, "foo");

/* execute foo */
int x = foo(10,30);
/* at some point */

the module.so.c look like :

/* some include or specific header should be add here

int foo (int x, int y) {
   /* can call some available function API */
   api_printf("enter in foo\n");
   return 10 * y + 3 * y;

so I foresee issue with binding library function and module function; or
issue with security, but I think it is possible. step needed are :

1. parse C file.
2. generate in memory asm of the code
3. bind function (indirect binding could be done)
4. and that it.

Advantage of this kind of approach is :
- lite interpreter (in reality it's a compiler)
- no need to learn a new complex API
- performance (since the code is fully compiled on load)
- no garbage collector by default (dev can make one by hand)
- probably more

Disadvantage :
- compiled program are not in safe environment, user can corrupt memory
- user can hack code more easily.
- user can make memory leak
- hard to debug ?
- probably more

Do my project is possible, do tcc source could be used to do such
project (should I rewrite every thing ?) ?

Thank you by advance for your reply.

(This project will be done in sparse time do not expect it soon)

Best regards

reply via email to

[Prev in Thread] Current Thread [Next in Thread]