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 NSString* imageInBundle = [resources stringByAppendingPathComponent:image];
47 NSString* imageAlongBundle = [root stringByAppendingPathComponent:image];
49 returnVal = ([mgr fileExistsAtPath:imageInBundle] ? imageInBundle
51 } else if ([executablePath hasSuffix:@".app/Contents/MacOS/factor"]) {
52 returnVal = executablePath;
53 returnVal = [returnVal stringByDeletingLastPathComponent];
54 returnVal = [returnVal stringByDeletingLastPathComponent];
55 returnVal = [returnVal stringByDeletingLastPathComponent];
56 returnVal = [returnVal stringByDeletingLastPathComponent];
57 returnVal = [returnVal stringByAppendingPathComponent:image];
60 returnVal = [path stringByAppendingPathComponent:image];
63 return [returnVal UTF8String];
66 void factor_vm::init_signals(void) {
71 // Amateurs at Apple: implement this function, properly!
72 Protocol* objc_getProtocol(char* name) {
73 if (strcmp(name, "NSTextInput") == 0)
74 return @protocol(NSTextInput);
79 uint64_t nano_count() {
80 uint64_t time = mach_absolute_time();
82 static uint64_t scaling_factor = 0;
83 if (!scaling_factor) {
84 mach_timebase_info_data_t info;
85 kern_return_t ret = mach_timebase_info(&info);
87 fatal_error("mach_timebase_info failed", ret);
88 scaling_factor = info.numer / info.denom;
91 return time * scaling_factor;