On Mon Jun 12 15:46:39 2023 +0000, Gabriel Ivăncescu wrote:
So to summarize, I move all detached scope locals to the scope's jsdisp, accessed by index (from lookup_local). If so, what would the point of "detached locals buffer" be? Or was that just an alternative? I mean I could store the local's value itself directly into the scope's props, no need to keep a separate buffer, I think. I'll only have to map indexed args into props with idx_get/put, and for arguments with "no name" (shadowed by duplicated names, or extra args passed to a func) maybe just store them with prop name = index, since locals can't have names starting with a digit… I think it should work, unless I'm missing something.
That would again special case shadowed arguments instead of making them a non-issue by design. That also wouldn't make values easily available to arguments object, so you'd need some unpleasant lookups there.
Also, performance. Copying an array is much cheaper than allocating props and gives further possible optimizations. Although we currently alloc props when addressing indexed properties, we could probably avoid that at least for objects with constant length. Interpreter could optimize the access by using the same code as we use for attached locals by accessing the buffer directly. That combined with compiler optimization that I mentioned could probably get rid of vast majority of lookups.