lua-users home
lua-l archive

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


Hello,

I've modified Lua to work using only fixed point 32 bit integers.  ie, any number entered in a script or interpreter is automatically intercepted and converted to fixed point values (1e10 -> 655360, 0x0002->131072, etc..).  Most of the changes were made to luaconf.h, but there were two other issues I had to fix:

1. the default increment value for "for" loops was originally "1".  I changed it to 1<<16 = 65536.
     - no problems

2. Table indexing gets messed up if the user types:
   
    t = {"one","two","three","four","five"}
    print(t[2])

    because internally this will be read as "print(t[131072])".  I have half fixed this issue.  I modified primaryexp() function within lparser.c as below.  If the _expression_ to be dereferenced is a number (ex: print(t[2+1])), key.k == VKNUM and I can directly change shift the number back from fixed point to integer.  Problem: if the _expression_ to be dereferenced is a variable (ex: a = 2; print(t[a])) then key.k == VNONRELOC and I can't find the result register the number is stored in.

Question: Can somebody please tell me how I can access the result register where the _expression_ is stored?  I think the register number is in "key.u.s.info" at the line marked TODO below.  Thank you very much!

case '[': {  /* `[' exp1 `]' */
        expdesc key;
        luaK_exp2anyreg(fs, v);
        yindex(ls, &key);

#ifdef LUA_FIXED_POINT

        if(key.k == VKNUM)
        {
            //if it's a number we need to shift it over
            key.u.nval = key.u.nval >> LUA_FIXED_POINT_SHIFT;
            luaK_indexed(fs, v, &key);
        }
        else if(key.k == VRELOCABLE)
        {
            //if it's a variable or _expression_ we need access it and convert from fixed point to integer
           
            luaK_indexed(fs, v, &key);

            //key.k == VNONRELOC now
            //check the result register at key.u.s.info
            //TODO: how do I access this register?????
           
        }

#else

        luaK_indexed(fs, v, &key);

#endif //LUA_FIXED_POINT

        break;