Support utf-8

This commit is contained in:
2026-01-19 21:39:41 +08:00
parent 4247a59146
commit 57def6137b
6 changed files with 129 additions and 32 deletions

View File

@@ -123,31 +123,31 @@ TEST_CASE("class init is called on declaration", "[class][init]") {
REQUIRE(a_num->value == 18.0);
}
TEST_CASE("interpreter performance: simple loop", "[perf][script]") {
State state;
const char* script = R"(
func sum_to(number n) -> number {
number s = 0;
for (number i = 0; i < n; i = i + 1) {
s = s + i;
}
return s;
}
number r = sum_to(1000);
)";
// TEST_CASE("interpreter performance: simple loop", "[perf][script]") {
// State state;
// const char* script = R"(
// func sum_to(number n) -> number {
// number s = 0;
// for (number i = 0; i < n; i = i + 1) {
// s = s + i;
// }
// return s;
// }
// number r = sum_to(1000);
// )";
BENCHMARK("sum_to(1000)") {
if (!state.do_string(script)) {
auto last_error = state.get_error();
REQUIRE(last_error.empty());
}
auto r_val = state.get_global("r");
REQUIRE(r_val);
REQUIRE(r_val->type() == Type::NUMBER);
auto r_num = std::dynamic_pointer_cast<NumberValue>(r_val);
REQUIRE(r_num->value == 499500.0);
};
}
// BENCHMARK("sum_to(1000)") {
// if (!state.do_string(script)) {
// auto last_error = state.get_error();
// REQUIRE(last_error.empty());
// }
// auto r_val = state.get_global("r");
// REQUIRE(r_val);
// REQUIRE(r_val->type() == Type::NUMBER);
// auto r_num = std::dynamic_pointer_cast<NumberValue>(r_val);
// REQUIRE(r_num->value == 499500.0);
// };
// }
TEST_CASE("loop break", "[script][loop]") {
State state;