lua-users home
lua-l archive

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



On 16/06/2007, at 9:20 PM, Andreas Rozek wrote:

If I change the second line to

  Result = false or "anything else";

then I get the expected output.


Here's an interesting thing. If I do luac on that modified version, the test is optimized away:

$ luac -l -

local Result = false;  -- you could also use "nil" here
    Result = false or "anything else";
  io.stdout:write("Result = '"..tostring(Result).."'");


main <stdin:0,0> (13 instructions, 52 bytes at 0x805d190)
0+ params, 6 slots, 0 upvalues, 1 local, 7 constants, 0 functions
        1       [1]     LOADBOOL        0 0 0
        2       [2]     LOADK           0 -1    ; "anything else"
        3       [3]     GETGLOBAL       1 -2    ; io
        4       [3]     GETTABLE        1 1 -3  ; "stdout"
        5       [3]     SELF            1 1 -4  ; "write"
        6       [3]     LOADK           3 -5    ; "Result = '"
        7       [3]     GETGLOBAL       4 -6    ; tostring
        8       [3]     MOVE            5 0
        9       [3]     CALL            4 2 2
        10      [3]     LOADK           5 -7    ; "'"
        11      [3]     CONCAT          3 3 5
        12      [3]     CALL            1 3 1
        13      [3]     RETURN          0 1

Compare this to the previous output I posted. The TEST and JMP are no longer there. Thus this tends to point the finger at the TEST instruction. It is not that it is successfully doing an "or" with a literal "false" - it is not doing an "or" at all.

- Nick