lua-users home
lua-l archive

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


Dear,
I was looking at the opcodes from lua-5.4.0-rc1 using "luac -l", and the simple code below

local v1 = 1
local v2 = 1.
local v3 = 1.0
local v4 = 1.01

is translated to

1 [1] VARARGPREP 0
2 [1] LOADI     0 1
3 [2] LOADF     1 1
4 [3] LOADF     2 1
5 [4] LOADK     3 0 ; 1.01

So, why "1." and "1.0" use LOADF but "1.01" uses LOADK?

I think that is caused by the fact LOADF loads the value from the sBx argument, an integer. In lvm.c, you can see it simply casting sBx as an int to a lua_Number:

vmcase(OP_LOADF) {
  int b = GETARG_sBx(i);
  setfltvalue(s2v(ra), cast_num(b));
  vmbreak;
}

So I would assume only floating point numbers with an integer value can be stored in LOADF instructions in the current implementation.

~Bas
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org