1 #import <Cocoa/Cocoa.h>
3 #include <mach/mach_time.h>
4 #include <sys/utsname.h>
12 void factor_vm::c_to_factor_toplevel(cell quot) { c_to_factor(quot); }
14 // Darwin 9 is 10.5, Darwin 10 is 10.6
15 // http://en.wikipedia.org/wiki/Darwin_(operating_system)#Release_history
16 void early_init(void) {
20 sscanf(u.release, "%d", &n);
22 std::cout << "Factor requires Mac OS X 10.5 or later.\n";
27 // You must free() this yourself.
28 const char* vm_executable_path(void) {
29 return safe_strdup([[[NSBundle mainBundle] executablePath] UTF8String]);
32 const char* default_image_path(void) {
33 NSBundle* bundle = [NSBundle mainBundle];
34 NSString* path = [bundle bundlePath];
35 NSString* executablePath = [[bundle executablePath] stringByResolvingSymlinksInPath];
36 NSString* executable = [executablePath lastPathComponent];
37 NSString* image = [executable stringByAppendingString:@".image"];
41 if ([path hasSuffix:@".app"] || [path hasSuffix:@".app/"]) {
42 NSFileManager* mgr = [NSFileManager defaultManager];
43 NSString* root = [path stringByDeletingLastPathComponent];
44 NSString* resources = [path stringByAppendingPathComponent:@"Contents/Resources"];
46 if (!isatty(fileno(stdin))) {
47 [mgr changeCurrentDirectoryPath: root];
50 NSString* imageInBundle = [resources stringByAppendingPathComponent:image];
51 NSString* imageAlongBundle = [root stringByAppendingPathComponent:image];
53 returnVal = ([mgr fileExistsAtPath:imageInBundle] ? imageInBundle
55 } else if ([executablePath hasSuffix:@".app/Contents/MacOS/factor"]) {
56 returnVal = executablePath;
57 returnVal = [returnVal stringByDeletingLastPathComponent];
58 returnVal = [returnVal stringByDeletingLastPathComponent];
59 returnVal = [returnVal stringByDeletingLastPathComponent];
60 returnVal = [returnVal stringByDeletingLastPathComponent];
61 returnVal = [returnVal stringByAppendingPathComponent:image];
64 returnVal = [path stringByAppendingPathComponent:image];
67 return [returnVal UTF8String];
70 void factor_vm::init_signals(void) {
75 // Amateurs at Apple: implement this function, properly!
76 Protocol* objc_getProtocol(char* name) {
77 if (strcmp(name, "NSTextInput") == 0)
78 return @protocol(NSTextInput);
83 uint64_t nano_count() {
84 uint64_t time = mach_absolute_time();
86 static uint64_t scaling_factor = 0;
87 if (!scaling_factor) {
88 mach_timebase_info_data_t info;
89 kern_return_t ret = mach_timebase_info(&info);
91 fatal_error("mach_timebase_info failed", ret);
92 scaling_factor = info.numer / info.denom;
95 return time * scaling_factor;