Add support for user atoms and namecalls #48
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for Luau's faster method invocation protocol that uses a concept called NAMECALL.
When Luau invokes a method with NAMECALL, it sets an interned string pointer into the Lua state struct which can then be quickly turned into either a string or a 16-bit index, for dispatching a user method quickly. This way method calls do not need to lookup methods from a Lua table nor is there any need to do any expensive string comparisons.
Expose some more Luau API to make the above possible. Also adds a couple of convenience functions like
checkVector
andtypeError
(used to implementcheckVector
, already in lua 5.4 backend).setReadonly
is something the Luau "conformance tests" were using so I added an API for it too. I think it freezing tables to be read-only enables some VM optimizations, but I'm not sure what exactly. It doesn't seem to affect the behavior of my tests in this patch.The
namecallatom
is a little tricky to understand as I couldn't find good docs for it. But I think it's usage is fairly apparent from thenamecall
test.I used the same types as in the underying API which means the atom pointers in
toStringAtom
andnamecallAtom
are*c_int
. I guess that's required for the Zig->C calling convention but c_ints are not otherwise used in the API so feel a little out of place.