LOCAL Declaration
Syntax:
LOCAL name AS typeLOCAL name() AS typeLOCAL name AS type [subscripts]
Description
The LOCAL statement declares one or more variables that are local to the current procedure (FUNCTION or SUB). Local variables are created on the stack when the procedure is entered and destroyed when the procedure returns. They are not visible outside the procedure in which they are declared.
Local variables are the most common type of variable declaration in PBXA64. They provide automatic storage management and prevent naming conflicts between procedures. When #DIM ALL is active, every local variable must be declared with LOCAL before use.
Arrays are declared by appending empty parentheses () or by specifying subscript bounds.
Parameters
| Parameter | Description |
|---|---|
name | The identifier name of the variable. Must follow PBXA64 naming rules and be unique within the procedure scope. |
AS type | The data type. Supported types: LONG (64-bit signed), DWORD (32-bit unsigned), INTEGER (16-bit signed), BYTE (8-bit unsigned), WORD (16-bit unsigned), SINGLE, DOUBLE, QUAD (64-bit signed), CUR (currency), EXT (extended precision), STRING, and user-defined TYPEs. |
subscripts | Optional. Specifies array bounds: (lower TO upper) or (upper) which implies (0 TO upper). Multi-dimensional arrays use comma-separated bounds. |
Example
FUNCTION Calculate(BYVAL radius AS DOUBLE) AS DOUBLE
LOCAL area AS DOUBLE
LOCAL pi AS DOUBLE
LOCAL results(1 TO 3) AS DOUBLE
pi = 3.14159265358979
area = pi * radius * radius
results(1) = radius
results(2) = area
results(3) = 2.0 * pi * radius ' circumference
PRINT "Radius: "; results(1)
PRINT "Area: "; results(2)
PRINT "Circumference: "; results(3)
FUNCTION = area
END FUNCTION
Generated Assembly
Stack Frame Allocation
; In the function prologue, the compiler calculates the total size ; of all LOCAL variables and subtracts it from RSP: sub rsp, 0x40 ; Allocate 64 bytes for locals ; Variables are placed at fixed negative offsets from RBP: ; LOCAL pi AS DOUBLE -> [rbp - 8] ; LOCAL area AS DOUBLE -> [rbp - 16] ; LOCAL results(3) AS DOUBLE -> [rbp - 24] to [rbp - 48]
Variable Access
; Read: x = pi movsd xmm0, [rbp - 8] ; Load DOUBLE into XMM0 ; Write: area = 3.14 movsd [rbp - 16], xmm0 ; Store DOUBLE from XMM0 ; Array element: results(2) = value mov rax, 2 ; index sub rax, 1 ; adjust for 1-based imul rax, 8 ; offset = index * 8 movsd [rbp - 24 + rax], xmm0 ; store at calculated offset
Notes
LOCALdeclarations must appear at the top of a procedure, before any executable statements.- Local variables are not initialized automatically. Their initial values are undefined unless explicitly assigned.
- Local variables take precedence over
GLOBALvariables with the same name within the procedure scope. - In PBXA64,
LONGis a 64-bit signed integer. UseDWORDfor 32-bit unsigned values andINTEGERfor 16-bit values. - String variables declared with
LOCALare dynamic and can hold strings of any length (subject to available memory).