diff options
-rw-r--r-- | MLKDynamicContext.m | 68 | ||||
-rw-r--r-- | MLKInteger.h | 2 | ||||
-rw-r--r-- | MLKInteger.m | 14 | ||||
-rw-r--r-- | MLKPackage.h | 5 | ||||
-rw-r--r-- | MLKPackage.m | 8 | ||||
-rw-r--r-- | MLKSymbol.m | 2 |
6 files changed, 96 insertions, 3 deletions
diff --git a/MLKDynamicContext.m b/MLKDynamicContext.m index f5042aa..90e237d 100644 --- a/MLKDynamicContext.m +++ b/MLKDynamicContext.m @@ -16,13 +16,19 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#import <Foundation/NSDictionary.h> #import <Foundation/NSArray.h> +#import <Foundation/NSDictionary.h> +#import <Foundation/NSSet.h> #import <Foundation/NSThread.h> +#import "MLKCons.h" #import "MLKDynamicContext.h" #import "MLKEnvironment.h" #import "MLKLinkedList.h" +#import "MLKPackage.h" +#import "MLKReadtable.h" +#import "MLKSymbol.h" +#import "MLKInteger.h" #define MAKE_ENVIRONMENT(variable, parent, parent_member) \ @@ -42,8 +48,68 @@ static MLKDynamicContext *global_context; +(void) initialize { NSMutableDictionary *vars = [NSMutableDictionary dictionary]; + MLKPackage *cl = [MLKPackage packageWithName:@"COMMON-LISP" + nicknames:[NSSet setWithObject:@"CL"]]; + MLKPackage *clUser = [MLKPackage packageWithName:@"COMMON-LISP-USER" + nicknames:[NSSet setWithObject:@"CL-USER"]]; + MLKPackage *keyword = [MLKPackage packageWithName:@"KEYWORD" + nicknames:[NSSet set]]; + MLKSymbol *t = [cl intern:@"T"]; + MLKReadtable *readtable = [[MLKReadtable alloc] init]; // FIXME: Initialise stuff. +#define INIT(VARNAME, VALUE) [vars setObject:VALUE forKey:[cl intern:VARNAME]] + + INIT(@"*BREAK-ON-SIGNALS*", nil); + INIT(@"*COMPILE-FILE-PATHNAME*", nil); + INIT(@"*COMPILE-FILE-TRUENAME*", nil); + INIT(@"*COMPILE-PRINT*", nil); + INIT(@"*COMPILE-VERBOSE*", t); + // INIT(@"*DEBUG-IO*", ); + INIT(@"*DEBUGGER-HOOK*", nil); + // INIT(@"*DEFAULT-PATHNAME-DEFAULTS*", ); + // INIT(@"*ERROR-OUTPUT*", ); + INIT(@"*FEATURES*", [MLKCons + cons:[keyword intern:@"ETOILET"] + with:[MLKCons + cons:[keyword intern:@"COMMON-LISP"] + with:[MLKCons + cons:[keyword intern:@"ANSI-CL"] + with:nil]]]); + INIT(@"*GENSYM-COUNTER*", [MLKInteger integerWithInt:0]); + INIT(@"*LOAD-PATHNAME*", nil); + INIT(@"*LOAD-PRINT*", nil); + INIT(@"*LOAD-TRUENAME*", nil); + INIT(@"*LOAD-VERBOSE*", t); + // INIT(@"*MACROEXPAND-HOOK*", ); + INIT(@"*MODULES*", nil); + INIT(@"*PACKAGE*", clUser); + INIT(@"*PRINT-ARRAY*", t); + INIT(@"*PRINT-BASE*", [MLKInteger integerWithInt:10]); + INIT(@"*PRINT-CASE*", [keyword intern:@"UPCASE"]); + INIT(@"*PRINT-CIRCLE*", nil); + INIT(@"*PRINT-ESCAPE*", t); + INIT(@"*PRINT-GENSYM*", t); + INIT(@"*PRINT-LENGTH*", nil); + INIT(@"*PRINT-LEVEL*", nil); + INIT(@"*PRINT-LINES*", nil); + INIT(@"*PRINT-MISER-WIDTH*", nil); + // INIT(@"*PRINT-PPRINT-DISPATCH*", ); + INIT(@"*PRINT-PRETTY*", t); + INIT(@"*PRINT-RADIX*", nil); + INIT(@"*PRINT-READABLY*", nil); + INIT(@"*PRINT-RIGHT-MARGIN*", nil); + // INIT(@"*QUERY-IO*", ); + // INIT(@"*RANDOM-STATE*", ); + INIT(@"*READ-BASE*", [MLKInteger integerWithInt:10]); + INIT(@"*READ-DEFAULT-FLOAT-FORMAT*", [cl intern:@"SINGLE-FLOAT"]); + INIT(@"*READ-EVAL*", t); + INIT(@"*READ-SUPPRESS*", nil); //FIXME: Support in reader + INIT(@"*READTABLE*", readtable); + // INIT(@"*STANDARD-INPUT*", ); + // INIT(@"*STANDARD-OUTPUT*", ); + // INIT(@"*TERMINAL-IO*", ); + // INIT(@"*TRACE-OUTPUT* ", ); global_context = [[self alloc] initWithParent:nil variables:vars diff --git a/MLKInteger.h b/MLKInteger.h index 57687b4..c651bab 100644 --- a/MLKInteger.h +++ b/MLKInteger.h @@ -34,11 +34,13 @@ -(MLKInteger *) initWithString:(NSString *)string negative:(BOOL)negative base:(unsigned int)base; +-(MLKInteger *) initWithInt:(int)intValue; +(MLKInteger *) integerWithMPZ:(mpz_t)mpz; +(MLKInteger *) integerWithString:(NSString *)string negative:(BOOL)negative base:(unsigned int)base; ++(MLKInteger *) integerWithInt:(int)intValue; -(int) intValue; diff --git a/MLKInteger.m b/MLKInteger.m index 7239f0b..10c3bca 100644 --- a/MLKInteger.m +++ b/MLKInteger.m @@ -29,6 +29,13 @@ return self; } +-(MLKInteger *) initWithInt:(int)intValue +{ + self = [super init]; + mpz_init_set_si (value, intValue); + return self; +} + -(MLKInteger *) initWithString:(NSString *)string negative:(BOOL)negative base:(unsigned int)base @@ -53,6 +60,12 @@ base:base]); } ++(MLKInteger *) integerWithInt:(int)intValue +{ + return AUTORELEASE ([[MLKInteger alloc] initWithInt:intValue]); +} + + #define DEFINE_MPZ_TWOARG_OPERATION(SELECTOR, GMPFUN) \ DEFINE_GMP_OPERATION (SELECTOR (MLKInteger *)arg, \ mpz, \ @@ -65,6 +78,7 @@ DEFINE_MPZ_TWOARG_OPERATION (subtract:, mpz_sub) DEFINE_MPZ_TWOARG_OPERATION (multiplyWith:, mpz_mul) DEFINE_MPZ_TWOARG_OPERATION (divideBy:, mpz_div) + -(int) intValue { return mpz_get_si (value); diff --git a/MLKPackage.h b/MLKPackage.h index ed3787e..6b17c3e 100644 --- a/MLKPackage.h +++ b/MLKPackage.h @@ -33,7 +33,10 @@ -(MLKPackage *) initWithName:(NSString *)name nicknames:(NSSet *)nicknames; -+(MLKPackage *)findPackage:(NSString *)name; ++(MLKPackage *) packageWithName:(NSString *)name + nicknames:(NSSet *)nicknames; + ++(MLKPackage *) findPackage:(NSString *)name; -(void) usePackage:(MLKPackage *)aPackage; -(void) import:(MLKSymbol *)aSymbol; diff --git a/MLKPackage.m b/MLKPackage.m index 66d3035..d7ac803 100644 --- a/MLKPackage.m +++ b/MLKPackage.m @@ -59,7 +59,13 @@ static NSMutableDictionary *packages = nil; return self; } -+(MLKPackage *)findPackage:(NSString *)name ++(MLKPackage *) packageWithName:(NSString *)name + nicknames:(NSSet *)nicknames +{ + return AUTORELEASE ([[self alloc] initWithName:name nicknames:nicknames]); +} + ++(MLKPackage *) findPackage:(NSString *)name { return [packages objectForKey:name]; } diff --git a/MLKSymbol.m b/MLKSymbol.m index 42a7141..1cab004 100644 --- a/MLKSymbol.m +++ b/MLKSymbol.m @@ -47,6 +47,8 @@ -(NSString *)descriptionForLisp { + // NOTE: Need to take *PRINT-GENSYM* into account. + // // FIXME: This is wrong in more than one way. return [NSString stringWithFormat:@"|%@|", name]; } |