summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2010-04-19 00:47:07 +0000
committerAdrian Thurston <thurston@complang.org>2010-04-19 00:47:07 +0000
commitf3e8845d101f76875d5bcbc457928917f4ba02cc (patch)
tree9a03ef072383cbd6a316b5b26629c615accf6fb5
parent021c532b2dd48cf802607106a3ea71fb5ae26e0d (diff)
downloadcolm-f3e8845d101f76875d5bcbc457928917f4ba02cc.tar.gz
yet more C porting
-rw-r--r--colm/Makefile.in1
-rw-r--r--colm/fsmrun.cpp45
-rw-r--r--colm/fsmrun.h3
-rw-r--r--colm/fsmrun2.c40
-rw-r--r--colm/fsmrun2.h2
-rw-r--r--colm/pdarun2.h2
6 files changed, 45 insertions, 48 deletions
diff --git a/colm/Makefile.in b/colm/Makefile.in
index e0610f96..1a929aa5 100644
--- a/colm/Makefile.in
+++ b/colm/Makefile.in
@@ -62,7 +62,6 @@ COLM_SRC = \
ctinput.cpp \
RUNTIME_SRC = fsmrun.cpp pdarun.cpp bytecode.cpp string.cpp tree.cpp
-
RUNTIME_SRC_C = map.c fsmrun2.c list.c input.c debug.c codevect.c pool.c
diff --git a/colm/fsmrun.cpp b/colm/fsmrun.cpp
index 268a21ac..fd50a866 100644
--- a/colm/fsmrun.cpp
+++ b/colm/fsmrun.cpp
@@ -26,6 +26,7 @@
#include "config.h"
#include "fsmrun.h"
#include "pdarun.h"
+#include "pdarun2.h"
#include "debug.h"
using std::cerr;
@@ -39,50 +40,6 @@ void operator<<( ostream &out, exit_object & )
exit(1);
}
-void incrementConsumed( PdaRun *pdaRun )
-{
- pdaRun->consumed += 1;
- debug( REALM_PARSE, "consumed up to %ld\n", pdaRun->consumed );
-}
-
-void decrementConsumed( PdaRun *pdaRun )
-{
- pdaRun->consumed -= 1;
- debug( REALM_PARSE, "consumed down to %ld\n", pdaRun->consumed );
-}
-
-void takeBackBuffered( InputStream *inputStream )
-{
- if ( inputStream->hasData != 0 ) {
- FsmRun *fsmRun = inputStream->hasData;
-
- if ( fsmRun->runBuf != 0 ) {
- if ( fsmRun->pe - fsmRun->p > 0 ) {
- #ifdef COLM_LOG_PARSE
- if ( colm_log_parse ) {
- cerr << "taking back buffered fsmRun: " << fsmRun <<
- " input stream: " << inputStream << endl;
- }
- #endif
-
- RunBuf *split = newRunBuf();
- memcpy( split->data, fsmRun->p, fsmRun->pe - fsmRun->p );
-
- split->length = fsmRun->pe - fsmRun->p;
- split->offset = 0;
- split->next = 0;
-
- fsmRun->pe = fsmRun->p;
-
- inputStream->funcs->pushBackBuf( inputStream, split );
- }
- }
-
- inputStream->hasData = 0;
- fsmRun->haveDataOf = 0;
- }
-}
-
void connect( FsmRun *fsmRun, InputStream *inputStream )
{
if ( inputStream->hasData != 0 && inputStream->hasData != fsmRun ) {
diff --git a/colm/fsmrun.h b/colm/fsmrun.h
index efec74d1..c227c7f5 100644
--- a/colm/fsmrun.h
+++ b/colm/fsmrun.h
@@ -70,9 +70,6 @@ Kid *makeToken( PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream, int id
void newToken( PdaRun *pdaRun, FsmRun *fsmRun );
void ignore( PdaRun *pdaRun, Tree *tree );
-void incrementConsumed( PdaRun *pdaRun );
-void decrementConsumed( PdaRun *pdaRun );
-
void initBindings( PdaRun *pdaRun );
void makeTokenPushBinding( PdaRun *pdaRun, int bindId, Tree *tree );
void unbind( Program *prg, Tree **sp, PdaRun *pdaRun, Tree *tree );
diff --git a/colm/fsmrun2.c b/colm/fsmrun2.c
index 85e2fbf9..37ed1f0b 100644
--- a/colm/fsmrun2.c
+++ b/colm/fsmrun2.c
@@ -22,6 +22,9 @@
#include "fsmrun2.h"
#include "pdarun2.h"
#include "input.h"
+#include "debug.h"
+
+#include <string.h>
void listPrepend( List *list, ListEl *new_el) { listAddBefore(list, list->head, new_el); }
void listAppend( List *list, ListEl *new_el) { listAddAfter(list, list->tail, new_el); }
@@ -85,4 +88,41 @@ void undoPosition( InputStream *inputStream, const char *data, long length )
inputStream->byte -= length;
}
+void incrementConsumed( PdaRun *pdaRun )
+{
+ pdaRun->consumed += 1;
+ debug( REALM_PARSE, "consumed up to %ld\n", pdaRun->consumed );
+}
+
+void decrementConsumed( PdaRun *pdaRun )
+{
+ pdaRun->consumed -= 1;
+ debug( REALM_PARSE, "consumed down to %ld\n", pdaRun->consumed );
+}
+
+void takeBackBuffered( InputStream *inputStream )
+{
+ if ( inputStream->hasData != 0 ) {
+ FsmRun *fsmRun = inputStream->hasData;
+
+ if ( fsmRun->runBuf != 0 ) {
+ if ( fsmRun->pe - fsmRun->p > 0 ) {
+ debug( REALM_PARSE, "taking back buffered fsmRun: %p input stream: %p\n", fsmRun, inputStream );
+ RunBuf *split = newRunBuf();
+ memcpy( split->data, fsmRun->p, fsmRun->pe - fsmRun->p );
+
+ split->length = fsmRun->pe - fsmRun->p;
+ split->offset = 0;
+ split->next = 0;
+
+ fsmRun->pe = fsmRun->p;
+
+ inputStream->funcs->pushBackBuf( inputStream, split );
+ }
+ }
+
+ inputStream->hasData = 0;
+ fsmRun->haveDataOf = 0;
+ }
+}
diff --git a/colm/fsmrun2.h b/colm/fsmrun2.h
index 0c4cf7d0..1765f8ca 100644
--- a/colm/fsmrun2.h
+++ b/colm/fsmrun2.h
@@ -88,6 +88,8 @@ typedef struct _FsmRun
void initFsmRun( FsmRun *fsmRun, struct _Program *prg );
void updatePosition( InputStream *inputStream, const char *data, long length );
void undoPosition( InputStream *inputStream, const char *data, long length );
+void takeBackBuffered( InputStream *inputStream );
+
#ifdef __cplusplus
}
diff --git a/colm/pdarun2.h b/colm/pdarun2.h
index da84e1f4..4d343eb3 100644
--- a/colm/pdarun2.h
+++ b/colm/pdarun2.h
@@ -536,6 +536,8 @@ inline static void appendWord( RtCodeVect *vect, Word word )
#endif
}
+void incrementConsumed( PdaRun *pdaRun );
+void decrementConsumed( PdaRun *pdaRun );
#ifdef __cplusplus
}