Re: Re: GEC Compilation of Externals

Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]>
Newsgroups gmane.comp.lang.eiffel.gobo.general
Organization Gobo
Message-ID <[email protected]>
Brian Heilig wrote:
> I remember now. I figured out how to make statements work with all
> three compilers by adding a semi-colon, just as you suggested. What I
> couldn't figure out were functions, for example:
> 
> sizeof: INTEGER is
>     -- Size to allocate (in bytes)
>   external
>     "C inline use <windows.h>"
>   alias
>     "sizeof (struct _COMMTIMEOUTS)"
>   end

I think ECMA says it should be:

  sizeof: INTEGER is
      -- Size to allocate (in bytes)
    external
      "C inline use <windows.h>"
    alias
      "return sizeof (struct _COMMTIMEOUTS);"
    end

> Eric, you mentioned implementing externals according to the ECMA
> specification. I agree that you have done that, but I don't think the
> inline mechanism is not specified well (from ECMA-367):
> 
> 8.31.14 Semantics: C Inline semantics
> In an external routine er of the inline form, an External_name of the
> form alias C_text denotes the algorithm defined, according to the
> semantics of the C language, by a C function that has:
> • As its signature, the signature specified by er.
> • As its body, C_text after replacement of every occurrence of $a,
> where the lower name of a is the lower name of one of the formal
> arguments of er, by a.
> 
> When implementing a function, simply replacing C_text will not do. A
> return statement is necessary.

I don't think you read the above semantics correctly. There is nothing
which says that C_text should be a C expression. It should be an
algorithm, in other word a piece of C code. The semantics rule of ECMA
defines what the generated result will be. Then it's up to developer
to make sure that the result will be correct C code. After all this
standard is about Eiffel, not C. So the alias clause is just interpreted
as a sequence of characters with special treatments for $ values, and
not as structured C code.

> In addition, consider the following
> example from ETL3 (http://se.inf.ethz.ch/~meyer/ongoing/etl/others.pdf
> para 31.11):
> 
> an_inline_function (x,y: INTEGER): INTEGER
>   external "[
>     C
>       inline
>       use <stdio.h>
>     ]"
>   alias "[
>     if ($x > 5) {
>       some_c_function ($y, cvar++);
>     }
>   ]"
> end
> 
> This can't work because C_text does not return a value as the
> signature of `an_inline_function' suggests it should.

But the ECMA standard and the Eiffel compiler expect that the developer
knows what it does when writing C code in inline external routines.
Perhaps the above should have been written:

an_inline_function (x,y: INTEGER): INTEGER
   external "[
     C
       inline
       use <stdio.h>
     ]"
   alias "[
     if ($x > 5) {
       return some_c_function ($y, cvar++);
     } else
       return 0;
   ]"
end


-- 
Eric Bezault
mailto:ericb-D6Qt/9opevxWk0Htik3J/[email protected]
http://www.gobosoft.com




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Everything you need is one click away.  Make Yahoo! your home page now.
http://us.click.yahoo.com/AHchtC/4FxNAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

To Post a message, send it to:   [email protected]
To Unsubscribe, send a blank message to: [email protected] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/gobo-eiffel/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.