Using the ..LOCALS Compiler Directive
The syntax of the ..LOCALS compiler directive is:
..LOCALS local_vars common_symbols
This command is useful when you want to place the EXECUTE function inside a procedure or function. EXECUTE takes a string parameter containing a PV-WAVE command. This command argument is compiled and executed at runtime, allowing the possibility for command options to be specified by the user. Because the data area is compressed after compilation, there may not be enough room for additional local variables and common block symbols created by EXECUTE. The ..LOCALS command provides a method of allocating extra space for these additional items.
The ..LOCALS compiler directive is similar to the .LOCALS executive command, except:
..LOCALS is only used inside procedures and functions.
Its arguments specify the number of
additional local variables and common block symbols that will be needed at “interpreter” time (when the already-compiled instructions are interpreted).
It is used in conjunction with the EXECUTE function, which can create new local variables and common block symbols at runtime.
Example 1
In this example, ..LOCALS is not needed. This simple procedure does not use the EXECUTE function to create new variables or common blocks.
PRO mypro1, a
COMMON c, c1, c2
a=10
END
Example 2
In this example, a new common block (d) and a new variable (x) are created with two calls to the EXECUTE function. The ..LOCALS directive creates additional space for one variable (x) and two common block symbols (d1 and d2).
PRO mypro2, a
..LOCALS 1 2
COMMON c, c1, c2
j=EXECUTE('COMMON d, d1, d2')
a=10
b=20
j=EXECUTE('x=30')
END
Example 3
The following procedure can create up to 20 new local variables, as specified by the user at runtime. This example is more realistic than the previous one, because here you do not know how many new variables will be needed until runtime. In this case, however, if i is greater than 20, the data area may fill up.
PRO mypro3, i
..LOCALS 20
for j=1, i DO BEGIN
k=EXECUTE('var'+STRTRIM(STRING(j),2)+'=0')
ENDFOR
END
This procedure creates i local variables:
VAR1=0
VAR2=0
VAR3=0
VARi=0
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.