summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GNUmakefile6
-rw-r--r--MLKPackage.h17
-rw-r--r--MLKPackage.m144
3 files changed, 153 insertions, 14 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 4cb6c82..b9ddad3 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -20,9 +20,9 @@ include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = etoilisp
etoilisp_OBJC_FILES = MLKCharacter.m MLKCons.m MLKDynamicContext.m \
MLKEndOfFileError.m MLKEnvironment.m MLKError.m \
- MLKLinkedList.m MLKLispValue.m MLKReader.m \
- MLKReaderError.m MLKStream.m MLKSymbol.m \
- MLKThrowException.m \
+ MLKLinkedList.m MLKLispValue.m MLKPackage.m \
+ MLKReader.m MLKReaderError.m MLKStream.m \
+ MLKSymbol.m MLKThrowException.m \
MLKUndefinedVariableException.m
BUNDLE_NAME = Test
diff --git a/MLKPackage.h b/MLKPackage.h
index e601b18..ed3787e 100644
--- a/MLKPackage.h
+++ b/MLKPackage.h
@@ -23,11 +23,11 @@
@interface MLKPackage : MLKLispValue
{
- NSMutableDictionary *symbols;
- NSMutableSet *exported_symbols;
- NSMutableSet *shadowed_symbols;
- NSMutableSet *nicknames;
- NSString *name;
+ NSMutableDictionary *_symbols;
+ NSMutableSet *_exported_symbols;
+ NSMutableSet *_shadowed_symbols;
+ NSMutableSet *_nicknames;
+ NSString *_name;
}
-(MLKPackage *) initWithName:(NSString *)name
@@ -37,7 +37,7 @@
-(void) usePackage:(MLKPackage *)aPackage;
-(void) import:(MLKSymbol *)aSymbol;
--(void) shadow:(MLKPackage *)aPackage;
+-(void) shadow:(MLKSymbol *)aSymbol;
-(void) unintern:(MLKSymbol *)aSymbol;
-(MLKSymbol *) intern:(NSString*)symbolName;
-(MLKSymbol *) findSymbol:(NSString*)symbolName;
@@ -47,9 +47,4 @@
-(NSSet *) exportedSymbols;
-(NSSet *) shadowedSymbols;
-(NSSet *) allSymbols;
-
-// [clUser cons: @"Mulk", [clUser __intern: @"NIL"]] ought to do the
-// Right Thing.
--(void) forwardInvocation:(NSInvocation *)anInvocation;
--(BOOL) respondsToSelector:(SEL)selector;
@end
diff --git a/MLKPackage.m b/MLKPackage.m
new file mode 100644
index 0000000..66d3035
--- /dev/null
+++ b/MLKPackage.m
@@ -0,0 +1,144 @@
+/* -*- mode: objc; coding: utf-8 -*- */
+/* Étoilisp/Mulklisp, a Common Lisp subset for the Étoilé runtime.
+ * Copyright (C) 2008 Matthias Andreas Benkard.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import "MLKPackage.h"
+#import "MLKSymbol.h"
+#import "MLKError.h"
+
+#import <Foundation/NSDictionary.h>
+#import <Foundation/NSSet.h>
+#import <Foundation/NSString.h>
+#import <Foundation/NSArray.h>
+
+
+static NSMutableDictionary *packages = nil;
+
+
+@implementation MLKPackage : MLKLispValue
+-(MLKPackage *) initWithName:(NSString *)name
+ nicknames:(NSSet *)nicknames
+{
+ int i;
+ NSArray *e;
+
+ self = [self init];
+
+ // FIXME: Make this thread-safe.
+ if (!packages)
+ packages = [[NSMutableDictionary alloc] init];
+
+ [packages setObject:self forKey:name];
+
+ e = [nicknames allObjects];
+ for (i = 0; i < [e count]; i++)
+ {
+ [packages setObject:self forKey:[e objectAtIndex:i]];
+ }
+
+ _symbols = [[NSMutableDictionary alloc] init];
+ _exported_symbols = [[NSMutableSet alloc] init];
+ _shadowed_symbols = [[NSMutableSet alloc] init];
+ _nicknames = [[NSMutableSet alloc] initWithSet:nicknames];
+ ASSIGN (_name, name);
+
+ return self;
+}
+
++(MLKPackage *)findPackage:(NSString *)name
+{
+ return [packages objectForKey:name];
+}
+
+-(void) usePackage:(MLKPackage *)aPackage
+{
+ int i;
+ NSArray *symbols;
+
+ symbols = [[aPackage allSymbols] allObjects];
+
+ for (i = 0; i < [symbols count]; i++)
+ [self import:[symbols objectAtIndex:i]];
+}
+
+-(void) import:(MLKSymbol *)aSymbol
+{
+ // FIXME: Check for conflicts.
+
+ // FIXME: What to do about exported and shadowed symbols that conflict
+ // with the new one?
+ [_symbols setObject:aSymbol forKey:[aSymbol name]];
+}
+
+-(void) shadow:(MLKSymbol *)aSymbol
+{
+ [_shadowed_symbols addObject:aSymbol];
+}
+
+-(void) unintern:(MLKSymbol *)aSymbol
+{
+ [_symbols removeObjectForKey:[aSymbol name]];
+}
+
+-(MLKSymbol *) intern:(NSString *)symbolName
+{
+ if ([[_symbols allKeys] containsObject:symbolName])
+ return [_symbols objectForKey:symbolName];
+ else
+ {
+ MLKSymbol *symbol = [[MLKSymbol alloc] initWithName:symbolName
+ package:self];
+ [_symbols setObject:symbol forKey:symbolName];
+ return symbol;
+ }
+}
+
+-(MLKSymbol *) findSymbol:(NSString *)symbolName
+{
+ if ([[_symbols allKeys] containsObject:symbolName])
+ return [_symbols objectForKey:symbolName];
+ else
+ [[MLKError errorWithMessage:@"Symbol not found."] raise];
+
+ return nil;
+}
+
+-(NSString *) name
+{
+ return _name;
+}
+
+-(NSSet *) nicknames
+{
+ return _nicknames;
+}
+
+-(NSSet *) exportedSymbols
+{
+ return _exported_symbols;
+}
+
+-(NSSet *) shadowedSymbols
+{
+ return _shadowed_symbols;
+}
+
+-(NSSet *) allSymbols
+{
+ return [NSSet setWithArray:[_symbols allValues]];
+}
+@end