diff --git a/xo-procedure2/include/xo/procedure2/init_primitives.hpp b/xo-procedure2/include/xo/procedure2/init_primitives.hpp index d2d51a59..6747fa6b 100644 --- a/xo-procedure2/include/xo/procedure2/init_primitives.hpp +++ b/xo-procedure2/include/xo/procedure2/init_primitives.hpp @@ -15,13 +15,20 @@ namespace xo { #endif struct Primitives { - /** polymorphich multiply + /** polymorphic multiply * * TODO: this will want to move to xo-numeric/ * so we can dispatch on vector, matrix, function types **/ static DPrimitive_gco_2_gco_gco s_mul_gco_gco_pm; + /** polymorphic subtract + * + * TODO: this will want to move to xo-numeric/ + * so we can dispatch on vector, matrix, function types + **/ + static DPrimitive_gco_2_gco_gco s_sub_gco_gco_pm; + /** polymorphic equality comparison * * TODO: this will want to move to x-numeric/ diff --git a/xo-procedure2/src/procedure2/init_primitives.cpp b/xo-procedure2/src/procedure2/init_primitives.cpp index c1eceada..f3759f4b 100644 --- a/xo-procedure2/src/procedure2/init_primitives.cpp +++ b/xo-procedure2/src/procedure2/init_primitives.cpp @@ -99,6 +99,66 @@ namespace xo { return obj(); } + obj + sub_gco_gco(obj rcx, + obj x_gco, + obj y_gco) + { + using xo::reflect::typeseq; + + obj mm = rcx.allocator(); + + // PLACEHOLDER + + // TODO: + // 1. move this to xo-numeric2/ when available + // 2. at that point will require polymorphic dispatch + // on argument representations, analogous to dispatch + // in FacetRegistry + + typeseq x_tseq = x_gco._typeseq(); + typeseq y_tseq = y_gco._typeseq(); + + // FOR NOW: just test runtime values + // + if (x_tseq == typeseq::id()) { + // i64 * .. + long x = GCObjectConversion::from_gco(mm, x_gco); + + if (y_tseq == typeseq::id()) { + // i64 * i64 + long y = GCObjectConversion::from_gco(mm, y_gco); + + return DInteger::box(mm, x - y); + } else if (y_tseq == typeseq::id()) { + // i64 * f64 + double y = GCObjectConversion::from_gco(mm, y_gco); + + return DFloat::box(mm, x - y); + } + } else if (x_tseq == typeseq::id()) { + if (y_tseq == typeseq::id()) { + // f64 * i64. + double x = GCObjectConversion::from_gco(mm, x_gco); + long y = GCObjectConversion::from_gco(mm, y_gco); + + return DFloat::box(mm, x - y); + } else if (y_tseq == typeseq::id()) { + // f64 * f64. + double x = GCObjectConversion::from_gco(mm, x_gco); + double y = GCObjectConversion::from_gco(mm, y_gco); + + return DFloat::box(mm, x - y); + } + } + + // here: error + throw std::runtime_error(tostr("sub_gco_gco: unexpected argument types xt,yt", + xtag("x.tseq", x_tseq), + xtag("y.tseq", y_tseq))); + return obj(); + } + obj equal_gco_gco(obj rcx, obj x_gco, @@ -113,7 +173,7 @@ namespace xo { // TODO // 1. move this to xo-numeric2/ when available // 2. at that point will require polymorphic dispatch on argument representations. - // + // typeseq x_tseq = x_gco._typeseq(); typeseq y_tseq = y_gco._typeseq(); @@ -150,7 +210,7 @@ namespace xo { return DFloat::box(mm, x == y); } } - + // here: error throw std::runtime_error(tostr("mul_gco_gco: unexpected argument types xt,yt", xtag("x.tseq", x_tseq), @@ -198,6 +258,9 @@ namespace xo { DPrimitive_gco_2_gco_gco Primitives::s_mul_gco_gco_pm("_mul", &mul_gco_gco); + DPrimitive_gco_2_gco_gco + Primitives::s_sub_gco_gco_pm("_sub", &sub_gco_gco); + DPrimitive_gco_2_gco_gco Primitives::s_equal_gco_gco_pm("_equal", &equal_gco_gco);