1 #import <Cocoa/Cocoa.h>
3 #include <mach/mach_time.h>
4 #include <sys/utsname.h>
10 void factor_vm::c_to_factor_toplevel(cell quot) { c_to_factor(quot); }
12 // Darwin 9 is 10.5, Darwin 10 is 10.6
13 // http://en.wikipedia.org/wiki/Darwin_(operating_system)#Release_history
14 void early_init(void) {
18 sscanf(u.release, "%d", &n);
20 std::cout << "Factor requires Mac OS X 10.5 or later.\n";
25 // You must free() this yourself.
26 const char* vm_executable_path(void) {
27 return safe_strdup([[[NSBundle mainBundle] executablePath] UTF8String]);
30 const char* default_image_path(void) {
31 NSBundle* bundle = [NSBundle mainBundle];
32 NSString* path = [bundle bundlePath];
33 NSString* executablePath = [[bundle executablePath] stringByResolvingSymlinksInPath];
34 NSString* executable = [executablePath lastPathComponent];
35 NSString* image = [executable stringByAppendingString:@".image"];
39 if ([path hasSuffix:@".app"] || [path hasSuffix:@".app/"]) {
40 NSFileManager* mgr = [NSFileManager defaultManager];
42 NSString* imageInBundle =
43 [[path stringByAppendingPathComponent:@"Contents/Resources"]
44 stringByAppendingPathComponent:image];
45 NSString* imageAlongBundle = [[path stringByDeletingLastPathComponent]
46 stringByAppendingPathComponent:image];
48 returnVal = ([mgr fileExistsAtPath:imageInBundle] ? imageInBundle
50 } else if ([executablePath hasSuffix:@".app/Contents/MacOS/factor"]) {
51 returnVal = executablePath;
52 returnVal = [returnVal stringByDeletingLastPathComponent];
53 returnVal = [returnVal stringByDeletingLastPathComponent];
54 returnVal = [returnVal stringByDeletingLastPathComponent];
55 returnVal = [returnVal stringByDeletingLastPathComponent];
56 returnVal = [returnVal stringByAppendingPathComponent:image];
58 returnVal = [path stringByAppendingPathComponent:image];
61 return [returnVal UTF8String];
64 void factor_vm::init_signals(void) {
69 // Amateurs at Apple: implement this function, properly!
70 Protocol* objc_getProtocol(char* name) {
71 if (strcmp(name, "NSTextInput") == 0)
72 return @protocol(NSTextInput);
77 uint64_t nano_count() {
78 uint64_t time = mach_absolute_time();
80 static uint64_t scaling_factor = 0;
81 if (!scaling_factor) {
82 mach_timebase_info_data_t info;
83 kern_return_t ret = mach_timebase_info(&info);
85 fatal_error("mach_timebase_info failed", ret);
86 scaling_factor = info.numer / info.denom;
89 return time * scaling_factor;