mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2026-02-28 11:50:57 +01:00
added 18.07
git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2049 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
[[Property:title|CECIL - Basic sample]]
|
||||
[[Property:weight|2]]
|
||||
[[Property:uuid|ed699d37-f480-0cef-817f-9f4a857c1691]]
|
||||
==cecil-test==
|
||||
|
||||
After you have done the appropriate steps to compile the example, you will get a `cecil.exe` on windows, or `cecil` on Unix.
|
||||
|
||||
This example performs some basic tests of CECIL from C to Eiffel and Eiffel to C. You can:
|
||||
* choose to raise an exception when a routine is not visible
|
||||
* create an Eiffel string
|
||||
* choose to raise a precondition violation from C.
|
||||
|
||||
|
||||
|
||||
A typical output will be:
|
||||
<code>
|
||||
$ cecil
|
||||
Do you want to enable the visible exception? (y-yes, n-no):n
|
||||
Disable visible exception
|
||||
|
||||
====== In eiffel_call ======
|
||||
Eiffel type id = 9
|
||||
Eiffel procedure make 0x100546b4
|
||||
Eiffel object = 0x30068030
|
||||
Testing linked_list...
|
||||
12345
|
||||
test_linked_list OK
|
||||
Testing memory...
|
||||
Give string length (enter a high number for raising an Eiffel exception)
|
||||
234
|
||||
Memory OK
|
||||
Testing if string void ...
|
||||
Enter a string: (press enter if you want to raise an Eiffel exception)
|
||||
wefsd
|
||||
wefsdTesting precondition...By default it is true
|
||||
|
||||
====== Done ======
|
||||
|
||||
====== In eiffel_call ======
|
||||
Eiffel type id = 9
|
||||
Eiffel procedure test_linked_list 0x10054ebc
|
||||
Eiffel object = 0x30068030
|
||||
Testing linked_list...
|
||||
12345
|
||||
test_linked_list OK
|
||||
|
||||
====== Done ======
|
||||
|
||||
====== In eiffel_call_1_arg ======
|
||||
Eiffel type id = 9
|
||||
Eiffel procedure print 0x1004e0a8
|
||||
Eiffel object = 0x30068030
|
||||
Eiffel object = 0x30068030
|
||||
Execute the Eiffel code `print (linked_list)' from the C side:
|
||||
MAIN [0x30068030]
|
||||
linked_list: LINKED_LIST [0x30068C40]
|
||||
|
||||
====== Done ======
|
||||
|
||||
====== In cecil_test ======
|
||||
protected indirection of 30068c40 is 300311bc
|
||||
Eiffel type id of STRING = 198
|
||||
Eiffel type id of LINKED_LIST [STRING] = 224
|
||||
Linked List forth: 10222fbc
|
||||
Linked list object = 0x30068c40
|
||||
Do you want to test the visibility of an Eiffel routine? (y-yes, n-no):
|
||||
n
|
||||
Do you want raise a precondition violation? (y-yes, n-no):
|
||||
n
|
||||
|
||||
====== Done ======
|
||||
</code>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
[[Property:title|CECIL - C to Eiffel]]
|
||||
[[Property:weight|0]]
|
||||
[[Property:uuid|c3b64ef2-28b2-920e-44fb-4cff2320c099]]
|
||||
==array==
|
||||
This example shows how to create an Eiffel array from an existing C array. After you have done the appropriate steps to compile the example, you will get a `cecil.exe` on windows, or `cecil` on Unix. Launch the program and you will be prompted for 10 integers that will be inserted in a C array, it will then initialize the Eiffel array and calls display from the MY_ARRAY class. A typical output will be:
|
||||
<code>
|
||||
$ ./cecil
|
||||
Enter 10 integers:
|
||||
Enter element 1: 1
|
||||
Enter element 2: 2
|
||||
Enter element 3: 3
|
||||
Enter element 4: 4
|
||||
Enter element 5: 5
|
||||
Enter element 6: 6
|
||||
Enter element 7: 7
|
||||
Enter element 8: 8
|
||||
Enter element 9: 9
|
||||
Enter element 10: 10
|
||||
|
||||
Display an Eiffel Array:
|
||||
@1 = 1
|
||||
@2 = 2
|
||||
@3 = 3
|
||||
@4 = 4
|
||||
@5 = 5
|
||||
@6 = 6
|
||||
@7 = 7
|
||||
@8 = 8
|
||||
@9 = 9
|
||||
@10 = 10
|
||||
</code>
|
||||
|
||||
==string==
|
||||
This example shows how to create an Eiffel string from an existing C string. After you have done the appropriate steps to compile the example, you will get a `cecil.exe` on windows, or `cecil` on Unix. Launch the program and you will be prompted for a string, it will then initialize the Eiffel string and calls io. put_string from the STD_FILES class. A typical output will be:
|
||||
<code>
|
||||
$ ./cecil
|
||||
Enter a string to convert in Eiffel string:
|
||||
Hello World!
|
||||
Now printing the Eiffel string from Eiffel
|
||||
|
||||
Hello World!
|
||||
</code>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
[[Property:title|CECIL - Eiffel to C]]
|
||||
[[Property:weight|1]]
|
||||
[[Property:uuid|3d1df3fe-2ac8-1ba3-c846-8329ea8a3772]]
|
||||
==array==
|
||||
|
||||
This example shows how to create a C array from an existing Eiffel array.
|
||||
|
||||
After you have done the appropriate steps to compile the example, you will get a `cecil.exe` on windows, or `cecil` on Unix.
|
||||
|
||||
Launch the program and you will be prompted for 10 integers that will be inserted in an Eiffel array, it will then initialize the C array and display it.
|
||||
|
||||
A typical output will be:
|
||||
<code>
|
||||
$ ./cecil
|
||||
This example create n array on the Eiffel side and print it on the C side
|
||||
Enter 10 integers:
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
|
||||
Displaying from C
|
||||
@1 = 1
|
||||
@2 = 2
|
||||
@3 = 3
|
||||
@4 = 4
|
||||
@5 = 5
|
||||
@6 = 6
|
||||
@7 = 7
|
||||
@8 = 8
|
||||
@9 = 9
|
||||
@10 = 10
|
||||
</code>
|
||||
|
||||
==object==
|
||||
This example shows the Eiffel memory management and all issues when passing an Eiffel object reference to C. In the example, you can edit the file `root_class.e` to modify the example:
|
||||
<code>
|
||||
--give_to_c (o1)
|
||||
give_to_c_by_pointer ($o1) -- Choose the way you pass it
|
||||
</code>
|
||||
When you choose the first possibility (commented by default), give_to_c will use the CECIL API eif_adopt to keep a reference on the Eiffel object. When you choose the second possibility, give_to_c_by_pointer will use the CECIL API eif_protect to keep a reference on the Eiffel object. Until forget_from_c is called from the C side, the object o1 will not be collected since we have protected it through the call to give_to_c or give_to_c_by_pointer. At the end after the object o1 is collected, we try to perform an operation on it which will fail with a call on void target exception. A typical output will be:
|
||||
<code>
|
||||
$ cecil
|
||||
Creating o1
|
||||
Object string is o1
|
||||
Give it to C
|
||||
Losing reference to initial o1 from Eiffel
|
||||
Collecting...
|
||||
Display new o1:
|
||||
Object string is o2
|
||||
Display o1 given to C:
|
||||
Object string is o1
|
||||
Losing reference from C
|
||||
Losing reference from Eiffel
|
||||
Collecting...
|
||||
An Eiffel object of type OBJECT is collected
|
||||
Old o1 forgot from both C and Eiffel:
|
||||
Raise a Void exception..
|
||||
|
||||
cecil: system execution failed.
|
||||
Following is the set of recorded exceptions:
|
||||
-------------------------------------------------------------------------------
|
||||
Class / Object Routine Nature of exception Effect
|
||||
-------------------------------------------------------------------------------
|
||||
ROOT_CLASS make @26 display:
|
||||
<30068030> Feature call on void target. Fail
|
||||
-------------------------------------------------------------------------------
|
||||
ROOT_CLASS make @26
|
||||
<30068030> Routine failure. Fail
|
||||
-------------------------------------------------------------------------------
|
||||
ROOT_CLASS root's creation
|
||||
<30068030> Routine failure. Exit
|
||||
-------------------------------------------------------------------------------
|
||||
An Eiffel object of type OBJECT is collected
|
||||
</code>
|
||||
|
||||
==string==
|
||||
This example shows how to create a C string from an existing Eiffel string. After you have done the appropriate steps to compile the example, you will get a `cecil.exe` on windows, or `cecil` on Unix. Launch the program and you will be prompted for a string from Eiffel and a C string will be created and display. A typical output will be:
|
||||
<code>
|
||||
$ cecil
|
||||
Enter a string to convert into a C string:
|
||||
Hello World!
|
||||
|
||||
Here is the C string:
|
||||
Hello World!
|
||||
</code>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
[[Property:title|CECIL - How to compile the samples?]]
|
||||
[[Property:weight|4]]
|
||||
[[Property:uuid|3548e1b4-9488-10d5-561e-f817c15d6ff0]]
|
||||
==Compiling for Windows==
|
||||
|
||||
Depending on your C compiler different steps have to be done, but do not forget to do the following before starting the C compiler specific part in a DOS console:
|
||||
<code>set ISE_EIFFEL=XXX</code>
|
||||
|
||||
where XXX is the EiffelStudio installation directory.
|
||||
|
||||
===With Borland C++:===
|
||||
|
||||
By default, Borland C++ is not in your path, so you will have to first set your path correctly by typing:
|
||||
<code>set PATH=%ISE_EIFFEL%\BCC55\bin;%PATH%</code>
|
||||
|
||||
If the file `Makefile. win' is present, then you can launch the compilation with:
|
||||
<code>make -f Makefile. win</code>
|
||||
|
||||
Otherwise launch the compilation with:
|
||||
<code>make -f Makefile. bcb</code>
|
||||
|
||||
===With Microsoft Visual C++:===
|
||||
|
||||
By default, the command line tools of Visual C++ should be available from the command line.
|
||||
|
||||
If the file `Makefile. win' is present, then you can launch the compilation with:
|
||||
<code>nmake -f Makefile. win</code>
|
||||
|
||||
Otherwise launch the compilation with:
|
||||
<code>nmake -f Makefile. msc</code>
|
||||
|
||||
==Compiling for UNIX==
|
||||
|
||||
Then, make sure that your path to the EiffelStudio executables are properly configured before launching the command below.
|
||||
|
||||
To compile and execute from scratch type:
|
||||
<code>finish_freezing -library</code>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
[[Property:title|CECIL - Threads]]
|
||||
[[Property:weight|3]]
|
||||
[[Property:uuid|44f2ee31-8634-6e54-f45a-8b36f780f888]]
|
||||
==bank_account==
|
||||
|
||||
After you have done the appropriate steps to compile the example, you will get a `bank_account.exe` on windows, or `bank_account` on Unix.
|
||||
|
||||
This program launches two types of threads:
|
||||
* the spenders withdraw some money from a shared bank account
|
||||
* the savers make some deposits on it.
|
||||
|
||||
The Eiffel Threads are launched from C. The synchronization is done from Eiffel. The shared bank account is a C structure, and is updated by the Eiffel Threads using some C externals.
|
||||
|
||||
<br/>
|
||||
In main. c: <br/>
|
||||
LISTSZ size of bank account history. <br/>
|
||||
DEPOSITORS numbers of savers. <br/>
|
||||
WITHDRAWERS numbers of spenders.
|
||||
<br/>
|
||||
|
||||
|
||||
|
||||
A typical output will be:
|
||||
<code>
|
||||
$ bank_account
|
||||
**** Bank account report:
|
||||
Thread 0x30036350 DEPOSIT 161
|
||||
Thread 0x30036350 DEPOSIT 614
|
||||
Thread 0x30036350 DEPOSIT 626
|
||||
Thread 0x30036350 DEPOSIT 880
|
||||
Thread 0x30036350 DEPOSIT 601
|
||||
Thread 0x30036350 DEPOSIT 480
|
||||
Thread 0x30036350 DEPOSIT 177
|
||||
Thread 0x30036350 DEPOSIT 451
|
||||
Thread 0x30036350 DEPOSIT 96
|
||||
Thread 0x30036350 DEPOSIT 219
|
||||
*** BALANCE: 5305
|
||||
Do you want to continue? (y/n)
|
||||
y
|
||||
**** Bank account report:
|
||||
Thread 0x3003fcf0 DEPOSIT 161
|
||||
Thread 0x3004f088 DEPOSIT 161
|
||||
Thread 0x300567a0 WITHDRAWAL 161
|
||||
Thread 0x3005e1f0 WITHDRAWAL 161
|
||||
Thread 0x30036350 DEPOSIT 531
|
||||
Thread 0x3003fcf0 DEPOSIT 614
|
||||
Thread 0x3004f088 DEPOSIT 614
|
||||
Thread 0x300567a0 WITHDRAWAL 614
|
||||
Thread 0x30036350 DEPOSIT 409
|
||||
Thread 0x3003fcf0 DEPOSIT 626
|
||||
*** BALANCE: 7485
|
||||
Do you want to continue? (y/n)
|
||||
y
|
||||
**** Bank account report:
|
||||
Thread 0x3004f088 DEPOSIT 626
|
||||
Thread 0x30036350 DEPOSIT 799
|
||||
Thread 0x300567a0 WITHDRAWAL 626
|
||||
Thread 0x3005e1f0 WITHDRAWAL 614
|
||||
Thread 0x3003fcf0 DEPOSIT 880
|
||||
Thread 0x30036350 DEPOSIT 860
|
||||
Thread 0x3004f088 DEPOSIT 880
|
||||
Thread 0x300567a0 WITHDRAWAL 880
|
||||
Thread 0x30036350 DEPOSIT 307
|
||||
Thread 0x3004f088 DEPOSIT 601
|
||||
*** BALANCE: 10318
|
||||
</code>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
[[Property:title|CECIL samples]]
|
||||
[[Property:weight|5]]
|
||||
[[Property:uuid|dab15073-3970-7e47-a2d8-c926faa50ade]]
|
||||
Before trying the examples, please take a moment and look at the [[CECIL - How to compile the samples?|description]] that will explain how to compile the CECIL samples.
|
||||
|
||||
Available samples include:
|
||||
* [[CECIL - C to Eiffel|C to Eiffel]]
|
||||
* [[CECIL - Eiffel to C|Eiffel to C]]
|
||||
* [[CECIL - Basic sample|Basic CECIL sample]]
|
||||
* [[CECIL - Threads|Threads]]
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user