🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.mod2
Article #381

exceptions (really volatile variables)

#381
From: Geoffrey Wyant
Date: Tue, 22 Apr 1986 14:00
59 lines
2494 bytes
One problem I see with implementing exceptions outside the 
language comes in the following form:
                               
    VAR
        fileOpened: BOOLEAN ;

        Exceptions.SetHandler(status) ;

        IF status <> ok THEN
            IF fileOpened THEN
                FileSystem.Close(...);
            END ;
        END ;

        fileOpened := FALSE ;
        FileSystem.Open(...) ;
        fileOpened := TRUE ;

Now a smart optimizing complier will notice that
the first assignment to fileOpened is never used.
It then thinks that it is free to delete that
expression.  This is clearly wrong.  The fact is 
that either the compiler has to know about stack
unwinders (exception handling) or there must be
some way to declare that a variable is "volitale"
and the compiler not optimize assignments to it.
Similiar things can happen when dealing with IO
devices (don't want optimize away those control
register assignments !) Now I think that it's a
bad idea to stick exception handling into the
language, but the ability to specify attributes
in a declaration, such as "volatile" seems to me
to be usefull.  Then one could write the above
example as

    VAR
        fileOpened: [VOLITALE] BOOLEAN ;

    ....      

I think that the notion of attributes could be
generalized to allow specifying field sizes
for dealing with device registers:

    VAR
        mythicalCSR: [VOLITALE] RECORD
                        [BITS] commands: 
                               SET OF (go, halt, catchFire) ;
                        [BITS] status:   
                               SET OF (broken, flaming, toasting, running) ;
                    END (* record *);

What do other people think of this ?  I think it provides usefull
functionality without warping the language too much.


                Geoff Wyant
-------
Technical Details
Message-ID: <8604240042.AA13982@uw-beaver.arpa>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!apollo.UUCP!wyant

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!apollo.UUCP!wyant
From: wyant@apollo.UUCP (Geoffrey Wyant)
Newsgroups: net.lang.mod2
Subject: exceptions (really volatile variables)
Message-ID: <8604240042.AA13982@uw-beaver.arpa>
Date: Tue, 22-Apr-86 09:00:16 EST
Article-I.D.: uw-beave.8604240042.AA13982
Posted: Tue Apr 22 09:00:16 1986
Date-Received: Sat, 26-Apr-86 04:26:11 EST
Sender: usenet@ucbvax.BERKELEY.EDU
Organization: The ARPA Internet
Lines: 59