summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-01-05 12:50:15 -0500
committerAdrian Thurston <thurston@complang.org>2013-01-05 12:50:15 -0500
commit12b342af87911d4dc5e872f5139a9b3133fec56e (patch)
tree03ab88a95187d5b1b6c582642bd9f67f616023dd
parent6c2d1d95cbf0b13f3de71a5eb4f8e65426fa6a47 (diff)
downloadcolm-12b342af87911d4dc5e872f5139a9b3133fec56e.tar.gz
towards unifying input and stream types
Now not treating input stream any different from source stream in the parse statement. Just pass it in as a source to the parser's input stream. We are moving towards copositional input streams.
-rw-r--r--colm/bytecode.c2
-rw-r--r--colm/input.c23
-rw-r--r--colm/pdarun.c2
-rw-r--r--colm/synthesis.cc26
4 files changed, 16 insertions, 37 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c
index cb8001ab..9c019d2e 100644
--- a/colm/bytecode.c
+++ b/colm/bytecode.c
@@ -173,7 +173,7 @@ Word streamAppend( Program *prg, Tree **sp, Tree *input, StreamImpl *is )
length = collect.length;
strCollectDestroy( &collect );
}
- else if ( input->id == LEL_ID_STREAM ) {
+ else if ( input->id == LEL_ID_STREAM || input->id == LEL_ID_INPUT ) {
treeUpref( input );
is->funcs->appendStream( is, input );
}
diff --git a/colm/input.c b/colm/input.c
index 64871979..2d60cee8 100644
--- a/colm/input.c
+++ b/colm/input.c
@@ -674,16 +674,23 @@ void _prependData( StreamImpl *is, const char *data, long length )
if ( is->attached != 0 )
detachStream( is->attached, is );
- /* Create a new buffer for the data. This is the easy implementation.
- * Something better is needed here. It puts a max on the amount of
- * data that can be pushed back to the inputStream. */
- assert( length < FSM_BUFSIZE );
+ if ( isSourceStream( is ) && ((Stream*)is->queue->tree)->in->funcs == &streamFuncs ) {
+ Stream *stream = (Stream*)is->queue->tree;
- RunBuf *newBuf = newRunBuf();
- newBuf->length = length;
- memcpy( newBuf->data, data, length );
+ _prependData( stream->in, data, length );
+ }
+ else {
+ /* Create a new buffer for the data. This is the easy implementation.
+ * Something better is needed here. It puts a max on the amount of
+ * data that can be pushed back to the inputStream. */
+ assert( length < FSM_BUFSIZE );
- inputStreamPrepend( is, newBuf );
+ RunBuf *newBuf = newRunBuf();
+ newBuf->length = length;
+ memcpy( newBuf->data, data, length );
+
+ inputStreamPrepend( is, newBuf );
+ }
}
int _undoPrependData( StreamImpl *is, int length )
diff --git a/colm/pdarun.c b/colm/pdarun.c
index 667a0eb5..648538c3 100644
--- a/colm/pdarun.c
+++ b/colm/pdarun.c
@@ -277,8 +277,6 @@ void detachSource( FsmRun *fsmRun, StreamImpl *is )
void clearBuffered( FsmRun *fsmRun )
{
- /* If there is data in the current buffer then send the whole send back
- * should be in this buffer. */
if ( fsmRun->tokstart != 0 ) {
fsmRun->p = fsmRun->pe = fsmRun->tokstart;
fsmRun->tokstart = 0;
diff --git a/colm/synthesis.cc b/colm/synthesis.cc
index 13d54dc6..f01a4f41 100644
--- a/colm/synthesis.cc
+++ b/colm/synthesis.cc
@@ -1419,32 +1419,6 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code, bool stop, bo
/*****************************/
- if ( parserText->list->length() == 1 &&
- parserText->list->head->type == ConsItem::ExprType )
- {
- /* Only one argument and it is an expression type. Evaluate it (but
- * ignore the code) to determine if it is an input type. */
- CodeVect unused;
- UniqueType *ut = parserText->list->head->expr->evaluate( pd, unused );
-
- if ( ut == pd->uniqueTypeInput ) {
- /* Only one argument and it is an input object. Set the input into
- * the parser and parse using it. */
- code.append( IN_DUP_TOP );
-
- parserText->list->head->expr->evaluate( pd, code );
-
- code.append( IN_TOP_SWAP );
- code.append( IN_SET_INPUT );
-
- code.append( IN_DUP_TOP );
-
- parseFrag( pd, code, stopId );
-
- goto finish;
- }
- }
-
code.append( IN_DUP_TOP );
code.append( IN_CONSTRUCT_INPUT );
code.append( IN_TOP_SWAP );