File: cecil.html

package info (click to toggle)
smarteiffel 1.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 12,288 kB
  • ctags: 40,785
  • sloc: ansic: 35,791; lisp: 4,036; sh: 1,783; java: 895; ruby: 613; python: 209; makefile: 115; csh: 78; cpp: 50
file content (119 lines) | stat: -rw-r--r-- 4,205 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!-- Title = calling Eiffel from  -->
<CENTER><P><IMG SRC="worker.gif" ALT="[Line]"><br>
<b>This page is not finished yet</b></P></center>


<TABLE BORDER=0 CELLSPACING=5 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#3366FF" NOSAVE >
<TR NOSAVE>
<TD NOSAVE>
<CENTER><FONT COLOR="#FFFFFF" SIZE=+3><B>Cecil</B></FONT></CENTER>
</TD>
</TR>
</TABLE>

<BR><BR><BR>

<P>
Here is the information you need if you want to call some Eiffel 
features from C code. To call C functions/macros from Eiffel see 
the documentation about <A HREF="external.html">externals</A>
(<code>man/external</code> in the distribution).
</P>
<P>
In order to call some Eiffel feature from C, you must use the 
<TT>-cecil &lt;cecil_file&gt;</TT> option with command <TT>compile</TT> 
or <TT>compile_to_c</TT>.
The <TT>&lt;cecil_file&gt;</TT> allows you to give the list of features 
you want to call from C. The corresponding stub routines will be 
automatically generated by SmartEiffel.
<BR>
When the <TT>-cecil</TT> option is used, command <TT>compile_to_c</TT> 
also produces an additional C heading file which includes the needed 
C prototypes.
</P>
<P>
Your <TT>&lt;cecil_file&gt;</TT> must contain at least two lines. 
The first line is the 
name of the C heading file to produce (it may be useful if you need
to create a C library). Other lines have the following structure:
</P>

<TABLE ALIGN=center BORDER=0 CELLSPACING=2 CELLPADDING=2 COLS=3>
<TR> <TD>&lt;c_name&gt;</TD> <TD>&lt;live_eiffel_type&gt;</TD> 
                                    <TD>&lt;feature_name&gt;</TD> </TR>
</TABLE>

<P>
The <TT>&lt;c_name&gt;</TT> is the name of the C function defined by 
<TT>compile_to_c</TT> to wrap the Eiffel call. 
The couple <TT>&lt;live_eiffel_type&gt; &lt;feature_name&gt; </TT>
gives the complete name of the Eiffel feature to call. For example:
</P>

<TABLE ALIGN=center BORDER=0 CELLSPACING=2 CELLPADDING=2 COLS=3>
<TR> <TD>IsEiffelStringEmpty</TD> <TD>STRING</TD> <TD>empty</TD> </TR>
<TR> <TD>STRINGitem</TD> <TD>STRING</TD> <TD>item</TD> </TR>
<TR> <TD>strgrtr</TD> <TD>STRING</TD> <TD>infix ">"</TD> </TR>
<TR> <TD>array_of_int_count</TD> <TD>ARRAY[INTEGER]</TD> <TD>count</TR>
<TR> <TD>X_f</TD> <TD>X</TD> <TD>f</TR>
</TABLE>


<P>
Keep in mind that the <TT>&lt;live_eiffel_type&gt;</TT> must be 
really <I>live</I>:
if <TT>&lt;live_eiffel_type&gt;</TT> is <TT>ARRAY[INTEGER]</TT> for example, 
your Eiffel program is supposed to create at least one <TT>ARRAY[INTEGER]</TT>.
</P>
<P>
The name of the feature to call, <TT>&lt;feature_name&gt;</TT> may even be 
an infix or a prefix feature name. The syntax is the same as the one used in 
Eiffel source. 
</P>
<P>
Since attributes are features, if is of course possible to access them 
with this mechanism.
</P>
<P>
A call to <TT>X_f</TT> in the C code is equivalent to a call to <TT>x.f</TT> 
in Eiffel, with <TT>x</TT> of type <TT>X</TT> <I>or any descendant of 
<TT>X</TT></I>.
Indeed, <TT>X_f</TT> takes care of late binding. This means that
<TT>X_f</TT> can be called on any (Current) argument of type <TT>X</TT> 
or heir of <TT>X</TT>.
</P>
<P>
As <TT>&lt;cecil_file&gt;</TT> is parsed by the SmartEiffel parser, it
 may contain Eiffel comments.
</P>
<P>
Here is one example of a Cecil file (others can be found in directories
<TT>SmartEiffel/tutorial/cecil/example*</TT>):
</P>

<PRE>
-- 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
</PRE>

People who tinker with the C code generated by SmartEiffel, not limiting 
themselves to the Cecil and/or external interfaces, should also read 
<A HREF="c_code.html">this page about the C code generated by SmartEiffel</A>.
Otherwise they might get into trouble.

<CENTER><P><IMG SRC="se-line.gif" ALT="[Line]" HEIGHT=16 WIDTH=550>
<BR>
<I><FONT SIZE=-1>Copyright &copy; Dominique COLNET and Suzanne COLLIN -
<A HREF="mailto:SmartEiffel@loria.fr">&lt;SmartEiffel@loria.fr&gt;</A> <BR>
<!-- hhmts start -->
Last modified: Tue Feb 11 12:10:59 CET 2003
<!-- hhmts end -->
<BR>
</FONT></I><BR></P></CENTER>