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];
44 if (!isatty(fileno(stdin))) {
45 NSString* root = [path stringByDeletingLastPathComponent];
46 [mgr changeCurrentDirectoryPath: root];
49 NSString* imageInBundle =
50 [[path stringByAppendingPathComponent:@"Contents/Resources"]
51 stringByAppendingPathComponent:image];
52 NSString* imageAlongBundle = [[path stringByDeletingLastPathComponent]
53 stringByAppendingPathComponent:image];
55 returnVal = ([mgr fileExistsAtPath:imageInBundle] ? imageInBundle
59 returnVal = [path stringByAppendingPathComponent:image];
62 return [returnVal UTF8String];
65 void factor_vm::init_signals(void) {
70 // Amateurs at Apple: implement this function, properly!
71 Protocol* objc_getProtocol(char* name) {
72 if (strcmp(name, "NSTextInput") == 0)
73 return @protocol(NSTextInput);
78 uint64_t nano_count() {
79 uint64_t time = mach_absolute_time();
81 static uint64_t scaling_factor = 0;
82 if (!scaling_factor) {
83 mach_timebase_info_data_t info;
84 kern_return_t ret = mach_timebase_info(&info);
86 fatal_error("mach_timebase_info failed", ret);
87 scaling_factor = info.numer / info.denom;
90 return time * scaling_factor;