Index | PAL Intro | Commands | Registers | Indices | Stack | Macros | Classes | Attributes | Errors
var/def - Define a new variable object
Synopsis
Description
Error Handling
Examples
See Also
Author
var/def write, attribute, ![target], [name], value
var/def write, attribute, ![target], [name]var/local write, attribute, [name], value
var/local write, attribute, [name]var/static write, attribute, [name], value
var/static write, attribute, [name]var/global write, attribute, [name], value
var/global write, attribute, [name]
Defines a new variable object with the type specified in the attribute argument. The type must be a variable type as defined in ps_attributes(5). The variable will be called name and assigned the optional value. A reference to the resulting object will be stored in the write register as a PSUNIT_TYPE_NODE.
The var/def instruction takes a target argument, which is the object underneath which to create the new variable.
The var/local instruction defines the variable in the instance container. This is for creating variables that are local to the current function and which will be unique for each instance of that function.
The var/static instruction defines the variable underneath the current executing object. This is for creating variables that are local to the current function but for which each function instance shares the same value.
The var/global instruction defines the variable underneath the module root. This is for creating variables that have global scope and may be referenced by any function within the module.
In all cases, if the object already exists the necessary classes and attributes will be added to the object to make it suitable for use as a variable. If the target object was already a variable of the same type with a value, and a new value is supplied by this instruction, it will replace the old value.
The attribute is either a text argument containing the name of the object attribute to add, or a PSUNIT_TYPE_ATTRDEF register returned by the attr/load instruction. The attribute must be a variable type as defined in ps_attributes(5).
The name may be a dot-separated path if the variable is to be created underneath a subcontainer. If the path doesnt already exist, it will be created. If a dot needs to be used in a name then prefix it with a backslash character (\).
The value is an argument containing the data to add to the attribute. If value is a register containing the type PSUNIT_TYPE_STRING or PSUNIT_TYPE_XVALUE and the instruction does not generate an error, then the register will be cleared as the data is now referenced elsewhere.
If value is encoded data (PSUNIT_TYPE_XVALUE) and the data encoding is not of an appropriate syntax to be stored directly in the selected attribute, then it will be re-encoded as a byte string before processing.
A runtime error is generated if an argument is of the wrong type, if a named attribute does not exist in the schema, or if a referenced object does not exist in the nexus.
The following demonstrates creating two different variables, one global string and a local pointer to the string.
.main % Create a global string variable attr/load P8, [psString], P9, [psPointer] var/global P0, P8, [gstring], [Air on a G String]
% Create a local pointer variable, % discarding the new reference var/local NULL, P9, [pstring], P0
% Obtaining reference to pstring variable % at a later time ... var/addr P0, [pstring]
% Follow the pointer reference ... attr/addr P0, P0, P9
pal_commands(5), pal_registers(5), pal_indices(5), ps_attributes(5), var_addr(5), attr_add(5), mtx_def(5), itree_def(5), xtree_def(5),
PROSE Assembly Language at prose.sourceforge.net.
Copyright (c) 2002-2017 Mark R. Bannister <cambridge@users.sourceforge.net>.
This is free software and can be downloaded from prose.sourceforge.net; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
PAL 1.0 | var_def (5) | 31 July 2017 |