gccjit-ravi534
Dibyendu Majumdar 8 years ago
parent 9895f2879c
commit 80feef445e

@ -31,11 +31,51 @@
#define keyfromval(v) \
(gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
#if defined(RAVI_ENABLED)
#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
#define hashstr(t,str) hashpow2(t, (str)->hash)
#define hashboolean(t,p) hashpow2(t, p)
#define hashint(t,i) hashpow2(t, i)
/*
** for some types, it is better to avoid modulus by power of 2, as
** they tend to have many 2 factors.
*/
#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1))))
#define hashpointer(t,p) hashmod(t, point2uint(p))
#endif
LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
TValue *value);
#if defined(RAVI_ENABLED)
/*
** search function for short strings
*/
static inline const TValue *luaH_getshortstr(Table *t, TString *key) {
Node *n = hashstr(t, key);
lua_assert(key->tt == LUA_TSHRSTR);
for (;;) { /* check whether 'key' is somewhere in the chain */
const TValue *k = gkey(n);
if (ttisshrstring(k) && eqshrstr(tsvalue(k), key))
return gval(n); /* that's it */
else {
int nx = gnext(n);
if (nx == 0)
return luaO_nilobject; /* not found */
n += nx;
}
}
}
#else
LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
#endif
LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);

@ -1192,6 +1192,22 @@ bug_index_event()
print 'Test 50 OK'
function event_test()
local a: table = {}
setmetatable(a, {__metatable = "xuxu",
__tostring=function(x: table) return x.name end})
assert(getmetatable(a) == "xuxu")
assert(tostring(a) == nil)
-- cannot change a protected metatable
assert(pcall(setmetatable, a, {}) == false)
a.name = "gororoba"
assert(tostring(a) == "gororoba")
end
event_test();
compile(event_test)
event_test();
print 'Test 51 OK'
for k,v in pairs(opcodes_coverage)
do
print(k, v)

@ -156,9 +156,10 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"MOVETAB", /* A B R(A) := R(B), check R(B) is a table */
"SETUPVALT", /* A B UpValue[B] := to_table(R(A)) */
"SELF_S", /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"GETTABLE_SK", /* A B C R(A) := R(B)[RK(C)], string key */
"SELF_SK", /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETTABLE_SK", /* A B C R(A)[RK(B)] := RK(C), string key */
// TODO temporary hack to allow existing tests to see old opcode names
"GETTABLE", /* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"SELF", /* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETTABLE", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
NULL
};

@ -56,7 +56,7 @@
*/
#define MAXHBITS (MAXABITS - 1)
#if !defined(RAVI_ENABLED)
#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
#define hashstr(t,str) hashpow2(t, (str)->hash)
@ -72,7 +72,7 @@
#define hashpointer(t,p) hashmod(t, point2uint(p))
#endif
#define dummynode (&dummynode_)
@ -556,7 +556,7 @@ const TValue *luaH_getint (Table *t, lua_Integer key) {
}
}
#if !defined(RAVI_ENABLED)
/*
** search function for short strings
*/
@ -575,7 +575,7 @@ const TValue *luaH_getshortstr (Table *t, TString *key) {
}
}
}
#endif
/*
** "Generic" get version. (Not that generic: not valid for integers,

@ -468,6 +468,7 @@ static char *buildop (Proto *p, int pc, char *buff) {
Instruction i = p->code[pc];
OpCode o = GET_OPCODE(i);
const char *name = luaP_opnames[o];
int line = getfuncline(p, pc);
sprintf(buff, "(%4d) %4d - ", line, pc);
switch (getOpMode(o)) {

@ -250,65 +250,66 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
luaG_runerror(L, "'__newindex' chain too long; possible loop");
}
#define GETTABLE_INLINE(L, t, key, val) \
if (!ttistable(t) || hvalue(t)->ravi_array.array_type == RAVI_TTABLE) { \
const TValue *aux; \
if (luaV_fastget(L,t,key,aux,luaH_get)) { setobj2s(L, val, aux); } \
else luaV_finishget(L,t,key,val,aux); \
} \
else { \
Table *h = hvalue(t); \
if (h->ravi_array.array_type == RAVI_TARRAYFLT) { \
if (!ttisinteger(key)) luaG_typeerror(L, key, "index"); \
raviH_get_float_inline(L, h, ivalue(key), val); \
} \
else { \
if (!ttisinteger(key)) luaG_typeerror(L, key, "index"); \
raviH_get_int_inline(L, h, ivalue(key), val); \
} \
static inline void GETTABLE_INLINE(lua_State *L, const TValue *t, TValue *key, StkId val) {
if (!ttistable(t) || hvalue(t)->ravi_array.array_type == RAVI_TTABLE) {
const TValue *slot;
if (luaV_fastget(L, t, key, slot, luaH_get)) { setobj2s(L, val, slot); }
else luaV_finishget(L, t, key, val, slot);
}
else {
Table *h = hvalue(t);
if (h->ravi_array.array_type == RAVI_TARRAYFLT) {
if (!ttisinteger(key)) luaG_typeerror(L, key, "index");
raviH_get_float_inline(L, h, ivalue(key), val);
}
else {
if (!ttisinteger(key)) luaG_typeerror(L, key, "index");
raviH_get_int_inline(L, h, ivalue(key), val);
}
}
}
#define SETTABLE_INLINE(L, t, key, val) \
if (!ttistable(t) || hvalue(t)->ravi_array.array_type == RAVI_TTABLE) { \
const TValue *slot; \
if (!luaV_fastset(L, t, key, slot, luaH_get, val)) \
luaV_finishset(L, t, key, val, slot); \
} \
else { \
Table *h = hvalue(t); \
if (h->ravi_array.array_type == RAVI_TARRAYFLT) { \
if (!ttisinteger(key)) luaG_typeerror(L, key, "index"); \
if (ttisfloat(val)) { \
raviH_set_float_inline(L, h, ivalue(key), fltvalue(val)); \
} \
else if (ttisinteger(val)) { \
raviH_set_float_inline(L, h, ivalue(key), (lua_Number)(ivalue(val))); \
} \
else { \
lua_Number d = 0.0; \
if (luaV_tonumber_(val, &d)) { \
raviH_set_float_inline(L, h, ivalue(key), d); \
} \
else \
luaG_runerror(L, "value cannot be converted to number"); \
} \
} \
else { \
if (!ttisinteger(key)) luaG_typeerror(L, key, "index"); \
if (ttisinteger(val)) { \
raviH_set_int_inline(L, h, ivalue(key), ivalue(val)); \
} \
else { \
lua_Integer i = 0; \
if (luaV_tointeger_(val, &i)) { \
raviH_set_int_inline(L, h, ivalue(key), i); \
} \
else \
luaG_runerror(L, "value cannot be converted to integer"); \
} \
} \
static inline void SETTABLE_INLINE(lua_State *L, const TValue *t, TValue *key, StkId val) {
if (!ttistable(t) || hvalue(t)->ravi_array.array_type == RAVI_TTABLE) {
const TValue *slot;
if (!luaV_fastset(L, t, key, slot, luaH_get, val))
luaV_finishset(L, t, key, val, slot);
}
else {
Table *h = hvalue(t);
if (h->ravi_array.array_type == RAVI_TARRAYFLT) {
if (!ttisinteger(key)) luaG_typeerror(L, key, "index");
if (ttisfloat(val)) {
raviH_set_float_inline(L, h, ivalue(key), fltvalue(val));
}
else if (ttisinteger(val)) {
raviH_set_float_inline(L, h, ivalue(key), (lua_Number)(ivalue(val)));
}
else {
lua_Number d = 0.0;
if (luaV_tonumber_(val, &d)) {
raviH_set_float_inline(L, h, ivalue(key), d);
}
else
luaG_runerror(L, "value cannot be converted to number");
}
}
else {
if (!ttisinteger(key)) luaG_typeerror(L, key, "index");
if (ttisinteger(val)) {
raviH_set_int_inline(L, h, ivalue(key), ivalue(val));
}
else {
lua_Integer i = 0;
if (luaV_tointeger_(val, &i)) {
raviH_set_int_inline(L, h, ivalue(key), i);
}
else
luaG_runerror(L, "value cannot be converted to integer");
}
}
}
}
/*
** Main function for table access (invoking metamethods if needed).
@ -943,7 +944,9 @@ int luaV_execute (lua_State *L) {
GETTABLE_INLINE(L, upval, rc, ra);
Protect((void)0);
} break;
#if 0
case OP_RAVI_GETTABLE_SK:
#endif
case OP_GETTABLE: {
StkId rb = RB(i); /* table */
TValue *rc = RKC(i); /* key */
@ -1613,9 +1616,40 @@ int luaV_execute (lua_State *L) {
setobj2s(L, ra, v);
}
else {
Protect(raviV_finishget(L, rb, rc, ra));
//Protect(raviV_finishget(L, rb, rc, ra));
Protect(luaV_finishget(L, rb, rc, ra, v));
}
} break;
#if 1
/* This opcode is used when the key is known to be
short string but the variable may or may not be
a table
*/
case OP_RAVI_GETTABLE_SK: {
StkId rb = RB(i); /* variable - may not be a table */
lua_assert(ISK(GETARG_C(i)));
TValue *rc = k + INDEXK(GETARG_C(i)); /* we know that the key a short string constant */
if (!ttistable(rb)) {
GETTABLE_INLINE(L, rb, rc, ra);
Protect((void)0);
}
else {
/* table case */
TString *key = tsvalue(rc);
lua_assert(key->tt == LUA_TSHRSTR);
Table *h = hvalue(rb);
const TValue *v = luaH_getshortstr(h, key);
if (!ttisnil(v) || metamethod_absent(h->metatable, TM_INDEX)) {
setobj2s(L, ra, v);
}
else {
Protect(luaV_finishget(L, rb, rc, ra, v));
//Protect(raviV_finishget(L, rb, rc, ra));
}
}
break;
}
#endif
case OP_RAVI_SELF_S:
case OP_RAVI_GETTABLE_S: {
/* Following is an inline version of luaH_getstr() - this is
@ -1625,10 +1659,12 @@ int luaV_execute (lua_State *L) {
StkId rb = RB(i);
if (op == OP_RAVI_SELF_S) { setobjs2s(L, ra + 1, rb); }
{
lua_assert(ISK(GETARG_C(i)));
TValue *rc = k + INDEXK(GETARG_C(i));
TString *key = tsvalue(rc);
lua_assert(key->tt == LUA_TSHRSTR);
Table *h = hvalue(rb);
#if 0
int position = lmod(key->hash, sizenode(h));
Node *n = &h->node[position];
const TValue *v;
@ -1647,11 +1683,15 @@ int luaV_execute (lua_State *L) {
n += nx;
}
}
#else
const TValue *v = luaH_getshortstr(h, key);
#endif
if (!ttisnil(v) || metamethod_absent(h->metatable, TM_INDEX)) {
setobj2s(L, ra, v);
}
else {
Protect(raviV_finishget(L, rb, rc, ra));
//Protect(raviV_finishget(L, rb, rc, ra));
Protect(luaV_finishget(L, rb, rc, ra, v));
}
}
} break;

Loading…
Cancel
Save