[LLVMdev] Using LLVM for a dynamically typed language

Evan Jones ejones at uwaterloo.ca
Thu Apr 21 08:02:36 PDT 2005


On Thu, 2005-21-04 at 10:28 -0400, Vyacheslav Akhmechet wrote:
> The problem is that I do not know the type of a target function at
> compile time. If you consider my code example, I don't know the type
> of 'i' until runtime (in fact, I can't even know a possible range of
> types 'i' may assume).

I don't think I properly understand what the issue is here. For my
perspective, if you can figure out the type of 'i' at runtime, you
either have to:

a) Make all functions the same type. For example, make them all return
void, take a vector of parameters as the first argument, and a vector
for return values as the second argument.

b) Call the appropriate LLVM functions to emit the code for the cast at
runtime.

I don't see how this is a specific challenge with LLVM. It seems to me
that this is a challenge that you will encounter when implementing a
dynamic language in *any* low-level language. I would encourage you to
prototype something in C, and then figure out how to translate that to
use LLVM. There are lots of dynamic languages you can use as examples.
Python would be appropriate here, since it has function objects. There
are also likely to be some textbooks that discuss these sorts of
implementation challenges. As compilers are not my research area, I
can't recommend any.

Good luck,

Evan Jones





More information about the llvm-dev mailing list