]> gitweb.factorcode.org Git - factor.git/blob - vm/os-macosx.mm
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / os-macosx.mm
1 #import <Cocoa/Cocoa.h>
2
3 #include "master.hpp"
4
5 namespace factor
6 {
7
8 void factor_vm::c_to_factor_toplevel(cell quot)
9 {
10         for(;;)
11         {
12 NS_DURING
13                 c_to_factor(quot,this);
14                 NS_VOIDRETURN;
15 NS_HANDLER
16                 dpush(allot_alien(F,(cell)localException));
17                 quot = userenv[COCOA_EXCEPTION_ENV];
18                 if(!tagged<object>(quot).type_p(QUOTATION_TYPE))
19                 {
20                         /* No Cocoa exception handler was registered, so
21                         extra/cocoa/ is not loaded. So we pass the exception
22                         along. */
23                         [localException raise];
24                 }
25 NS_ENDHANDLER
26         }
27 }
28
29 void early_init(void)
30 {
31         SInt32 version;
32         Gestalt(gestaltSystemVersion,&version);
33         if(version <= 0x1050)
34         {
35                 printf("Factor requires Mac OS X 10.5 or later.\n");
36                 exit(1);
37         }
38
39         [[NSAutoreleasePool alloc] init];
40 }
41
42 const char *vm_executable_path(void)
43 {
44         return [[[NSBundle mainBundle] executablePath] UTF8String];
45 }
46
47 const char *default_image_path(void)
48 {
49         NSBundle *bundle = [NSBundle mainBundle];
50         NSString *path = [bundle bundlePath];
51         NSString *executable = [[bundle executablePath] lastPathComponent];
52         NSString *image = [executable stringByAppendingString:@".image"];
53
54         NSString *returnVal;
55
56         if([path hasSuffix:@".app"] || [path hasSuffix:@".app/"])
57         {
58                 NSFileManager *mgr = [NSFileManager defaultManager];
59
60                 NSString *imageInBundle = [[path stringByAppendingPathComponent:@"Contents/Resources"] stringByAppendingPathComponent:image];
61                 NSString *imageAlongBundle = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:image];
62
63                 returnVal = ([mgr fileExistsAtPath:imageInBundle]
64                         ? imageInBundle : imageAlongBundle);
65         }
66         else
67                 returnVal = [path stringByAppendingPathComponent:image];
68
69         return [returnVal UTF8String];
70 }
71
72 void init_signals(void)
73 {
74         unix_init_signals();
75         mach_initialize();
76 }
77
78 /* Amateurs at Apple: implement this function, properly! */
79 Protocol *objc_getProtocol(char *name)
80 {
81         if(strcmp(name,"NSTextInput") == 0)
82                 return @protocol(NSTextInput);
83         else
84                 return nil;
85 }
86
87 }