Are the CALL_FUNCTION_* opcodes ever used?

Discussion in 'Python' started by Peter Otten, Sep 21, 2006.

  1. Peter Otten

    Peter Otten Guest

    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
    Peter Otten, Sep 21, 2006
    #1
    1. Advertising

  2. 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
    Fabiano Sidler, Sep 22, 2006
    #2
    1. Advertising

  3. 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
    Fabiano Sidler, Sep 22, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Albretch
    Replies:
    4
    Views:
    881
    Larry Barowski
    Oct 2, 2004
  2. Sreejith K

    Changing Python Opcodes

    Sreejith K, Aug 18, 2009, in forum: Python
    Replies:
    5
    Views:
    984
  3. Jason
    Replies:
    0
    Views:
    179
    Jason
    Jul 6, 2004
  4. Canny
    Replies:
    2
    Views:
    94
    Dr J R Stockton
    Jul 2, 2009
  5. Canny
    Replies:
    0
    Views:
    86
    Canny
    Jul 2, 2009
Loading...

Share This Page