renumber types, Objective-C exception handling

slava 2006-02-20 03:08:08 +00:00
parent 4990bade15
commit c2140920bd
19 changed files with 91 additions and 47 deletions

View File

@ -12,25 +12,34 @@ endif
DEFAULT_LIBS = -lm
UNIX_OBJS = native/unix/file.o \
native/unix/signal.o \
native/unix/ffi.o \
native/unix/run.o \
native/unix/memory.o \
native/unix/mach_signal.o \
native/unix/icache.o
WIN32_OBJS = native/win32/ffi.o \
native/win32/file.o \
native/win32/misc.o \
native/win32/run.o \
native/win32/memory.o
UNIX_OBJS = native/unix/file.o \
native/unix/signal.o \
native/unix/ffi.o \
native/unix/memory.o \
native/unix/icache.o
MACOSX_OBJS = $(UNIX_OBJS) \
native/macosx/run.o \
native/macosx/mach_signal.o
GENERIC_UNIX_OBJS = $(UNIX_OBJS) \
native/unix/run.o
ifdef WIN32
PLAF_OBJS = $(WIN32_OBJS)
PLAF_SUFFIX = .exe
PLAF_OBJS = $(WIN32_OBJS)
PLAF_SUFFIX = .exe
else
PLAF_OBJS = $(UNIX_OBJS)
ifdef MACOSX
PLAF_OBJS = $(MACOSX_OBJS)
else
PLAF_OBJS = $(GENERIC_UNIX_OBJS)
endif
endif
OBJS = $(PLAF_OBJS) native/array.o native/bignum.o \
@ -79,12 +88,14 @@ bsd:
macosx:
$(MAKE) $(BINARY) \
CFLAGS="$(DEFAULT_CFLAGS)" \
LIBS="$(DEFAULT_LIBS)"
LIBS="$(DEFAULT_LIBS)" \
MACOSX=y
macosx-sdl:
$(MAKE) $(BINARY) \
CFLAGS="$(DEFAULT_CFLAGS) -DFACTOR_SDL" \
LIBS="$(DEFAULT_LIBS) -lSDL -lSDLmain -framework Cocoa -framework OpenGL"
LIBS="$(DEFAULT_LIBS) -lSDL -lSDLmain -framework Cocoa -framework OpenGL" \
MACOSX=y
linux linux-x86 linux-amd64:
$(MAKE) $(BINARY) \
@ -120,3 +131,6 @@ clean:
.S.o:
$(CC) -c $(CFLAGS) -o $@ $<
.m.o:
$(CC) -c $(CFLAGS) -o $@ $<

View File

@ -1,12 +1,19 @@
- CFBundle error handling
- messages returning structs by value
- fix bootstrap compile errors
- out of memory from ffi calls
- update amd64 for %unbox-struct and callbacks
- clean up C stack frame assembly code to avoid moving spilled arguments
twice
- input values which get spilled
+ portability:
- port ffi to win64
- update amd64 for %unbox-struct and callbacks
- win64 port
- get factor running on mac intel
+ io:
- if select() returns an error, fep
- stream server can hang because of exception handler limitations
- better i/o scheduler
- if two tasks write to a unix stream, the buffer can overflow
@ -15,12 +22,8 @@
+ objective C/cocoa:
- CFBundle error handling
- autoload frameworks in cocoa class words
- exceptions
- subclassing
- messages returning structs by value
- fix bootstrap compile errors
- super message sends
+ ui/help:
@ -45,12 +48,10 @@
- float intrinsics
- complex float type
- complex float intrinsics
- out of memory from ffi calls
- out of memory from overflow check
- remove literal table
- callbacks
- input values which get spilled
- value type struct inputs
- value type struct inputs to callbacks
- C functions returning structs by value
- exceptions inside callbacks are broken:
- we need to unwind the stacks to the level where the exception handler
was set
@ -64,8 +65,6 @@
- [ [ dup call ] dup call ] infer hangs
- the invalid recursion form case needs to be fixed, for inlines too
- code gc
- clean up C stack frame assembly code to avoid moving spilled arguments
twice
+ misc:

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
! This library allows one to generate a new set of bootstrap
! images (boot.image.{le32,le64,be32,be64}.
! images.
!
! It does this by parsing the set of source files needed to
! generate the minimal image, and writing the cons cells, words,
@ -59,8 +59,8 @@ SYMBOL: architecture
: string-type 12 ; inline
: sbuf-type 13 ; inline
: wrapper-type 14 ; inline
: word-type 17 ; inline
: tuple-type 18 ; inline
: word-type 16 ; inline
: tuple-type 17 ; inline
: immediate ( x tag -- tagged ) swap tag-bits shift bitor ;
: >header ( id -- tagged ) object-tag immediate ;

View File

@ -330,7 +330,7 @@ num-types f <array> builtins set
{ { 1 { "dll-path" "alien" } f } } define-builtin
"word?" "words" create t "inline" set-word-prop
"word" "words" create 17 "word?" "words" create
"word" "words" create 16 "word?" "words" create
{
{ 1 { "hashcode" "kernel" } f }
{ 2 { "word-name" "words" } f }
@ -341,11 +341,11 @@ num-types f <array> builtins set
} define-builtin
"tuple?" "kernel" create t "inline" set-word-prop
"tuple" "kernel" create 18 "tuple?" "kernel" create
"tuple" "kernel" create 17 "tuple?" "kernel" create
{ } define-builtin
"byte-array?" "arrays" create t "inline" set-word-prop
"byte-array" "arrays" create 19
"byte-array" "arrays" create 18
"byte-array?" "arrays" create
{ } define-builtin

View File

@ -1,8 +1,8 @@
! Copyright (C) 2006 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
IN: cocoa
USING: alien errors kernel namespaces objc-NSApplication
objc-NSAutoreleasePool objc-NSObject threads ;
USING: alien errors io kernel namespaces objc-NSApplication
objc-NSAutoreleasePool objc-NSObject objc-NSException threads ;
: with-autorelease-pool ( quot -- )
NSAutoreleasePool [new] slip [release] ; inline
@ -29,3 +29,8 @@ objc-NSAutoreleasePool objc-NSObject threads ;
\ NSApplication set-global
[ (event-loop) ] in-thread
] when ;
IN: errors
: objc-error. ( alien -- )
"Objective C exception:" print [reason] CF>string print ;

View File

@ -22,6 +22,7 @@ USING: cocoa compiler io kernel objc sequences words ;
"NSDate"
"NSError"
"NSEvent"
"NSException"
"NSInvocation"
"NSMethodSignature"
"NSObject"

View File

@ -2,8 +2,6 @@
! See http://factorcode.org/license.txt for BSD license.
IN: objc
LIBRARY: objc
TYPEDEF: void* SEL
TYPEDEF: void* id

View File

@ -20,7 +20,7 @@ M: object clone ;
: set-boot ( quot -- ) 8 setenv ;
: num-types ( -- n ) 20 ; inline
: num-types ( -- n ) 19 ; inline
: ? ( cond t f -- t/f ) rot [ drop ] [ nip ] if ; inline

View File

@ -60,8 +60,11 @@ SYMBOL: error-continuation
: callstack-overflow. ( obj -- )
"Return stack overflow" print drop ;
! Hook for library/cocoa/
DEFER: objc-error. ( alien -- )
PREDICATE: cons kernel-error ( obj -- ? )
dup first kernel-error = swap second 0 15 between? and ;
dup first kernel-error = swap second 0 16 between? and ;
M: kernel-error error. ( error -- )
#! Kernel errors are indexed by integers.
@ -82,6 +85,7 @@ M: kernel-error error. ( error -- )
[ datastack-overflow. ]
[ callstack-underflow. ]
[ callstack-overflow. ]
[ objc-error. ]
} dispatch ;
M: no-method summary drop "No suitable method" ;

View File

@ -148,7 +148,7 @@ GENERIC: task-container ( task -- vector )
f ;
: io-multiplex ( timeout -- )
>r FD_SETSIZE init-fdsets r> make-timeval select drop
>r FD_SETSIZE init-fdsets r> make-timeval select io-error
read-fdset get read-tasks get handle-fdset
write-fdset get write-tasks get handle-fdset ;

View File

@ -14,6 +14,7 @@
#define ERROR_DS_OVERFLOW (13<<3)
#define ERROR_CS_UNDERFLOW (14<<3)
#define ERROR_CS_OVERFLOW (15<<3)
#define ERROR_OBJECTIVE_C (16<<3)
/* Are we throwing an error? */
bool throwing;

View File

@ -11,6 +11,7 @@ void init_factor(char* image, CELL ds_size, CELL cs_size,
init_stacks(ds_size,cs_size);
/* callframe must be valid in case load_image() does GC */
callframe = F;
thrown_error = F;
load_image(image,literal_size);
callframe = userenv[BOOT_ENV];
init_c_io();

22
native/macosx/run.m Normal file
View File

@ -0,0 +1,22 @@
/* Cocoa exception handling for Mac OS X */
#include "../factor.h"
#import "Foundation/NSException.h"
void platform_run()
{
for(;;)
{
SETJMP(toplevel);
handle_error();
NS_DURING
run(false);
NS_VOIDRETURN;
NS_HANDLER
general_error(ERROR_OBJECTIVE_C,
tag_object(make_alien(F,localException)),
true);
NS_ENDHANDLER
}
}

View File

@ -77,11 +77,11 @@ INLINE CELL align8(CELL a)
#define SBUF_TYPE 13
#define WRAPPER_TYPE 14
#define DLL_TYPE 15
#define WORD_TYPE 17
#define TUPLE_TYPE 18
#define BYTE_ARRAY_TYPE 19
#define WORD_TYPE 16
#define TUPLE_TYPE 17
#define BYTE_ARRAY_TYPE 18
#define TYPE_COUNT 20
#define TYPE_COUNT 19
/* Canonical T object. It's just a word */
CELL T;

View File

@ -37,12 +37,10 @@ void run(bool handle_errors)
if(handle_errors)
{
thrown_error = F;
SETJMP(toplevel);
handle_error();
}
handle_error();
for(;;)
{
if(callframe == F)

View File

@ -78,6 +78,7 @@ INLINE void call(CELL quot)
callframe = quot;
}
void handle_error();
void run(bool handle_errors);
void run_toplevel(void);
DLLEXPORT void run_callback(CELL quot);

View File

@ -1,5 +1,5 @@
#include "../factor.h"
#include "mach_signal.h"
#include "../macosx/mach_signal.h"
// this function tests if a given faulting location is in a poison page. The
// page address is taken from area + round_up_to_page_size(area_size) +