Skip to content

Commit

Permalink
kernel: make Push/PopGlobalForLoopVariable static
Browse files Browse the repository at this point in the history
Since we now have the type of the index variable readily available in ReadFor,
we can move the calls to Push/PopGlobalForLoopVariable from the coder to the
reader, where they arguably always belonged.
  • Loading branch information
fingolfin committed Dec 29, 2019
1 parent f47b9a9 commit 31fecda
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
9 changes: 0 additions & 9 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,12 +1086,6 @@ void CodeForBegin ( void )

void CodeForIn ( void )
{
Expr var = PopExpr();
if (TNUM_EXPR(var) == EXPR_REF_GVAR)
{
PushGlobalForLoopVariable(READ_EXPR(var, 0));
}
PushExpr(var);
}

void CodeForBeginBody ( void )
Expand All @@ -1112,9 +1106,6 @@ void CodeForEndBody (
/* get the variable reference */
var = PopExpr();

if (TNUM_EXPR(var) == EXPR_REF_GVAR)
PopGlobalForLoopVariable();

/* select the type of the for-statement */
if ( TNUM_EXPR(list) == EXPR_RANGE && SIZE_EXPR(list) == 2*sizeof(Expr)
&& IS_REF_LVAR(var) ) {
Expand Down
8 changes: 6 additions & 2 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ static void ReadFuncExprAbbrevSingle(ScannerState * s, TypSymbolSet follow);

static void ReadAtom(ScannerState * s, TypSymbolSet follow, Char mode);

void PushGlobalForLoopVariable( UInt var)
static void PushGlobalForLoopVariable( UInt var)
{
struct ReaderState * rs = ReaderState();
if (rs->CurrentGlobalForLoopDepth < 100)
rs->CurrentGlobalForLoopVariables[rs->CurrentGlobalForLoopDepth] = var;
rs->CurrentGlobalForLoopDepth++;
}

void PopGlobalForLoopVariable( void )
static void PopGlobalForLoopVariable( void )
{
GAP_ASSERT(ReaderState()->CurrentGlobalForLoopDepth);
ReaderState()->CurrentGlobalForLoopDepth--;
Expand Down Expand Up @@ -2061,11 +2061,15 @@ static void ReadFor(ScannerState * s, TypSymbolSet follow)

/* 'do' <Statements> */
Match(s, S_DO, "do", STATBEGIN|S_OD|follow);
if (ref.type == R_GVAR)
PushGlobalForLoopVariable(ref.var);
ReaderState()->LoopNesting++;
TRY_IF_NO_ERROR { IntrForBeginBody(); }
nrs = ReadStats(s, S_OD|follow);
TRY_IF_NO_ERROR { IntrForEndBody( nrs ); }
ReaderState()->LoopNesting--;
if (ref.type == R_GVAR)
PopGlobalForLoopVariable();

/* 'od' */
Match(s, S_OD, "while parsing a 'for' loop: statement or 'od'", follow);
Expand Down
8 changes: 0 additions & 8 deletions src/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ void StartFakeFuncExpr(Int startLine);
void FinishAndCallFakeFuncExpr(void);


/****************************************************************************
**
*/
void PushGlobalForLoopVariable(UInt var);

void PopGlobalForLoopVariable(void);


/****************************************************************************
**
*F Call0ArgsInNewReader(Obj f) . . . . . . . . . . . . call a GAP function
Expand Down

0 comments on commit 31fecda

Please sign in to comment.