Browse Source

changed types to strict (nil disallowed) in lcode.c

master
Pavel R. 5 months ago
parent
commit
7adbc171f6
2 changed files with 26 additions and 26 deletions
  1. +22
    -22
      src/lcode.c
  2. +4
    -4
      src/lundump.c

+ 22
- 22
src/lcode.c View File

@ -700,11 +700,11 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
break;
default:
luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
if (ravi_type == RAVI_TM_STRING_OR_NIL)
if (ravi_type == RAVI_TM_STRING)
luaK_codeABC(fs, OP_RAVI_TOSTRING, reg, 0, 0);
else if (ravi_type == RAVI_TM_FUNCTION_OR_NIL)
else if (ravi_type == RAVI_TM_FUNCTION)
luaK_codeABC(fs, OP_RAVI_TOCLOSURE, reg, 0, 0);
else if (ravi_type == RAVI_TM_USERDATA_OR_NIL && usertype)
else if (ravi_type == RAVI_TM_USERDATA && usertype)
luaK_codeABx(fs, OP_RAVI_TOTYPE, reg, luaK_stringK(fs, usertype));
break;
}
@ -869,9 +869,9 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
var->ravi_type_map == RAVI_TM_FLOAT_ARRAY ||
var->ravi_type_map == RAVI_TM_INTEGER_ARRAY ||
var->ravi_type_map == RAVI_TM_TABLE ||
var->ravi_type_map == RAVI_TM_STRING_OR_NIL ||
var->ravi_type_map == RAVI_TM_FUNCTION_OR_NIL ||
var->ravi_type_map == RAVI_TM_USERDATA_OR_NIL)) {
var->ravi_type_map == RAVI_TM_STRING ||
var->ravi_type_map == RAVI_TM_FUNCTION ||
var->ravi_type_map == RAVI_TM_USERDATA)) {
/* handled by MOVEI, MOVEF, MOVEIARRAY, MOVEFARRAY at runtime */
return;
}
@ -913,8 +913,8 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
"Invalid assignment: %s expected",
var->ravi_type_map == RAVI_TM_TABLE ? "table" : (var->ravi_type_map == RAVI_TM_FLOAT_ARRAY ? "number[]" : "integer[]")));
}
else if (var->ravi_type_map == RAVI_TM_STRING_OR_NIL) {
if ((ex_ravi_type_map & ~RAVI_TM_STRING_OR_NIL) == 0)
else if (var->ravi_type_map == RAVI_TM_STRING) {
if ((ex_ravi_type_map & ~RAVI_TM_STRING) == 0)
return;
luaX_syntaxerror(
fs->ls,
@ -922,8 +922,8 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
fs->ls->L,
"Invalid assignment: string expected"));
}
else if (var->ravi_type_map == RAVI_TM_FUNCTION_OR_NIL) {
if ((ex_ravi_type_map & ~RAVI_TM_FUNCTION_OR_NIL) == 0)
else if (var->ravi_type_map == RAVI_TM_FUNCTION) {
if ((ex_ravi_type_map & ~RAVI_TM_FUNCTION) == 0)
return;
luaX_syntaxerror(
fs->ls,
@ -931,8 +931,8 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
fs->ls->L,
"Invalid assignment: function expected"));
}
else if (var->ravi_type_map == RAVI_TM_USERDATA_OR_NIL) {
if ((ex_ravi_type_map & ~RAVI_TM_USERDATA_OR_NIL) == 0 &&
else if (var->ravi_type_map == RAVI_TM_USERDATA) {
if ((ex_ravi_type_map & ~RAVI_TM_USERDATA) == 0 &&
(!(ex_ravi_type_map & RAVI_TM_USERDATA) || (var->usertype && var->usertype == ex->usertype)))
return;
luaX_syntaxerror(
@ -948,8 +948,8 @@ static OpCode check_valid_setupval(FuncState *fs, expdesc *var, expdesc *ex,
OpCode op = OP_SETUPVAL;
if ((var->ravi_type_map == RAVI_TM_INTEGER || var->ravi_type_map == RAVI_TM_FLOAT ||
var->ravi_type_map == RAVI_TM_INTEGER_ARRAY || var->ravi_type_map == RAVI_TM_FLOAT_ARRAY ||
var->ravi_type_map == RAVI_TM_TABLE || var->ravi_type_map == RAVI_TM_STRING_OR_NIL ||
var->ravi_type_map == RAVI_TM_FUNCTION_OR_NIL || var->ravi_type_map == RAVI_TM_USERDATA_OR_NIL) &&
var->ravi_type_map == RAVI_TM_TABLE || var->ravi_type_map == RAVI_TM_STRING ||
var->ravi_type_map == RAVI_TM_FUNCTION || var->ravi_type_map == RAVI_TM_USERDATA) &&
ex->ravi_type_map & ~var->ravi_type_map) {
if (var->ravi_type_map == RAVI_TM_INTEGER)
op = OP_RAVI_SETUPVALI;
@ -961,11 +961,11 @@ static OpCode check_valid_setupval(FuncState *fs, expdesc *var, expdesc *ex,
op = OP_RAVI_SETUPVAL_FARRAY;
else if (var->ravi_type_map == RAVI_TM_TABLE)
op = OP_RAVI_SETUPVALT;
else if (var->ravi_type_map == RAVI_TM_STRING_OR_NIL)
else if (var->ravi_type_map == RAVI_TM_STRING)
luaK_codeABC(fs, OP_RAVI_TOSTRING, reg, 0, 0);
else if (var->ravi_type_map == RAVI_TM_FUNCTION_OR_NIL)
else if (var->ravi_type_map == RAVI_TM_FUNCTION)
luaK_codeABC(fs, OP_RAVI_TOCLOSURE, reg, 0, 0);
else if (var->ravi_type_map == RAVI_TM_USERDATA_OR_NIL) {
else if (var->ravi_type_map == RAVI_TM_USERDATA) {
TString *usertype = fs->f->upvalues[var->u.info].usertype;
luaK_codeABx(fs, OP_RAVI_TOTYPE, reg, luaK_stringK(fs, usertype));
}
@ -1547,17 +1547,17 @@ static void code_type_assertion(FuncState *fs, UnOpr op, expdesc *e, TString *us
opcode = OP_RAVI_TOTAB;
tm = RAVI_TM_TABLE;
}
else if (op == OPR_TO_STRING && (e->ravi_type_map & (~RAVI_TM_STRING_OR_NIL)) != 0) {
else if (op == OPR_TO_STRING && (e->ravi_type_map & (~RAVI_TM_STRING)) != 0) {
opcode = OP_RAVI_TOSTRING;
tm = RAVI_TM_STRING_OR_NIL;
tm = RAVI_TM_STRING;
}
else if (op == OPR_TO_CLOSURE && (e->ravi_type_map & (~RAVI_TM_FUNCTION_OR_NIL)) != 0) {
else if (op == OPR_TO_CLOSURE && (e->ravi_type_map & (~RAVI_TM_FUNCTION)) != 0) {
opcode = OP_RAVI_TOCLOSURE;
tm = RAVI_TM_FUNCTION_OR_NIL;
tm = RAVI_TM_FUNCTION;
}
else if (op == OPR_TO_TYPE) {
opcode = OP_RAVI_TOTYPE;
tm = RAVI_TM_USERDATA_OR_NIL;
tm = RAVI_TM_USERDATA;
}
else {
/* nothing to do*/


+ 4
- 4
src/lundump.c View File

@ -192,12 +192,12 @@ static ravi_type_map ravi_map_old_type_to_new(lu_byte type) {
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_OR_NIL;
case 5: return RAVI_TM_FUNCTION;
case 6: return RAVI_TM_TABLE;
case 7: return RAVI_TM_STRING_OR_NIL;
case 7: return RAVI_TM_STRING;
case 8: return RAVI_TM_NIL;
case 9: return RAVI_TM_BOOLEAN_OR_NIL;
case 10: return RAVI_TM_USERDATA_OR_NIL;
case 9: return RAVI_TM_BOOLEAN;
case 10: return RAVI_TM_USERDATA;
default: return RAVI_TM_ANY;
}
}


Loading…
Cancel
Save