make-image can now generate images with Unicode strings
[factor/jcg.git] / vm / os-macosx.m
blob9b0366ff757adc0154c33410088d2592a9d72c60
1 #import <Cocoa/Cocoa.h>
3 #include "master.h"
5 void c_to_factor_toplevel(CELL quot)
7         for(;;)
8         {
9 NS_DURING
10                 c_to_factor(quot);
11                 NS_VOIDRETURN;
12 NS_HANDLER
13                 dpush(allot_alien(F,(CELL)localException));
14                 quot = userenv[COCOA_EXCEPTION_ENV];
15                 if(type_of(quot) != QUOTATION_TYPE)
16                 {
17                         /* No Cocoa exception handler was registered, so
18                         extra/cocoa/ is not loaded. So we pass the exception
19                         along. */
20                         [localException raise];
21                 }
22 NS_ENDHANDLER
23         }
26 void early_init(void)
28         SInt32 version;
29         Gestalt(gestaltSystemVersion,&version);
30         if(version <= 0x1050)
31         {
32                 printf("Factor requires Mac OS X 10.5 or later.\n");
33                 exit(1);
34         }
36         [[NSAutoreleasePool alloc] init];
39 const char *vm_executable_path(void)
41         return [[[NSBundle mainBundle] executablePath] UTF8String];
44 const char *default_image_path(void)
46         NSBundle *bundle = [NSBundle mainBundle];
47         NSString *path = [bundle bundlePath];
48         NSString *executable = [[bundle executablePath] lastPathComponent];
49         NSString *image = [executable stringByAppendingString:@".image"];
51         NSString *returnVal;
53         if([path hasSuffix:@".app"] || [path hasSuffix:@".app/"])
54         {
55                 NSFileManager *mgr = [NSFileManager defaultManager];
57                 NSString *imageInBundle = [[path stringByAppendingPathComponent:@"Contents/Resources"] stringByAppendingPathComponent:image];
58                 NSString *imageAlongBundle = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:image];
60                 returnVal = ([mgr fileExistsAtPath:imageInBundle]
61                         ? imageInBundle : imageAlongBundle);
62         }
63         else
64                 returnVal = [path stringByAppendingPathComponent:image];
66         return [returnVal UTF8String];
69 void init_signals(void)
71         unix_init_signals();
72         mach_initialize();
75 /* Amateurs at Apple: implement this function, properly! */
76 Protocol *objc_getProtocol(char *name)
78         if(strcmp(name,"NSTextInput") == 0)
79                 return @protocol(NSTextInput);
80         else
81                 return nil;