Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out state #579

Merged
merged 34 commits into from
Mar 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e1c75eb
Whitespace cleanup in blister.c
markuspf Feb 3, 2016
59754bd
Introduce a struct that contains all of the interpreter's state
markuspf Feb 3, 2016
530b7d4
Use the newly introduced global state.
markuspf Feb 3, 2016
53513ff
Clean out global variables in code.{c,h}
markuspf Feb 3, 2016
4856a23
Remove global variables from cyclotom.c
markuspf Feb 3, 2016
2aa084e
Remove global variables from gap.c
markuspf Feb 4, 2016
8b3a1bf
Remove global variables from gvars.c
markuspf Feb 4, 2016
1761c43
Remove global variables from gap.h
markuspf Feb 4, 2016
a1a3e8c
Remove global variables from interprtr.{c,h}
markuspf Feb 4, 2016
5e93b8d
Remove global variables from objects.{c,h}
markuspf Feb 4, 2016
b1e8931
Remove global variables from objscoll.{c,h}
markuspf Feb 4, 2016
24aa0aa
Remove global variables from opers.c
markuspf Feb 4, 2016
a8d0a1a
Remove global variables from read.{c,h}
markuspf Feb 4, 2016
c353029
Remove global variables from scanner.{c,h}
markuspf Feb 4, 2016
64b85a4
Remove global variables from stats.{c,h}
markuspf Feb 4, 2016
01244e7
Remove variables from vars.{c,h}
markuspf Feb 4, 2016
c03895d
Fix fallout of variable removal
markuspf Feb 4, 2016
13260b7
Fix some fallout from refactor, install initialisation code
markuspf Feb 4, 2016
04311ce
Readd some InitGlobalBag and add missed-out TLS
markuspf Feb 4, 2016
affa940
Add back more InitGlobalBag() calls
markuspf Feb 4, 2016
4a1c966
On-demand creation of PrintObj stack
markuspf Feb 4, 2016
3ab9b1f
InitGlobalBag(TLS(CurrNamespace));
markuspf Feb 4, 2016
d805127
Input stream fixes
markuspf Feb 4, 2016
7465104
Readd collectors initialisation
markuspf Feb 4, 2016
3df7132
Remove calls to malloc
markuspf Mar 1, 2016
15f6f0e
Rename InterpreterState to GlobalState
markuspf Mar 1, 2016
840de8f
Initialise global state
markuspf Mar 1, 2016
76cd5a6
Add some initialisation code
markuspf Mar 1, 2016
0f90080
Fix call to InitPrintObjStack
markuspf Mar 1, 2016
d6dae60
Remove some HPC-GAP specific code
markuspf Mar 2, 2016
813c468
Fix typo
markuspf Mar 2, 2016
e0e771a
Minor cleanup
markuspf Mar 2, 2016
0046584
Minor cleanup
markuspf Mar 2, 2016
5ec6759
Remove another global variable
markuspf Mar 2, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cnf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOURCE= \
funcs \
gap \
gasman \
globalstate \
gmpints \
gvars \
intfuncs \
Expand Down
920 changes: 479 additions & 441 deletions cnf/Makegap.in

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/blister.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@

#include "saveload.h" /* saving and loading */

#include "code.h" /* coder */
#include "hpc/thread.h" /* threads */
#include "hpc/tls.h" /* thread-local storage */
#include "code.h" /* coder */
#include "hpc/thread.h" /* threads */
#include "hpc/tls.h" /* thread-local storage */


/****************************************************************************
Expand Down
62 changes: 40 additions & 22 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
**
** 'PtrBody' is a pointer to the current body.
*/
Stat * PtrBody;
/* TL: Stat * PtrBody; */

/****************************************************************************
**
Expand All @@ -80,16 +80,14 @@ Obj FilenameCache;
** coding.
*/
#define MAX_FUNC_EXPR_NESTING 1024
/* TL: Stat OffsBody; */

/* TL: Stat OffsBodyStack[1024]; */
/* TL: UInt OffsBodyCount = 0; */

Stat OffsBody;

Stat OffsBodyStack[MAX_FUNC_EXPR_NESTING];
UInt OffsBodyCount = 0;

UInt LoopNesting = 0;
UInt LoopStack[MAX_FUNC_EXPR_NESTING];
UInt LoopStackCount = 0;
/* TL: UInt LoopNesting = 0; */
/* TL: UInt LoopStack[MAX_FUNC_EXPR_NESTING]; */
/* TL: UInt LoopStackCount = 0; */

static inline void PushOffsBody( void ) {
assert(TLS(OffsBodyCount) <= MAX_FUNC_EXPR_NESTING-1);
Expand All @@ -101,6 +99,14 @@ static inline void PopOffsBody( void ) {
TLS(OffsBody) = TLS(OffsBodyStack)[--TLS(OffsBodyCount)];
}

static void SetupOffsBodyStackAndLoopStack() {
// Careful: Malloc without free
/* Since this mallocs we use a global variable at the moment
TLS(OffsBodyStack) = malloc(MAX_FUNC_EXPR_NESTING*sizeof(Stat));
TLS(LoopStack) = malloc(MAX_FUNC_EXPR_NESTING*sizeof(UInt));
*/
}

static inline void PushLoopNesting( void ) {
assert(TLS(LoopStackCount) <= MAX_FUNC_EXPR_NESTING-1);
TLS(LoopStack)[TLS(LoopStackCount)++] = TLS(LoopNesting);
Expand Down Expand Up @@ -234,7 +240,7 @@ Expr NewExpr (
** 'CodeResult' is the result of the coding, i.e., the function that was
** coded.
*/
Obj CodeResult;
/* TL: Obj CodeResult; */


/****************************************************************************
Expand All @@ -255,9 +261,9 @@ Obj CodeResult;
** 'PopStat' returns the top statement from the statements stack and pops
** it. It is an error if the stack is empty.
*/
Bag StackStat;
/* TL: Bag StackStat; */

Int CountStat;
/* TL: Int CountStat; */

void PushStat (
Stat stat )
Expand Down Expand Up @@ -349,9 +355,9 @@ Stat PopSeqStat (
** 'PopExpr' returns the top expressions from the expressions stack and pops
** it. It is an error if the stack is empty.
*/
Bag StackExpr;
/* TL: Bag StackExpr; */

Int CountExpr;
/* TL: Int CountExpr; */

void PushExpr (
Expr expr )
Expand Down Expand Up @@ -531,7 +537,7 @@ void CodeFuncCallOptionsEnd ( UInt nr )
**
** ...only function expressions inbetween...
*/
Bag CodeLVars;
/* TL: Bag CodeLVars; */

void CodeBegin ( void )
{
Expand Down Expand Up @@ -744,7 +750,7 @@ void CodeFuncExprEnd (

/* get the function expression */
fexp = CURR_FUNC;
assert(!LoopNesting);
assert(!TLS(LoopNesting));

/* get the body of the function */
/* push an addition return-void-statement if neccessary */
Expand Down Expand Up @@ -794,6 +800,7 @@ void CodeFuncExprEnd (
PopLoopNesting();

/* restore the remembered offset */
TLS(OffsBody) = BRK_CALL_TO();
PopOffsBody();

/* if this was inside another function definition, make the expression */
Expand Down Expand Up @@ -3380,6 +3387,19 @@ void LoadBody ( Obj body )
*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *
*/

void InitCoderState(GlobalState *state)
{
state->OffsBodyCount = 0;
state->LoopNesting = 0;
state->LoopStackCount = 0;
state->StackStat = NewBag( T_BODY, 64*sizeof(Stat) );
state->StackExpr = NewBag( T_BODY, 64*sizeof(Expr) );
}

void DestroyCoderState(GlobalState *state)
{
}

/****************************************************************************
**
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
Expand All @@ -3398,8 +3418,8 @@ static Int InitKernel (
MakeBagTypePublic(T_BODY);

/* make the result variable known to Gasman */
InitGlobalBag( &CodeResult, "CodeResult" );
InitGlobalBag( &TLS(CodeResult), "CodeResult" );

InitGlobalBag( &FilenameCache, "FilenameCache" );

/* allocate the statements and expressions stacks */
Expand All @@ -3409,6 +3429,8 @@ static Int InitKernel (
/* some functions and globals needed for float conversion */
InitCopyGVar( "EAGER_FLOAT_LITERAL_CACHE", &EAGER_FLOAT_LITERAL_CACHE);
InitFopyGVar( "CONVERT_FLOAT_LITERAL_EAGER", &CONVERT_FLOAT_LITERAL_EAGER);
// InstallTLSHandler(SetupOffsBodyStackAndLoopStack, NULL);
SetupOffsBodyStackAndLoopStack();

/* return success */
return 0;
Expand Down Expand Up @@ -3507,9 +3529,5 @@ StructInitInfo * InitInfoCode ( void )

/****************************************************************************
**

*E code.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here
*/



2 changes: 1 addition & 1 deletion src/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
**
** 'PtrBody' is a pointer to the current body.
*/
extern Stat * PtrBody;
/* TL: extern Stat * PtrBody; */


/****************************************************************************
Expand Down
1 change: 1 addition & 0 deletions src/compiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extern "C" {


#include "intrprtr.h" /* interpreter */
#include "globalstate.h" /* */

#include "compiler.h" /* compiler */

Expand Down
19 changes: 10 additions & 9 deletions src/cyclotom.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,16 @@
** It is created in 'InitCyc' with room for up to 1000 coefficients and is
** resized when need arises.
*/
Obj ResultCyc;
/* TL: Obj ResultCyc; */

void GrowResultCyc(UInt size) {
Obj *res;
UInt i;
if ( LEN_PLIST(TLS(ResultCyc)) < size ) {
if (TLS(ResultCyc) == 0) {
TLS(ResultCyc) = NEW_PLIST( T_PLIST, size );
res = &(ELM_PLIST( TLS(ResultCyc), 1 ));
for ( i = 0; i < size; i++ ) { res[i] = INTOBJ_INT(0); }
} else if ( LEN_PLIST(TLS(ResultCyc)) < size ) {
GROW_PLIST( TLS(ResultCyc), size );
SET_LEN_PLIST( TLS(ResultCyc), size );
res = &(ELM_PLIST( TLS(ResultCyc), 1 ));
Expand All @@ -175,8 +179,8 @@ void GrowResultCyc(UInt size) {
** is called to compute $e_n^i$ and can then do this easier by just putting
** 1 at the <i>th place in 'ResultCyc' and then calling 'Cyclotomic'.
*/
Obj LastECyc;
UInt LastNCyc;
/* TL: Obj LastECyc; */
/* TL: UInt TLS(LastNCyc); */


/****************************************************************************
Expand Down Expand Up @@ -2150,14 +2154,11 @@ static Int InitKernel (

/* install the marking function */
InfoBags[ T_CYC ].name = "cyclotomic";
InitMarkFuncBags( T_CYC, MarkCycSubBags );

/* create the result buffer */
InitGlobalBag( &ResultCyc , "src/cyclotom.c:ResultCyc" );
InitGlobalBag( &TLS(ResultCyc) , "src/cyclotom.c:ResultCyc" );

/* tell Gasman about the place were we remember the primitive root */
InitGlobalBag( &LastECyc, "src/cyclotom.c:LastECyc" );

InitGlobalBag( &TLS(LastECyc), "src/cyclotom.c:LastECyc" );
/* install the type function */
ImportGVarFromLibrary( "TYPE_CYC", &TYPE_CYC );
TypeObjFuncs[ T_CYC ] = TypeCyc;
Expand Down
9 changes: 9 additions & 0 deletions src/exprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,15 @@ static Int InitLibrary (
return 0;
}

void InitExprState(GlobalState *state)
{
state->CurrEvalExprFuncs = EvalExprFuncs;
}

void DestroyExprState(GlobalState *state)
{
}

/****************************************************************************
**
*F InitInfoExprs() . . . . . . . . . . . . . . . . . table of init functions
Expand Down
6 changes: 3 additions & 3 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ Obj EvalFunccallXargs (
**
*/

Int RecursionDepth;
/* TL: Int RecursionDepth; */
static UInt RecursionTrapInterval;

static void RecursionDepthTrap( void )
Expand Down Expand Up @@ -1394,7 +1394,7 @@ void PrintFunccallOpts (
*F ExecBegin() . . . . . . . . . . . . . . . . . . . . . begin an execution
*F ExecEnd(<error>) . . . . . . . . . . . . . . . . . . . end an execution
*/
Obj ExecState;
/* TL: Obj ExecState; */

void ExecBegin ( Obj frame )
{
Expand Down Expand Up @@ -1506,7 +1506,7 @@ static Int InitKernel (
InitCopyGVar("STEVES_TRACING", &STEVES_TRACING);

/* make the global variable known to Gasman */
InitGlobalBag( &ExecState, "src/funcs.c:ExecState" );
InitGlobalBag( &TLS(ExecState), "src/funcs.c:ExecState" );

/* Register the handler for our exported function */
InitHdlrFuncsFromTable( GVarFuncs );
Expand Down
3 changes: 1 addition & 2 deletions src/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ extern void ExecEnd (
UInt error );


extern Int RecursionDepth;

/* TL: extern Int RecursionDepth; */
/****************************************************************************
**

Expand Down
28 changes: 22 additions & 6 deletions src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
#include "sysfiles.h" /* file input/output */
#include "weakptr.h" /* weak pointers */
#include "profile.h" /* profiling */

#include "globalstate.h" /* Global State */

#ifdef GAPMPI
#include "hpc/gapmpi.h" /* ParGAP/MPI */
#endif
Expand Down Expand Up @@ -746,6 +749,8 @@ int main (
InstallBacktraceHandlers();
#endif

InitMainGlobalState();

#ifdef HAVE_REALPATH
if (argc >= 3 && !strcmp(argv[1],"--createstartupscript")) {
return DoCreateStartupScript(argc,argv,0);
Expand Down Expand Up @@ -1145,7 +1150,7 @@ Obj ErrorLVars0;
Obj ErrorLVars;
Int ErrorLLevel;

extern Obj BottomLVars;
// extern Obj BottomLVars;


void DownEnvInner( Int depth )
Expand Down Expand Up @@ -1266,7 +1271,7 @@ Obj FuncPrintExecutingStatement(Obj self, Obj context)
*/

/* syJmp_buf CatchBuffer; */
Obj ThrownObject = 0;
/* TL: Obj ThrownObject = 0; */

Obj FuncCALL_WITH_CATCH( Obj self, Obj func, Obj args )
{
Expand Down Expand Up @@ -1320,8 +1325,8 @@ Obj FuncJUMP_TO_CATCH( Obj self, Obj payload)
}


UInt UserHasQuit;
UInt UserHasQUIT;
/* TL: UInt UserHasQuit; */
/* TL: UInt UserHasQUIT; */
UInt SystemErrorCode;

Obj FuncSetUserHasQuit( Obj Self, Obj value)
Expand Down Expand Up @@ -3049,7 +3054,8 @@ static Int InitKernel (
StructInitInfo * module )
{
/* init the completion function */
InitGlobalBag( &ThrownObject, "src/gap.c:ThrownObject" );
/* InitGlobalBag( &ThrownObject, "src/gap.c:ThrownObject" ); */
InitGlobalBag( &TLS(ThrownObject), "src/gap.c:ThrownObject" );

/* list of exit functions */
InitGlobalBag( &WindowCmdString, "src/gap.c:WindowCmdString" );
Expand Down Expand Up @@ -3334,7 +3340,6 @@ void InitializeGap (
UInt i;
Int ret;


/* initialize the basic system and gasman */
#ifdef GAPMPI
/* ParGAP/MPI needs to call MPI_Init() first to remove command line args */
Expand All @@ -3349,6 +3354,15 @@ void InitializeGap (
SyCacheSize, 0, SyAbortBags );
InitMsgsFuncBags( SyMsgsBags );

TLS(StackNams) = NEW_PLIST( T_PLIST, 16 );
TLS(CountNams) = 0;
TLS(ReadTop) = 0;
TLS(ReadTilde) = 0;
TLS(CurrLHSGVar) = 0;
TLS(IntrCoding) = 0;
TLS(IntrIgnoring) = 0;
TLS(NrError) = 0;
TLS(ThrownObject) = 0;

/* get info structures for the build in modules */
NrModules = 0;
Expand Down Expand Up @@ -3383,6 +3397,8 @@ void InitializeGap (
}
}

InitGlobalState(MainGlobalState);

InitGlobalBag(&POST_RESTORE, "gap.c: POST_RESTORE");
InitFopyGVar( "POST_RESTORE", &POST_RESTORE);

Expand Down
4 changes: 2 additions & 2 deletions src/gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ typedef UInt ExecStatus;



extern UInt UserHasQuit;
extern UInt UserHasQUIT;
// TL: extern UInt UserHasQuit;
// TL: extern UInt UserHasQUIT;
extern UInt SystemErrorCode;

#if 0
Expand Down
Loading