tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Use tcc to make embedded just-in-time compile/interpr


From: David Mertens
Subject: Re: [Tinycc-devel] Use tcc to make embedded just-in-time compile/interpreter
Date: Fri, 16 Dec 2011 08:29:55 -0600

Your quest is nearly complete already. Check out libtcc.h and the associated test file in the sources. :-)

The only issues I have found with such a scheme is that I have to create a new tccstate every time I want to compile a new function. New functions compiled with an old state appear to clobber old function pointers.

Keep me posted. I'm slowly working on creating a C jit for Perl, and I'll bet we could work together on something, if nothing more than improving the libtcc docs. :-)

David

On Dec 16, 2011 7:31 AM, "Benoit Gschwind" <address@hidden> wrote:
Hello,

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 */
cclose(c);


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
easily
- 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

_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

reply via email to

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