diff options
author | Adrian Thurston <thurston@complang.org> | 2013-01-05 14:07:58 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2013-01-05 14:07:58 -0500 |
commit | 205da42c6f7f9aef3caa4acda774249e58dd7c20 (patch) | |
tree | 7b2681a03ea1645be0811528cb6ebc850b201a95 /colm | |
parent | 12b342af87911d4dc5e872f5139a9b3133fec56e (diff) | |
download | colm-205da42c6f7f9aef3caa4acda774249e58dd7c20.tar.gz |
completed unification of the Input and Stream types
Diffstat (limited to 'colm')
-rw-r--r-- | colm/bytecode.c | 22 | ||||
-rw-r--r-- | colm/bytecode.h | 6 | ||||
-rw-r--r-- | colm/declare.cc | 1 | ||||
-rw-r--r-- | colm/parsedata.h | 4 | ||||
-rw-r--r-- | colm/pdabuild.cc | 1 | ||||
-rw-r--r-- | colm/pool.c | 15 | ||||
-rw-r--r-- | colm/pool.h | 3 | ||||
-rw-r--r-- | colm/synthesis.cc | 20 | ||||
-rw-r--r-- | colm/tree.c | 16 | ||||
-rw-r--r-- | colm/tree.h | 15 |
10 files changed, 23 insertions, 80 deletions
diff --git a/colm/bytecode.c b/colm/bytecode.c index 9c019d2e..df92e2e5 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 || input->id == LEL_ID_INPUT ) { + else if ( input->id == LEL_ID_STREAM ) { treeUpref( input ); is->funcs->appendStream( is, input ); } @@ -2115,7 +2115,7 @@ again: case IN_INPUT_APPEND_WC: { debug( REALM_BYTECODE, "IN_INPUT_APPEND_WC \n" ); - Input *accumStream = (Input*)vm_pop(); + Stream *accumStream = (Stream*)vm_pop(); Tree *input = vm_pop(); streamAppend( prg, sp, input, accumStream->in ); @@ -2126,7 +2126,7 @@ again: case IN_INPUT_APPEND_WV: { debug( REALM_BYTECODE, "IN_INPUT_APPEND_WV \n" ); - Input *accumStream = (Input*)vm_pop(); + Stream *accumStream = (Stream*)vm_pop(); Tree *input = vm_pop(); Word len = streamAppend( prg, sp, input, accumStream->in ); @@ -2152,7 +2152,7 @@ again: debug( REALM_BYTECODE, "IN_INPUT_APPEND_BKT\n" ); - undoStreamAppend( prg, sp, 0, ((Input*)accumStream)->in, input, len ); + undoStreamAppend( prg, sp, 0, ((Stream*)accumStream)->in, input, len ); treeDownref( prg, sp, accumStream ); treeDownref( prg, sp, input ); break; @@ -2451,7 +2451,7 @@ again: case IN_INPUT_PULL_WV: { debug( REALM_BYTECODE, "IN_INPUT_PULL_WV\n" ); - Input *accumStream = (Input*)vm_pop(); + Stream *accumStream = (Stream*)vm_pop(); Tree *len = vm_pop(); Tree *string = streamPullBc( prg, exec->parser->fsmRun, accumStream->in, len ); treeUpref( string ); @@ -2475,7 +2475,7 @@ again: debug( REALM_BYTECODE, "IN_INPUT_PULL_BKT\n" ); - undoPull( prg, ((Input*)accumStream)->in, string ); + undoPull( prg, ((Stream*)accumStream)->in, string ); treeDownref( prg, sp, accumStream ); treeDownref( prg, sp, string ); break; @@ -2483,7 +2483,7 @@ again: case IN_INPUT_PUSH_WV: { debug( REALM_BYTECODE, "IN_INPUT_PUSH_WV\n" ); - Input *input = (Input*)vm_pop(); + Stream *input = (Stream*)vm_pop(); Tree *tree = vm_pop(); long len = streamPush( prg, sp, 0, input->in, tree, false ); vm_push( 0 ); @@ -2500,7 +2500,7 @@ again: case IN_INPUT_PUSH_IGNORE_WV: { debug( REALM_BYTECODE, "IN_INPUT_PUSH_IGNORE_WV\n" ); - Input *input = (Input*)vm_pop(); + Stream *input = (Stream*)vm_pop(); Tree *tree = vm_pop(); long len = streamPush( prg, sp, 0, input->in, tree, true ); vm_push( 0 ); @@ -2518,7 +2518,7 @@ again: Word len; read_word( len ); - Input *input = (Input*)vm_pop(); + Stream *input = (Stream*)vm_pop(); debug( REALM_BYTECODE, "IN_INPUT_PUSH_BKT\n" ); @@ -2563,7 +2563,7 @@ again: case IN_CONSTRUCT_INPUT: { debug( REALM_BYTECODE, "IN_CONSTRUCT_INPUT\n" ); - Tree *input = constructInput( prg ); + Tree *input = constructStream( prg ); treeUpref( input ); vm_push( input ); break; @@ -2581,7 +2581,7 @@ again: debug( REALM_BYTECODE, "IN_SET_INPUT\n" ); Parser *parser = (Parser*)vm_pop(); - Input *accumStream = (Input*)vm_pop(); + Stream *accumStream = (Stream*)vm_pop(); parser->input = accumStream; treeUpref( (Tree*)accumStream ); treeDownref( prg, sp, (Tree*)parser ); diff --git a/colm/bytecode.h b/colm/bytecode.h index 2e115339..26482f2d 100644 --- a/colm/bytecode.h +++ b/colm/bytecode.h @@ -331,17 +331,13 @@ typedef unsigned char uchar; #define GEN_VECTOR 0x12 #define GEN_PARSER 0x13 -/* Virtual machine stack size, number of pointers. - * This will be mmapped. */ - /* Known language element ids. */ #define LEL_ID_PTR 1 #define LEL_ID_BOOL 2 #define LEL_ID_INT 3 #define LEL_ID_STR 4 #define LEL_ID_STREAM 5 -#define LEL_ID_INPUT 6 -#define LEL_ID_IGNORE 7 +#define LEL_ID_IGNORE 6 /* * Flags diff --git a/colm/declare.cc b/colm/declare.cc index 74b01eab..6a285277 100644 --- a/colm/declare.cc +++ b/colm/declare.cc @@ -96,7 +96,6 @@ void Compiler::declareBaseLangEls() intLangEl = declareLangEl( this, rootNamespace, "int", LangEl::Term ); strLangEl = declareLangEl( this, rootNamespace, "str", LangEl::Term ); streamLangEl = declareLangEl( this, rootNamespace, "stream", LangEl::Term ); - inputLangEl = declareLangEl( this, rootNamespace, "accum_stream", LangEl::Term ); ignoreLangEl = declareLangEl( this, rootNamespace, "il", LangEl::Term ); /* Make the EOF language element. */ diff --git a/colm/parsedata.h b/colm/parsedata.h index b94386c7..f3a0121a 100644 --- a/colm/parsedata.h +++ b/colm/parsedata.h @@ -912,7 +912,6 @@ struct Compiler LangEl *intLangEl; LangEl *strLangEl; LangEl *streamLangEl; - LangEl *inputLangEl; LangEl *anyLangEl; LangEl *rootLangEl; LangEl *noTokenLangEl; @@ -957,7 +956,6 @@ struct Compiler UniqueType *uniqueTypeInt; UniqueType *uniqueTypeStr; UniqueType *uniqueTypeStream; - UniqueType *uniqueTypeInput; UniqueType *uniqueTypeIgnore; UniqueType *uniqueTypeAny; @@ -970,14 +968,12 @@ struct Compiler void initStrObject(); void initStreamObject(); - void initInputObject(); void initIntObject(); void initTokenObjects(); ObjectDef *intObj; ObjectDef *strObj; ObjectDef *streamObj; - ObjectDef *inputObj; ObjectDef *tokenObj; FsmTables *fsmTables; diff --git a/colm/pdabuild.cc b/colm/pdabuild.cc index 560b8761..1dbd649e 100644 --- a/colm/pdabuild.cc +++ b/colm/pdabuild.cc @@ -230,7 +230,6 @@ void Compiler::makeLangElIds() assert( intLangEl->id == LEL_ID_INT ); assert( strLangEl->id == LEL_ID_STR ); assert( streamLangEl->id == LEL_ID_STREAM ); - assert( inputLangEl->id == LEL_ID_INPUT ); assert( ignoreLangEl->id == LEL_ID_IGNORE ); } diff --git a/colm/pool.c b/colm/pool.c index 4b9766d3..a6c31593 100644 --- a/colm/pool.c +++ b/colm/pool.c @@ -305,18 +305,3 @@ void streamFree( Program *prg, Stream *stream ) { mapElFree( prg, (MapEl*)stream ); } - - -/* - * Input - */ - -Input *inputAllocate( Program *prg ) -{ - return (Input*)mapElAllocate( prg ); -} - -void inputFree( Program *prg, Input *accumStream ) -{ - mapElFree( prg, (MapEl*)accumStream ); -} diff --git a/colm/pool.h b/colm/pool.h index 454a5354..3a547bb8 100644 --- a/colm/pool.h +++ b/colm/pool.h @@ -73,9 +73,6 @@ long locationNumLost( Program *prg ); Stream *streamAllocate( Program *prg ); void streamFree( Program *prg, Stream *stream ); -Input *inputAllocate( Program *prg ); -void inputFree( Program *prg, Input *stream ); - /* Wrong place. */ TreePair mapRemove( Program *prg, Map *map, Tree *key ); diff --git a/colm/synthesis.cc b/colm/synthesis.cc index f01a4f41..2c7e7e8b 100644 --- a/colm/synthesis.cc +++ b/colm/synthesis.cc @@ -39,7 +39,6 @@ void Compiler::initUniqueTypes( ) uniqueTypeInt = new UniqueType( TYPE_TREE, intLangEl ); uniqueTypeStr = new UniqueType( TYPE_TREE, strLangEl ); uniqueTypeStream = new UniqueType( TYPE_TREE, streamLangEl ); - uniqueTypeInput = new UniqueType( TYPE_TREE, inputLangEl ); uniqueTypeIgnore = new UniqueType( TYPE_TREE, ignoreLangEl ); uniqueTypeAny = new UniqueType( TYPE_TREE, anyLangEl ); @@ -49,7 +48,6 @@ void Compiler::initUniqueTypes( ) uniqeTypeMap.insert( uniqueTypeInt ); uniqeTypeMap.insert( uniqueTypeStr ); uniqeTypeMap.insert( uniqueTypeStream ); - uniqeTypeMap.insert( uniqueTypeInput ); uniqeTypeMap.insert( uniqueTypeIgnore ); uniqeTypeMap.insert( uniqueTypeAny ); } @@ -1481,7 +1479,6 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code, bool stop, bo /* * Finish operation */ -finish: /* Parse instruction, dependent on whether or not we are producing revert * or commit code. */ @@ -2430,7 +2427,7 @@ void Compiler::addMatchText( ObjectDef *frame, LangEl *lel ) void Compiler::addInput( ObjectDef *frame ) { /* Make the type ref. */ - TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeInput ); + TypeRef *typeRef = TypeRef::cons( internal, uniqueTypeStream ); /* Create the field and insert it into the map. */ ObjField *el = new ObjField( internal, typeRef, "input" ); @@ -2533,19 +2530,12 @@ void Compiler::initStreamObject( ) streamObj = new ObjectDef( ObjectDef::BuiltinType, "stream", nextObjectId++ ); streamLangEl->objectDef = streamObj; -} - -void Compiler::initInputObject( ) -{ - inputObj = new ObjectDef( ObjectDef::BuiltinType, - "accum_stream", nextObjectId++ ); - inputLangEl->objectDef = inputObj; - initFunction( uniqueTypeStr, inputObj, "pull", + initFunction( uniqueTypeStr, streamObj, "pull", IN_INPUT_PULL_WV, IN_INPUT_PULL_WV, uniqueTypeInt, false ); - initFunction( uniqueTypeStr, inputObj, "push", + initFunction( uniqueTypeStr, streamObj, "push", IN_INPUT_PUSH_WV, IN_INPUT_PUSH_WV, uniqueTypeAny, false ); - initFunction( uniqueTypeStr, inputObj, "push_ignore", + initFunction( uniqueTypeStr, streamObj, "push_ignore", IN_INPUT_PUSH_IGNORE_WV, IN_INPUT_PUSH_IGNORE_WV, uniqueTypeAny, false ); } @@ -3350,11 +3340,9 @@ void Compiler::removeNonUnparsableRepls() void Compiler::compileByteCode() { -// initUniqueTypes(); initIntObject(); initStrObject(); initStreamObject(); - initInputObject(); initTokenObjects(); makeDefaultIterators(); initAllLanguageObjects(); diff --git a/colm/tree.c b/colm/tree.c index 89e30e48..edd0dc79 100644 --- a/colm/tree.c +++ b/colm/tree.c @@ -319,11 +319,11 @@ Tree *constructTerm( Program *prg, Word id, Head *tokdata ) return tree; } -Tree *constructInput( Program *prg ) +Tree *constructStream( Program *prg ) { - Input *input = inputAllocate( prg ); + Stream *input = streamAllocate( prg ); input->refs = 0; - input->id = LEL_ID_INPUT; + input->id = LEL_ID_STREAM; input->in = malloc( sizeof(StreamImpl) ); initStreamImpl( input->in ); return (Tree*)input; @@ -1069,19 +1069,13 @@ free_tree: else if ( tree->id == LEL_ID_STREAM ) { Stream *stream = (Stream*)tree; clearSourceStream( prg, sp, stream->in ); - free( stream->in ); if ( stream->in->file != 0 ) fclose( stream->in->file ); - else + else if ( stream->in->fd > 0 ) close( stream->in->fd ); + free( stream->in ); streamFree( prg, stream ); } - else if ( tree->id == LEL_ID_INPUT ) { - Input *input = (Input*)tree; - clearStreamImpl( prg, sp, input->in ); - free( input->in ); - inputFree( prg, input ); - } else { if ( tree->id != LEL_ID_IGNORE ) stringFree( prg, tree->tokdata ); diff --git a/colm/tree.h b/colm/tree.h index 2a117171..8b6d509d 100644 --- a/colm/tree.h +++ b/colm/tree.h @@ -192,17 +192,6 @@ typedef struct _Stream StreamImpl *in; } Stream; -typedef struct _Input -{ - /* Must overlay Tree. */ - short id; - unsigned short flags; - long refs; - Kid *child; - - StreamImpl *in; -} Input; - typedef struct _Parser { /* Must overlay Tree. */ @@ -215,7 +204,7 @@ typedef struct _Parser struct _PdaRun *pdaRun; struct _FsmRun *fsmRun; - struct _Input *input; + struct _Stream *input; Tree *result; } Parser; @@ -283,7 +272,7 @@ Tree *constructTerm( struct ColmProgram *prg, Word id, Head *tokdata ); Tree *constructReplacementTree( Kid *kid, Tree **bindings, struct ColmProgram *prg, long pat ); Tree *createGeneric( struct ColmProgram *prg, long genericId ); Tree *constructToken( struct ColmProgram *prg, Tree **root, long nargs ); -Tree *constructInput( struct ColmProgram *prg ); +Tree *constructStream( struct ColmProgram *prg ); int testFalse( struct ColmProgram *prg, Tree *tree ); |