Mercurial > cpython-lru_cache-weakref
annotate Python/makeopcodetargets.py @ 51145:9742e8a4dca1
Issue #4707: round(x, n) now returns an integer when x is an integer.
Previously it returned a float.
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Wed, 28 Jan 2009 21:25:58 +0000 |
| parents | d86e23318b41 |
| children | df090597afaa |
| 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 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
6 import imp |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
7 import os |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
8 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
9 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
10 def find_module(modname): |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
11 """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
|
12 """ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
13 modpath = os.path.join( |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
14 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
|
15 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
|
16 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
17 def write_contents(f): |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
18 """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
|
19 """ |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
20 opcode = find_module("opcode") |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
21 targets = ['_unknown_opcode'] * 256 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
22 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
|
23 if opname == "STOP_CODE": |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
24 # XXX opcode not implemented |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
25 continue |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
26 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
|
27 f.write("static void *opcode_targets[256] = {\n") |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
28 f.write(",\n".join("\t&&%s" % s for s in targets)) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
29 f.write("\n};\n") |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
30 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
31 |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
32 if __name__ == "__main__": |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
33 import sys |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
34 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
|
35 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
|
36 target = sys.argv[1] |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
37 else: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
38 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
|
39 f = open(target, "w") |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
40 try: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
41 write_contents(f) |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
42 finally: |
|
d86e23318b41
Issue #4753: By enabling a configure option named '--with-computed-gotos'
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff
changeset
|
43 f.close() |
