[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "or" shortcut does not work - but why?
- From: Andreas Rozek <Rozek@...>
- Date: Mon, 18 Jun 2007 20:56:32 +0200
Good evening!
>> I'll try to look at the TEST instruction, as suggested by Nick.
>
>A particularity of this instruction is that it assumes that "boolean
>expressions" in C (tests, && and ||) always result in 1 for true
(instead
>of any non-zero value). Of course ANSI C ensures that, but maybe
>the compiler is doing something wrong there?
I guess, the relevant code (in lvm.c) looks like this:
case OP_TEST: {
printf("TEST: l_isfalse = %d, GETARG_C = %d\n",l_isfalse(ra),GETARG_C
(i));
if (l_isfalse(ra) != GETARG_C(i))
dojump(L, pc, GETARG_sBx(*pc));
pc++;
continue;
}
Well, I added a simple "printf" for testing purposes, of course
The output of that printf statement is as follows:
TEST: l_isfalse = 1, GETARG_C = 1
Comparing this with the opcodes produced by lua:
0041 02000000 [01] loadbool 0 0 0 ; false
0045 07000000 [02] setglobal 0 0 ; Result
0049 05000000 [03] getglobal 0 0 ; Result
004D 1A400000 [04] test 0 1 ; to [6] if false
0051 16000080 [05] jmp 1 ; to [7]
0055 01400000 [06] loadk 0 1 ; "anything else"
0059 07000000 [07] setglobal 0 0 ; Result
...
I'm a bit unsure how to interpret these values:
- l_isfalse = 1 - looks ok, doesn't it?
- GETARG_C = 1 - is that correct? (shouldn't it be 0?)
lopcodes.h defines GETARG_C as follows:
#define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
Perhaps I have to look deeper in that direction!?
Kind regards,
Andreas Rozek Phone: ++49 (7031) 436 5784
Brunnenstraße 30/2 Mobile: ++49 (151) 172 879 18
D-71032 Böblingen EMail: Andreas.Rozek@gmx.de
Germany URL: http://www.Andreas-Rozek.de