about summary refs log tree commit diff stats
path: root/src/lua.c
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-12-17 22:20:46 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-17 22:23:18 -0800
commit42b1bd842cd693f034c97b4644c9f28146fc489d (patch)
tree7b9e8bcf0aad13aae0f8147a549eb83f8f4aec68 /src/lua.c
parentc12ba48a630474e0d53ead2770bd1887463c5915 (diff)
downloadteliva-42b1bd842cd693f034c97b4644c9f28146fc489d.tar.gz
keep tests from messing up big picture
Diffstat (limited to 'src/lua.c')
-rw-r--r--src/lua.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lua.c b/src/lua.c
index d95ac99..4c0691a 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -361,6 +361,23 @@ int run_tests(lua_State *L) {
 }
 
 
+void clear_call_graph(lua_State *L) {
+  int oldtop = lua_gettop(L);
+  luaL_newmetatable(L, "__teliva_call_graph_depth");
+  int cgt = lua_gettop(L);
+  lua_pushnil(L);
+  while (lua_next(L, cgt) != 0) {
+    lua_pop(L, 1);  /* old value */
+    lua_pushvalue(L, -1);  /* duplicate key */
+    lua_pushnil(L);  /* new value */
+    lua_settable(L, cgt);
+    /* one copy of key left for lua_next */
+  }
+  lua_pop(L, 1);
+  assert(lua_gettop(L) == oldtop);
+}
+
+
 char *Image_name = NULL;
 extern void load_tlv (lua_State *L, char *filename);
 static int handle_image (lua_State *L, char **argv, int n) {
@@ -375,6 +392,8 @@ static int handle_image (lua_State *L, char **argv, int n) {
   if (status != 0) return 0;
   status = run_tests(L);
   if (status != 0) return report_in_developer_mode(L, status);
+  /* clear callgraph stats from running tests */
+  clear_call_graph(L);
   /* call main() */
   lua_getglobal(L, "main");
   status = docall(L, 0, 1);