datastack in ESI
parent
df39f78f6d
commit
5f5b0e131b
|
@ -28,48 +28,32 @@
|
||||||
IN: compiler
|
IN: compiler
|
||||||
USE: alien
|
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 -- )
|
: LITERAL ( cell -- )
|
||||||
#! Push literal on data stack.
|
#! Push literal on data stack.
|
||||||
#! Assume that it is ok to clobber EAX without saving.
|
ESI I>[R]
|
||||||
DATASTACK EAX [I]>R
|
4 ESI R+I ;
|
||||||
EAX I>[R]
|
|
||||||
4 DATASTACK I+[I] ;
|
|
||||||
|
|
||||||
: [LITERAL] ( cell -- )
|
: [LITERAL] ( cell -- )
|
||||||
#! Push complex literal on data stack by following an
|
#! Push complex literal on data stack by following an
|
||||||
#! indirect pointer.
|
#! indirect pointer.
|
||||||
ECX PUSH-R
|
EAX [I]>R
|
||||||
( cell -- ) ECX [I]>R
|
EAX ESI R>[R]
|
||||||
DATASTACK EAX [I]>R
|
4 ESI R+I ;
|
||||||
ECX EAX R>[R]
|
|
||||||
4 DATASTACK I+[I]
|
|
||||||
ECX POP-R ;
|
|
||||||
|
|
||||||
: PUSH-DS ( -- )
|
: PUSH-DS ( -- )
|
||||||
#! Push contents of EAX onto datastack.
|
#! Push contents of EAX onto datastack.
|
||||||
ECX PUSH-R
|
EAX ESI R>[R]
|
||||||
DATASTACK ECX [I]>R
|
4 ESI R+I ;
|
||||||
EAX ECX R>[R]
|
|
||||||
4 DATASTACK I+[I]
|
|
||||||
ECX POP-R ;
|
|
||||||
|
|
||||||
: PEEK-DS ( -- )
|
: PEEK-DS ( -- )
|
||||||
#! Peek datastack, store pointer to datastack top in EAX.
|
#! Peek datastack, store pointer to datastack top in EAX.
|
||||||
DATASTACK EAX [I]>R
|
ESI EAX R>R
|
||||||
4 EAX R-I ;
|
4 EAX R-I ;
|
||||||
|
|
||||||
: POP-DS ( -- )
|
: POP-DS ( -- )
|
||||||
#! Pop datastack, store pointer to datastack top in EAX.
|
#! Pop datastack, store pointer to datastack top in EAX.
|
||||||
PEEK-DS
|
PEEK-DS
|
||||||
EAX DATASTACK R>[I] ;
|
EAX ESI R>R ;
|
||||||
|
|
||||||
: SELF-CALL ( name -- )
|
: SELF-CALL ( name -- )
|
||||||
#! Call named C function in Factor interpreter executable.
|
#! Call named C function in Factor interpreter executable.
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
#include "factor.h"
|
#include "factor.h"
|
||||||
|
|
||||||
|
void init_errors(void)
|
||||||
|
{
|
||||||
|
thrown_error = F;
|
||||||
|
}
|
||||||
|
|
||||||
void fatal_error(char* msg, CELL tagged)
|
void fatal_error(char* msg, CELL tagged)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Fatal error: %s %ld\n",msg,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)
|
void throw_error(CELL error)
|
||||||
{
|
{
|
||||||
dpush(error);
|
/* dpush(error); */
|
||||||
/* Execute the 'throw' word */
|
/* call(userenv[BREAK_ENV]); */
|
||||||
call(userenv[BREAK_ENV]);
|
thrown_error = error;
|
||||||
|
|
||||||
/* Return to run() method */
|
/* Return to run() method */
|
||||||
siglongjmp(toplevel,1);
|
siglongjmp(toplevel,1);
|
||||||
|
|
|
@ -19,6 +19,11 @@
|
||||||
#define ERROR_CALLSTACK_OVERFLOW (18<<3)
|
#define ERROR_CALLSTACK_OVERFLOW (18<<3)
|
||||||
#define ERROR_CLOSED (19<<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 fatal_error(char* msg, CELL tagged);
|
||||||
void critical_error(char* msg, CELL tagged);
|
void critical_error(char* msg, CELL tagged);
|
||||||
void throw_error(CELL object);
|
void throw_error(CELL object);
|
||||||
|
|
|
@ -18,6 +18,7 @@ int main(int argc, char** argv)
|
||||||
init_io();
|
init_io();
|
||||||
init_signals();
|
init_signals();
|
||||||
init_compiler();
|
init_compiler();
|
||||||
|
init_errors();
|
||||||
|
|
||||||
args = F;
|
args = F;
|
||||||
while(--argc != 0)
|
while(--argc != 0)
|
||||||
|
@ -27,7 +28,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
userenv[ARGS_ENV] = args;
|
userenv[ARGS_ENV] = args;
|
||||||
|
|
||||||
#if defined(i386) || defined(__i386) || defined(__i386__)
|
#ifdef FACTOR_X86
|
||||||
userenv[CPU_ENV] = tag_object(from_c_string("x86"));
|
userenv[CPU_ENV] = tag_object(from_c_string("x86"));
|
||||||
#else
|
#else
|
||||||
userenv[CPU_ENV] = tag_object(from_c_string("unknown"));
|
userenv[CPU_ENV] = tag_object(from_c_string("unknown"));
|
||||||
|
|
|
@ -27,6 +27,10 @@
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif /* FFI */
|
#endif /* FFI */
|
||||||
|
|
||||||
|
#if defined(i386) || defined(__i386) || defined(__i386__)
|
||||||
|
#define FACTOR_X86
|
||||||
|
#endif
|
||||||
|
|
||||||
#define INLINE inline static
|
#define INLINE inline static
|
||||||
|
|
||||||
/* CELL must be 32 bits and your system must have 32-bit pointers */
|
/* CELL must be 32 bits and your system must have 32-bit pointers */
|
||||||
|
|
|
@ -16,6 +16,13 @@ void run(void)
|
||||||
|
|
||||||
/* Error handling. */
|
/* Error handling. */
|
||||||
sigsetjmp(toplevel, 1);
|
sigsetjmp(toplevel, 1);
|
||||||
|
if(thrown_error != F)
|
||||||
|
{
|
||||||
|
dpush(thrown_error);
|
||||||
|
/* Notify any 'catch' blocks */
|
||||||
|
call(userenv[BREAK_ENV]);
|
||||||
|
thrown_error = F;
|
||||||
|
}
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,9 +25,7 @@ CELL callframe;
|
||||||
CELL ds_bot;
|
CELL ds_bot;
|
||||||
|
|
||||||
/* raw pointer to datastack top */
|
/* raw pointer to datastack top */
|
||||||
/* #define X86_STACK */
|
#ifdef FACTOR_X86
|
||||||
|
|
||||||
#ifdef X86_STACK
|
|
||||||
register CELL ds asm("%esi");
|
register CELL ds asm("%esi");
|
||||||
#else
|
#else
|
||||||
CELL ds;
|
CELL ds;
|
||||||
|
@ -37,11 +35,7 @@ CELL ds;
|
||||||
CELL cs_bot;
|
CELL cs_bot;
|
||||||
|
|
||||||
/* raw pointer to callstack top */
|
/* raw pointer to callstack top */
|
||||||
#ifdef X86_STACK
|
|
||||||
register CELL cs asm("edi");
|
|
||||||
#else
|
|
||||||
CELL cs;
|
CELL cs;
|
||||||
#endif
|
|
||||||
|
|
||||||
/* raw pointer to currently executing word */
|
/* raw pointer to currently executing word */
|
||||||
WORD* executing;
|
WORD* executing;
|
||||||
|
|
Loading…
Reference in New Issue