diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-25 14:55:54 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-25 14:55:54 +0200 |
commit | f6da3068e9e854d6913ba45cf2b7d9deafd87a91 (patch) | |
tree | 38271d4598f91699153e92f9505fe57c22c2f0fa | |
parent | 1935a12096ad737edf5ec94e5b7a18980566f9ab (diff) |
Environment handling: Add MLKEnvironment methods for direct access to bindings.
-rw-r--r-- | MLKEnvironment.h | 2 | ||||
-rw-r--r-- | MLKEnvironment.m | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/MLKEnvironment.h b/MLKEnvironment.h index 0789b1a..bfa5f2b 100644 --- a/MLKEnvironment.h +++ b/MLKEnvironment.h @@ -37,6 +37,8 @@ -(MLKEnvironment *) parent; -(NSSet *) bindings; +-(void) addBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol; +-(void) setBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol; -(void) addBindingForSymbol:(MLKSymbol *)symbol; -(void) addBindings:(NSDictionary *)bindings; -(void) addValues:(NSDictionary *)bindings; diff --git a/MLKEnvironment.m b/MLKEnvironment.m index 29f7740..7119bac 100644 --- a/MLKEnvironment.m +++ b/MLKEnvironment.m @@ -137,10 +137,24 @@ -(void) addBindingForSymbol:(MLKSymbol *)symbol { - [_bindings setObject:[MLKBinding binding] + [self addBinding:[MLKBinding binding] forSymbol:symbol]; +} + +-(void) addBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol +{ + [_bindings setObject:binding forKey:(symbol ? (id)symbol : (id)[NSNull null])]; } +-(void) setBinding:(MLKBinding *)binding forSymbol:(MLKSymbol *)symbol +{ + if (![self bindingForSymbol:symbol]) + [NSException raise:@"MLKUnboundVariableError" + format:@"The variable %@ is unbound.", + [symbol descriptionForLisp]]; + [self addBinding:binding forSymbol:symbol]; +} + -(MLKEnvironment *) environmentForSymbol:(MLKSymbol *)symbol { if ([_bindings objectForKey:symbol]) |