Difference between revisions of "Cecil"
(to be translated...) |
(in French, English words are in italics. In English, they don't need to ;-)) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Book]] |
[[Category:Book]] |
||
+ | Cecil is a mecanism that permits to call Eiffel code from C. In this way, it is the opposite of [[externals]]. |
||
− | *** Please translate this page from French |
||
+ | |||
− | *** Thanks! |
||
+ | In order to call Eiffel from C, you must use the flag <TT>-cecil <cecil_file></TT> with [[compile]] or [[compile_to_c]]. The file <TT><cecil_file></TT> must give the list of [[Glossary#Feature|features]] that you want to call from C. The stub routines are automatically generated by SmartEiffel. |
||
+ | |||
+ | When the flag <TT>-cecil</TT> is used, [[compile_to_c]] also produces one more C header file, which contains all stubs routines prototypes. |
||
+ | |||
+ | Your <TT><cecil_file></TT> file must contain at least two lines. The first line is the name of the C header file to produce (a <TT>.h</TT> file). The others lines have the following structure: |
||
+ | |||
+ | <c_name> <eiffel_type> <feature_name> |
||
+ | |||
+ | The <TT><c_name></TT> is the name of the C stub routine that wraps the Eiffel call. The couple <TT><eiffel_type> <feature_name></TT> give the complete name of the Eiffel [[Glossary#Feature|feature]] to call. |
||
+ | |||
+ | You can also put Eiffel-style comments. |
||
+ | |||
+ | For example: |
||
+ | |||
+ | -- features from STRING : |
||
+ | StringIsEmpty STRING empty |
||
+ | StringItem STRING item |
||
+ | StringGT STRING infix ">" |
||
+ | -- features from ARRAY[INTEGER] : |
||
+ | IntArrayCount ARRAY[INTEGER] count |
||
+ | IntArrayItem ARRAY[INTEGER] item |
||
+ | -- features from X : |
||
+ | X_f X f |
||
+ | |||
+ | Please note that the <TT><type_eiffel></TT> must be a [[Glossary#LiveType|'''live type''']]. For example, if the <TT><eiffel_type></TT> is [[library_class:ARRAY|<TT>ARRAY</TT>]]<TT>[</TT>[[library_class:INTEGER|<TT>INTEGER</TT>]]<TT>]</TT>, your Eiffel program must at least create one instance of type [[library_class:ARRAY|<TT>ARRAY</TT>]]<TT>[</TT>[[library_class:INTEGER|<TT>INTEGER</TT>]]<TT>]</TT>. |
||
+ | |||
+ | The name of the [[Glossary#Feature|feature]] to call, <TT><feature_name></TT>, can be a prefix or infix name. The [[Syntax_diagrams#FeatureName|syntax]] is the same as the one used in the Eiffel source code. |
||
+ | |||
+ | Nota bene: |
||
+ | * since attributes are [[Glossary#Feature|features]], it is of course possible to access them with this mecanism. |
||
+ | * The [[Glossary#LateBinding|late binding]] is also taken in account. In the above example, a call to <TT>X_f()</TT> in C is equivalent to the call <TT>x.f</TT> in Eiffel, with <TT>x</TT> of type <TT>X</TT> ''or a descendant of <TT>X</TT>''. |
||
+ | |||
+ | Here is another example of a Cecil file (other can be found in the tutorial <TT>SmartEiffel/tutorial/cecil</TT>): |
||
+ | -- The name of the include C file: |
||
+ | eiffel.h |
||
+ | -- The features you want to call from C: |
||
+ | array_of_animal_item ARRAY[ANIMAL] item |
||
+ | array_of_animal_lower ARRAY[ANIMAL] lower |
||
+ | array_of_animal_upper ARRAY[ANIMAL] upper |
||
+ | cry ANIMAL cry |
||
+ | string_to_external STRING to_external |
Revision as of 00:01, 9 July 2005
Cecil is a mecanism that permits to call Eiffel code from C. In this way, it is the opposite of externals.
In order to call Eiffel from C, you must use the flag -cecil <cecil_file> with compile or compile_to_c. The file <cecil_file> must give the list of features that you want to call from C. The stub routines are automatically generated by SmartEiffel.
When the flag -cecil is used, compile_to_c also produces one more C header file, which contains all stubs routines prototypes.
Your <cecil_file> file must contain at least two lines. The first line is the name of the C header file to produce (a .h file). The others lines have the following structure:
<c_name> <eiffel_type> <feature_name>
The <c_name> is the name of the C stub routine that wraps the Eiffel call. The couple <eiffel_type> <feature_name> give the complete name of the Eiffel feature to call.
You can also put Eiffel-style comments.
For example:
-- features from STRING : StringIsEmpty STRING empty StringItem STRING item StringGT STRING infix ">" -- features from ARRAY[INTEGER] : IntArrayCount ARRAY[INTEGER] count IntArrayItem ARRAY[INTEGER] item -- features from X : X_f X f
Please note that the <type_eiffel> must be a live type. For example, if the <eiffel_type> is ARRAY[INTEGER], your Eiffel program must at least create one instance of type ARRAY[INTEGER].
The name of the feature to call, <feature_name>, can be a prefix or infix name. The syntax is the same as the one used in the Eiffel source code.
Nota bene:
- since attributes are features, it is of course possible to access them with this mecanism.
- The late binding is also taken in account. In the above example, a call to X_f() in C is equivalent to the call x.f in Eiffel, with x of type X or a descendant of X.
Here is another example of a Cecil file (other can be found in the tutorial SmartEiffel/tutorial/cecil):
-- The name of the include C file: eiffel.h -- The features you want to call from C: array_of_animal_item ARRAY[ANIMAL] item array_of_animal_lower ARRAY[ANIMAL] lower array_of_animal_upper ARRAY[ANIMAL] upper cry ANIMAL cry string_to_external STRING to_external