Index | PAL Intro | Commands | Registers | Indices | Stack | Macros | Classes | Attributes | Errors
func/def - Define a new program function
Synopsis
Description
Declaring A Return Value
Declaring Formal Parameters
Error Handling
Examples
See Also
Author
func/def [name], &[.codeptr]
func/def [name], &[.codeptr], returntype
func/def [name], &[.codeptr], returntype, partype, [parname] <, partype, [parname] ... >
Creates a new function object underneath the current executing object in the nexus, and attaches program code to it. This is the standard way in PROSE to initialise a function, and is usually called in the ._init section.
The name of the function should be provided in the read argument name, while the supporting code for the function is pointed to by a code label, identified in the read argument codeptr.
The name may be a dot-separated path if the node 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 (\).
Functions may optionally return a variable object as well as accept variable objects as arguments. If they need to do so, the return value and/or formal parameters need to be declared. See DECLARING A RETURN VALUE and DECLARING FORMAL PARAMETERS.
If a function is to return a variable, the returntype argument must be supplied. This defines the type of variable that the function will return and is the name of an object attribute supplied as text, or a PSUNIT_TYPE_ATTRDEF register returned by the attr/load instruction. The type must be a variable type as defined in ps_attributes(5).
When a variable object is returned by a function using the func/rtn instruction, it is made available to the caller as an encoded attribute value (PSUNIT_TYPE_XVALUE) in the write register identified by the func/call or func/bcall instruction.
If returntype is missing or NULL, the function will not be able to return a value and the write register will be unaffected in the caller.
If a function is to accept variables passed to it as arguments, formal parameters must be declared using one or more pairs of partype and parname.
The partype arguments define the type of variable accepted by each successive parameter and is the name of an object attribute supplied as text, or a PSUNIT_TYPE_ATTRDEF register returned by the attr/load instruction. The type must be a variable type as defined in ps_attributes(5).
The parname arguments supply the name of each successive parameter. This defines the variable name that will be automatically created using var/local when the function is called, in order to store the value of each argument supplied by the caller.
A runtime error occurs if an argument is of the wrong type, or if a named attribute does not exist in the schema.
func/def [copy], &[.copy] Creates a function called copy with code provided by the section identified by the .copy code label. This function returns no value and accepts no parameters. func/def [move], &[.move], [psInteger] Creates a function called move with code from .move. This function returns a GMP integer. It accepts no parameters. func/def [shift], &[.shift_main], NULL, [psString], [s] Creates a function called shift with code from .shift_main. This function returns no value. It accepts a single parameter "s" which is a string type.
pal_intro(5), pal_commands(5), pal_indices(5), ps_attributes(5), func_call(5), func_addr(5), func_rtn(5), var_local(5),
PROSE Assembly Language at prose.sourceforge.net.
Copyright (c) 2002-2013 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 | func_def (5) | 8 March 2013 |