Skip to content

Commit 803a31e

Browse files
committed
kernel: move ScannerState out of GAPState
This simplifies the code overall.
1 parent 3a32e52 commit 803a31e

5 files changed

Lines changed: 10 additions & 31 deletions

File tree

src/gapstate.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "system.h"
1919

20-
#include "scanner.h"
2120
#include "sysjmp.h"
2221

2322
#if defined(HPCGAP)
@@ -58,11 +57,6 @@ typedef struct GAPState {
5857
syJmp_buf ReadJmpError;
5958

6059
/* From scanner.c */
61-
// TODO: eventually, ScannerState should be removed from GAPState
62-
// (and then also #include "scanner.h" at the top), and instead code
63-
// using a caller should dynamically allocate a ScannerState on the stack.
64-
// But for now, we can't really do that.
65-
ScannerState Scanner;
6660
UInt NrError;
6761
UInt NrErrLine;
6862

src/io.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ typedef struct {
9191
// character
9292
Char * ptr;
9393

94-
//
95-
UInt symbol;
96-
9794
// the number of the line where the fragment of code currently being
9895
// interpreted started; used for profiling
9996
Int interpreterStartLine;
@@ -472,10 +469,6 @@ static UInt OpenDefaultOutput(void)
472469
** may also fail if you have too many files open at once. It is system
473470
** dependent how many are too many, but 16 files should work everywhere.
474471
**
475-
** Directely after the 'OpenInput' call the variable 'Symbol' has the value
476-
** 'S_ILLEGAL' to indicate that no symbol has yet been read from this file.
477-
** The first symbol is read by 'Read' in the first call to 'Match' call.
478-
**
479472
** You can open '*stdin*' to read from the standard input file, which is
480473
** usually the terminal, or '*errin*' to read from the standard error file,
481474
** which is the terminal even if '*stdin*' is redirected from a file.
@@ -515,7 +508,6 @@ UInt OpenInput (
515508
if (IO()->InputStackPointer > 0) {
516509
GAP_ASSERT(IS_CHAR_PUSHBACK_EMPTY());
517510
IO()->Input->ptr = STATE(In);
518-
IO()->Input->symbol = STATE(Scanner).Symbol;
519511
IO()->Input->interpreterStartLine = STATE(InterpreterStartLine);
520512
}
521513

@@ -534,10 +526,9 @@ UInt OpenInput (
534526
strlcpy(IO()->Input->name, filename, sizeof(IO()->Input->name));
535527
IO()->Input->gapnameid = 0;
536528

537-
/* start with an empty line and no symbol */
529+
// start with an empty line
538530
STATE(In) = IO()->Input->line;
539531
STATE(In)[0] = STATE(In)[1] = '\0';
540-
STATE(Scanner).Symbol = S_ILLEGAL;
541532
STATE(InterpreterStartLine) = 0;
542533
IO()->Input->number = 1;
543534

@@ -562,7 +553,6 @@ UInt OpenInputStream(Obj stream, UInt echo)
562553
if (IO()->InputStackPointer > 0) {
563554
GAP_ASSERT(IS_CHAR_PUSHBACK_EMPTY());
564555
IO()->Input->ptr = STATE(In);
565-
IO()->Input->symbol = STATE(Scanner).Symbol;
566556
IO()->Input->interpreterStartLine = STATE(InterpreterStartLine);
567557
}
568558

@@ -584,10 +574,9 @@ UInt OpenInputStream(Obj stream, UInt echo)
584574
strlcpy(IO()->Input->name, "stream", sizeof(IO()->Input->name));
585575
IO()->Input->gapnameid = 0;
586576

587-
/* start with an empty line and no symbol */
577+
// start with an empty line
588578
STATE(In) = IO()->Input->line;
589579
STATE(In)[0] = STATE(In)[1] = '\0';
590-
STATE(Scanner).Symbol = S_ILLEGAL;
591580
STATE(InterpreterStartLine) = 0;
592581
IO()->Input->number = 1;
593582

@@ -643,7 +632,6 @@ UInt CloseInput ( void )
643632
#endif
644633
IO()->Input = IO()->InputStack[sp - 1];
645634
STATE(In) = IO()->Input->ptr;
646-
STATE(Scanner).Symbol = IO()->Input->symbol;
647635
STATE(InterpreterStartLine) = IO()->Input->interpreterStartLine;
648636

649637
/* indicate success */
@@ -658,8 +646,6 @@ UInt CloseInput ( void )
658646
void FlushRestOfInputLine( void )
659647
{
660648
STATE(In)[0] = STATE(In)[1] = '\0';
661-
/* IO()->Input->number = 1; */
662-
STATE(Scanner).Symbol = S_ILLEGAL;
663649
}
664650

665651
/****************************************************************************

src/read.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,7 +2529,10 @@ ExecStatus ReadEvalCommand(Obj context, Obj *evalResult, UInt *dualSemicolon)
25292529
#endif
25302530

25312531
struct ReaderState * volatile rs = ReaderState();
2532-
ScannerState * volatile s = &STATE(Scanner);
2532+
2533+
ScannerState scanner;
2534+
ScannerState * volatile s = &scanner;
2535+
memset(s, 0, sizeof(ScannerState));
25332536

25342537
/* get the first symbol from the input */
25352538
Match(s, s->Symbol, "", 0UL);
@@ -2660,7 +2663,10 @@ UInt ReadEvalFile(Obj *evalResult)
26602663
#endif
26612664

26622665
struct ReaderState * volatile rs = ReaderState();
2663-
ScannerState * volatile s = &STATE(Scanner);
2666+
2667+
ScannerState scanner;
2668+
ScannerState * volatile s = &scanner;
2669+
memset(s, 0, sizeof(ScannerState));
26642670

26652671
/* get the first symbol from the input */
26662672
Match(s, s->Symbol, "", 0UL);

src/scanner.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,8 +1123,6 @@ static Int InitKernel (
11231123
StructInitInfo * module )
11241124
{
11251125
InitHdlrFuncsFromTable( GVarFuncs );
1126-
1127-
InitGlobalBag(&STATE(Scanner).ValueObj, "ValueObj");
11281126
return 0;
11291127
}
11301128

src/scanner.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ typedef UInt TypSymbolSet;
195195
*T ScannerState
196196
**
197197
** The struct 'ScannerState' encapsulates the state of the scanner.
198-
**
199-
** In the future, it is planned to allow use of multiple instances of the
200-
** scanner simultaneously within a single thread. However, this is not yet
201-
** ready, and currently only once instance of 'ScannerState' is used, which
202-
** is stored inside the global instance of struct 'GAPState'.
203198
*/
204199
typedef struct {
205200

0 commit comments

Comments
 (0)