[LLVMdev] Scheme on LLVM IR

craven at gmx.net craven at gmx.net
Wed Aug 7 03:10:00 PDT 2013


> Can't you handle this entirely in the front-end? Just decide by fiat
> that all of your scheme functions will take an extra (hidden to the
> Scheme users) parameter saying how many args they were given. That's
> how C++ deals with the implicit "this" parameter for class methods.

> Then you could either use varargs or bitcast your functions to a
> reasonable type when used.

Thanks for pointing out the obvious! This never crossed my mind, but it
should work well! I'll try to implement this, and see where it leads me
:)

One especially problematic function seems to be APPLY. It takes a
function and a list of values as parameters, and applies the function to
the values [as in (apply + '(1 2 3)) -> (+ 1 2 3)]. So if varargs adhere
to the standard ABI, I could just cast the function to varargs
parameters, then call it, and (with the arity checking you described
above), things should work correctly?

>> Varargs seem a bad match, as everything is passed on the stack, not in
>> registers, and no count is kept of the actual number of arguments.
>
> Is that on x86-32 Windows? In almost all other cases varargs are
> passed in a manner compatible with non-variadic functions -- there's
> just too much bad software out there that relies on this (it was
> allowed in the bad old K&R C days) so ABIs are designed with that in
> mind.

That's what I tested, I'll try other targets too, to see what code they
generate.

Thanks for the swift help!

Peter



More information about the llvm-dev mailing list