From 04ec9b4f1b887852f06b47390a23d5985cb0c6df Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 26 Apr 2020 21:03:59 -0500 Subject: [PATCH] Stupid bug fix --- app.lua | 9 +++++---- src/ui/components.lua | 21 ++++++++++----------- src/wasm/analyze.lua | 7 ++++++- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app.lua b/app.lua index b79f72d..8b34609 100644 --- a/app.lua +++ b/app.lua @@ -60,12 +60,13 @@ function open_file(path) ui.fire_propagating_event(globals.ui.function_blocks_container, "dummy") local i = 0 - for _, func in ipairs(globals.wasm_module.funcs) do + local funcs = globals.wasm_module.funcs + while globals.wasm_module.funcs[i] do ui.insert_child( globals.ui.function_blocks_container, - with(ui.make_element("function_block", func, globals.wasm_module)) { - rect = Rectangle(math.random() * 1000, math.random() * 1000, 400, 400); - layer = #globals.wasm_module.funcs - i + with(ui.make_element("function_block", funcs[i], globals.wasm_module)) { + rect = Rectangle(math.random() * 5000, math.random() * 5000, 400, 400); + layer = #funcs - i }) i = i + 1 diff --git a/src/ui/components.lua b/src/ui/components.lua index 92065a9..7471cf7 100644 --- a/src/ui/components.lua +++ b/src/ui/components.lua @@ -431,12 +431,9 @@ function function_ref_lines:init() local func_blocks = globals.ui.function_blocks_container.children local funcs = {} for _, f in ipairs(func_blocks) do - print(f.func.funcidx - 1) - funcs[f.func.funcidx - 1] = f + funcs[f.func.funcidx] = f end - print "------------" - self.arrows = {} for _, from in ipairs(func_blocks) do if from.func.callees then @@ -447,7 +444,7 @@ function function_ref_lines:init() if from.func.callers then for _, to in ipairs(from.func.callers) do - table.insert(self.arrows, { from = funcs[to - 1]; to = from; color = COLORS.secondary_dark }) + table.insert(self.arrows, { from = funcs[to]; to = from; color = COLORS.secondary_dark }) end end end @@ -455,12 +452,14 @@ end function function_ref_lines:predraw() for _, arr in ipairs(self.arrows) do - local from = arr.from.rect - local to = arr.to.rect - love.graphics.setColor(arr.color) - draw_arrow( - from.x + from.w / 2, from.y + from.h / 2, - to.x + to.w / 2, to.y + to.h / 2) + if arr.from and arr.to then + local from = arr.from.rect + local to = arr.to.rect + love.graphics.setColor(arr.color) + draw_arrow( + from.x + from.w / 2, from.y + from.h / 2, + to.x + to.w / 2, to.y + to.h / 2) + end end end diff --git a/src/wasm/analyze.lua b/src/wasm/analyze.lua index 52fe537..829f965 100644 --- a/src/wasm/analyze.lua +++ b/src/wasm/analyze.lua @@ -1,4 +1,9 @@ -import {} +import { + pprint = "lualib.pprint"; +} + +-- instr.x is 0 indexed +-- funcidx is 1 indexed function add_function_relations(wasm_funcs) function func_rel_helper(callees, instrs) -- 2.25.1