Skip to content

Commit

Permalink
kernel: add SetPrintObjIndex helper
Browse files Browse the repository at this point in the history
This then allows us to move PrintObjIndex from the global GAPState struct to
the ObjectsModuleState struct.
  • Loading branch information
fingolfin committed Apr 24, 2019
1 parent 0cb3443 commit 9886081
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/gapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ typedef struct GAPState {
// that use GAP as a library to handle errors

/* From objects.c */
Int PrintObjIndex;
Int PrintObjDepth;

/* From info.c */
Expand Down
2 changes: 1 addition & 1 deletion src/lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ static void PrintListDefault(Obj list)
if ( elm != 0 ) {
if (1 < i)
Pr("%<,%< %2>", 0L, 0L);
STATE(PrintObjIndex) = i;
SetPrintObjIndex(i);
PrintObj( elm );
}
else {
Expand Down
25 changes: 15 additions & 10 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static ModuleStateOffset ObjectsStateOffset = -1;

typedef struct {
Obj PrintObjThis;
Int PrintObjIndex;
#if defined(HPCGAP)
Obj PrintObjThissObj;
Obj * PrintObjThiss;
Expand Down Expand Up @@ -920,14 +921,14 @@ void PrintObj (

if ( !fromview && 0 < STATE(PrintObjDepth) ) {
os->PrintObjThiss[STATE(PrintObjDepth)-1] = os->PrintObjThis;
os->PrintObjIndices[STATE(PrintObjDepth)-1] = STATE(PrintObjIndex);
os->PrintObjIndices[STATE(PrintObjDepth)-1] = os->PrintObjIndex;
}

/* handle the <obj> */
if (!fromview) {
STATE(PrintObjDepth) += 1;
os->PrintObjThis = obj;
STATE(PrintObjIndex) = 0;
os->PrintObjIndex = 0;
}

/* dispatch to the appropriate printing function */
Expand Down Expand Up @@ -958,7 +959,7 @@ void PrintObj (
/* if <obj> is a subobject, then restore and unmark the superobject*/
if ( 0 < STATE(PrintObjDepth) ) {
os->PrintObjThis = os->PrintObjThiss[STATE(PrintObjDepth)-1];
STATE(PrintObjIndex) = os->PrintObjIndices[STATE(PrintObjDepth)-1];
os->PrintObjIndex = os->PrintObjIndices[STATE(PrintObjDepth)-1];
}
}
LastPV = lastPV;
Expand Down Expand Up @@ -1002,11 +1003,15 @@ static Obj PrintObjHandler(Obj self, Obj obj)
}


static Obj FuncSET_PRINT_OBJ_INDEX(Obj self, Obj ind)
void SetPrintObjIndex(Int index)
{
if (IS_INTOBJ(ind))
STATE(PrintObjIndex) = INT_INTOBJ(ind);
return 0;
MODULE_STATE(Objects).PrintObjIndex = index;
}

static Obj FuncSET_PRINT_OBJ_INDEX(Obj self, Obj index)
{
SetPrintObjIndex(GetSmallInt("SET_PRINT_OBJ_INDEX", index));
return 0;
}


Expand Down Expand Up @@ -1051,13 +1056,13 @@ void ViewObj (

if ( 0 < STATE(PrintObjDepth) ) {
os->PrintObjThiss[STATE(PrintObjDepth)-1] = os->PrintObjThis;
os->PrintObjIndices[STATE(PrintObjDepth)-1] = STATE(PrintObjIndex);
os->PrintObjIndices[STATE(PrintObjDepth)-1] = os->PrintObjIndex;
}

/* handle the <obj> */
STATE(PrintObjDepth) += 1;
os->PrintObjThis = obj;
STATE(PrintObjIndex) = 0;
os->PrintObjIndex = 0;

/* dispatch to the appropriate viewing function */

Expand Down Expand Up @@ -1086,7 +1091,7 @@ void ViewObj (
/* if <obj> is a subobject, then restore and unmark the superobject */
if ( 0 < STATE(PrintObjDepth) ) {
os->PrintObjThis = os->PrintObjThiss[STATE(PrintObjDepth)-1];
STATE(PrintObjIndex) = os->PrintObjIndices[STATE(PrintObjDepth)-1];
os->PrintObjIndex = os->PrintObjIndices[STATE(PrintObjDepth)-1];
}

LastPV = lastPV;
Expand Down
2 changes: 2 additions & 0 deletions src/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ void PrintObj(Obj obj);

extern Obj PrintObjOper;

void SetPrintObjIndex(Int index);


/****************************************************************************
**
Expand Down

0 comments on commit 9886081

Please sign in to comment.