Are the CALL_FUNCTION_* opcodes ever used?

P

Peter Otten

Fabiano said:
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?
.... func(*args)
.... func(**kw)
.... func(*args, **kw)
.... 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
 
F

Fabiano Sidler

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
 
F

Fabiano Sidler

... 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top