Skip to content

Commit

Permalink
kernel: use ExecStatus instead of UInt where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jan 9, 2022
1 parent 11ca464 commit bb7065c
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 203 deletions.
21 changes: 20 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ typedef struct TypInputFile TypInputFile;
typedef struct TypOutputFile TypOutputFile;


/****************************************************************************
**
*T ExecStatus . . . . type of status values returned by read, eval and exec
** subroutines, explaining why evaluation, or execution
** has terminated.
*/

typedef enum {
STATUS_END, // ran off the end of the code
STATUS_RETURN, // 'return' statement
STATUS_BREAK, // 'break' statement
STATUS_CONTINUE, // 'continue' statement
STATUS_QUIT, // 'quit' statement
STATUS_QQUIT, // 'QUIT' statement
STATUS_EOF, // end of file while parsing
STATUS_ERROR, // syntax error while parsing
} ExecStatus;


/****************************************************************************
**
*T EvalBoolFunc
Expand All @@ -254,7 +273,7 @@ typedef struct TypOutputFile TypOutputFile;
*/
typedef Obj (*EvalBoolFunc)(Expr);
typedef Obj (*EvalExprFunc)(Expr);
typedef UInt (*ExecStatFunc)(Stat);
typedef ExecStatus (*ExecStatFunc)(Stat);
typedef void (*PrintStatFunc)(Stat);
typedef void (*PrintExprFunc)(Expr);

Expand Down
52 changes: 18 additions & 34 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static ALWAYS_INLINE Obj EvalOrExecCall(Int ignoreResult, UInt nr, Stat call, St
** handled here
*/

static UInt ExecProccallOpts(Stat call)
static ExecStatus ExecProccallOpts(Stat call)
{
Expr opts = READ_STAT(call, 0);
Expr real_call = READ_STAT(call, 1);
Expand All @@ -203,75 +203,59 @@ static UInt ExecProccallOpts(Stat call)

EvalOrExecCall(1, narg, real_call, opts);

return 0;
return STATUS_END;
}


static UInt ExecProccall0args(Stat call)
static ExecStatus ExecProccall0args(Stat call)
{
EvalOrExecCall(1, 0, call, 0);

// return 0 (to indicate that no leave-statement was executed)
return 0;
return STATUS_END;
}

static UInt ExecProccall1args(Stat call)
static ExecStatus ExecProccall1args(Stat call)
{
EvalOrExecCall(1, 1, call, 0);

// return 0 (to indicate that no leave-statement was executed)
return 0;
return STATUS_END;
}

static UInt ExecProccall2args(Stat call)
static ExecStatus ExecProccall2args(Stat call)
{
EvalOrExecCall(1, 2, call, 0);

// return 0 (to indicate that no leave-statement was executed)
return 0;
return STATUS_END;
}

static UInt ExecProccall3args(Stat call)
static ExecStatus ExecProccall3args(Stat call)
{
EvalOrExecCall(1, 3, call, 0);

// return 0 (to indicate that no leave-statement was executed)
return 0;
return STATUS_END;
}

static UInt ExecProccall4args(Stat call)
static ExecStatus ExecProccall4args(Stat call)
{
EvalOrExecCall(1, 4, call, 0);

// return 0 (to indicate that no leave-statement was executed)
return 0;
return STATUS_END;
}

static UInt ExecProccall5args(Stat call)
static ExecStatus ExecProccall5args(Stat call)
{
EvalOrExecCall(1, 5, call, 0);

// return 0 (to indicate that no leave-statement was executed)
return 0;
return STATUS_END;
}

static UInt ExecProccall6args(Stat call)
static ExecStatus ExecProccall6args(Stat call)
{
EvalOrExecCall(1, 6, call, 0);

// return 0 (to indicate that no leave-statement was executed)
return 0;
return STATUS_END;
}

static UInt ExecProccallXargs(Stat call)
static ExecStatus ExecProccallXargs(Stat call)
{
// pass in 7 (instead of NARG_SIZE_CALL(SIZE_STAT(call)))
// to allow the compiler to perform better optimizations
// (as we know that the number of arguments is >= 7 here)
EvalOrExecCall(1, 7, call, 0);

// return 0 (to indicate that no leave-statement was executed)
return 0;
return STATUS_END;
}

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static Obj FuncSHELL(Obj self,
//
// return values of ReadEvalCommand
//
UInt status;
ExecStatus status;
Obj evalResult;

//
Expand Down
19 changes: 0 additions & 19 deletions src/gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,6 @@ extern UInt ViewObjGVar;
void ViewObjHandler(Obj obj);


/****************************************************************************
**
*T ExecStatus . . . . type of status values returned by read, eval and exec
** subroutines, explaining why evaluation, or execution
** has terminated.
*/

typedef enum {
STATUS_END, // ran off the end of the code
STATUS_RETURN, // 'return' statement
STATUS_BREAK, // 'break' statement
STATUS_CONTINUE, // 'continue' statement
STATUS_QUIT, // 'quit' statement
STATUS_QQUIT, // 'QUIT' statement
STATUS_EOF, // end of file while parsing
STATUS_ERROR, // syntax error while parsing
} ExecStatus;


/****************************************************************************
**
*S MAX_FUNC_EXPR_NESTING_BITS
Expand Down
2 changes: 1 addition & 1 deletion src/hookintrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void InstallPrintExprFunc(Int pos, PrintExprFunc f)
HashUnlock(&activeHooks);
}

static UInt ProfileExecStatPassthrough(Stat stat)
static ExecStatus ProfileExecStatPassthrough(Stat stat)
{
GAP_HOOK_LOOP(visitStat, stat);
return OriginalExecStatFuncsForHook[TNUM_STAT(stat)](stat);
Expand Down
12 changes: 6 additions & 6 deletions src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
static void INTERPRETER_PROFILE_HOOK(IntrState * intr, int ignoreLevel)
{
if (!intr->coding) {
InterpreterHook(GetInputFilenameID(GetCurrentInput()),
intr->startLine,
intr->returning || (intr->ignoring > ignoreLevel));
InterpreterHook(
GetInputFilenameID(GetCurrentInput()), intr->startLine,
intr->returning != STATUS_END || (intr->ignoring > ignoreLevel));
}
intr->startLine = 0;
}
Expand All @@ -75,7 +75,7 @@ static void INTERPRETER_PROFILE_HOOK(IntrState * intr, int ignoreLevel)

// Need to
#define SKIP_IF_RETURNING_NO_PROFILE_HOOK() \
if (intr->returning > 0) { \
if (intr->returning != STATUS_END) { \
return; \
}

Expand Down Expand Up @@ -245,7 +245,7 @@ void IntrBegin(IntrState * intr)
GAP_ASSERT(intr->coding == 0);

/* no return-statement was yet interpreted */
intr->returning = 0;
intr->returning = STATUS_END;
}

ExecStatus IntrEnd(IntrState * intr, BOOL error, Obj * result)
Expand Down Expand Up @@ -590,7 +590,7 @@ Int IntrIfEndBody(IntrState * intr, UInt nr)
INTERPRETER_PROFILE_HOOK(intr, 0);

/* ignore or code */
if (intr->returning > 0) {
if (intr->returning != STATUS_END) {
return 0;
}
if (intr->ignoring > 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -2506,10 +2506,10 @@ static void RecreateStackNams(ReaderState * rs, Obj context)
** will be set to 1 if the command was followed by a double semicolon, else
** it is set to 0. If 'dualSemicolon' is zero then it is ignored.
*/
UInt ReadEvalCommand(Obj context,
TypInputFile * input,
Obj * evalResult,
BOOL * dualSemicolon)
ExecStatus ReadEvalCommand(Obj context,
TypInputFile * input,
Obj * evalResult,
BOOL * dualSemicolon)
{
volatile ExecStatus status;
volatile Obj tilde;
Expand Down Expand Up @@ -2642,7 +2642,7 @@ UInt ReadEvalCommand(Obj context,
** It does not expect the first symbol of its input already read and reads
** to the end of the input (unless an error happens).
*/
UInt ReadEvalFile(TypInputFile * input, Obj * evalResult)
ExecStatus ReadEvalFile(TypInputFile * input, Obj * evalResult)
{
volatile ExecStatus status;
volatile Obj tilde;
Expand Down
10 changes: 5 additions & 5 deletions src/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
** will be set to 1 if the command was followed by a double semicolon, else
** it is set to 0. If 'dualSemicolon' is zero then it is ignored.
*/
UInt ReadEvalCommand(Obj context,
TypInputFile * input,
Obj * evalResult,
BOOL * dualSemicolon);
ExecStatus ReadEvalCommand(Obj context,
TypInputFile * input,
Obj * evalResult,
BOOL * dualSemicolon);


/****************************************************************************
Expand All @@ -50,7 +50,7 @@ UInt ReadEvalCommand(Obj context,
** It does not expect the first symbol of its input already read and reads
** to the end of the input (unless an error happens).
*/
UInt ReadEvalFile(TypInputFile * input, Obj * evalResult);
ExecStatus ReadEvalFile(TypInputFile * input, Obj * evalResult);


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

0 comments on commit bb7065c

Please sign in to comment.