2016-03-04 08:08:47 +03:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
#import "mal_readline.h"
|
2016-03-04 10:56:54 +03:00
|
|
|
#import "types.h"
|
2016-03-04 08:08:47 +03:00
|
|
|
#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), @""));
|
|
|
|
}
|
|
|
|
|
2016-03-04 10:56:54 +03:00
|
|
|
int main () {
|
2016-03-04 08:08:47 +03:00
|
|
|
// 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]);
|
2016-03-04 10:56:54 +03:00
|
|
|
} @catch(NSException *e) {
|
|
|
|
if ([[e name] isEqualTo:@"ReaderContinue"]) { continue; }
|
|
|
|
printf("Exception: %s\n", [[e reason] UTF8String]);
|
2016-03-04 08:08:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[pool drain];
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|