<div dir="ltr">Hi everyone.<div><br></div><div><div style="font-size:12.8px">It seems that some people are struggling with the fact that methods in Pharo (and other Smalltalk on top of Cog) cannot have more than 15 arguments. Typically the problem arises while generating Smalltalk code or porting code from other Smalltalks.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I have been thinking for a while about this problem. In this mail I write a small sketch to solve it, it&#39;s something that could go to production very quickly and that requires almost only image-side changes. Eliot has already reviewed and approved the sketch, but I&#39;&#39;d like to know if someone is strongly against that change.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">The generic idea is to change the send calling convention at the bytecode level, using a temp vector to pass overflowing arguments. </div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">The normal calling convention in the Smalltalk bytecode is as follows:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">push receiver</div><div style="font-size:12.8px">push arg 1 </div><div style="font-size:12.8px">push arg 2 </div><div style="font-size:12.8px">....</div><div style="font-size:12.8px">push arg N</div><div style="font-size:12.8px">send selector</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">N is limited to 15 arguments due compiled method header &amp; bytecode encoding. </div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">In the new design, if the send has less than 15 arguments, the calling convention remains the same. Over 15 arguments, the overflowing arguments are passed in a temp vector in a similar way to the closure temp vectors.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">The convention will look like that:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div>push receiver</div><div>push arg 1 </div><div>push arg 2 </div><div>....</div><div>push arg N</div><div>popIntoArray N-15 values</div><div>send selector</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">The compilation of a method with more than 15 arguments is then changed:</div><div style="font-size:12.8px">- As for temp vectors, the 15th arg array can&#39;t be become or read-only, hence the temp vector instructions can be used to access the overflowing arguments through the 15th arg.</div><div style="font-size:12.8px">- the compiled method header is still marked with 15 arguments</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">In addition one needs to change CompiledMethod to:</div><div style="font-size:12.8px">- allow larger frames (instead of 56 we could allow 128 or 256)</div><div style="font-size:12.8px">- have numArgs answering the right number of methods with many arguments. I think the number of arguments could be in the additional method state in this case as it is very uncommon.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">And to change the fall-back of a couple primitives, such as:</div><div style="font-size:12.8px">- Object&gt;&gt;<span style="font-size:12.8px">perform: withArgs:</span></div><div style="font-size:12.8px"><span style="font-size:12.8px">- Object&gt;&gt;</span><span style="font-size:12.8px">perform: withArgs:inSupedClass:</span><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px">- BlockClosure&gt;&gt;valueWithArgs:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">This design would allow methods to up to 141 arguments.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">What do you guys think ? </div><div>
</div></div></div>