lua-users home
lua-l archive

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


On Tue, Mar 4, 2014 at 3:19 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> To properly handle div and mod by zero, throwing an error on the Lua
>> state. I am defining lua_Number as lua_Integer. For that, I've defined
>> luai_num{div,mod,pow} as luaV_{div,mod,pow}. This approach sounds to
>> work fine, except by the frexp() function. I defined it temporarily as
>> an inline stub function, which seems to work but I don't think it is a
>> good solution because it leads to different hash functions for
>> lua_Number and lua_Integer. I'll take a deeper look to try to find a
>> better way to make lua_Number have the same behaviour of lua_Integer.
>> Do you have any tip?
>
> It is not enough to change the macros. Currently, the compiler uses
> those macros to do constant folding, but the compiler should not raise
> an error in a division by zero, as it cannot know whether the division
> will ever be executed. We will have to change the compiler, too.

I meant raise runtime errors. That is, if the division by zero is
eventually executed, an error will be raised. For that, those macros
should be enough. Doesn't it? (As far as I could test, it worked
well).

> Another approach would be to avoid having values of type "lua_Number" in
> the first place.  As far as I see, a lua_Number can only be created in 4
> cases (if we assume there are no previous lua_Numbers):
>
> - by the parser
> - by a float division
> - by a coersion from a string to a number
> - by lua_pushnumber
>
> Maybe the core could have some macros to control that. (You probably
> would need something for the parser anyway; what does it do when
> the code contains a floating-point constant?)

I thought about going in that way (have a control macro to disable
floating-point numbers), but I wanted to have it working without
changing (or changing very little) the Lua source code first (just
configuring luaconf.h). BTW, it seems to be functional just
configuring these macros. Anyway, I will go in that way now and try to
have such a macro.

About the floating-point constants, by now what happens is that they
are accepted, but they are converted to integers. Another weird thing
(at least to me) is that I defined getlocaledecpoint() as '.', but the
lexer is still considering ','.

Thanks!

Regards,
-- 
Lourival Vieira Neto