some miscellaneous error handling and bootstrapping cleanups

cvs
Slava Pestov 2004-08-23 06:15:10 +00:00
parent c66ded6bf8
commit 64de158286
16 changed files with 44 additions and 56 deletions

View File

@ -6,7 +6,6 @@
- jvm factor -- still supporting httpd? - jvm factor -- still supporting httpd?
- make inferior.factor nicer to use - make inferior.factor nicer to use
- telnetd printing signal 13, and other problems - telnetd printing signal 13, and other problems
- check error callstack, not enough >pop>?
+ docs: + docs:
@ -74,7 +73,6 @@
- namespace clone drops static var bindings - namespace clone drops static var bindings
- ditch expand - ditch expand
- set-object-path - set-object-path
- more readable traces
- telnetd: send errors on socket - telnetd: send errors on socket
- contains ==> contains? - contains ==> contains?

View File

@ -68,10 +68,3 @@ USE: vectors
#! the point after the callcc1 call, and places X at the top #! the point after the callcc1 call, and places X at the top
#! of the original datastack. #! of the original datastack.
[ [ continue1 ] (callcc) ] reify ; [ [ continue1 ] (callcc) ] reify ;
: suspend ( -- )
"top-level-continuation" get dup [
call
] [
toplevel
] ifte ;

View File

@ -53,8 +53,8 @@ USE: vectors
"error-line" set "error-line" set
"error-col" set "error-col" set
"error" set "error" set
datastack >pop> "error-datastack" set datastack "error-datastack" set
callstack >pop> >pop> "error-callstack" set callstack "error-callstack" set
namestack "error-namestack" set namestack "error-namestack" set
catchstack "error-catchstack" set catchstack "error-catchstack" set
] bind ] bind

View File

@ -117,5 +117,8 @@ USE: words
[ [
interpreter-loop interpreter-loop
] [ ] [
[ default-error-handler suspend ] when* [
default-error-handler
"top-level-continuation" get call
] when*
] catch ; ] catch ;

View File

@ -72,12 +72,12 @@ USE: stdio
"/library/platform/native/parse-syntax.factor" "/library/platform/native/parse-syntax.factor"
"/library/platform/native/parse-stream.factor" "/library/platform/native/parse-stream.factor"
"/library/platform/native/unparser.factor" "/library/platform/native/unparser.factor"
"/library/format.factor"
"/library/styles.factor" "/library/styles.factor"
"/library/vocabulary-style.factor" "/library/vocabulary-style.factor"
"/library/prettyprint.factor" "/library/prettyprint.factor"
"/library/debugger.factor"
"/library/platform/native/debugger.factor" "/library/platform/native/debugger.factor"
"/library/debugger.factor"
"/library/platform/native/init.factor" "/library/platform/native/init.factor"
"/library/math/math.factor" "/library/math/math.factor"

View File

@ -66,13 +66,8 @@ primitives,
"/library/platform/native/parser.factor" "/library/platform/native/parser.factor"
"/library/platform/native/parse-syntax.factor" "/library/platform/native/parse-syntax.factor"
"/library/platform/native/parse-stream.factor" "/library/platform/native/parse-stream.factor"
"/library/platform/native/unparser.factor"
"/library/format.factor" "/library/format.factor"
"/library/styles.factor" "/library/platform/native/unparser.factor"
"/library/vocabulary-style.factor"
"/library/prettyprint.factor"
"/library/debugger.factor"
"/library/platform/native/debugger.factor"
"/library/platform/native/init.factor" "/library/platform/native/init.factor"
] [ ] [
cross-compile-resource cross-compile-resource

View File

@ -94,6 +94,7 @@ USE: vectors
signal-error signal-error
io-task-twice-error io-task-twice-error
no-io-tasks-error no-io-tasks-error
profiling-disabled-error
} vector-nth execute ; } vector-nth execute ;
: kernel-error? ( obj -- ? ) : kernel-error? ( obj -- ? )

View File

@ -35,12 +35,3 @@ USE: vectors
: catchstack ( -- cs ) catchstack* clone ; : catchstack ( -- cs ) catchstack* clone ;
: set-catchstack* ( cs -- ) 6 setenv ; : set-catchstack* ( cs -- ) 6 setenv ;
: set-catchstack ( cs -- ) clone set-catchstack* ; : set-catchstack ( cs -- ) clone set-catchstack* ;
DEFER: >c
DEFER: throw
: init-errors ( -- )
64 <vector> set-catchstack*
[ 1 exit* ] >c ( last resort )
[ default-error-handler 1 exit* ] >c
[ throw ] 5 setenv ( kernel calls on error ) ;

View File

@ -41,11 +41,17 @@ USE: words
: cli-args ( -- args ) 10 getenv ; : cli-args ( -- args ) 10 getenv ;
: init-error-handler ( -- )
[ 1 exit* ] >c ( last resort )
[ default-error-handler 1 exit* ] >c
[ throw ] 5 setenv ( kernel calls on error ) ;
: warm-boot ( -- ) : warm-boot ( -- )
#! A fully bootstrapped image has this as the boot #! A fully bootstrapped image has this as the boot
#! quotation. #! quotation.
boot boot
init-error-handler
init-random init-random
"stdio" get <ansi-stream> "stdio" set "stdio" get <ansi-stream> "stdio" set

View File

@ -35,6 +35,10 @@ USE: stdio
USE: streams USE: streams
USE: threads USE: threads
USE: words USE: words
USE: vectors
: init-errors ( -- )
64 <vector> set-catchstack* ;
: init-gc ( -- ) : init-gc ( -- )
[ garbage-collection ] 7 setenv ; [ garbage-collection ] 7 setenv ;
@ -42,10 +46,10 @@ USE: words
: boot ( -- ) : boot ( -- )
#! Initialize an interpreter with the basic services. #! Initialize an interpreter with the basic services.
init-gc init-gc
init-errors
init-namespaces init-namespaces
init-threads init-threads
init-stdio init-stdio
init-errors
"HOME" os-env [ "." ] unless* "~" set "HOME" os-env [ "." ] unless* "~" set
10 "base" set 10 "base" set
"/" "/" set "/" "/" set

View File

@ -25,15 +25,9 @@
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: namespaces
DEFER: init-namespaces
IN: vectors IN: vectors
DEFER: vector= DEFER: vector=
IN: errors
DEFER: init-errors
IN: kernel IN: kernel
USE: arithmetic USE: arithmetic
USE: combinators USE: combinators
@ -105,12 +99,6 @@ USE: vectors
[ 103 | "fixnum/bignum/ratio/float/complex" ] [ 103 | "fixnum/bignum/ratio/float/complex" ]
] assoc ; ] assoc ;
: toplevel ( -- )
init-namespaces
init-errors
0 <vector> set-datastack
0 <vector> set-callstack ;
: java? f ; : java? f ;
: native? t ; : native? t ;

View File

@ -30,11 +30,6 @@ void throw_error(CELL error)
dpush(error); dpush(error);
/* Execute the 'throw' word */ /* Execute the 'throw' word */
call(userenv[BREAK_ENV]); call(userenv[BREAK_ENV]);
if(callframe == 0)
{
/* Crash at startup */
fatal_error("Error thrown before BREAK_ENV set",error);
}
/* Return to run() method */ /* Return to run() method */
siglongjmp(toplevel,1); siglongjmp(toplevel,1);
@ -43,6 +38,20 @@ void throw_error(CELL error)
void general_error(CELL error, CELL tagged) void general_error(CELL error, CELL tagged)
{ {
CONS* c = cons(error,tag_cons(cons(tagged,F))); CONS* c = cons(error,tag_cons(cons(tagged,F)));
if(userenv[BREAK_ENV] == 0)
{
/* Crash at startup */
fprintf(stderr,"Error thrown before BREAK_ENV set\n");
fprintf(stderr,"Error #%d\n",to_fixnum(error));
if(error == ERROR_TYPE)
{
fprintf(stderr,"Type #%d\n",to_fixnum(
untag_cons(tagged)->car));
fprintf(stderr,"Got type #%d\n",type_of(
untag_cons(tagged)->cdr));
}
exit(1);
}
throw_error(tag_cons(c)); throw_error(tag_cons(c));
} }

View File

@ -40,8 +40,8 @@ typedef unsigned short CHAR;
and allows profiling. */ and allows profiling. */
#define EXTRA_CALL_INFO #define EXTRA_CALL_INFO
#include "error.h"
#include "memory.h" #include "memory.h"
#include "error.h"
#include "gc.h" #include "gc.h"
#include "types.h" #include "types.h"
#include "array.h" #include "array.h"

View File

@ -129,7 +129,7 @@ void primitive_setenv(void)
void primitive_profiling(void) void primitive_profiling(void)
{ {
#ifndef EXTRA_CALL_INFO #ifndef EXTRA_CALL_INFO
general_error(PROFILING_DISABLED,F); general_error(ERROR_PROFILING_DISABLED,F);
#else #else
CELL d = dpop(); CELL d = dpop();
if(d == F) if(d == F)

View File

@ -43,11 +43,6 @@ CELL userenv[USER_ENV];
/* This ensures that words in the user's interpreter do not count */ /* This ensures that words in the user's interpreter do not count */
CELL profile_depth; CELL profile_depth;
void signal_handler(int signal, siginfo_t* siginfo, void* uap);
void profiling_step(int signal, siginfo_t* siginfo, void* uap);
void init_signals(void);
void clear_environment(void);
INLINE CELL dpop(void) INLINE CELL dpop(void)
{ {
ds -= CELLS; ds -= CELLS;
@ -100,6 +95,11 @@ INLINE void call(CELL quot)
callframe = quot; callframe = quot;
} }
void signal_handler(int signal, siginfo_t* siginfo, void* uap);
void profiling_step(int signal, siginfo_t* siginfo, void* uap);
void init_signals(void);
void clear_environment(void);
void run(void); void run(void);
void undefined(void); void undefined(void);
void docol(void); void docol(void);

View File

@ -1,5 +1,5 @@
#define STACK_UNDERFLOW(stack,bot) ((stack) < UNTAG(bot) + sizeof(ARRAY)) #define STACK_UNDERFLOW(stack,bot) ((stack) < UNTAG(bot))
#define STACK_OVERFLOW(stack,bot) ((stack) >= UNTAG(bot) + object_size(bot)) #define STACK_OVERFLOW(stack,bot) ((stack) >= UNTAG(bot) + STACK_SIZE)
void reset_datastack(void); void reset_datastack(void);
void reset_callstack(void); void reset_callstack(void);