IEEE
CORE REQUIREMENTS AND PRACTICES Std 1275-1994
3.2.3.1 Instance chains
A package is opened from a device path (or equivalent device alias) that specifies the path from the root of the
device tree to the device in question. Each component of that path, beginning at the root, is opened, creating an
instance for each device in the path. The instances are linked together so that each package instance may locate
the instance of its parent.
When an instance is no longer needed (i.e., the program that opened a package decides that it will no longer need
the function provided by that package), the instance may be closed, thus freeing the memory used by its private
data and perhaps deactivating devices controlled by that package or its parents. An instance may be closed
individually or the entire instance chain to which it belongs may be closed. In the latter case, the instances in the
chain are closed in the order opposite to the order in which they were opened. In other words, an instance is closed,
and then its parent instance is closed, and then its parent’s parent, and so on.
3.2.3.2 Instance methods
Before using a package method, in most cases the package must first be opened, thus creating an instance. The
instance is represented by an ihandle, a numerical value that refers to a particular instance. At any given time, one
instance, at most, may be the current instance. The private data of the current instance is accessible; the private
data of other instances is not.
In order to use a package method, its instance must be made current.
To call a method from another method within the same package, no special action need be taken; since the
appropriate instance must already be the current instance for the calling method to run, the called method may be
invoked directly, without changing the current instance.
To call a package method from the “outside” (i.e., from some execution context other than the instance containing
the method in question), a different approach is used. The caller identifies both the method to be called and the in-
stance that is to be current for the duration of that method’s execution. There are various commands for calling
methods, differing in the forms of method and instance identification. In general, such a command saves the
ihandle of the current instance by pushing it on the return stack, makes the called instance the current instance,
executes the method, and then pops the saved ihandle from the return stack, restoring the current instance to that
value.
The caller must know the ihandle of the instance corresponding to the method to be called. There are two common
ways to acquire this knowledge:
— The caller may have opened the package whose method is to be called. The process of opening a package
returns the resulting ihandle, which the caller may save for later use in calling the ihandle’s associated
methods.
— The package to be called may be the parent of the calling instance. As mentioned in 3.2.3.1, each instance
automatically knows the ihandle of its parent.
A static method can be executed at any time, regardless of whether or not its package is open. It can be executed
directly by other methods within the same package, or its execution token may be passed to execute or catch
or stored in a defer word for later execution. There are various ways to determine its execution token in various
circumstances, for example, find-method or ['].'
19