|
Lugaru's Epsilon Programmer's Editor 14.04
Context:
|
Epsilon User's Manual and Reference > Primitives and EEL Subroutines > Control Primitives > Bytecode Filesload_commands(char *file)The load_commands( ) primitive loads a bytecode file of command, subroutine and variable definitions into Epsilon after the EEL compiler has produced it from the .e source file. The primitive changes the name provided so that it has the appropriate .b extension, then opens and reads the file. The primitive prints a message and aborts to top-level if it cannot find the file or the file name is invalid. The subroutine load_from_path( ) searches for a bytecode file using the lookpath( ) primitive (see Manipulating File Names) and loads it using load_commands( ).
The load_eel_from_path( ) subroutine searches for an EEL
source file with the specified name using lookpath( ). Then it
compiles and loads the file. Bits in the
The primitive returns
The autoload_commands( ) primitive described below executes any when_loading( ) functions defined in the file, just as load_commands( ) would. Epsilon never arranges for a when_loading( ) function to be autoloaded, and will execute and discard such functions as soon as they're loaded. If you run autoload_commands( ) on a file with when_loading( ) functions, Epsilon will execute them twice: once when it initially sets up the autoloading, and once when it autoloads the file.
The primitive's final parameter should be nonzero to indicate that
the autoloaded function will be a subroutine, or zero if the function
will be a command. (Recall that commands are designed to be invoked
directly by the user, and may not take parameters, while subroutines
are generally invoked by commands or other subroutines, and may take
parameters.) Epsilon enters the command or subroutine in its name
table with a special code to indicate that the function is an
autoloaded function: When Epsilon wants to call an autoloaded function, it first invokes the EEL subroutine load_from_path( ), passing it the file name from the autoload( ) call. The standard definition of this function is in the file control.e. It searches for the file along the EPSPATH, as described in How Epsilon Finds its Files, and then loads the file. The load_from_path( ) subroutine reports an error and aborts the calling function if it cannot find the file. When load_from_path( ) returns, Epsilon checks to see if the function is now defined as a regular, non-autoloaded function. If it is, Epsilon calls it. However, it is not necessarily an error if the function is still undefined. Sometimes a function's work can be done entirely by the when_loading( ) subroutines that are run and immediately discarded as a bytecode file loads. For example, all the work of the set-color command was once done by a when_loading( ) function in the EEL file color.e. (In recent versions, it no longer uses autoloading.) Loading the corresponding bytecode file automatically ran this when_loading( ) function, which displayed some windows and let the user choose colors. When the user exited from the command, Epsilon discarded the code for the when_loading( ) function that displayed windows and interpreted keys, and finishes loading the bytecode file. The set-color command was still defined as a command that autoloads the color.b bytecode file, so the next time the user ran this command, Epsilon loaded the file again. If the autoloaded function was called with parameters, but remains undefined after Epsilon tries to autoload it, Epsilon aborts the calling function with an error message. Functions that use the above technique to load temporarily may not take parameters. Like load_commands( ), the primitive autoload_commands( ) takes the name of a compiled EEL bytecode file as a parameter. It loads any variables or bindings contained in the file, just like load_commands( ). But instead of loading the functions in the file, this primitive generates an autoload request for each function in the file. Whenever any EEL function tries to call a function in the file, Epsilon will load the entire file.
|