diff --git a/constants.lua b/constants.lua index d7e72f2..fa7b02a 100644 --- a/constants.lua +++ b/constants.lua @@ -66,12 +66,12 @@ constants.opcodes = { OP_I32_NE = 0x47, OP_I32_LT_S = 0x48, OP_I32_LT_U = 0x49, - OP_I32_GT_S = 0x50, - OP_I32_GT_U = 0x51, - OP_I32_LE_S = 0x52, - OP_I32_LE_U = 0x53, - OP_I32_GE_S = 0x54, - OP_I32_GE_U = 0x55, + OP_I32_GT_S = 0x4A, + OP_I32_GT_U = 0x4B, + OP_I32_LE_S = 0x4C, + OP_I32_LE_U = 0x4D, + OP_I32_GE_S = 0x4E, + OP_I32_GE_U = 0x4F, -- i64 comparisons OP_I64_EQZ = 0x50, OP_I64_EQ = 0x51, @@ -321,6 +321,8 @@ constants.ilengths = { [c.OP_I32_GT_U] = 1, [c.OP_I32_LE_S] = 1, [c.OP_I32_LE_U] = 1, + [c.OP_I32_GE_S] = 1, + [c.OP_I32_GE_U] = 1, -- i64 comparisons [c.OP_I64_EQZ] = 1, [c.OP_I64_EQ] = 1, diff --git a/wasmlib.lua b/wasmlib.lua index 0b4de4f..62b34b7 100644 --- a/wasmlib.lua +++ b/wasmlib.lua @@ -8,6 +8,10 @@ local intutil = require("intutil") local fileutil = require("fileutil") local strutil = require("strutil") +local function trace(...) + if wasmlib.TRACING then print(...) end +end + wasmlib.VM = { numImportedFuncs = 0, stack = {}, @@ -332,7 +336,7 @@ local function findMatchingEndOrElse(body, i, depth) local length = constants.ilengths[opcode] if length == 0 then if constants.blockOpcodes[opcode] ~= nil then - i = findMatchingEndOrElse(body, i + 1, depth + 1) + (depth > 0 and 1 or 0) + i = findMatchingEndOrElse(body, i + 2, depth + 1) + (depth > 0 and 1 or 0) elseif opcode == constants.opcodes.OP_ELSE then i = i + 1 end @@ -422,6 +426,8 @@ function wasmlib.VM:step() end local opcode = self:nextArg() + trace(self:curFrame().pc,opcode,"###",table.unpack(self.stack)) + trace(#self.labelStack,"---",table.unpack(self.labelStack)) local c = constants.opcodes local optable = {