Double-clicking Factor.app now works

release
slava 2006-03-19 07:42:40 +00:00
parent ff1d24d25e
commit 79bcbff3ec
7 changed files with 75 additions and 25 deletions

View File

@ -2,8 +2,10 @@ CC = gcc
CP = cp CP = cp
BINARY = f BINARY = f
IMAGE = factor.image
BUNDLE = Factor.app BUNDLE = Factor.app
BUNDLE_BINARY = $(BUNDLE)/Contents/MacOS/Factor BUNDLE_BINARY = $(BUNDLE)/Contents/MacOS/Factor
BUNDLE_IMAGE = $(BUNDLE)/Contents/factor.image
ifdef DEBUG ifdef DEBUG
DEFAULT_CFLAGS = -g DEFAULT_CFLAGS = -g
@ -92,7 +94,10 @@ macosx:
CFLAGS="$(DEFAULT_CFLAGS)" \ CFLAGS="$(DEFAULT_CFLAGS)" \
LIBS="$(DEFAULT_LIBS) -framework Cocoa -framework OpenGL" \ LIBS="$(DEFAULT_LIBS) -framework Cocoa -framework OpenGL" \
MACOSX=y MACOSX=y
macosx.app:
$(CP) $(BINARY) $(BUNDLE_BINARY) $(CP) $(BINARY) $(BUNDLE_BINARY)
$(CP) $(IMAGE) $(BUNDLE_IMAGE)
linux linux-x86 linux-amd64: linux linux-x86 linux-amd64:
$(MAKE) $(BINARY) \ $(MAKE) $(BINARY) \

View File

@ -37,20 +37,7 @@ INLINE bool factor_arg(const char* str, const char* arg, CELL* value)
return false; return false;
} }
int main(int argc, char** argv) void usage(void)
{
char *image;
CELL ds_size = 128;
CELL cs_size = 128;
CELL generations = 2;
CELL young_size = 2 * CELLS;
CELL aging_size = 4 * CELLS;
CELL code_size = CELLS;
CELL literal_size = 128;
CELL args;
CELL i;
if(argc == 1)
{ {
printf("Usage: factor <image file> [ parameters ... ]\n"); printf("Usage: factor <image file> [ parameters ... ]\n");
printf("Runtime options -- n is a number:\n"); printf("Runtime options -- n is a number:\n");
@ -63,9 +50,23 @@ int main(int argc, char** argv)
printf("Other options are handled by the Factor library.\n"); printf("Other options are handled by the Factor library.\n");
printf("See the documentation for details.\n"); printf("See the documentation for details.\n");
printf("Send bug reports to Slava Pestov <slava@factorcode.org>.\n"); printf("Send bug reports to Slava Pestov <slava@factorcode.org>.\n");
return 1;
} }
int main(int argc, char** argv)
{
char *image = NULL;
CELL ds_size = 128;
CELL cs_size = 128;
CELL generations = 2;
CELL young_size = 2 * CELLS;
CELL aging_size = 4 * CELLS;
CELL code_size = CELLS;
CELL literal_size = 128;
CELL args;
CELL i;
early_init();
for(i = 1; i < argc; i++) for(i = 1; i < argc; i++)
{ {
if(factor_arg(argv[i],"+D%d",&ds_size)) continue; if(factor_arg(argv[i],"+D%d",&ds_size)) continue;
@ -78,11 +79,16 @@ int main(int argc, char** argv)
if(strncmp(argv[i],"+",1) == 0) if(strncmp(argv[i],"+",1) == 0)
{ {
printf("Unknown option: %s\n",argv[i]); printf("Unknown option: %s\n",argv[i]);
usage();
return 1; return 1;
} }
if(strncmp(argv[i],"-",1) != 0 && image == NULL)
image = argv[1];
} }
image = argv[1]; if(image == NULL)
image = default_image_path();
init_factor(image, init_factor(image,
ds_size * 1024, ds_size * 1024,
@ -94,7 +100,7 @@ int main(int argc, char** argv)
literal_size * 1024); literal_size * 1024);
args = F; args = F;
while(--argc != 1) while(--argc > 1)
{ {
args = cons(tag_object(from_c_string(argv[argc])),args); args = cons(tag_object(from_c_string(argv[argc])),args);
} }

View File

@ -141,4 +141,10 @@ CELL executing;
#include "dll.h" #include "dll.h"
#include "wrapper.h" #include "wrapper.h"
void usage(void);
void early_init(void);
const char *default_image_path(void);
#endif /* __FACTOR_H__ */ #endif /* __FACTOR_H__ */

View File

@ -20,11 +20,16 @@ void load_image(char* filename, int literal_table)
HEADER h; HEADER h;
HEADER_2 ext_h; HEADER_2 ext_h;
printf("Loading %s...",filename);
file = fopen(filename,"rb"); file = fopen(filename,"rb");
if(file == NULL) if(file == NULL)
fatal_error("Cannot open image for reading",errno); {
fprintf(stderr,"Cannot open image file: %s\n",filename);
fprintf(stderr,"%s\n",strerror(errno));
usage();
exit(1);
}
printf("Loading %s...",filename);
/* read header */ /* read header */
{ {

View File

@ -1,7 +1,10 @@
/* Cocoa exception handling for Mac OS X */ /* Cocoa exception handling and default image path for Mac OS X */
#include "../factor.h" #include "../factor.h"
#import "Foundation/NSAutoreleasePool.h"
#import "Foundation/NSBundle.h"
#import "Foundation/NSException.h" #import "Foundation/NSException.h"
#import "Foundation/NSString.h"
/* This code is convoluted because Cocoa places restrictions on longjmp and /* This code is convoluted because Cocoa places restrictions on longjmp and
exception handling. In particular, a longjmp can never cross an NS_DURING, exception handling. In particular, a longjmp can never cross an NS_DURING,
@ -20,7 +23,7 @@ NS_DURING
{ {
CELL e = error; CELL e = error;
error = F; error = F;
general_error(ERROR_OBJECTIVE_C,error,true); general_error(ERROR_OBJECTIVE_C,e,true);
} }
run(); run();
@ -31,3 +34,15 @@ NS_ENDHANDLER
} }
} }
void early_init(void)
{
[[NSAutoreleasePool alloc] init];
}
const char *default_image_path(void)
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle bundlePath];
NSString *image = [path stringByAppendingString:@"/Contents/factor.image"];
return [image cString];
}

View File

@ -1,7 +1,13 @@
#include "../factor.h" #include "../factor.h"
void platform_run() void platform_run(void)
{ {
run_toplevel(); run_toplevel();
} }
void early_init(void) {}
char *default_image_path()
{
return "factor.image";
}

View File

@ -24,7 +24,14 @@ static long exception_handler(void *rec, void *frame, void *ctx, void *dispatch)
signal_error(SIGSEGV); signal_error(SIGSEGV);
} }
void platform_run () void platform_run(void)
{ {
seh_call(run_toplevel, exception_handler); seh_call(run_toplevel, exception_handler);
} }
void early_init(void) {}
const char *default_image_path()
{
return "factor.image";
}