Eloquence B.08.20 introduces automatic code management. Program code that
is not loaded explicitly may be loaded on demand and is discarded when no
This functionality may either be used with Eloquence subroutines and functions
(described below) or Eloquence classes (documented in a
Eloquence automatic code management allows simplifying applications.
Where previously the developer had to ensure all referenced code is defined
in memory and that code no longer needed is eventually removed from memory,
Eloquence can now take over that task.
As applications became more modular and capable, explicit code
management also got more complex.
Depending on the application one is likely to find a number of
LOAD SUB and DEL SUB calls in programs to ensure all referenced code
Some applications have utility procedures to ensure external code is loaded.
Eloquence can now load referenced subroutines and functions on demand and delete
the code when no longer in use or provide developers with the hooks to implement
their own code management.
When enabled and an undefined subroutine or function is referenced, Eloquence will
attempt to locate a matching program file in the path and load all segments (other
than the main segment, same as a LOAD SUB).
Each loaded segment is internally marked as "autoloaded" to distinguish it
from segments defined in the program or explicitly loaded segments.
The Eloquence code management assumes external subroutines and functions
reside in a separate program file, named as the subroutine or function.
For example, a SUB Test is assumed to be defined in a file Test.PROG and a
FNTest$ is assumed to be defined in a program file Test$.PROG.
When a call to an autoloaded subroutine or function ends it is hidden and
eventually is removed from memory. Unused code segments are cached in
memory (to avoid the effort of loading it again) until the amount of
autoloaded code exceeds an internal limit (currently 1 MB).
Once the cache reaches its maximum size segments are deleted in LRU order
(Least Recent Use).
On demand loading of functions and subroutines
A call to a function or subroutine results in an ERROR 7 if it is not defined
in memory. When using automatic code management the function may be loaded
On-demand loading of code is enabled by default. It may be configured in
the Eloquence config file with the OPTION AUTOLOAD.
OPTION AUTOLOAD 1
If the option value is zero autoloading is disabled, otherwise enabled.
The language runtime will use the program PATH (if defined) or the default
volume label (MSI) to load a subroutine or function currently not present.
Each subroutine or function must be defined in a separate PROG file with a
matching name. The following conventions are used:
If a matching PROG file could not be found an ERROR 7 is returned.
- SUB Test -> Test.PROG
- FNTest -> FNTest.PROG
- FNTest$ -> FNTest$.PROG
Code autoload makes use of the NLN mode. Any code segment loaded automatically
is not renumbered but retains the original program line numbers.
ON UNDEFINED CALL
The ON UNDEFINED CALL statement allows customizing the
automatic loading of functions and subroutines by specifying a procedure
that is called if a missing subroutine or function is encountered.
This procedure is passed the name and type of the missing subroutine
or function as the argument. If the "undefined" handler procedure can't
be called a runtime ERROR 49 is returned.
The "undefined" handler procedure is expected to load the missing function.
Upon return from the procedure the failed call is retried (once).
FIXME: Any code loaded by the UNDEFINED procedure is considered autoloaded,
its program lines are not renumbered and it will be discarded once the
cache size is exceeded. Please refer to the
NLN mode documentation for details.
The syntax is:
ON UNDEFINED CALL Procedure
! Ignore any program error, just print an error message
ON ERROR GOSUB E
! Attempts an implicit LOAD SUB "Test1" if on-demand
! loading is enabled
! Specify own undefined handler procedure
ON UNDEFINED CALL Undefined
! Error handler
E: PRINT ERRM$
! Procedure that is called on an undefined segment
PRINT "Undefined: "&N$
This program output is as below:
ERROR 7 IN LINE ..
ERROR 7 IN LINE ..
ERROR 7 IN LINE ..