[pure-lang-svn] SF.net SVN: pure-lang: [92] pure/trunk/runtime.cc
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-17 12:39:04
|
Revision: 92 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=92&view=rev Author: agraef Date: 2008-05-17 05:39:04 -0700 (Sat, 17 May 2008) Log Message: ----------- Add code for debugging expression allocations. Modified Paths: -------------- pure/trunk/runtime.cc Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-05-17 06:39:30 UTC (rev 91) +++ pure/trunk/runtime.cc 2008-05-17 12:39:04 UTC (rev 92) @@ -19,6 +19,26 @@ >= interpreter::stackmax) \ pure_throw(stack_exception()) +// Debug expression allocations. +#if DEBUG>2 +set<pure_expr*> mem_allocations; +#define MEMDEBUG_NEW(x) mem_allocations.insert(x); \ + cerr << "NEW: " << (void*)x << ": " << x << endl; +#define MEMDEBUG_FREE(x) mem_allocations.erase(x); \ + cerr << "FREE: " << (void*)x << ": " << x << endl; +#define MEMDEBUG_INIT mem_allocations.clear(); +#define MEMDEBUG_SUMMARY cerr << "SUMMARY:\n"; \ + for (set<pure_expr*>::iterator x = mem_allocations.begin(); \ + x != mem_allocations.end(); x++) \ + cerr << (void*)(*x) << ": " << (*x) << endl; \ + mem_allocations.clear(); +#else +#define MEMDEBUG_NEW(x) +#define MEMDEBUG_FREE(x) +#define MEMDEBUG_INIT +#define MEMDEBUG_SUMMARY +#endif + // Expression pointers are allocated in larger chunks for better performance. // NOTE: Only internal fields get initialized by new_expr(), the remaining // fields *must* be initialized as appropriate by the caller. @@ -49,6 +69,7 @@ interpreter& interp = *interpreter::g_interp; x->xp = interp.exps; interp.exps = x; + MEMDEBUG_FREE(x) } static inline @@ -209,6 +230,7 @@ } va_end(ap); } + MEMDEBUG_NEW(x) return x; } @@ -220,6 +242,7 @@ pure_expr *x = new_expr(); x->tag = tag; x->data.clos = 0; + MEMDEBUG_NEW(x) return x; } @@ -229,6 +252,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::INT; x->data.i = i; + MEMDEBUG_NEW(x) return x; } @@ -253,6 +277,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::BIGINT; make_bigint(x->data.z, size, limbs); + MEMDEBUG_NEW(x) return x; } @@ -262,6 +287,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::BIGINT; mpz_init_set(x->data.z, z); + MEMDEBUG_NEW(x) return x; } @@ -271,6 +297,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::DBL; x->data.d = d; + MEMDEBUG_NEW(x) return x; } @@ -280,6 +307,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::PTR; x->data.p = p; + MEMDEBUG_NEW(x) return x; } @@ -290,6 +318,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::STR; x->data.s = strdup(s); + MEMDEBUG_NEW(x) return x; } @@ -300,6 +329,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::STR; x->data.s = toutf8(s, 0); + MEMDEBUG_NEW(x) return x; } @@ -310,6 +340,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::STR; x->data.s = s; + MEMDEBUG_NEW(x) return x; } @@ -438,6 +469,7 @@ f->tag = EXPR::APP; f->data.x[0] = x; f->data.x[1] = y; + MEMDEBUG_NEW(f) return f; } } @@ -545,6 +577,7 @@ #if DEBUG>1 cerr << "pure_invoke: calling " << f << endl; #endif + MEMDEBUG_INIT // Push an exception. pure_exception ex; ex.e = 0; interp.estk.push_front(ex); // Call the function now. Catch exceptions generated by the runtime. @@ -559,11 +592,13 @@ if (tmps != e) pure_freenew(tmps); tmps = next; } + MEMDEBUG_SUMMARY return 0; } else { pure_expr *res = fp(); // normal return interp.estk.pop_front(); + MEMDEBUG_SUMMARY #if DEBUG>1 pure_expr *tmps = interp.tmps; while (tmps) { @@ -958,6 +993,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::STR; x->data.s = buf; + MEMDEBUG_NEW(x) return x; } @@ -1004,6 +1040,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::STR; x->data.s = buf; + MEMDEBUG_NEW(x) return x; } @@ -1018,6 +1055,7 @@ pure_expr *x = new_expr(); x->tag = EXPR::STR; x->data.s = buf; + MEMDEBUG_NEW(x) return x; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |