From ddea702ca4d28d6d921eedc7619a8dbbdc142db2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 12 Jun 2018 11:19:51 +0200 Subject: [PATCH] WIP misc --- src/funcs.c | 35 +++++++++---------------- src/hpc/thread.c | 3 ++- src/stats.c | 27 +++++-------------- src/vars.h | 1 + tst/test-error/bad-array-double-1.g.out | 2 +- tst/test-error/bad-array-int-0.g.out | 2 +- tst/test-error/bad-array-string.g.out | 2 +- tst/test-error/debug-var.g.out | 8 +++--- tst/test-error/up-down-env.g.out | 2 +- 9 files changed, 30 insertions(+), 52 deletions(-) diff --git a/src/funcs.c b/src/funcs.c index 7c9a33604c..3f23f29a2c 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -98,6 +98,7 @@ UInt ExecProccallOpts( CALL_1ARGS(PushOptions, opts); EXEC_STAT( ADDR_STAT( call )[1]); +// TODO: restore the stat here, in case of an error in PopOptions CALL_0ARGS(PopOptions); @@ -973,42 +974,32 @@ void PrintFunccallOpts ( *F ExecBegin() . . . . . . . . . . . . . . . . . . . . . begin an execution *F ExecEnd() . . . . . . . . . . . . . . . . . . . end an execution */ -/* TL: Obj ExecState; */ -void ExecBegin ( Obj frame ) +void ExecBegin(Obj frame) { - Obj execState; /* old execution state */ + // remember the old execution state + PushPlist(FuncsState()->ExecState, STATE(CurrLVars)); - /* remember the old execution state */ - execState = NEW_PLIST(T_PLIST, 3); - SET_LEN_PLIST(execState, 3); - SET_ELM_PLIST(execState, 1, FuncsState()->ExecState); - SET_ELM_PLIST(execState, 2, STATE(CurrLVars)); - /* the 'CHANGED_BAG(STATE(CurrLVars))' is needed because it is delayed */ + // the 'CHANGED_BAG(STATE(CurrLVars))' is needed because it is delayed CHANGED_BAG( STATE(CurrLVars) ); - SET_ELM_PLIST(execState, 3, INTOBJ_INT((Int)STATE(CurrStat))); - FuncsState()->ExecState = execState; - /* set up new state */ + // set up new state SWITCH_TO_OLD_LVARS( frame ); - SET_BRK_CURR_STAT( 0 ); +// SET_BRK_CALL_TO(0); } -void ExecEnd ( - UInt error ) +void ExecEnd(UInt error) { - /* if everything went fine */ + // if everything went fine if ( ! error ) { /* the state must be primal again */ - assert( STATE(CurrStat) == 0 ); + //GAP_ASSERT( STATE(CurrStat) == 0 ); } - /* switch back to the old state */ - SET_BRK_CURR_STAT((Stat)INT_INTOBJ(ELM_PLIST(FuncsState()->ExecState, 3))); - SWITCH_TO_OLD_LVARS( ELM_PLIST(FuncsState()->ExecState, 2) ); - FuncsState()->ExecState = ELM_PLIST(FuncsState()->ExecState, 1); + // switch back to the old state + SWITCH_TO_OLD_LVARS(PopPlist(FuncsState()->ExecState)); } /**************************************************************************** @@ -1162,7 +1153,7 @@ static Int InitKernel ( static void InitModuleState(ModuleStateOffset offset) { - FuncsState()->ExecState = 0; + FuncsState()->ExecState = NEW_PLIST(T_PLIST_EMPTY, 128); FuncsState()->RecursionDepth = 0; } diff --git a/src/hpc/thread.c b/src/hpc/thread.c index 5771732190..64da923854 100644 --- a/src/hpc/thread.c +++ b/src/hpc/thread.c @@ -8,6 +8,7 @@ #include "plist.h" #include "stats.h" #include "stringobj.h" +#include "vars.h" #include "hpc/guards.h" #include "hpc/misc.h" @@ -848,7 +849,7 @@ static void InterruptCurrentThread(int locked, Stat stat) if (!locked) pthread_mutex_lock(thread->lock); STATE(CurrExecStatFuncs) = ExecStatFuncs; - SET_BRK_CURR_STAT(stat); + SET_BRK_CALL_TO(stat); state = GetThreadState(TLS(threadID)); if ((state & TSTATE_MASK) == TSTATE_INTERRUPTED) UpdateThreadState(TLS(threadID), state, TSTATE_RUNNING); diff --git a/src/stats.c b/src/stats.c index 1b97995939..430e84000d 100644 --- a/src/stats.c +++ b/src/stats.c @@ -45,6 +45,7 @@ inline UInt EXEC_STAT(Stat stat) { UInt tnum = TNUM_STAT(stat); + SET_BRK_CALL_TO(stat); return (*STATE(CurrExecStatFuncs)[ tnum ]) ( stat ); } @@ -71,17 +72,6 @@ inline UInt EXEC_STAT(Stat stat) UInt (* ExecStatFuncs[256]) ( Stat stat ); -/**************************************************************************** -** -*V CurrStat . . . . . . . . . . . . . . . . . currently executed statement -** -** 'CurrStat' is the statement that is currently being executed. The sole -** purpose of 'CurrStat' is to make it possible to point to the location in -** case an error is signalled. -*/ -/* TL: Stat CurrStat; */ - - /**************************************************************************** ** *V ReturnObjStat . . . . . . . . . . . . . . . . result of return-statement @@ -270,7 +260,7 @@ UInt ExecIfElif ( for ( i = 1; i <= nr; i++ ) { /* if the condition evaluates to 'true', execute the branch body */ - SET_BRK_CURR_STAT( stat ); + SET_BRK_CALL_TO( stat ); cond = ADDR_STAT(stat)[2*(i-1)]; if ( EVAL_BOOL_EXPR( cond ) != False ) { @@ -301,7 +291,7 @@ UInt ExecIfElifElse ( for ( i = 1; i <= nr; i++ ) { /* if the condition evaluates to 'true', execute the branch body */ - SET_BRK_CURR_STAT( stat ); + SET_BRK_CALL_TO( stat ); cond = ADDR_STAT(stat)[2*(i-1)]; if ( EVAL_BOOL_EXPR( cond ) != False ) { @@ -378,7 +368,6 @@ static ALWAYS_INLINE UInt ExecForHelper(Stat stat, UInt nr) } /* evaluate the list */ - SET_BRK_CURR_STAT( stat ); list = EVAL_EXPR( ADDR_STAT(stat)[1] ); /* get the body */ @@ -470,7 +459,6 @@ UInt ExecFor(Stat stat) return ExecForHelper(stat, 1); } - UInt ExecFor2(Stat stat) { return ExecForHelper(stat, 2); @@ -522,7 +510,6 @@ static ALWAYS_INLINE UInt ExecForRangeHelper(Stat stat, UInt nr) lvar = LVAR_REFLVAR( ADDR_STAT(stat)[0] ); /* evaluate the range */ - SET_BRK_CURR_STAT( stat ); VisitStatIfHooked(ADDR_STAT(stat)[1]); elm = EVAL_EXPR( ADDR_EXPR( ADDR_STAT(stat)[1] )[0] ); while ( ! IS_INTOBJ(elm) ) { @@ -693,7 +680,6 @@ static ALWAYS_INLINE UInt ExecWhileHelper(Stat stat, UInt nr) body3 = ADDR_STAT(stat)[3]; /* while the condition evaluates to 'true', execute the body */ - SET_BRK_CURR_STAT( stat ); while ( EVAL_BOOL_EXPR( cond ) != False ) { #if !defined(HAVE_SIGNAL) @@ -710,7 +696,7 @@ static ALWAYS_INLINE UInt ExecWhileHelper(Stat stat, UInt nr) if (nr >= 3) EXEC_STAT_IN_LOOP(body3); - SET_BRK_CURR_STAT( stat ); + SET_BRK_CALL_TO( stat ); } @@ -769,7 +755,6 @@ static ALWAYS_INLINE UInt ExecRepeatHelper(Stat stat, UInt nr) body3 = ADDR_STAT(stat)[3]; /* execute the body until the condition evaluates to 'true' */ - SET_BRK_CURR_STAT( stat ); do { #if !defined(HAVE_SIGNAL) @@ -786,7 +771,7 @@ static ALWAYS_INLINE UInt ExecRepeatHelper(Stat stat, UInt nr) if (nr >= 3) EXEC_STAT_IN_LOOP(body3); - SET_BRK_CURR_STAT( stat ); + SET_BRK_CALL_TO( stat ); } while ( EVAL_BOOL_EXPR( cond ) == False ); @@ -941,7 +926,7 @@ UInt ExecAssert2Args ( "you may 'return true;' or 'return false;'"); } if ( decision == False ) { - SET_BRK_CURR_STAT( stat ); + SET_BRK_CALL_TO( stat ); ErrorReturnVoid( "Assertion failure", 0L, 0L, "you may 'return;'"); } diff --git a/src/vars.h b/src/vars.h index aea2712f97..2c04c79dae 100644 --- a/src/vars.h +++ b/src/vars.h @@ -234,6 +234,7 @@ static inline Obj SwitchToNewLvars(Obj func, UInt narg, UInt nloc // create new lvars (may cause garbage collection) Obj new_lvars = NewLVarsBag( narg+nloc ); LVarsHeader * hdr = (LVarsHeader *)ADDR_OBJ(new_lvars); + hdr->stat = 0; hdr->func = func; hdr->parent = old; diff --git a/tst/test-error/bad-array-double-1.g.out b/tst/test-error/bad-array-double-1.g.out index 93e4d74651..b7dd3ebce6 100644 --- a/tst/test-error/bad-array-double-1.g.out +++ b/tst/test-error/bad-array-double-1.g.out @@ -5,7 +5,7 @@ function( ) ... end gap> f(); Error, no method found! For debugging hints type ?Recovery from NoMethodFound Error, no 1st choice method found for `[]' on 3 arguments at GAPROOT/lib/methsel2.g:250 called from - called from +return "abc"[1, 1]; at *stdin*:3 called from ( ) called from read-eval loop at *stdin*:5 type 'quit;' to quit to outer loop diff --git a/tst/test-error/bad-array-int-0.g.out b/tst/test-error/bad-array-int-0.g.out index c5ca3fbd32..dba95bc6cf 100644 --- a/tst/test-error/bad-array-int-0.g.out +++ b/tst/test-error/bad-array-int-0.g.out @@ -7,7 +7,7 @@ function( ) ... end gap> f(); Error, no method found! For debugging hints type ?Recovery from NoMethodFound Error, no 1st choice method found for `[]' on 2 arguments at GAPROOT/lib/methsel2.g:250 called from -l[0] at *stdin*:5 called from +return l[0]; at *stdin*:5 called from ( ) called from read-eval loop at *stdin*:7 type 'quit;' to quit to outer loop diff --git a/tst/test-error/bad-array-string.g.out b/tst/test-error/bad-array-string.g.out index 77bd95cebc..18c1377a63 100644 --- a/tst/test-error/bad-array-string.g.out +++ b/tst/test-error/bad-array-string.g.out @@ -5,7 +5,7 @@ function( ) ... end gap> f(); Error, no method found! For debugging hints type ?Recovery from NoMethodFound Error, no 1st choice method found for `[]' on 2 arguments at GAPROOT/lib/methsel2.g:250 called from -1["abc"] at *stdin*:3 called from +return 1["abc"]; at *stdin*:3 called from ( ) called from read-eval loop at *stdin*:5 type 'quit;' to quit to outer loop diff --git a/tst/test-error/debug-var.g.out b/tst/test-error/debug-var.g.out index 2f17b287e2..a522f22688 100644 --- a/tst/test-error/debug-var.g.out +++ b/tst/test-error/debug-var.g.out @@ -33,7 +33,7 @@ Syntax warning: Unbound global variable in *errin*:6 unbound_global; ^ Error, Variable: 'unbound_global' must have a value in - called from + Error( "breakpoint" ); at *stdin*:9 called from g( 10 ) at *stdin*:12 called from ( ) called from read-eval loop at *errin*:6 @@ -47,7 +47,7 @@ brk> IsBound(y); true brk> unbound_higher; Error, Variable: 'unbound_higher' must have an assigned value in - called from + Error( "breakpoint" ); at *stdin*:9 called from g( 10 ) at *stdin*:12 called from ( ) called from read-eval loop at *errin*:12 @@ -63,7 +63,7 @@ brk> IsBound(z); true brk> unbound_local; Error, Variable: 'unbound_local' must have an assigned value in - called from + Error( "breakpoint" ); at *stdin*:9 called from g( 10 ) at *stdin*:12 called from ( ) called from read-eval loop at *errin*:17 @@ -109,7 +109,7 @@ brk_2> IsBound(y); true brk_2> unbound_higher; Error, Variable: must have a value in - called from + Error( "foobar" ); at *stdin*:20 called from Error( "breakpoint" ); at *stdin*:9 called from g( 10 ) at *stdin*:12 called from ( ) diff --git a/tst/test-error/up-down-env.g.out b/tst/test-error/up-down-env.g.out index 60cf192f2d..36586e931c 100644 --- a/tst/test-error/up-down-env.g.out +++ b/tst/test-error/up-down-env.g.out @@ -2,7 +2,7 @@ gap> f:=lvl -> 1/lvl + f(lvl-1); function( lvl ) ... end gap> f(7); Error, Rational operations: must not be zero in - return 1 / lvl + f( (lvl - 1) ); at *stdin*:2 called from + 1 / lvl at *stdin*:2 called from f( lvl - 1 ) at *stdin*:2 called from f( lvl - 1 ) at *stdin*:2 called from f( lvl - 1 ) at *stdin*:2 called from