|
|
|
@ -589,8 +589,8 @@ static const char Lua_header[] =
|
|
|
|
|
"extern void raviV_op_setupvalai(lua_State *L, LClosure *cl, TValue *ra, int b);\n"
|
|
|
|
|
"extern void raviV_op_setupvalaf(lua_State *L, LClosure *cl, TValue *ra, int b);\n"
|
|
|
|
|
"extern void raviV_op_setupvalt(lua_State *L, LClosure *cl, TValue *ra, int b);\n"
|
|
|
|
|
"extern void raise_error(lua_State *L, int errorcode);\n"
|
|
|
|
|
"extern void raise_error_with_info(lua_State *L, int errorcode, const char *info);\n"
|
|
|
|
|
"extern void raviV_raise_error(lua_State *L, int errorcode);\n"
|
|
|
|
|
"extern void raviV_raise_error_with_info(lua_State *L, int errorcode, const char *info);\n"
|
|
|
|
|
"extern void luaD_call (lua_State *L, StkId func, int nResults);\n"
|
|
|
|
|
"extern void raviH_set_int(lua_State *L, RaviArray *t, lua_Unsigned key, lua_Integer value);\n"
|
|
|
|
|
"extern void raviH_set_float(lua_State *L, RaviArray *t, lua_Unsigned key, lua_Number value);\n"
|
|
|
|
@ -720,7 +720,7 @@ static void emit_IARRAY_GET(struct function *fn, int A, int B, int C, bool omitA
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_array_out_of_bounds);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_array_out_of_bounds);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_array_out_of_bounds);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -744,7 +744,7 @@ static void emit_FARRAY_GET(struct function *fn, int A, int B, int C, bool omitA
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_array_out_of_bounds);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_array_out_of_bounds);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_array_out_of_bounds);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -780,7 +780,7 @@ static void emit_IARRAY_SET(struct function *fn, int A, int B, int C, bool known
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_integer_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_integer_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_integer_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
membuff_add_string(&fn->body, "i = ivalue(rc);\n");
|
|
|
|
@ -821,7 +821,7 @@ static void emit_FARRAY_SET(struct function *fn, int A, int B, int C, bool known
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_number_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_number_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_number_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
membuff_add_string(&fn->body, "n = (ttisinteger(rc) ? (double)ivalue(rc) : fltvalue(rc));\n");
|
|
|
|
@ -1165,7 +1165,7 @@ static void emit_op_testset(struct function *fn, int A, int B, int C, int j, int
|
|
|
|
|
|
|
|
|
|
static void emit_endf(struct function *fn) {
|
|
|
|
|
membuff_add_string(&fn->body, "Lraise_error:\n");
|
|
|
|
|
membuff_add_string(&fn->body, "raise_error(L, error_code); /* does not return */\n");
|
|
|
|
|
membuff_add_string(&fn->body, "raviV_raise_error(L, error_code); /* does not return */\n");
|
|
|
|
|
membuff_add_string(&fn->body, "return 0;\n");
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1454,7 +1454,7 @@ static void emit_op_movei(struct function *fn, int A, int B, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_integer_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_integer_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_integer_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1472,7 +1472,7 @@ static void emit_op_movef(struct function *fn, int A, int B, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_number_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_number_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_number_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1487,7 +1487,7 @@ static void emit_op_MOVEIARRAY(struct function *fn, int A, int B, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_integer_array_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_integer_array_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_integer_array_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1502,7 +1502,7 @@ static void emit_op_MOVEFARRAY(struct function *fn, int A, int B, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_number_array_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_number_array_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_number_array_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1517,7 +1517,7 @@ static void emit_op_movetab(struct function *fn, int A, int B, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_table_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_table_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_table_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1532,7 +1532,7 @@ static void emit_op_toint(struct function *fn, int A, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_integer_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_integer_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_integer_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1549,7 +1549,7 @@ static void emit_op_toflt(struct function *fn, int A, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_number_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_number_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_number_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1562,7 +1562,7 @@ static void emit_op_toai(struct function *fn, int A, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_integer_array_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_integer_array_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_integer_array_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1575,7 +1575,7 @@ static void emit_op_toaf(struct function *fn, int A, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_number_array_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_number_array_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_number_array_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1588,7 +1588,7 @@ static void emit_op_totab(struct function *fn, int A, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_table_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_table_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_table_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1601,7 +1601,7 @@ static void emit_op_toclosure(struct function *fn, int A, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_closure_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_closure_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_closure_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1614,7 +1614,7 @@ static void emit_op_tostring(struct function *fn, int A, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_string_expected);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_string_expected);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_string_expected);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
|
}
|
|
|
|
@ -1629,7 +1629,7 @@ static void emit_op_totype(struct function *fn, int A, int Bx, int pc) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_type_mismatch);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error_with_info(L, %d, getstr(tsvalue(rb)));\n", Error_type_mismatch);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error_with_info(L, %d, getstr(tsvalue(rb)));\n", Error_type_mismatch);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, " }\n");
|
|
|
|
|
membuff_add_string(&fn->body, "}\n");
|
|
|
|
@ -1732,7 +1732,7 @@ static void emit_op_forprep(struct function *fn, int A, int pc, int pc1) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_for_limit_must_be_number);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_for_limit_must_be_number);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_for_limit_must_be_number);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, " }\n");
|
|
|
|
|
membuff_add_fstring(&fn->body, " if (!ttisnumber(rc)) {\n", A);
|
|
|
|
@ -1740,7 +1740,7 @@ static void emit_op_forprep(struct function *fn, int A, int pc, int pc1) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_for_step_must_be_number);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_for_step_must_be_number);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_for_step_must_be_number);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, " }\n");
|
|
|
|
|
membuff_add_fstring(&fn->body, " if (!ttisnumber(ra)) {\n", A);
|
|
|
|
@ -1748,7 +1748,7 @@ static void emit_op_forprep(struct function *fn, int A, int pc, int pc1) {
|
|
|
|
|
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_for_initial_value_must_be_number);
|
|
|
|
|
membuff_add_string(&fn->body, " goto Lraise_error;\n");
|
|
|
|
|
#else
|
|
|
|
|
membuff_add_fstring(&fn->body, " raise_error(L, %d);\n", Error_for_initial_value_must_be_number);
|
|
|
|
|
membuff_add_fstring(&fn->body, " raviV_raise_error(L, %d);\n", Error_for_initial_value_must_be_number);
|
|
|
|
|
#endif
|
|
|
|
|
membuff_add_string(&fn->body, " }\n");
|
|
|
|
|
membuff_add_fstring(&fn->body, " tonumberns(rb, nlimit_%d);\n", A);
|
|
|
|
@ -2335,3 +2335,32 @@ bool raviJ_codegen(struct lua_State *L, struct Proto *p, struct ravi_compile_opt
|
|
|
|
|
cleanup(&fn);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *errortext[] = {"integer expected",
|
|
|
|
|
"number expected",
|
|
|
|
|
"integer[] expected",
|
|
|
|
|
"number[] expected",
|
|
|
|
|
"table expected",
|
|
|
|
|
"upvalue of integer type, cannot be set to non integer value",
|
|
|
|
|
"upvalue of number type, cannot be set to non number value",
|
|
|
|
|
"upvalue of integer[] type, cannot be set to non integer[] value",
|
|
|
|
|
"upvalue of number[] type, cannot be set to non number[] value",
|
|
|
|
|
"upvalue of table type, cannot be set to non table value",
|
|
|
|
|
"for llimit must be a number",
|
|
|
|
|
"for step must be a number",
|
|
|
|
|
"for initial value must be a number",
|
|
|
|
|
"array index is out of bounds",
|
|
|
|
|
"string expected",
|
|
|
|
|
"closure expected",
|
|
|
|
|
"type mismatch: wrong userdata type",
|
|
|
|
|
NULL};
|
|
|
|
|
|
|
|
|
|
void raviV_raise_error(lua_State *L, int errorcode) {
|
|
|
|
|
assert(errorcode >= 0 && errorcode < Error_type_mismatch);
|
|
|
|
|
luaG_runerror(L, errortext[errorcode]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void raviV_raise_error_with_info(lua_State *L, int errorcode, const char *info) {
|
|
|
|
|
assert(errorcode == Error_type_mismatch);
|
|
|
|
|
luaG_runerror(L, "type mismatch: expected %s", info);
|
|
|
|
|
}
|
|
|
|
|