Function labels

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Function labels

asev98
I can't understand how should I choose a name for my function. In the slide 22 there's written "each label b command in a VM function f should generate a globally unque symbol f&b..." I don't understand how to "build" these symbol. It says that f is the name of the function, for example foo, and "b is the label within VM function's code", where? Then it refers to the function saying "goto b", so it seems to me that also b is the name of the function. Someone can explain me this?
Reply | Threaded
Open this post in threaded view
|

Re: Function labels

cadet1620
Administrator
There are two different types of names.

Vm function command names are used by VM call commands. The name must be unmodified so that call commands in other VM files can call the function. For example, the VM command
function Sys.main
generates the assembly language label
(Sys.main)

Vm label command names are used by VM goto and if-goto commands to build loops and conditional code within individual functions. A label command in function Main.main may use the same name as a label command in function Main.run, so the name must be modified.

The suggested modification is to combine the name of the current function with the label command's name using a '$' character. For example
function Main.main
...
label loop
...
goto loop
...
function Main.run
...
label loop
...
goto loop
generates the assembly language
(Main.main)
...
(Main.main$loop)
...
@Main.main$loop
0;JMP
...
(Main.run)
...
(Main.main$run)
...
@Main.main$run
0;JMP
Reply | Threaded
Open this post in threaded view
|

Re: Function labels

asev98
It's like writing std::mult in C. In f$b f is the function father of label b that is the label son of function f.
So I could write loop1, loop2 etc. instead of f$b and it would work in the same way, it would be just a lot more difficult understanding and reading the code.
This gave me another doubt: this label naming convention should be applied only to function's labels or to every label in asm?