datastack in ESI
parent
df39f78f6d
commit
5f5b0e131b
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
#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 */
|
||||
|
|
|
@ -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(;;)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue