Something went wrong. Try again.
quick and dirty pure lua webassembly interpreter
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105local intutil = {}
function intutil.fromle16(tab, idx) local n = tab[idx] n = n | tab[idx+1] << 8 return nend
function intutil.tole16(tab, idx, n) tab[idx] = n & 0xFF tab[idx+1] = (n >> 8) & 0xFFend
function intutil.fromle32(tab, idx) local n = tab[idx] n = n | tab[idx+1] << 8 n = n | tab[idx+2] << 16 n = n | tab[idx+3] << 24 return nend
function intutil.tole32(tab, idx, n) tab[idx] = n & 0xFF tab[idx+1] = (n >> 8) & 0xFF tab[idx+2] = (n >> 16) & 0xFF tab[idx+3] = (n >> 24) & 0xFFend
function intutil.fromle64(tab, idx) local n = tab[idx] n = n | tab[idx+1] << 8 n = n | tab[idx+2] << 16 n = n | tab[idx+3] << 24 n = n | tab[idx+4] << 32 n = n | tab[idx+5] << 40 n = n | tab[idx+6] << 48 n = n | tab[idx+7] << 56 return nend
function intutil.tole64(tab, idx, n) tab[idx] = n & 0xFF tab[idx+1] = (n >> 8) & 0xFF tab[idx+2] = (n >> 16) & 0xFF tab[idx+3] = (n >> 24) & 0xFF tab[idx+4] = (n >> 32) & 0xFF tab[idx+5] = (n >> 40) & 0xFF tab[idx+6] = (n >> 48) & 0xFF tab[idx+7] = (n >> 56) & 0xFFend
function intutil.signexti32(n) if (n & 0x80000000) ~= 0 then n = n | 0xFFFFFFFF00000000 end return nend
function intutil.signexti16(n) if (n & 0x8000) ~= 0 then n = n | 0xFFFFFFFFFFFF0000 end return nend
function intutil.signexti8(n) if (n & 0x80) ~= 0 then n = n | 0xFFFFFFFFFFFFFF00 end return nend
function intutil.fromuleb128(tab, idx) local result = 0 local shift = 0 local len = 0 repeat local byte = tab[idx+len] result = result | ((byte & 0x7F) << shift) shift = shift + 7 len = len + 1 until (byte & 0x80) == 0 return len, resultend
function intutil.fromsleb128(tab, idx, bits) bits = bits or 64 local result = 0 local shift = 0 local len = 0
repeat local byte = tab[idx+len] result = result | ((byte & 0x7F) << shift) shift = shift + 7 len = len + 1 until (byte & 0x80) == 0
if (shift < bits) and ((tab[idx+len-1] & 0x40) ~= 0) then result = result | (((1 << bits) - 1) << shift) end return len, result & ((1 << bits) - 1)end
return intutil