How can you get a count of many local variables there are?

There doesn’t seem to be any Glulx opcodes that tell you how many local variables there are. Well if you know the function address you can obtain it fairly easily, but if your code is inserted at a random place and you don’t know the function address it seems quite difficult.

Is there some weird I6 expression that will be compiled into a constant for the number of local variables? Or any other ideas?

I have an idea of how it can be obtained, but it’s pretty convoluted: call @save and store in a memory stream, then parse the Quetzal file, parse its stack chunk, and read the locals count from the final stack frame.

Nope, no such syntax.

A system constant that compiles to this might be doable. Probably just as easy to have a system constant that compiles to the address of the function being compiled.

1 Like

I won’t say you shouldn’t add them, but I probably wouldn’t be able to take advantage of them in I7 extensions for a long time. (Same for getting the address of a label.) Requiring an I6 compiler update to use an extension is just too much to ask. But then if they’re never added, no one could ever take advantage of them… What I’m saying is it’s probably not worth it, and it’s not holding me up. :slightly_smiling_face:

Heh. Understood. Maybe I’ll make a “nice to have” task.

What about determining which variable number (locals offset address) a variable is? Any existing syntax? If not I guess I can try parsing some dummy generated code which uses it.

Nope. #g$GLOB does this for globals, so there’s a pattern, but it doesn’t exist for locals.

I guess I should ask where these syntax patterns are documented. They’re not in the DM4, they’re not in the I6 addendum. Somewhere in the technical manual perhaps?

Ah, I’ve found the specific example of #g$ in the release notes.

Documentation? I grepped the source code.

Took me ten minutes to find the right lines because I started out grepping for $g instead.

That’s useful when you have some idea of what I6 can do already… but if someone were curious about what is possible with all the strange I6 incantations, it seems rereading the changelog is the best way.