Exception Handling

"David Jobet" <david.jobet@ng-market.com>
21 Jul 2002 02:06:29 -0400

          From comp.compilers

Related articles
Exception Handling david.jobet@ng-market.com (David Jobet) (2002-07-21)
Re: Exception Handling vbdis@aol.com (VBDis) (2002-07-24)
Re: Exception Handling casse@netcourrier.com (Casse Hugues) (2002-07-24)
Re: Exception Handling jacob@jacob.remcomp.fr (jacob navia) (2002-07-24)
Re: Exception Handling david.jobet@ng-market.com (David Jobet) (2002-07-25)
Re: Exception Handling journeyman@compilerguru.com (journeyman) (2002-08-04)
Re: Exception Handling nmm1@cus.cam.ac.uk (Nick Maclaren) (2002-08-10)
[8 later articles]
| List of all articles for this month |
From: "David Jobet" <david.jobet@ng-market.com>
Newsgroups: comp.compilers
Date: 21 Jul 2002 02:06:29 -0400
Organization: Next generation market
Keywords: errors
Posted-Date: 21 Jul 2002 02:06:29 EDT

Hi,


I'm developping a compiler (for the fun) for a new language called Nosica.
(http://nosica.ng-market.net)


I'm stuck with exception implementation because I'm using C as as my
assembly language.


Finding docs for exceptions is not very easy, but I came to a model using
custom setjmp /longjmp (because the standard C version appears to save a
lot more than needed for C++ compatibility).


For example, the following nosica code : (looks like java)
---
try
{
    int i;
    Data data = new Data();


    f(); // may throw. Return adress is equal to PC (Program Counter)


    // .. do some stuff


    Data data2 = new Data();


    g(); // never throw


    // Do some stuff


    h(); // may throw
}
catch (Exception e)
{
    // catch all
}
---


would be transformed into the following c code :


---
JmpBuffer env;
int returnJmp;
if ((returnJmp=setjmp(env)) == 0)
{
register(env, exception_list_type_code);
// try_block
unregister(env);
[finally_block]
}
else
{
    Exception e = (Exception)returnJump;
    switch (e.getReturnAddress())
    {
    case h_addr :
        DECREF(data2);
    case f_addr :
        DECREF(data);
        int_destructor(i);


        // all local variables have been destroyed
        [finally_block]


        if (exceptionHandled(e)) // look if e can be handled by a registered
exception of this try block
        break;


    default :
        ExceptionRepository.THROW(e); // rethrow
    }


    switch (e.getTypeCode())
    {
        EXCEPTION_TypeCode :
            Exception_Block
            break;
    }
}
---


Basically, I need to have the return address that the called function would
return to if there was no exception thrown.
In this case, the compiler could switch on this return value and produce the
*good* code needed to clean up local variables.


Problem is I don't know how to get this return address in order to produce
the good case (here h_addr and f_addr).


Is there any way to get them using assembly ?


Thank you


David


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.