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

View File

@ -37,9 +37,24 @@ INLINE bool factor_arg(const char* str, const char* arg, CELL* value)
return false;
}
void usage(void)
{
printf("Usage: factor <image file> [ parameters ... ]\n");
printf("Runtime options -- n is a number:\n");
printf(" +Dn Data stack size, kilobytes\n");
printf(" +Cn Call stack size, kilobytes\n");
printf(" +Gn Number of generations, must be >= 2\n");
printf(" +Yn Size of n-1 youngest generations, megabytes\n");
printf(" +An Size of tenured and semi-spaces, megabytes\n");
printf(" +Xn Code heap size, megabytes\n");
printf("Other options are handled by the Factor library.\n");
printf("See the documentation for details.\n");
printf("Send bug reports to Slava Pestov <slava@factorcode.org>.\n");
}
int main(int argc, char** argv)
{
char *image;
char *image = NULL;
CELL ds_size = 128;
CELL cs_size = 128;
CELL generations = 2;
@ -50,21 +65,7 @@ int main(int argc, char** argv)
CELL args;
CELL i;
if(argc == 1)
{
printf("Usage: factor <image file> [ parameters ... ]\n");
printf("Runtime options -- n is a number:\n");
printf(" +Dn Data stack size, kilobytes\n");
printf(" +Cn Call stack size, kilobytes\n");
printf(" +Gn Number of generations, must be >= 2\n");
printf(" +Yn Size of n-1 youngest generations, megabytes\n");
printf(" +An Size of tenured and semi-spaces, megabytes\n");
printf(" +Xn Code heap size, megabytes\n");
printf("Other options are handled by the Factor library.\n");
printf("See the documentation for details.\n");
printf("Send bug reports to Slava Pestov <slava@factorcode.org>.\n");
return 1;
}
early_init();
for(i = 1; i < argc; i++)
{
@ -78,11 +79,16 @@ int main(int argc, char** argv)
if(strncmp(argv[i],"+",1) == 0)
{
printf("Unknown option: %s\n",argv[i]);
usage();
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,
ds_size * 1024,
@ -94,7 +100,7 @@ int main(int argc, char** argv)
literal_size * 1024);
args = F;
while(--argc != 1)
while(--argc > 1)
{
args = cons(tag_object(from_c_string(argv[argc])),args);
}

View File

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

View File

@ -20,11 +20,16 @@ void load_image(char* filename, int literal_table)
HEADER h;
HEADER_2 ext_h;
printf("Loading %s...",filename);
file = fopen(filename,"rb");
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 */
{

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"
#import "Foundation/NSAutoreleasePool.h"
#import "Foundation/NSBundle.h"
#import "Foundation/NSException.h"
#import "Foundation/NSString.h"
/* This code is convoluted because Cocoa places restrictions on longjmp and
exception handling. In particular, a longjmp can never cross an NS_DURING,
@ -20,7 +23,7 @@ NS_DURING
{
CELL e = error;
error = F;
general_error(ERROR_OBJECTIVE_C,error,true);
general_error(ERROR_OBJECTIVE_C,e,true);
}
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"
void platform_run()
void platform_run(void)
{
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);
}
void platform_run ()
void platform_run(void)
{
seh_call(run_toplevel, exception_handler);
}
void early_init(void) {}
const char *default_image_path()
{
return "factor.image";
}