summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler.h1
-rw-r--r--src/input.c2
-rw-r--r--src/list.c2
-rw-r--r--src/pdabuild.cc8
-rw-r--r--src/pdacodegen.cc1
-rw-r--r--src/program.h1
-rw-r--r--src/struct.c24
-rw-r--r--src/struct.h2
8 files changed, 26 insertions, 15 deletions
diff --git a/src/compiler.h b/src/compiler.h
index cf23bc9c..085fdd1d 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -907,6 +907,7 @@ struct Compiler
int nextLelId;
int firstNonTermId;
+ int structInbuiltId;
LangEl **langElIndex;
PdaState *actionDestState;
diff --git a/src/input.c b/src/input.c
index 5ae2a78d..cb5522c3 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1113,7 +1113,7 @@ stream_t *colm_stream_new_struct( program_t *prg )
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;
+ stream->id = prg->rtd->struct_inbuilt_id;
stream->destructor = &colm_stream_destroy;
return stream;
}
diff --git a/src/list.c b/src/list.c
index ebcc4618..245e3331 100644
--- a/src/list.c
+++ b/src/list.c
@@ -205,7 +205,7 @@ list_t *colm_list_new( struct colm_program *prg )
struct colm_list *list = (struct colm_list*) malloc( memsize );
memset( list, 0, memsize );
colm_struct_add( prg, (struct colm_struct *)list );
- list->id = STRUCT_INBUILT_ID;
+ list->id = prg->rtd->struct_inbuilt_id;
list->destructor = &colm_list_destroy;
return list;
}
diff --git a/src/pdabuild.cc b/src/pdabuild.cc
index 6ab45471..2ce1cecb 100644
--- a/src/pdabuild.cc
+++ b/src/pdabuild.cc
@@ -242,9 +242,14 @@ void Compiler::makeLangElIds()
void Compiler::makeStructElIds()
{
- int nextId = 0;
+ /* Start at the next lang el id and go up from there. Using disjoint sets
+ * allows us to verify that a tree is a tree and struct is a struct because
+ * the ID field is at the same offset. */
+ int nextId = nextLelId;
for ( StructElList::Iter sel = structEls; sel.lte(); sel++ )
sel->id = nextId++;
+
+ structInbuiltId = nextId;
}
void Compiler::refNameSpace( LangEl *lel, Namespace *nspace )
@@ -1709,6 +1714,7 @@ void Compiler::makeRuntimeData()
runtimeData->no_token_id = noTokenLangEl->id;
runtimeData->global_id = globalSel->id;
runtimeData->argv_el_id = argvElSel->id;
+ runtimeData->struct_inbuilt_id = structInbuiltId;
runtimeData->fsm_execute = &internalFsmExecute;
runtimeData->send_named_lang_el = &internalSendNamedLangEl;
diff --git a/src/pdacodegen.cc b/src/pdacodegen.cc
index ef1c1ced..2e08ee3e 100644
--- a/src/pdacodegen.cc
+++ b/src/pdacodegen.cc
@@ -510,6 +510,7 @@ void PdaCodeGen::writeRuntimeData( colm_sections *runtimeData, struct pda_tables
" " << runtimeData->no_token_id << ",\n"
" " << runtimeData->global_id << ",\n"
" " << runtimeData->argv_el_id << ",\n"
+ " " << runtimeData->struct_inbuilt_id << ",\n"
" &fsm_execute,\n"
" &sendNamedLangEl,\n"
" &initBindings,\n"
diff --git a/src/program.h b/src/program.h
index 8138c393..e5cfbeea 100644
--- a/src/program.h
+++ b/src/program.h
@@ -98,6 +98,7 @@ struct colm_sections
long no_token_id;
long global_id;
long argv_el_id;
+ long struct_inbuilt_id;
void (*fsm_execute)( struct pda_run *pda_run, struct stream_impl *input_stream );
void (*send_named_lang_el)( struct colm_program *prg, tree_t **tree,
diff --git a/src/struct.c b/src/struct.c
index 11b3e2ec..0a6fd781 100644
--- a/src/struct.c
+++ b/src/struct.c
@@ -61,24 +61,28 @@ struct colm_struct *colm_struct_new_size( program_t *prg, int size )
struct colm_struct *colm_struct_new( program_t *prg, int id )
{
- struct colm_struct *s = colm_struct_new_size( prg, prg->rtd->sel_info[id].size );
+ struct colm_struct *s = colm_struct_new_size( prg, prg->rtd->sel_info[id - prg->rtd->num_lang_els].size );
s->id = id;
return s;
}
+struct struct_el_info *colm_sel_info( program_t *prg, int id )
+{
+ return &prg->rtd->sel_info[id - prg->rtd->num_lang_els];
+}
+
void colm_struct_delete( program_t *prg, tree_t **sp, struct colm_struct *el )
{
- if ( el->id == STRUCT_INBUILT_ID ) {
+ if ( el->id == prg->rtd->struct_inbuilt_id ) {
colm_destructor_t destructor = ((struct colm_inbuilt*)el)->destructor;
if ( destructor != 0 )
(*destructor)( prg, sp, el );
}
-
- if ( el->id >= 0 ) {
- short *t = prg->rtd->sel_info[el->id].trees;
- int i, len = prg->rtd->sel_info[el->id].trees_len;
- for ( i = 0; i < len; i++ ) {
- tree_t *tree = colm_struct_get_field( el, tree_t*, t[i] );
+ else {
+ int tree_i;
+ struct struct_el_info *sel = colm_sel_info( prg, el->id );
+ for ( tree_i = 0; tree_i < sel->trees_len; tree_i++ ) {
+ tree_t *tree = colm_struct_get_field( el, tree_t*, sel->trees[tree_i] );
colm_tree_downref( prg, sp, tree );
}
}
@@ -110,7 +114,7 @@ parser_t *colm_parser_new( program_t *prg, struct generic_info *gi, int reducer
memset( parser, 0, memsize );
colm_struct_add( prg, (struct colm_struct*) parser );
- parser->id = STRUCT_INBUILT_ID;
+ parser->id = prg->rtd->struct_inbuilt_id;
parser->destructor = &colm_parser_destroy;
parser->pda_run = pda_run;
@@ -136,7 +140,7 @@ map_t *colm_map_new( struct colm_program *prg )
struct colm_map *map = (struct colm_map*) malloc( memsize );
memset( map, 0, memsize );
colm_struct_add( prg, (struct colm_struct *)map );
- map->id = STRUCT_INBUILT_ID;
+ map->id = prg->rtd->struct_inbuilt_id;
return map;
}
diff --git a/src/struct.h b/src/struct.h
index ccc8b442..bafbfb64 100644
--- a/src/struct.h
+++ b/src/struct.h
@@ -173,8 +173,6 @@ struct colm_struct *colm_map_get( struct colm_program *prg, map_t *map,
struct colm_struct *colm_construct_generic( struct colm_program *prg, long generic_id );
struct colm_struct *colm_construct_reducer( struct colm_program *prg, long generic_id, int reducer_id );
-#define STRUCT_INBUILT_ID -1
-
#if defined(__cplusplus)
}
#endif