#import #import "mal_readline.h" #import "types.h" #import "reader.h" #import "printer.h" NSObject *READ(NSString *str) { return read_str(str); } NSObject *EVAL(NSObject *ast, NSString *env) { return ast; } NSString *PRINT(NSObject *exp) { return _pr_str(exp, true); } NSString *REP(NSString *line) { return PRINT(EVAL(READ(line), @"")); } int main () { // Create an autorelease pool to manage the memory into the program NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // If using automatic reference counting (ARC), use @autoreleasepool instead: // @autoreleasepool { while (true) { char *rawline = _readline("user> "); if (!rawline) { break; } NSString *line = [NSString stringWithUTF8String:rawline]; if ([line length] == 0) { continue; } @try { printf("%s\n", [[REP(line) description] UTF8String]); } @catch(NSString *e) { printf("Error: %s\n", [e UTF8String]); } @catch(NSException *e) { if ([[e name] isEqualTo:@"ReaderContinue"]) { continue; } printf("Exception: %s\n", [[e reason] UTF8String]); } } [pool drain]; // } }