[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: comment error about OP_VARARG in lopcodes.h
- From: VirusCamp <viruscamp@...>
- Date: Fri, 23 Oct 2009 21:51:16 +0800
>a,b,c = ...
; source chunk: (interactive mode)
; x86 standard (32-bit, little endian, doubles)
; function [0] definition (level 1)
; 0 upvalues, 0 params, 3 stacks
.function 0 0 2 3
.const "a" ; 0
.const "b" ; 1
.const "c" ; 2
[1] vararg 0 4
[2] setglobal 2 2 ; c := R2
[3] setglobal 1 1 ; b := R1
[4] setglobal 0 0 ; a := R0
[5] return 0 1
; end of function
So in VARARG, A=0, B =4 ,is that right ?
R(A),....R(A+B-1) = ...
can be translated to
R0,R1,R2,R3 = ...
2009/10/23 KHMan <keinhong@gmail.com>:
> VirusCamp wrote:
>>
>> I'm working on luadec, but got confused about OP_VARARG in lua-5.1.4.
>> I think the comment is wrong, that should be R(A), R(A+1), ...,
>> R(A+B-2) = vararg
>>
>> lopcodes.h line 210
>> OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
>>
>>
>> lvm.c line 751
>> case OP_VARARG: {
>> int b = GETARG_B(i) - 1;
>> ..........
>> for (j = 0; j < b; j++) {
>
> Nothing wrong there. You can plug in some numbers in order to 'see' the
> indices and ranges better.
>
> GETARG_B(i)'s zero value is taken by multiple return mode, since b is -1
> when GETARG_B(i) == 0 and -1 is LUA_MULTRET in the test.
>
> When GETARG_B(i) is 1, b = 0 and the loop iterates once only, for one value.
> So, A+B-1 = A+1-1 = A.
>
> I think perhaps you have confused b with B in the comments. B is
> GETARG_B(i).
>
> --
> Cheers,
> Kein-Hong Man (esq.)
> Kuala Lumpur, Malaysia
>
>