From 4b34db513bf93b1a425fb7567d220ba751092b17 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 10 Jun 2015 10:48:56 +0200 Subject: Clear up unused frames --- src/sc_interp.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/sc_interp.c') diff --git a/src/sc_interp.c b/src/sc_interp.c index e1a5df7..86e2329 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -811,8 +811,6 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) struct frame *fr = sc_block_frame(bl); - renew_frame(fr); - if ( fr == NULL ) { fr = add_subframe(sc_interp_get_frame(scin)); sc_block_set_frame(bl, fr); @@ -827,6 +825,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) fprintf(stderr, "Failed to add frame.\n"); return 1; } + fr->visited = 1; parse_frame_options(fr, sc_interp_get_frame(scin), options); @@ -897,6 +896,27 @@ static void run_macro_contents(SCInterpreter *scin) } +static void delete_unused_subframes(struct frame *fr) +{ + int i; + int done = 1; + + do { + printf("checking %i children of %p\n", fr->num_children, fr); + for ( i=0; inum_children; i++ ) { + if ( !fr->children[i]->visited ) { + delete_subframe(fr, fr->children[i]); + done = 0; + printf("deleting %p\n", fr->children[i]); + break; + } else { + delete_unused_subframes(fr->children[i]); + } + } + } while ( !done ); +} + + int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) { //printf("Running this --------->\n"); @@ -975,6 +995,8 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) } + delete_unused_subframes(sc_interp_get_frame(scin)); + return 0; } -- cgit v1.2.3