Applied changes based on official version of TinyScheme (CVS commit dated

2008/01/25 01:31). Put OP_T0LVL in charge of reacting to EOF.
This commit is contained in:
Kevin Cozens 2009-08-08 00:25:55 -04:00
parent 21cebda8a9
commit 3db68e254a
2 changed files with 35 additions and 48 deletions

View File

@ -13,7 +13,8 @@ enum scheme_port_kind {
port_string=2,
port_srfi6=4,
port_input=16,
port_output=32
port_output=32,
port_saw_EOF=64
};
typedef struct port {
@ -57,7 +58,6 @@ func_dealloc free;
/* return code */
int retcode;
int tracing;
int top_EOF; /* Have we seen EOF at top level? */
#define CELL_SEGSIZE 25000 /* # of cells in one segment */

View File

@ -1425,18 +1425,13 @@ static int file_push(scheme *sc, const char *fname) {
}
static void file_pop(scheme *sc) {
if(sc->file_i==0)
{ sc->top_EOF = 1; }
else
if(sc->file_i != 0)
{
sc->nesting=sc->nesting_stack[sc->file_i];
port_close(sc,sc->loadport,port_input);
sc->file_i--;
sc->loadport->_object._port=sc->load_stack+sc->file_i;
if(file_interactive(sc)) {
putstr(sc,prompt);
sc->nesting=sc->nesting_stack[sc->file_i];
port_close(sc,sc->loadport,port_input);
sc->file_i--;
sc->loadport->_object._port=sc->load_stack+sc->file_i;
}
}
}
static int file_interactive(scheme *sc) {
@ -1645,6 +1640,8 @@ static gunichar inchar(scheme *sc) {
port *pt;
pt = sc->inport->_object._port;
if(pt->kind & port_saw_EOF)
{ return(EOF); }
if(pt->kind&port_file)
{
if (sc->bc_flag)
@ -1655,6 +1652,9 @@ static gunichar inchar(scheme *sc) {
else
c = basic_inchar(pt);
if(c == EOF && sc->inport == sc->loadport) {
/* Instead, set port_saw_EOF */
pt->kind |= port_saw_EOF;
file_pop(sc);
return EOF;
/* NOTREACHED */
@ -2590,34 +2590,36 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) {
}
case OP_T0LVL: /* top level */
/* If we reached the end of file, this loop is done. */
if(sc->loadport->_object._port->kind & port_saw_EOF)
{
if(sc->file_i == 0)
{
sc->args=sc->NIL;
s_goto(sc,OP_QUIT);
}
else
{
file_pop(sc);
s_return(sc,sc->value);
}
/* NOTREACHED */
}
/* If interactive, be nice to user. */
if(file_interactive(sc))
{
sc->envir = sc->global_env;
dump_stack_reset(sc);
putstr(sc,"\n");
putstr(sc,prompt);
s_save(sc,OP_T0LVL, mk_integer(sc,sc->file_i), sc->NIL);
}
else
{
/* Each load of any file gets its own top-level loop that
ends when the file has been read. We detect that by
monitoring sc->file_i. */
pointer depth = sc->args;
if(is_integer(depth) && ivalue(depth) == sc->file_i)
{
s_save(sc,OP_T0LVL, depth, sc->NIL);
}
else
{
s_return(sc,sc->value);
/* NOTREACHED */
}
}
/* Set up another iteration of REPL */
sc->nesting=0;
sc->save_inport=sc->inport;
sc->inport = sc->loadport;
s_save(sc,OP_T0LVL, sc->NIL, sc->NIL);
s_save(sc,OP_VALUEPRINT, sc->NIL, sc->NIL);
s_save(sc,OP_T1LVL, sc->NIL, sc->NIL);
s_goto(sc,OP_READ_INTERNAL);
@ -2629,15 +2631,8 @@ static pointer opexe_0(scheme *sc, enum scheme_opcodes op) {
case OP_READ_INTERNAL: /* internal read */
sc->tok = token(sc);
if(sc->tok==TOK_EOF) {
if(sc->top_EOF)
{
sc->args=sc->NIL;
s_goto(sc,OP_QUIT);
} else {
s_return(sc,sc->EOF_OBJ);
}
}
if(sc->tok==TOK_EOF)
{ s_return(sc,sc->EOF_OBJ); }
s_goto(sc,OP_RDSEXPR);
case OP_GENSYM:
@ -4114,13 +4109,8 @@ static pointer opexe_5(scheme *sc, enum scheme_opcodes op) {
case OP_RDSEXPR:
switch (sc->tok) {
case TOK_EOF:
if(sc->top_EOF)
{
sc->args=sc->NIL;
s_goto(sc,OP_QUIT);
} else {
s_return(sc,sc->EOF_OBJ);
}
s_return(sc,sc->EOF_OBJ);
/* NOTREACHED */
/*
* Commented out because we now skip comments in the scanner
*
@ -4741,7 +4731,6 @@ int scheme_init_custom_alloc(scheme *sc, func_alloc malloc, func_dealloc free) {
sc->loadport=sc->NIL;
sc->nesting=0;
sc->interactive_repl=0;
sc->top_EOF = 0;
sc->print_output=0;
if (alloc_cellseg(sc,FIRST_CELLSEGS) != FIRST_CELLSEGS) {
@ -4875,7 +4864,6 @@ void scheme_load_file(scheme *sc, FILE *fin) {
sc->interactive_repl=1;
}
sc->inport=sc->loadport;
sc->top_EOF = 0;
sc->args = mk_integer(sc,sc->file_i);
Eval_Cycle(sc, OP_T0LVL);
typeflag(sc->loadport)=T_ATOM;
@ -4896,7 +4884,6 @@ void scheme_load_string(scheme *sc, const char *cmd) {
sc->retcode=0;
sc->interactive_repl=0;
sc->inport=sc->loadport;
sc->top_EOF = 0;
sc->args = mk_integer(sc,sc->file_i);
Eval_Cycle(sc, OP_T0LVL);
typeflag(sc->loadport)=T_ATOM;