From 68df4d33715cbda0c0512807ee331181c376ac2a Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 12 Feb 2021 14:42:51 +0100 Subject: [PATCH] Extend test program a bit to try the new reset() method. --- test/unit/main.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/unit/main.cpp b/test/unit/main.cpp index b5c91e8..bae689d 100644 --- a/test/unit/main.cpp +++ b/test/unit/main.cpp @@ -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(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;