diff --git a/library/compiler/compiler-macros.factor b/library/compiler/compiler-macros.factor index f210a5ba80..b5c9d50894 100644 --- a/library/compiler/compiler-macros.factor +++ b/library/compiler/compiler-macros.factor @@ -28,48 +28,32 @@ IN: compiler USE: alien -: DATASTACK ( -- ptr ) - #! A pointer to a pointer to the datastack top. - "ds" dlsym-self ; - -: CALLSTACK ( -- ptr ) - #! A pointer to a pointer to the callstack top. - "cs" dlsym-self ; - : LITERAL ( cell -- ) #! Push literal on data stack. - #! Assume that it is ok to clobber EAX without saving. - DATASTACK EAX [I]>R - EAX I>[R] - 4 DATASTACK I+[I] ; + ESI I>[R] + 4 ESI R+I ; : [LITERAL] ( cell -- ) #! Push complex literal on data stack by following an #! indirect pointer. - ECX PUSH-R - ( cell -- ) ECX [I]>R - DATASTACK EAX [I]>R - ECX EAX R>[R] - 4 DATASTACK I+[I] - ECX POP-R ; + EAX [I]>R + EAX ESI R>[R] + 4 ESI R+I ; : PUSH-DS ( -- ) #! Push contents of EAX onto datastack. - ECX PUSH-R - DATASTACK ECX [I]>R - EAX ECX R>[R] - 4 DATASTACK I+[I] - ECX POP-R ; + EAX ESI R>[R] + 4 ESI R+I ; : PEEK-DS ( -- ) #! Peek datastack, store pointer to datastack top in EAX. - DATASTACK EAX [I]>R + ESI EAX R>R 4 EAX R-I ; : POP-DS ( -- ) #! Pop datastack, store pointer to datastack top in EAX. PEEK-DS - EAX DATASTACK R>[I] ; + EAX ESI R>R ; : SELF-CALL ( name -- ) #! Call named C function in Factor interpreter executable. diff --git a/native/error.c b/native/error.c index 84932d7b7c..350c6e2dfc 100644 --- a/native/error.c +++ b/native/error.c @@ -1,5 +1,10 @@ #include "factor.h" +void init_errors(void) +{ + thrown_error = F; +} + void fatal_error(char* msg, CELL tagged) { fprintf(stderr,"Fatal error: %s %ld\n",msg,tagged); @@ -15,9 +20,9 @@ void critical_error(char* msg, CELL tagged) void throw_error(CELL error) { - dpush(error); - /* Execute the 'throw' word */ - call(userenv[BREAK_ENV]); + /* dpush(error); */ + /* call(userenv[BREAK_ENV]); */ + thrown_error = error; /* Return to run() method */ siglongjmp(toplevel,1); diff --git a/native/error.h b/native/error.h index 2b6dda1b5a..47d1a98170 100644 --- a/native/error.h +++ b/native/error.h @@ -19,6 +19,11 @@ #define ERROR_CALLSTACK_OVERFLOW (18<<3) #define ERROR_CLOSED (19<<3) +/* When throw_error throws an error, it sets this global and +longjmps back to the top-level. */ +CELL thrown_error; + +void init_errors(void); void fatal_error(char* msg, CELL tagged); void critical_error(char* msg, CELL tagged); void throw_error(CELL object); diff --git a/native/factor.c b/native/factor.c index ad200c062b..67f2ff9bd0 100644 --- a/native/factor.c +++ b/native/factor.c @@ -18,6 +18,7 @@ int main(int argc, char** argv) init_io(); init_signals(); init_compiler(); + init_errors(); args = F; while(--argc != 0) @@ -27,7 +28,7 @@ int main(int argc, char** argv) userenv[ARGS_ENV] = args; -#if defined(i386) || defined(__i386) || defined(__i386__) +#ifdef FACTOR_X86 userenv[CPU_ENV] = tag_object(from_c_string("x86")); #else userenv[CPU_ENV] = tag_object(from_c_string("unknown")); diff --git a/native/factor.h b/native/factor.h index d5d310ab81..2b29cf9d5b 100644 --- a/native/factor.h +++ b/native/factor.h @@ -27,6 +27,10 @@ #include #endif /* FFI */ +#if defined(i386) || defined(__i386) || defined(__i386__) + #define FACTOR_X86 +#endif + #define INLINE inline static /* CELL must be 32 bits and your system must have 32-bit pointers */ diff --git a/native/run.c b/native/run.c index 93e2a07b0e..136ce257d3 100644 --- a/native/run.c +++ b/native/run.c @@ -16,6 +16,13 @@ void run(void) /* Error handling. */ sigsetjmp(toplevel, 1); + if(thrown_error != F) + { + dpush(thrown_error); + /* Notify any 'catch' blocks */ + call(userenv[BREAK_ENV]); + thrown_error = F; + } for(;;) { diff --git a/native/run.h b/native/run.h index 9e658ac5f9..4323d0a1ef 100644 --- a/native/run.h +++ b/native/run.h @@ -25,9 +25,7 @@ CELL callframe; CELL ds_bot; /* raw pointer to datastack top */ -/* #define X86_STACK */ - -#ifdef X86_STACK +#ifdef FACTOR_X86 register CELL ds asm("%esi"); #else CELL ds; @@ -37,11 +35,7 @@ CELL ds; CELL cs_bot; /* raw pointer to callstack top */ -#ifdef X86_STACK -register CELL cs asm("edi"); -#else CELL cs; -#endif /* raw pointer to currently executing word */ WORD* executing;