Investigate strongly typed builtin function behaviours
Opened this issue · 0 comments
Currently builtin functions have one of two behaviours: Regular
and Constructor
. Regular
takes the this_value
and a generic arguments
vector. Constructor
takes this_value
, arguments
and an optional new_target
. These correspond with normal JS calls and new
calls of functions.
The benefit of these is that calling functions is always similar: Just get this
, get the arguments
and get the function being called, and call. The downside is that the arguments need to be gathered into a Vec. Often enough we only need a few parameters so they could easily be stack-allocated. A ShortVec would work but sometimes it will spill. It will also not really match what the function actually wants.
It might instead be possible to bring function pointer calling down to the interpreter level directly, and extend the different behaviours. eg. Infallible functions, functions that don't take this, functions that don't need Agent
, functions that take 0, 1, 2, 3, ... parameters. At present our Behaviour is a 16 byte value; 8 bytes for the function pointer and 1 byte + 7 bytes of padding for the behaviour discriminant. There's essentially no limit (aside from reasonability) to how many different behaviours we can have.