SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
A Peek into Python’s
Metaclass and Bytecode
as a Smalltalk User
Koan-Sin Tan
freedom_at_computer.org
COSCUP 2015, Taipei
why this topic
• ‘I was only vaguely aware of Smalltalk at the time; I remember being surprised
by its use of metaclasses (which is quite different from that in Python or
Ruby!) when I read about them much later. Smalltalk's bytecode was a bigger
influence of Python's bytecode though. I'd read about it in a book by Adele
Goldberg and others, I believe "Smalltalk-80: The Language and its
Implementation”’ [1]
• And, I had a talk comparing Ruby’s metaclass and byte code to Smalltalk’s in
the end of 2012 [2]
• google “smalltalk and ruby bytecode”
[1] http://python-history.blogspot.com/2013/10/origin-of-metaclasses-in-
python.html
[2] http://www.slideshare.net/kstan2/smalltalk-and-ruby-20121208-15542185
what won’t be discussed
• anything beyond simple metaclass and bytecode
comparisons
• So, no inline cache if you was in the SpiderMonkey talk
yesterday. Yes, I know inline cache was for Smalltalk-80. If
you want to know how inline cache is used in Smalltalk,
read an excellent article [1]
• And no other stuff in object model (whatever object model
means to you)
[1] http://www.mirandabanda.org/cogblog/2011/03/01/build-
me-a-jit-as-fast-as-you-can/
http://www.world.st/learn/books
who am I
• Learnt to write program on MPF-II
• Used to be a programming language junkie
• Learnt a bit Smalltalk during early '90s, use it on
and off
• Recent interest in ST-80 because of Scratch and
BYOB/SNAP
• Knew little about Python
the first smalltalk-80 I used is on Sun’s SunView, image
from Wikipedia
http://squeak.org
http://pharo.org
Two Popular Open Source Smalltalk Systems
Scratch was written in Smalltalk
8
http://news.softpedia.com/images/reviews/large/
Scratch_Large_001.png
What I knew about python
• It’s a popular scripting language
• My classmate told me about Python in ’94 or ’95
• IPython notebook: using python and R to share
notes
• And of course, Python is more than Smalltalk-80
share my understanding of python metaclass as
bytecode as a common programmer
Quick Overview of ST-80
• Object-Oriented
Programming
• OO GUI environment,
IDE
• stack VM, bytecode
• Lambda, functional
language, block
• Message passing
• Design Pattern:
• if you read the GoF
book, you ran into
lots of Smalltalk
patterns before
• Learning/educational
• Logo and the dream
of Dynabook
Metaclass
Metaclass in ST-80
• From "purple book", Chap 16
1. Every class is ultimately a subclass of class Object, except for Object itself, which
has no superclass. In particular, Class is a subclass of ClassDescription, which is
a subclass of Behavior which is a subclass of Object
2. Every object is an instance of a class
3. Every class is an instance of a metaclass
4. All metaclasses are subclasses of Class
5. Every metaclass is an instance of Metaclass
6. The method of Class and it superclasses support the behavior common to all
objects that are classes
7. The methods of instances of Metaclass add the behavior specific to particular
classes
Smalltalk Object Model
•10 factorial --> 3628800
•10 factorial class --> SmallInteger
•SmallInteger superclass --> Integer
•Integer	superclass	--> Number	
•Number	superclass	--> Magnitude	
•Magnitude	superclass	--> Object	
•Object	superclass	-->	ProtoObject	
•ProtoObject	superclass	-->	nil
14
• 10 factorial class allSuperclasses --> an
OrderedCollection(Integer Number Magnitude
Object ProtoObject)
Python int
print(type(1))
<class 'int'>
print(type(1).__base__)
<class 'object'>
print(type(1).__base__.__base__)
None
print(type(1).__mro__)
(<class 'int'>, <class ‘object'>)
• So int, then object, no
hierarchy for numbers. How
about container types, e.g.,
set and dict? NO!
• Fortunately, there is another
path since python3000(?)
• There is PEP 3119 “Abstract Base
Classes” (ABC) and its companion
PEP 3141. So, there are ABCs for
numbers in module numbers and
collections module collections 
numbers.Integral.__base__
<class 'numbers.Rational'>
numbers.Integral.__base__.__base__
<class 'numbers.Real'>
numbers.Integral.__base__.__base__.__base__
<class 'numbers.Complex'>
numbers.Integral.__base__.__base__.__base__.__base__
<class 'numbers.Number'>
numbers.Integral.__base__.__base__.__base__.__base__.__
base__
<class ‘object'>
numbers.Integral.__mro__
(<class 'numbers.Integral'>, <class
'numbers.Rational'>, <class 'numbers.Real'>, <class
'numbers.Complex'>, <class 'numbers.Number'>, <class
'object'>)
https://docs.python.org/3/reference/datamodel.html
Number
Complex
Real
Integral
10
Rational
object
Key
instance-of
a class named Metaclass
SmallInteger	class	-->	SmallInteger	class	
Integer	class	-->	Integer	class	
Number	class	-->	Number	class	
Magnitude	class	-->	Magnitude	class	
Object	class	-->	Object	class	
ProtoObject	class	-->	ProtoObject	class
SmallInteger class superclass --> Integer class

Integer class superclass --> Number class

Number class superclass --> Magnitude class

Magnitude class superclass --> Object class

Object class superclass --> ProtoObject class

ProtoObject class superclass --> Class
Class class --> Class class

Class class class --> Metaclass

Metaclass class --> Metaclass class

Metaclass class class --> Metaclass
Object
Magnitude
Number
Object class
Magnitude class
Number class
Key
instance-of
Integer class
SmallInteger SmallInteger class
10
Integer
ProtoObject ProtoObject class
figures modified from “Pharo by Example”
18
Object
Magnitude
Number
Object class
Magnitude class
Number class
Key
instance-of
Integer class
SmallInteger SmallInteger class
10
Integer
ProtoObject ProtoObject class
Class
Class class
Metaclass
Metaclass class
19
Class class class --> Metaclass

Metaclass superclass --> ClassDescription

ClassDescription superclass --> Behavior

Behavior superclass --> Object



Class class superclass --> ClassDescription class

ClassDescription class superclass --> Behavior class

Behavior class superclass --> Object class
20
Object
Magnitude
Number
Object class
Magnitude class
Number class
Key
instance-of
Integer class
SmallInteger
SmallInteger class
10
Integer
ProtoObject
ProtoObject class
Class
Class class
Metaclass
Metaclass class
ClassDescription
Behavior
ClassDescription class
Behavior class
21
from “PBE”
Python metaclass
type(1).__class__
<class ‘type'>
type(1).__class__.__class_
<class ‘type’>
numbers.Integral.__class__
<class ‘abc.ABC’>
numbers.Rationl.__class__
<class ‘abc.ABC’>
abc.ABC.__class__
<class ‘type’>
————————————————————————————————
import dis
def testClass():
class Foo:
def foo(self, a, b):
return a + b
bar = Foo()
bar.foo(2+3)
dis.dis(testClass)
3 0 LOAD_BUILD_CLASS
1 LOAD_CONST 1 (<code object
Foo at 0x1101aee40, file "<ipython-
input-37-12f9deff1239>", line 3>)
4 LOAD_CONST 2 ('Foo')
7 MAKE_FUNCTION 0
10 LOAD_CONST 2 ('Foo')
13 CALL_FUNCTION 2 (2 positional,
0 keyword pair)
16 STORE_FAST 0 (Foo)
6 19 LOAD_FAST 0 (Foo)
22 CALL_FUNCTION 0 (0 positional,
0 keyword pair)
25 STORE_FAST 1 (bar)
7 28 LOAD_FAST 1 (bar)
31 LOAD_ATTR 0 (foo)
34 LOAD_CONST 5 (5)
37 CALL_FUNCTION 1 (1 positional,
0 keyword pair)
40 POP_TOP
41 LOAD_CONST 0 (None)
44 RETURN_VALUE
Python metaclass
• LOAD_BUILD_CLASS:
LOAD_BUILD_CLASS¶
Pushes builtins.__build_class__() onto the
stack. It is later called by CALL_FUNCTION to
construct a class [1]
• builtins.__build_class__
static PyMethodDef builtin_methods[] = {
{"__build_class__", (PyCFunction)builtin___build_class__,
METH_VARARGS | METH_KEYWORDS, build_class_doc},
{"__import__", (PyCFunction)builtin___import__,
METH_VARARGS | METH_KEYWORDS, import_doc},
{"abs", builtin_abs, METH_O, abs_doc},
[1] https://docs.python.org/3/
library/dis.html
• builtin_build_class__
• if no specific metaclass was
given and there no special
metaclass in base classes of a
class, the default metaclass is
the ‘type’
• BTW, as far as I can tell there are
some classes have non-type
metaclasses in standard Python
distribution. We know numbers
and collections
• try “grep metaclass=“ in python
source code
builtin_build_class__()
static PyObject *
builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
{
…
if (meta == NULL) {
/* if there are no bases, use type: */
if (PyTuple_GET_SIZE(bases) == 0) {
meta = (PyObject *) (&PyType_Type);
}
/* else get the type of the first base */
else {
PyObject *base0 = PyTuple_GET_ITEM(bases, 0);
meta = (PyObject *) (base0->ob_type);
}
Py_INCREF(meta);
isclass = 1; /* meta is really a class */
}
…
}
Some others
another use of python’s ABCs
isinstance(10, int)
True
isinstance(10, complex)
false
isinstance(10, numbers.Rational)
True
isinstance(10, numbers.Real)
True
isinstance(10, numbers.Complex)
True
isinstance(10, numbers.Number)
True
Number
Complex
Real
Integral
10
Rational
object
Key
instance-of
bytecode
Bytecode
• Bytecode is not new at all
• Smalltalk is one of early bytecode users
• Smalltalk bytecode
• end of Chapter 26, http://www.mirandabanda.org/
bluebook/
bluebook_chapter26.html#TheBytecodes26
• Chap. 28, http://www.mirandabanda.org/bluebook/
bluebook_chapter28.html
Smalltalk bytecode categories
• pushes	
• indicates	the	source	of	an	object	to	be	added	to	the	top	of	the	
interpreter's	stack	
• stores	
• indicates	the	variable	whose	value	should	be	changed	
• sends	
• specifies	the	selector	of	a	message	to	be	sent	and	how	many	
arguments	it	should	have.	
• returns	
• 	a	value	is	returned	for	the	message	that	invoked	that	
CompiledMethod	
• and	jumps	
• you	know	what	these	are 30
Smalltalk	bytecodes
Range Bits FuncHon
0-15 0000iiii Push	Receiver	Variable	#iiii
16-31 0001iiii Push	Temporary	LocaHon	#iiii
32-63 001iiiii Push	Literal	Constant	#iiiii
64-95 010iiiii Push	Literal	Variable	#iiiii
96-103 01100iii Pop	and	Store	Receiver	Variable	#iii
104-111 01101iii Pop	and	Store	Temporary	LocaHon	#iii
112-119 01110iii Push	(receiver,	true,	false,	nil,	-1,	0,	1,	2)	[iii]
120-123 011110ii Return	(receiver,	true,	false,	nil)	[ii]	From	Message
124-125 0111110i Return	Stack	Top	From	(Message,	Block)	[i]
126-127 0111111i unused
128 10000000	jjkkkkkk Push	(Receiver	Variable,	Temporary	LocaHon,	Literal	Constant,	Literal	Variable)	[jj]	#kkkkkk
129 10000001	jjkkkkkk Store	(Receiver	Variable,	Temporary	LocaHon,	Illegal,	Literal	Variable)	[jj]	#kkkkkk
130 10000010	jjkkkkkk Pop	and	Store	(Receiver	Variable,	Temporary	LocaHon,	Illegal,	Literal	Variable)	[jj]	#kkkkkk
131 10000011	jjjkkkkk Send	Literal	Selector	#kkkkk	With	jjj	Arguments
132 10000100	jjjjjjjj	kkkkkkkk Send	Literal	Selector	#kkkkkkkk	With	jjjjjjjj	Arguments
133 10000101	jjjkkkkk Send	Literal	Selector	#kkkkk	To	Superclass	With	jjj	Arguments
134 10000110	jjjjjjjj	kkkkkkkk Send	Literal	Selector	#kkkkkkkk	To	Superclass	With	jjjjjjjj	Arguments
135 10000111 Pop	Stack	Top
136 10001000 Duplicate	Stack	Top
137 10001001 Push	AcHve	Context
138-143 unused
144-151 10010iii Jump	iii	+	1	(i.e.,	1	through	8)
152-159 10011iii Pop	and	Jump	0n	False	iii	+1	(i.e.,	1	through	8)
160-167 10100iii	jjjjjjjj Jump(iii	-	4)	*256+jjjjjjjj
168-171 101010ii	jjjjjjjj Pop	and	Jump	On	True	ii	*256+jjjjjjjj
172-175 101011ii	jjjjjjjj Pop	and	Jump	On	False	ii	*256+jjjjjjjj
176-191 1011iiii Send	ArithmeHc	Message	#iiii
192-207 1100iiii Send	Special	Message	#iiii
208-223 1101iiii Send	Literal	Selector	#iiii	With	No	Arguments
224-239 1110iiii Send	Literal	Selector	#iiii	With	1	Argument
240-255 1111iiii Send	Literal	Selector	#iiii	With	2	Arguments	
31
• An	example	method,	
forCompiledMethod
"to show how CompiledMethod works"
| foo |
foo := 'test'.
^ 1 + 2
• Bytecode:	in	System	Browser	of	Squeak/Pharo,	we	can	see	bytecode	easily	
17 <20> pushConstant: 'test'
18 <68> popIntoTemp: 0
19 <76> pushConstant: 1
20 <77> pushConstant: 2
21 <B0> send: +
22 <7C> returnTop
32
foo
    | foo |
    foo := 'test'.
    ^ 1 + 2
17 <20> pushConstant: ‘test'
18 <68> popIntoTemp: 0
19 <76> pushConstant: 1
20 <77> pushConstant: 2
21 <B0> send: +
22 <7C> returnTop
 
def test():
foo = "test"
return 1 + 2
dis.dis(test)
2 0 LOAD_CONST 1 ('test')
3 STORE_FAST 0 (foo)
3 6 LOAD_CONST 4 (3)
9 RETURN_VALUE
foo: a and: b

    "to show how CompiledMethod works"



    | foo |

    foo := 'test'.

    ^ a + b
17 <20> pushConstant: 'test'
18 <6A> popIntoTemp: 2
19 <10> pushTemp: 0
20 <11> pushTemp: 1
21 <B0> send: +
22 <7C> returnTop
def test(a, b):
foo = "test"
return a + b
dis.dis(test)
2 0 LOAD_CONST 1 ('test')
3 STORE_FAST 2 (foo)
3 6 LOAD_FAST 0 (a)
9 LOAD_FAST 1 (b)
12 BINARY_ADD
13 RETURN_VALUE
displaying smalltalk bytecode
• CompiledMethod
• Class>>compiledMethodAt
• (Integer compiledMethodAt: #factorial) symbolic.
• (COSCUP2015 compiledMethodAt:
#forCompiledMethod) symbolic.
(Integer compiledMethodAt: #factorial) symbolic.

'29 <70> self

30 <75> pushConstant: 0

31 <B6> send: =

32 <99> jumpFalse: 35

33 <76> pushConstant: 1

34 <7C> returnTop

35 <70> self

36 <75> pushConstant: 0

37 <B3> send: >

38 <9E> jumpFalse: 46

39 <70> self

40 <70> self

41 <76> pushConstant: 1

42 <B1> send: -

43 <D0> send: factorial

44 <B8> send: *

45 <7C> returnTop

46 <70> self

47 <22> pushConstant: ''Not valid for negative integers''

48 <E1> send: error:

49 <87> pop

50 <78> returnSelf

'
(COSCUP2015 compiledMethodAt: #forCompiledMethod) symbolic.

'17 <20> pushConstant: ''test''

18 <68> popIntoTemp: 0

19 <76> pushConstant: 1

20 <77> pushConstant: 2

21 <B0> send: +

22 <7C> returnTop

'
Add a method
COSCUP2015 compile: '

foo

    ^42'
Add a class
|	myClass	myInstance	|

myClass	:=	Behavior	new.	"create	anon	behavior"

myClass	compile:	'theAnswer	^42'.	"add	a	method	for	instances"

(myClass	compiledMethodAt:	#theAnswer)	symbolic.	

myInstance	:=	myClass	new.	"create	an	instance"

Transcript	show:	myInstance	theAnswer;	cr.	"shows	42”
Python Bytecode
• General
• Unary
• Binary
• In-place
• Misc
• print: PRINT_EXPR
• set, map, tuple, list, etc.
https://docs.python.org/3/library/dis.html
foobar: a and: b

    "to show how CompiledMethod works"



    | foo |

    foo := 'test'.

    ^ Array with: (a + b) with: foo
25 <20> pushConstant: ‘test'
26 <6A> popIntoTemp: 2
27 <41> pushLit: Array
28 <10> pushTemp: 0
29 <11> pushTemp: 1
30 <B0> send: +
31 <12> pushTemp: 2
32 <F2> send: with:with:
33 <7C> returnTop
import dis
def foo(a, b):
foo = "test"
return (a+b, foo)
dis.dis(foo)
3 0 LOAD_CONST 1 ('test')
3 STORE_FAST 2 (foo)
4 6 LOAD_FAST 0 (a)
9 LOAD_FAST 1 (b)
12 BINARY_ADD
13 LOAD_FAST 2 (foo)
16 BUILD_TUPLE 2
19 RETURN_VALUE
observations
• ST-80’s bytecode is relatively simple or say
primitive one
• Python’s bytecode has many some unique
instructions and some specialized instructions for
builtin types (for legacy or performance reasons,
maybe)
• I know ST-80’s bytecode showed its age, but I am
surprised that Python’s bytecode is low level and
old too
So?
• We walked through metaclass and bytecode in
ST-80 and Python? Do you agree Guido’s words I
cited previously
https://www.moedict.tw/' ?font=ebas

Contenu connexe

Tendances

Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Andrei KUCHARAVY
 
C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...Gianluca Padovani
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8Heartin Jacob
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask TrainingJanBask Training
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updatesVinay H G
 
Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyTravis Oliphant
 
Python Raster Function - Esri Developer Conference - 2015
Python Raster Function - Esri Developer Conference - 2015Python Raster Function - Esri Developer Conference - 2015
Python Raster Function - Esri Developer Conference - 2015akferoz07
 
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...David Beazley (Dabeaz LLC)
 
Machine Learning on Your Hand - Introduction to Tensorflow Lite Preview
Machine Learning on Your Hand - Introduction to Tensorflow Lite PreviewMachine Learning on Your Hand - Introduction to Tensorflow Lite Preview
Machine Learning on Your Hand - Introduction to Tensorflow Lite PreviewModulabs
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmerselliando dias
 
Modern Java Concurrency
Modern Java ConcurrencyModern Java Concurrency
Modern Java ConcurrencyBen Evans
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to ClojureRenzo Borgatti
 
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...Holden Karau
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPTShivam Gupta
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 

Tendances (20)

Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
CBOR - The Better JSON
CBOR - The Better JSONCBOR - The Better JSON
CBOR - The Better JSON
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Python for All
Python for All Python for All
Python for All
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask Training
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPy
 
Python Raster Function - Esri Developer Conference - 2015
Python Raster Function - Esri Developer Conference - 2015Python Raster Function - Esri Developer Conference - 2015
Python Raster Function - Esri Developer Conference - 2015
 
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
Why Extension Programmers Should Stop Worrying About Parsing and Start Thinki...
 
Numba lightning
Numba lightningNumba lightning
Numba lightning
 
Machine Learning on Your Hand - Introduction to Tensorflow Lite Preview
Machine Learning on Your Hand - Introduction to Tensorflow Lite PreviewMachine Learning on Your Hand - Introduction to Tensorflow Lite Preview
Machine Learning on Your Hand - Introduction to Tensorflow Lite Preview
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmers
 
Modern Java Concurrency
Modern Java ConcurrencyModern Java Concurrency
Modern Java Concurrency
 
Python final ppt
Python final pptPython final ppt
Python final ppt
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to Clojure
 
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 

En vedette

Conozcamos Nuestros Pueblos
Conozcamos Nuestros PueblosConozcamos Nuestros Pueblos
Conozcamos Nuestros Pueblosamarilis17
 
Degima industrial, naval, civil and energy - 2010
Degima   industrial, naval, civil and energy - 2010Degima   industrial, naval, civil and energy - 2010
Degima industrial, naval, civil and energy - 2010Javier Cantera
 
Textil laboral y calzado de seguridad J'HAYBER WORKS - 2013
Textil laboral y calzado de seguridad J'HAYBER WORKS - 2013Textil laboral y calzado de seguridad J'HAYBER WORKS - 2013
Textil laboral y calzado de seguridad J'HAYBER WORKS - 2013Suministros Herco
 
Webinar CRM Latam & 5 Factores de Exito
Webinar CRM Latam & 5 Factores de ExitoWebinar CRM Latam & 5 Factores de Exito
Webinar CRM Latam & 5 Factores de ExitoDoble Group, LLC
 
Tempo August 2014
Tempo August 2014 Tempo August 2014
Tempo August 2014 Tempoplanet
 
Reparaciones electronicas
Reparaciones electronicasReparaciones electronicas
Reparaciones electronicasFrank Garcia
 
Tls eng kaz swiss 9.07.12
Tls eng kaz swiss 9.07.12Tls eng kaz swiss 9.07.12
Tls eng kaz swiss 9.07.12Alfiya-92
 
Políticas comerciales
Políticas comercialesPolíticas comerciales
Políticas comercialesCésar Torres
 
Content Strategy Proposal for B2B Client
Content Strategy Proposal for B2B Client Content Strategy Proposal for B2B Client
Content Strategy Proposal for B2B Client Aparna Das
 
China's economy: slowing distorted and debt-addicted
China's economy: slowing distorted and debt-addictedChina's economy: slowing distorted and debt-addicted
China's economy: slowing distorted and debt-addictedRBS Economics
 

En vedette (16)

Bcp corporativo animado
Bcp corporativo animadoBcp corporativo animado
Bcp corporativo animado
 
Oriol mitjà erradicará el pian en 2020
Oriol mitjà erradicará el pian en 2020Oriol mitjà erradicará el pian en 2020
Oriol mitjà erradicará el pian en 2020
 
Basque audiovisual
Basque audiovisualBasque audiovisual
Basque audiovisual
 
Conozcamos Nuestros Pueblos
Conozcamos Nuestros PueblosConozcamos Nuestros Pueblos
Conozcamos Nuestros Pueblos
 
Degima industrial, naval, civil and energy - 2010
Degima   industrial, naval, civil and energy - 2010Degima   industrial, naval, civil and energy - 2010
Degima industrial, naval, civil and energy - 2010
 
Frans Hals
Frans HalsFrans Hals
Frans Hals
 
Textil laboral y calzado de seguridad J'HAYBER WORKS - 2013
Textil laboral y calzado de seguridad J'HAYBER WORKS - 2013Textil laboral y calzado de seguridad J'HAYBER WORKS - 2013
Textil laboral y calzado de seguridad J'HAYBER WORKS - 2013
 
Webinar CRM Latam & 5 Factores de Exito
Webinar CRM Latam & 5 Factores de ExitoWebinar CRM Latam & 5 Factores de Exito
Webinar CRM Latam & 5 Factores de Exito
 
Tempo August 2014
Tempo August 2014 Tempo August 2014
Tempo August 2014
 
Plan estrategico
Plan estrategicoPlan estrategico
Plan estrategico
 
Reparaciones electronicas
Reparaciones electronicasReparaciones electronicas
Reparaciones electronicas
 
Tls eng kaz swiss 9.07.12
Tls eng kaz swiss 9.07.12Tls eng kaz swiss 9.07.12
Tls eng kaz swiss 9.07.12
 
Políticas comerciales
Políticas comercialesPolíticas comerciales
Políticas comerciales
 
Content Strategy Proposal for B2B Client
Content Strategy Proposal for B2B Client Content Strategy Proposal for B2B Client
Content Strategy Proposal for B2B Client
 
Prueba
PruebaPrueba
Prueba
 
China's economy: slowing distorted and debt-addicted
China's economy: slowing distorted and debt-addictedChina's economy: slowing distorted and debt-addicted
China's economy: slowing distorted and debt-addicted
 

Similaire à A peek into Python's Metaclass and Bytecode from a Smalltalk User

What is Python?
What is Python?What is Python?
What is Python?PranavSB
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Djangosolutionstreet
 
Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Kiran Jonnalagadda
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 
Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptxSAICHARANREDDYN
 
Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)Sebastian Witowski
 
Python indroduction
Python indroductionPython indroduction
Python indroductionFEG
 
Perl5 meta programming
Perl5 meta programmingPerl5 meta programming
Perl5 meta programmingkarupanerura
 
Python for katana
Python for katanaPython for katana
Python for katanakedar nath
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application DevelopmentDhaval Kaneria
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternNitin Bhide
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxRohitKumar639388
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovypaulbowler
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsRanel Padon
 

Similaire à A peek into Python's Metaclass and Bytecode from a Smalltalk User (20)

What is Python?
What is Python?What is Python?
What is Python?
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Django
 
Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptx
 
Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)
 
Python indroduction
Python indroductionPython indroduction
Python indroduction
 
Perl5 meta programming
Perl5 meta programmingPerl5 meta programming
Perl5 meta programming
 
Gcrc talk
Gcrc talkGcrc talk
Gcrc talk
 
Python for katana
Python for katanaPython for katana
Python for katana
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovy
 
Python for lab_folk
Python for lab_folkPython for lab_folk
Python for lab_folk
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 

Plus de Koan-Sin Tan

running stable diffusion on android
running stable diffusion on androidrunning stable diffusion on android
running stable diffusion on androidKoan-Sin Tan
 
Exploring Your Apple M1 devices with Open Source Tools
Exploring Your Apple M1 devices with Open Source ToolsExploring Your Apple M1 devices with Open Source Tools
Exploring Your Apple M1 devices with Open Source ToolsKoan-Sin Tan
 
Running TFLite on Your Mobile Devices, 2020
Running TFLite on Your Mobile Devices, 2020Running TFLite on Your Mobile Devices, 2020
Running TFLite on Your Mobile Devices, 2020Koan-Sin Tan
 
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolExploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolKoan-Sin Tan
 
TFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU DelegatesTFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU DelegatesKoan-Sin Tan
 
A Sneak Peek of MLIR in TensorFlow
A Sneak Peek of MLIR in TensorFlowA Sneak Peek of MLIR in TensorFlow
A Sneak Peek of MLIR in TensorFlowKoan-Sin Tan
 
A Peek into Google's Edge TPU
A Peek into Google's Edge TPUA Peek into Google's Edge TPU
A Peek into Google's Edge TPUKoan-Sin Tan
 
Why You Cannot Use Neural Engine to Run Your NN Models on A11 Devices?
Why You Cannot Use Neural Engine to Run Your NN Models on A11 Devices?Why You Cannot Use Neural Engine to Run Your NN Models on A11 Devices?
Why You Cannot Use Neural Engine to Run Your NN Models on A11 Devices?Koan-Sin Tan
 
Introduction to TensorFlow Lite
Introduction to TensorFlow Lite Introduction to TensorFlow Lite
Introduction to TensorFlow Lite Koan-Sin Tan
 
Tensorflow on Android
Tensorflow on AndroidTensorflow on Android
Tensorflow on AndroidKoan-Sin Tan
 
SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016Koan-Sin Tan
 
Android Wear and the Future of Smartwatch
Android Wear and the Future of SmartwatchAndroid Wear and the Future of Smartwatch
Android Wear and the Future of SmartwatchKoan-Sin Tan
 
Understanding Android Benchmarks
Understanding Android BenchmarksUnderstanding Android Benchmarks
Understanding Android BenchmarksKoan-Sin Tan
 
Dark Silicon, Mobile Devices, and Possible Open-Source Solutions
Dark Silicon, Mobile Devices, and Possible Open-Source SolutionsDark Silicon, Mobile Devices, and Possible Open-Source Solutions
Dark Silicon, Mobile Devices, and Possible Open-Source SolutionsKoan-Sin Tan
 

Plus de Koan-Sin Tan (16)

running stable diffusion on android
running stable diffusion on androidrunning stable diffusion on android
running stable diffusion on android
 
Exploring Your Apple M1 devices with Open Source Tools
Exploring Your Apple M1 devices with Open Source ToolsExploring Your Apple M1 devices with Open Source Tools
Exploring Your Apple M1 devices with Open Source Tools
 
A Peek into TFRT
A Peek into TFRTA Peek into TFRT
A Peek into TFRT
 
Running TFLite on Your Mobile Devices, 2020
Running TFLite on Your Mobile Devices, 2020Running TFLite on Your Mobile Devices, 2020
Running TFLite on Your Mobile Devices, 2020
 
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolExploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
 
TFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU DelegatesTFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU Delegates
 
A Sneak Peek of MLIR in TensorFlow
A Sneak Peek of MLIR in TensorFlowA Sneak Peek of MLIR in TensorFlow
A Sneak Peek of MLIR in TensorFlow
 
A Peek into Google's Edge TPU
A Peek into Google's Edge TPUA Peek into Google's Edge TPU
A Peek into Google's Edge TPU
 
Why You Cannot Use Neural Engine to Run Your NN Models on A11 Devices?
Why You Cannot Use Neural Engine to Run Your NN Models on A11 Devices?Why You Cannot Use Neural Engine to Run Your NN Models on A11 Devices?
Why You Cannot Use Neural Engine to Run Your NN Models on A11 Devices?
 
Caffe2 on Android
Caffe2 on AndroidCaffe2 on Android
Caffe2 on Android
 
Introduction to TensorFlow Lite
Introduction to TensorFlow Lite Introduction to TensorFlow Lite
Introduction to TensorFlow Lite
 
Tensorflow on Android
Tensorflow on AndroidTensorflow on Android
Tensorflow on Android
 
SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016SoC Idling for unconf COSCUP 2016
SoC Idling for unconf COSCUP 2016
 
Android Wear and the Future of Smartwatch
Android Wear and the Future of SmartwatchAndroid Wear and the Future of Smartwatch
Android Wear and the Future of Smartwatch
 
Understanding Android Benchmarks
Understanding Android BenchmarksUnderstanding Android Benchmarks
Understanding Android Benchmarks
 
Dark Silicon, Mobile Devices, and Possible Open-Source Solutions
Dark Silicon, Mobile Devices, and Possible Open-Source SolutionsDark Silicon, Mobile Devices, and Possible Open-Source Solutions
Dark Silicon, Mobile Devices, and Possible Open-Source Solutions
 

Dernier

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 

A peek into Python's Metaclass and Bytecode from a Smalltalk User

  • 1. A Peek into Python’s Metaclass and Bytecode as a Smalltalk User Koan-Sin Tan freedom_at_computer.org COSCUP 2015, Taipei
  • 2. why this topic • ‘I was only vaguely aware of Smalltalk at the time; I remember being surprised by its use of metaclasses (which is quite different from that in Python or Ruby!) when I read about them much later. Smalltalk's bytecode was a bigger influence of Python's bytecode though. I'd read about it in a book by Adele Goldberg and others, I believe "Smalltalk-80: The Language and its Implementation”’ [1] • And, I had a talk comparing Ruby’s metaclass and byte code to Smalltalk’s in the end of 2012 [2] • google “smalltalk and ruby bytecode” [1] http://python-history.blogspot.com/2013/10/origin-of-metaclasses-in- python.html [2] http://www.slideshare.net/kstan2/smalltalk-and-ruby-20121208-15542185
  • 3. what won’t be discussed • anything beyond simple metaclass and bytecode comparisons • So, no inline cache if you was in the SpiderMonkey talk yesterday. Yes, I know inline cache was for Smalltalk-80. If you want to know how inline cache is used in Smalltalk, read an excellent article [1] • And no other stuff in object model (whatever object model means to you) [1] http://www.mirandabanda.org/cogblog/2011/03/01/build- me-a-jit-as-fast-as-you-can/
  • 5. who am I • Learnt to write program on MPF-II • Used to be a programming language junkie • Learnt a bit Smalltalk during early '90s, use it on and off • Recent interest in ST-80 because of Scratch and BYOB/SNAP • Knew little about Python
  • 6. the first smalltalk-80 I used is on Sun’s SunView, image from Wikipedia
  • 8. Scratch was written in Smalltalk 8 http://news.softpedia.com/images/reviews/large/ Scratch_Large_001.png
  • 9. What I knew about python • It’s a popular scripting language • My classmate told me about Python in ’94 or ’95 • IPython notebook: using python and R to share notes • And of course, Python is more than Smalltalk-80
  • 10. share my understanding of python metaclass as bytecode as a common programmer
  • 11. Quick Overview of ST-80 • Object-Oriented Programming • OO GUI environment, IDE • stack VM, bytecode • Lambda, functional language, block • Message passing • Design Pattern: • if you read the GoF book, you ran into lots of Smalltalk patterns before • Learning/educational • Logo and the dream of Dynabook
  • 13. Metaclass in ST-80 • From "purple book", Chap 16 1. Every class is ultimately a subclass of class Object, except for Object itself, which has no superclass. In particular, Class is a subclass of ClassDescription, which is a subclass of Behavior which is a subclass of Object 2. Every object is an instance of a class 3. Every class is an instance of a metaclass 4. All metaclasses are subclasses of Class 5. Every metaclass is an instance of Metaclass 6. The method of Class and it superclasses support the behavior common to all objects that are classes 7. The methods of instances of Metaclass add the behavior specific to particular classes
  • 14. Smalltalk Object Model •10 factorial --> 3628800 •10 factorial class --> SmallInteger •SmallInteger superclass --> Integer •Integer superclass --> Number •Number superclass --> Magnitude •Magnitude superclass --> Object •Object superclass --> ProtoObject •ProtoObject superclass --> nil 14
  • 15. • 10 factorial class allSuperclasses --> an OrderedCollection(Integer Number Magnitude Object ProtoObject)
  • 16. Python int print(type(1)) <class 'int'> print(type(1).__base__) <class 'object'> print(type(1).__base__.__base__) None print(type(1).__mro__) (<class 'int'>, <class ‘object'>) • So int, then object, no hierarchy for numbers. How about container types, e.g., set and dict? NO! • Fortunately, there is another path since python3000(?) • There is PEP 3119 “Abstract Base Classes” (ABC) and its companion PEP 3141. So, there are ABCs for numbers in module numbers and collections module collections  numbers.Integral.__base__ <class 'numbers.Rational'> numbers.Integral.__base__.__base__ <class 'numbers.Real'> numbers.Integral.__base__.__base__.__base__ <class 'numbers.Complex'> numbers.Integral.__base__.__base__.__base__.__base__ <class 'numbers.Number'> numbers.Integral.__base__.__base__.__base__.__base__.__ base__ <class ‘object'> numbers.Integral.__mro__ (<class 'numbers.Integral'>, <class 'numbers.Rational'>, <class 'numbers.Real'>, <class 'numbers.Complex'>, <class 'numbers.Number'>, <class 'object'>) https://docs.python.org/3/reference/datamodel.html Number Complex Real Integral 10 Rational object Key instance-of
  • 17. a class named Metaclass SmallInteger class --> SmallInteger class Integer class --> Integer class Number class --> Number class Magnitude class --> Magnitude class Object class --> Object class ProtoObject class --> ProtoObject class SmallInteger class superclass --> Integer class
 Integer class superclass --> Number class
 Number class superclass --> Magnitude class
 Magnitude class superclass --> Object class
 Object class superclass --> ProtoObject class
 ProtoObject class superclass --> Class Class class --> Class class
 Class class class --> Metaclass
 Metaclass class --> Metaclass class
 Metaclass class class --> Metaclass
  • 18. Object Magnitude Number Object class Magnitude class Number class Key instance-of Integer class SmallInteger SmallInteger class 10 Integer ProtoObject ProtoObject class figures modified from “Pharo by Example” 18
  • 19. Object Magnitude Number Object class Magnitude class Number class Key instance-of Integer class SmallInteger SmallInteger class 10 Integer ProtoObject ProtoObject class Class Class class Metaclass Metaclass class 19
  • 20. Class class class --> Metaclass
 Metaclass superclass --> ClassDescription
 ClassDescription superclass --> Behavior
 Behavior superclass --> Object
 
 Class class superclass --> ClassDescription class
 ClassDescription class superclass --> Behavior class
 Behavior class superclass --> Object class 20
  • 21. Object Magnitude Number Object class Magnitude class Number class Key instance-of Integer class SmallInteger SmallInteger class 10 Integer ProtoObject ProtoObject class Class Class class Metaclass Metaclass class ClassDescription Behavior ClassDescription class Behavior class 21
  • 23. Python metaclass type(1).__class__ <class ‘type'> type(1).__class__.__class_ <class ‘type’> numbers.Integral.__class__ <class ‘abc.ABC’> numbers.Rationl.__class__ <class ‘abc.ABC’> abc.ABC.__class__ <class ‘type’> ———————————————————————————————— import dis def testClass(): class Foo: def foo(self, a, b): return a + b bar = Foo() bar.foo(2+3) dis.dis(testClass) 3 0 LOAD_BUILD_CLASS 1 LOAD_CONST 1 (<code object Foo at 0x1101aee40, file "<ipython- input-37-12f9deff1239>", line 3>) 4 LOAD_CONST 2 ('Foo') 7 MAKE_FUNCTION 0 10 LOAD_CONST 2 ('Foo') 13 CALL_FUNCTION 2 (2 positional, 0 keyword pair) 16 STORE_FAST 0 (Foo) 6 19 LOAD_FAST 0 (Foo) 22 CALL_FUNCTION 0 (0 positional, 0 keyword pair) 25 STORE_FAST 1 (bar) 7 28 LOAD_FAST 1 (bar) 31 LOAD_ATTR 0 (foo) 34 LOAD_CONST 5 (5) 37 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 40 POP_TOP 41 LOAD_CONST 0 (None) 44 RETURN_VALUE
  • 24. Python metaclass • LOAD_BUILD_CLASS: LOAD_BUILD_CLASS¶ Pushes builtins.__build_class__() onto the stack. It is later called by CALL_FUNCTION to construct a class [1] • builtins.__build_class__ static PyMethodDef builtin_methods[] = { {"__build_class__", (PyCFunction)builtin___build_class__, METH_VARARGS | METH_KEYWORDS, build_class_doc}, {"__import__", (PyCFunction)builtin___import__, METH_VARARGS | METH_KEYWORDS, import_doc}, {"abs", builtin_abs, METH_O, abs_doc}, [1] https://docs.python.org/3/ library/dis.html • builtin_build_class__ • if no specific metaclass was given and there no special metaclass in base classes of a class, the default metaclass is the ‘type’ • BTW, as far as I can tell there are some classes have non-type metaclasses in standard Python distribution. We know numbers and collections • try “grep metaclass=“ in python source code
  • 25. builtin_build_class__() static PyObject * builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) { … if (meta == NULL) { /* if there are no bases, use type: */ if (PyTuple_GET_SIZE(bases) == 0) { meta = (PyObject *) (&PyType_Type); } /* else get the type of the first base */ else { PyObject *base0 = PyTuple_GET_ITEM(bases, 0); meta = (PyObject *) (base0->ob_type); } Py_INCREF(meta); isclass = 1; /* meta is really a class */ } … }
  • 27. another use of python’s ABCs isinstance(10, int) True isinstance(10, complex) false isinstance(10, numbers.Rational) True isinstance(10, numbers.Real) True isinstance(10, numbers.Complex) True isinstance(10, numbers.Number) True Number Complex Real Integral 10 Rational object Key instance-of
  • 29. Bytecode • Bytecode is not new at all • Smalltalk is one of early bytecode users • Smalltalk bytecode • end of Chapter 26, http://www.mirandabanda.org/ bluebook/ bluebook_chapter26.html#TheBytecodes26 • Chap. 28, http://www.mirandabanda.org/bluebook/ bluebook_chapter28.html
  • 30. Smalltalk bytecode categories • pushes • indicates the source of an object to be added to the top of the interpreter's stack • stores • indicates the variable whose value should be changed • sends • specifies the selector of a message to be sent and how many arguments it should have. • returns • a value is returned for the message that invoked that CompiledMethod • and jumps • you know what these are 30
  • 31. Smalltalk bytecodes Range Bits FuncHon 0-15 0000iiii Push Receiver Variable #iiii 16-31 0001iiii Push Temporary LocaHon #iiii 32-63 001iiiii Push Literal Constant #iiiii 64-95 010iiiii Push Literal Variable #iiiii 96-103 01100iii Pop and Store Receiver Variable #iii 104-111 01101iii Pop and Store Temporary LocaHon #iii 112-119 01110iii Push (receiver, true, false, nil, -1, 0, 1, 2) [iii] 120-123 011110ii Return (receiver, true, false, nil) [ii] From Message 124-125 0111110i Return Stack Top From (Message, Block) [i] 126-127 0111111i unused 128 10000000 jjkkkkkk Push (Receiver Variable, Temporary LocaHon, Literal Constant, Literal Variable) [jj] #kkkkkk 129 10000001 jjkkkkkk Store (Receiver Variable, Temporary LocaHon, Illegal, Literal Variable) [jj] #kkkkkk 130 10000010 jjkkkkkk Pop and Store (Receiver Variable, Temporary LocaHon, Illegal, Literal Variable) [jj] #kkkkkk 131 10000011 jjjkkkkk Send Literal Selector #kkkkk With jjj Arguments 132 10000100 jjjjjjjj kkkkkkkk Send Literal Selector #kkkkkkkk With jjjjjjjj Arguments 133 10000101 jjjkkkkk Send Literal Selector #kkkkk To Superclass With jjj Arguments 134 10000110 jjjjjjjj kkkkkkkk Send Literal Selector #kkkkkkkk To Superclass With jjjjjjjj Arguments 135 10000111 Pop Stack Top 136 10001000 Duplicate Stack Top 137 10001001 Push AcHve Context 138-143 unused 144-151 10010iii Jump iii + 1 (i.e., 1 through 8) 152-159 10011iii Pop and Jump 0n False iii +1 (i.e., 1 through 8) 160-167 10100iii jjjjjjjj Jump(iii - 4) *256+jjjjjjjj 168-171 101010ii jjjjjjjj Pop and Jump On True ii *256+jjjjjjjj 172-175 101011ii jjjjjjjj Pop and Jump On False ii *256+jjjjjjjj 176-191 1011iiii Send ArithmeHc Message #iiii 192-207 1100iiii Send Special Message #iiii 208-223 1101iiii Send Literal Selector #iiii With No Arguments 224-239 1110iiii Send Literal Selector #iiii With 1 Argument 240-255 1111iiii Send Literal Selector #iiii With 2 Arguments 31
  • 32. • An example method, forCompiledMethod "to show how CompiledMethod works" | foo | foo := 'test'. ^ 1 + 2 • Bytecode: in System Browser of Squeak/Pharo, we can see bytecode easily 17 <20> pushConstant: 'test' 18 <68> popIntoTemp: 0 19 <76> pushConstant: 1 20 <77> pushConstant: 2 21 <B0> send: + 22 <7C> returnTop 32
  • 33. foo     | foo |     foo := 'test'.     ^ 1 + 2 17 <20> pushConstant: ‘test' 18 <68> popIntoTemp: 0 19 <76> pushConstant: 1 20 <77> pushConstant: 2 21 <B0> send: + 22 <7C> returnTop   def test(): foo = "test" return 1 + 2 dis.dis(test) 2 0 LOAD_CONST 1 ('test') 3 STORE_FAST 0 (foo) 3 6 LOAD_CONST 4 (3) 9 RETURN_VALUE
  • 34. foo: a and: b
     "to show how CompiledMethod works"
 
     | foo |
     foo := 'test'.
     ^ a + b 17 <20> pushConstant: 'test' 18 <6A> popIntoTemp: 2 19 <10> pushTemp: 0 20 <11> pushTemp: 1 21 <B0> send: + 22 <7C> returnTop def test(a, b): foo = "test" return a + b dis.dis(test) 2 0 LOAD_CONST 1 ('test') 3 STORE_FAST 2 (foo) 3 6 LOAD_FAST 0 (a) 9 LOAD_FAST 1 (b) 12 BINARY_ADD 13 RETURN_VALUE
  • 35. displaying smalltalk bytecode • CompiledMethod • Class>>compiledMethodAt • (Integer compiledMethodAt: #factorial) symbolic. • (COSCUP2015 compiledMethodAt: #forCompiledMethod) symbolic. (Integer compiledMethodAt: #factorial) symbolic.
 '29 <70> self
 30 <75> pushConstant: 0
 31 <B6> send: =
 32 <99> jumpFalse: 35
 33 <76> pushConstant: 1
 34 <7C> returnTop
 35 <70> self
 36 <75> pushConstant: 0
 37 <B3> send: >
 38 <9E> jumpFalse: 46
 39 <70> self
 40 <70> self
 41 <76> pushConstant: 1
 42 <B1> send: -
 43 <D0> send: factorial
 44 <B8> send: *
 45 <7C> returnTop
 46 <70> self
 47 <22> pushConstant: ''Not valid for negative integers''
 48 <E1> send: error:
 49 <87> pop
 50 <78> returnSelf
 ' (COSCUP2015 compiledMethodAt: #forCompiledMethod) symbolic.
 '17 <20> pushConstant: ''test''
 18 <68> popIntoTemp: 0
 19 <76> pushConstant: 1
 20 <77> pushConstant: 2
 21 <B0> send: +
 22 <7C> returnTop
 '
  • 36. Add a method COSCUP2015 compile: '
 foo
     ^42'
  • 38. Python Bytecode • General • Unary • Binary • In-place • Misc • print: PRINT_EXPR • set, map, tuple, list, etc. https://docs.python.org/3/library/dis.html
  • 39. foobar: a and: b
     "to show how CompiledMethod works"
 
     | foo |
     foo := 'test'.
     ^ Array with: (a + b) with: foo 25 <20> pushConstant: ‘test' 26 <6A> popIntoTemp: 2 27 <41> pushLit: Array 28 <10> pushTemp: 0 29 <11> pushTemp: 1 30 <B0> send: + 31 <12> pushTemp: 2 32 <F2> send: with:with: 33 <7C> returnTop import dis def foo(a, b): foo = "test" return (a+b, foo) dis.dis(foo) 3 0 LOAD_CONST 1 ('test') 3 STORE_FAST 2 (foo) 4 6 LOAD_FAST 0 (a) 9 LOAD_FAST 1 (b) 12 BINARY_ADD 13 LOAD_FAST 2 (foo) 16 BUILD_TUPLE 2 19 RETURN_VALUE
  • 40. observations • ST-80’s bytecode is relatively simple or say primitive one • Python’s bytecode has many some unique instructions and some specialized instructions for builtin types (for legacy or performance reasons, maybe) • I know ST-80’s bytecode showed its age, but I am surprised that Python’s bytecode is low level and old too
  • 41. So? • We walked through metaclass and bytecode in ST-80 and Python? Do you agree Guido’s words I cited previously