Compare commits

...

2 Commits
master ... mini

Author SHA1 Message Date
Dibyendu Majumdar 5d88ea52fd issue #189 enable coroutines by default so that tests do not fail
4 years ago
Dibyendu Majumdar d69e0470e1 issue #189
4 years ago

@ -48,8 +48,9 @@ set(LUA_CORE_SRCS src/lapi.c src/lcode.c src/lctype.c src/ldebug.c src/ldo.c src
src/lvm.c src/lzio.c src/ravi_jit.c src/ltests.c src/ravi_profile.c
src/ravi_membuf.c src/ravi_jitshared.c src/bit.c src/ravi_alloc.c)
# define the Lua library source files
set(LUA_LIB_SRCS src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcorolib.c src/ldblib.c src/liolib.c
src/lmathlib.c src/loslib.c src/ltablib.c src/lstrlib.c src/loadlib.c src/linit.c src/lutf8lib.c)
set(LUA_COROUTINE_LIB src/lcorolib.c)
set(LUA_LIB_SRCS src/lauxlib.c src/lbaselib.c src/lbitlib.c src/ldblib.c src/liolib.c
src/lmathlib.c src/loslib.c src/ltablib.c src/lstrlib.c src/loadlib.c src/linit.c src/lutf8lib.c ${LUA_COROUTINE_LIB})
set(LUA_HEADERS include/lua.h include/luaconf.h include/lualib.h include/lauxlib.h)
# LLVM code gen
set(LLVM_JIT_SRCS src/ravi_llvmjit.cpp src/ravi_llvmtypes.cpp

@ -80,8 +80,11 @@ struct lua_longjmp; /* defined in ldo.c */
/* extra stack space to handle TM calls and some other extras */
#define EXTRA_STACK 5
#ifdef RAVI_SUPPORT_COROUTINES
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
#else
#define BASIC_STACK_SIZE (128*300)
#endif
/* kinds of Garbage Collection */

@ -225,7 +225,9 @@ extern const char lua_ident[];
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
#ifdef RAVI_SUPPORT_COROUTINES
LUA_API lua_State *(lua_newthread) (lua_State *L);
#endif
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);

@ -850,6 +850,7 @@
#define RAVI_USE_LLVM_ARITH_FLOATPRIORITY 1
/* Enables the 'defer' statement - RAVI extension */
#define RAVI_DEFER_STATEMENT
#define RAVI_SUPPORT_COROUTINES
#endif

@ -129,7 +129,9 @@ LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
StkId val, const TValue *slot);
LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
StkId val, const TValue *slot);
#ifdef RAVI_SUPPORT_COUROUTINES
LUAI_FUNC void luaV_finishOp (lua_State *L);
#endif
/* RAVI change: the int return value is a Ravi extension */
LUAI_FUNC int luaV_execute (lua_State *L);
LUAI_FUNC void luaV_concat (lua_State *L, int total);

@ -17,6 +17,7 @@
#include "lauxlib.h"
#include "lualib.h"
#ifdef RAVI_SUPPORT_COROUTINES
static lua_State *getco (lua_State *L) {
lua_State *co = lua_tothread(L, 1);
@ -166,3 +167,4 @@ LUAMOD_API int luaopen_coroutine (lua_State *L) {
return 1;
}
#endif

@ -181,6 +181,7 @@ static void correctstack (lua_State *L, TValue *oldstack) {
void luaD_reallocstack (lua_State *L, int newsize) {
#ifdef RAVI_SUPPORT_COROUTINES
TValue *oldstack = L->stack;
int lim = L->stacksize;
lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
@ -191,10 +192,14 @@ void luaD_reallocstack (lua_State *L, int newsize) {
L->stacksize = newsize;
L->stack_last = L->stack + newsize - EXTRA_STACK;
correctstack(L, oldstack);
#else
luaG_runerror(L, "stack overflow");
#endif
}
void luaD_growstack (lua_State *L, int n) {
#ifdef RAVI_SUPPORT_COROUTINES
int size = L->stacksize;
if (size > LUAI_MAXSTACK) /* error after extra size? */
luaD_throw(L, LUA_ERRERR);
@ -210,6 +215,9 @@ void luaD_growstack (lua_State *L, int n) {
else
luaD_reallocstack(L, newsize);
}
#else
luaG_runerror(L, "stack overflow");
#endif
}
@ -225,6 +233,7 @@ static int stackinuse (lua_State *L) {
void luaD_shrinkstack (lua_State *L) {
#ifdef RAVI_SUPPORT_COROUTINES
int inuse = stackinuse(L);
int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;
if (goodsize > LUAI_MAXSTACK)
@ -240,6 +249,7 @@ void luaD_shrinkstack (lua_State *L) {
luaD_reallocstack(L, goodsize);
else /* don't change stack */
condmovestack(L,{},{}); /* (change only for debugging) */
#endif
}
@ -607,7 +617,7 @@ void luaD_callnoyield (lua_State *L, StkId func, int nResults) {
L->nny--;
}
#ifdef RAVI_SUPPORT_COROUTINES
/*
** Completes the execution of an interrupted C function, calling its
** continuation function.
@ -817,7 +827,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,
lua_unlock(L);
return 0; /* return to 'luaD_hook' */
}
#endif
int luaD_pcall (lua_State *L, Pfunc func, void *u,
ptrdiff_t old_top, ptrdiff_t ef) {

@ -41,7 +41,9 @@
static const luaL_Reg loadedlibs[] = {
{"_G", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
#ifdef RAVI_SUPPORT_COUROUTINES
{LUA_COLIBNAME, luaopen_coroutine},
#endif
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},

@ -276,7 +276,7 @@ static void close_state (lua_State *L) {
(*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
}
#ifdef RAVI_SUPPORT_COROUTINES
LUA_API lua_State *lua_newthread (lua_State *L) {
global_State *g = G(L);
lua_State *L1;
@ -305,7 +305,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
lua_unlock(L);
return L1;
}
#endif
void luaE_freethread (lua_State *L, lua_State *L1) {
LX *l = fromstate(L1);

@ -902,7 +902,7 @@ static int udataval (lua_State *L) {
return 1;
}
#ifdef RAVI_SUPPORT_COROUTINES
static int doonnewstack (lua_State *L) {
lua_State *L1 = lua_newthread(L);
size_t l;
@ -913,7 +913,7 @@ static int doonnewstack (lua_State *L) {
lua_pushinteger(L, status);
return 1;
}
#endif
static int s2d (lua_State *L) {
lua_pushnumber(L, *cast(const double *, luaL_checkstring(L, 1)));
@ -958,7 +958,9 @@ static lua_State *getstate (lua_State *L) {
static int loadlib (lua_State *L) {
static const luaL_Reg libs[] = {
{"_G", luaopen_base},
#ifdef RAVI_SUPPORT_COROUTINES
{"coroutine", luaopen_coroutine},
#endif
{"debug", luaopen_debug},
{"io", luaopen_io},
{"os", luaopen_os},
@ -1311,9 +1313,11 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
else if EQ("newtable") {
lua_newtable(L1);
}
#ifdef RAVI_SUPPORT_COROUTINES
else if EQ("newthread") {
lua_newthread(L1);
}
#endif
else if EQ("newuserdata") {
lua_newuserdata(L1, getnum);
}
@ -1404,10 +1408,12 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
else if EQ("replace") {
lua_replace(L1, getindex);
}
#ifdef RAVI_SUPPORT_COROUTINES
else if EQ("resume") {
int i = getindex;
status = lua_resume(lua_tothread(L1, i), L, getnum);
}
#endif
else if EQ("return") {
int n = getnum;
if (L1 != L) {
@ -1493,6 +1499,7 @@ static struct X { int x; } x;
if (n == 0) n = lua_gettop(fs);
lua_xmove(fs, ts, n);
}
#ifdef RAVI_SUPPORT_COROUTINES
else if EQ("yield") {
return lua_yield(L1, getnum);
}
@ -1501,6 +1508,7 @@ static struct X { int x; } x;
int i = getindex;
return lua_yieldk(L1, nres, i, Cfunck);
}
#endif
else luaL_error(L, "unknown instruction %s", buff);
}
return 0;
@ -1612,7 +1620,7 @@ static int sethook (lua_State *L) {
return 0;
}
#ifdef RAVI_SUPPORT_COROUTINES
static int coresume (lua_State *L) {
int status;
lua_State *co = lua_tothread(L, 1);
@ -1628,6 +1636,7 @@ static int coresume (lua_State *L) {
return 1;
}
}
#endif
/* }====================================================== */
@ -1637,7 +1646,9 @@ static const struct luaL_Reg tests_funcs[] = {
{"checkmemory", lua_checkmemory},
{"closestate", closestate},
{"d2s", d2s},
#ifdef RAVI_SUPPORT_COROUTINES
{"doonnewstack", doonnewstack},
#endif
{"doremote", doremote},
{"gccolor", gc_color},
{"gcage", gc_age},
@ -1660,7 +1671,9 @@ static const struct luaL_Reg tests_funcs[] = {
{"querystr", string_query},
{"querytab", table_query},
{"ref", tref},
#ifdef RAVI_SUPPORT_COROUTINES
{"resume", coresume},
#endif
{"s2d", s2d},
{"sethook", sethook},
{"stacklevel", stacklevel},

@ -987,7 +987,7 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
p->cache = ncl; /* save it on cache for reuse */
}
#ifdef RAVI_SUPPORT_COROUTINES
/*
** finish execution of an opcode interrupted by an yield
*/
@ -1051,7 +1051,7 @@ void luaV_finishOp (lua_State *L) {
default: lua_assert(0);
}
}
#endif

Loading…
Cancel
Save