469,366 Members | 2,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Are the CALL_FUNCTION_* opcodes ever used?

Hi folks!

Studying python byte code I encountered an interesting issue: there is no
matter, which one of the following function calls I compile:

1: func('foo','bar',foo='bar')
2: func('foobar')
3: func(foo='bar')

The compiler always uses the simple CALL_FUNCTION for all of the source
examples above. While this is fine for me (since the labels in Python/ceval.c
for the other 3 opcodes lead to the same code anyway), I'm curious to know
if there is a case where the compiler really uses the CALL_FUNCTION_* opcodes
or if we could silently remove these opcodes without breaking anything?

Greetings,
Fips
Sep 21 '06 #1
2 1117
Fabiano Sidler wrote:
Studying python byte code I encountered an interesting issue: there is no
matter, which one of the following function calls I compile:

1: func('foo','bar',foo='bar')
2: func('foobar')
3: func(foo='bar')

The compiler always uses the simple CALL_FUNCTION for all of the source
examples above. While this is fine for me (since the labels in
Python/ceval.c for the other 3 opcodes lead to the same code anyway), I'm
curious to know if there is a case where the compiler really uses the
CALL_FUNCTION_* opcodes or if we could silently remove these opcodes
without breaking anything?
>>def test():
.... func(*args)
.... func(**kw)
.... func(*args, **kw)
....
>>dis.dis(test)
2 0 LOAD_GLOBAL 0 (func)
3 LOAD_GLOBAL 1 (args)
6 CALL_FUNCTION_VAR 0
9 POP_TOP

3 10 LOAD_GLOBAL 0 (func)
13 LOAD_GLOBAL 2 (kw)
16 CALL_FUNCTION_KW 0
19 POP_TOP

4 20 LOAD_GLOBAL 0 (func)
23 LOAD_GLOBAL 1 (args)
26 LOAD_GLOBAL 2 (kw)
29 CALL_FUNCTION_VAR_KW 0
32 POP_TOP
33 LOAD_CONST 0 (None)
36 RETURN_VALUE

So there.

Peter
Sep 21 '06 #2
On Thursday 21 September 2006 22:36, Peter Otten wrote:
>def test():

... func(*args)
... func(**kw)
... func(*args, **kw)
Oh, I didn't know the possibility of using the *args and **kwargs semantics
at function call. Thank you for revealing them to me! :)
Now it is also obvious how the CALL_FUNCTION_* opcodes are used.

Greetings,
Fips
Sep 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.