diff --git a/ravicomp/src/codegen.c b/ravicomp/src/codegen.c index 4acf87d..df80dcc 100644 --- a/ravicomp/src/codegen.c +++ b/ravicomp/src/codegen.c @@ -313,22 +313,58 @@ static const char Lua_header[] = " io->value_ = iu->user_; settt_(io, iu->ttuv_); \\\n" " checkliveness(L,io); }\n" "typedef enum {\n" - " RAVI_TANY = 0,\n" - " RAVI_TNUMINT = 1,\n" - " RAVI_TNUMFLT,\n" - " RAVI_TARRAYINT,\n" - " RAVI_TARRAYFLT,\n" - " RAVI_TFUNCTION,\n" - " RAVI_TTABLE,\n" - " RAVI_TSTRING,\n" - " RAVI_TNIL,\n" - " RAVI_TBOOLEAN,\n" - " RAVI_TUSERDATA\n" + "RAVI_TI_NIL,\n" + "RAVI_TI_FALSE,\n" + "RAVI_TI_TRUE,\n" + "RAVI_TI_INTEGER,\n" + "RAVI_TI_FLOAT,\n" + "RAVI_TI_INTEGER_ARRAY,\n" + "RAVI_TI_FLOAT_ARRAY,\n" + "RAVI_TI_TABLE,\n" + "RAVI_TI_STRING,\n" + "RAVI_TI_FUNCTION,\n" + "RAVI_TI_USERDATA,\n" + "RAVI_TI_OTHER\n" + "} ravi_type_index;\n" + "typedef uint32_t ravi_type_map;\n" + "#define RAVI_TM_NIL (((ravi_type_map)1)<top - 1; - int compatible = ravi_checktype(L, input, type, usertype); + int compatible = raviV_checktype(L, input, type, usertype); if (compatible) { setobjs2s(L, pos, L->top - 1); L->top--; /* pop value */ diff --git a/src/ldump.c b/src/ldump.c index f6a57de..ad522aa 100644 --- a/src/ldump.c +++ b/src/ldump.c @@ -150,23 +150,6 @@ static void DumpUpvalues (const Proto *f, DumpState *D) { } } -static lu_byte ravi_type_map_to_old_type(ravi_type_map type_map) { - switch (type_map) { - case RAVI_TM_ANY: return 0; - case RAVI_TM_INTEGER: return 1; - case RAVI_TM_FLOAT: return 2; - case RAVI_TM_INTEGER_ARRAY: return 3; - case RAVI_TM_FLOAT_ARRAY: return 4; - case RAVI_TM_FUNCTION | RAVI_TM_NIL: return 5; - case RAVI_TM_TABLE: return 6; - case RAVI_TM_STRING | RAVI_TM_NIL: return 7; - case RAVI_TM_NIL: return 8; - case RAVI_TM_BOOLEAN | RAVI_TM_NIL: return 9; - case RAVI_TM_USERDATA | RAVI_TM_NIL: return 10; - default: return 0; - } -} - static void DumpDebug (const Proto *f, DumpState *D) { int i, n; n = (D->strip) ? 0 : f->sizelineinfo; @@ -179,7 +162,7 @@ static void DumpDebug (const Proto *f, DumpState *D) { DumpString((D->strip) ? NULL : f->locvars[i].varname, D); DumpInt(f->locvars[i].startpc, D); DumpInt(f->locvars[i].endpc, D); - DumpByte(ravi_type_map_to_old_type(f->locvars[i].ravi_type_map), D); + DumpInt(f->locvars[i].ravi_type_map, D); DumpString(f->locvars[i].usertype, D); } /* n = (D->strip) ? 0 : f->sizeupvalues; */ @@ -187,7 +170,7 @@ static void DumpDebug (const Proto *f, DumpState *D) { DumpInt(n, D); for (i = 0; i < n; i++) { DumpString((D->strip) ? NULL : f->upvalues[i].name, D); - DumpByte(ravi_type_map_to_old_type(f->upvalues[i].ravi_type_map), D); + DumpInt(f->upvalues[i].ravi_type_map, D); DumpString(f->upvalues[i].usertype, D); } } diff --git a/src/lobject.c b/src/lobject.c index 2b26be2..24a20a1 100644 --- a/src/lobject.c +++ b/src/lobject.c @@ -33,24 +33,6 @@ LUAI_DDEF const TValue luaO_nilobject_ = {NILCONSTANT}; -int ravi_checktype(lua_State *L, StkId input, ravi_type_map type, TString* usertype) { - if (type == RAVI_TM_ANY) return 1; - if (type & RAVI_TM_NIL && ttisnil(input)) return 1; - if (type & RAVI_TM_FALSE && ttisboolean(input) && l_isfalse(input)) return 1; - if (type & RAVI_TM_TRUE && ttisboolean(input) && !l_isfalse(input)) return 1; - if (type & RAVI_TM_INTEGER && ttisinteger(input)) return 1; - if (type & RAVI_TM_FLOAT && ttisfloat(input)) return 1; - if (type & RAVI_TM_INTEGER_ARRAY && ttisiarray(input)) return 1; - if (type & RAVI_TM_FLOAT_ARRAY && ttisfarray(input)) return 1; - if (type & RAVI_TM_TABLE && ttisLtable(input)) return 1; - if (type & RAVI_TM_STRING && ttisstring(input)) return 1; - if (type & RAVI_TM_FUNCTION && ttisclosure(input)) return 1; - if (type & RAVI_TM_USERDATA) { - if (raviV_check_usertype(L, usertype, input)) return 1; - } - return 0; -} - /* ** converts an integer to a "floating point byte", represented as ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if diff --git a/src/lobject.h b/src/lobject.h index 34ce3b5..49dd297 100644 --- a/src/lobject.h +++ b/src/lobject.h @@ -92,6 +92,23 @@ typedef uint32_t ravi_type_map; #define RAVI_TM_INDEXABLE (RAVI_TM_INTEGER_ARRAY | RAVI_TM_FLOAT_ARRAY | RAVI_TM_TABLE) #define RAVI_TM_ANY (~0) +typedef enum { + RAVI_TNIL = RAVI_TM_NIL, /* NIL */ + RAVI_TNUMINT = RAVI_TM_INTEGER, /* integer number */ + RAVI_TNUMFLT = RAVI_TM_FLOAT, /* floating point number */ + RAVI_TNUMBER = RAVI_TM_NUMBER, + RAVI_TARRAYINT = RAVI_TM_INTEGER_ARRAY, /* array of ints */ + RAVI_TARRAYFLT = RAVI_TM_FLOAT_ARRAY, /* array of doubles */ + RAVI_TTABLE = RAVI_TM_TABLE, /* Lua table */ + RAVI_TSTRING = RAVI_TM_STRING | RAVI_TM_NIL, /* string */ + RAVI_TFUNCTION = RAVI_TM_FUNCTION | RAVI_TM_NIL, /* Lua or C Function */ + RAVI_TBOOLEAN = RAVI_TM_BOOLEAN | RAVI_TM_NIL, /* boolean */ + RAVI_TTRUE = RAVI_TM_TRUE, + RAVI_TFALSE = RAVI_TM_FALSE, + RAVI_TUSERDATA = RAVI_TM_USERDATA | RAVI_TM_NIL, /* userdata or lightuserdata */ + RAVI_TANY = RAVI_TM_ANY, /* Lua dynamic type */ +} ravitype_t; + /* ** Tagged Values. This is the basic representation of values in Lua, ** an actual value plus a tag with its type. diff --git a/src/lundump.c b/src/lundump.c index 0f9f068..9ecfc25 100644 --- a/src/lundump.c +++ b/src/lundump.c @@ -183,24 +183,6 @@ static void LoadUpvalues (LoadState *S, Proto *f) { } } -static ravi_type_map ravi_old_type_to_type_map(lu_byte old) { - switch (old) { - case 0: return RAVI_TM_ANY; - case 1: return RAVI_TM_INTEGER; - case 2: return RAVI_TM_FLOAT; - case 3: return RAVI_TM_INTEGER_ARRAY; - case 4: return RAVI_TM_FLOAT_ARRAY; - case 5: return RAVI_TM_FUNCTION | RAVI_TM_NIL; - case 6: return RAVI_TM_TABLE; - case 7: return RAVI_TM_STRING | RAVI_TM_NIL; - case 8: return RAVI_TM_NIL; - case 9: return RAVI_TM_BOOLEAN | RAVI_TM_NIL; - case 10: return RAVI_TM_USERDATA | RAVI_TM_NIL; - default: return RAVI_TM_ANY; - } -} - - static void LoadDebug (LoadState *S, Proto *f) { int i, n; n = LoadInt(S); @@ -218,13 +200,13 @@ static void LoadDebug (LoadState *S, Proto *f) { f->locvars[i].varname = LoadString(S); f->locvars[i].startpc = LoadInt(S); f->locvars[i].endpc = LoadInt(S); - f->locvars[i].ravi_type_map = ravi_old_type_to_type_map(LoadByte(S)); + f->locvars[i].ravi_type_map = LoadInt(S); f->locvars[i].usertype = LoadString(S); } n = LoadInt(S); for (i = 0; i < n; i++) { f->upvalues[i].name = LoadString(S); - f->upvalues[i].ravi_type_map = ravi_old_type_to_type_map(LoadByte(S)); + f->upvalues[i].ravi_type_map = LoadInt(S); f->upvalues[i].usertype = LoadString(S); } } diff --git a/src/lvm.c b/src/lvm.c index a95ecfc..57dd020 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -1204,32 +1204,23 @@ void luaV_finishOp (lua_State *L) { if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \ Protect(luaV_finishset(L,t,k,v,slot)); } -int raviV_checktype(lua_State *L, TValue *input, ravitype_t type, TString *usertype) { - if (type == RAVI_TANY) - return 1; - if (type == RAVI_TNIL && ttisnil(input)) - return 1; - if (type == RAVI_TBOOLEAN && ttisboolean(input)) - return 1; - if (type == RAVI_TNUMINT && ttisinteger(input)) - return 1; - if (type == RAVI_TNUMFLT && ttisfloat(input)) - return 1; - if (type == RAVI_TARRAYINT && ttisiarray(input)) - return 1; - if (type == RAVI_TARRAYFLT && ttisfarray(input)) - return 1; - if (type == RAVI_TTABLE && ttisLtable(input)) - return 1; - if (type == RAVI_TSTRING && ttisstring(input)) - return 1; - if (type == RAVI_TFUNCTION && ttisclosure(input)) - return 1; - if (type == RAVI_TUSERDATA) { - if (raviV_check_usertype(L, usertype, input)) - return 1; +int raviV_checktype(lua_State *L, TValue *input, ravi_type_map type, TString *usertype) { + if (type == RAVI_TM_ANY) return 1; + if (type & RAVI_TM_NIL && ttisnil(input)) return 1; + if (type & RAVI_TM_FALSE && ttisboolean(input) && l_isfalse(input)) return 1; + if (type & RAVI_TM_TRUE && ttisboolean(input) && !l_isfalse(input)) return 1; + if (type & RAVI_TM_INTEGER && ttisinteger(input)) return 1; + if (type & RAVI_TM_FLOAT && ttisfloat(input)) return 1; + if (type & RAVI_TM_INTEGER_ARRAY && ttisiarray(input)) return 1; + if (type & RAVI_TM_FLOAT_ARRAY && ttisfarray(input)) return 1; + if (type & RAVI_TM_TABLE && ttisLtable(input)) return 1; + if (type & RAVI_TM_STRING && ttisstring(input)) return 1; + if (type & RAVI_TM_FUNCTION && ttisclosure(input)) return 1; + if (type & RAVI_TM_USERDATA) { + if (raviV_check_usertype(L, usertype, input)) return 1; } return 0; + } int raviV_check_usertype(lua_State *L, TString *name, const TValue *o) diff --git a/src/lvm.h b/src/lvm.h index 111211e..2d66c5a 100644 --- a/src/lvm.h +++ b/src/lvm.h @@ -172,7 +172,7 @@ LUAI_FUNC void raviV_settable_sskey(lua_State *L, const TValue *t, TValue *key, LUAI_FUNC void raviV_gettable_i(lua_State *L, const TValue *t, TValue *key, StkId val); LUAI_FUNC void raviV_settable_i(lua_State *L, const TValue *t, TValue *key, StkId val); LUAI_FUNC void raviV_op_totype(lua_State *L, TValue *ra, TValue *rb); -LUAI_FUNC int raviV_checktype(lua_State *L, TValue *input, ravitype_t 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); #ifdef RAVI_DEFER_STATEMENT LUAI_FUNC void raviV_op_defer(lua_State *L, TValue *ra); diff --git a/src/ravi_jitshared.c b/src/ravi_jitshared.c index 1a9e7d5..5751da6 100644 --- a/src/ravi_jitshared.c +++ b/src/ravi_jitshared.c @@ -299,10 +299,59 @@ static const char Lua_header[] = " { TValue *io=(o); const Udata *iu = (u); \\\n" " io->value_ = iu->user_; settt_(io, iu->ttuv_); \\\n" " checkliveness(L,io); }\n" + "typedef enum {\n" + "RAVI_TI_NIL,\n" + "RAVI_TI_FALSE,\n" + "RAVI_TI_TRUE,\n" + "RAVI_TI_INTEGER,\n" + "RAVI_TI_FLOAT,\n" + "RAVI_TI_INTEGER_ARRAY,\n" + "RAVI_TI_FLOAT_ARRAY,\n" + "RAVI_TI_TABLE,\n" + "RAVI_TI_STRING,\n" + "RAVI_TI_FUNCTION,\n" + "RAVI_TI_USERDATA,\n" + "RAVI_TI_OTHER\n" + "} ravi_type_index;\n" + "typedef uint32_t ravi_type_map;\n" + "#define RAVI_TM_NIL (((ravi_type_map)1)<