summaryrefslogtreecommitdiff
path: root/src/program.c
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2016-03-09 18:12:18 +0100
committerAdrian Thurston <thurston@complang.org>2016-03-09 18:12:18 +0100
commit0814cc34b38b6c0667427577890b0803d7d835ab (patch)
tree9948c3fee6b288a3980e062075cc0641cba15dbe /src/program.c
parent977743c0de8c62930a468ebbce99cdfdb5e214e5 (diff)
downloadcolm-0814cc34b38b6c0667427577890b0803d7d835ab.tar.gz
manage file name allocations and allow them to be exported
File names used in locations need to live beyond a program delete, but allocating them when exporting locations is too costly. Instead manage them in the colm program and allow them to be exported so they can live beyond the colm program. Will do something similar with the token text.
Diffstat (limited to 'src/program.c')
-rw-r--r--src/program.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/program.c b/src/program.c
index d2f9b200..d941cb31 100644
--- a/src/program.c
+++ b/src/program.c
@@ -195,6 +195,9 @@ program_t *colm_new_program( struct colm_sections *rtd )
vm_init( prg );
rtd->init_need();
+
+ prg->stream_fns = malloc( sizeof(char*) * 1 );
+ prg->stream_fns[0] = 0;
return prg;
}
@@ -233,6 +236,13 @@ void colm_set_reduce_ctx( struct colm_program *prg, void *ctx )
prg->red_ctx = ctx;
}
+const char **colm_extract_fns( struct colm_program *prg )
+{
+ const char **fns = prg->stream_fns;
+ prg->stream_fns = 0;
+ return fns;
+}
+
int colm_delete_program( program_t *prg )
{
tree_t **sp = prg->stack_root;
@@ -281,6 +291,16 @@ int colm_delete_program( program_t *prg )
vm_clear( prg );
+ if ( prg->stream_fns ) {
+ char **ptr = prg->stream_fns;
+ while ( *ptr != 0 ) {
+ free( *ptr );
+ ptr += 1;
+ }
+
+ free( prg->stream_fns );
+ }
+
free( prg );
return exit_status;