Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104897
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Encapsulation in Python |
| Date | Tue, 15 Mar 2016 12:23:34 +1100 |
| Lines | 43 |
| Message-ID | <mailman.148.1458005017.12893.python-list@python.org> (permalink) |
| References | <56E17985.7060002@benmezger.nl> <mailman.139.1457623672.15725.python-list@python.org> <6984dafc-fffd-4d46-a173-421bb5c142d2@googlegroups.com> <mailman.25.1457711277.26429.python-list@python.org> <4ddc3696-3f71-4598-98a6-929267f51fb9@googlegroups.com> <mailman.42.1457801128.12893.python-list@python.org> <56e53cd3$0$1586$c3e8da3$5496439d@news.astraweb.com> <1376c684-2e7f-417a-9683-e47789f019fe@googlegroups.com> <CALwzidm0PPzMBNYFyxhAv0Y3-2dLRA0J8wbcD6Qj5tGYf37SAQ@mail.gmail.com> <mailman.132.1457990663.12893.python-list@python.org> <nc7chi$lbu$1@dont-email.me> <mailman.133.1457994074.12893.python-list@python.org> <nc7ef9$sgf$1@dont-email.me> <mailman.137.1457997645.12893.python-list@python.org> <nc7it9$ejq$1@dont-email.me> <mailman.140.1458001784.12893.python-list@python.org> <nc7n8k$qru$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de /axgPW0hdv666Z3/1RxsawfXLR+d/SKvxSuj+6E3FV6g== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'else:': 0.03; 'elif': 0.04; 'subject:Python': 0.05; 'cpython': 0.05; 'expressions': 0.07; 'repeated': 0.07; 'cc:addr:python-list': 0.09; 'here?': 0.09; 'lookup': 0.09; 'index': 0.13; "(i'm": 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'opcode': 0.16; 'provision': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'not,': 0.22; 'amounts': 0.22; "python's": 0.23; 'this:': 0.23; 'written': 0.24; 'header:In- Reply-To:1': 0.24; 'testing': 0.25; "i've": 0.25; 'switch': 0.27; 'message-id:@mail.gmail.com': 0.27; 'sequence': 0.27; 'values': 0.28; 'dictionary': 0.29; 'hash': 0.29; 'received:209.85.213.174': 0.29; 'that.': 0.30; 'work.': 0.30; 'code': 0.30; '15,': 0.30; 'branch': 0.30; 'anyone': 0.32; 'implement': 0.32; 'table': 0.32; 'getting': 0.33; 'jump': 0.33; 'tue,': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'label': 0.35; 'maps': 0.35; 'but': 0.36; 'needed': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'or,': 0.38; 'does': 0.39; 'total': 0.62; 'details': 0.62; 'more': 0.63; 'within': 0.64; 'mar': 0.65; "they're": 0.66; 'obvious': 0.76; 'chrisa': 0.84; 'yourself...': 0.84; 'to:none': 0.91; 'subject:skip:E 10': 0.96 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=HFyI5PCDfGROo7f1DXJxVFF0lEw0geuA0UFUGzlgjjg=; b=k5DRSWOVxoaq+JA0qwEb0P5QyGn2JrxPIYe0Xd+nV88nXRqWbtNz59HhLzn0v6aEkR jbXNAAjjBMYKkYcwqdLzTLhgSTPOaRkCSRqqR7iI13VBcEm5jW16N5UdWyDmaCtY2qy3 TlnYjv/o601yo2aaHFVpGPTin81DcVBH6297CVHs1qd8eposfaWQmJ7J7a3gNLP4muNi masV55V0hOK0t2nlepSksEbcJRQ7QjxvXSAnQDVbBfjNnkbgZYqeTHc6y2TQ53yVvLA7 /UKkt/dDyrQtBszcI9AMYUpaO9ol+zaQc5Yy8IAX0Cc+hIiYl9wUW+mNGkFpDwVYbwMG DP3w== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=HFyI5PCDfGROo7f1DXJxVFF0lEw0geuA0UFUGzlgjjg=; b=hQoRit130qJRuGaO/5CHKZv9awoHK3PNMNBsu4qZj4eCHYwth7L3DNVnuniPV2/95/ 5SbvXfDLZl5ut4CMpoKfiVQ1+25DxoYJHEQMruO3QyLeN8BWlSl6cTacN7CbS/JKw4r1 G5uCCVz928Xx0i3cApL9KyEB3AtO9wpmohZIWxpUWIMPvh4hK4AqVZ3Q4XhSrfK4WRnA 0TjXsZIqC3OTNURvVp3hYdHnaby/hRk2qEOctW7PPWCLQiCotW9ggqB+PbWDLmVkasR7 HILz7D6fV3vy9rPzHIWuOCuAO9Y91ibLNcIUPW7Zvou11GD04bh1jjic0eX+FRgGmlwQ 8uGw== |
| X-Gm-Message-State | AD7BkJLYrrvuEVvLhChk/fEd1cse4agsLUI5RU1SNQX95pRCloEqaNmyqyYzW9G1qjCUSdRfxZniLErPtwzv0Q== |
| X-Received | by 10.50.43.168 with SMTP id x8mr21171574igl.92.1458005014492; Mon, 14 Mar 2016 18:23:34 -0700 (PDT) |
| In-Reply-To | <nc7n8k$qru$1@dont-email.me> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:104897 |
Show key headers only | View raw
On Tue, Mar 15, 2016 at 12:10 PM, BartC <bc@freeuk.com> wrote:
> The one-byte-code switch works when all case expressions are known at
> compile-time. It makes use of a jump-table within the byte-code.
>
> The total sequence will be more than one byte-code, typically:
>
> LOAD_FAST The index
> SWITCH Jump to the right label
> ....
> L5: One of multiple labels
> ... Deal with the code in this branch
> JUMP_ABSOLUTE Break out of the switch
>
> ... Provision is needed for the jump-table
>
> But only one is needed for testing and dispatch. Now I've sketched it out,
> perhaps you can fill in the details for yourself... (I'm not getting
> involved in CPython development.)
Let's be fair here; anyone can make a single byte-code that does
arbitrary amounts of work. (Consider Python's CALL_FUNCTION or the old
PRINT_ITEM opcode.) How much work does SWITCH do here? Does the jump
table require that the possible case values be compact? If they're
not, how does it operate?
In Python, the most obvious way to do the repeated comparisons would
be a hash lookup. The SWITCH opcode could take a dictionary that maps
values to jump targets, with an 'else' target if the lookup fails, and
jump to that. It would actually be possible to implement this entirely
in an optimizer, with code written like this:
if x == 'asdf':
...
elif x == 'qwer':
...
elif x in ('zxcv', '1234'):
...
else:
...
Or, of course, it could get its own syntax.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Encapsulation in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-10 08:27 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-10 16:45 -0800
Re: Encapsulation in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-11 08:47 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-11 18:39 -0800
Re: Encapsulation in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-12 09:44 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-12 19:11 -0800
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-13 21:11 +1100
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 10:32 -0700
Re: Encapsulation in Python Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-14 15:09 -0600
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 21:23 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-14 22:07 +0000
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 22:20 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-14 22:40 +0000
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 23:19 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-14 23:56 +0000
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:12 +1100
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-15 00:54 +0000
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:58 +1100
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-15 01:22 +0000
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 13:02 +1100
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 00:28 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-15 01:10 +0000
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 12:23 +1100
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 04:41 +0000
Re: Encapsulation in Python rurpy@yahoo.com - 2016-03-14 17:17 -0700
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:25 +1100
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:06 +1100
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 13:14 +1100
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:40 +1100
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 21:08 -0700
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 00:47 +0000
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:46 +1100
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:56 +1100
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 04:36 +0000
Re: Encapsulation in Python Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:01 +1100
Re: Encapsulation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 04:45 +0000
Re: Encapsulation in Python Christian Gollwitzer <auriocus@gmx.de> - 2016-03-15 22:02 +0100
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-16 00:39 +0000
Re: Encapsulation in Python BartC <bc@freeuk.com> - 2016-03-16 22:58 +0000
Re: Encapsulation in Python sohcahtoa82@gmail.com - 2016-03-14 11:11 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 23:09 -0700
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-11 18:56 -0800
Re: Encapsulation in Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-12 13:52 +1300
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-12 08:49 -0800
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-13 08:10 +1100
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-12 19:36 -0800
Re: Encapsulation in Python Chris Angelico <rosuav@gmail.com> - 2016-03-13 15:05 +1100
Re: Encapsulation in Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-14 12:35 +1300
Re: Encapsulation in Python Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 15:55 -0700
csiph-web