Skip to content

Commit

Permalink
kernel: remove input stream stack
Browse files Browse the repository at this point in the history
Instead of pre-allocating a fixed number of TypInputFile instances on each
thread, we allocate the required storage dynamically on the stack. This
arguably makes it easier to reason about the global state of GAP.

It also enables future simplifications and improvements, e.g. further
decoupling the input file code from the line buffering and potential
optimizations resulting from that.
  • Loading branch information
fingolfin committed Oct 12, 2020
1 parent c955ca0 commit ae0c5c1
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 206 deletions.
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ typedef const struct init_info StructInitInfo;
*T TypInputFile . . . . . . . . . . structure of an open input file, local
**
** This is a forward declaration so that TypInputFile can be used in header
** files. The actual declaration is in io.c and is private.
** files. The actual declaration is in io.h.
*/
typedef struct TypInputFile TypInputFile;

Expand Down
18 changes: 9 additions & 9 deletions src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,13 @@ static Obj Shell(Obj context,
if (!OpenOutput(outFile, FALSE))
ErrorQuit("SHELL: can't open outfile %s",(Int)outFile,0);

if(!OpenInput(inFile))
TypInputFile input = { 0 };
if (!OpenInput(&input, inFile))
{
CloseOutput();
ErrorQuit("SHELL: can't open infile %s",(Int)inFile,0);
}

TypInputFile * input = GetCurrentInput();

oldPrintObjState = SetPrintObjState(0);

while ( 1 ) {
Expand Down Expand Up @@ -255,7 +254,7 @@ static Obj Shell(Obj context,
STATE(ErrorLVars) = errorLVars;

/* now read and evaluate and view one command */
status = ReadEvalCommand(errorLVars, input, &evalResult, &dualSemicolon);
status = ReadEvalCommand(errorLVars, &input, &evalResult, &dualSemicolon);
if (STATE(UserHasQUIT))
break;

Expand Down Expand Up @@ -310,14 +309,14 @@ static Obj Shell(Obj context,

if (STATE(UserHasQuit))
{
FlushRestOfInputLine(input);
FlushRestOfInputLine(&input);
STATE(UserHasQuit) = 0; /* quit has done its job if we are here */
}

}

SetPrintObjState(oldPrintObjState);
CloseInput();
CloseInput(&input);
CloseOutput();
STATE(ErrorLLevel) = oldErrorLLevel;
SetRecursionDepth(oldRecursionDepth);
Expand Down Expand Up @@ -402,11 +401,12 @@ int realmain( int argc, char * argv[] )
read of init.g somehow*/
/* maybe compile in which case init.g got skipped */
if ( SyCompilePlease ) {
if ( ! OpenInput(SyCompileInput) ) {
TypInputFile input = { 0 };
if ( ! OpenInput(&input, SyCompileInput) ) {
return 1;
}
func = READ_AS_FUNC();
if (!CloseInput()) {
func = READ_AS_FUNC(&input);
if (!CloseInput(&input)) {
return 2;
}
crc = SyGAPCRC(SyCompileInput);
Expand Down
Loading

0 comments on commit ae0c5c1

Please sign in to comment.