@ -566,7 +566,10 @@ static void ravi_code_typecoersion(LexState *ls, int reg, ravitype_t ravi_type)
luaK_codeABC ( ls - > fs , ravi_type = = RAVI_TARRAYINT ? OP_RAVI_TOARRAYI
: OP_RAVI_TOARRAYF ,
reg , 0 , 0 ) ;
// TODO handle table, string, function, userdata, boolean types
else if ( ravi_type = = RAVI_TTABLE )
luaK_codeABC ( ls - > fs , OP_RAVI_TOTAB ,
reg , 0 , 0 ) ;
// TODO handle string, function, userdata, boolean types
}
/* RAVI code an instruction to initialize a typed value */
@ -1086,7 +1089,7 @@ static void constructor (LexState *ls, expdesc *t) {
struct ConsControl cc ;
cc . na = cc . nh = cc . tostore = 0 ;
cc . t = t ;
init_exp ( t , VRELOCABLE , pc , RAVI_T ANY ) ; /* RAVI TODO - set table of type */
init_exp ( t , VRELOCABLE , pc , RAVI_T TABLE ) ; /* RAVI TODO - set table of type */
init_exp ( & cc . v , VVOID , 0 , RAVI_TANY ) ; /* no value (yet) */
luaK_exp2nextreg ( ls - > fs , t ) ; /* fix it at stack top */
checknext ( ls , ' { ' ) ;
@ -1222,9 +1225,10 @@ static int explist (LexState *ls, expdesc *v) {
/* TODO instead of using vars here could we just rely upon register_typeinfo? */
static void ravi_typecheck ( LexState * ls , expdesc * v , int * vars , int nvars ,
int n ) {
if ( n < nvars & & vars [ n ] ! = RAVI_TANY & & v - > ravi_type ! = vars [ n ] ) {
if ( v - > ravi_type ! = vars [ n ] & &
( vars [ n ] = = RAVI_TARRAYFLT | | vars [ n ] = = RAVI_TARRAYINT ) & &
ravitype_t vartype = vars [ n ] ;
if ( n < nvars & & vartype ! = RAVI_TANY & & v - > ravi_type ! = vartype ) {
if ( v - > ravi_type ! = vartype & &
( vartype = = RAVI_TARRAYFLT | | vartype = = RAVI_TARRAYINT ) & &
v - > k = = VNONRELOC ) {
/* as the bytecode for generating a table is already emitted by this stage
* we have to amend the generated byte code - not sure if there is a
@ -1246,7 +1250,7 @@ static void ravi_typecheck(LexState *ls, expdesc *v, int *vars, int nvars,
if ( reg ! = v - > u . info )
continue ;
op =
( var s[ n ] = = RAVI_TARRAYINT ) ? OP_RAVI_NEWARRAYI : OP_RAVI_NEWARRAYF ;
( var type = = RAVI_TARRAYINT ) ? OP_RAVI_NEWARRAYI : OP_RAVI_NEWARRAYF ;
SET_OPCODE ( * pc , op ) ; /* modify opcode */
DEBUG_CODEGEN (
raviY_printf ( ls - > fs , " [%d]* %o ; modify opcode \n " , i , * pc ) ) ;
@ -1256,9 +1260,10 @@ static void ravi_typecheck(LexState *ls, expdesc *v, int *vars, int nvars,
luaX_syntaxerror ( ls , " expecting array initializer " ) ;
}
/* if we are calling a function then convert return types */
else if ( v - > ravi_type ! = vars [ n ] & &
( vars [ n ] = = RAVI_TNUMFLT | | vars [ n ] = = RAVI_TNUMINT | |
vars [ n ] = = RAVI_TARRAYFLT | | vars [ n ] = = RAVI_TARRAYINT ) & &
else if ( v - > ravi_type ! = vartype & &
( vartype = = RAVI_TNUMFLT | | vartype = = RAVI_TNUMINT | |
vartype = = RAVI_TARRAYFLT | | vartype = = RAVI_TARRAYINT | |
vartype = = RAVI_TTABLE ) & &
v - > k = = VCALL ) {
/* For local variable declarations that call functions e.g.
* local i = func ( )
@ -1284,13 +1289,14 @@ static void ravi_typecheck(LexState *ls, expdesc *v, int *vars, int nvars,
for ( i = n ; i < ( n + nrets ) ; i + + )
/* do we need to convert ? */
ravi_code_typecoersion ( ls , a + ( i - n ) , vars [ i ] ) ;
} else if ( ( var s[ n ] = = RAVI_TNUMFLT | | vars [ n ] = = RAVI_TNUMINT ) & &
} else if ( ( var type = = RAVI_TNUMFLT | | vartype = = RAVI_TNUMINT ) & &
v - > k = = VINDEXED ) {
if ( ( var s[ n ] = = RAVI_TNUMFLT & & v - > ravi_type ! = RAVI_TARRAYFLT ) | |
( var s[ n ] = = RAVI_TNUMINT & & v - > ravi_type ! = RAVI_TARRAYINT ) )
if ( ( var type = = RAVI_TNUMFLT & & v - > ravi_type ! = RAVI_TARRAYFLT ) | |
( var type = = RAVI_TNUMINT & & v - > ravi_type ! = RAVI_TARRAYINT ) )
luaX_syntaxerror ( ls , " Invalid local assignment " ) ;
} else
} else {
luaX_syntaxerror ( ls , " Invalid local assignment " ) ;
}
}
}