diff options
-rw-r--r-- | src/bytecode.c | 14 | ||||
-rw-r--r-- | src/compiler.cc | 6 | ||||
-rw-r--r-- | src/ctinput.cc | 4 | ||||
-rw-r--r-- | src/input.c | 33 | ||||
-rw-r--r-- | src/input.h | 10 | ||||
-rw-r--r-- | src/struct.c | 44 | ||||
-rw-r--r-- | src/struct.h | 2 | ||||
-rw-r--r-- | src/synthesis.cc | 4 | ||||
-rw-r--r-- | src/tree.c | 47 | ||||
-rw-r--r-- | src/tree.h | 3 |
10 files changed, 73 insertions, 94 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 7fca5496..346e0d04 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -478,7 +478,7 @@ static Tree *construct_arg0( Program *prg, int argc, const char **argv ) static List *construct_argv( Program *prg, int argc, const char **argv ) { - List *list = (List*)constructGeneric( prg, prg->rtd->argvGenericId ); + List *list = (List*)colm_construct_generic( prg, prg->rtd->argvGenericId ); int i; for ( i = 1; i < argc; i++ ) { Head *head = stringAllocPointer( prg, argv[i], strlen(argv[i]) ); @@ -2663,8 +2663,8 @@ again: debug( prg, REALM_BYTECODE, "IN_CONS_GENERIC %hd\n", genericId ); - Tree *replTree = constructGeneric( prg, genericId ); - vm_push( replTree ); + Struct *gen = colm_construct_generic( prg, genericId ); + vm_push_struct( gen ); break; } case IN_CONS_OBJECT: { @@ -3371,7 +3371,7 @@ again: Tree *mode = vm_pop(); Tree *name = vm_pop(); - Stream *res = openFile( prg, name, mode ); + Stream *res = colm_stream_open_file( prg, name, mode ); vm_push_stream( res ); treeDownref( prg, sp, name ); treeDownref( prg, sp, mode ); @@ -3383,7 +3383,7 @@ again: /* Pop the root object. */ Tree *obj = vm_pop(); if ( prg->stdinVal == 0 ) - prg->stdinVal = openStreamFd( prg, "<stdin>", 0 ); + prg->stdinVal = colm_stream_open_fd( prg, "<stdin>", 0 ); vm_push_stream( prg->stdinVal ); break; @@ -3394,7 +3394,7 @@ again: /* Pop the root object. */ Tree *obj = vm_pop(); if ( prg->stdoutVal == 0 ) - prg->stdoutVal = openStreamFd( prg, "<stdout>", 1 ); + prg->stdoutVal = colm_stream_open_fd( prg, "<stdout>", 1 ); vm_push_stream( prg->stdoutVal ); break; @@ -3405,7 +3405,7 @@ again: /* Pop the root object. */ Tree *obj = vm_pop(); if ( prg->stderrVal == 0 ) - prg->stderrVal = openStreamFd( prg, "<stderr>", 2 ); + prg->stderrVal = colm_stream_open_fd( prg, "<stderr>", 2 ); vm_push_stream( prg->stderrVal ); break; diff --git a/src/compiler.cc b/src/compiler.cc index 068a75ee..e66473c5 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -983,7 +983,7 @@ void Compiler::initEmptyScanners() PdaRun *Compiler::parsePattern( Program *prg, Tree **sp, const InputLoc &loc, int parserId, StreamImpl *sourceStream ) { - StreamImpl *in = newSourceStreamGeneric( "<internal>" ); + StreamImpl *in = colm_impl_new_generic( "<internal>" ); PdaRun *pdaRun = new PdaRun; colm_pda_init( prg, pdaRun, pdaTables, parserId, 0, false, 0 ); @@ -1026,13 +1026,13 @@ void Compiler::parsePatterns() for ( ConsList::Iter cons = replList; cons.lte(); cons++ ) { if ( cons->langEl != 0 ) { - StreamImpl *in = newSourceStreamCons( "<internal>", cons ); + StreamImpl *in = colm_impl_new_cons( "<internal>", cons ); cons->pdaRun = parsePattern( prg, sp, cons->loc, cons->langEl->parserId, in ); } } for ( PatList::Iter pat = patternList; pat.lte(); pat++ ) { - StreamImpl *in = newSourceStreamPat( "<internal>", pat ); + StreamImpl *in = colm_impl_new_pat( "<internal>", pat ); pat->pdaRun = parsePattern( prg, sp, pat->loc, pat->langEl->parserId, in ); } diff --git a/src/ctinput.cc b/src/ctinput.cc index 4a9c92ad..5319002d 100644 --- a/src/ctinput.cc +++ b/src/ctinput.cc @@ -37,7 +37,7 @@ extern StreamFuncs replFuncs; * Pattern */ -StreamImpl *newSourceStreamPat( const char *name, Pattern *pattern ) +StreamImpl *colm_impl_new_pat( const char *name, Pattern *pattern ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); memset( ss, 0, sizeof(StreamImpl) ); @@ -235,7 +235,7 @@ StreamFuncs patternFuncs = * Constructor */ -StreamImpl *newSourceStreamCons( const char *name, Constructor *constructor ) +StreamImpl *colm_impl_new_cons( const char *name, Constructor *constructor ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); memset( ss, 0, sizeof(StreamImpl) ); diff --git a/src/input.c b/src/input.c index fa6bb5dc..56c3c7df 100644 --- a/src/input.c +++ b/src/input.c @@ -995,7 +995,7 @@ struct StreamFuncs fileFuncs = }; -StreamImpl *newSourceStreamFile( const char *name, FILE *file ) +StreamImpl *colm_impl_new_file( const char *name, FILE *file ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); initStreamImpl( ss, name ); @@ -1006,7 +1006,7 @@ StreamImpl *newSourceStreamFile( const char *name, FILE *file ) return ss; } -StreamImpl *newSourceStreamFd( const char *name, long fd ) +StreamImpl *colm_impl_new_fd( const char *name, long fd ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); initStreamImpl( ss, name ); @@ -1017,7 +1017,7 @@ StreamImpl *newSourceStreamFd( const char *name, long fd ) return ss; } -StreamImpl *newSourceStreamGeneric( const char *name ) +StreamImpl *colm_impl_new_generic( const char *name ) { StreamImpl *ss = (StreamImpl*)malloc(sizeof(StreamImpl)); initStreamImpl( ss, name ); @@ -1026,25 +1026,26 @@ StreamImpl *newSourceStreamGeneric( const char *name ) return ss; } -Stream *openStreamFile( Program *prg, char *name, FILE *file ) +Stream *colm_stream_new_struct( Program *prg ) { - StreamImpl *impl = newSourceStreamFile( name, file ); - - struct colm_stream *s = colm_stream_new_struct( prg ); - s->impl = impl; - return s; + size_t memsize = sizeof(struct colm_stream); + struct colm_stream *stream = (struct colm_stream*) malloc( memsize ); + memset( stream, 0, memsize ); + colm_struct_add( prg, (struct colm_struct *)stream ); + stream->id = STRUCT_INBUILT_ID; + return stream; } -Stream *openStreamFd( Program *prg, char *name, long fd ) +Stream *colm_stream_open_fd( Program *prg, char *name, long fd ) { - StreamImpl *impl = newSourceStreamFd( name, fd ); + StreamImpl *impl = colm_impl_new_fd( name, fd ); struct colm_stream *s = colm_stream_new_struct( prg ); s->impl = impl; return s; } -Stream *openFile( Program *prg, Tree *name, Tree *mode ) +Stream *colm_stream_open_file( Program *prg, Tree *name, Tree *mode ) { Head *headName = ((Str*)name)->value; Head *headMode = ((Str*)mode)->value; @@ -1067,15 +1068,17 @@ Stream *openFile( Program *prg, Tree *name, Tree *mode ) memcpy( fileName, stringData(headName), stringLength(headName) ); fileName[stringLength(headName)] = 0; FILE *file = fopen( fileName, fopenMode ); - if ( file != 0 ) - stream = openStreamFile( prg, fileName, file ); + if ( file != 0 ) { + stream = colm_stream_new_struct( prg ); + stream->impl = colm_impl_new_file( fileName, file ); + } return stream; } Stream *colm_stream_new( Program *prg ) { - StreamImpl *impl = newSourceStreamGeneric( "<internal>" ); + StreamImpl *impl = colm_impl_new_generic( "<internal>" ); struct colm_stream *stream = colm_stream_new_struct( prg ); stream->impl = impl; diff --git a/src/input.h b/src/input.h index 533389c3..89bfe4b1 100644 --- a/src/input.h +++ b/src/input.h @@ -162,11 +162,11 @@ struct _StreamImpl int consumed; }; -StreamImpl *newSourceStreamPat( const char *name, struct Pattern *pattern ); -StreamImpl *newSourceStreamCons( const char *name, struct Constructor *constructor ); -StreamImpl *newSourceStreamFile( const char *name, FILE *file ); -StreamImpl *newSourceStreamFd( const char *name, long fd ); -StreamImpl *newSourceStreamGeneric( const char *name ); +StreamImpl *colm_impl_new_pat( const char *name, struct Pattern *pattern ); +StreamImpl *colm_impl_new_cons( const char *name, struct Constructor *constructor ); +StreamImpl *colm_impl_new_file( const char *name, FILE *file ); +StreamImpl *colm_impl_new_fd( const char *name, long fd ); +StreamImpl *colm_impl_new_generic( const char *name ); void updatePosition( StreamImpl *inputStream, const char *data, long length ); void undoPosition( StreamImpl *inputStream, const char *data, long length ); diff --git a/src/struct.c b/src/struct.c index 8915ec2b..36264319 100644 --- a/src/struct.c +++ b/src/struct.c @@ -2,10 +2,12 @@ #include <colm/struct.h> #include "internal.h" +#include "bytecode.h" #include <stdlib.h> #include <string.h> #include <assert.h> +#include <stdbool.h> struct colm_tree *colm_get_global( Program *prg, long pos ) { @@ -94,16 +96,6 @@ Parser *colm_parser_new( Program *prg, GenericInfo *gi ) return parser; } -Stream *colm_stream_new_struct( Program *prg ) -{ - size_t memsize = sizeof(struct colm_stream); - struct colm_stream *stream = (struct colm_stream*) malloc( memsize ); - memset( stream, 0, memsize ); - colm_struct_add( prg, (struct colm_struct *)stream ); - stream->id = STRUCT_INBUILT_ID; - return stream; -} - void colm_map_destroy( Program *prg, Tree **sp, struct colm_struct *s ) { struct colm_map *map = (struct colm_map*) s; @@ -126,3 +118,35 @@ Map *colm_map_new( struct colm_program *prg ) map->id = STRUCT_INBUILT_ID; return map; } + +Struct *colm_construct_generic( Program *prg, long genericId ) +{ + GenericInfo *genericInfo = &prg->rtd->genericInfo[genericId]; + Struct *newGeneric = 0; + switch ( genericInfo->type ) { + case GEN_MAP_EL: + case GEN_LIST_EL: + break; + + case GEN_MAP: { + Map *map = colm_map_new( prg ); + map->genericInfo = genericInfo; + newGeneric = (Struct*) map; + break; + } + case GEN_LIST: { + List *list = colm_list_new( prg ); + list->genericInfo = genericInfo; + newGeneric = (Struct*) list; + break; + } + case GEN_PARSER: { + Parser *parser = colm_parser_new( prg, genericInfo ); + parser->input = colm_stream_new( prg ); + newGeneric = (Struct*) parser; + break; + } + } + + return newGeneric; +} diff --git a/src/struct.h b/src/struct.h index 7f0e10a9..0a6e1778 100644 --- a/src/struct.h +++ b/src/struct.h @@ -147,6 +147,8 @@ struct colm_struct *colm_map_el_get( struct colm_program *prg, struct colm_struct *colm_map_get( struct colm_program *prg, Map *map, Word genId, Word field ); +struct colm_struct *colm_construct_generic( struct colm_program *prg, long genericId ); + #define STRUCT_INBUILT_ID -1 #if defined(__cplusplus) diff --git a/src/synthesis.cc b/src/synthesis.cc index 3dc36f62..e720d631 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -625,9 +625,7 @@ bool LangVarRef::canTakeRef( Compiler *pd, VarRefLookup &lookup ) const * via a local and attributes. */ if ( lookup.inObject->type == ObjectDef::FrameType ) canTake = true; - else if ( isLocalRef() ) - { - cerr << "lastPtrInQual: " << lookup.lastPtrInQual << endl; + else if ( isLocalRef() ) { if ( lookup.lastPtrInQual < 0 && ! lookup.uniqueType->ptr() ) canTake = true; } @@ -961,44 +961,6 @@ Tree *splitTree( Program *prg, Tree *tree ) return tree; } -Tree *constructGeneric( Program *prg, long genericId ) -{ - GenericInfo *genericInfo = &prg->rtd->genericInfo[genericId]; - Tree *newGeneric = 0; - switch ( genericInfo->type ) { - case GEN_MAP: { - Map *map = colm_map_new( prg ); - map->genericInfo = genericInfo; - newGeneric = (Tree*) map; - break; - } - case GEN_MAP_EL: { - break; - } - case GEN_LIST: { - List *list = colm_list_new( prg ); - list->genericInfo = genericInfo; - newGeneric = (Tree*) list; - break; - } - case GEN_LIST_EL: { - break; - } - case GEN_PARSER: { - Parser *parser = colm_parser_new( prg, genericInfo ); - parser->input = (Tree*)colm_stream_new( prg ); - newGeneric = (Tree*) parser; - break; - } - default: - assert(false); - return 0; - } - - return newGeneric; -} - - /* We can't make recursive calls here since the tree we are freeing may be * very large. Need the VM stack. */ void treeFreeRec( Program *prg, Tree **sp, Tree *tree ) @@ -1097,15 +1059,6 @@ free_tree: break; } // case LEL_ID_STREAM: { -// Stream *stream = (Stream*)tree; -// clearSourceStream( prg, sp, stream->in ); -// if ( stream->in->file != 0 ) -// fclose( stream->in->file ); -// else if ( stream->in->fd >= 0 ) -// close( stream->in->fd ); -// free( stream->in ); -// streamFree( prg, stream ); -// break; // } default: { if ( tree->id != LEL_ID_IGNORE ) @@ -230,7 +230,6 @@ Tree *constructTree( struct colm_program *prg, Kid *kid, Tree **bindings, long pat ); Tree *constructObject( struct colm_program *prg, Kid *kid, Tree **bindings, long langElId ); -Tree *constructGeneric( struct colm_program *prg, long genericId ); Tree *constructToken( struct colm_program *prg, Tree **args, long nargs ); Object *newList2( struct colm_program *prg ); @@ -238,7 +237,7 @@ Object *newList2( struct colm_program *prg ); int testFalse( struct colm_program *prg, Tree *tree ); Tree *makeTree( struct colm_program *prg, Tree **args, long nargs ); Stream *openFile( struct colm_program *prg, Tree *name, Tree *mode ); -Stream *openStreamFd( struct colm_program *prg, char *name, long fd ); +Stream *colm_stream_open_fd( struct colm_program *prg, char *name, long fd ); Kid *copyIgnoreList( struct colm_program *prg, Kid *ignoreHeader ); Kid *copyKidList( struct colm_program *prg, Kid *kidList ); void streamFree( struct colm_program *prg, Stream *s ); |