initial checkin of opcode UNMF

pull/81/head
Dibyendu Majumdar 9 years ago
parent e3f457b645
commit af16b26e71

@ -648,7 +648,7 @@ void luaV_finishOp (lua_State *L) {
#define vmcasenb(l,b) case l: {b} /* nb = no break */
static void stackDump(lua_State *L, const char *s) {
if (s)
if (!s)
return;
StkId p = L->stack;
if (p == NULL)
@ -671,9 +671,9 @@ static void stackDump(lua_State *L, const char *s) {
else if (ttisnil(p))
printf("stack[%d] = nil\n", i);
else if (ttisfloat(p))
printf("stack[%d] = float\n", i);
printf("stack[%d] = float (%.6f)\n", i, fltvalue(p));
else if (ttisinteger(p))
printf("stack[%d] = integer\n", i);
printf("stack[%d] = integer (%d)\n", i, ivalue(p));
else if (ttislightuserdata(p))
printf("stack[%d] = light user data\n", i);
else if (ttisfulluserdata(p))

@ -70,6 +70,59 @@ static void free_handle(LuaHandle *h)
free(h);
}
static int test_unmf()
{
LuaHandle *h = alloc_handle();
LuaHandle copyh = *h; /* save contents */
int rc = 0;
/* Here we simulate following
* local p = 56.65
* local q = -p
* return q
*
* So we need two registers
* p in register 0
* q in register 1
* return value must be register 1
*/
/* R(1) = -R(0) */
/* register 1 holds q */
/* register 0 holds p */
h->instructions[0] = CREATE_ABC(OP_UNMF, 1, 0, 0);
/* return register 1 (q) */
h->instructions[1] = CREATE_ABC(OP_RETURN, 1, 2, 0);
if (GETARG_A(h->instructions[0]) != 1)
return 1;
if (GETARG_B(h->instructions[0]) != 0)
return 1;
/* set register 0 (p) */
h->stack[1].tt_ = LUA_TNUMFLT;
h->stack[1].value_.n = 56.65;
h->p->maxstacksize = 2; /* need two registers */
h->ci->top = h->ci->u.l.base + h->p->maxstacksize;
h->L->top = h->ci->top;
h->ci->nresults = 1;
luaV_execute(h->L);
if (h->L->top != &h->L->stack[1])
rc = 1;
if (h->L->ci != NULL)
rc = 1;
if (h->stack[0].tt_ != LUA_TNUMFLT ||
h->stack[0].value_.n != -56.65)
rc = 1;
*h = copyh; /* restore contents */
free_handle(h);
return rc;
}
static int test_return1()
{
LuaHandle *h = alloc_handle();
@ -94,7 +147,7 @@ static int test_return1()
*h = copyh; /* restore contents */
free_handle(h);
return 0;
return rc;
}
static int test_return0()
@ -114,7 +167,7 @@ static int test_return0()
*h = copyh; /* restore contents */
free_handle(h);
return 0;
return rc;
}
@ -123,6 +176,7 @@ int main(const char *argv[])
int failures = 0;
failures += test_return0();
failures += test_return1();
failures += test_unmf();
return failures ? 1 : 0;
}
Loading…
Cancel
Save