Post

Taught my Kotlin scripting runtime to handle default parameters and named arguments. For simplicity, default evaluation lives in the function body and gets removed when inlined at the call site. #kotlin

6 reposts181 likes

I considered doing it this way, but adding a separate function and calling it reliably behind the scene sounds like a major headache. So instead I added special instructions to the VM to communicate a bit mask of used default values to the function. They are only present before inlining.

Assembly result looks interesting. I can pretty much follow everything as listed. (Came from S/360 assembly background) I know what the mnemonic "MOV" does, and how the syntax of the instruction works, but what does the dot p mean as appended to the mov? (dot i means int, right?)

I need two different move instructions since I use separate stacks for primitive (.p) and object types (.a) for implementation reasons. The .i in the MUL instruction stands for 32bit integer multiplication, indeed.

Your implementation is much more advanced than mine, which is primarily because I don't need to be fully generalized and can make a bunch of simplifying assumptions. Still, very cool 😎