2.2.1Class Compiler

Main interface to the reflexive compiler.

Class Compiler( [path] ) from \
                 _BaseCompiler( )
path The default search path of the compiler.

The static compiler class is an interface to the compilation facilities and the vritual machine currently running the caller Falcon program.

Compiled resources (either external binary modules or falcon scripts, that can be stored on external resources or compiled on-the-fly) are integrated in the running virtual machine as a separate module, immediately linked and made runnable. The caller script receives a Module instance which can be used to control the execution of the target module, or to unload it at a later time.

The linked modules receive every globally exported symbol that is accessible to the caller script, but their export requests are ignored (they can't modify the global execution environment of the calling script).

Although a single compiler should be enough for the needs of a simple script program, it is possible to create as many instances of the compiler as needed.

However, it is sensible to instance this class through singleton objects, so that they get prepared by the link step of the VM:


      load compiler

      object MyCompiler from Compiler
      end

Note: If path is not provided, defaults to "." (script current working directory).

Methods
compileCompiles a script on the fly.
loadByNameLoads a module given its logical name.
loadFileLoads a Falcon resource from a location on the filesystem.
Properties inherited from class _BaseCompiler
alwaysRecomp If true, a load method finding a valid .
compileInMemory If true (the default) intermediate compilation steps are performed in memory.
ignoreSources If true, sources are ignored, and only .
language Language code used to load language-specific string tables.
launchAtLink If true, the main function (that is, the entry point) of the loaded modules is executed before returning it.
path The search path for modules loaded by name.
saveMandatory If true, when saveModule option is true too and a module can't be serialized, the compiler raises an exception.
saveModules If true, once compiled a source that is located on a local file system, the compiler will also try to save the .
sourceEncoding The encoding of the source file.
Methods inherited from class _BaseCompiler
addFalconPathAdds the default system paths to the path searched by this compiler.
setDirectiveCompiles a script on the fly.

Methods

compile

Compiles a script on the fly.

Compiler.compile( modName, data )
modName A logical unique that will be given to the module after compilation.
data The data to compile. It may be a string or a stream valid for input.
ReturnOn success, a Module instance that contains the compiled module.
Raise
SyntaxError if the module contains logical error.
IoError if the input data is a file stream and there have been a read failure.

Tries to compile the module in the data parameter. On failure, a SyntaxError is raised; the subErrors member of the returned error will contain an array where every single compilation error is specified.

On success, an instance of Module class is returned.

loadByName

Loads a module given its logical name.

Compiler.loadByName( modName )
modName The logical name of the module to be loaded.
ReturnOn success, a Module instance that contains the loaded module.
Raise
SyntaxError if the module contains logical error.
IoError if the input data is a file stream and there have been a read failure.

Tries to load a logically named module scanning for suitable sources, pre-compiled modules and binary modules in the search path. In case a suitable module cannot be found, the method returns nil. If a module is found, a CodeError is raised in case compilation or link steps fails.

loadFile

Loads a Falcon resource from a location on the filesystem.

Compiler.loadFile( modPath, [alias] )
modPath Relative or absolute path to a loadable Falcon module or source.
alias Alias under which the module should be loaded.
ReturnOn success, a Module instance that contains the loaded module.
Raise
SyntaxError if the module contains logical error.
IoError if the input data is a file stream and there have been a read failure.

Loads the given file, trying to perform compilation or loading of the relevant .fam precompiled module depending on the property settings. In example, if loading "./test.fal", unless alwaysRecomp property is true, "./test.fam" will be searched too, and if it's found and newer than ./test.fal, it will be loaded instead, skipping compilation step. Similarly, if "./test.fam" is searched, unless ignoreSource is true, "./test.fal" will be searched too, and if it's newer than ./test.fam it will be recompiled.

If alias parameter is given, the loaded modules assumes the given name. The same naming conventions used by the load directive (names starting with a single "." or with "self.") are provided. Notice that the path separators are NOT automatically transformed into "." in the module logical name, so to import the module under a local namespace, using this parameter is essential.

In case a suitable module cannot be found, the method returns nil. If a module is found, a CodeError is raised in case compilation or link steps fails.

Made with http://www.falconpl.org