Skip to content

Commit

Permalink
Fix DownEnv / UpEnv handling
Browse files Browse the repository at this point in the history
Also get rid of STATE(ErrorLVars0)

This is an example for DownEnv/UpEnv usage:

gap> f:=lvl -> 1/lvl + f(lvl-1);
function( lvl ) ... end
gap> f(3);
Error, Rational operations: <divisor> must not be zero in
  return 1 / lvl + f( (lvl - 1) ); called from
f( lvl - 1 ) called from
f( lvl - 1 ) called from
f( lvl - 1 ) called from
<function "f">( <arguments> )
 called from read-eval loop at line 12 of *stdin*
you can replace <divisor> via 'return <divisor>;'
brk> lvl;
0
brk> UpEnv(1); lvl;
0
brk> DownEnv(1); lvl;
1
brk> DownEnv(1); lvl;
2
brk> UpEnv(1); lvl;
1
brk> DownEnv(1); lvl;
2
brk> DownEnv(1); lvl;
3
brk> DownEnv(1); lvl;
3
brk> UpEnv(1); lvl;
2

Note that before this commit, the very last UpEnv(1) incorrectly returned
us to level 0.
  • Loading branch information
fingolfin committed Oct 17, 2017
1 parent 0889bf2 commit bff7efb
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ void DownEnvInner( Int depth )
depth = 0;
}
/* ... then go back to the top, and later go down to the appropriate level. */
STATE(ErrorLVars) = STATE(ErrorLVars0);
STATE(ErrorLVars) = STATE(BaseShellContext);
STATE(ErrorLLevel) = 0;
STATE(ShellContext) = STATE(BaseShellContext);
}
Expand Down
3 changes: 0 additions & 3 deletions src/gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ extern void ErrorReturnVoid (
Int arg2,
const Char * msg2 );

/* TL: extern Obj ErrorLVars;
TL: extern Obj ErrorLVars0;
*/

/****************************************************************************
**
Expand Down
3 changes: 1 addition & 2 deletions src/gapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ typedef struct GAPState {
UInt UserHasQUIT;
Obj ShellContext;
Obj BaseShellContext;
Obj ErrorLVars0; // the initial ErrorLVars value, i.e. for the lvars were the break occurred
Obj ErrorLVars; // ErrorLVars as modified by DownEnv / UpEnv
Int ErrorLLevel; // record where on the stack ErrorLVars is relative to the top, i.e. ErrorLVars0
Int ErrorLLevel; // record where on the stack ErrorLVars is relative to the top, i.e. BaseShellContext

/* From objects.c */
Obj PrintObjThis;
Expand Down
4 changes: 0 additions & 4 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -2755,7 +2755,6 @@ ExecStatus ReadEvalCommand ( Obj context, UInt *dualSemicolon )
volatile UInt readTilde;
volatile UInt currLHSGVar;
volatile Obj errorLVars;
volatile Obj errorLVars0;
syJmp_buf readJmpError;
#ifdef HPCGAP
int lockSP;
Expand Down Expand Up @@ -2792,9 +2791,7 @@ ExecStatus ReadEvalCommand ( Obj context, UInt *dualSemicolon )
STATE(CurrLHSGVar) = 0;
RecreateStackNams(context);
errorLVars = STATE(ErrorLVars);
errorLVars0 = STATE(ErrorLVars0);
STATE(ErrorLVars) = context;
STATE(ErrorLVars0) = STATE(ErrorLVars);
#ifdef HPCGAP
lockSP = RegionLockSP();
#endif
Expand Down Expand Up @@ -2862,7 +2859,6 @@ ExecStatus ReadEvalCommand ( Obj context, UInt *dualSemicolon )
STATE(ReadTilde) = readTilde;
STATE(CurrLHSGVar) = currLHSGVar;
STATE(ErrorLVars) = errorLVars;
STATE(ErrorLVars0) = errorLVars0;

/* copy the result (if any) */
STATE(ReadEvalResult) = STATE(IntrResult);
Expand Down

0 comments on commit bff7efb

Please sign in to comment.