setupval workaround

pull/81/head
dibyendumajumdar 9 years ago
parent dd8b225e73
commit 4fbc7a1717

@ -67,5 +67,6 @@ LUAI_FUNC void raviV_op_setlist(lua_State *L, CallInfo *ci, TValue *ra, int b, i
LUAI_FUNC void raviV_op_concat(lua_State *L, CallInfo *ci, int a, int b, int c);
LUAI_FUNC void raviV_op_closure(lua_State *L, CallInfo *ci, LClosure *cl, int a, int Bx);
LUAI_FUNC void raviV_op_vararg(lua_State *L, CallInfo *ci, LClosure *cl, int a, int b);
LUAI_FUNC void raviV_op_setupval(lua_State *L, LClosure *cl, TValue *ra, int b);
#endif

@ -288,6 +288,7 @@ struct ravi_gcc_types_t {
gcc_jit_function *raviV_op_concatT;
gcc_jit_function *raviV_op_closureT;
gcc_jit_function *raviV_op_varargT;
gcc_jit_function *raviV_op_setupvalT;
gcc_jit_function *raviH_set_intT;
gcc_jit_function *raviH_set_floatT;

@ -74,21 +74,6 @@ assert(ravi.compile(x))
assert(x() == 5)
print("test 5 OK")
-- test 6
x = function ()
local j = 0
for i=2.0,6.0,3.1 do
j = i
end
return j
end
if (not ravi.compile(x)) then
print("test 6 FAILED to compile")
end
assert(x() == 5.1)
print("test 6 OK")
-- test 7
x = function ()
local a=5
@ -472,10 +457,15 @@ matrix.getdata = function(m)
return m[3]
end
matrix.datalen = function(data)
return #data
end
x = function()
local m = matrix.new(5,5)
local data: number[] = matrix.getdata(m)
for i = 1,#data do
local data_len: integer = matrix.datalen(data)
for i = 1,data_len do
data[i] = i
end
-- get third col
@ -639,6 +629,35 @@ x1=5
assert(f() == 5)
print("test 28 OK")
-- test 35
function x()
local x = 1
local f = function()
x=x+1
return x
end
return f
end
f=x()
assert(ravi.compile(f))
assert(f() == 2)
assert(f() == 3)
print("test 35 OK")
-- test setupval, getupval
function x()
local a = 0
return function(x) a=a+x; return a; end
end
-- ravi.dumplua(x)
ravi.compile(x)
y=x()
ravi.compile(y)
assert(y(2) == 2)
assert(y(2) == 4)
assert(y(3) == 7)
print('test SETUPVAL and GETUPVAL Ok')
-- test 32
x=function(a,b)
return a%b
@ -657,18 +676,18 @@ assert(x(5,2) == 2)
assert(math.abs(x(5.5,2.1)-2.0) < 1e-12)
print("test 33 OK")
-- test 35
function x()
local x = 1
local f = function()
x=x+1
return x
-- test 6
x = function ()
local j = 0
for i=2.0,6.0,3.1 do
j = i
end
return f
return j
end
f=x()
assert(ravi.compile(f))
assert(f() == 2)
assert(f() == 3)
print("test 35 OK")
if (not ravi.compile(x)) then
print("test 6 FAILED to compile")
end
assert(x() == 5.1)
print("test 6 OK")

@ -1754,5 +1754,14 @@ void raviV_op_loadnil(CallInfo *ci, int a, int b) {
} while (b--);
}
void raviV_op_setupval(lua_State *L, LClosure *cl, TValue *ra, int b) {
UpVal *uv = cl->upvals[b];
setobj(L, uv->v, ra);
luaC_upvalbarrier(L, uv);
}
/* }================================================================== */

@ -125,6 +125,7 @@ static bool can_compile(Proto *p) {
case OP_MUL:
case OP_DIV:
case OP_GETUPVAL:
case OP_SETUPVAL:
break;
case OP_LOADKX:
case OP_FORPREP:
@ -133,7 +134,6 @@ static bool can_compile(Proto *p) {
case OP_IDIV:
case OP_UNM:
case OP_POW:
case OP_SETUPVAL:
default: {
p->ravi_jit.jit_status = 1;
return false;

@ -299,7 +299,19 @@ void ravi_emit_GETUPVAL(ravi_function_def_t *def, int A, int B, int pc) {
// UpValue[B] := R(A)
void ravi_emit_SETUPVAL(ravi_function_def_t *def, int A, int B, int pc) {
#if 1
// Work around libgccjit compilation failure
// The inline version causes segmentation fault during compilation
(void)pc;
ravi_emit_load_base(def);
gcc_jit_rvalue *ra = ravi_emit_get_register(def, A);
gcc_jit_block_add_eval(def->current_block, NULL,
ravi_function_call4_rvalue(def,
def->ravi->types->raviV_op_setupvalT,
gcc_jit_param_as_rvalue(def->L),
gcc_jit_lvalue_as_rvalue(def->lua_closure_val),
ra, ravi_int_constant(def, B)));
#else
// UpVal *uv = cl->upvals[GETARG_B(i)];
// setobj(L, uv->v, ra);
// luaC_upvalbarrier(L, uv);
@ -313,12 +325,11 @@ void ravi_emit_SETUPVAL(ravi_function_def_t *def, int A, int B, int pc) {
gcc_jit_lvalue *type = ravi_emit_load_type(def, gcc_jit_lvalue_as_rvalue(v));
// (type & BIT_ISCOLLECTIBLE) != 0
gcc_jit_rvalue *bit_iscollectible = gcc_jit_context_new_rvalue_from_int(def->function_context,
def->ravi->types->C_intT, BIT_ISCOLLECTABLE);
gcc_jit_rvalue *bit_iscollectible = ravi_int_constant(def, BIT_ISCOLLECTABLE);
gcc_jit_rvalue *is_collectible_bit =
gcc_jit_context_new_binary_op(def->function_context, NULL, GCC_JIT_BINARY_OP_BITWISE_AND,
def->ravi->types->C_intT, gcc_jit_lvalue_as_rvalue(type), bit_iscollectible);
gcc_jit_rvalue *zero = gcc_jit_context_new_rvalue_from_int(def->function_context, def->ravi->types->C_intT, 0);
gcc_jit_rvalue *zero = ravi_int_constant(def, 0);
gcc_jit_rvalue *is_collectible = ravi_emit_comparison(def, GCC_JIT_COMPARISON_NE,
is_collectible_bit, zero);
@ -331,7 +342,8 @@ void ravi_emit_SETUPVAL(ravi_function_def_t *def, int A, int B, int pc) {
// Collectible type and upvalue is closed
// ((type & BIT_ISCOLLECTIBLE) != 0) && ((up)->v == &(up)->u.value))
gcc_jit_rvalue *andcond =
gcc_jit_context_new_binary_op(def->function_context, NULL, GCC_JIT_BINARY_OP_LOGICAL_AND, def->ravi->types->C_boolT,
gcc_jit_context_new_binary_op(def->function_context, NULL, GCC_JIT_BINARY_OP_LOGICAL_AND,
def->ravi->types->C_boolT,
is_collectible, upisclosed);
gcc_jit_block *then =
@ -348,6 +360,7 @@ void ravi_emit_SETUPVAL(ravi_function_def_t *def, int A, int B, int pc) {
ravi_emit_branch(def, end);
ravi_set_current_block(def, end);
#endif
}
// UpValue[A][RK(B)] := RK(C)

@ -1109,6 +1109,19 @@ bool ravi_setup_lua_types(ravi_gcc_context_t *ravi) {
ravi->context, NULL, GCC_JIT_FUNCTION_IMPORTED, t->C_voidT,
"raviH_set_float", 4, params, 0);
//void raviV_op_setupval(lua_State *L, LClosure *cl, TValue *ra, int b)
params[0] =
gcc_jit_context_new_param(ravi->context, NULL, t->plua_StateT, "L");
params[1] =
gcc_jit_context_new_param(ravi->context, NULL, t->pLClosureT, "cl");
params[2] = gcc_jit_context_new_param(ravi->context, NULL, t->pTValueT, "ra");
params[3] = gcc_jit_context_new_param(ravi->context, NULL, t->C_intT, "b");
t->raviV_op_setupvalT = gcc_jit_context_new_function(
ravi->context, NULL, GCC_JIT_FUNCTION_IMPORTED, t->C_voidT,
"raviV_op_setupval", 4, params, 0);
params[0] = gcc_jit_context_new_param(ravi->context, NULL, t->C_pconstcharT,
"format");
t->printfT = gcc_jit_context_new_function(ravi->context, NULL,

Loading…
Cancel
Save