[pypy-dev] call_function

Carl Friedrich Bolz cfbolz at gmx.de
Fri Dec 16 15:08:38 CET 2005

Hi Ben!

> I was having a quick look at how function calling is implemented in PyPy 
> and I can't seem to understand why the CALL_FUNCTION opcode and the space 
> call_function method seem to do duplicate things. 
> Whay doesn't CALL_FUNCTION just pop oparg items off the stack and call the 
> space call_function? It doesn't seem like the functionality would be any 
> different as the varargs cases are handled differently anyway?

Well, the way we handle function arguments is definitively a bit
convoluted. But for this case what you plan would not suffice: the oparg
argument to the CALL_FUNCTION bytecode is not just the number of
arguments of that function. Quoting from the CPython docs

     Calls a function. The low byte of argc indicates the number of
positional parameters, the high byte the number of keyword parameters.
On the stack, the opcode finds the keyword parameters first. For each
keyword argument, the value is on top of the key. Below the keyword
parameters, the positional parameters are on the stack, with the
right-most parameter on top. Below the parameters, the function object
to call is on the stack.

That is why the fast paths in our CALL_FUNCTION implementation work: the
test oparg == 1 tests that the function has exactly one positional and
no keyword argument.


Carl Friedrich

More information about the Pypy-dev mailing list