473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 1237
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Lyle Fairfield | last post by:
I was just showing a youngster some MS-SQL stuff on a remote Internet enabled shared server. He logged in with my User Name and Password. I was busy for a minute. Then he said, "This (stored...
10
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some...
2
by: Striped | last post by:
Is there any tool to convert source code, e.g. of a C# method, to opcodes being used in System.Reflection.Emit? It's a real pain to do that manually, especially for big pieces of code. public...
5
by: Toby Webb | last post by:
How can I convert the following code (from MSDN) to work in VB.NET (the opcodes are raising errors): Public Enum WLAN_INTF_OPCODE wlan_intf_opcode_autoconf_start = 0x000000000...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.