label command outside of a function

classic Classic list List threaded Threaded
3 messages Options
cdg
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

label command outside of a function

cdg
The book says that Each label b command in a VM function f should generate a globally unique symbol "f$b" where "f" is the function name and "b" is the label symbol within the VM function's code. That makes sense, but what's the convention when a label command occurs outside a function? For example, in ProgramFlow\FibonacciSeries\FibonacciSeries.vm there are no function commands but there are label commands.

One strategy: in such cases, just use the name of the file in which the label command occurs. Another strategy: fix a function name that isn't used anywhere else, e.g. filename.OUTSIDE_ANY_FUNCTIONS.

Maybe I'm worrying about nothing here. But the fact that this case isn't mentioned in the book or on the forum (so far as I could see) makes me suspect I've missed something.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: label command outside of a function

cadet1620
Administrator
I initialize my label prefix to ClassName$ so that label before the first function end up named ClassName$$label which is guaranteed to never collide with functionName$label.

It would also work to just initialize the label prefix to "" in which case you'd get $label for non-function labels.

(Non-function labels and gotos are a test code aberration; the Jack compiler never generates them.)

--Mark
cdg
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: label command outside of a function

cdg
Got it. Thanks!

On Fri, 2 Sep 2016 at 18:31 cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:
I initialize my label prefix to ClassName$ so that label before the first function end up named ClassName$$label which is guaranteed to never collide with functionName$label.

It would also work to just initialize the label prefix to "" in which case you'd get $label for non-function labels.

(Non-function labels and gotos are a test code aberration; the Jack compiler never generates them.)

--Mark


To unsubscribe from label command outside of a function, click here.
NAML
Loading...