diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-09-02 12:01:30 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-09-02 12:01:30 +0200 |
commit | 34682b0b087a9ced1f23a91f67167f71f304a4a8 (patch) | |
tree | 70ef9e0a697a3fdfa194ce4819d55ce2b36fc8af | |
parent | 84597fcf74fc74672fe664456e62ec6be5f2b066 (diff) |
Switch from NS_DURING..NS_HANDLER..NS_ENDHANDLER to @try..@catch..@finally.
-rw-r--r-- | MLKArray.m | 13 | ||||
-rw-r--r-- | MLKCharacterStream.m | 11 | ||||
-rw-r--r-- | MLKDynamicContext.m | 25 | ||||
-rw-r--r-- | MLKEnvironment.m | 19 | ||||
-rw-r--r-- | MLKFileHandleStream.m | 4 | ||||
-rw-r--r-- | MLKInterpreter.m | 70 | ||||
-rw-r--r-- | MLKListenerController.m | 10 | ||||
-rw-r--r-- | MLKPackage.m | 9 | ||||
-rw-r--r-- | MLKReadEvalPrintLoop.m | 15 | ||||
-rw-r--r-- | MLKRoot.m | 10 | ||||
-rw-r--r-- | MLKStreamStream.m | 4 | ||||
-rw-r--r-- | MLKSymbol.m | 11 |
12 files changed, 70 insertions, 131 deletions
@@ -23,6 +23,7 @@ #import <Foundation/NSArray.h> #import <Foundation/NSEnumerator.h> +#import <Foundation/NSException.h> #include <stdio.h> #include <search.h> @@ -241,19 +242,17 @@ static int equalp (const void *x, const void *y) -(id) objectAtIndex:(NSUInteger)index { - NS_DURING + @try { - NS_VALUERETURN (nullify([self idAtIndex:index]), id); + return nullify ([self idAtIndex:index]); } - NS_HANDLER + @catch (NSException *e) { - if ([[localException name] isEqualToString:@"NSRangeException"]) + if ([[e name] isEqualToString:NSRangeException]) return nil; else - [localException raise]; - return nil; + @throw; } - NS_ENDHANDLER; } -(void) insertObject:(id)anObject atIndex:(NSUInteger)index diff --git a/MLKCharacterStream.m b/MLKCharacterStream.m index d64ed3c..a152060 100644 --- a/MLKCharacterStream.m +++ b/MLKCharacterStream.m @@ -17,6 +17,7 @@ */ #import "MLKCharacterStream.h" +#import "MLKStreamError.h" #import "runtime-compatibility.h" #import "util.h" @@ -73,18 +74,14 @@ { BOOL eofp = NO; - NS_DURING + @try { [self peekChar]; } - NS_HANDLER + @catch (MLKStreamError *e) { - if ([[localException name] isEqual:@"MLKStreamError"]) - eofp = YES; - else - [localException raise]; + eofp = YES; } - NS_ENDHANDLER; return eofp; } diff --git a/MLKDynamicContext.m b/MLKDynamicContext.m index 70979cf..5029a95 100644 --- a/MLKDynamicContext.m +++ b/MLKDynamicContext.m @@ -43,6 +43,7 @@ #import "MLKSharpsignColonReader.h" #import "MLKSymbol.h" #import "MLKInteger.h" +#import "MLKUnboundVariableError.h" #import "runtime-compatibility.h" #import "util.h" @@ -359,35 +360,25 @@ static MLKDynamicContext *global_context; -(id) findRestart:(MLKSymbol *)symbol { - NS_DURING + @try { - NS_VALUERETURN ([_restarts valueForSymbol:symbol], id); + return [_restarts valueForSymbol:symbol]; } - NS_HANDLER - { - if (![[localException name] isEqualToString: @"MLKUnboundVariableError"]) - [localException raise]; - } - NS_ENDHANDLER; + @catch (MLKUnboundVariableError *e) { } return nil; } -(id) findHandler:(MLKSymbol *)symbol { - NS_DURING + @try { if (_activeHandlerEnvironment) - NS_VALUERETURN ([[_activeHandlerEnvironment parent] valueForSymbol:symbol], id); + return [[_activeHandlerEnvironment parent] valueForSymbol:symbol]; else - NS_VALUERETURN ([_conditionHandlers valueForSymbol:symbol], id); - } - NS_HANDLER - { - if (![[localException name] isEqualToString: @"MLKUnboundVariableError"]) - [localException raise]; + return [_conditionHandlers valueForSymbol:symbol]; } - NS_ENDHANDLER; + @catch (MLKUnboundVariableError *e) { } return nil; } diff --git a/MLKEnvironment.m b/MLKEnvironment.m index d057a8c..13abce4 100644 --- a/MLKEnvironment.m +++ b/MLKEnvironment.m @@ -23,6 +23,7 @@ #import <Foundation/NSSet.h> #import "MLKEnvironment.h" +#import "MLKUnboundVariableError.h" #import "NSObject-MLKPrinting.h" #import "runtime-compatibility.h" #import "util.h" @@ -79,9 +80,9 @@ MLKBinding *binding; if (!(binding = [self bindingForSymbol:symbol])) - [NSException raise:@"MLKUnboundVariableError" - format:@"The variable %@ is unbound.", - MLKPrintToString(symbol)]; + @throw LAUTORELEASE ([[MLKUnboundVariableError alloc] + initWithSymbol:symbol + inEnvironment:self]); [binding setValue:value]; } @@ -91,9 +92,9 @@ MLKBinding *binding; if (!(binding = [self bindingForSymbol:symbol])) - [NSException raise:@"MLKUnboundVariableError" - format:@"The variable %@ is unbound.", - MLKPrintToString(symbol)]; + @throw LAUTORELEASE ([[MLKUnboundVariableError alloc] + initWithSymbol:symbol + inEnvironment:self]); return [binding value]; } @@ -157,9 +158,9 @@ -(void) setBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol { if (![self bindingForSymbol:symbol]) - [NSException raise:@"MLKUnboundVariableError" - format:@"The variable %@ is unbound.", - MLKPrintToString(symbol)]; + @throw LAUTORELEASE ([[MLKUnboundVariableError alloc] + initWithSymbol:symbol + inEnvironment:self]); [self addBinding:binding forSymbol:symbol]; } diff --git a/MLKFileHandleStream.m b/MLKFileHandleStream.m index 456cddd..7c7065e 100644 --- a/MLKFileHandleStream.m +++ b/MLKFileHandleStream.m @@ -17,6 +17,7 @@ */ #import "MLKFileHandleStream.h" +#import "MLKStreamError.h" #import "runtime-compatibility.h" #import "util.h" @@ -52,8 +53,7 @@ if ([data length] == 0) { - [NSException raise:@"MLKStreamError" - format:@"Tried to read beyond end of file."]; + @throw LAUTORELEASE ([[MLKStreamError alloc] initWithStream:self]); } return *(uint8_t*)[data bytes]; diff --git a/MLKInterpreter.m b/MLKInterpreter.m index 81415d1..027e2f7 100644 --- a/MLKInterpreter.m +++ b/MLKInterpreter.m @@ -34,6 +34,7 @@ #import "MLKReader.h" #import "MLKRoot.h" #import "MLKSymbol.h" +#import "MLKThrowException.h" #import "NSObject-MLKPrinting.h" #import "globals.h" #import "runtime-compatibility.h" @@ -198,16 +199,15 @@ PRIMARY (NSArray *array) //if (trace) NSLog (@"; EVAL: %@", MLKPrintToString(_form)); #elif 0 - NS_DURING + @catch { values = [self reallyInterpretWithEnvironment:env]; } - NS_HANDLER + @catch (...) { NSLog (@"; BROKEN EVAL: %@", MLKPrintToString(_form)); - [localException raise]; + @throw; } - NS_ENDHANDLER; #else values = [self reallyInterpretWithEnvironment:env]; #endif @@ -258,7 +258,7 @@ PRIMARY (NSArray *array) catchTag = PRIMARY ([_tagForm interpretWithEnvironment:env]); - NS_DURING + @try { newctx = [[MLKDynamicContext alloc] initWithParent:[MLKDynamicContext currentContext] variables:nil @@ -270,28 +270,18 @@ PRIMARY (NSArray *array) values = [self interpretBodyWithEnvironment:env]; - NS_VALUERETURN (values, NSArray *); + return values; } - NS_HANDLER + @catch (MLKThrowException *throw) { [MLKDynamicContext popContext]; LRELEASE (newctx); - - if ([[localException name] isEqualToString:@"MLKThrow"]) - { - id thrownTag = [[localException userInfo] - objectForKey:@"THROWN TAG"]; - - if (thrownTag == catchTag) - return [[localException userInfo] - objectForKey:@"THROWN OBJECTS"]; - else - [localException raise]; - } + + if ([throw catchTag] == catchTag) + return [throw thrownValues]; else - [localException raise]; + @throw; } - NS_ENDHANDLER; [MLKDynamicContext popContext]; LRELEASE (newctx); @@ -447,20 +437,15 @@ PRIMARY (NSArray *array) [dynctx pushContext]; - NS_DURING + @try { values = [self interpretBodyWithEnvironment:newenv]; } - NS_HANDLER + @finally { [MLKDynamicContext popContext]; LRELEASE (dynctx); - [localException raise]; } - NS_ENDHANDLER; - - [MLKDynamicContext popContext]; - LRELEASE (dynctx); return values; } @@ -556,20 +541,15 @@ PRIMARY (NSArray *array) [dynctx pushContext]; - NS_DURING + @try { result = [self interpretBodyWithEnvironment:env]; } - NS_HANDLER + @finally { [MLKDynamicContext popContext]; LRELEASE (dynctx); - [localException raise]; } - NS_ENDHANDLER; - - [MLKDynamicContext popContext]; - LRELEASE (dynctx); return result; } @@ -594,17 +574,9 @@ PRIMARY (NSArray *array) catchTag = PRIMARY([_tagForm interpretWithEnvironment:env]); values = [_valueForm interpretWithEnvironment:env]; - userInfo = [NSDictionary dictionaryWithObjectsAndKeys: - catchTag, @"THROWN TAG", - values, @"THROWN OBJECTS", nil]; - if ([[MLKDynamicContext currentContext] catchTagIsEstablished:denullify (catchTag)]) - [[NSException exceptionWithName:@"MLKThrow" - reason:[NSString stringWithFormat: - @"THROW: tag %@, values %@.", - MLKPrintToString(catchTag), - MLKPrintToString(values)] - userInfo:userInfo] raise]; + @throw LAUTORELEASE ([[MLKThrowException alloc] initWithCatchTag:catchTag + values:values]); else // FIXME: This should really be a condition rather than // an exception. See CLHS THROW. @@ -625,18 +597,14 @@ PRIMARY (NSArray *array) { NSArray *results; - NS_DURING + @try { results = [_protectedForm interpretWithEnvironment:env]; } - NS_HANDLER + @finally { [self interpretBodyWithEnvironment:env]; - [localException raise]; } - NS_ENDHANDLER; - - [self interpretBodyWithEnvironment:env]; return results; } diff --git a/MLKListenerController.m b/MLKListenerController.m index 2998ab2..9e8ddee 100644 --- a/MLKListenerController.m +++ b/MLKListenerController.m @@ -51,11 +51,11 @@ [submitButton setEnabled:NO]; - NS_DURING + @try { object = [MLKReader readFromString:input]; } - NS_HANDLER + @catch (NSException *e) { // A parsing error. Beep and let the user try again. // XXX Maybe the status line could be made to provide more information on the error. @@ -64,7 +64,6 @@ [inputField selectText:self]; return; } - NS_ENDHANDLER; [inputField setStringValue:@""]; [inputField selectText:self]; @@ -119,7 +118,7 @@ object = denullify(object); - NS_DURING + @try { int i; NSArray *results; @@ -167,7 +166,7 @@ waitUntilDone:waitp]; } } - NS_HANDLER + @catch (NSException *localException) { NSString *bare_msg = [NSString stringWithFormat: @"Caught an unhandled exception.\nName: %s\nReason: %s\n", @@ -187,7 +186,6 @@ withObject:response waitUntilDone:waitp]; } - NS_ENDHANDLER; [MLKDynamicContext popContext]; LDESTROY (newctx); diff --git a/MLKPackage.m b/MLKPackage.m index 193c83a..bc4e0f4 100644 --- a/MLKPackage.m +++ b/MLKPackage.m @@ -17,6 +17,7 @@ */ #import "MLKDynamicContext.h" +#import "MLKNoSuchSymbolError.h" #import "MLKPackage.h" #import "MLKSymbol.h" #import "NSObject-MLKPrinting.h" @@ -457,12 +458,8 @@ static NSMutableDictionary *packages = nil; if ((symbol = [_accessible_symbols objectForKey:symbolName])) return (symbol == (id)[NSNull null] ? nil : (id)symbol); else - [NSException raise:@"MLKNoSuchSymbolError" - format:@"The package %@ does not contain a symbol named %@.", - self, - symbolName]; - - return nil; + @throw LAUTORELEASE ([[MLKNoSuchSymbolError alloc] initWithPackage:self + symbolName:symbolName]); } -(NSString *) name diff --git a/MLKReadEvalPrintLoop.m b/MLKReadEvalPrintLoop.m index 0e213b0..e3700ea 100644 --- a/MLKReadEvalPrintLoop.m +++ b/MLKReadEvalPrintLoop.m @@ -51,7 +51,7 @@ static char **_argv; static const char *prompt (EditLine *e) { - NS_DURING + @try { MLKPackage *package = [[MLKDynamicContext currentContext] valueForSymbol:[[MLKPackage @@ -60,14 +60,13 @@ static const char *prompt (EditLine *e) { return [[NSString stringWithFormat:@"%@> ", [package name]] UTF8String]; } - NS_HANDLER + @catch (NSException *localException) { printf ("Caught an unhandled exception.\nName: %s\nReason: %s\n", [[localException name] UTF8String], [[localException reason] UTF8String]); return "> "; } - NS_ENDHANDLER } @@ -102,7 +101,7 @@ static const char *prompt (EditLine *e) { printf ("Loading init.lisp.\n"); #if 1 - NS_DURING + @try { #endif input = [NSInputStream inputStreamWithFileAtPath:@"init.lisp"]; @@ -117,13 +116,12 @@ static const char *prompt (EditLine *e) { [input close]; #if 1 } - NS_HANDLER + @catch (NSException *localException) { printf ("Caught an unhandled exception.\nName: %s\nReason: %s\n", [[localException name] UTF8String], [[localException reason] UTF8String]); } - NS_ENDHANDLER; #endif printf ("Done.\n\n"); @@ -159,7 +157,7 @@ static const char *prompt (EditLine *e) { break; #if 1 - NS_DURING + @try #else #ifdef GNUSTEP GSDebugAllocationActive (YES); @@ -185,13 +183,12 @@ static const char *prompt (EditLine *e) { } } #if 1 - NS_HANDLER + @catch (NSException *localException) { printf ("Caught an unhandled exception.\nName: %s\nReason: %s\n", [[localException name] UTF8String], [[localException reason] UTF8String]); } - NS_ENDHANDLER; #endif LRELEASE (pool); @@ -141,22 +141,16 @@ load (id _data, NSString *fileName, id _marker) forSymbol:[sys intern:@"*LOAD-LEVEL*"]]; [ctx pushContext]; - NS_DURING + @try { success = [MLKInterpreter load:stream verbose:YES print:YES]; } - NS_HANDLER + @finally { [MLKDynamicContext popContext]; LRELEASE (ctx); [input close]; - [localException raise]; } - NS_ENDHANDLER; - - [MLKDynamicContext popContext]; - LRELEASE (ctx); - [input close]; [ostream writeString:@"; \\"]; for (i = 0; i < 68 - 2*level; i++) diff --git a/MLKStreamStream.m b/MLKStreamStream.m index 7e19932..e6afcb7 100644 --- a/MLKStreamStream.m +++ b/MLKStreamStream.m @@ -16,6 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#import "MLKStreamError.h" #import "MLKStreamStream.h" #import "runtime-compatibility.h" #import "util.h" @@ -69,8 +70,7 @@ if (bytes_read < 1) { - [NSException raise:@"MLKStreamError" - format:@"Tried to read beyond end of file."]; + @throw LAUTORELEASE ([[MLKStreamError alloc] initWithStream:self]); } return octet; diff --git a/MLKSymbol.m b/MLKSymbol.m index 46ccd32..b6bc55f 100644 --- a/MLKSymbol.m +++ b/MLKSymbol.m @@ -17,6 +17,7 @@ */ #import "MLKDynamicContext.h" +#import "MLKNoSuchSymbolError.h" #import "MLKPackage.h" #import "MLKReader.h" #import "MLKReadtable.h" @@ -120,21 +121,17 @@ else printName = name; - NS_DURING + @try { if ([currentPackage findSymbol:name] == self) accessible = YES; else accessible = NO; } - NS_HANDLER + @catch (MLKNoSuchSymbolError *e) { - if ([[localException name] isEqualToString:@"MLKNoSuchSymbolError"]) - accessible = NO; - else - [localException raise]; + accessible = NO; } - NS_ENDHANDLER; if (homePackage == [MLKPackage findPackage:@"KEYWORD"]) packagePrefix = @":"; |