15.7 Fluid and Global Declarations

Fluid and global declarations must be used to indicate variables that are to be used as non-local variables in compiled code. The values associated with local variables are stored on a stack. If a variable has been declared global or fluid then the compiled code will instead access the value cell of that variable. In addition the content of the value cells of special variables being used as formal parameters must be preserved. The compiler currently defaults variables bound in a particular function to local. Note that local variables exist as anonymous stack locations, therefore called functions cannot see them. An undeclared non-local variable is declared fluid by the compiler with the warning:

⋆⋆⋆ NAME declared fluid

The appearance of this message may indicate an additional error. If a previous function used this name in the parameter list then it may have to be recompiled. The local variable in the previous function will not refer to the same variable as the one recently declared fluid, even though the names are the same in the source code listing.

Previous documentation has given users the impression that it is illegal to bind an id which has been declared global. This is not true, an attempt to bind a global variable will cause the following message to be displayed.

⋆⋆⋆ Illegal to bind global VARIABLE but binding anyway

The lack of distinction between global and fluid in PSL appears to be due to the fact that shallow binding is employed in PSL. In a deep bound system one has to search down a binding stack to locate the value of a fluid id, which could get expensive. A global declaration within a deep bound system would allow the interpreter to assume that the value of an id is in a fixed location. Of course in a shallow bound system the value of a id is always found in the value cell of that id.