Vyacheslav Akhmechet
2005-Apr-21 15:34 UTC
[LLVMdev] Using LLVM for a dynamically typed language
> 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.This is something I was considering. I guess I'll end up going with this option.> 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 disagree. If I could push a bunch of arguments on a stack (or specify a list of arguments, etc.) and just use a "call" instruction with a pointer to a memory address I wouldn't run into this problem. This is a specific challenge with LLVM because it is strictly typed.
On Thu, 2005-21-04 at 11:34 -0400, Vyacheslav Akhmechet wrote:> I disagree. If I could push a bunch of arguments on a stack (or > specify a list of arguments, etc.) and just use a "call" instruction > with a pointer to a memory address I wouldn't run into this problem. > This is a specific challenge with LLVM because it is strictly typed.Ah! Right. You can't manually construct a function call on the stack with LLVM. However, an alternative worth considering would be to use varargs functions. This would basically compile to native code that just stuffs a bunch of things on the stack. As in your example, the function itself knows the number and type of parameters that are expected. Before executing the "body" of the function, it can verify that things are being passed as expected and raise an exception if the are not. This is basically similar to Chris's suggestion of using a structure to pass the arguments, except you don't actually need to construct the structure itself. Evan Jones
On Thu, 21 Apr 2005, Evan Jones wrote:> On Thu, 2005-21-04 at 11:34 -0400, Vyacheslav Akhmechet wrote: >> I disagree. If I could push a bunch of arguments on a stack (or >> specify a list of arguments, etc.) and just use a "call" instruction >> with a pointer to a memory address I wouldn't run into this problem. >> This is a specific challenge with LLVM because it is strictly typed. > > Ah! Right. You can't manually construct a function call on the stack > with LLVM. However, an alternative worth considering would be to use > varargs functions. This would basically compile to native code that just > stuffs a bunch of things on the stack.I strongly recommend avoiding varargs functions if possible. It would be better to pass an explicit list/array of parameters instead. The optimizer is severely hobbled for varargs functions, but it does a good job of ripping appart simple arrays and structures.> As in your example, the function itself knows the number and type of > parameters that are expected. Before executing the "body" of the > function, it can verify that things are being passed as expected and > raise an exception if the are not.I agree. The structure/array passed in should indicate how many params there are and the callee should verify things are happy before continuing. Alternatively, instead of putting the # args in the array, you could pass it in as an explicit extra argument, which would help out the optimizer even more. -Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
Apparently Analagous Threads
- [LLVMdev] Using LLVM for a dynamically typed language
- [LLVMdev] Using LLVM for a dynamically typed language
- [LLVMdev] Using LLVM for a dynamically typed language
- [LLVMdev] Using LLVM for a dynamically typed language
- [LLVMdev] GCC assembler rejects native code generated by LLVM