Stupid bug fix
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 27 Apr 2020 02:03:59 +0000 (21:03 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 27 Apr 2020 02:03:59 +0000 (21:03 -0500)
app.lua
src/ui/components.lua
src/wasm/analyze.lua

diff --git a/app.lua b/app.lua
index b79f72d5ac8b90e7daa2ad909b03c6a2e887bea2..8b34609978ae9137e88cd55e1f5477e71b8ba5f5 100644 (file)
--- 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
index 92065a981600d817e28621e420489fca3b01b0ed..7471cf74ab629b7b5e9a1676f1ad428e314c1ec2 100644 (file)
@@ -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
 
index 52fe537580de9449ecbeebe3c64af49ab5ca0d0b..829f965042ee484449427db2dd60b3483923cd51 100644 (file)
@@ -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)