<div dir="ltr">With WPython I've solved this scenario with only a new opcode, LOAD_CONSTS, which basically unpacks the (constant) tuple into the stack.<div><br></div><div>So, you don't need new opcodes for new function calls, and LOAD_CONSTS is only used when needed.</div><div><br></div><div>Regards,</div><div>Cesare</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-04-21 17:52 GMT+02:00 Serhiy Storchaka <span dir="ltr"><<a href="mailto:storchaka@gmail.com" target="_blank">storchaka@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Currently the call of function with keyword arguments (say `f(a, b, x=c, y=d)`) is compiled to following bytecode:<br>
<br>
0 LOAD_NAME 0 (f)<br>
3 LOAD_NAME 1 (a)<br>
6 LOAD_NAME 2 (b)<br>
9 LOAD_CONST 0 ('x')<br>
12 LOAD_NAME 3 (c)<br>
15 LOAD_CONST 1 ('y')<br>
18 LOAD_NAME 4 (d)<br>
21 CALL_FUNCTION 514 (2 positional, 2 keyword pair)<br>
<br>
For every positional argument its value is pushed on the stack, and for every keyword argument its name and its value are pushed on the stack. But keyword arguments are always constant strings! We can reorder the stack, and push keyword argument values and names separately. And we can save all keyword argument names for this call in a constant tuple and load it by one bytecode command.<br>
<br>
0 LOAD_NAME 0 (f)<br>
3 LOAD_NAME 1 (a)<br>
6 LOAD_NAME 2 (b)<br>
9 LOAD_NAME 3 (c)<br>
12 LOAD_NAME 4 (d)<br>
15 LOAD_CONST 0 (('x', 'y'))<br>
18 CALL_FUNCTION2 2<br>
<br>
Benefits:<br>
<br>
1. We save one command for every keyword parameter after the first. This saves bytecode size and execution time.<br>
<br>
2. Since the number of keyword arguments is obtained from tuple's size, new CALL_FUNCTION opcode needs only the number of positional arguments. It's argument is simpler and needs less bits (important for wordcode).<br>
<br>
Disadvantages:<br>
<br>
1. Increases the number of constants.<br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div><br></div>