Beyond Bytecode - A Wordcode-based Python
嚜濁eyond Bytecode:
a Wordcode-based Python
Cesare Di Mauro
A-Tono s.r.l.
PyCon Tre 2009 每 Firenze (Florence)
May 9, 2009
Cesare Di Mauro 每 PyCon Tre 2009
Beyond Bytecode: a Wordcode-based Python
May 9, 2009
1 / 30
From Python source to Bytecode
char
Control Flow
Graph
Source
pgen.c
Parse Tree
ast.c
adsl
Abstract
Syntax Tree
Cesare Di Mauro 每 PyCon Tre 2009
compile.c
compile.c
node
instr
Bytecode
char
peephole.c
Bytecode
Beyond Bytecode: a Wordcode-based Python
char
May 9, 2009
2 / 30
About Python bytecodes
Bytecode stream: an opcodes mixture.
? 1 byte (no parameter)
? 3 bytes (16 bits parameter value)
? 6 bytes (32 bits parameter value)
Byte order is little-endian (low byte first).
23
BINARY_ADD
Single byte opcode
Cesare Di Mauro 每 PyCon Tre 2009
100
1
2
LOAD_CONST
513
(?spam?)
Multi byte opcode
Beyond Bytecode: a Wordcode-based Python
May 9, 2009
3 / 30
An example: Fibonacci?s sequence
2
def fib(n):
0 LOAD_FAST
0 (n)
3 LOAD_CONST
1 (1)
6 COMPARE_OP
1 (
else:
5
return fib(n - 2) + fib(n 每 1)
17 POP_TOP
18 LOAD_GLOBAL
0 (fib)
21 LOAD_FAST
0 (n)
24 LOAD_CONST
2 (2)
27 BINARY_SUBTRACT
With Python 2.6.1 we have:
? 22 opcodes / instructions
? 50 bytes space needed
28 CALL_FUNCTION
1
31 LOAD_GLOBAL
0 (fib)
34 LOAD_FAST
0 (n)
37 LOAD_CONST
1 (1)
40 BINARY_SUBTRACT
41 CALL_FUNCTION
1
44 BINARY_ADD
45 RETURN_VALUE
46 LOAD_CONST
0 (None)
49 RETURN_VALUE
Cesare Di Mauro 每 PyCon Tre 2009
Beyond Bytecode: a Wordcode-based Python
May 9, 2009
4 / 30
A look at the VM (ceval.c) main loop
for (;;) {
opcode = NEXTOP();
Branch
if (HAS_ARG(opcode))
misprediction
oparg = NEXTARG();
switch(opcode) {
case BINARY_ADD:
// Code here
}
CPU
pipeline
flush &
reload
}
Cesare Di Mauro 每 PyCon Tre 2009
Beyond Bytecode: a Wordcode-based Python
May 9, 2009
5 / 30
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- bits and bytes
- beyond bytecode a wordcode based python
- lecture 8 aes the advanced encryption standard lecture
- smbus2 documentation
- steganography hiding data in plain sight
- part 5 the python language
- introduction to assembly and risc v
- data structure and algorithm in python array based sequences
- introduction to image processing and python pixel
- bit byte and binary
Related searches
- a classifier for the snp based inference
- is beyond finance a scam
- marketing a service based business
- a team based organizational structure has a
- create a matrix in python using for
- comptia a performance based practice
- what is a computer based information system
- python pandas add column based on condition
- beyond a reasonable doubt standard
- bytecode to text
- replace a value in python list
- python range based for loop