diff options
author | Adrian Thurston <thurston@complang.org> | 2014-12-26 15:42:57 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2014-12-26 15:42:57 -0500 |
commit | 7709fdb5aa27cdc55dbe999b2ed5ba995648dc60 (patch) | |
tree | bbc0f10171db3eeae56c4a8f061830e15b9c05de /src/struct.c | |
parent | aa7f56241b5bc4ecc77cff606122ba51654e18a6 (diff) | |
download | colm-7709fdb5aa27cdc55dbe999b2ed5ba995648dc60.tar.gz |
started converting stream to object type
Diffstat (limited to 'src/struct.c')
-rw-r--r-- | src/struct.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/struct.c b/src/struct.c index dd56f1a0..b05276be 100644 --- a/src/struct.c +++ b/src/struct.c @@ -9,13 +9,11 @@ struct colm_tree *colm_get_global( Program *prg, long pos ) return colm_struct_get_field( prg->global, pos ); } -struct colm_struct *colm_struct_new( Program *prg, int id ) +static struct colm_struct *colm_struct_new_size( Program *prg, int size ) { - int structSize = prg->rtd->selInfo[id].size; - size_t memsize = sizeof(struct colm_struct) + ( sizeof(Tree*) * structSize ); + size_t memsize = sizeof(struct colm_struct) + ( sizeof(Tree*) * size ); struct colm_struct *item = (struct colm_struct*) malloc( memsize ); memset( item, 0, memsize ); - item->id = id; if ( prg->heap.head == 0 ) { prg->heap.head = prg->heap.tail = item; @@ -31,13 +29,29 @@ struct colm_struct *colm_struct_new( Program *prg, int id ) return item; } +struct colm_struct *colm_struct_new( Program *prg, int id ) +{ + struct colm_struct *s = colm_struct_new_size( prg, prg->rtd->selInfo[id].size ); + s->id = id; + return s; +} + +struct colm_struct *colm_struct_inbuilt( Program *prg, int size, void *destructor ) +{ + struct colm_struct *s = colm_struct_new_size( prg, size ); + s->id = -1; + return s; +} + void colm_struct_delete( Program *prg, Tree **sp, struct colm_struct *el ) { - short *t = prg->rtd->selInfo[el->id].trees; - int i, len = prg->rtd->selInfo[el->id].treesLen; - for ( i = 0; i < len; i++ ) { - Tree *tree = colm_struct_get_field( el, t[i] ); - treeDownref( prg, sp, tree ); + if ( el->id >= 0 ) { + short *t = prg->rtd->selInfo[el->id].trees; + int i, len = prg->rtd->selInfo[el->id].treesLen; + for ( i = 0; i < len; i++ ) { + Tree *tree = colm_struct_get_field( el, t[i] ); + treeDownref( prg, sp, tree ); + } } free( el ); } |