mirror of
https://github.com/kanaka/mal.git
synced 2024-09-11 21:57:38 +03:00
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
49 lines
1.2 KiB
Objective-C
49 lines
1.2 KiB
Objective-C
#import <Foundation/Foundation.h>
|
|
|
|
#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];
|
|
|
|
// }
|
|
}
|