annotate Tools/modulator/EXAMPLE.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 897afcacba00
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 # Example input file for modulator if you don't have tk.
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 # You may also have to strip some imports out of modulator to make
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 # it work.
2712
74747bffb6a4 Made the example slightly more complete
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
6
74747bffb6a4 Made the example slightly more complete
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
7 import genmodule
74747bffb6a4 Made the example slightly more complete
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
8
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 # Generate code for a simple object with a method called sample
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 o = genmodule.object()
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 o.name = 'simple object'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 o.abbrev = 'simp'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 o.methodlist = ['sample']
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 o.funclist = ['new']
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 # Generate code for an object that looks numberish
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 o2 = genmodule.object()
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 o2.name = 'number-like object'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 o2.abbrev = 'nl'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 o2.typelist = ['tp_as_number']
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 o2.funclist = ['new', 'tp_repr', 'tp_compare']
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 # Generate code for a method with a full complement of functions,
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 # some methods, accessible as sequence and allowing structmember.c type
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 # structure access as well.
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 o3 = genmodule.object()
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 o3.name = 'over-the-top object'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 o3.abbrev = 'ot'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 o3.methodlist = ['method1', 'method2']
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 o3.funclist = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr',
30772
897afcacba00 Patch #812378: Normalize white space.
Martin v. Löwis <martin@v.loewis.de>
parents: 2712
diff changeset
37 'tp_compare', 'tp_repr', 'tp_hash']
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 o3.typelist = ['tp_as_sequence', 'structure']
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 # Now generate code for a module that incorporates these object types.
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 # Also add the boilerplates for functions to create instances of each
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 # type.
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 m = genmodule.module()
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 m.name = 'sample'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 m.abbrev = 'sample'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 m.methodlist = ['newsimple', 'newnumberish', 'newott']
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 m.objects = [o, o2, o3]
2712
74747bffb6a4 Made the example slightly more complete
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
50
74747bffb6a4 Made the example slightly more complete
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
51 fp = open('EXAMPLEmodule.c', 'w')
74747bffb6a4 Made the example slightly more complete
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
52 genmodule.write(fp, m)
74747bffb6a4 Made the example slightly more complete
Jack Jansen <jack.jansen@cwi.nl>
parents: 2466
diff changeset
53 fp.close()