2010/10/24 Greg Ewing email@example.com
Cesare Di Mauro wrote:
I think that having max 255 args and 255 kwargs is a good and reasonable limit which we can live on, and helps the virtual machine implementation
Is there any corresponding limit to the number of arguments to tuple and dict constructor?
AFAIK there's no such limit. However, I'll use BUILD_TUPLE and BUILD_MAP opcodes for such purpose, because they are faster.
If not, the limit could perhaps be circumvented without changing the VM by having the compiler convert calls with large numbers of args into code that builds an appropriate tuple and dict and makes a *args/**kwds call.
I greatly prefer this solution, but it's a bit more complicated when there are *arg and/or **kwargs special arguments.
If we have > 255 args and *args is defined, we need to: 1) emit BUILD_TUPLE after pushed the regular arguments 2) emit LOAD_GLOBAL("tuple") 3) push *args 4) emit CALL_FUNCTION(1) to convert *args to a tuple 5) emit BINARY_ADD to append *args to the regular arguments 6) emit CALL_FUNCTION_VAR
If we have > 255 kwargs and **kwargs defined, we need to: 1) emit BUILD_MAP after pushed the regular keyword arguments 2) emit LOAD_ATTR("update") 3) push **kwargs 4) emit CALL_FUNCTION(1) to update the regular keyword arguments with the ones in **kwargs 5) emit CALL_FUNCTION_KW
And, finally, combining all the above in the worst case.
But, as I said, I prefer this one to handle "complex" cases instead of changing the VM slowing the common ones.