|[Newbie Alert] How can I interface an interpreter to C code? firstname.lastname@example.org (Ravi Mohan) (2005-12-23)|
|Re: How can I interface an interpreter to C code? email@example.com (Eric) (2005-12-24)|
|Date:||24 Dec 2005 15:36:32 -0500|
When you're running in a VM and you want to call compiled C code, this
is called a native interface. In the Java world it's called JNI, and in
the .NET world it's called Platform Invoke (p-invoke).
As John said, you basically need to create a virtual instruction that
can call a routine at a specified address. The need to know the address
is a fundamental requirement, of course.
On Windows we typically call into native DLLs. The virtual machine
could be given the job of loading the DLL, and then it can query the
addresses of the public functions.
In the embedded world, we typically compile code to run in a fixed
memory range, and we use a vector table to create standard entry points
the VM can call into.
One of the key requirements is to pass parameters both ways. This
requires the VM to know the particular calling convention used by the C
All this is a little harder if you have a managed memory environment in
your VM (like the JVM or .NET CLR). It requires a lot of thought on how
to handle pointers in this kind of situation since it's considered
"unsafe" to access managed memory areas with a pointer. It's not
impossible to implement, but you need to be aware of the security
Return to the
Search the comp.compilers archives again.