Removed RAVI_DEFER_STATEMENT define (there are no reasons to disable it)

master
annelin 3 years ago
parent 7d376acf62
commit be65484feb

@ -226,10 +226,7 @@ extern const char lua_ident[];
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L); LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L); LUA_API lua_State *(lua_newthread) (lua_State *L);
#ifdef RAVI_DEFER_STATEMENT
LUA_API int (lua_resetthread) (lua_State *L); LUA_API int (lua_resetthread) (lua_State *L);
#endif
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API const lua_Number *(lua_version) (lua_State *L); LUA_API const lua_Number *(lua_version) (lua_State *L);

@ -852,7 +852,6 @@
/* Following cause the first hash lookup to be inlined, /* Following cause the first hash lookup to be inlined,
and if value is 2 then the second hash lookup is also inlined. */ and if value is 2 then the second hash lookup is also inlined. */
#define RAVI_USE_INLINE_SHORTSTR_TGET 1 #define RAVI_USE_INLINE_SHORTSTR_TGET 1
#define RAVI_DEFER_STATEMENT
#endif #endif

@ -578,12 +578,8 @@ static const char Lua_header[] =
"};\n" "};\n"
"struct UpVal {\n" "struct UpVal {\n"
" TValue *v;\n" " TValue *v;\n"
#ifdef RAVI_DEFER_STATEMENT
" unsigned int refcount;\n" " unsigned int refcount;\n"
" unsigned int flags;\n" " unsigned int flags;\n"
#else
" lu_mem refcount;\n"
#endif
" union {\n" " union {\n"
" struct {\n" " struct {\n"
" UpVal *next;\n" " UpVal *next;\n"
@ -613,11 +609,7 @@ static const char Lua_header[] =
" (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))\n" " (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))\n"
"extern int luaV_tonumber_(const TValue *obj, lua_Number *n);\n" "extern int luaV_tonumber_(const TValue *obj, lua_Number *n);\n"
"extern int luaV_tointeger(const TValue *obj, lua_Integer *p, int mode);\n" "extern int luaV_tointeger(const TValue *obj, lua_Integer *p, int mode);\n"
#ifdef RAVI_DEFER_STATEMENT
"extern int luaF_close (lua_State *L, StkId level, int status);\n" "extern int luaF_close (lua_State *L, StkId level, int status);\n"
#else
"extern void luaF_close (lua_State *L, StkId level);\n"
#endif
"extern int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres);\n" "extern int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres);\n"
"extern void luaD_growstack (lua_State *L, int n);\n" "extern void luaD_growstack (lua_State *L, int n);\n"
"extern int luaV_equalobj(lua_State *L, const TValue *t1, const TValue *t2);\n" "extern int luaV_equalobj(lua_State *L, const TValue *t1, const TValue *t2);\n"
@ -654,9 +646,7 @@ static const char Lua_header[] =
"extern void raviV_settable_sskey(lua_State *L, const TValue *t, TValue *key, TValue *val);\n" "extern void raviV_settable_sskey(lua_State *L, const TValue *t, TValue *key, TValue *val);\n"
"extern void raviV_gettable_i(lua_State *L, const TValue *t, TValue *key, TValue *val);\n" "extern void raviV_gettable_i(lua_State *L, const TValue *t, TValue *key, TValue *val);\n"
"extern void raviV_settable_i(lua_State *L, const TValue *t, TValue *key, TValue *val);\n" "extern void raviV_settable_i(lua_State *L, const TValue *t, TValue *key, TValue *val);\n"
#ifdef RAVI_DEFER_STATEMENT
"extern void raviV_op_defer(lua_State *L, TValue *ra);\n" "extern void raviV_op_defer(lua_State *L, TValue *ra);\n"
#endif
"extern lua_Integer luaV_shiftl(lua_Integer x, lua_Integer y);\n" "extern lua_Integer luaV_shiftl(lua_Integer x, lua_Integer y);\n"
"extern void ravi_dump_value(lua_State *L, const struct lua_TValue *v);\n" "extern void ravi_dump_value(lua_State *L, const struct lua_TValue *v);\n"
"extern void raviV_op_bnot(lua_State *L, TValue *ra, TValue *rb);\n" "extern void raviV_op_bnot(lua_State *L, TValue *ra, TValue *rb);\n"
@ -1180,17 +1170,11 @@ static int emit_op_mov(struct function *fn, Instruction *insn)
static int emit_op_ret(struct function *fn, Instruction *insn) static int emit_op_ret(struct function *fn, Instruction *insn)
{ {
// TODO Only call luaF_close if needed (i.e. some variable escaped) // TODO Only call luaF_close if needed (i.e. some variable escaped)
#ifdef RAVI_DEFER_STATEMENT
if (raviX_ptrlist_size((const PtrList *)fn->proc->procs) > 0) { if (raviX_ptrlist_size((const PtrList *)fn->proc->procs) > 0) {
raviX_buffer_add_string(&fn->body, "{\nluaF_close(L, base, LUA_OK);\n"); raviX_buffer_add_string(&fn->body, "{\nluaF_close(L, base, LUA_OK);\n");
raviX_buffer_add_string(&fn->body, "base = ci->u.l.base;\n"); raviX_buffer_add_string(&fn->body, "base = ci->u.l.base;\n");
raviX_buffer_add_string(&fn->body, "}\n"); raviX_buffer_add_string(&fn->body, "}\n");
} }
#else
if (raviX_ptrlist_size((const PtrList *)fn->proc->procs) > 0) {
raviX_buffer_add_string(&fn->body, "luaF_close(L, base);\n");
}
#endif
raviX_buffer_add_string(&fn->body, "{\n"); raviX_buffer_add_string(&fn->body, "{\n");
/* Results are copied to stack position given by ci->func and above. /* Results are copied to stack position given by ci->func and above.
* stackbase is set here so S(n) refers to (stackbase+n) * stackbase is set here so S(n) refers to (stackbase+n)
@ -1919,12 +1903,8 @@ static int emit_op_close(struct function *fn, Instruction *insn)
raviX_buffer_add_string(&fn->body, "{\n TValue *clsvar = "); raviX_buffer_add_string(&fn->body, "{\n TValue *clsvar = ");
emit_reg_accessor(fn, pseudo, 0); emit_reg_accessor(fn, pseudo, 0);
raviX_buffer_add_string(&fn->body, ";\n"); raviX_buffer_add_string(&fn->body, ";\n");
#ifdef RAVI_DEFER_STATEMENT
raviX_buffer_add_string(&fn->body, " luaF_close(L, clsvar, LUA_OK);\n"); raviX_buffer_add_string(&fn->body, " luaF_close(L, clsvar, LUA_OK);\n");
emit_reload_base(fn); emit_reload_base(fn);
#else
raviX_buffer_add_string(&fn->body, " luaF_close(L, clsvar);\n");
#endif
raviX_buffer_add_string(&fn->body, "}\n"); raviX_buffer_add_string(&fn->body, "}\n");
return 0; return 0;
} }

@ -75,11 +75,9 @@ static int luaB_auxwrap (lua_State *L) {
lua_State *co = lua_tothread(L, lua_upvalueindex(1)); lua_State *co = lua_tothread(L, lua_upvalueindex(1));
int r = auxresume(L, co, lua_gettop(L)); int r = auxresume(L, co, lua_gettop(L));
if (r < 0) { if (r < 0) {
#ifdef RAVI_DEFER_STATEMENT
int stat = lua_status(co); int stat = lua_status(co);
if (stat != LUA_OK && stat != LUA_YIELD) if (stat != LUA_OK && stat != LUA_YIELD)
lua_resetthread(co); /* close variables in case of errors */ lua_resetthread(co); /* close variables in case of errors */
#endif
if (lua_type(L, -1) == LUA_TSTRING) { /* error object is a string? */ if (lua_type(L, -1) == LUA_TSTRING) { /* error object is a string? */
luaL_where(L, 1); /* add extra info, if available */ luaL_where(L, 1); /* add extra info, if available */
lua_insert(L, -2); lua_insert(L, -2);

@ -104,12 +104,10 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
break; break;
} }
#ifdef RAVI_DEFER_STATEMENT
case CLOSEPROTECT: { case CLOSEPROTECT: {
setnilvalue(oldtop); /* no error message */ setnilvalue(oldtop); /* no error message */
break; break;
} }
#endif
default: { default: {
setobjs2s(L, oldtop, L->top - 1); /* error message on current top */ setobjs2s(L, oldtop, L->top - 1); /* error message on current top */
break; break;
@ -126,9 +124,7 @@ l_noret luaD_throw (lua_State *L, int errcode) {
} }
else { /* thread has no error handler */ else { /* thread has no error handler */
global_State *g = G(L); global_State *g = G(L);
#ifdef RAVI_DEFER_STATEMENT
errcode = luaF_close(L, L->stack, errcode); /* close all upvalues */ errcode = luaF_close(L, L->stack, errcode); /* close all upvalues */
#endif
L->status = cast_byte(errcode); /* mark it as dead */ L->status = cast_byte(errcode); /* mark it as dead */
if (g->mainthread->errorJmp) { /* main thread has a handler? */ if (g->mainthread->errorJmp) { /* main thread has a handler? */
setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */ setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */
@ -690,11 +686,7 @@ static int recover (lua_State *L, int status) {
if (ci == NULL) return 0; /* no recovery point */ if (ci == NULL) return 0; /* no recovery point */
/* "finish" luaD_pcall */ /* "finish" luaD_pcall */
oldtop = restorestack(L, ci->extra); oldtop = restorestack(L, ci->extra);
#ifdef RAVI_DEFER_STATEMENT
luaF_close(L, oldtop, status); luaF_close(L, oldtop, status);
#else
luaF_close(L, oldtop);
#endif
luaD_seterrorobj(L, status, oldtop); luaD_seterrorobj(L, status, oldtop);
L->ci = ci; L->ci = ci;
L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */ L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */
@ -837,18 +829,12 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
status = luaD_rawrunprotected(L, func, u); status = luaD_rawrunprotected(L, func, u);
if (status != LUA_OK) { /* an error occurred? */ if (status != LUA_OK) { /* an error occurred? */
StkId oldtop = restorestack(L, old_top); StkId oldtop = restorestack(L, old_top);
#ifndef RAVI_DEFER_STATEMENT
luaF_close(L, oldtop); /* close possible pending closures */
luaD_seterrorobj(L, status, oldtop);
#endif
L->ci = old_ci; L->ci = old_ci;
L->allowhook = old_allowhooks; L->allowhook = old_allowhooks;
L->nny = old_nny; L->nny = old_nny;
#ifdef RAVI_DEFER_STATEMENT
status = luaF_close(L, oldtop, status); /* close possible pending closures */ status = luaF_close(L, oldtop, status); /* close possible pending closures */
oldtop = restorestack(L, old_top); oldtop = restorestack(L, old_top);
luaD_seterrorobj(L, status, oldtop); luaD_seterrorobj(L, status, oldtop);
#endif
luaD_shrinkstack(L); luaD_shrinkstack(L);
} }
L->errfunc = old_errfunc; L->errfunc = old_errfunc;

@ -68,22 +68,15 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
lua_assert(isintwups(L) || L->openupval == NULL); lua_assert(isintwups(L) || L->openupval == NULL);
while (*pp != NULL && (p = *pp)->v >= level) { while (*pp != NULL && (p = *pp)->v >= level) {
lua_assert(upisopen(p)); lua_assert(upisopen(p));
#ifdef RAVI_DEFER_STATEMENT
if (p->v == level && !p->flags) /* found a corresponding upvalue that is not a deferred value? */ { if (p->v == level && !p->flags) /* found a corresponding upvalue that is not a deferred value? */ {
return p; /* return it */ return p; /* return it */
} }
#else
if (p->v == level) /* found a corresponding upvalue? */
return p; /* return it */
#endif
pp = &p->u.open.next; pp = &p->u.open.next;
} }
/* not found: create a new upvalue */ /* not found: create a new upvalue */
uv = luaM_new(L, UpVal); uv = luaM_new(L, UpVal);
uv->refcount = 0; uv->refcount = 0;
#ifdef RAVI_DEFER_STATEMENT
uv->flags = 0; uv->flags = 0;
#endif
uv->u.open.next = *pp; /* link it to list of open upvalues */ uv->u.open.next = *pp; /* link it to list of open upvalues */
uv->u.open.touched = 1; uv->u.open.touched = 1;
*pp = uv; *pp = uv;
@ -95,7 +88,6 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
return uv; return uv;
} }
#ifdef RAVI_DEFER_STATEMENT
static void calldeferred(lua_State *L, void *ud) { static void calldeferred(lua_State *L, void *ud) {
UNUSED(ud); UNUSED(ud);
luaD_callnoyield(L, L->top - 2, 0); luaD_callnoyield(L, L->top - 2, 0);
@ -176,24 +168,6 @@ int luaF_close (lua_State *L, StkId level, int status) {
} }
return status; return status;
} }
#else
void luaF_close (lua_State *L, StkId level) {
UpVal *uv;
while (L->openupval != NULL && (uv = L->openupval)->v >= level) {
lua_assert(upisopen(uv));
L->openupval = uv->u.open.next; /* remove from 'open' list */
if (uv->refcount == 0) /* no references? */
luaM_free(L, uv); /* free upvalue */
else {
TValue* slot = &uv->u.value; /* new position for value */
setobj(L, slot, uv->v); /* move value to upvalue slot */
uv->v = slot; /* now current value lives here */
luaC_upvalbarrier(L, uv, slot);
}
}
}
#endif
Proto *luaF_newproto (lua_State *L) { Proto *luaF_newproto (lua_State *L) {
GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto)); GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));

@ -32,7 +32,6 @@
#define upisopen(up) ((up)->v != &(up)->u.value) #define upisopen(up) ((up)->v != &(up)->u.value)
#ifdef RAVI_DEFER_STATEMENT
/* /*
** Special "status" for 'luaF_close' ** Special "status" for 'luaF_close'
*/ */
@ -42,18 +41,13 @@
/* close upvalues running all closing methods in protected mode */ /* close upvalues running all closing methods in protected mode */
#define CLOSEPROTECT (-2) #define CLOSEPROTECT (-2)
#endif
LUAI_FUNC Proto *luaF_newproto (lua_State *L); LUAI_FUNC Proto *luaF_newproto (lua_State *L);
LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);
LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);
LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
#ifdef RAVI_DEFER_STATEMENT
LUAI_FUNC int luaF_close (lua_State *L, StkId level, int status); LUAI_FUNC int luaF_close (lua_State *L, StkId level, int status);
#else
LUAI_FUNC void luaF_close (lua_State *L, StkId level);
#endif
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
/* The additional type argument is a Ravi extension */ /* The additional type argument is a Ravi extension */
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,

@ -40,11 +40,7 @@
static const char *const luaX_tokens [] = { static const char *const luaX_tokens [] = {
"and", "break", "do", "else", "elseif", "and", "break", "do", "else", "elseif",
"end", "false", "for", "function", "goto", "if", "end", "false", "for", "function", "goto", "if",
#ifdef RAVI_DEFER_STATEMENT
"in", "local", "defer", "nil", "not", "or", "repeat", "in", "local", "defer", "nil", "not", "or", "repeat",
#else
"in", "local", "nil", "not", "or", "repeat",
#endif
"return", "then", "true", "until", "while", "return", "then", "true", "until", "while",
"//", "..", "...", "==", ">=", "<=", "~=", "//", "..", "...", "==", ">=", "<=", "~=",
"<<", ">>", "::", "<eof>", "<<", ">>", "::", "<eof>",

@ -27,11 +27,7 @@ enum RESERVED {
/* terminal symbols denoted by reserved words */ /* terminal symbols denoted by reserved words */
TK_AND = FIRST_RESERVED, TK_BREAK, TK_AND = FIRST_RESERVED, TK_BREAK,
TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
#ifdef RAVI_DEFER_STATEMENT
TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_DEFER, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_DEFER, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
#else
TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
#endif
TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
/* other terminal symbols */ /* other terminal symbols */
TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,

@ -648,12 +648,8 @@ typedef struct Proto {
typedef struct UpVal { typedef struct UpVal {
TValue *v; /* points to stack or to its own value */ TValue *v; /* points to stack or to its own value */
#ifdef RAVI_DEFER_STATEMENT
unsigned int refcount; /* reference counter */ unsigned int refcount; /* reference counter */
unsigned int flags; /* Used to mark deferred values */ unsigned int flags; /* Used to mark deferred values */
#else
lu_mem refcount; /* reference counter */
#endif
union { union {
struct { /* (when open) */ struct { /* (when open) */
struct UpVal *next; /* linked list */ struct UpVal *next; /* linked list */

@ -165,9 +165,7 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"SELF_SK", /* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */ "SELF_SK", /* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETFIELD", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */ "SETFIELD", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
"GETTABUP_SK", "GETTABUP_SK",
#ifdef RAVI_DEFER_STATEMENT
"DEFER", "DEFER",
#endif
NULL NULL
}; };
@ -319,9 +317,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_SELF_SK */ ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_SELF_SK */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETFIELD */ ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETFIELD */
,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_RAVI_GETTABUP_SK */ ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_RAVI_GETTABUP_SK */
#ifdef RAVI_DEFER_STATEMENT
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_DEFER */ ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_DEFER */
#endif
}; };

@ -290,16 +290,10 @@ OP_RAVI_GETFIELD, /* A B C R(A) := R(B)[RK(C)], string key */
OP_RAVI_SELF_SK, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key */ OP_RAVI_SELF_SK, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key */
OP_RAVI_SETFIELD, /* A B C R(A)[RK(B)] := RK(C), string key */ OP_RAVI_SETFIELD, /* A B C R(A)[RK(B)] := RK(C), string key */
OP_RAVI_GETTABUP_SK, /* A B C R(A) := UpValue[B][RK(C)], string key */ OP_RAVI_GETTABUP_SK, /* A B C R(A) := UpValue[B][RK(C)], string key */
#ifdef RAVI_DEFER_STATEMENT
OP_RAVI_DEFER, /* A mark variable A "deferred" */ OP_RAVI_DEFER, /* A mark variable A "deferred" */
#endif
} OpCode; } OpCode;
#ifdef RAVI_DEFER_STATEMENT
#define NUM_OPCODES (cast(int, OP_RAVI_DEFER) + 1) #define NUM_OPCODES (cast(int, OP_RAVI_DEFER) + 1)
#else
#define NUM_OPCODES (cast(int, OP_RAVI_GETTABUP_SK) + 1)
#endif
/*=========================================================================== /*===========================================================================
Notes: Notes:

@ -981,7 +981,6 @@ static Proto *addprototype (LexState *ls) {
** so that, if it invokes the GC, the GC knows which registers ** so that, if it invokes the GC, the GC knows which registers
** are in use at that time. ** are in use at that time.
*/ */
#ifdef RAVI_DEFER_STATEMENT
static void codeclosure (LexState *ls, expdesc *v, int deferred) { static void codeclosure (LexState *ls, expdesc *v, int deferred) {
FuncState *fs = ls->fs->prev; FuncState *fs = ls->fs->prev;
int pc = -1; int pc = -1;
@ -995,14 +994,6 @@ static void codeclosure (LexState *ls, expdesc *v, int deferred) {
} }
DEBUG_VARS(raviY_printf(ls->fs, "codeclosure -> closure created %e\n", v)); DEBUG_VARS(raviY_printf(ls->fs, "codeclosure -> closure created %e\n", v));
} }
#else
static void codeclosure (LexState *ls, expdesc *v) {
FuncState *fs = ls->fs->prev;
init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1), RAVI_TM_FUNCTION, NULL);
luaK_exp2nextreg(fs, v); /* fix it at the last register */
DEBUG_VARS(raviY_printf(ls->fs, "codeclosure -> closure created %e\n", v));
}
#endif
static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
@ -1363,7 +1354,6 @@ static void parlist (LexState *ls) {
} }
} }
#ifdef RAVI_DEFER_STATEMENT
static void body (LexState *ls, expdesc *e, int ismethod, int line, int deferred) { static void body (LexState *ls, expdesc *e, int ismethod, int line, int deferred) {
/* body -> '(' parlist ')' block END */ /* body -> '(' parlist ')' block END */
FuncState new_fs; FuncState new_fs;
@ -1386,28 +1376,6 @@ static void body (LexState *ls, expdesc *e, int ismethod, int line, int deferred
codeclosure(ls, e, deferred); codeclosure(ls, e, deferred);
close_func(ls); close_func(ls);
} }
#else
static void body (LexState *ls, expdesc *e, int ismethod, int line) {
/* body -> '(' parlist ')' block END */
FuncState new_fs;
BlockCnt bl;
new_fs.f = addprototype(ls);
new_fs.f->linedefined = line;
open_func(ls, &new_fs, &bl);
checknext(ls, '(');
if (ismethod) {
new_localvarliteral(ls, "self"); /* create 'self' parameter */
adjustlocalvars(ls, 1);
}
parlist(ls);
checknext(ls, ')');
statlist(ls);
new_fs.f->lastlinedefined = ls->linenumber;
check_match(ls, TK_END, TK_FUNCTION, line);
codeclosure(ls, e);
close_func(ls);
}
#endif
/* parse expression list */ /* parse expression list */
static int explist (LexState *ls, expdesc *v) { static int explist (LexState *ls, expdesc *v) {
@ -1699,11 +1667,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
} }
case TK_FUNCTION: { case TK_FUNCTION: {
luaX_next(ls); luaX_next(ls);
#ifdef RAVI_DEFER_STATEMENT
body(ls, v, 0, ls->linenumber, 0); body(ls, v, 0, ls->linenumber, 0);
#else
body(ls, v, 0, ls->linenumber);
#endif
return; return;
} }
default: { default: {
@ -2277,7 +2241,6 @@ static void ifstat (LexState *ls, int line) {
} }
/* parse a local function statement - called from statement() */ /* parse a local function statement - called from statement() */
#ifdef RAVI_DEFER_STATEMENT
static void localfunc (LexState *ls, int defer) { static void localfunc (LexState *ls, int defer) {
expdesc b = {.ravi_type_map = RAVI_TM_ANY, .pc = -1}; expdesc b = {.ravi_type_map = RAVI_TM_ANY, .pc = -1};
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
@ -2295,18 +2258,6 @@ static void localfunc (LexState *ls, int defer) {
/* debug information will only see the variable after this point! */ /* debug information will only see the variable after this point! */
getlocvar(fs, b.u.info)->startpc = fs->pc; getlocvar(fs, b.u.info)->startpc = fs->pc;
} }
#else
static void localfunc (LexState *ls) {
expdesc b = {.ravi_type = RAVI_TANY, .pc = -1};
FuncState *fs = ls->fs;
/* RAVI change - add type */
new_localvar(ls, str_checkname(ls), RAVI_TFUNCTION, NULL); /* new local variable */
adjustlocalvars(ls, 1); /* enter its scope */
body(ls, &b, 0, ls->linenumber); /* function created in next register */
/* debug information will only see the variable after this point! */
getlocvar(fs, b.u.info)->startpc = fs->pc;
}
#endif
/* parse a local variable declaration statement - called from statement() */ /* parse a local variable declaration statement - called from statement() */
static void localstat (LexState *ls) { static void localstat (LexState *ls) {
@ -2366,11 +2317,7 @@ static void funcstat (LexState *ls, int line) {
luaX_next(ls); /* skip FUNCTION */ luaX_next(ls); /* skip FUNCTION */
ismethod = funcname(ls, &v); ismethod = funcname(ls, &v);
DEBUG_VARS(raviY_printf(ls->fs, "funcstat -> declaring function %e\n", &v)); DEBUG_VARS(raviY_printf(ls->fs, "funcstat -> declaring function %e\n", &v));
#ifdef RAVI_DEFER_STATEMENT
body(ls, &b, ismethod, line, 0); body(ls, &b, ismethod, line, 0);
#else
body(ls, &b, ismethod, line);
#endif
luaK_storevar(ls->fs, &v, &b); luaK_storevar(ls->fs, &v, &b);
luaK_fixline(ls->fs, line); /* definition "happens" in the first line */ luaK_fixline(ls->fs, line); /* definition "happens" in the first line */
} }
@ -2463,22 +2410,16 @@ static void statement (LexState *ls) {
case TK_LOCAL: { /* stat -> localstat */ case TK_LOCAL: { /* stat -> localstat */
luaX_next(ls); /* skip LOCAL */ luaX_next(ls); /* skip LOCAL */
if (testnext(ls, TK_FUNCTION)) /* local function? */ if (testnext(ls, TK_FUNCTION)) /* local function? */
#ifdef RAVI_DEFER_STATEMENT
localfunc(ls, 0); localfunc(ls, 0);
#else
localfunc(ls);
#endif
else else
localstat(ls); localstat(ls);
break; break;
} }
#ifdef RAVI_DEFER_STATEMENT
case TK_DEFER: { /* stat -> deferstat */ case TK_DEFER: { /* stat -> deferstat */
luaX_next(ls); /* skip DEFER */ luaX_next(ls); /* skip DEFER */
localfunc(ls, 1); localfunc(ls, 1);
break; break;
} }
#endif
case TK_DBCOLON: { /* stat -> label */ case TK_DBCOLON: { /* stat -> label */
luaX_next(ls); /* skip double colon */ luaX_next(ls); /* skip double colon */
labelstat(ls, str_checkname(ls), line); labelstat(ls, str_checkname(ls), line);

@ -258,11 +258,7 @@ void *ravi_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize)
static void close_state (lua_State *L) { static void close_state (lua_State *L) {
global_State *g = G(L); global_State *g = G(L);
#ifdef RAVI_DEFER_STATEMENT
luaF_close(L, L->stack, CLOSEPROTECT); /* close all upvalues for this thread */ luaF_close(L, L->stack, CLOSEPROTECT); /* close all upvalues for this thread */
#else
luaF_close(L, L->stack); /* close all upvalues for this thread */
#endif
luaC_freeallobjects(L); /* collect all objects */ luaC_freeallobjects(L); /* collect all objects */
if (g->version) /* closing a fully built state? */ if (g->version) /* closing a fully built state? */
luai_userstateclose(L); luai_userstateclose(L);
@ -310,18 +306,13 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
void luaE_freethread (lua_State *L, lua_State *L1) { void luaE_freethread (lua_State *L, lua_State *L1) {
LX *l = fromstate(L1); LX *l = fromstate(L1);
#ifdef RAVI_DEFER_STATEMENT
luaF_close(L1, L1->stack, NOCLOSINGMETH); /* close all upvalues for this thread */ luaF_close(L1, L1->stack, NOCLOSINGMETH); /* close all upvalues for this thread */
#else
luaF_close(L1, L1->stack); /* close all upvalues for this thread */
#endif
lua_assert(L1->openupval == NULL); lua_assert(L1->openupval == NULL);
luai_userstatefree(L, L1); luai_userstatefree(L, L1);
freestack(L1); freestack(L1);
luaM_free(L, l); luaM_free(L, l);
} }
#ifdef RAVI_DEFER_STATEMENT
int lua_resetthread (lua_State *L) { int lua_resetthread (lua_State *L) {
CallInfo *ci; CallInfo *ci;
int status; int status;
@ -342,7 +333,6 @@ int lua_resetthread (lua_State *L) {
lua_unlock(L); lua_unlock(L);
return status; return status;
} }
#endif
/* TODO following should probably not live here*/ /* TODO following should probably not live here*/

@ -1090,7 +1090,6 @@ void luaV_finishOp (lua_State *L) {
** Execute a jump instruction. The 'updatemask' allows signals to stop ** Execute a jump instruction. The 'updatemask' allows signals to stop
** tight loops. (Without it, the local copy of 'mask' could never change.) ** tight loops. (Without it, the local copy of 'mask' could never change.)
*/ */
#ifdef RAVI_DEFER_STATEMENT
#define dojump(ci, i, e) \ #define dojump(ci, i, e) \
{ \ { \
int a = GETARG_A(i); \ int a = GETARG_A(i); \
@ -1099,12 +1098,6 @@ void luaV_finishOp (lua_State *L) {
pc += GETARG_sBx(i) + e; \ pc += GETARG_sBx(i) + e; \
updatemask(L); \ updatemask(L); \
} }
#else
#define dojump(ci,i,e) \
{ int a = GETARG_A(i); \
if (a != 0) luaF_close(L, ci->u.l.base + a - 1); \
pc += GETARG_sBx(i) + e; updatemask(L); }
#endif
/* for test instructions, execute the jump instruction that follows it */ /* for test instructions, execute the jump instruction that follows it */
#define donextjump(ci) { i = *pc; dojump(ci, i, 1); } #define donextjump(ci) { i = *pc; dojump(ci, i, 1); }
@ -1382,9 +1375,7 @@ int luaV_execute (lua_State *L) {
&&vmlabel(OP_RAVI_SELF_SK), &&vmlabel(OP_RAVI_SELF_SK),
&&vmlabel(OP_RAVI_SETFIELD), &&vmlabel(OP_RAVI_SETFIELD),
&&vmlabel(OP_RAVI_GETTABUP_SK), &&vmlabel(OP_RAVI_GETTABUP_SK),
#ifdef RAVI_DEFER_STATEMENT
&&vmlabel(OP_RAVI_DEFER), &&vmlabel(OP_RAVI_DEFER),
#endif
}; };
#endif #endif
@ -1829,12 +1820,8 @@ int luaV_execute (lua_State *L) {
StkId lim = nci->u.l.base + getproto(nfunc)->numparams; StkId lim = nci->u.l.base + getproto(nfunc)->numparams;
int aux; int aux;
/* close all upvalues from previous call */ /* close all upvalues from previous call */
#ifdef RAVI_DEFER_STATEMENT
if (cl->p->sizep > 0) if (cl->p->sizep > 0)
Protect_base(luaF_close(L, oci->u.l.base, NOCLOSINGMETH)); Protect_base(luaF_close(L, oci->u.l.base, NOCLOSINGMETH));
#else
if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);
#endif
/* move new frame into old one */ /* move new frame into old one */
for (aux = 0; nfunc + aux < lim; aux++) for (aux = 0; nfunc + aux < lim; aux++)
setobjs2s(L, ofunc + aux, nfunc + aux); setobjs2s(L, ofunc + aux, nfunc + aux);
@ -1851,14 +1838,10 @@ int luaV_execute (lua_State *L) {
} }
vmcase(OP_RETURN) { vmcase(OP_RETURN) {
int b = GETARG_B(i); int b = GETARG_B(i);
#ifdef RAVI_DEFER_STATEMENT
if (cl->p->sizep > 0) { if (cl->p->sizep > 0) {
Protect_base(luaF_close(L, base, LUA_OK)); Protect_base(luaF_close(L, base, LUA_OK));
ra = RA(i); ra = RA(i);
} }
#else
if (cl->p->sizep > 0) luaF_close(L, base);
#endif
savepc(L); savepc(L);
int nres = (b != 0 ? b - 1 : cast_int(L->top - ra)); int nres = (b != 0 ? b - 1 : cast_int(L->top - ra));
b = luaD_poscall(L, ci, ra, nres); b = luaD_poscall(L, ci, ra, nres);
@ -2663,14 +2646,12 @@ int luaV_execute (lua_State *L) {
luaG_runerror(L, "number[] expected"); luaG_runerror(L, "number[] expected");
vmbreak; vmbreak;
} }
#ifdef RAVI_DEFER_STATEMENT
vmcase(OP_RAVI_DEFER) { vmcase(OP_RAVI_DEFER) {
UpVal *up = luaF_findupval(L, ra); /* create new upvalue */ UpVal *up = luaF_findupval(L, ra); /* create new upvalue */
up->flags = 1; /* mark it as deferred */ up->flags = 1; /* mark it as deferred */
setnilvalue(ra); /* initialize it with nil */ setnilvalue(ra); /* initialize it with nil */
vmbreak; vmbreak;
} }
#endif
} }
} }
} }
@ -3207,7 +3188,6 @@ void raviV_op_totype(lua_State *L, TValue *ra, TValue *rb) {
luaG_runerror(L, "type mismatch: expected %s", getstr(key)); luaG_runerror(L, "type mismatch: expected %s", getstr(key));
} }
#ifdef RAVI_DEFER_STATEMENT
/* /*
** OP_RAVI_DEFER ** OP_RAVI_DEFER
*/ */
@ -3216,7 +3196,6 @@ void raviV_op_defer(lua_State *L, TValue *ra) {
up->flags = 1; /* mark it as deferred */ up->flags = 1; /* mark it as deferred */
setnilvalue(ra); /* initialize it with nil */ setnilvalue(ra); /* initialize it with nil */
} }
#endif
/* }================================================================== */ /* }================================================================== */

@ -174,9 +174,7 @@ LUAI_FUNC void raviV_settable_i(lua_State *L, const TValue *t, TValue *key, StkI
LUAI_FUNC void raviV_op_totype(lua_State *L, TValue *ra, TValue *rb); LUAI_FUNC void raviV_op_totype(lua_State *L, TValue *ra, TValue *rb);
LUAI_FUNC int raviV_checktype(lua_State *L, TValue *input, ravi_type_map type, TString *usertype); LUAI_FUNC int raviV_checktype(lua_State *L, TValue *input, ravi_type_map type, TString *usertype);
LUAI_FUNC int raviV_check_usertype(lua_State *L, TString *name, const TValue *o); LUAI_FUNC int raviV_check_usertype(lua_State *L, TString *name, const TValue *o);
#ifdef RAVI_DEFER_STATEMENT
LUAI_FUNC void raviV_op_defer(lua_State *L, TValue *ra); LUAI_FUNC void raviV_op_defer(lua_State *L, TValue *ra);
#endif
LUAI_FUNC void raviV_debug_trace(lua_State *L, int opCode, int pc); LUAI_FUNC void raviV_debug_trace(lua_State *L, int opCode, int pc);
#endif #endif

@ -565,12 +565,8 @@ static const char Lua_header[] =
"};\n" "};\n"
"struct UpVal {\n" "struct UpVal {\n"
" TValue *v;\n" " TValue *v;\n"
#ifdef RAVI_DEFER_STATEMENT
" unsigned int refcount;\n" " unsigned int refcount;\n"
" unsigned int flags;\n" " unsigned int flags;\n"
#else
" lu_mem refcount;\n"
#endif
" union {\n" " union {\n"
" struct {\n" " struct {\n"
" UpVal *next;\n" " UpVal *next;\n"

@ -83,9 +83,7 @@ static LuaFunc Lua_functions[] = {
{ "raviV_settable_sskey", raviV_settable_sskey }, { "raviV_settable_sskey", raviV_settable_sskey },
{ "raviV_gettable_i", raviV_gettable_i }, { "raviV_gettable_i", raviV_gettable_i },
{ "raviV_settable_i", raviV_settable_i }, { "raviV_settable_i", raviV_settable_i },
#ifdef RAVI_DEFER_STATEMENT
{ "raviV_op_defer", raviV_op_defer }, { "raviV_op_defer", raviV_op_defer },
#endif
{ "raviV_op_bnot", raviV_op_bnot}, { "raviV_op_bnot", raviV_op_bnot},
{ "lua_absindex", lua_absindex }, { "lua_absindex", lua_absindex },

Loading…
Cancel
Save