Extend test program a bit to try the new reset() method.

This commit is contained in:
King_DuckZ 2021-02-12 14:42:51 +01:00
parent cfc8bb89f8
commit 68df4d3371

View file

@ -24,6 +24,24 @@ System.print("my_sum = %(my_sum) (expected: 19)")
var my_sub = Maths.sub(Maths.sub(8, 5), Maths.sub(20, 19)) + 1
System.print("my_sub = %(my_sub) (expected: 3)")
)script";
const constexpr char g_script_2[] = ""
R"script(class Maths {
foreign static mul(a,b)
foreign static div(a,b)
foreign static sum(a,b)
foreign static sub(a,b)
}
var my_mul_2 = Maths.mul(Maths.mul(2, 2), Maths.mul(3, 2)) - 4
System.print("my_mul_2 = %(my_mul_2) (expected: 20)")
var my_sum_2 = Maths.sum(Maths.sum(3, 4), Maths.sum(5, -1)) + 8
System.print("my_sum_2 = %(my_sum_2) (expected: 19)")
var my_sub_2 = Maths.sub(Maths.sub(8, 5), Maths.sub(20, 19)) + 1
System.print("my_sub_2 = %(my_sub_2) (expected: 3)")
)script";
class MyConfig : public wren::DefConfiguration {
@ -89,6 +107,18 @@ int main() {
wren::VM vm(&config, nullptr);
vm.interpret("main", g_script);
wren::variable_ensure_slot(vm, {"main", "my_mul"}, 0);
std::cout << "Dynafunc mem usage: " << vm.dynafunc_byte_size() << " bytes\n";
vm.reset(&config);
std::cout << "Dynafunc mem usage after reset: " << vm.dynafunc_byte_size() << " bytes\n";
vm.interpret("main", g_script_2);
{
auto [var] = wren::variables<int>(vm, wren::ModuleAndName{"main", "my_mul_2"});
std::cout << "main::my_mul2 == " << var << " (expected: 20)\n";
}
std::cout << "Dynafunc mem usage: " << vm.dynafunc_byte_size() << " bytes\n";
return 0;