diff --git a/src/interpreter2/VirtualSchematikaMachine.cpp b/src/interpreter2/VirtualSchematikaMachine.cpp index 9104fa2f..40ccb834 100644 --- a/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/src/interpreter2/VirtualSchematikaMachine.cpp @@ -185,6 +185,14 @@ namespace xo { if (expr_pr) log && log(xtag("expr", expr_pr)); + if (value_.value()) { + auto value_pr = const_cast *>(value_.value())->to_facet(); + if (value_pr) + log && log(xtag("value", value_pr)); + } else { + log && log("value not present or tk error"); + } + auto stack_pr = stack_.to_facet(); if (stack_pr) log && log(xtag("stack", stack_pr)); diff --git a/utest/VirtualSchematikaMachine.test.cpp b/utest/VirtualSchematikaMachine.test.cpp index 75726b72..a42746ae 100644 --- a/utest/VirtualSchematikaMachine.test.cpp +++ b/utest/VirtualSchematikaMachine.test.cpp @@ -490,7 +490,7 @@ namespace xo { log && vsm_fixture.log_memory_layout(&log); } - TEST_CASE("VirtualSchematikaMachine-fact0", "[interpreter2][VSM]") + TEST_CASE("VirtualSchematikaMachine-if2", "[interpreter2][VSM]") { const auto & testname = Catch::getResultCapture().getCurrentTestName(); @@ -504,6 +504,53 @@ namespace xo { vsm.begin_interactive_session(); + span_type input = span_type::from_cstr("def n = 4; if (n == 4) then n * 3 else n * 5;"); + + for (int i_expr = 0; i_expr < 2; ++i_expr) { + log && log(xtag("input", input)); + + VsmResultExt res + = vsm.read_eval_print(input, eof_flag); + + REQUIRE(res.is_value()); + REQUIRE(res.value()); + + log && log(xtag("res.tseq", res.value()->_typeseq()), + xtag("res.type", TypeRegistry::id2name(res.value()->_typeseq()))); + + if (i_expr == 0) { + auto x = obj::from(*res.value()); + REQUIRE(x); + REQUIRE(strcmp(x->chars(), "n") == 0); + input = res.remaining_; + } else if (i_expr == 1) { + auto x = obj::from(*res.value()); + REQUIRE(x); + REQUIRE(x->value() == 12); + + REQUIRE(res.remaining_.size() == 1); + REQUIRE(*res.remaining_.lo() == '\n'); + input = res.remaining_; + } + } + + log && vsm_fixture.log_memory_layout(&log); + } + + TEST_CASE("VirtualSchematikaMachine-fact0", "[interpreter2][VSM]") + { + const auto & testname = Catch::getResultCapture().getCurrentTestName(); + + bool c_debug_flag = false; + scope log(XO_DEBUG(c_debug_flag), xtag("test", testname)); + + VsmFixture vsm_fixture(testname, c_debug_flag); + auto & vsm = vsm_fixture.vsm_; + + bool eof_flag = true; + + vsm.begin_interactive_session(); + span_type input = span_type::from_cstr("def fact = lambda (n) { if (n == 0) then 1 else n * fact(n - 1) }; fact(4);"); for (int i_expr = 0; i_expr < 2; ++i_expr) {