xo-procedure2: + generic subtract primitive
This commit is contained in:
parent
4a5d924676
commit
c7d820a92b
2 changed files with 73 additions and 3 deletions
|
|
@ -15,13 +15,20 @@ namespace xo {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct Primitives {
|
struct Primitives {
|
||||||
/** polymorphich multiply
|
/** polymorphic multiply
|
||||||
*
|
*
|
||||||
* TODO: this will want to move to xo-numeric/
|
* TODO: this will want to move to xo-numeric/
|
||||||
* so we can dispatch on vector, matrix, function types
|
* so we can dispatch on vector, matrix, function types
|
||||||
**/
|
**/
|
||||||
static DPrimitive_gco_2_gco_gco s_mul_gco_gco_pm;
|
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
|
/** polymorphic equality comparison
|
||||||
*
|
*
|
||||||
* TODO: this will want to move to x-numeric/
|
* TODO: this will want to move to x-numeric/
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,66 @@ namespace xo {
|
||||||
return obj<AGCObject>();
|
return obj<AGCObject>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj<AGCObject>
|
||||||
|
sub_gco_gco(obj<ARuntimeContext> rcx,
|
||||||
|
obj<AGCObject> x_gco,
|
||||||
|
obj<AGCObject> y_gco)
|
||||||
|
{
|
||||||
|
using xo::reflect::typeseq;
|
||||||
|
|
||||||
|
obj<AAllocator> 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<DInteger>()) {
|
||||||
|
// i64 * ..
|
||||||
|
long x = GCObjectConversion<long>::from_gco(mm, x_gco);
|
||||||
|
|
||||||
|
if (y_tseq == typeseq::id<DInteger>()) {
|
||||||
|
// i64 * i64
|
||||||
|
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
|
||||||
|
|
||||||
|
return DInteger::box<AGCObject>(mm, x - y);
|
||||||
|
} else if (y_tseq == typeseq::id<DFloat>()) {
|
||||||
|
// i64 * f64
|
||||||
|
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
|
||||||
|
|
||||||
|
return DFloat::box<AGCObject>(mm, x - y);
|
||||||
|
}
|
||||||
|
} else if (x_tseq == typeseq::id<DFloat>()) {
|
||||||
|
if (y_tseq == typeseq::id<DInteger>()) {
|
||||||
|
// f64 * i64.
|
||||||
|
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
|
||||||
|
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
|
||||||
|
|
||||||
|
return DFloat::box<AGCObject>(mm, x - y);
|
||||||
|
} else if (y_tseq == typeseq::id<DFloat>()) {
|
||||||
|
// f64 * f64.
|
||||||
|
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
|
||||||
|
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
|
||||||
|
|
||||||
|
return DFloat::box<AGCObject>(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<AGCObject>();
|
||||||
|
}
|
||||||
|
|
||||||
obj<AGCObject>
|
obj<AGCObject>
|
||||||
equal_gco_gco(obj<ARuntimeContext> rcx,
|
equal_gco_gco(obj<ARuntimeContext> rcx,
|
||||||
obj<AGCObject> x_gco,
|
obj<AGCObject> x_gco,
|
||||||
|
|
@ -113,7 +173,7 @@ namespace xo {
|
||||||
// TODO
|
// TODO
|
||||||
// 1. move this to xo-numeric2/ when available
|
// 1. move this to xo-numeric2/ when available
|
||||||
// 2. at that point will require polymorphic dispatch on argument representations.
|
// 2. at that point will require polymorphic dispatch on argument representations.
|
||||||
//
|
//
|
||||||
|
|
||||||
typeseq x_tseq = x_gco._typeseq();
|
typeseq x_tseq = x_gco._typeseq();
|
||||||
typeseq y_tseq = y_gco._typeseq();
|
typeseq y_tseq = y_gco._typeseq();
|
||||||
|
|
@ -150,7 +210,7 @@ namespace xo {
|
||||||
return DFloat::box<AGCObject>(mm, x == y);
|
return DFloat::box<AGCObject>(mm, x == y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// here: error
|
// here: error
|
||||||
throw std::runtime_error(tostr("mul_gco_gco: unexpected argument types xt,yt",
|
throw std::runtime_error(tostr("mul_gco_gco: unexpected argument types xt,yt",
|
||||||
xtag("x.tseq", x_tseq),
|
xtag("x.tseq", x_tseq),
|
||||||
|
|
@ -198,6 +258,9 @@ namespace xo {
|
||||||
DPrimitive_gco_2_gco_gco
|
DPrimitive_gco_2_gco_gco
|
||||||
Primitives::s_mul_gco_gco_pm("_mul", &mul_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
|
DPrimitive_gco_2_gco_gco
|
||||||
Primitives::s_equal_gco_gco_pm("_equal", &equal_gco_gco);
|
Primitives::s_equal_gco_gco_pm("_equal", &equal_gco_gco);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue