[mercury-users] Circular lists

Tyson Dowd trd at cs.mu.oz.au
Fri Nov 28 13:35:50 AEDT 1997


On 27-Nov-1997, Paul Massey <pma at miscrit.be> wrote:
> 
> :- pred death(int::in,int::out) is det.
> :- pragma(c_code, death(I::in,O::out),"{ int sp0; sp=I; O=sp0;}").
> ---------------------------------------------------------
> 
> With this I get no warnings that I'm doing something
> dangerous/stupid. My system just crashes at a later point
> (all sorts of very unhelpful messages about
> cygwin-exception-handler being called, etc, on my WinNT).
> 
> Given that the sp??? typo could be hidden in any piece of C
> code (in my code, the library or elsewhere) it could take
> alot of effort to find such a problem. So *my* programming
> efficiency drops. For me, I'd say a safe ELI means that *my*
> code being brain-dead or having typo's should not crash the
> Mercury system in a place over which I don't have any
> control.

As an aside note, we have been renaming variables and registers
in the runtime system to make it a little harder for these sorts
of typos to cause problems - sp (the Mercury stack pointer) is now
MR_sp. However, your point is still valid.

> One of the things I liked about BIMProlog was that it had a
> number of levels in the ELI facilities. The top level being
> about as safe as its possible to get it (loads of checks,
> copying, etc), with a second level providing 'pass'
> parameters which had much of the protections removed (faster
> but more dangerous - although never as dangerous as the
> above).
> 
> Having those multiple levels meant that I could use the
> safer/slower functions in less critical/infrequently used
> code and the faster/more dangerous code in the more critical
> sections (where I more often spend the time trying to remove
> redundant calls/debugging/testing/etc in any case). This at
> least meant when a problem occured that I could reduce the
> search space to those areas using the less-safe facilities.
> 
> Mercury has at present only the lower level interface (my
> opinion). Wouldn't it be possible to add a higher-level
> facility which provides more checking so that I can make the
> above trade-off during my any development ?

Yes. This is equivalent to what I suggested to Richard O'Keefe --
a "new" C interface (or new features for the existing one) for user
level access to C. This should include better typing (not just Word for
everything), and use of const. 

I think the main thing we'd like to avoid is checking C syntax - if
possible, we should set the interface up so that it provides the
necessary environment to do safe C, and the C compiler can tell you
if what you are doing is not safe.

-- 
       Tyson Dowd           # 
                            #         Linux versus Windows is a 
     trd at cs.mu.oz.au        #            Win lose situation.
http://www.cs.mu.oz.au/~trd #




More information about the users mailing list