[LLVMdev] Using LLVM for a dynamically typed language

Vyacheslav Akhmechet coffeemug at gmail.com
Thu Apr 21 06:31:59 PDT 2005


I recently ran into the following problem.

I'm prototyping a compiler for a dynamically typed language in which
functions are first class objects. Assuming I have something like
this:

if(rand() > 5)
  i = define(x, y, z) { return x + y + z; }
else
  i = define(x, y) { return x + y; }

At this point I cannot know the type of 'i' at compile time. At
runtime 'i' is a structure that contains a type and a function
pointer. What I can't figure out is how to cast my llvm function 
pointer to an appropriate function type. I cannot know until runtime
what the type will be. Naturally I can add runtime code that will do
all appropriate checks (number of parameters, etc.) but how do I do
the actual cast?

I hope I'm being clear.

Thanks,
- Slava.




More information about the llvm-dev mailing list