Skip to content

Commit

Permalink
WIP misc
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jun 12, 2018
1 parent be8995d commit ddea702
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 52 deletions.
35 changes: 13 additions & 22 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -973,42 +974,32 @@ void PrintFunccallOpts (
*F ExecBegin() . . . . . . . . . . . . . . . . . . . . . begin an execution
*F ExecEnd(<error>) . . . . . . . . . . . . . . . . . . . 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));
}

/****************************************************************************
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/hpc/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "plist.h"
#include "stats.h"
#include "stringobj.h"
#include "vars.h"

#include "hpc/guards.h"
#include "hpc/misc.h"
Expand Down Expand Up @@ -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);
Expand Down
27 changes: 6 additions & 21 deletions src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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
Expand Down Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -470,7 +459,6 @@ UInt ExecFor(Stat stat)
return ExecForHelper(stat, 1);
}


UInt ExecFor2(Stat stat)
{
return ExecForHelper(stat, 2);
Expand Down Expand Up @@ -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) ) {
Expand Down Expand Up @@ -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)
Expand All @@ -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 );

}

Expand Down Expand Up @@ -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)
Expand All @@ -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 );

Expand Down Expand Up @@ -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;'");
}

Expand Down
1 change: 1 addition & 0 deletions src/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tst/test-error/bad-array-double-1.g.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
<corrupted statement> called from
return "abc"[1, 1]; at *stdin*:3 called from
<function "f">( <arguments> )
called from read-eval loop at *stdin*:5
type 'quit;' to quit to outer loop
Expand Down
2 changes: 1 addition & 1 deletion tst/test-error/bad-array-int-0.g.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
<function "f">( <arguments> )
called from read-eval loop at *stdin*:7
type 'quit;' to quit to outer loop
Expand Down
2 changes: 1 addition & 1 deletion tst/test-error/bad-array-string.g.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
<function "f">( <arguments> )
called from read-eval loop at *stdin*:5
type 'quit;' to quit to outer loop
Expand Down
8 changes: 4 additions & 4 deletions tst/test-error/debug-var.g.out
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Syntax warning: Unbound global variable in *errin*:6
unbound_global;
^
Error, Variable: 'unbound_global' must have a value in
<corrupted statement> called from
Error( "breakpoint" ); at *stdin*:9 called from
g( 10 ) at *stdin*:12 called from
<function "f">( <arguments> )
called from read-eval loop at *errin*:6
Expand All @@ -47,7 +47,7 @@ brk> IsBound(y);
true
brk> unbound_higher;
Error, Variable: 'unbound_higher' must have an assigned value in
<corrupted statement> called from
Error( "breakpoint" ); at *stdin*:9 called from
g( 10 ) at *stdin*:12 called from
<function "f">( <arguments> )
called from read-eval loop at *errin*:12
Expand All @@ -63,7 +63,7 @@ brk> IsBound(z);
true
brk> unbound_local;
Error, Variable: 'unbound_local' must have an assigned value in
<corrupted statement> called from
Error( "breakpoint" ); at *stdin*:9 called from
g( 10 ) at *stdin*:12 called from
<function "f">( <arguments> )
called from read-eval loop at *errin*:17
Expand Down Expand Up @@ -109,7 +109,7 @@ brk_2> IsBound(y);
true
brk_2> unbound_higher;
Error, Variable: <debug-variable-64-4> must have a value in
<corrupted statement> called from
Error( "foobar" ); at *stdin*:20 called from
Error( "breakpoint" ); at *stdin*:9 called from
g( 10 ) at *stdin*:12 called from
<function "f">( <arguments> )
Expand Down
2 changes: 1 addition & 1 deletion tst/test-error/up-down-env.g.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ gap> f:=lvl -> 1/lvl + f(lvl-1);
function( lvl ) ... end
gap> f(7);
Error, Rational operations: <divisor> 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
Expand Down

0 comments on commit ddea702

Please sign in to comment.