Main interface to the reflexive compiler.
class Compiler( [path] ) \ from _BaseCompiler
compile() | Compiles a script on the fly. |
loadByName() | Loads a module given its logical name. |
loadFile() | Loads a Falcon resource from a location on the filesystem. |
alwaysRecomp from _BaseCompiler | If true, a load method finding a valid .fam that may substitute a .fal will ignore it, and will try to compile and load the .fal instead. |
compileInMemory from _BaseCompiler | If true (the default) intermediate compilation steps are performed in memory. |
ignoreSources from _BaseCompiler | If true, sources are ignored, and only .fam or shared object/dynamic link libraries will be loaded. |
language from _BaseCompiler | Language code used to load language-specific string tables. |
launchAtLink from _BaseCompiler | If true, the __main__ function (that is, the entry point) of the loaded modules is executed before returning it. |
path from _BaseCompiler | The search path for modules loaded by name. |
saveMandatory from _BaseCompiler | If true, when saveModule option is true too and a module can't be serialized, the compiler raises an exception. |
saveModules from _BaseCompiler | If true, once compiled a source that is located on a local file system, the compiler will also try to save the .fam pre-compiled module, that may be used if the same module is loaded a second time. |
sourceEncoding from _BaseCompiler | The encoding of the source file. |
addFalconPath from _BaseCompiler | Adds the default system paths to the path searched by this compiler. |
setDirective from _BaseCompiler | Compiles a script on the fly. |
class Compiler( [path] ) \ from _BaseCompiler
path | The default search path of the compiler. |
Main interface to the reflexive 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).
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. | ||||
Returns: | On success, a Module instance that contains the compiled module. | ||||
Raises: |
|
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.
Loads a module given its logical name.
Compiler.loadByName( modName )
modName | The logical name of the module to be loaded. | ||||
Returns: | On success, a Module instance that contains the loaded module. | ||||
Raises: |
|
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.
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. | ||||
Returns: | On success, a Module instance that contains the loaded module. | ||||
Raises: |
|
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.