home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / man / external.txt < prev    next >
Text File  |  1999-06-05  |  5KB  |  107 lines

  1.  
  2.                                  Externals
  3.                                       
  4.    Here is the information you need if you want to call C or Java code
  5.    from Eiffel code (to call Eiffel feature from C or Java see [1]cecil
  6.    file).
  7.    
  8.    The most common way to call external code from Eiffel is to use the
  9.    external feature definition as described in the book "Eiffel The
  10.    Language". See also the SmallEiffel directory lib_show/external to
  11.    have some examples.
  12.    
  13.    Below is the current list of SmallEiffel external specifications.
  14.    
  15.    external "C_WithoutCurrent"
  16.    
  17.    Simple call to a C function (or procedure). The external called
  18.    routine does not get Current as an argument. A C prototype is
  19.    automatically added in a generated C header file. Use this when you
  20.    provide yourself the C code for the external routine.
  21.    Note: for compatibility with other Eiffel compilers external "C" is
  22.    treated exactly as external "C_WithoutCurrent".
  23.    
  24.    external "C_WithCurrent"
  25.    
  26.    C call with Current. The external called routine gets Current as its
  27.    first argument. A C prototype is automatically added in a generated C
  28.    header file. Use this when you provide yourself the C code for the
  29.    external routine.
  30.    
  31.    external "C_InlineWithoutCurrent"
  32.    
  33.    Similar to "C_WithoutCurrent", except that no prototype is produced.
  34.    Use this if you already have the corresponding prototype coming from
  35.    somewhere else (stdio.h for example), which is likely if you call a
  36.    routine from a standard C library (e.g. printf). Actually, the name is
  37.    not really well chosen, since "Inline" has little to do with this...
  38.    
  39.    external "C_InlineWithCurrent"
  40.    
  41.    Similar to "C_WithCurrent", except that no prototype is produced.
  42.    Use this if you already have the corresponding prototype coming from
  43.    somewhere else (stdio.h for example), which is likely if you call a
  44.    routine from a standard C library (e.g. printf). Actually, the name is
  45.    not really well chosen, since "Inline" has little to do with this...
  46.    
  47.    external "SmallEiffel"
  48.    
  49.    This external specification is reserved to the SmallEiffel compiler
  50.    itself. Do not use it. Such a feature is directly supported both by
  51.    compile_to_c and compile_to_jvm. For example, infix "+" of INTEGER is
  52.    direcly mapped as C '+' by compile_to_c. For the same infix "+",
  53.    command compile_to_jvm produce the appropriate Java virtual machine
  54.    byte code.
  55.    
  56.    external "JVM_invokestatic"
  57.    
  58.    Calling a Java static method. As it is a static Java call, the Eiffel
  59.    receiver is not used. The "alias" field of the feature is used to
  60.    indicate the Java class, the Java function name and the corresponding
  61.    Java bytecode descriptor. Syntax to use in the alias string is :
  62.    alias "<JavaClassPath>.<MethodName> <Descriptor>"
  63.           
  64.    A dot is the separator between <JavaClassPath> and <MethodName>.
  65.    A blank character is the separator between <MethodName> and
  66.    <Descriptor>.
  67.    The <JavaClassPath> uses the JVM internal notation as described in
  68.    JVMS(*). For example, when one wants to use java.lang.Math, the
  69.    <JavaClassPath> is "java/lang/Math". The <MethodName> gives the Java
  70.    method name. The <Descriptor> gives the internal Java bytecode
  71.    descriptor as described in JVMS(*).
  72. (*) - JVMS -
  73.    "The Java Virtual Machine Specification",
  74.    Tim Lindholm and Frank Yellin, The Java Series,
  75.    Addison-Wesley, ISBN 0-201-63452-X.
  76.  
  77.    external "JVM_invokevirtual"
  78.    
  79.    Calling a Java virtual method. As for "JVM_invokestatic", the alias
  80.    string gives all needed information to call the virtual function. The
  81.    Current Eiffel target is not used (only arguments and the result are
  82.    considered).
  83.    
  84.    Inlining C code
  85.    
  86.    Another way to call C code from Eiffel is to use "c_inline_c" or
  87.    "c_inline_h" as defined in GENERAL. The argument of "c_inline_c" (or
  88.    "c_inline_h") must always be a manifest string which may contains the
  89.    C code you want to put inlieu.
  90.    Using c_inline_[c/h] also implies you do know exactly the C code
  91.    SmallEiffel produces. For portability, it is also much better to use
  92.    previous solutions.
  93.    People who tinker with the C code generated by SmallEiffel, not
  94.    limiting themselves to the Cecil and/or external interfaces, should
  95.    also read [2]this page about the C code generated by SmallEiffel,
  96.    Otherwise they might get into trouble.
  97.    
  98.                                    [Line]
  99.    Copyright © Dominique COLNET and Suzanne COLLIN - [3]<colnet@loria.fr>
  100.                      Last update: 05 May 1999, by OZ. 
  101.  
  102. References
  103.  
  104.    1. file://localhost/home/colnet/SmallEiffel/man/man/cecil.html
  105.    2. file://localhost/home/colnet/SmallEiffel/man/man/c_code.html
  106.    3. mailto:colnet@loria.fr
  107.