[LLVMdev] Using LLVM for a dynamically typed language

Evan Jones ejones at uwaterloo.ca
Thu Apr 21 08:12:50 PDT 2005

On Thu, 2005-21-04 at 18:51 +0400, Vladimir Prus wrote:
> However, I never seen any implementation details 
> so don't know how dynamic features are dealt with. 

I am not an expert about this, but I have done a bit of reading about
IronPython and Jython. As far as I am aware of, these issues are dealt
with in the same way that they are handled in CPython. Basically, when
they compile Python code they just emit the sequence of function calls
that the interpreter would make. Thus, doing something like this:

pyobject.foo += 1

Turns into something like this:

PythonObject temp = pyobject.get_attr( 'foo' );
Array parameters = [ temp, new PythonInteger( 1 ) ];
PythonObject addMethod = temp.get_attr( '__add__' );
PythonObject result = addMethod.call( parameters );
pyobject.set_attr( 'foo', result );

This ends up executing much faster than having to go around an
interpreter loop multiple times. You could actually use the same
approach to compile Python to native code.

Evan Jones

More information about the llvm-dev mailing list