Merge branch 'new_type_info' into type-maps

pull/213/head
Dibyendu Majumdar 3 years ago committed by GitHub
commit 063a55604e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1630,7 +1630,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
*/
StkId input = L->top - 1;
int compatible = ravi_checktype(L, input, type, usertype);
int compatible = raviV_checktype(L, input, type, usertype);
if (!compatible)
name = NULL;

@ -920,7 +920,7 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
fs->ls,
luaO_pushfstring(
fs->ls->L,
"Invalid assignment: string expected"));
"Invalid assignment: string expected"));
}
else if (var->ravi_type_map == (RAVI_TM_FUNCTION | RAVI_TM_NIL)) {
if ((ex_ravi_type_map & ~(RAVI_TM_FUNCTION | RAVI_TM_NIL)) == 0)
@ -929,7 +929,7 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
fs->ls,
luaO_pushfstring(
fs->ls->L,
"Invalid assignment: function expected"));
"Invalid assignment: function expected"));
}
else if (var->ravi_type_map == (RAVI_TM_USERDATA | RAVI_TM_NIL)) {
if ((ex_ravi_type_map & ~(RAVI_TM_USERDATA | RAVI_TM_NIL)) == 0 &&
@ -939,8 +939,8 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
fs->ls,
luaO_pushfstring(
fs->ls->L,
"Invalid assignment: usertype %s expected", (var->usertype ? getstr(var->usertype) : "UNKNOWN")));
}
"Invalid assignment: usertype %s expected", (var->usertype ? getstr(var->usertype) : "UNKNOWN")));
}
}
static OpCode check_valid_setupval(FuncState *fs, expdesc *var, expdesc *ex,

@ -1223,30 +1223,30 @@ static void constructor (LexState *ls, expdesc *t) {
* be anchored somewhere else by the time parsing finishes
*/
static TString *user_defined_type_name(LexState *ls, TString *typename) {
size_t len = 0;
if (testnext(ls, '.')) {
char buffer[128] = { 0 };
const char *str = getstr(typename);
len = strlen(str);
if (len >= sizeof buffer) {
luaX_syntaxerror(ls, "User defined type name is too long");
return typename;
}
snprintf(buffer, sizeof buffer, "%s", str);
do {
typename = str_checkname(ls);
str = getstr(typename);
size_t newlen = len + strlen(str) + 1;
if (newlen >= sizeof buffer) {
luaX_syntaxerror(ls, "User defined type name is too long");
return typename;
}
snprintf(buffer + len, sizeof buffer - len, ".%s", str);
len = newlen;
} while (testnext(ls, '.'));
typename = luaX_newstring(ls, buffer, strlen(buffer));
}
return typename;
size_t len = 0;
if (testnext(ls, '.')) {
char buffer[128] = {0};
const char *str = getstr(typename);
len = strlen(str);
if (len >= sizeof buffer) {
luaX_syntaxerror(ls, "User defined type name is too long");
return typename;
}
snprintf(buffer, sizeof buffer, "%s", str);
do {
typename = str_checkname(ls);
str = getstr(typename);
size_t newlen = len + strlen(str) + 1;
if (newlen >= sizeof buffer) {
luaX_syntaxerror(ls, "User defined type name is too long");
return typename;
}
snprintf(buffer + len, sizeof buffer - len, ".%s", str);
len = newlen;
} while (testnext(ls, '.'));
typename = luaX_newstring(ls, buffer, strlen(buffer));
}
return typename;
}
/* RAVI Parse
@ -1279,8 +1279,8 @@ static ravi_type_map declare_localvar(LexState *ls, TString **pusertype) {
tm = RAVI_TM_TABLE;
else if (strcmp(str, "string") == 0)
tm = RAVI_TM_STRING | RAVI_TM_NIL;
else if (strcmp(str, "boolean") == 0)
tm = RAVI_TM_BOOLEAN | RAVI_TM_NIL;
//else if (strcmp(str, "boolean") == 0)
// tm = RAVI_TM_BOOLEAN | RAVI_TM_NIL;
else if (strcmp(str, "any") == 0)
tm = RAVI_TM_ANY;
else {

@ -1204,6 +1204,33 @@ 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;
}
return 0;
}
int raviV_check_usertype(lua_State *L, TString *name, const TValue *o)
{

@ -172,6 +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_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);

@ -1,5 +1,5 @@
f = compiler.load([[
function doit(a, 25_bits.luawhat)
function doit(a, what)
local f: integer = ~0
if what == '&' then
return a&f
@ -25,4 +25,4 @@ assert(math.abs(doit(16, '|') - ~0) < 1e-15)
assert(math.abs(doit(16, '<<') - 32) < 1e-15)
assert(math.abs(doit(16, '>>') - 8) < 1e-15)
assert(math.abs(doit(16, '~') - ~16) < 1e-15)
print 'Ok'
print 'Ok'

@ -1842,6 +1842,42 @@ do
end
print 'Test 87 OK'
do
local function doit(a: integer, what)
local f: integer = ~0
if what == '&' then
return a&f
elseif what == '|' then
return a|f
elseif what == '<<' then
return a<<1
elseif what == '>>' then
return a>>1
elseif what == '~' then
return ~a
else
return 0
end
end
check(doit, 'TOINT', 'LOADK', 'EQ', 'JMP', 'BAND_II',
'RETURN', 'JMP', 'EQ', 'JMP', 'BOR_II', 'RETURN',
'JMP', 'EQ', 'JMP', 'SHL_II', 'RETURN', 'JMP', 'EQ',
'JMP', 'SHR_II', 'RETURN', 'JMP', 'EQ', 'JMP',
'BNOT_I', 'RETURN', 'JMP', 'LOADK', 'RETURN', 'RETURN')
assert(doit and type(doit) == 'function')
assert(math.abs(doit(16, '&') - 16) < 1e-15)
assert(math.abs(doit(16, '|') - ~0) < 1e-15)
assert(math.abs(doit(16, '<<') - 32) < 1e-15)
assert(math.abs(doit(16, '>>') - 8) < 1e-15)
assert(math.abs(doit(16, '~') - ~16) < 1e-15)
compile(doit)
assert(math.abs(doit(16, '&') - 16) < 1e-15)
assert(math.abs(doit(16, '|') - ~0) < 1e-15)
assert(math.abs(doit(16, '<<') - 32) < 1e-15)
assert(math.abs(doit(16, '>>') - 8) < 1e-15)
assert(math.abs(doit(16, '~') - ~16) < 1e-15)
end
print 'Test 88 OK'
for k,v in pairs(opcodes_coverage)
do

Loading…
Cancel
Save