summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-01-27 09:21:43 -0500
committerAdrian Thurston <thurston@complang.org>2013-01-27 09:21:43 -0500
commit31789197f8e9dc3829790e3ddc9ce36087634172 (patch)
tree9d2e6d97d70026bcdc842a11c2ce1ce7849967ee
parent48712d213c4120a22e58ad6bba0e81ae8edba1e0 (diff)
downloadcolm-31789197f8e9dc3829790e3ddc9ce36087634172.tar.gz
copy data into fsm run just ahead of the consume calls
This is the first changes for scanning data in input streams and eliminating the holding of data in FsmRun.
-rw-r--r--colm/pdarun.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/colm/pdarun.c b/colm/pdarun.c
index 1a14c43c..5bd0553a 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -129,8 +129,6 @@ void decrementSteps( PdaRun *pdaRun )
debug( REALM_PARSE, "steps down to %ld\n", pdaRun->steps );
}
-/* Load up a token, starting from tokstart if it is set. If not set then
- * start it at data. */
Head *streamPull( Program *prg, FsmRun *fsmRun, StreamImpl *is, long length )
{
/* We should not be in the midst of getting a token. */
@@ -140,8 +138,8 @@ Head *streamPull( Program *prg, FsmRun *fsmRun, StreamImpl *is, long length )
runBuf->next = fsmRun->runBuf;
fsmRun->runBuf = runBuf;
- int len = 0;
- is->funcs->getData( fsmRun, is, 0, runBuf->data, length, &len );
+ int lenCopied = 0;
+ is->funcs->getData( fsmRun, is, 0, runBuf->data, length, &lenCopied );
is->funcs->consumeData( is, length );
fsmRun->p = fsmRun->pe = runBuf->data + length;
@@ -250,7 +248,6 @@ static void sendBackIgnore( Program *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsm
debug( REALM_PARSE, "trigger parse stop, steps = target = %d\n", pdaRun->targetSteps );
pdaRun->stop = true;
}
-
}
void attachStream( FsmRun *fsmRun, StreamImpl *is )
@@ -786,7 +783,17 @@ void sendIgnore( Program *prg, Tree **sp, StreamImpl *is, FsmRun *fsmRun, PdaRun
Head *peekMatch( Program *prg, FsmRun *fsmRun, StreamImpl *is )
{
long length = fsmRun->p - fsmRun->tokstart;
- Head *head = stringAllocPointer( prg, fsmRun->tokstart, length );
+
+ RunBuf *runBuf = newRunBuf();
+ runBuf->next = fsmRun->runBuf;
+ fsmRun->runBuf = runBuf;
+
+ int lenCopied = 0;
+ is->funcs->getData( fsmRun, is, 0, runBuf->data, length, &lenCopied );
+ fsmRun->p = fsmRun->pe = runBuf->data + length;
+
+ Head *head = stringAllocPointer( prg, runBuf->data, length );
+
head->location = locationAllocate( prg );
head->location->line = is->line;
head->location->column = is->column;
@@ -801,7 +808,18 @@ Head *peekMatch( Program *prg, FsmRun *fsmRun, StreamImpl *is )
Head *extractMatch( Program *prg, FsmRun *fsmRun, StreamImpl *is )
{
long length = fsmRun->p - fsmRun->tokstart;
- Head *head = stringAllocPointer( prg, fsmRun->tokstart, length );
+
+ RunBuf *runBuf = newRunBuf();
+ runBuf->next = fsmRun->runBuf;
+ fsmRun->runBuf = runBuf;
+
+ int lenCopied = 0;
+ is->funcs->getData( fsmRun, is, 0, runBuf->data, length, &lenCopied );
+ is->funcs->consumeData( is, length );
+ fsmRun->p = fsmRun->pe = runBuf->data + length;
+
+ Head *head = stringAllocPointer( prg, runBuf->data, length );
+
head->location = locationAllocate( prg );
head->location->line = is->line;
head->location->column = is->column;
@@ -809,8 +827,6 @@ Head *extractMatch( Program *prg, FsmRun *fsmRun, StreamImpl *is )
debug( REALM_PARSE, "location byte: %d\n", is->byte );
- is->funcs->consumeData( is, length );
-
return head;
}