Commit | Line | Data |
---|---|---|
57350ed7 JM |
1 | #import <Foundation/Foundation.h> |
2 | ||
3 | #import "mal_readline.h" | |
7cae6e6f | 4 | #import "types.h" |
57350ed7 JM |
5 | #import "reader.h" |
6 | #import "printer.h" | |
7 | ||
8 | NSObject *READ(NSString *str) { | |
9 | return read_str(str); | |
10 | } | |
11 | ||
12 | NSObject *EVAL(NSObject *ast, NSString *env) { | |
13 | return ast; | |
14 | } | |
15 | ||
16 | NSString *PRINT(NSObject *exp) { | |
17 | return _pr_str(exp, true); | |
18 | } | |
19 | ||
20 | NSString *REP(NSString *line) { | |
21 | return PRINT(EVAL(READ(line), @"")); | |
22 | } | |
23 | ||
7cae6e6f | 24 | int main () { |
57350ed7 JM |
25 | // Create an autorelease pool to manage the memory into the program |
26 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
27 | // If using automatic reference counting (ARC), use @autoreleasepool instead: | |
28 | // @autoreleasepool { | |
29 | ||
30 | while (true) { | |
31 | char *rawline = _readline("user> "); | |
32 | if (!rawline) { break; } | |
33 | NSString *line = [NSString stringWithUTF8String:rawline]; | |
34 | if ([line length] == 0) { continue; } | |
35 | @try { | |
36 | printf("%s\n", [[REP(line) description] UTF8String]); | |
37 | } @catch(NSString *e) { | |
38 | printf("Error: %s\n", [e UTF8String]); | |
7cae6e6f JM |
39 | } @catch(NSException *e) { |
40 | if ([[e name] isEqualTo:@"ReaderContinue"]) { continue; } | |
41 | printf("Exception: %s\n", [[e reason] UTF8String]); | |
57350ed7 JM |
42 | } |
43 | } | |
44 | ||
45 | [pool drain]; | |
46 | ||
47 | // } | |
48 | } |