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 const char* vm_executable_path(void) {
26 return [[[NSBundle mainBundle] executablePath] UTF8String];
29 const char* default_image_path(void) {
30 NSBundle* bundle = [NSBundle mainBundle];
31 NSString* path = [bundle bundlePath];
32 NSString* executable = [[bundle executablePath] lastPathComponent];
33 NSString* image = [executable stringByAppendingString:@".image"];
37 if ([path hasSuffix:@".app"] || [path hasSuffix:@".app/"]) {
38 NSFileManager* mgr = [NSFileManager defaultManager];
40 NSString* imageInBundle =
41 [[path stringByAppendingPathComponent:@"Contents/Resources"]
42 stringByAppendingPathComponent:image];
43 NSString* imageAlongBundle = [[path stringByDeletingLastPathComponent]
44 stringByAppendingPathComponent:image];
46 returnVal = ([mgr fileExistsAtPath:imageInBundle] ? imageInBundle
49 returnVal = [path stringByAppendingPathComponent:image];
51 return [returnVal UTF8String];
54 void factor_vm::init_signals(void) {
59 /* Amateurs at Apple: implement this function, properly! */
60 Protocol* objc_getProtocol(char* name) {
61 if (strcmp(name, "NSTextInput") == 0)
62 return @protocol(NSTextInput);
67 uint64_t nano_count() {
68 uint64_t time = mach_absolute_time();
70 static uint64_t scaling_factor = 0;
71 if (!scaling_factor) {
72 mach_timebase_info_data_t info;
73 kern_return_t ret = mach_timebase_info(&info);
75 fatal_error("mach_timebase_info failed", ret);
76 scaling_factor = info.numer / info.denom;
79 return time * scaling_factor;