A strange error found (x^y == x)

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

A strange error found (x^y == x)

Long Z
HW: STM32F107RCT6 (ARM Cortex M3)
OS: MadOS
I port lua to a RTOS, and then found a strange error :
* math.pow(2, 2) result 4.0 BUT 2^2 result 2.
* After some test, I found x^y result x always.
* I used v5.4.0, v5.3.5 and v5.1.5 for testing, and got the same result.
Here is my luaconfig.h used in v5.4.0.


luaconf.h (28K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

Joseph C. Sible
On Sat, Jul 4, 2020 at 3:01 PM Long Z <[hidden email]> wrote:
>
> HW: STM32F107RCT6 (ARM Cortex M3)
> OS: MadOS
> I port lua to a RTOS, and then found a strange error :
> * math.pow(2, 2) result 4.0 BUT 2^2 result 2.
> * After some test, I found x^y result x always.
> * I used v5.4.0, v5.3.5 and v5.1.5 for testing, and got the same result.
> Here is my luaconfig.h used in v5.4.0.
>

Here's some troubleshooting ideas/questions:

* Are you running the Lua source code on the STM32, or are you
compiling it somewhere else and just running the bytecode there? If
the latter, does the former work any better?
* If you stub out the whole constfolding function in src/lcode.c,
replacing the entire body with "return 0;", does anything change?
* If you do "function mypow(x, y) return x ^ y end" and then call
"mypow(2, 2)", what does it return?
* If you get the numbers at runtime instead of hardcoding them in the
Lua source, does anything change?

Joseph C. Sible
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

Long Z
The Lua Interpreter was compiled with MadOS. 
I change the "main" in lua.c to "lua", and startup it as a thread.
I do some test like filesystem、network、..., It seems running fine.
* I running the Lua source code on the STM32.
* Nothing changed
* I define " function mypow(x,y) return x^y end " but got an error " stdin:1: 'end' expected near '<\25>' ".
* It looks same.

Joseph C. Sible <[hidden email]> 于2020年7月5日周日 上午5:43写道:
On Sat, Jul 4, 2020 at 3:01 PM Long Z <[hidden email]> wrote:
>
> HW: STM32F107RCT6 (ARM Cortex M3)
> OS: MadOS
> I port lua to a RTOS, and then found a strange error :
> * math.pow(2, 2) result 4.0 BUT 2^2 result 2.
> * After some test, I found x^y result x always.
> * I used v5.4.0, v5.3.5 and v5.1.5 for testing, and got the same result.
> Here is my luaconfig.h used in v5.4.0.
>

Here's some troubleshooting ideas/questions:

* Are you running the Lua source code on the STM32, or are you
compiling it somewhere else and just running the bytecode there? If
the latter, does the former work any better?
* If you stub out the whole constfolding function in src/lcode.c,
replacing the entire body with "return 0;", does anything change?
* If you do "function mypow(x, y) return x ^ y end" and then call
"mypow(2, 2)", what does it return?
* If you get the numbers at runtime instead of hardcoding them in the
Lua source, does anything change?

Joseph C. Sible


--
龙的传人
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

dyngeccetor8
On 2020-07-12 5:05 a.m., Long Z wrote:
 > [...]
> * I define " function mypow(x,y) return x^y end " but got an error "
> stdin:1: 'end' expected near '<\25>' ".
> [...]
>     * If you do "function mypow(x, y) return x ^ y end" and then call
>     "mypow(2, 2)", what does it return?

This looks strange. If \25 is ASCII(0x25) then it's percent sign.

-- Martin
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

Luiz Henrique de Figueiredo
> > stdin:1: 'end' expected near '<\25>' ".
> This looks strange. If \25 is ASCII(0x25) then it's percent sign.

It's 25 decimal, not hex. So ^W.
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

Long Z
I try to track progress of the two method in lvm.c:

- math.pow(2,2)
OP_VARARGPREP
OP_GETTABUP
OP_GETFIELD
OP_LOADI
OP_TAILCALL -> luaD_call -> math_pow
OP_RETURN1

- 2^2
OP_VARARGPREP
OP_LOADI
OP_RETURN
OP_RETURN1

"2^2" have NOT went into OP_TAILCALL, and also OP_POW. 
So strange...

Luiz Henrique de Figueiredo <[hidden email]> 于2020年7月13日周一 上午8:45写道:
> > stdin:1: 'end' expected near '<\25>' ".
> This looks strange. If \25 is ASCII(0x25) then it's percent sign.

It's 25 decimal, not hex. So ^W.


--
龙的传人
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

Luiz Henrique de Figueiredo
> "2^2" have NOT went into OP_TAILCALL, and also OP_POW.
> So strange...

"2^2" is computed at compile time because it's a constant expression.
"return 2^2" gives this bytecode:

VARARGPREP      0
LOADF           0 4
RETURN          0 2 1   ; 1 out
RETURN          0 1 1   ; 0 out

which matches your report except that you had LOADI instead of LOADF.
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

Long Z
Thank you, guys.
It seems the Serial-Tool used by me send error string to the Lua-Interpreter.
When a string I typed contained '^', the Serial-Tool just sent the characters before '^'.
So, it is NOT a bug/err of lua.

Luiz Henrique de Figueiredo <[hidden email]> 于2020年7月13日周一 下午8:45写道:
> "2^2" have NOT went into OP_TAILCALL, and also OP_POW.
> So strange...

"2^2" is computed at compile time because it's a constant expression.
"return 2^2" gives this bytecode:

VARARGPREP      0
LOADF           0 4
RETURN          0 2 1   ; 1 out
RETURN          0 1 1   ; 0 out

which matches your report except that you had LOADI instead of LOADF.


--
龙的传人
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

Long Z
Checked
When I typed "2 \^ 2", the result was 4.0 ...

Long Z <[hidden email]> 于2020年7月13日周一 下午9:51写道:
Thank you, guys.
It seems the Serial-Tool used by me send error string to the Lua-Interpreter.
When a string I typed contained '^', the Serial-Tool just sent the characters before '^'.
So, it is NOT a bug/err of lua.

Luiz Henrique de Figueiredo <[hidden email]> 于2020年7月13日周一 下午8:45写道:
> "2^2" have NOT went into OP_TAILCALL, and also OP_POW.
> So strange...

"2^2" is computed at compile time because it's a constant expression.
"return 2^2" gives this bytecode:

VARARGPREP      0
LOADF           0 4
RETURN          0 2 1   ; 1 out
RETURN          0 1 1   ; 0 out

which matches your report except that you had LOADI instead of LOADF.


--
龙的传人


--
龙的传人
Reply | Threaded
Open this post in threaded view
|

Re: A strange error found (x^y == x)

Long Z
When a string I typed contained '^', the Serial-Tool(Serial for Mac) ONLY sent the characters before '^'.
When I typed "2 \^ 2", the result was 4.0.
So, it is NOT a bug/err of lua.

Long Z <[hidden email]> 于2020年7月13日周一 下午9:59写道:
Checked
When I typed "2 \^ 2", the result was 4.0 ...

Long Z <[hidden email]> 于2020年7月13日周一 下午9:51写道:
Thank you, guys.
It seems the Serial-Tool used by me send error string to the Lua-Interpreter.
When a string I typed contained '^', the Serial-Tool just sent the characters before '^'.
So, it is NOT a bug/err of lua.

Luiz Henrique de Figueiredo <[hidden email]> 于2020年7月13日周一 下午8:45写道:
> "2^2" have NOT went into OP_TAILCALL, and also OP_POW.
> So strange...

"2^2" is computed at compile time because it's a constant expression.
"return 2^2" gives this bytecode:

VARARGPREP      0
LOADF           0 4
RETURN          0 2 1   ; 1 out
RETURN          0 1 1   ; 0 out

which matches your report except that you had LOADI instead of LOADF.


--
龙的传人


--
龙的传人


--
龙的传人