Store a label's address in a variable

How can the address of a label (or any instruction) be stored in a variable, for later use with @jumpabs? Any crazy solutions accepted…

Okay I’ve found this process. It’s not even all that convoluted really.

jump MyLabel_Catch;
.MyLabel_Catch_Continue;
@stkpeek 1 res;
print "label address: ", res, "^";

...

jump MyLabel;
.MyLabel_Catch;
@catch temp ?MyLabel_Catch_Continue;
.MyLabel;

The two blocks of code don’t have to be next to each other, and you don’t have to call MyLabel this time through the function. I probably should be cleaning up the call stub that got pushed onto the stack… but I don’t remember how to throw away values off the stack.

1 Like

This is not a question I expected to come up. :) I’ll have to re-read the docs to think about the call stub question!

It doesn’t seem difficult to provide a special language syntax for getting the address of a label within a Glulx function. (Z-code label addresses don’t generally fit in a 16-bit variable, so this would be Glulx only.) However, as with the example above, you’d have to actually enter the function to generate the value. Getting the address of an arbitrary label would be a lot more work, because the compiler throws away label offsets when it reaches the end of the function.

1 Like

Hm, not to say it would be easy… it would require a new trick in the backpatching system.