LUA虚拟机的字节码怎么看?

https://the-ravi-programming-...

http://files.catwell.info/mis...

'A' : 8 bits
'B' : 9 bits
'C' : 9 bits
'Ax' : 26 bits ('A', 'B', and 'C' together)
'Bx' : 18 bits ('B' and 'C' together)
'sBx' : signed Bx

比如这段:

function y(...) print(...) end

1 [1] GETTABUP  0 0 -1  ; _ENV "print"
2 [1] VARARG    1 0     ; VARARG will set L->top
3 [1] CALL      0 0 1   ; B=0 so L->top set by previous instruction
4 [1] RETURN    0 1

每条指令后面的数字(2个或者3个)表示什么意思?

E:\Project\ZhScheme\lua>luac -l luac.out

main <test.lua:0,0> (6 instructions, 24 bytes at 004784F8)
0+ params, 2 slots, 0 upvalues, 0 locals, 4 constants, 0 functions
        1       [1]     LOADK           0 -2    ; 18
        2       [1]     SETGLOBAL       0 -1    ; a
        3       [2]     GETGLOBAL       0 -3    ; print
        4       [2]     LOADK           1 -4    ; "hello world"
        5       [2]     CALL            0 2 1
        6       [2]     RETURN          0 1
阅读 1.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进