Difference between revisions of "Plugins"

From Liberty Eiffel Wiki
Jump to navigation Jump to search
(no space before a semi-colon)
(→‎C Generation: includes file)
(8 intermediate revisions by the same user not shown)
Line 10: Line 10:
   
 
* the Eiffel side, which provides an interface usable by other Eiffel objects ;
 
* the Eiffel side, which provides an interface usable by other Eiffel objects ;
* the external side, which implements the plugin's interface for one or several [[Glossary#BackEnd|back-ends]] (forr example, C and Java).
+
* the external side, which implements the plugin's interface for one or several [[Glossary#BackEnd|back-ends]] (for example, C and Java).
   
 
The Eiffel side is 100% Eiffel code, and it uses ''external'' features that allow crossing the barrier to the other side of the plugin. The barrier is managed by SmartEiffel : the compiler associates external functions with the ''external'' features using configuration files furnished by the plugin.
 
The Eiffel side is 100% Eiffel code, and it uses ''external'' features that allow crossing the barrier to the other side of the plugin. The barrier is managed by SmartEiffel : the compiler associates external functions with the ''external'' features using configuration files furnished by the plugin.
Line 49: Line 49:
 
* all the <TT>.h</TT> files, which are included in the compiler-generated header file
 
* all the <TT>.h</TT> files, which are included in the compiler-generated header file
 
* the <TT>libs</TT> file, which contains a description of the native libraries to link
 
* the <TT>libs</TT> file, which contains a description of the native libraries to link
* the <TT>paths</TT> file, which contains a description of the paths used to find the libraies
+
* the <TT>paths</TT> file, which contains a description of the paths used to find the libraries
  +
* the <TT>includes</TT> file, whilch contains a description of the paths used to find header files
   
 
The '''<TT>.c</TT> and <TT>.h</TT>''' files are included in alphabetic order.
 
The '''<TT>.c</TT> and <TT>.h</TT>''' files are included in alphabetic order.
   
The '''<TT>libs</TT> and <TT>paths</TT>''' files use an identical syntax to that of the [[configuration file]].
+
The '''<TT>includes</TT>, <TT>libs</TT> and <TT>paths</TT>''' files use an identical syntax to that of the [[configuration file]].
   
 
The sections carry the operating system name, the ''flavor'' from the configuration file and finally the C compiler used, in that order and separated by a period. If the plugin doesn't depend on one of these elements, it can be omitted.
 
The sections carry the operating system name, the ''flavor'' from the configuration file and finally the C compiler used, in that order and separated by a period. If the plugin doesn't depend on one of these elements, it can be omitted.

Revision as of 14:47, 20 March 2006


Plugins are a means to augment in a spectactular manner the capabilities of SmartEiffel, by incorporating libraries which have the color, smell, and taste of the standard libraries. In fact, it's an extension of the standard Eiffel mechanism, externals.

The goal of plugins is independence from the back-end. This means that, potentially, the same library could be used simultaneously by compile_to_c and compile_to_jvm. Note that in the future we want to provide other back-ends. In this case, the plugin system will become more important.

How does it work ?

A plugin is made up of two interdependent parts :

  • the Eiffel side, which provides an interface usable by other Eiffel objects ;
  • the external side, which implements the plugin's interface for one or several back-ends (for example, C and Java).

The Eiffel side is 100% Eiffel code, and it uses external features that allow crossing the barrier to the other side of the plugin. The barrier is managed by SmartEiffel : the compiler associates external functions with the external features using configuration files furnished by the plugin.

Eiffel Side

The Eiffel side uses external features. The syntax is as follows:

feature
   my_plugin_feature is
      external "plug_in"
      alias "{
         location: "/path/to/my/plugins"
         module_name: "my_plugin"
         feature_name: "feature"
      }"

Of course, a feature can take arguments and return a result ! (after all, it's an external) ;-)

Beware however, it is necessary to only pass and return only basic expanded base types : (INTEGER, BOOLEAN, etc.) or use POINTER (common usage: a_string.to_external).

  • location indicates the directory where you store one or many of your plugins. This path can contain environment variables (either true system environment variables, or variables definined in the [Environment] section of your configuration file).

For example, the standard SmartEiffel libraries are defined by using the following location:

location: "${sys}plugins"
  • module_name contains the plugin name itself. This must be the name of a sub-directory of location that contains a directory for a specific back-end (for example, c for the C generator, java for the Java generator). The content of each of these sub-repositories depends on the generator, and is specified below.
  • feature_name is the name of the feature, function, method etc. named by the back-end (for example, C calls functions, Java calls methods). What they're called is not important : they're all features ;-)

Dark side

C Generation

The C back-end uses a sub-directory of your plugin named c. the files used are:

  • all the .c files, which are included in the compiler-generated C files
  • all the .h files, which are included in the compiler-generated header file
  • the libs file, which contains a description of the native libraries to link
  • the paths file, which contains a description of the paths used to find the libraries
  • the includes file, whilch contains a description of the paths used to find header files

The .c and .h files are included in alphabetic order.

The includes, libs and paths files use an identical syntax to that of the configuration file.

The sections carry the operating system name, the flavor from the configuration file and finally the C compiler used, in that order and separated by a period. If the plugin doesn't depend on one of these elements, it can be omitted.

The keys in these files are only informative; however, the values are used to generate command line calls to the C compiler.

For an example, you can examine the configurations files for Vision.

Note: when there are no arguments, names are generated without parentheses. This permits to attributes, variables and to macros. The absence of parentheses is not then a bug but a desired behavior. In the case where one wants access to a function without an argument, it suffices to use a macro to replace a name without parentheses with the name of the function to call.

Java Generation

For the Java back-end, the plugin sub-directory must be named java. The compiler uses the following files :

  • the .java files are compiled using the command line options and/or from the configuration file (see compile_to_jvm for more detail). The .class files so generated are automatically copied in the compilation directory of the program.
  • the .class files, if they are present and if they are more recent than the corresponding .java files are utilized in place of a compilation of the .java files, in the same manner as the make command under UNIX.

To shorten the compilation time of a program dependent on plugins supplied with the compiler (like for example the io plugin), the installer will compile the .java plugin files during installation.