OILS / opy / gold / obj_literals.py View on Github | oilshell.org

26 lines, 7 significant
1#!/usr/bin/env python2
2"""
3obj_literals.py
4"""
5from __future__ import print_function
6
7# Hm in OPy, ALL of these do a bunch of LOAD_CONST, and then BUILD_LIST,
8# BUILD_TUPLE, BUILD_SET. dict is done with BUILD_MAP and STORE_SUBSCR.
9
10# In CPython:
11
12# - the tuple is stored as a whole constant.
13# - A STORE_MAP bytecode is used for the dictionary.
14
15# (CPython tested with ../bin/opyc dis gold/obj_literals.pyc, after manually
16# importing this file.)
17
18def f():
19 mylist = [1, 2, 3] # 3 LOAD_CONST then BUILD_LIST
20
21 mytuple = ('str', 42)
22
23 f(('a', 3))
24
25 d = {'key': 3}
26 myset = {1, 2}