| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #import <Cocoa/Cocoa.h> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "master.hpp" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void c_to_factor_toplevel(cell quot) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	for(;;) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | NS_DURING | 
					
						
							|  |  |  | 		c_to_factor(quot); | 
					
						
							|  |  |  | 		NS_VOIDRETURN; | 
					
						
							|  |  |  | NS_HANDLER | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		dpush(allot_alien(F,(cell)localException)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		quot = userenv[COCOA_EXCEPTION_ENV]; | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		if(!tagged<object>(quot).type_p(QUOTATION_TYPE)) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			/* No Cocoa exception handler was registered, so | 
					
						
							|  |  |  | 			extra/cocoa/ is not loaded. So we pass the exception | 
					
						
							|  |  |  | 			along. */ | 
					
						
							|  |  |  | 			[localException raise]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | NS_ENDHANDLER | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void early_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SInt32 version; | 
					
						
							|  |  |  | 	Gestalt(gestaltSystemVersion,&version); | 
					
						
							|  |  |  | 	if(version <= 0x1050) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		printf("Factor requires Mac OS X 10.5 or later.\n"); | 
					
						
							|  |  |  | 		exit(1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	[[NSAutoreleasePool alloc] init]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const char *vm_executable_path(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return [[[NSBundle mainBundle] executablePath] UTF8String]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const char *default_image_path(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NSBundle *bundle = [NSBundle mainBundle]; | 
					
						
							|  |  |  | 	NSString *path = [bundle bundlePath]; | 
					
						
							|  |  |  | 	NSString *executable = [[bundle executablePath] lastPathComponent]; | 
					
						
							|  |  |  | 	NSString *image = [executable stringByAppendingString:@".image"]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	NSString *returnVal; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if([path hasSuffix:@".app"] || [path hasSuffix:@".app/"]) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		NSFileManager *mgr = [NSFileManager defaultManager]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		NSString *imageInBundle = [[path stringByAppendingPathComponent:@"Contents/Resources"] stringByAppendingPathComponent:image]; | 
					
						
							|  |  |  | 		NSString *imageAlongBundle = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:image]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		returnVal = ([mgr fileExistsAtPath:imageInBundle] | 
					
						
							|  |  |  | 			? imageInBundle : imageAlongBundle); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		returnVal = [path stringByAppendingPathComponent:image]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return [returnVal UTF8String]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void init_signals(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unix_init_signals(); | 
					
						
							|  |  |  | 	mach_initialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Amateurs at Apple: implement this function, properly! */ | 
					
						
							|  |  |  | Protocol *objc_getProtocol(char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(strcmp(name,"NSTextInput") == 0) | 
					
						
							|  |  |  | 		return @protocol(NSTextInput); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return nil; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |