From bff7efb0243968666a4234195a2943635bbd28a5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 17 Oct 2017 17:47:58 +0200 Subject: [PATCH] Fix DownEnv / UpEnv handling 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: 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 ( ) called from read-eval loop at line 12 of *stdin* you can replace via 'return ;' 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. --- src/gap.c | 2 +- src/gap.h | 3 --- src/gapstate.h | 3 +-- src/read.c | 4 ---- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/gap.c b/src/gap.c index 5908c7907ec..212914f13e0 100644 --- a/src/gap.c +++ b/src/gap.c @@ -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); } diff --git a/src/gap.h b/src/gap.h index 53851f5762d..b3ac7972da1 100644 --- a/src/gap.h +++ b/src/gap.h @@ -201,9 +201,6 @@ extern void ErrorReturnVoid ( Int arg2, const Char * msg2 ); -/* TL: extern Obj ErrorLVars; - TL: extern Obj ErrorLVars0; - */ /**************************************************************************** ** diff --git a/src/gapstate.h b/src/gapstate.h index e3b223a77da..9e726664bac 100644 --- a/src/gapstate.h +++ b/src/gapstate.h @@ -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; diff --git a/src/read.c b/src/read.c index 475ec717649..5a736094ef6 100644 --- a/src/read.c +++ b/src/read.c @@ -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; @@ -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 @@ -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);