]> gitweb.factorcode.org Git - factor.git/blob - vm/os-macosx.m
1f3c1af95bdb91183e7889f5ab1dad9ba1a43845
[factor.git] / vm / os-macosx.m
1 #include "factor.h"
2
3 #import "Foundation/NSAutoreleasePool.h"
4 #import "Foundation/NSBundle.h"
5 #import "Foundation/NSException.h"
6 #import "Foundation/NSString.h"
7 #import "Foundation/NSPathUtilities.h"
8
9 static CELL error;
10
11 /* This code is convoluted because Cocoa places restrictions on longjmp and
12 exception handling. In particular, a longjmp can never cross an NS_DURING,
13 NS_HANDLER or NS_ENDHANDLER. */
14 void platform_run()
15 {
16         error = F;
17
18         for(;;)
19         {
20 NS_DURING
21                 SETJMP(stack_chain->toplevel);
22                 handle_error();
23
24                 if(error != F)
25                 {
26                         CELL e = error;
27                         error = F;
28                         general_error(ERROR_OBJECTIVE_C,e,F,true);
29                 }
30
31                 run();
32                 NS_VOIDRETURN;
33 NS_HANDLER
34                 error = tag_object(make_alien(F,(CELL)localException));
35 NS_ENDHANDLER
36         }
37 }
38
39 void early_init(void)
40 {
41         [[NSAutoreleasePool alloc] init];
42 }
43
44 const char *default_image_path(void)
45 {
46         NSBundle *bundle = [NSBundle mainBundle];
47         NSString *path = [bundle bundlePath];
48         NSString *image;
49         if([path hasSuffix:@".app"] || [path hasSuffix:@".app/"])
50                 image = [[path stringByDeletingLastPathComponent] stringByAppendingString:@"/factor.image"];
51         else
52                 image = [path stringByAppendingString:@"/factor.image"];
53         return [image cString];
54 }
55
56 void init_signals(void)
57 {
58         unix_init_signals();
59         mach_initialize();
60 }