stevehalliwell / ulox

A bytecode interpreted scripting language for games in Unity.
MIT License
24 stars 0 forks source link

Calling convention optimisation #241

Open stevehalliwell opened 8 months ago

stevehalliwell commented 8 months ago

Presently we put a call frame on and put on the value stack

  1. this/closure
  2. args
  3. returns

So when we return we shuffle those returns down to the top of the stack for the caller. If we instead did

  1. returns
  2. this/closure
  3. args

we wouldn't have to shuffle anything, returns would already be where they belong

stevehalliwell commented 4 months ago

This is because we run into the call value, and then the args on the stack. We set that value as the zero point for that new callstack. If we knew the return count ahead of time in the compiler, we could push the nulls required for returns ahead of the value itself. This becomes tough when we allow discarded returns and are fully dynamic.