]> gitweb.factorcode.org Git - factor.git/commitdiff
datastack in ESI
authorSlava Pestov <slava@factorcode.org>
Sat, 6 Nov 2004 20:51:17 +0000 (20:51 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 6 Nov 2004 20:51:17 +0000 (20:51 +0000)
library/compiler/compiler-macros.factor
native/error.c
native/error.h
native/factor.c
native/factor.h
native/run.c
native/run.h

index f210a5ba803319106aa450f72e83e76d72cf8d89..b5c9d50894ae08dfe88d3f4498a4ab2cebbd36f9 100644 (file)
 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.
index 84932d7b7c23ccd483618b428601bdb43d0e1592..350c6e2dfc51cc0ceb04fa547fff27514c709772 100644 (file)
@@ -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);
index 2b6dda1b5ac6a899fb146c2d02c0c4e8fa6ab07d..47d1a98170b4fd0b48bff172fc605d15c7386b75 100644 (file)
 #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);
index ad200c062b7178ab6deb796c9f6e9dd5ad9435cc..67f2ff9bd032626a4f9f4d0302a24cc8912c8a5b 100644 (file)
@@ -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"));
index d5d310ab81b3ec6e30483d984c08db4098573602..2b29cf9d5bc46c03d8e7d75296e942a0888b9b36 100644 (file)
 #include <dlfcn.h>
 #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 */
index 93e2a07b0e29ae54355f14fe53d6fbf824d15258..136ce257d340f83ba64acd3033741deeb81ab93a 100644 (file)
@@ -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(;;)
        {
index 9e658ac5f9ec96b4ff42b823e771f87fb2cd0eb6..4323d0a1effb6b1c036de47b8a46fb7e81440e02 100644 (file)
@@ -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;