lunajit/vm.lua

74 lines
1.1 KiB
Lua

local funcbc = require('jit.util').funcbc
function opcode(id, name, a, b, c, metamethod)
return {
id=id,
name=name,
a=a,
b=b,
c=c,
methametod=metamethod,
}
end
function gen_opcodes(tbl)
length = #tbl
res = {}
for i=1,length do
res[i] = i+1
end
return res
end
Mode = {
none = 0,
dst = 1,
base = 2,
var = 3,,
rbase = 4,
uv = 5,
lit = 6,
lits = 7,
pri = 8,
num = 9,
str = 10,
tab = 11,
func = 12,
jump = 13,
cdata = 14,
max = 15,
none = 15, -- same as max
}
Metamethod = {
index = 0,
newindex = 1,
gc = 2,
mode = 3,
eq = 4,
len = 5,
lt = 6,
le = 7,
concat = 8,
call = 9,
add = 10,
sub = 11,
mul = 12,
div = 13,
mod = 14,
pow = 15,
unm = 16,
metatable = 17,
tostring = 18,
}
Opcodes = gen_opcodes {
opcode(37, 'POW', Mode.dst, Mode.none, Mode.lits, Metamethod.none),
opcode(41, 'KSHORT', Mode.dst, Mode.var, Mode.var, Metamethod.pow),
}
print(Opcodes[1])
ins, m = funcbc(test1, 3) -- TODO: what is m?
print(ins)
print(m)