[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Loop until condition is true
From:       Konstantin Veretennicov <kveretennicov () gmail ! com>
Date:       2005-06-21 14:28:32
Message-ID: 4660fe3005062107282e3ffcc9 () mail ! gmail ! com
[Download RAW message or body]

On 6/21/05, Magnus Lycka <lycka@carmen.se> wrote:
> I don't know anything about the Python compiler internals,
> but it doesn't seem very hard to identify simple literals following
> while and if, and to skip the runtime test. (Perhaps it's done
> already?)

True doesn't seem to be a literal, it is looked up by name and can be
rebound to, say, 0 anytime:

>>> import dis
>>> o = compile('while True: pass', '<string>', 'exec')
>>> dis.dis(o)
  1           0 SETUP_LOOP              12 (to 15)
        >>    3 LOAD_NAME                0 (True)
              6 JUMP_IF_FALSE            4 (to 13)
              9 POP_TOP
             10 JUMP_ABSOLUTE            3
             ...

OTOH,

>>> p = compile('while 1: pass', '<string>', 'exec')
>>> dis.dis(p)
  1           0 SETUP_LOOP               5 (to 8)
        >>    3 JUMP_ABSOLUTE            3
             ...

- kv
-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic