xo-numeric: type decoration for multiply
This commit is contained in:
parent
7bfe5d9586
commit
9fda81bd04
4 changed files with 37 additions and 10 deletions
|
|
@ -20,6 +20,8 @@
|
|||
#include <xo/object2/DFloat.hpp>
|
||||
#include <xo/object2/number/IGCObject_DFloat.hpp>
|
||||
|
||||
#include <xo/stringtable2/StringTable.hpp>
|
||||
|
||||
#include <xo/alloc2/CollectorTypeRegistry.hpp>
|
||||
#include <xo/gc/X1Collector.hpp>
|
||||
//#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
|
||||
|
|
@ -45,6 +47,7 @@ namespace ut {
|
|||
using xo::scm::NumericPrimitives;
|
||||
using xo::scm::Primitives;
|
||||
using xo::scm::DPrimitive_gco_2_gco_gco;
|
||||
using xo::scm::StringTable;
|
||||
using xo::mm::CollectorTypeRegistry;
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::ACollector;
|
||||
|
|
@ -87,12 +90,14 @@ namespace ut {
|
|||
DX1Collector gc(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&gc);
|
||||
auto coll = with_facet<ACollector>::mkobj(&gc);
|
||||
auto stbl = StringTable(1024 /*hint_max_capacity*/, false /*!debug_flag*/);
|
||||
|
||||
bool ok = CollectorTypeRegistry::instance().install_types(coll);
|
||||
REQUIRE(ok);
|
||||
|
||||
// wrap primitive as GCObject, then as expression
|
||||
obj<AGCObject> prim_gco = with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc));
|
||||
obj<AGCObject> prim_gco
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc, &stbl));
|
||||
obj<AExpression,DConstant> fn_expr = DConstant::make(alloc, prim_gco);
|
||||
REQUIRE(fn_expr.data() != nullptr);
|
||||
|
||||
|
|
@ -127,12 +132,13 @@ namespace ut {
|
|||
DX1Collector gc(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&gc);
|
||||
auto coll = with_facet<ACollector>::mkobj(&gc);
|
||||
auto stbl = StringTable(1024 /*hint_max_capacity*/, false /*!debug_flag*/);
|
||||
|
||||
bool ok = CollectorTypeRegistry::instance().install_types(coll);
|
||||
REQUIRE(ok);
|
||||
|
||||
obj<AGCObject> prim_gco
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc));
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc, &stbl));
|
||||
obj<AExpression,DConstant> fn_expr = DConstant::make(alloc, prim_gco);
|
||||
|
||||
obj<AGCObject> val1 = DFloat::box<AGCObject>(alloc, 3.0);
|
||||
|
|
@ -163,11 +169,13 @@ namespace ut {
|
|||
DX1Collector gc(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&gc);
|
||||
auto coll = with_facet<ACollector>::mkobj(&gc);
|
||||
auto stbl = StringTable(1024 /*hint_max_capacity*/, false /*!debug_flag*/);
|
||||
|
||||
bool ok = CollectorTypeRegistry::instance().install_types(coll);
|
||||
REQUIRE(ok);
|
||||
|
||||
obj<AGCObject> prim_gco = with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc));
|
||||
obj<AGCObject> prim_gco
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc, &stbl));
|
||||
obj<AExpression,DConstant> fn_expr = DConstant::make(alloc, prim_gco);
|
||||
|
||||
obj<AGCObject> val1 = DFloat::box<AGCObject>(alloc, 3.0);
|
||||
|
|
@ -198,11 +206,13 @@ namespace ut {
|
|||
DX1Collector gc(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&gc);
|
||||
auto coll = with_facet<ACollector>::mkobj(&gc);
|
||||
auto stbl = StringTable(1024 /*hint_max_capacity*/, false /*!debug_flag*/);
|
||||
|
||||
bool ok = CollectorTypeRegistry::instance().install_types(coll);
|
||||
REQUIRE(ok);
|
||||
|
||||
obj<AGCObject> prim_gco = with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc));
|
||||
obj<AGCObject> prim_gco
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc, &stbl));
|
||||
obj<AExpression,DConstant> fn_expr = DConstant::make(alloc, prim_gco);
|
||||
|
||||
obj<AGCObject> val1 = DFloat::box<AGCObject>(alloc, 3.0);
|
||||
|
|
@ -236,12 +246,13 @@ namespace ut {
|
|||
DX1Collector gc(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&gc);
|
||||
auto coll = with_facet<ACollector>::mkobj(&gc);
|
||||
auto stbl = StringTable(1024 /*hint_max_capacity*/, false /*!debug_flag*/);
|
||||
|
||||
bool ok = CollectorTypeRegistry::instance().install_types(coll);
|
||||
REQUIRE(ok);
|
||||
|
||||
obj<AGCObject> prim_gco
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc));
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc, &stbl));
|
||||
obj<AExpression,DConstant> fn_expr = DConstant::make(alloc, prim_gco);
|
||||
|
||||
obj<AGCObject> val1 = DFloat::box<AGCObject>(alloc, 3.0);
|
||||
|
|
@ -281,12 +292,13 @@ namespace ut {
|
|||
DX1Collector gc(cfg);
|
||||
auto alloc = with_facet<AAllocator>::mkobj(&gc);
|
||||
auto coll = with_facet<ACollector>::mkobj(&gc);
|
||||
auto stbl = StringTable(1024 /*hint_max_capacity*/, false /*!debug_flag*/);
|
||||
|
||||
bool ok = CollectorTypeRegistry::instance().install_types(coll);
|
||||
REQUIRE(ok);
|
||||
|
||||
obj<AGCObject> prim_gco
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc));
|
||||
= with_facet<AGCObject>::mkobj(NumericPrimitives::make_multiply_pm(alloc, &stbl));
|
||||
obj<AExpression,DConstant> fn_expr = DConstant::make(alloc, prim_gco);
|
||||
|
||||
obj<AGCObject> val1 = DFloat::box<AGCObject>(alloc, 3.0);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ namespace xo {
|
|||
|
||||
public:
|
||||
/** polymorphic (in both arguments1) multiply **/
|
||||
static DPrimitive_gco_2_gco_gco * make_multiply_pm(obj<AAllocator> mm);
|
||||
static DPrimitive_gco_2_gco_gco * make_multiply_pm(obj<AAllocator> mm,
|
||||
StringTable * stbl);
|
||||
|
||||
/** polymorphic (in both arguments) divide **/
|
||||
static DPrimitive_gco_2_gco_gco * make_divide_pm(obj<AAllocator> mm);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "NumericPrimitives.hpp"
|
||||
#include "NumericDispatch.hpp"
|
||||
#include <xo/type/AtomicType.hpp>
|
||||
#include <xo/type/FunctionType.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AAllocator;
|
||||
|
|
@ -13,9 +15,21 @@ namespace xo {
|
|||
namespace scm {
|
||||
|
||||
DPrimitive_gco_2_gco_gco *
|
||||
NumericPrimitives::make_multiply_pm(obj<AAllocator> mm)
|
||||
NumericPrimitives::make_multiply_pm(obj<AAllocator> mm,
|
||||
StringTable * stbl)
|
||||
{
|
||||
return DPrimitive_gco_2_gco_gco::_make(mm, "_mul",
|
||||
(void)stbl;
|
||||
|
||||
// TODO: want to expand this to record schedule based on argument types.
|
||||
//
|
||||
// e.g. f64 x f64 -> f64
|
||||
|
||||
auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric());
|
||||
// #op+: numeric x numeric -> numeric
|
||||
auto pm_ty = obj<AType,DFunctionType>
|
||||
(DFunctionType::_make(mm, numeric_ty, numeric_ty, numeric_ty));
|
||||
|
||||
return DPrimitive_gco_2_gco_gco::_make(mm, "_mul", pm_ty,
|
||||
&NumericDispatch::multiply);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace xo {
|
|||
bool ok = true;
|
||||
|
||||
ok = ok & install_aux(sink,
|
||||
NumericPrimitives::make_multiply_pm(mm),
|
||||
NumericPrimitives::make_multiply_pm(mm, stbl),
|
||||
flags & InstallFlags::f_essential);
|
||||
ok = ok & install_aux(sink,
|
||||
NumericPrimitives::make_divide_pm(mm),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue