summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2010-04-17 01:18:30 +0000
committerAdrian Thurston <thurston@complang.org>2010-04-17 01:18:30 +0000
commit9f09b7990a18b9eac3ac612b570e47e5d1fd4f75 (patch)
treec6729ddaad984b3cc2a8e8184024cd0c2cc9d395
parent332671bb0a1f8e5b24f768b451e584163b5814c6 (diff)
downloadcolm-9f09b7990a18b9eac3ac612b570e47e5d1fd4f75.tar.gz
Some more C porting. Will need to implemented debug statements next.
-rw-r--r--colm/fsmcodegen.h2
-rw-r--r--colm/fsmrun.cpp48
-rw-r--r--colm/fsmrun.h21
-rw-r--r--colm/fsmrun2.c61
-rw-r--r--colm/fsmrun2.h27
-rw-r--r--colm/input.c2
-rw-r--r--colm/input.h18
-rw-r--r--colm/parsetree.h2
-rw-r--r--colm/pdarun.h1
-rw-r--r--colm/pdarun2.h59
-rw-r--r--colm/pool.h27
-rw-r--r--colm/redbuild.h2
12 files changed, 143 insertions, 127 deletions
diff --git a/colm/fsmcodegen.h b/colm/fsmcodegen.h
index cd015e04..eb29b781 100644
--- a/colm/fsmcodegen.h
+++ b/colm/fsmcodegen.h
@@ -28,6 +28,7 @@
#include "keyops.h"
#include "parsedata.h"
#include "redfsm.h"
+#include "fsmrun.h"
using std::string;
using std::ostream;
@@ -45,7 +46,6 @@ struct LongestMatch;
struct TokenDef;
struct InlineList;
struct InlineItem;
-struct FsmRun;
struct NameInst;
struct FsmCodeGen;
diff --git a/colm/fsmrun.cpp b/colm/fsmrun.cpp
index 563e4b3e..cd7c6be1 100644
--- a/colm/fsmrun.cpp
+++ b/colm/fsmrun.cpp
@@ -38,23 +38,6 @@ void operator<<( ostream &out, exit_object & )
exit(1);
}
-void initFsmRun( FsmRun *fsmRun, Program *prg )
-{
- fsmRun->prg = prg;
- fsmRun->tables = prg->rtd->fsmTables;
- fsmRun->runBuf = 0;
- fsmRun->haveDataOf = 0;
- fsmRun->curStream = 0;
-
- /* Run buffers need to stick around because
- * token strings point into them. */
- fsmRun->runBuf = newRunBuf();
- fsmRun->runBuf->next = 0;
-
- fsmRun->p = fsmRun->pe = fsmRun->runBuf->data;
- fsmRun->peof = 0;
-}
-
void incrementConsumed( PdaRun *pdaRun )
{
pdaRun->consumed += 1;
@@ -75,37 +58,6 @@ void decrementConsumed( PdaRun *pdaRun )
#endif
}
-/* Keep the position up to date after consuming text. */
-void updatePosition( InputStream *inputStream, const char *data, long length )
-{
- if ( !inputStream->handlesLine ) {
- for ( int i = 0; i < length; i++ ) {
- if ( data[i] != '\n' )
- inputStream->column += 1;
- else {
- inputStream->line += 1;
- inputStream->column = 1;
- }
- }
- }
-
- inputStream->byte += length;
-}
-
-/* Keep the position up to date after sending back text. */
-void undoPosition( InputStream *inputStream, const char *data, long length )
-{
- /* FIXME: this needs to fetch the position information from the parsed
- * token and restore based on that.. */
- if ( !inputStream->handlesLine ) {
- for ( int i = 0; i < length; i++ ) {
- if ( data[i] == '\n' )
- inputStream->line -= 1;
- }
- }
-
- inputStream->byte -= length;
-}
void takeBackBuffered( InputStream *inputStream )
{
diff --git a/colm/fsmrun.h b/colm/fsmrun.h
index 8aa94222..fdb3de60 100644
--- a/colm/fsmrun.h
+++ b/colm/fsmrun.h
@@ -46,28 +46,9 @@ void operator<<( std::ostream &out, exit_object & );
#include "fsmrun2.h"
-struct FsmRun
-{
- Program *prg;
- FsmTables *tables;
-
- RunBuf *runBuf;
-
- /* FsmRun State. */
- long region, cs, act;
- char *tokstart, *tokend;
- char *p, *pe, *peof;
- bool returnResult;
- char *mark[MARK_SLOTS];
- long matchedToken;
-
- InputStream *haveDataOf;
- Tree *curStream;
-};
-
void execAction( FsmRun *fsmRun, GenAction *genAction );
void fsmExecute( FsmRun *fsmRun, InputStream *inputStream );
-void initFsmRun( FsmRun *fsmRun, Program *prg );
+
void initInputStream( InputStream *in );
void sendQueuedTokens( Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream );
void sendHandleError( Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream, Kid *input );
diff --git a/colm/fsmrun2.c b/colm/fsmrun2.c
index 1e8365dd..415b1746 100644
--- a/colm/fsmrun2.c
+++ b/colm/fsmrun2.c
@@ -20,6 +20,67 @@
*/
#include "fsmrun2.h"
+#include "pdarun2.h"
#include "input.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); }
+ListEl *listDetach( List *list, ListEl *el );
+ListEl *listDetachFirst(List *list ) { return listDetach(list, list->head); }
+ListEl *listDetachLast(List *list ) { return listDetach(list, list->tail); }
+
+long listLength(List *list)
+ { return list->listLen; }
+
+void initFsmRun( FsmRun *fsmRun, Program *prg )
+{
+ fsmRun->prg = prg;
+ fsmRun->tables = prg->rtd->fsmTables;
+ fsmRun->runBuf = 0;
+ fsmRun->haveDataOf = 0;
+ fsmRun->curStream = 0;
+
+ /* Run buffers need to stick around because
+ * token strings point into them. */
+ fsmRun->runBuf = newRunBuf();
+ fsmRun->runBuf->next = 0;
+
+ fsmRun->p = fsmRun->pe = fsmRun->runBuf->data;
+ fsmRun->peof = 0;
+}
+
+
+/* Keep the position up to date after consuming text. */
+void updatePosition( InputStream *inputStream, const char *data, long length )
+{
+ int i;
+ if ( !inputStream->handlesLine ) {
+ for ( i = 0; i < length; i++ ) {
+ if ( data[i] != '\n' )
+ inputStream->column += 1;
+ else {
+ inputStream->line += 1;
+ inputStream->column = 1;
+ }
+ }
+ }
+
+ inputStream->byte += length;
+}
+
+/* Keep the position up to date after sending back text. */
+void undoPosition( InputStream *inputStream, const char *data, long length )
+{
+ /* FIXME: this needs to fetch the position information from the parsed
+ * token and restore based on that.. */
+ int i;
+ if ( !inputStream->handlesLine ) {
+ for ( i = 0; i < length; i++ ) {
+ if ( data[i] == '\n' )
+ inputStream->line -= 1;
+ }
+ }
+
+ inputStream->byte -= length;
+}
diff --git a/colm/fsmrun2.h b/colm/fsmrun2.h
index afdc357c..0c4cf7d0 100644
--- a/colm/fsmrun2.h
+++ b/colm/fsmrun2.h
@@ -22,6 +22,8 @@
#ifndef _FSMRUN2_H
#define _FSMRUN2_H
+#include "input.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -62,6 +64,31 @@ typedef struct _FsmTables
long numActionSwitch;
} FsmTables;
+struct _Program;
+
+typedef struct _FsmRun
+{
+ struct _Program *prg;
+ FsmTables *tables;
+
+ RunBuf *runBuf;
+
+ /* FsmRun State. */
+ long region, cs, act;
+ char *tokstart, *tokend;
+ char *p, *pe, *peof;
+ int returnResult;
+ char *mark[MARK_SLOTS];
+ long matchedToken;
+
+ InputStream *haveDataOf;
+ struct _Tree *curStream;
+} 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 );
+
#ifdef __cplusplus
}
#endif
diff --git a/colm/input.c b/colm/input.c
index a9b40593..c1dcf648 100644
--- a/colm/input.c
+++ b/colm/input.c
@@ -20,6 +20,8 @@
*/
#include "input.h"
+#include "fsmrun2.h"
+#include "pdarun2.h"
#include <stdio.h>
#include <stdlib.h>
diff --git a/colm/input.h b/colm/input.h
index 0a3b503f..ce9fddbe 100644
--- a/colm/input.h
+++ b/colm/input.h
@@ -53,8 +53,8 @@ struct Pattern;
struct PatternItem;
struct Replacement;
struct ReplItem;
-struct FsmRun;
-typedef struct _Tree Tree;
+struct _FsmRun;
+struct _Tree;
enum RunBufType {
RunBufDataType = 0,
@@ -67,7 +67,7 @@ typedef struct _RunBuf
enum RunBufType type;
char data[FSM_BUFSIZE];
long length;
- Tree *tree;
+ struct _Tree *tree;
long offset;
struct _RunBuf *next, *prev;
} RunBuf;
@@ -86,14 +86,14 @@ struct InputFuncs
int (*tryAgainLater)( InputStream *is );
int (*getData)( InputStream *is, char *dest, int length );
int (*getDataImpl)( InputStream *is, char *dest, int length );
- Tree *(*getTree)( InputStream *is );
+ struct _Tree *(*getTree)( InputStream *is );
struct KlangEl *(*getLangEl)( InputStream *is, long *bindId, char **data, long *length );
- void (*pushTree)( InputStream *is, Tree *tree, int ignore );
+ void (*pushTree)( InputStream *is, struct _Tree *tree, int ignore );
void (*pushText)( InputStream *is, const char *data, long len );
- Tree *(*undoPush)( InputStream *is, int length );
+ struct _Tree *(*undoPush)( InputStream *is, int length );
void (*appendData)( InputStream *is, const char *data, long len );
- void (*appendTree)( InputStream *is, Tree *tree );
- Tree *(*undoAppend)( InputStream *is, int length );
+ void (*appendTree)( InputStream *is, struct _Tree *tree );
+ struct _Tree *(*undoAppend)( InputStream *is, int length );
void (*pushBackNamed)( InputStream *is );
void (*pushBackBuf)( InputStream *is, RunBuf *runBuf );
};
@@ -111,7 +111,7 @@ struct _InputStream
{
struct InputFuncs *funcs;
- struct FsmRun *hasData;
+ struct _FsmRun *hasData;
char eofSent;
char flush;
diff --git a/colm/parsetree.h b/colm/parsetree.h
index e19842b4..24f7393f 100644
--- a/colm/parsetree.h
+++ b/colm/parsetree.h
@@ -48,7 +48,7 @@
struct NameInst;
struct FsmGraph;
struct RedFsm;
-struct FsmRun;
+struct _FsmRun;
struct ObjectDef;
struct ElementOf;
struct UniqueType;
diff --git a/colm/pdarun.h b/colm/pdarun.h
index 38853011..4eeb9b36 100644
--- a/colm/pdarun.h
+++ b/colm/pdarun.h
@@ -33,7 +33,6 @@ using std::ostream;
typedef struct _Tree Tree;
struct ParseData;
-struct FsmRun;
struct KlangEl;
struct InputStreamAccum;
diff --git a/colm/pdarun2.h b/colm/pdarun2.h
index 4e2def9a..98fe0cf6 100644
--- a/colm/pdarun2.h
+++ b/colm/pdarun2.h
@@ -149,15 +149,14 @@ typedef struct _List
void listAddAfter( List *list, ListEl *prev_el, ListEl *new_el );
void listAddBefore( List *list, ListEl *next_el, ListEl *new_el );
-inline void listPrepend( List *list, ListEl *new_el) { listAddBefore(list, list->head, new_el); }
-inline void listAppend( List *list, ListEl *new_el) { listAddAfter(list, list->tail, new_el); }
+void listPrepend( List *list, ListEl *new_el );
+void listAppend( List *list, ListEl *new_el );
ListEl *listDetach( List *list, ListEl *el );
-inline ListEl *listDetachFirst(List *list ) { return listDetach(list, list->head); }
-inline ListEl *listDetachLast(List *list ) { return listDetach(list, list->tail); }
+ListEl *listDetachFirst(List *list );
+ListEl *listDetachLast(List *list );
-inline long listLength(List *list)
- { return list->listLen; }
+long listLength(List *list);
typedef struct _Stream
{
@@ -213,7 +212,7 @@ typedef struct _PatReplNode
long ignore;
/* Just match nonterminal, don't go inside. */
- bool stop;
+ unsigned char stop;
} PatReplNode;
/* FIXME: should have a descriptor for object types to give the length. */
@@ -221,10 +220,10 @@ typedef struct _PatReplNode
typedef struct _LangElInfo
{
const char *name;
- bool repeat;
- bool list;
- bool literal;
- bool ignore;
+ unsigned char repeat;
+ unsigned char list;
+ unsigned char literal;
+ unsigned char ignore;
long frameId;
@@ -253,7 +252,7 @@ typedef struct _ProdInfo
unsigned long lhsId;
const char *name;
long frameId;
- bool lhsUpref;
+ unsigned char lhsUpref;
} ProdInfo;
typedef struct _FrameInfo
@@ -360,22 +359,42 @@ typedef struct _PdaTables
RuntimeData *rtd;
} PdaTables;
+
+struct PoolBlock
+{
+ void *data;
+ struct PoolBlock *next;
+};
+
+struct PoolItem
+{
+ struct PoolItem *next;
+};
+
+struct PoolAlloc
+{
+ struct PoolBlock *head;
+ long nextel;
+ struct PoolItem *pool;
+ int sizeofT;
+};
+
typedef struct _Program
{
int argc;
char **argv;
- bool ctxDepParsing;
+ unsigned char ctxDepParsing;
RuntimeData *rtd;
Tree *global;
- PoolAlloc kidPool;
- PoolAlloc treePool;
- PoolAlloc parseTreePool;
- PoolAlloc listElPool;
- PoolAlloc mapElPool;
- PoolAlloc headPool;
- PoolAlloc locationPool;
+ struct PoolAlloc kidPool;
+ struct PoolAlloc treePool;
+ struct PoolAlloc parseTreePool;
+ struct PoolAlloc listElPool;
+ struct PoolAlloc mapElPool;
+ struct PoolAlloc headPool;
+ struct PoolAlloc locationPool;
Tree *trueVal;
Tree *falseVal;
diff --git a/colm/pool.h b/colm/pool.h
index 6a2dccee..67446d28 100644
--- a/colm/pool.h
+++ b/colm/pool.h
@@ -22,35 +22,10 @@
#ifndef _POOL_H
#define _POOL_H
-#include <iostream>
-
-using std::cerr;
-using std::endl;
-using std::ostream;
-
/* Allocation, number of items. */
#define FRESH_BLOCK 8128
-struct PoolBlock
-{
- void *data;
- PoolBlock *next;
-};
-
-struct PoolItem
-{
- PoolItem *next;
-};
-
-struct PoolAlloc
-{
- PoolBlock *head;
- long nextel;
- PoolItem *pool;
- int sizeofT;
-};
-
-void initPoolAlloc( PoolAlloc *poolAlloc, int sizeofT );
+void initPoolAlloc( struct PoolAlloc *poolAlloc, int sizeofT );
typedef struct _Program Program;
typedef struct _Kid Kid;
diff --git a/colm/redbuild.h b/colm/redbuild.h
index 2bc2b2f9..f83acddc 100644
--- a/colm/redbuild.h
+++ b/colm/redbuild.h
@@ -26,6 +26,7 @@
#include "avltree.h"
#include "fsmgraph.h"
#include "parsedata.h"
+#include "fsmrun2.h"
/* Forwards. */
struct FsmTrans;
@@ -33,7 +34,6 @@ struct FsmGraph;
struct ParseData;
struct FsmCodeGen;
struct RedFsm;
-struct FsmRun;
struct GenCondSpace;
struct Condition;