From 5842b193c769a51ecf03ac297648504e39325028 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 26 Jan 2026 17:08:25 -0500 Subject: [PATCH] xo-procedure2: add apply_nocheck() utest on gco multiply --- .../procedure2/procedure2_register_types.cpp | 2 + xo-procedure2/utest/DPrimitive.test.cpp | 82 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/xo-procedure2/src/procedure2/procedure2_register_types.cpp b/xo-procedure2/src/procedure2/procedure2_register_types.cpp index dedceb69..497773d2 100644 --- a/xo-procedure2/src/procedure2/procedure2_register_types.cpp +++ b/xo-procedure2/src/procedure2/procedure2_register_types.cpp @@ -23,6 +23,8 @@ namespace xo { bool ok = true; + // (note: don't currently intend to support AGCObject for DSimpleRcx) + ok &= gc.install_type(impl_for()); return ok; diff --git a/xo-procedure2/utest/DPrimitive.test.cpp b/xo-procedure2/utest/DPrimitive.test.cpp index db501dae..b3775e62 100644 --- a/xo-procedure2/utest/DPrimitive.test.cpp +++ b/xo-procedure2/utest/DPrimitive.test.cpp @@ -5,10 +5,29 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include namespace xo { using xo::scm::Primitives; + using xo::scm::DSimpleRcx; + using xo::scm::ARuntimeContext; + using xo::scm::DFloat; + using xo::scm::DInteger; + using xo::scm::DArray; + using xo::mm::AAllocator; + using xo::mm::AGCObject; + using xo::mm::DArena; + using xo::mm::ArenaConfig; + using xo::facet::with_facet; + using xo::facet::obj; namespace ut { static InitEvidence s_init = InitSubsys::require(); @@ -29,6 +48,69 @@ namespace xo { REQUIRE(Primitives::s_mul_gco_gco_pm.is_nary() == false); } + TEST_CASE("DPrimitive-apply_nocheck-float-float", "[procedure2][DPrimitive]") + { + ArenaConfig cfg { .name_ = "testarena", .size_ = 4*1024 }; + DArena arena = DArena::map(cfg); + auto alloc = with_facet::mkobj(&arena); + + DSimpleRcx rcx_data(alloc); + obj rcx = with_facet::mkobj(&rcx_data); + + // 3.0 * 7.0 = 21.0 + obj x = DFloat::box(alloc, 3.0); + obj y = DFloat::box(alloc, 7.0); + DArray * args = DArray::array(alloc, x, y); + + obj result = Primitives::s_mul_gco_gco_pm.apply_nocheck(rcx, args); + + auto result_float = obj::from(result); + REQUIRE(result_float); + REQUIRE(result_float.data()->value() == 21.0); + } + + TEST_CASE("DPrimitive-apply_nocheck-int-int", "[procedure2][DPrimitive]") + { + ArenaConfig cfg { .name_ = "testarena", .size_ = 4*1024 }; + DArena arena = DArena::map(cfg); + auto alloc = with_facet::mkobj(&arena); + + DSimpleRcx rcx_data(alloc); + obj rcx = with_facet::mkobj(&rcx_data); + + // 3 * 7 = 21 + obj x = DInteger::box(alloc, 3L); + obj y = DInteger::box(alloc, 7L); + DArray * args = DArray::array(alloc, x, y); + + obj result = Primitives::s_mul_gco_gco_pm.apply_nocheck(rcx, args); + + auto result_int = obj::from(result); + REQUIRE(result_int); + REQUIRE(result_int.data()->value() == 21L); + } + + TEST_CASE("DPrimitive-apply_nocheck-int-float", "[procedure2][DPrimitive]") + { + ArenaConfig cfg { .name_ = "testarena", .size_ = 4*1024 }; + DArena arena = DArena::map(cfg); + auto alloc = with_facet::mkobj(&arena); + + DSimpleRcx rcx_data(alloc); + obj rcx = with_facet::mkobj(&rcx_data); + + // 3 * 7.0 = 21.0 (mixed: result is float) + obj x = DInteger::box(alloc, 3L); + obj y = DFloat::box(alloc, 7.0); + DArray * args = DArray::array(alloc, x, y); + + obj result = Primitives::s_mul_gco_gco_pm.apply_nocheck(rcx, args); + + auto result_float = obj::from(result); + REQUIRE(result_float); + REQUIRE(result_float.data()->value() == 21.0); + } + } /*namespace ut*/ } /*namespace xo*/