Skip to content

Commit

Permalink
Add profile hooks into interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Sep 4, 2018
1 parent f7fbe46 commit d06176a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/gapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ typedef struct GAPState {
UInt SymbolStartPos;
UInt SymbolStartLine;

// Used for recording the first line of the fragment of code currently
// begin interpreted, so the current line is outputted when profiling
UInt InterpreterStartLine;

const Char * Prompt;

Char * In;
Expand Down
13 changes: 12 additions & 1 deletion src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "funcs.h"
#include "gapstate.h"
#include "gvars.h"
#include "hookintrprtr.h"
#include "integer.h"
#include "io.h"
#include "lists.h"
Expand Down Expand Up @@ -82,8 +83,18 @@
*/
/* TL: UInt IntrCoding; */

#define INTERPRETER_PROFILE_HOOK() \
InterpreterHook(GetInputFilenameID(), STATE(InterpreterStartLine), \
STATE(IntrCoding) || STATE(IntrReturning) || \
STATE(IntrIgnoring)); \
STATE(InterpreterStartLine) = 0;

#define SKIP_IF_RETURNING() \
INTERPRETER_PROFILE_HOOK(); \
if (STATE(IntrReturning) > 0) { \
return; \
}

#define SKIP_IF_RETURNING() if ( STATE(IntrReturning) > 0 ) { return; }
#define SKIP_IF_IGNORING() if ( STATE(IntrIgnoring) > 0 ) { return; }


Expand Down
7 changes: 7 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
**
** 'number' is the number of the current line, is used in error messages.
**
** 'numberInterpreter' is the number of the line where the fragment of code
** currently being interpreted started, is used for profiling
**
** 'stream' is none zero if the input points to a stream.
**
** 'sline' contains the next line from the stream as GAP string.
Expand All @@ -73,6 +76,7 @@ typedef struct {
Char * ptr;
UInt symbol;
Int number;
Int numberInterpreter;
Obj stream;
UInt isstringstream;
Obj sline;
Expand Down Expand Up @@ -537,6 +541,7 @@ UInt OpenInputStream(Obj stream, UInt echo)
GAP_ASSERT(IS_CHAR_PUSHBACK_EMPTY());
IO()->Input->ptr = STATE(In);
IO()->Input->symbol = STATE(Symbol);
IO()->Input->numberInterpreter = STATE(InterpreterStartLine);
}

/* enter the file identifier and the file name */
Expand All @@ -561,6 +566,7 @@ UInt OpenInputStream(Obj stream, UInt echo)
STATE(In) = IO()->Input->line;
STATE(In)[0] = STATE(In)[1] = '\0';
STATE(Symbol) = S_ILLEGAL;
STATE(InterpreterStartLine) = 0;
IO()->Input->number = 1;

/* indicate success */
Expand Down Expand Up @@ -602,6 +608,7 @@ UInt CloseInput ( void )
IO()->Input = IO()->InputStack[sp - 1];
STATE(In) = IO()->Input->ptr;
STATE(Symbol) = IO()->Input->symbol;
STATE(InterpreterStartLine) = IO()->Input->numberInterpreter;

/* indicate success */
return 1;
Expand Down
4 changes: 4 additions & 0 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ void Match (
{
Char errmsg [256];

if (STATE(InterpreterStartLine) == 0) {
STATE(InterpreterStartLine) = STATE(SymbolStartLine);
}

// if 'STATE(Symbol)' is the expected symbol match it away
if ( symbol == STATE(Symbol) ) {
STATE(Symbol) = NextSymbol();
Expand Down

0 comments on commit d06176a

Please sign in to comment.