lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Running Lua 5.2(alpha) this:

      b = true
      c = false
      x = (7 or 2) and true or c
      y = (8 or 2) and b or c
      print(x,"--",y) --> 7 -- true !!!!

disassembles to

 1 [1] SETTABUP  0 -1 -2 ; _ENV "b" true
 2 [2] SETTABUP  0 -3 -4 ; _ENV "c" false
 3 [3] LOADK     0 -6 ; 7
 4 [3] TEST      0 0 1
 5 [3] JMP       5 ; to 11
 6 [3] JMP       3 ; to 10
 7 [3] GETTABUP  0 0 -3 ; _ENV "c"
 8 [3] JMP       2 ; to 11
 9 [3] LOADBOOL  0 0 1
 10 [3] LOADBOOL  0 1 0
 11 [3] SETTABUP  0 -5 0 ; _ENV "x"
 12 [4] LOADK     0 -8 ; 8
 13 [4] TEST      0 0 1
 14 [4] JMP       0 ; to 15
 15 [4] GETTABUP  0 0 -1 ; _ENV "b"
 16 [4] TEST      0 0 1
 17 [4] JMP       1 ; to 19
 18 [4] GETTABUP  0 0 -3 ; _ENV "c"
 19 [4] SETTABUP  0 -7 0 ; _ENV "y"
 20 [5] GETTABUP  0 0 -9 ; _ENV "print"
 21 [5] GETTABUP  1 0 -5 ; _ENV "x"
 22 [5] LOADK     2 -10 ; "--"
 23 [5] GETTABUP  3 0 -7 ; _ENV "y"
 24 [5] CALL      0 4 1
 25 [5] RETURN    0 1

Apart from the fact that the logic must be wrong somewhere
before line 11, I note that at line 14 there is a JMP 0, a NOP.
Would it be difficult to eliminate (TEST x x x,JMP 0) pairs?

-- 
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/