diff options
-rw-r--r-- | MLKPackage.m | 9 | ||||
-rw-r--r-- | MLKRoot.m | 73 |
2 files changed, 74 insertions, 8 deletions
diff --git a/MLKPackage.m b/MLKPackage.m index 1fa668d..205dea1 100644 --- a/MLKPackage.m +++ b/MLKPackage.m @@ -89,6 +89,15 @@ static NSMutableDictionary *packages = nil; [sys export:[sys intern:@"CONS"]]; [sys export:[sys intern:@"LOAD"]]; [sys export:[sys intern:@"EQ"]]; + [sys export:[sys intern:@"ATOM"]]; + [sys export:[sys intern:@"LISTP"]]; + [sys export:[sys intern:@"CONSP"]]; + [sys export:[sys intern:@"SYMBOLP"]]; + [sys export:[sys intern:@"NULL"]]; + [sys export:[sys intern:@"ADD"]]; + [sys export:[sys intern:@"SUBTRACT"]]; + [sys export:[sys intern:@"MULTIPLY"]]; + [sys export:[sys intern:@"DIVIDE"]]; [tlUser usePackage:clUser]; } @@ -22,6 +22,9 @@ #import "MLKRoot.h" #import "MLKStream.h" #import "MLKSymbol.h" +#import "MLKInteger.h" +#import "MLKSingleFloat.h" +#import "MLKDoubleFloat.h" #import "runtime-compatibility.h" #import <Foundation/NSArray.h> @@ -55,6 +58,15 @@ static MLKPackage *sys; static MLKPackage *cl; +static id truify (BOOL value) +{ + return (value ? (id) [cl intern:@"T"] : nil); +} + +#define RETURN_VALUE(thing) \ + return [NSArray arrayWithObject:nullify(thing)]; + + @implementation MLKRoot +(void) initialize { @@ -150,17 +162,62 @@ static MLKPackage *cl; [input close]; - if (success) - return [NSArray arrayWithObject:[cl intern:@"T"]]; - else - return [NSArray arrayWithObject:[NSNull null]]; + RETURN_VALUE (truify (success)); } +(NSArray *) eq:(NSArray *)args { - if ([args objectAtIndex:0] == [args objectAtIndex:1]) - return [NSArray arrayWithObject:[cl intern:@"T"]]; - else - return [NSArray arrayWithObject:[NSNull null]]; + RETURN_VALUE (truify ([args objectAtIndex:0] == [args objectAtIndex:1])); +} + ++(NSArray *) symbolp:(NSArray *)args +{ + id arg0 = [args objectAtIndex:0]; + RETURN_VALUE (truify (arg0 == [NSNull null] + || [arg0 isKindOfClass:[MLKSymbol class]])); +} + ++(NSArray *) listp:(NSArray *)args +{ + id arg0 = [args objectAtIndex:0]; + RETURN_VALUE (truify (arg0 == [NSNull null] + || [arg0 isKindOfClass:[MLKCons class]])); +} + ++(NSArray *) consp:(NSArray *)args +{ + id arg0 = [args objectAtIndex:0]; + RETURN_VALUE (truify ([arg0 isKindOfClass:[MLKCons class]])); +} + ++(NSArray *) atom:(NSArray *)args +{ + id arg0 = [args objectAtIndex:0]; + RETURN_VALUE (truify (![arg0 isKindOfClass:[MLKCons class]])); +} + ++(NSArray *) null:(NSArray *)args +{ + RETURN_VALUE (truify ([args objectAtIndex:0] == [NSNull null])); +} + ++(NSArray *) add:(NSArray *)args +{ + RETURN_VALUE ([[args objectAtIndex:0] add:[args objectAtIndex:1]]); +} + ++(NSArray *) subtract:(NSArray *)args +{ + RETURN_VALUE ([[args objectAtIndex:0] subtract:[args objectAtIndex:1]]); +} + ++(NSArray *) multiply:(NSArray *)args +{ + RETURN_VALUE ([[args objectAtIndex:0] multiplyWith:[args objectAtIndex:1]]); +} + ++(NSArray *) divide:(NSArray *)args +{ + RETURN_VALUE ([[args objectAtIndex:0] divideBy:[args objectAtIndex:1]]); } @end |