annotate Python/makeopcodetargets.py @ 63446:0dcae455ec07 3.1

Merged revisions 83352,83355-83358,83362,83366,83368-83369 via svnmerge from svn+ssh://svn.python.org/python/branches/py3k ........ r83352 | georg.brandl | 2010-07-31 20:11:07 +0200 (Sa, 31 Jul 2010) | 1 line #9440: Remove borderline test case that fails based on unpredictable conditions such as compiler flags. ........ r83355 | georg.brandl | 2010-07-31 21:17:11 +0200 (Sa, 31 Jul 2010) | 1 line Fix bad merge: test_support -> support. ........ r83356 | georg.brandl | 2010-07-31 21:29:15 +0200 (Sa, 31 Jul 2010) | 1 line Remove trailing whitespace. ........ r83357 | georg.brandl | 2010-07-31 21:59:55 +0200 (Sa, 31 Jul 2010) | 1 line #5778: document that sys.version can contain a newline. ........ r83358 | georg.brandl | 2010-07-31 22:05:31 +0200 (Sa, 31 Jul 2010) | 1 line #9442: do not document a specific format for sys.version; rather refer to version_info and the platform module. ........ r83362 | georg.brandl | 2010-07-31 23:12:15 +0200 (Sa, 31 Jul 2010) | 1 line #8910: add a file explaining why Lib/test/data is there. ........ r83366 | georg.brandl | 2010-07-31 23:26:40 +0200 (Sa, 31 Jul 2010) | 1 line There always is a False and True now. ........ r83368 | georg.brandl | 2010-07-31 23:40:15 +0200 (Sa, 31 Jul 2010) | 1 line #7909: the prefixes \\.\ and \\?\ indicate special Windows paths, do not try to manipulate them. See http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx for details. ........ r83369 | georg.brandl | 2010-07-31 23:41:42 +0200 (Sa, 31 Jul 2010) | 1 line Fix "Berkeley" name. ........
author Georg Brandl <georg@python.org>
date Sun, 01 Aug 2010 19:17:57 +0000
parents f197407bdba2
children 3c9232a684ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51031
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1 #! /usr/bin/env python
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
2 """Generate C code for the jump table of the threaded code interpreter
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
3 (for compilers supporting computed gotos or "labels-as-values", such as gcc).
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
4 """
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
5
51202
df090597afaa Make Python/makeopcodetargets runnable with Python 2.3. With any luck, this
Mark Dickinson <dickinsm@gmail.com>
parents: 51031
diff changeset
6 # This code should stay compatible with Python 2.3, at least while
df090597afaa Make Python/makeopcodetargets runnable with Python 2.3. With any luck, this
Mark Dickinson <dickinsm@gmail.com>
parents: 51031
diff changeset
7 # some of the buildbots have Python 2.3 as their system Python.
df090597afaa Make Python/makeopcodetargets runnable with Python 2.3. With any luck, this
Mark Dickinson <dickinsm@gmail.com>
parents: 51031
diff changeset
8
51031
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
9 import imp
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
10 import os
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
11
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
12
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
13 def find_module(modname):
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
14 """Finds and returns a module in the local dist/checkout.
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
15 """
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
16 modpath = os.path.join(
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
17 os.path.dirname(os.path.dirname(__file__)), "Lib")
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
18 return imp.load_module(modname, *imp.find_module(modname, [modpath]))
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
19
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
20 def write_contents(f):
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
21 """Write C code contents to the target file object.
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
22 """
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
23 opcode = find_module("opcode")
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
24 targets = ['_unknown_opcode'] * 256
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
25 for opname, op in opcode.opmap.items():
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
26 if opname == "STOP_CODE":
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
27 # XXX opcode not implemented
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
28 continue
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
29 targets[op] = "TARGET_%s" % opname
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
30 f.write("static void *opcode_targets[256] = {\n")
61467
f197407bdba2 Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 51202
diff changeset
31 f.write(",\n".join([" &&%s" % s for s in targets]))
51031
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
32 f.write("\n};\n")
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
33
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
34
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
35 if __name__ == "__main__":
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
36 import sys
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
37 assert len(sys.argv) < 3, "Too many arguments"
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
38 if len(sys.argv) == 2:
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
39 target = sys.argv[1]
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
40 else:
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
41 target = "Python/opcode_targets.h"
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
42 f = open(target, "w")
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
43 try:
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
44 write_contents(f)
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
45 finally:
d86e23318b41 Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
46 f.close()