[pypy-dev] call_function

Ben.Young at risk.sungard.com Ben.Young at risk.sungard.com
Fri Dec 16 15:26:03 CET 2005


pypy-dev-bounces at codespeak.net wrote on 16/12/2005 14:23:56:

> Carl Friedrich Bolz <cfbolz at gmx.de> wrote on 16/12/2005 14:08:38:
> 
> > 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
> > (http://python.org/doc/2.4.2/lib/bytecodes.html):
> > 
> > CALL_FUNCTION    argc
> >      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.
> > 
> 
> Well, you always check the high byte is zero and then call down. It just 


Sorry, I meant "you could always check" here.

> seems like then fact that there are 4 fastcall "hacks" doesn't need to 
be 
> known at this level (as it is already known at the level below (i.e in 
the 
> space))
> 
> Thanks for the reply.

Cheers,
Ben

> 
> Cheers,
> Ben
> 
> > Cheers,
> > 
> > Carl Friedrich
> > 
> > 
> > 
> 
> _______________________________________________
> pypy-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-dev
> 
> 




More information about the Pypy-dev mailing list