Eloquence B.08.20 introduces external class definitions
(classes and its methods defined in a separate file).
Classes and methods may be loaded automatically.
Classes can be defined in a program or in a separate program file
(external classes). If defined in a separate file the following assumptions
External classes may be loaded explicitly in the program with the
LOAD CLASS statement:
LOAD CLASS "Customer"
LOAD CLASS "Customer,CLASSES"
The argument of the LOAD CLASS statement is the name
and optionally path of a program file which implements a class as
described above. If a class path is defined it is used to load
the class defintion instead of the devail volume (MSI).
The program file is opened and classes defined in the main program
segment are registered with Eloquence.
Any member functions in that class are marked as loadable on demand
and are read dynamically when needed.
A class read with the LOAD CLASS statement is subject
to the usual type scoping rules. Unless defined as EXPORT
it is only available in the current program segment (subroutine or function)
and is discarded if the program segment is left.
Member functions for externally defined classes read with the
LOAD CLASS statement are managed dynamically.
They are loaded when used for the first time and deleted either
along with the class or when they have not been used for some time.
Please note: Typically, a class path is defined to make loading
of externally defined classes automatic.
The DEL CLASS statement is used to discard class
definition and any member function of the specified class.
DEL CLASS Typename
The DEL CLASS argument is the type name as specified
in the class definition.
The class definition and any member function is deleted. In case
the class is in use (an instance of that class exists) the deletion of
the class is delayed until any instance is deleted.
It is expected that DEL CLASS is rarely useful in
Defining a Class Path
The Class Path is similar to the Program file path
but affects the LOAD CLASS statement and autoloadinng of
A class path may be defined in the Eloquence config file, through
the EQCLSPATH environment variable or by the
application using the CLSPATH statement.
Eloquence config file
The CLSPATH config item may be used in the config
file (eloq.config or .eloqrc) to specify a class path.
The EQCLSPATH environment variable
The EQCLSPATH environment variable may be used to
specify a path. If present, this pas precendence over a definition
in the config file.
The CLSPATH statement
The CLSPATH statement may be used to specify a path.
This has precendence over a definition in the config file or the
EQCLSPATH environment variable. For example,
On demand loading of classes and methods
Referencing an undefined class or method results in a runtime
error. When using automatic code management class definitions
and methods may be loaded on demand.
On-demand loading of classes is enabled by default. It may be
configured in the Eloquence config file with the OPTION CLSLOAD.
OPTION CLSLOAD 1
If the option value is zero autoloading is disabled, otherwise enabled.
The language runtime will use the class apth (if defined) or the default
volume label (MSI) to load classes and methods currently not present.
Each class must be defined in a separate PROG file with a matching name.
If a matching PROG file could not be found a runtime error is returned.
Code autoload makes use of the NLN mode. Any code segment loaded
automatically is not renumbered but retains the original program
Using a class path
A path affects the LOAD CLASS statement that is
used to load a class definition from a program file (unless an
absolute path or a volume label is specified).
When a class path is defined it also enables autoloading of class
definitions and methods.
A reference to an undefined class will result in loading the
class definition, calling a cals method not currently in memory
will load the method from the class file.
The CLSPATH statement may be used by an application
to specify a class path. This class path is active until another
class path is assigned. An empty string may be used to specify an
empty class path (and disable use of class path).
The CLSPATH$ function may be used to obtain the
currently active class path. It returns an empty string if no
class path is active.
The example below adds the "HOME"/cls directory as a first element
of the class path and then loads the program file "START".
Loading classes automatically
If enabled, the language runtime will load class definitions and
methods on demand. The .PROG file name must match the class name.
The example below demonstrates the use of autoloading of classes and
--- Tsample.PROG ---
IF BACKGROUND THEN PRINTER IS STDOUT
NEW A AS Tsample2
--- Tsample1.PROG ---
PRINT "Tsample1: ";TYPEOF$(THIS)
PRINT "Tsample1: ";TYPEOF$(THIS)
--- Tsample2.PROG ---
TYPE Tsample2 EXTENDS Tsample1
PRINT "Tsample2: ";TYPEOF$(THIS)
Running the Tsample program causes the loading of the class definition
Tsample2 which in turn will load the class definition Tsample1. It then
prints the result below:
Since the Tsample2 class does not define a method Test it falls back to the
Test method provided by the base class. However, since the type of the object
is still Tsample2 this gets printed.
Next, the appropriate Print method gets called.
The class methods in this example are loaded as needed.