Skip to content

Commit

Permalink
Preview of Python 3.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed May 26, 2012
1 parent 3fb340c commit 50657fb
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 190 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BYTES = \
python_10 python_11 python_13 python_14 python_15 python_16 \
python_20 python_21 python_22 python_23 python_24 \
python_25 python_26 python_27 \
python_30 python_31 python_32
python_30 python_31 python_32 python_33

BYTE_OBJS = $(BYTES:%=out/%.o)
BYTE_SRCS = $(BYTES:%=bytes/%.cpp)
Expand Down
370 changes: 185 additions & 185 deletions PythonBytecode.txt

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DECLARE_PYTHON(2, 7)
DECLARE_PYTHON(3, 0)
DECLARE_PYTHON(3, 1)
DECLARE_PYTHON(3, 2)
DECLARE_PYTHON(3, 3)

const char* Pyc::OpcodeName(int opcode)
{
Expand All @@ -48,7 +49,7 @@ const char* Pyc::OpcodeName(int opcode)
"GET_ITER", "PRINT_ITEM_TO", "PRINT_NEWLINE_TO", "INPLACE_LSHIFT",
"INPLACE_RSHIFT", "INPLACE_AND", "INPLACE_XOR", "INPLACE_OR",
"WITH_CLEANUP", "IMPORT_STAR", "YIELD_VALUE", "LOAD_BUILD_CLASS",
"STORE_LOCALS", "POP_EXCEPT", "SET_ADD",
"STORE_LOCALS", "POP_EXCEPT", "SET_ADD", "YIELD_FROM",

"STORE_NAME", "DELETE_NAME", "UNPACK_TUPLE", "UNPACK_LIST", "UNPACK_ARG",
"STORE_ATTR", "DELETE_ATTR", "STORE_GLOBAL", "DELETE_GLOBAL",
Expand Down Expand Up @@ -108,6 +109,7 @@ int Pyc::ByteToOpcode(int maj, int min, int opcode)
case 0: return python_30_map(opcode);
case 1: return python_31_map(opcode);
case 2: return python_32_map(opcode);
case 3: return python_33_map(opcode);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum Opcode {
GET_ITER, PRINT_ITEM_TO, PRINT_NEWLINE_TO, INPLACE_LSHIFT,
INPLACE_RSHIFT, INPLACE_AND, INPLACE_XOR, INPLACE_OR, WITH_CLEANUP,
IMPORT_STAR, YIELD_VALUE, LOAD_BUILD_CLASS, STORE_LOCALS,
POP_EXCEPT, SET_ADD,
POP_EXCEPT, SET_ADD, YIELD_FROM,

/* Has parameter word */
PYC_HAVE_ARG,
Expand Down
2 changes: 1 addition & 1 deletion bytes/comp_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

maplist = [ 10, 11, 13, 14, 15, 16,
20, 21, 22, 23, 24, 25, 26, 27,
30, 31, 32 ]
30, 31, 32, 33 ]

for mapver in maplist:
infile = open('python_%d.map' % mapver, 'rt')
Expand Down
101 changes: 101 additions & 0 deletions bytes/python_33.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
1 POP_TOP
2 ROT_TWO
3 ROT_THREE
4 DUP_TOP
5 DUP_TOP_TWO
9 NOP
10 UNARY_POSITIVE
11 UNARY_NEGATIVE
12 UNARY_NOT
15 UNARY_INVERT
19 BINARY_POWER
20 BINARY_MULTIPLY
22 BINARY_MODULO
23 BINARY_ADD
24 BINARY_SUBTRACT
25 BINARY_SUBSCR
26 BINARY_FLOOR_DIVIDE
27 BINARY_TRUE_DIVIDE
28 INPLACE_FLOOR_DIVIDE
29 INPLACE_TRUE_DIVIDE
54 STORE_MAP
55 INPLACE_ADD
56 INPLACE_SUBTRACT
57 INPLACE_MULTIPLY
59 INPLACE_MODULO
60 STORE_SUBSCR
61 DELETE_SUBSCR
62 BINARY_LSHIFT
63 BINARY_RSHIFT
64 BINARY_AND
65 BINARY_XOR
66 BINARY_OR
67 INPLACE_POWER
68 GET_ITER
69 STORE_LOCALS
70 PRINT_EXPR
71 LOAD_BUILD_CLASS
72 YIELD_FROM
75 INPLACE_LSHIFT
76 INPLACE_RSHIFT
77 INPLACE_AND
78 INPLACE_XOR
79 INPLACE_OR
80 BREAK_LOOP
81 WITH_CLEANUP
83 RETURN_VALUE
84 IMPORT_STAR
86 YIELD_VALUE
87 POP_BLOCK
88 END_FINALLY
89 POP_EXCEPT
90 STORE_NAME_A
91 DELETE_NAME_A
92 UNPACK_SEQUENCE_A
93 FOR_ITER_A
94 UNPACK_EX_A
95 STORE_ATTR_A
96 DELETE_ATTR_A
97 STORE_GLOBAL_A
98 DELETE_GLOBAL_A
100 LOAD_CONST_A
101 LOAD_NAME_A
102 BUILD_TUPLE_A
103 BUILD_LIST_A
104 BUILD_SET_A
105 BUILD_MAP_A
106 LOAD_ATTR_A
107 COMPARE_OP_A
108 IMPORT_NAME_A
109 IMPORT_FROM_A
110 JUMP_FORWARD_A
111 JUMP_IF_FALSE_OR_POP_A
112 JUMP_IF_TRUE_OR_POP_A
113 JUMP_ABSOLUTE_A
114 POP_JUMP_IF_FALSE_A
115 POP_JUMP_IF_TRUE_A
116 LOAD_GLOBAL_A
119 CONTINUE_LOOP_A
120 SETUP_LOOP_A
121 SETUP_EXCEPT_A
122 SETUP_FINALLY_A
124 LOAD_FAST_A
125 STORE_FAST_A
126 DELETE_FAST_A
130 RAISE_VARARGS_A
131 CALL_FUNCTION_A
132 MAKE_FUNCTION_A
133 BUILD_SLICE_A
134 MAKE_CLOSURE_A
135 LOAD_CLOSURE_A
136 LOAD_DEREF_A
137 STORE_DEREF_A
138 DELETE_DEREF_A
140 CALL_FUNCTION_VAR_A
141 CALL_FUNCTION_KW_A
142 CALL_FUNCTION_VAR_KW_A
143 SETUP_WITH_A
144 EXTENDED_ARG_A
145 LIST_APPEND_A
146 SET_ADD_A
147 MAP_ADD_A
9 changes: 9 additions & 0 deletions pyc_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ void PycModule::setVersion(unsigned int magic)
m_unicode = true;
break;

case MAGIC_3_3:
m_maj = 3;
m_min = 3;
m_unicode = true;
break;

/* Bad Magic detected */
default:
m_maj = -1;
Expand All @@ -137,6 +143,9 @@ void PycModule::loadFromFile(const char* filename)
}
in.get32(); // Timestamp -- who cares?

if (verCompare(3, 3) >= 0)
in.get32(); // Size parameter added in Python 3.3

m_code = LoadObject(&in, this).cast<PycCode>();
}

Expand Down
9 changes: 9 additions & 0 deletions pyc_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum PycMagic {
MAGIC_3_0 = 0x0A0D0C3A,
MAGIC_3_1 = 0x0A0D0C4E,
MAGIC_3_2 = 0x0A0D0C6C,
MAGIC_3_3 = 0x0A0D0C94,
};

#define PYC_VERSION(maj, min) MAGIC_##maj##_##min
Expand All @@ -37,6 +38,14 @@ class PycModule {

unsigned int majorVer() const { return m_maj; }
unsigned int minorVer() const { return m_min; }

int verCompare(int maj, int min) const
{
if (m_maj == maj)
return m_min - min;
return m_maj - maj;
}

bool isUnicode() const { return m_unicode; }

PycRef<PycCode> code() const { return m_code; }
Expand Down
2 changes: 1 addition & 1 deletion pyc_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PycRef<PycObject> CreateObject(int type)
return new PycSet(PycObject::TYPE_FROZENSET);
default:
fprintf(stderr, "CreateObject: Got unsupported type 0x%X\n", type);
return (PycObject*)0;
return Pyc_NULL;
}
}

Expand Down

0 comments on commit 50657fb

Please sign in to comment.