[issue4753] Faster opcode dispatch on gcc
Paolo 'Blaisorblade' Giarrusso
report at bugs.python.org
Thu Jan 1 06:15:12 CET 2009
Paolo 'Blaisorblade' Giarrusso <p.giarrusso at gmail.com> added the comment:
== On the patch itself ==
Why don't you use the C preprocessor instead of that Python code?
Sample code:
#define OPCODE_LIST(DEFINE_OPCODE) \
DEFINE_OPCODE(STOP_CODE, 0) \
DEFINE_OPCODE(POP_TOP, 1) \
DEFINE_OPCODE(ROT_TWO, 2) \
DEFINE_OPCODE(ROT_THREE, 3) \
DEFINE_OPCODE(DUP_TOP, 4) \
DEFINE_OPCODE(ROT_FOUR, 5) \
DEFINE_OPCODE(NOP, 9) \
...
# define DECL_OPCODE(opcode) \
[opcode] = && label_ ## opcode,
void *opcodes[] = {
OPCODE_LIST(DECL_OPCODE)
};
# undef DECL_OPCODE
There are also other ways to do it, but using higher-order functions
within the preprocessor in this way is something that I learned from the
V8 source code.
It has the advantage that OPCODE_LIST can be used in a lot of other
places (maybe when implementing the 'opcode' module, if it's written in C).
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4753>
_______________________________________
More information about the Python-bugs-list
mailing list