micropython/micropython — pull request #223 by pfalcon (2014-01-25 00:57:14+00:00)
Title: Draft: try to free parse tree after compilation

So, this would conclude series of "use explicit memory management during compilation phase" - with it, I get strictly bytecode buffer, code object and function object un-freed after compile - with simple expression at interactive prompt.

But it fails miserably on testsuite with double-free and plain segfaults. Double-free's hint that it's not a tree, but acyclic graph. But looking at some segfault, I saw:
~~~~
#2540 0x0804b5cf in parse_node_free_struct (pn_in=134747584) at ../py/parse.c:144
#2541 0x0804b5cf in parse_node_free_struct (pn_in=134746360) at ../py/parse.c:144
#2542 0x0804b5cf in parse_node_free_struct (pn_in=134747584) at ../py/parse.c:144
#2543 0x0804b5cf in parse_node_free_struct (pn_in=134746360) at ../py/parse.c:144
#2544 0x0804b5cf in parse_node_free_struct (pn_in=134747584) at ../py/parse.c:144
#2545 0x0804b5cf in parse_node_free_struct (pn_in=134746360) at ../py/parse.c:144
#2546 0x0804b5cf in parse_node_free_struct (pn_in=134747584) at ../py/parse.c:144
~~~~

So, it's not even acyclic sometimes, and loops until stack overflow. Damien, would you have ideas how to do that right quickly? (My idea is that some node kinds should be filtered regarding arg recursion, but digging for specifics is ... well, digging too deep ;-) ). Also, do you have an idea if that would clean up properly in case of various errors during lexing/parsing/compiling (like, is there a chance that some node may not link subtrees and they will be left separate, not reachable from result_stack[0]?)